Completed
Branch EE5Update (bc64e6)
by
unknown
09:36 queued 05:38
created
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, 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, 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.
core/libraries/qtips/EE_Qtip_Config.lib.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -207,7 +207,7 @@
 block discarded – undo
207 207
     {
208 208
         foreach ($this->_qtipsa as $qt) {
209 209
             // make sure we have what we need.
210
-            if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
210
+            if ( ! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
211 211
                 throw new EE_Error(
212 212
                     sprintf(
213 213
                         esc_html__(
Please login to merge, or discard this patch.
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -14,235 +14,235 @@  discard block
 block discarded – undo
14 14
  */
15 15
 abstract class EE_Qtip_Config extends EE_Base
16 16
 {
17
-    /**
18
-     * This will hold the qtips setup array (setup by children)
19
-     *
20
-     * @access protected
21
-     * @var array
22
-     */
23
-    protected $_qtipsa;
17
+	/**
18
+	 * This will hold the qtips setup array (setup by children)
19
+	 *
20
+	 * @access protected
21
+	 * @var array
22
+	 */
23
+	protected $_qtipsa;
24 24
 
25 25
 
26
-    /**
27
-     * This holds the constructed EE_Qtip objects
28
-     *
29
-     * @access protected
30
-     * @var EE_Qtip
31
-     */
32
-    protected $_qtips;
26
+	/**
27
+	 * This holds the constructed EE_Qtip objects
28
+	 *
29
+	 * @access protected
30
+	 * @var EE_Qtip
31
+	 */
32
+	protected $_qtips;
33 33
 
34 34
 
35
-    /**
36
-     * an array of default options for instantiated qtip js objects
37
-     *
38
-     * @access protected
39
-     * @var array
40
-     */
41
-    protected $_default_options;
35
+	/**
36
+	 * an array of default options for instantiated qtip js objects
37
+	 *
38
+	 * @access protected
39
+	 * @var array
40
+	 */
41
+	protected $_default_options;
42 42
 
43 43
 
44
-    /**
45
-     * constructor
46
-     *
47
-     * @access public
48
-     */
49
-    public function __construct()
50
-    {
51
-        $this->_qtipsa = $this->_qtips = array();
52
-        $this->_set_default_options();
53
-        $this->_set_tips_array();
54
-        $this->_construct_tips();
55
-    }
44
+	/**
45
+	 * constructor
46
+	 *
47
+	 * @access public
48
+	 */
49
+	public function __construct()
50
+	{
51
+		$this->_qtipsa = $this->_qtips = array();
52
+		$this->_set_default_options();
53
+		$this->_set_tips_array();
54
+		$this->_construct_tips();
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * Children define this method and its purpose is to setup the $_qtipsa property.  The format of this property is:
60
-     *
61
-     * $qtipsa = array(
62
-     *        0 => array(
63
-     *            'content_id' => 'some_unique_id_for_referencing_content', //just the string
64
-     *            'content' => 'html/text content for the qtip',
65
-     *            'target' => '#target-element', //use the same schema as jQuery selectors.  This will match what the
66
-     *            target is for the qTip in the dom (i.e. if class then '.some-class').
67
-     *            'options' => array() //use this to override any of the default options for this specific qtip.
68
-     *        )
69
-     * );
70
-     *
71
-     * @abstract
72
-     * @access protected
73
-     * @return void
74
-     */
75
-    abstract protected function _set_tips_array();
58
+	/**
59
+	 * Children define this method and its purpose is to setup the $_qtipsa property.  The format of this property is:
60
+	 *
61
+	 * $qtipsa = array(
62
+	 *        0 => array(
63
+	 *            'content_id' => 'some_unique_id_for_referencing_content', //just the string
64
+	 *            'content' => 'html/text content for the qtip',
65
+	 *            'target' => '#target-element', //use the same schema as jQuery selectors.  This will match what the
66
+	 *            target is for the qTip in the dom (i.e. if class then '.some-class').
67
+	 *            'options' => array() //use this to override any of the default options for this specific qtip.
68
+	 *        )
69
+	 * );
70
+	 *
71
+	 * @abstract
72
+	 * @access protected
73
+	 * @return void
74
+	 */
75
+	abstract protected function _set_tips_array();
76 76
 
77 77
 
78
-    /**
79
-     * all the default options for the qtip js are defined here.  Children class can override the defaults for all the
80
-     * qtips defined in their config OR just leave it and have the parent default options apply.
81
-     *
82
-     * commented out options are there for reference so you know which can be defined by the child.
83
-     *
84
-     * Note: children do NOT have to define all these options.  Just define the ones to override.
85
-     *
86
-     * @link   http://qtip2.com/options
87
-     *
88
-     * @access protected
89
-     * @return void
90
-     */
91
-    protected function _set_default_options()
92
-    {
93
-        $this->_default_options = array(
94
-            // 'id' => 'unique_id_referncing_qtip_instance',
95
-            'prerender'      => false,
96
-            // increases page load if true,
97
-            'suppress'       => true,
98
-            // whether default browser tooltips are suppressed.
99
-            'content'        => array(
100
-                'button' => false,
101
-                // what you want for the close button text/link.
102
-                'title'  => true,
103
-                // Options: "string", true.  If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title.
104
-                'clone'  => true,
105
-                // Options: true|false.  if true then the text will be cloned from the content instead of removed from the dom.
106
-            ),
107
-            'show_only_once' => false,
108
-            // this is NOT a qtip2 library option, but is something added for EE specific use.  If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit).
109
-            'position'       => array(
110
-                'my'        => 'top left',
111
-                // top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top
112
-                'at'        => 'bottom right',
113
-                // same options as above.
114
-                'target'    => 'event',
115
-                // if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page.
116
-                'container' => false,
117
-                // what HTML element the tooltip is appended to (it's containing element). jquery object.  Use 'jQuery::#selector' and js will parse'
118
-                'viewport'  => true,
119
-                // @link http://qtip2.com/plugins#viewport
120
-                'adjust'    => array(
121
-                    'x'      => 0,
122
-                    // adjust position on x axis by 0 pixels.
123
-                    'y'      => 0,
124
-                    // adjust position on y axis by 0 pixels.
125
-                    'mouse'  => true,
126
-                    // when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target.  False, stops following.
127
-                    'resize' => true,
128
-                    // adjust tooltip position when window is resized.
129
-                    'scroll' => true,
130
-                    // position of tooltip adjusted when window (or position.container) is scrolled.
131
-                    'method' => 'flipinvert',
132
-                    // @link http://qtip2.com/plugins#viewport
133
-                ),
134
-            ),
135
-            'show'           => array(
136
-                'event'  => 'mouseenter',
137
-                // what event triggers tooltip to be shown.  Any jQuery standard event or custom events can be used. space separated events provide multiple triggers.
138
-                'target' => false,
139
-                // options jQuery::#selector|false.  Used to indicate which html element will trigger show event.  When false, the element the qtip() method was called upon is used.
140
-                'delay'  => 90,
141
-                // time in millisecons by which to delay showing of tooltip.
142
-                'solo'   => false,
143
-                // determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden)
144
-                'modal'  => array(
145
-                    'on'         => false, // does tooltip trigger modal?
146
-                    'blur'       => true, // does clicking on the dimmed background hide the tooltip and remove the dim?
147
-                    'escape'     => true, // hitting escape key hide the tooltip and cancel modal
148
-                    'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on?
149
-                ),
150
-            ),
151
-            'hide'           => array(
152
-                'event'    => 'mouseleave',
153
-                // similar as what you do for show.event.
154
-                'target'   => false,
155
-                // Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used.
156
-                'delay'    => 0,
157
-                // set time in milliseconds for delaying the hide of the tooltip
158
-                'inactive' => false,
159
-                // if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with)
160
-                'fixed'    => false,
161
-                // when set to true, the tooltip will not hide if moused over.
162
-                'leave'    => 'window',
163
-                // specify whether the tooltip will hide when leaving the window it's conained within.
164
-                'distance' => false,
165
-                // if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip.
166
-            ),
167
-            'style'          => array(
168
-                'classes' => 'qtip-tipsy',
169
-                // Options "string", false.  A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class.
170
-                'def'     => true,
171
-                // set to false and the default qtip class does not get applied
172
-                'widget'  => false,
173
-                // whether ui-widget classes of the themeroller UI styles are applied to tooltip.
174
-                'width'   => false,
175
-                // Options: "string", integer, false.  with this you can override all applied CSS width styles for tooltip.  Can be any valid width CSS value. (does not override min/max width styles)
176
-                'height'  => false,
177
-                // same as above except applies to height.
178
-                'tip'     => array(
179
-                    'corner' => true,
180
-                    // where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false.  true inherits
181
-                    'mimic'  => false,
182
-                    // see documentation @link http://qtip2.com/plugins#tips
183
-                    'border' => true,
184
-                    // Options: true, integer. determines the width of the border that surrounds the tip element.  True inherits from tooltip.
185
-                    'width'  => 6,
186
-                    // width of rendered tip in pixels in relation to the side of the tooltip the tip is on.
187
-                    'height' => 6,
188
-                    // works the same as tip.width
189
-                    'offset' => 0,
190
-                    // use to set the offset of the tip in relation to its corner position.
191
-                ),
192
-            ),
78
+	/**
79
+	 * all the default options for the qtip js are defined here.  Children class can override the defaults for all the
80
+	 * qtips defined in their config OR just leave it and have the parent default options apply.
81
+	 *
82
+	 * commented out options are there for reference so you know which can be defined by the child.
83
+	 *
84
+	 * Note: children do NOT have to define all these options.  Just define the ones to override.
85
+	 *
86
+	 * @link   http://qtip2.com/options
87
+	 *
88
+	 * @access protected
89
+	 * @return void
90
+	 */
91
+	protected function _set_default_options()
92
+	{
93
+		$this->_default_options = array(
94
+			// 'id' => 'unique_id_referncing_qtip_instance',
95
+			'prerender'      => false,
96
+			// increases page load if true,
97
+			'suppress'       => true,
98
+			// whether default browser tooltips are suppressed.
99
+			'content'        => array(
100
+				'button' => false,
101
+				// what you want for the close button text/link.
102
+				'title'  => true,
103
+				// Options: "string", true.  If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title.
104
+				'clone'  => true,
105
+				// Options: true|false.  if true then the text will be cloned from the content instead of removed from the dom.
106
+			),
107
+			'show_only_once' => false,
108
+			// this is NOT a qtip2 library option, but is something added for EE specific use.  If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit).
109
+			'position'       => array(
110
+				'my'        => 'top left',
111
+				// top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top
112
+				'at'        => 'bottom right',
113
+				// same options as above.
114
+				'target'    => 'event',
115
+				// if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page.
116
+				'container' => false,
117
+				// what HTML element the tooltip is appended to (it's containing element). jquery object.  Use 'jQuery::#selector' and js will parse'
118
+				'viewport'  => true,
119
+				// @link http://qtip2.com/plugins#viewport
120
+				'adjust'    => array(
121
+					'x'      => 0,
122
+					// adjust position on x axis by 0 pixels.
123
+					'y'      => 0,
124
+					// adjust position on y axis by 0 pixels.
125
+					'mouse'  => true,
126
+					// when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target.  False, stops following.
127
+					'resize' => true,
128
+					// adjust tooltip position when window is resized.
129
+					'scroll' => true,
130
+					// position of tooltip adjusted when window (or position.container) is scrolled.
131
+					'method' => 'flipinvert',
132
+					// @link http://qtip2.com/plugins#viewport
133
+				),
134
+			),
135
+			'show'           => array(
136
+				'event'  => 'mouseenter',
137
+				// what event triggers tooltip to be shown.  Any jQuery standard event or custom events can be used. space separated events provide multiple triggers.
138
+				'target' => false,
139
+				// options jQuery::#selector|false.  Used to indicate which html element will trigger show event.  When false, the element the qtip() method was called upon is used.
140
+				'delay'  => 90,
141
+				// time in millisecons by which to delay showing of tooltip.
142
+				'solo'   => false,
143
+				// determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden)
144
+				'modal'  => array(
145
+					'on'         => false, // does tooltip trigger modal?
146
+					'blur'       => true, // does clicking on the dimmed background hide the tooltip and remove the dim?
147
+					'escape'     => true, // hitting escape key hide the tooltip and cancel modal
148
+					'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on?
149
+				),
150
+			),
151
+			'hide'           => array(
152
+				'event'    => 'mouseleave',
153
+				// similar as what you do for show.event.
154
+				'target'   => false,
155
+				// Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used.
156
+				'delay'    => 0,
157
+				// set time in milliseconds for delaying the hide of the tooltip
158
+				'inactive' => false,
159
+				// if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with)
160
+				'fixed'    => false,
161
+				// when set to true, the tooltip will not hide if moused over.
162
+				'leave'    => 'window',
163
+				// specify whether the tooltip will hide when leaving the window it's conained within.
164
+				'distance' => false,
165
+				// if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip.
166
+			),
167
+			'style'          => array(
168
+				'classes' => 'qtip-tipsy',
169
+				// Options "string", false.  A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class.
170
+				'def'     => true,
171
+				// set to false and the default qtip class does not get applied
172
+				'widget'  => false,
173
+				// whether ui-widget classes of the themeroller UI styles are applied to tooltip.
174
+				'width'   => false,
175
+				// Options: "string", integer, false.  with this you can override all applied CSS width styles for tooltip.  Can be any valid width CSS value. (does not override min/max width styles)
176
+				'height'  => false,
177
+				// same as above except applies to height.
178
+				'tip'     => array(
179
+					'corner' => true,
180
+					// where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false.  true inherits
181
+					'mimic'  => false,
182
+					// see documentation @link http://qtip2.com/plugins#tips
183
+					'border' => true,
184
+					// Options: true, integer. determines the width of the border that surrounds the tip element.  True inherits from tooltip.
185
+					'width'  => 6,
186
+					// width of rendered tip in pixels in relation to the side of the tooltip the tip is on.
187
+					'height' => 6,
188
+					// works the same as tip.width
189
+					'offset' => 0,
190
+					// use to set the offset of the tip in relation to its corner position.
191
+				),
192
+			),
193 193
 
194
-        );
195
-    }
194
+		);
195
+	}
196 196
 
197 197
 
198
-    /**
199
-     * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to
200
-     * the $_qtips property
201
-     *
202
-     * @access protected
203
-     * @return void
204
-     */
205
-    protected function _construct_tips()
206
-    {
207
-        foreach ($this->_qtipsa as $qt) {
208
-            // make sure we have what we need.
209
-            if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
210
-                throw new EE_Error(
211
-                    sprintf(
212
-                        esc_html__(
213
-                            'There is something wrong with the _qtipsa property setup for the %s qtip config class.  The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.',
214
-                            'event_espresso'
215
-                        ),
216
-                        get_class($this),
217
-                        var_export($qt, true)
218
-                    )
219
-                );
220
-            }
198
+	/**
199
+	 * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to
200
+	 * the $_qtips property
201
+	 *
202
+	 * @access protected
203
+	 * @return void
204
+	 */
205
+	protected function _construct_tips()
206
+	{
207
+		foreach ($this->_qtipsa as $qt) {
208
+			// make sure we have what we need.
209
+			if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
210
+				throw new EE_Error(
211
+					sprintf(
212
+						esc_html__(
213
+							'There is something wrong with the _qtipsa property setup for the %s qtip config class.  The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.',
214
+							'event_espresso'
215
+						),
216
+						get_class($this),
217
+						var_export($qt, true)
218
+					)
219
+				);
220
+			}
221 221
 
222
-            // make sure the options include defaults and just override via set config.
223
-            $options_override = isset($qt['options']) ? (array) $qt['options'] : array();
224
-            $options = array_merge($this->_default_options, $options_override);
225
-            $setup = array(
226
-                'content_id' => $qt['content_id'],
227
-                'options'    => $options,
228
-                'target'     => $qt['target'],
229
-                'content'    => $qt['content'],
230
-            );
231
-            $this->_qtips[] = new EE_Qtip($setup);
232
-        }
233
-    }
222
+			// make sure the options include defaults and just override via set config.
223
+			$options_override = isset($qt['options']) ? (array) $qt['options'] : array();
224
+			$options = array_merge($this->_default_options, $options_override);
225
+			$setup = array(
226
+				'content_id' => $qt['content_id'],
227
+				'options'    => $options,
228
+				'target'     => $qt['target'],
229
+				'content'    => $qt['content'],
230
+			);
231
+			$this->_qtips[] = new EE_Qtip($setup);
232
+		}
233
+	}
234 234
 
235 235
 
236
-    /**
237
-     * return the _qtips property contents
238
-     *
239
-     * @access public
240
-     * @return EE_Qtip[]
241
-     */
242
-    public function get_tips()
243
-    {
244
-        return $this->_qtips;
245
-    }
236
+	/**
237
+	 * return the _qtips property contents
238
+	 *
239
+	 * @access public
240
+	 * @return EE_Qtip[]
241
+	 */
242
+	public function get_tips()
243
+	{
244
+		return $this->_qtips;
245
+	}
246 246
 }
247 247
 
248 248
 // class names you can use for tooltip styles
@@ -294,17 +294,17 @@  discard block
 block discarded – undo
294 294
  */
295 295
 class EE_Qtip extends EE_Base
296 296
 {
297
-    public $content_id;
298
-    public $options;
299
-    public $target;
300
-    public $content;
297
+	public $content_id;
298
+	public $options;
299
+	public $target;
300
+	public $content;
301 301
 
302
-    public function __construct($setup_array)
303
-    {
304
-        foreach ($setup_array as $prop => $value) {
305
-            if (EEH_Class_Tools::has_property($this, $prop)) {
306
-                $this->{$prop} = $value;
307
-            }
308
-        }
309
-    }
302
+	public function __construct($setup_array)
303
+	{
304
+		foreach ($setup_array as $prop => $value) {
305
+			if (EEH_Class_Tools::has_property($this, $prop)) {
306
+				$this->{$prop} = $value;
307
+			}
308
+		}
309
+	}
310 310
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/db/EEME_Base.lib.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function __construct()
73 73
     {
74
-        if (! $this->_model_name_extended) {
74
+        if ( ! $this->_model_name_extended) {
75 75
             throw new EE_Error(
76 76
                 esc_html__(
77 77
                     "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
                 )
80 80
             );
81 81
         }
82
-        $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end';
82
+        $construct_end_action = 'AHEE__EEM_'.$this->_model_name_extended.'__construct__end';
83 83
         if (did_action($construct_end_action)) {
84 84
             throw new EE_Error(
85 85
                 sprintf(
@@ -94,15 +94,15 @@  discard block
 block discarded – undo
94 94
             );
95 95
         }
96 96
         add_filter(
97
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
97
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__tables',
98 98
             array($this, 'add_extra_tables_on_filter')
99 99
         );
100 100
         add_filter(
101
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
101
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__fields',
102 102
             array($this, 'add_extra_fields_on_filter')
103 103
         );
104 104
         add_filter(
105
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
105
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations',
106 106
             array($this, 'add_extra_relations_on_filter')
107 107
         );
108 108
         $this->_register_extending_methods();
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
     {
128 128
         if ($this->_extra_fields) {
129 129
             foreach ($this->_extra_fields as $table_alias => $fields) {
130
-                if (! isset($existing_fields[ $table_alias ])) {
131
-                    $existing_fields[ $table_alias ] = array();
130
+                if ( ! isset($existing_fields[$table_alias])) {
131
+                    $existing_fields[$table_alias] = array();
132 132
                 }
133
-                $existing_fields[ $table_alias ] = array_merge(
134
-                    (array) $existing_fields[ $table_alias ],
135
-                    $this->_extra_fields[ $table_alias ]
133
+                $existing_fields[$table_alias] = array_merge(
134
+                    (array) $existing_fields[$table_alias],
135
+                    $this->_extra_fields[$table_alias]
136 136
                 );
137 137
             }
138 138
         }
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
                 $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
164 164
                 add_filter(
165 165
                     $callback_name,
166
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
166
+                    array($this, self::dynamic_callback_method_prefix.$method_name_on_model),
167 167
                     10,
168 168
                     10
169 169
                 );
@@ -178,15 +178,15 @@  discard block
 block discarded – undo
178 178
     public function deregister()
179 179
     {
180 180
         remove_filter(
181
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
181
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__tables',
182 182
             array($this, 'add_extra_tables_on_filter')
183 183
         );
184 184
         remove_filter(
185
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
185
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__fields',
186 186
             array($this, 'add_extra_fields_on_filter')
187 187
         );
188 188
         remove_filter(
189
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
189
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations',
190 190
             array($this, 'add_extra_relations_on_filter')
191 191
         );
192 192
         $all_methods = get_class_methods(get_class($this));
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
                 $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
197 197
                 remove_filter(
198 198
                     $callback_name,
199
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
199
+                    array($this, self::dynamic_callback_method_prefix.$method_name_on_model),
200 200
                     10
201 201
                 );
202 202
             }
203 203
         }
204 204
         /** @var EEM_Base $model_to_reset */
205
-        $model_to_reset = 'EEM_' . $this->_model_name_extended;
205
+        $model_to_reset = 'EEM_'.$this->_model_name_extended;
206 206
         if (class_exists($model_to_reset)) {
207 207
             $model_to_reset::reset();
208 208
         }
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
             // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction
225 225
             $this->_ = $model_called;
226 226
             // phpcs:enable
227
-            $extending_method = self::extending_method_prefix . $method_called_on_model;
227
+            $extending_method = self::extending_method_prefix.$method_called_on_model;
228 228
             if (method_exists($this, $extending_method)) {
229 229
                 return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
230 230
             } else {
Please login to merge, or discard this patch.
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -43,211 +43,211 @@
 block discarded – undo
43 43
  */
44 44
 abstract class EEME_Base
45 45
 {
46
-    const extending_method_prefix = 'ext_';
47
-    const dynamic_callback_method_prefix = 'dynamic_callback_method_';
48
-
49
-    protected $_extra_tables = array();
50
-    protected $_extra_fields = array();
51
-    protected $_extra_relations = array();
52
-
53
-    /**
54
-     * The model name that is extended (not classname)
55
-     *
56
-     * @var string
57
-     */
58
-    protected $_model_name_extended = null;
59
-
60
-    /**
61
-     * The model this extends
62
-     *
63
-     * @var EEM_Base
64
-     */
65
-    protected $_ = null;
66
-
67
-
68
-    /**
69
-     * @throws \EE_Error
70
-     */
71
-    public function __construct()
72
-    {
73
-        if (! $this->_model_name_extended) {
74
-            throw new EE_Error(
75
-                esc_html__(
76
-                    "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
77
-                    "event_espresso"
78
-                )
79
-            );
80
-        }
81
-        $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end';
82
-        if (did_action($construct_end_action)) {
83
-            throw new EE_Error(
84
-                sprintf(
85
-                    esc_html__(
86
-                        "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired",
87
-                        "event_espresso"
88
-                    ),
89
-                    get_class($this),
90
-                    $this->_model_name_extended,
91
-                    $construct_end_action
92
-                )
93
-            );
94
-        }
95
-        add_filter(
96
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
97
-            array($this, 'add_extra_tables_on_filter')
98
-        );
99
-        add_filter(
100
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
101
-            array($this, 'add_extra_fields_on_filter')
102
-        );
103
-        add_filter(
104
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
105
-            array($this, 'add_extra_relations_on_filter')
106
-        );
107
-        $this->_register_extending_methods();
108
-    }
109
-
110
-
111
-    /**
112
-     * @param array $existing_tables
113
-     * @return array
114
-     */
115
-    public function add_extra_tables_on_filter($existing_tables)
116
-    {
117
-        return array_merge((array) $existing_tables, $this->_extra_tables);
118
-    }
119
-
120
-
121
-    /**
122
-     * @param array $existing_fields
123
-     * @return array
124
-     */
125
-    public function add_extra_fields_on_filter($existing_fields)
126
-    {
127
-        if ($this->_extra_fields) {
128
-            foreach ($this->_extra_fields as $table_alias => $fields) {
129
-                if (! isset($existing_fields[ $table_alias ])) {
130
-                    $existing_fields[ $table_alias ] = array();
131
-                }
132
-                $existing_fields[ $table_alias ] = array_merge(
133
-                    (array) $existing_fields[ $table_alias ],
134
-                    $this->_extra_fields[ $table_alias ]
135
-                );
136
-            }
137
-        }
138
-        return $existing_fields;
139
-    }
140
-
141
-
142
-    /**
143
-     * @param array $existing_relations
144
-     * @return array
145
-     */
146
-    public function add_extra_relations_on_filter($existing_relations)
147
-    {
148
-        return array_merge((array) $existing_relations, $this->_extra_relations);
149
-    }
150
-
151
-
152
-    /**
153
-     * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the
154
-     * model extended. (Internally uses filters, and the __call magic method)
155
-     */
156
-    protected function _register_extending_methods()
157
-    {
158
-        $all_methods = get_class_methods(get_class($this));
159
-        foreach ($all_methods as $method_name) {
160
-            if (strpos($method_name, self::extending_method_prefix) === 0) {
161
-                $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
162
-                $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
163
-                add_filter(
164
-                    $callback_name,
165
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
166
-                    10,
167
-                    10
168
-                );
169
-            }
170
-        }
171
-    }
172
-
173
-    /**
174
-     * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the
175
-     * model extended. (Internally uses filters, and the __call magic method)
176
-     */
177
-    public function deregister()
178
-    {
179
-        remove_filter(
180
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
181
-            array($this, 'add_extra_tables_on_filter')
182
-        );
183
-        remove_filter(
184
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
185
-            array($this, 'add_extra_fields_on_filter')
186
-        );
187
-        remove_filter(
188
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
189
-            array($this, 'add_extra_relations_on_filter')
190
-        );
191
-        $all_methods = get_class_methods(get_class($this));
192
-        foreach ($all_methods as $method_name) {
193
-            if (strpos($method_name, self::extending_method_prefix) === 0) {
194
-                $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
195
-                $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
196
-                remove_filter(
197
-                    $callback_name,
198
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
199
-                    10
200
-                );
201
-            }
202
-        }
203
-        /** @var EEM_Base $model_to_reset */
204
-        $model_to_reset = 'EEM_' . $this->_model_name_extended;
205
-        if (class_exists($model_to_reset)) {
206
-            $model_to_reset::reset();
207
-        }
208
-    }
209
-
210
-
211
-    /**
212
-     * @param string $callback_method_name
213
-     * @param array  $args
214
-     * @return mixed
215
-     * @throws EE_Error
216
-     */
217
-    public function __call($callback_method_name, $args)
218
-    {
219
-        if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) {
220
-            // it's a dynamic callback for a method name
221
-            $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name);
222
-            list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args;
223
-            // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction
224
-            $this->_ = $model_called;
225
-            // phpcs:enable
226
-            $extending_method = self::extending_method_prefix . $method_called_on_model;
227
-            if (method_exists($this, $extending_method)) {
228
-                return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
229
-            } else {
230
-                throw new EE_Error(
231
-                    sprintf(
232
-                        esc_html__(
233
-                            "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)",
234
-                            "event_espresso"
235
-                        ),
236
-                        $this->_model_name_extended,
237
-                        get_class($this),
238
-                        $extending_method,
239
-                        $extending_method
240
-                    )
241
-                );
242
-            }
243
-        } else {
244
-            throw new EE_Error(
245
-                sprintf(
246
-                    esc_html__("There is no method named '%s' on '%s'", "event_espresso"),
247
-                    $callback_method_name,
248
-                    get_class($this)
249
-                )
250
-            );
251
-        }
252
-    }
46
+	const extending_method_prefix = 'ext_';
47
+	const dynamic_callback_method_prefix = 'dynamic_callback_method_';
48
+
49
+	protected $_extra_tables = array();
50
+	protected $_extra_fields = array();
51
+	protected $_extra_relations = array();
52
+
53
+	/**
54
+	 * The model name that is extended (not classname)
55
+	 *
56
+	 * @var string
57
+	 */
58
+	protected $_model_name_extended = null;
59
+
60
+	/**
61
+	 * The model this extends
62
+	 *
63
+	 * @var EEM_Base
64
+	 */
65
+	protected $_ = null;
66
+
67
+
68
+	/**
69
+	 * @throws \EE_Error
70
+	 */
71
+	public function __construct()
72
+	{
73
+		if (! $this->_model_name_extended) {
74
+			throw new EE_Error(
75
+				esc_html__(
76
+					"When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
77
+					"event_espresso"
78
+				)
79
+			);
80
+		}
81
+		$construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end';
82
+		if (did_action($construct_end_action)) {
83
+			throw new EE_Error(
84
+				sprintf(
85
+					esc_html__(
86
+						"Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired",
87
+						"event_espresso"
88
+					),
89
+					get_class($this),
90
+					$this->_model_name_extended,
91
+					$construct_end_action
92
+				)
93
+			);
94
+		}
95
+		add_filter(
96
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
97
+			array($this, 'add_extra_tables_on_filter')
98
+		);
99
+		add_filter(
100
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
101
+			array($this, 'add_extra_fields_on_filter')
102
+		);
103
+		add_filter(
104
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
105
+			array($this, 'add_extra_relations_on_filter')
106
+		);
107
+		$this->_register_extending_methods();
108
+	}
109
+
110
+
111
+	/**
112
+	 * @param array $existing_tables
113
+	 * @return array
114
+	 */
115
+	public function add_extra_tables_on_filter($existing_tables)
116
+	{
117
+		return array_merge((array) $existing_tables, $this->_extra_tables);
118
+	}
119
+
120
+
121
+	/**
122
+	 * @param array $existing_fields
123
+	 * @return array
124
+	 */
125
+	public function add_extra_fields_on_filter($existing_fields)
126
+	{
127
+		if ($this->_extra_fields) {
128
+			foreach ($this->_extra_fields as $table_alias => $fields) {
129
+				if (! isset($existing_fields[ $table_alias ])) {
130
+					$existing_fields[ $table_alias ] = array();
131
+				}
132
+				$existing_fields[ $table_alias ] = array_merge(
133
+					(array) $existing_fields[ $table_alias ],
134
+					$this->_extra_fields[ $table_alias ]
135
+				);
136
+			}
137
+		}
138
+		return $existing_fields;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param array $existing_relations
144
+	 * @return array
145
+	 */
146
+	public function add_extra_relations_on_filter($existing_relations)
147
+	{
148
+		return array_merge((array) $existing_relations, $this->_extra_relations);
149
+	}
150
+
151
+
152
+	/**
153
+	 * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the
154
+	 * model extended. (Internally uses filters, and the __call magic method)
155
+	 */
156
+	protected function _register_extending_methods()
157
+	{
158
+		$all_methods = get_class_methods(get_class($this));
159
+		foreach ($all_methods as $method_name) {
160
+			if (strpos($method_name, self::extending_method_prefix) === 0) {
161
+				$method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
162
+				$callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
163
+				add_filter(
164
+					$callback_name,
165
+					array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
166
+					10,
167
+					10
168
+				);
169
+			}
170
+		}
171
+	}
172
+
173
+	/**
174
+	 * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the
175
+	 * model extended. (Internally uses filters, and the __call magic method)
176
+	 */
177
+	public function deregister()
178
+	{
179
+		remove_filter(
180
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
181
+			array($this, 'add_extra_tables_on_filter')
182
+		);
183
+		remove_filter(
184
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
185
+			array($this, 'add_extra_fields_on_filter')
186
+		);
187
+		remove_filter(
188
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
189
+			array($this, 'add_extra_relations_on_filter')
190
+		);
191
+		$all_methods = get_class_methods(get_class($this));
192
+		foreach ($all_methods as $method_name) {
193
+			if (strpos($method_name, self::extending_method_prefix) === 0) {
194
+				$method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
195
+				$callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
196
+				remove_filter(
197
+					$callback_name,
198
+					array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
199
+					10
200
+				);
201
+			}
202
+		}
203
+		/** @var EEM_Base $model_to_reset */
204
+		$model_to_reset = 'EEM_' . $this->_model_name_extended;
205
+		if (class_exists($model_to_reset)) {
206
+			$model_to_reset::reset();
207
+		}
208
+	}
209
+
210
+
211
+	/**
212
+	 * @param string $callback_method_name
213
+	 * @param array  $args
214
+	 * @return mixed
215
+	 * @throws EE_Error
216
+	 */
217
+	public function __call($callback_method_name, $args)
218
+	{
219
+		if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) {
220
+			// it's a dynamic callback for a method name
221
+			$method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name);
222
+			list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args;
223
+			// phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction
224
+			$this->_ = $model_called;
225
+			// phpcs:enable
226
+			$extending_method = self::extending_method_prefix . $method_called_on_model;
227
+			if (method_exists($this, $extending_method)) {
228
+				return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
229
+			} else {
230
+				throw new EE_Error(
231
+					sprintf(
232
+						esc_html__(
233
+							"An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)",
234
+							"event_espresso"
235
+						),
236
+						$this->_model_name_extended,
237
+						get_class($this),
238
+						$extending_method,
239
+						$extending_method
240
+					)
241
+				);
242
+			}
243
+		} else {
244
+			throw new EE_Error(
245
+				sprintf(
246
+					esc_html__("There is no method named '%s' on '%s'", "event_espresso"),
247
+					$callback_method_name,
248
+					get_class($this)
249
+				)
250
+			);
251
+		}
252
+	}
253 253
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/db/EEE_Base_Class.lib.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 
50 50
     public function __construct()
51 51
     {
52
-        if (! $this->_model_name_extended) {
52
+        if ( ! $this->_model_name_extended) {
53 53
             throw new EE_Error(
54 54
                 sprintf(
55 55
                     esc_html__(
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                 )
60 60
             );
61 61
         }
62
-        if (did_action('AHEE__EE_' . $this->_model_name_extended . '__construct__end')) {
62
+        if (did_action('AHEE__EE_'.$this->_model_name_extended.'__construct__end')) {
63 63
             throw new EE_Error(
64 64
                 sprintf(
65 65
                     esc_html__(
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
                 $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model";
88 88
                 add_filter(
89 89
                     $callback_name,
90
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
90
+                    array($this, self::dynamic_callback_method_prefix.$method_name_on_model),
91 91
                     10,
92 92
                     10
93 93
                 );
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
                 $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model";
109 109
                 remove_filter(
110 110
                     $callback_name,
111
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
111
+                    array($this, self::dynamic_callback_method_prefix.$method_name_on_model),
112 112
                     10
113 113
                 );
114 114
             }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
             $this->_ = $model_called;
128 128
             // phpcs:enable
129 129
             $args_provided_to_method_on_model = $args[2];
130
-            $extending_method = self::extending_method_prefix . $method_called_on_model;
130
+            $extending_method = self::extending_method_prefix.$method_called_on_model;
131 131
             if (method_exists($this, $extending_method)) {
132 132
                 return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
133 133
             } else {
Please login to merge, or discard this patch.
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -31,126 +31,126 @@
 block discarded – undo
31 31
  */
32 32
 class EEE_Base_Class
33 33
 {
34
-    const extending_method_prefix = 'ext_';
35
-    const dynamic_callback_method_prefix = 'dynamic_callback_method_';
36
-    /**
37
-     * The model name that is extended (not classname)
38
-     *
39
-     * @var string
40
-     */
41
-    protected $_model_name_extended = null;
42
-    /**
43
-     * The model this extends
44
-     *
45
-     * @var EE_Base_Class
46
-     */
47
-    protected $_ = null;
34
+	const extending_method_prefix = 'ext_';
35
+	const dynamic_callback_method_prefix = 'dynamic_callback_method_';
36
+	/**
37
+	 * The model name that is extended (not classname)
38
+	 *
39
+	 * @var string
40
+	 */
41
+	protected $_model_name_extended = null;
42
+	/**
43
+	 * The model this extends
44
+	 *
45
+	 * @var EE_Base_Class
46
+	 */
47
+	protected $_ = null;
48 48
 
49
-    public function __construct()
50
-    {
51
-        if (! $this->_model_name_extended) {
52
-            throw new EE_Error(
53
-                sprintf(
54
-                    esc_html__(
55
-                        "When declaring a class extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
56
-                        "event_espresso"
57
-                    )
58
-                )
59
-            );
60
-        }
61
-        if (did_action('AHEE__EE_' . $this->_model_name_extended . '__construct__end')) {
62
-            throw new EE_Error(
63
-                sprintf(
64
-                    esc_html__(
65
-                        "Hooked in model object extension '%s' too late! The model object %s has already been used!",
66
-                        "event_espresso"
67
-                    ),
68
-                    get_class($this),
69
-                    $this->_model_name_extended
70
-                )
71
-            );
72
-        }
73
-        $this->_register_extending_methods();
74
-    }
49
+	public function __construct()
50
+	{
51
+		if (! $this->_model_name_extended) {
52
+			throw new EE_Error(
53
+				sprintf(
54
+					esc_html__(
55
+						"When declaring a class extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
56
+						"event_espresso"
57
+					)
58
+				)
59
+			);
60
+		}
61
+		if (did_action('AHEE__EE_' . $this->_model_name_extended . '__construct__end')) {
62
+			throw new EE_Error(
63
+				sprintf(
64
+					esc_html__(
65
+						"Hooked in model object extension '%s' too late! The model object %s has already been used!",
66
+						"event_espresso"
67
+					),
68
+					get_class($this),
69
+					$this->_model_name_extended
70
+				)
71
+			);
72
+		}
73
+		$this->_register_extending_methods();
74
+	}
75 75
 
76
-    /**
77
-     * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the
78
-     * model extended. (Internally uses filters, and the __call magic method)
79
-     */
80
-    protected function _register_extending_methods()
81
-    {
82
-        $all_methods = get_class_methods(get_class($this));
83
-        foreach ($all_methods as $method_name) {
84
-            if (strpos($method_name, self::extending_method_prefix) === 0) {
85
-                $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
86
-                $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model";
87
-                add_filter(
88
-                    $callback_name,
89
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
90
-                    10,
91
-                    10
92
-                );
93
-            }
94
-        }
95
-    }
76
+	/**
77
+	 * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the
78
+	 * model extended. (Internally uses filters, and the __call magic method)
79
+	 */
80
+	protected function _register_extending_methods()
81
+	{
82
+		$all_methods = get_class_methods(get_class($this));
83
+		foreach ($all_methods as $method_name) {
84
+			if (strpos($method_name, self::extending_method_prefix) === 0) {
85
+				$method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
86
+				$callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model";
87
+				add_filter(
88
+					$callback_name,
89
+					array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
90
+					10,
91
+					10
92
+				);
93
+			}
94
+		}
95
+	}
96 96
 
97
-    /**
98
-     * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the
99
-     * model extended. (Internally uses filters, and the __call magic method)
100
-     */
101
-    public function deregister()
102
-    {
103
-        $all_methods = get_class_methods(get_class($this));
104
-        foreach ($all_methods as $method_name) {
105
-            if (strpos($method_name, self::extending_method_prefix) === 0) {
106
-                $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
107
-                $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model";
108
-                remove_filter(
109
-                    $callback_name,
110
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
111
-                    10
112
-                );
113
-            }
114
-        }
115
-    }
97
+	/**
98
+	 * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the
99
+	 * model extended. (Internally uses filters, and the __call magic method)
100
+	 */
101
+	public function deregister()
102
+	{
103
+		$all_methods = get_class_methods(get_class($this));
104
+		foreach ($all_methods as $method_name) {
105
+			if (strpos($method_name, self::extending_method_prefix) === 0) {
106
+				$method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
107
+				$callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model";
108
+				remove_filter(
109
+					$callback_name,
110
+					array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
111
+					10
112
+				);
113
+			}
114
+		}
115
+	}
116 116
 
117 117
 
118
-    public function __call($callback_method_name, $args)
119
-    {
120
-        if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) {
121
-            // it's a dynamic callback for a method name
122
-            $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name);
123
-            $original_return_val = $args[0];
124
-            $model_called = $args[1];
125
-            // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction
126
-            $this->_ = $model_called;
127
-            // phpcs:enable
128
-            $args_provided_to_method_on_model = $args[2];
129
-            $extending_method = self::extending_method_prefix . $method_called_on_model;
130
-            if (method_exists($this, $extending_method)) {
131
-                return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
132
-            } else {
133
-                throw new EE_Error(
134
-                    sprintf(
135
-                        esc_html__(
136
-                            "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)",
137
-                            "event_espresso"
138
-                        ),
139
-                        $this->_model_name_extended,
140
-                        get_class($this),
141
-                        $extending_method,
142
-                        $extending_method
143
-                    )
144
-                );
145
-            }
146
-        } else {
147
-            throw new EE_Error(
148
-                sprintf(
149
-                    esc_html__("There is no method named '%s' on '%s'", "event_espresso"),
150
-                    $callback_method_name,
151
-                    get_class($this)
152
-                )
153
-            );
154
-        }
155
-    }
118
+	public function __call($callback_method_name, $args)
119
+	{
120
+		if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) {
121
+			// it's a dynamic callback for a method name
122
+			$method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name);
123
+			$original_return_val = $args[0];
124
+			$model_called = $args[1];
125
+			// phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction
126
+			$this->_ = $model_called;
127
+			// phpcs:enable
128
+			$args_provided_to_method_on_model = $args[2];
129
+			$extending_method = self::extending_method_prefix . $method_called_on_model;
130
+			if (method_exists($this, $extending_method)) {
131
+				return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
132
+			} else {
133
+				throw new EE_Error(
134
+					sprintf(
135
+						esc_html__(
136
+							"An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)",
137
+							"event_espresso"
138
+						),
139
+						$this->_model_name_extended,
140
+						get_class($this),
141
+						$extending_method,
142
+						$extending_method
143
+					)
144
+				);
145
+			}
146
+		} else {
147
+			throw new EE_Error(
148
+				sprintf(
149
+					esc_html__("There is no method named '%s' on '%s'", "event_espresso"),
150
+					$callback_method_name,
151
+					get_class($this)
152
+				)
153
+			);
154
+		}
155
+	}
156 156
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Ticket_Shortcodes.lib.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -47,20 +47,20 @@  discard block
 block discarded – undo
47 47
             '[TKT_USES_*]'              => esc_html__(
48 48
                 'This attribute based shortcode parses to show the number of uses the ticket has.  The optional "schema" attribute can be used to indicate what schema is used when the uses is infinite.  Options are:',
49 49
                 'event_espresso'
50
-            ) .
51
-                                           '<p><ul>' .
52
-                                           '<li><strong>symbol</strong>:' . esc_html__(
50
+            ).
51
+                                           '<p><ul>'.
52
+                                           '<li><strong>symbol</strong>:'.esc_html__(
53 53
                                                'This returns the &infin; symbol.',
54 54
                                                'event_espresso'
55
-                                           ) . '</li>' .
56
-                                           '<li><strong>text</strong>:' . esc_html__(
55
+                                           ).'</li>'.
56
+                                           '<li><strong>text</strong>:'.esc_html__(
57 57
                                                'This returns the word, "Unlimited". This is also the default if the "schema" attribute is not used.',
58 58
                                                'event_espresso'
59
-                                           ) . '</li>' .
60
-                                           '<li><strong>{custom}</strong>:' . esc_html__(
59
+                                           ).'</li>'.
60
+                                           '<li><strong>{custom}</strong>:'.esc_html__(
61 61
                                                'You can put anything you want as a string instead and that will be used.  So you could have the world "any" and whenever uses for a ticket is infinity, this shortcode will parse to "any".',
62 62
                                                'event_espresso'
63
-                                           ) . '</li>' .
63
+                                           ).'</li>'.
64 64
                                            '</ul></p>',
65 65
         );
66 66
     }
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
         $this->_ticket = empty($this->_ticket)
83 83
                          && $this->_data instanceof EE_Line_Item
84 84
                          && $aee instanceof EE_Messages_Addressee
85
-                         && ! empty($aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'])
86
-                         && $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] instanceof EE_Ticket
87
-            ? $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket']
85
+                         && ! empty($aee->line_items_with_children[$this->_data->ID()]['EE_Ticket'])
86
+                         && $aee->line_items_with_children[$this->_data->ID()]['EE_Ticket'] instanceof EE_Ticket
87
+            ? $aee->line_items_with_children[$this->_data->ID()]['EE_Ticket']
88 88
             : $this->_ticket;
89 89
 
90 90
         // if still no ticket, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the ticket from the reg_obj instead.
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 
96 96
 
97 97
         // If there is no event object by now then get out.
98
-        if (! $this->_ticket instanceof EE_Ticket) {
98
+        if ( ! $this->_ticket instanceof EE_Ticket) {
99 99
             return '';
100 100
         }
101 101
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                 break;
122 122
 
123 123
             case '[TKT_QTY_PURCHASED]':
124
-                return $aee instanceof EE_Messages_Addressee ? $aee->tickets[ $this->_ticket->ID() ]['count'] : '';
124
+                return $aee instanceof EE_Messages_Addressee ? $aee->tickets[$this->_ticket->ID()]['count'] : '';
125 125
                 break;
126 126
         }
127 127
 
Please login to merge, or discard this patch.
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -17,123 +17,123 @@
 block discarded – undo
17 17
  */
18 18
 class EE_Ticket_Shortcodes extends EE_Shortcodes
19 19
 {
20
-    /**
21
-     * Will hold the EE_Ticket if available
22
-     *
23
-     * @var EE_Ticket
24
-     */
25
-    protected $_ticket;
26
-
27
-
28
-    protected function _init_props()
29
-    {
30
-        $this->label = esc_html__('Ticket Shortcodes', 'event_espresso');
31
-        $this->description = esc_html__('All shortcodes specific to ticket related data', 'event_espresso');
32
-        $this->_shortcodes = array(
33
-            '[TICKET_ID]'               => esc_html__('Will be replaced by the ticket ID of a ticket', 'event_espresso'),
34
-            '[TICKET_NAME]'             => esc_html__('The name of the ticket', 'event_espresso'),
35
-            '[TICKET_DESCRIPTION]'      => esc_html__('The description of the ticket', 'event_espresso'),
36
-            '[TICKET_PRICE]'            => esc_html__('The price of the ticket', 'event_espresso'),
37
-            '[TICKET_PRICE_WITH_TAXES]' => esc_html__(
38
-                'The price of the ticket including any taxes that might be on the ticket',
39
-                'event_espresso'
40
-            ),
41
-            '[TKT_QTY_PURCHASED]'       => esc_html__(
42
-                'The total quantity of the current ticket in the list that has been purchased in this transaction',
43
-                'event_espresso'
44
-            ),
45
-            '[TKT_USES_*]'              => esc_html__(
46
-                'This attribute based shortcode parses to show the number of uses the ticket has.  The optional "schema" attribute can be used to indicate what schema is used when the uses is infinite.  Options are:',
47
-                'event_espresso'
48
-            ) .
49
-                                           '<p><ul>' .
50
-                                           '<li><strong>symbol</strong>:' . esc_html__(
51
-                                               'This returns the &infin; symbol.',
52
-                                               'event_espresso'
53
-                                           ) . '</li>' .
54
-                                           '<li><strong>text</strong>:' . esc_html__(
55
-                                               'This returns the word, "Unlimited". This is also the default if the "schema" attribute is not used.',
56
-                                               'event_espresso'
57
-                                           ) . '</li>' .
58
-                                           '<li><strong>{custom}</strong>:' . esc_html__(
59
-                                               'You can put anything you want as a string instead and that will be used.  So you could have the world "any" and whenever uses for a ticket is infinity, this shortcode will parse to "any".',
60
-                                               'event_espresso'
61
-                                           ) . '</li>' .
62
-                                           '</ul></p>',
63
-        );
64
-    }
65
-
66
-
67
-    protected function _parser($shortcode)
68
-    {
69
-
70
-        $this->_ticket = $this->_data instanceof EE_Ticket ? $this->_data : null;
71
-
72
-        $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
73
-        $aee = ! $aee instanceof EE_Messages_Addressee && is_array(
74
-            $this->_extra_data
75
-        ) && isset($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
76
-            ? $this->_extra_data['data'] : $aee;
77
-
78
-
79
-        // possible EE_Line_Item may be incoming data
80
-        $this->_ticket = empty($this->_ticket)
81
-                         && $this->_data instanceof EE_Line_Item
82
-                         && $aee instanceof EE_Messages_Addressee
83
-                         && ! empty($aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'])
84
-                         && $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] instanceof EE_Ticket
85
-            ? $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket']
86
-            : $this->_ticket;
87
-
88
-        // if still no ticket, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the ticket from the reg_obj instead.
89
-        if (empty($this->_ticket)) {
90
-            $this->_ticket = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
91
-                ? $aee->reg_obj->ticket() : null;
92
-        }
93
-
94
-
95
-        // If there is no event object by now then get out.
96
-        if (! $this->_ticket instanceof EE_Ticket) {
97
-            return '';
98
-        }
99
-
100
-        switch ($shortcode) {
101
-            case '[TICKET_ID]':
102
-                return $this->_ticket->ID();
103
-                break;
104
-
105
-            case '[TICKET_NAME]':
106
-                return $this->_ticket->get('TKT_name');
107
-                break;
108
-
109
-            case '[TICKET_DESCRIPTION]':
110
-                return $this->_ticket->get('TKT_description');
111
-                break;
112
-
113
-            case '[TICKET_PRICE]':
114
-                return EEH_Template::format_currency($this->_ticket->get('TKT_price'));
115
-                break;
116
-
117
-            case '[TICKET_PRICE_WITH_TAXES]':
118
-                return EEH_Template::format_currency($this->_ticket->get_ticket_total_with_taxes());
119
-                break;
120
-
121
-            case '[TKT_QTY_PURCHASED]':
122
-                return $aee instanceof EE_Messages_Addressee ? $aee->tickets[ $this->_ticket->ID() ]['count'] : '';
123
-                break;
124
-        }
125
-
126
-        if (strpos($shortcode, '[TKT_USES_*') !== false) {
127
-            $attrs = $this->_get_shortcode_attrs($shortcode);
128
-            $schema = empty($attrs['schema']) ? null : $attrs['schema'];
129
-            return $this->_ticket->get_pretty('TKT_uses', $schema);
130
-        }
131
-        return '';
132
-    }
133
-
134
-
135
-    public function get_ticket_set()
136
-    {
137
-        return $this->_ticket;
138
-    }
20
+	/**
21
+	 * Will hold the EE_Ticket if available
22
+	 *
23
+	 * @var EE_Ticket
24
+	 */
25
+	protected $_ticket;
26
+
27
+
28
+	protected function _init_props()
29
+	{
30
+		$this->label = esc_html__('Ticket Shortcodes', 'event_espresso');
31
+		$this->description = esc_html__('All shortcodes specific to ticket related data', 'event_espresso');
32
+		$this->_shortcodes = array(
33
+			'[TICKET_ID]'               => esc_html__('Will be replaced by the ticket ID of a ticket', 'event_espresso'),
34
+			'[TICKET_NAME]'             => esc_html__('The name of the ticket', 'event_espresso'),
35
+			'[TICKET_DESCRIPTION]'      => esc_html__('The description of the ticket', 'event_espresso'),
36
+			'[TICKET_PRICE]'            => esc_html__('The price of the ticket', 'event_espresso'),
37
+			'[TICKET_PRICE_WITH_TAXES]' => esc_html__(
38
+				'The price of the ticket including any taxes that might be on the ticket',
39
+				'event_espresso'
40
+			),
41
+			'[TKT_QTY_PURCHASED]'       => esc_html__(
42
+				'The total quantity of the current ticket in the list that has been purchased in this transaction',
43
+				'event_espresso'
44
+			),
45
+			'[TKT_USES_*]'              => esc_html__(
46
+				'This attribute based shortcode parses to show the number of uses the ticket has.  The optional "schema" attribute can be used to indicate what schema is used when the uses is infinite.  Options are:',
47
+				'event_espresso'
48
+			) .
49
+										   '<p><ul>' .
50
+										   '<li><strong>symbol</strong>:' . esc_html__(
51
+											   'This returns the &infin; symbol.',
52
+											   'event_espresso'
53
+										   ) . '</li>' .
54
+										   '<li><strong>text</strong>:' . esc_html__(
55
+											   'This returns the word, "Unlimited". This is also the default if the "schema" attribute is not used.',
56
+											   'event_espresso'
57
+										   ) . '</li>' .
58
+										   '<li><strong>{custom}</strong>:' . esc_html__(
59
+											   'You can put anything you want as a string instead and that will be used.  So you could have the world "any" and whenever uses for a ticket is infinity, this shortcode will parse to "any".',
60
+											   'event_espresso'
61
+										   ) . '</li>' .
62
+										   '</ul></p>',
63
+		);
64
+	}
65
+
66
+
67
+	protected function _parser($shortcode)
68
+	{
69
+
70
+		$this->_ticket = $this->_data instanceof EE_Ticket ? $this->_data : null;
71
+
72
+		$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
73
+		$aee = ! $aee instanceof EE_Messages_Addressee && is_array(
74
+			$this->_extra_data
75
+		) && isset($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
76
+			? $this->_extra_data['data'] : $aee;
77
+
78
+
79
+		// possible EE_Line_Item may be incoming data
80
+		$this->_ticket = empty($this->_ticket)
81
+						 && $this->_data instanceof EE_Line_Item
82
+						 && $aee instanceof EE_Messages_Addressee
83
+						 && ! empty($aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'])
84
+						 && $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] instanceof EE_Ticket
85
+			? $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket']
86
+			: $this->_ticket;
87
+
88
+		// if still no ticket, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the ticket from the reg_obj instead.
89
+		if (empty($this->_ticket)) {
90
+			$this->_ticket = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
91
+				? $aee->reg_obj->ticket() : null;
92
+		}
93
+
94
+
95
+		// If there is no event object by now then get out.
96
+		if (! $this->_ticket instanceof EE_Ticket) {
97
+			return '';
98
+		}
99
+
100
+		switch ($shortcode) {
101
+			case '[TICKET_ID]':
102
+				return $this->_ticket->ID();
103
+				break;
104
+
105
+			case '[TICKET_NAME]':
106
+				return $this->_ticket->get('TKT_name');
107
+				break;
108
+
109
+			case '[TICKET_DESCRIPTION]':
110
+				return $this->_ticket->get('TKT_description');
111
+				break;
112
+
113
+			case '[TICKET_PRICE]':
114
+				return EEH_Template::format_currency($this->_ticket->get('TKT_price'));
115
+				break;
116
+
117
+			case '[TICKET_PRICE_WITH_TAXES]':
118
+				return EEH_Template::format_currency($this->_ticket->get_ticket_total_with_taxes());
119
+				break;
120
+
121
+			case '[TKT_QTY_PURCHASED]':
122
+				return $aee instanceof EE_Messages_Addressee ? $aee->tickets[ $this->_ticket->ID() ]['count'] : '';
123
+				break;
124
+		}
125
+
126
+		if (strpos($shortcode, '[TKT_USES_*') !== false) {
127
+			$attrs = $this->_get_shortcode_attrs($shortcode);
128
+			$schema = empty($attrs['schema']) ? null : $attrs['schema'];
129
+			return $this->_ticket->get_pretty('TKT_uses', $schema);
130
+		}
131
+		return '';
132
+	}
133
+
134
+
135
+	public function get_ticket_set()
136
+	{
137
+		return $this->_ticket;
138
+	}
139 139
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Payment_List_Shortcodes.lib.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,15 +29,15 @@  discard block
 block discarded – undo
29 29
                 'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:',
30 30
                 'event_espresso'
31 31
             )
32
-                                  . '<p><ul>' .
33
-                                  '<li><strong>no_payments</strong>:' . sprintf(
32
+                                  . '<p><ul>'.
33
+                                  '<li><strong>no_payments</strong>:'.sprintf(
34 34
                                       esc_html__(
35 35
                                           'Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"',
36 36
                                           'event_espresso'
37 37
                                       ),
38 38
                                       htmlspecialchars('<td class="aln-cntr" colspan="6">'),
39 39
                                       htmlspecialchars('</td>')
40
-                                  ) . '</li>' .
40
+                                  ).'</li>'.
41 41
                                   '</ul></p>',
42 42
         );
43 43
     }
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         $this->_validate_list_requirements();
68 68
 
69 69
 
70
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
70
+        if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) {
71 71
             return '';
72 72
         }
73 73
 
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -18,88 +18,88 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Payment_List_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    protected function _init_props()
22
-    {
23
-        $this->label = esc_html__('Payment List Shortcodes', 'event_espresso');
24
-        $this->description = esc_html__('All shortcodes specific to payment lists', 'event_espresso');
25
-        $this->_shortcodes = array(
26
-            '[PAYMENT_LIST_*]' => esc_html__(
27
-                'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:',
28
-                'event_espresso'
29
-            )
30
-                                  . '<p><ul>' .
31
-                                  '<li><strong>no_payments</strong>:' . sprintf(
32
-                                      esc_html__(
33
-                                          'Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"',
34
-                                          'event_espresso'
35
-                                      ),
36
-                                      htmlspecialchars('<td class="aln-cntr" colspan="6">'),
37
-                                      htmlspecialchars('</td>')
38
-                                  ) . '</li>' .
39
-                                  '</ul></p>',
40
-        );
41
-    }
42
-
43
-
44
-    protected function _parser($shortcode)
45
-    {
46
-
47
-        if (strpos($shortcode, '[PAYMENT_LIST_*') !== false) {
48
-            return $this->_get_payment_list($shortcode);
49
-        }
50
-        return '';
51
-    }
52
-
53
-
54
-    /**
55
-     * verify incoming data contains what is needed for retrieving and parsing each payment for transaction.
56
-     *
57
-     * @since 4.5.0
58
-     *
59
-     * @param string $shortcode The incoming shortcode.
60
-     *
61
-     * @return string parsed ticket line item list.
62
-     */
63
-    private function _get_payment_list($shortcode)
64
-    {
65
-        $this->_validate_list_requirements();
66
-
67
-
68
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
69
-            return '';
70
-        }
71
-
72
-        $valid_shortcodes = array('payment');
73
-
74
-        $addressee_obj = $this->_data['data'];
75
-        $templates = $this->_extra_data['template'];
76
-        $payments = apply_filters(
77
-            'FHEE__Payment_List_Shortcodes___get_payments_list__payments',
78
-            $addressee_obj->payments
79
-        );
80
-
81
-        // let's get any attributes that may be present and set the defaults.
82
-        $atts = $this->_get_shortcode_attrs($shortcode);
83
-
84
-        $no_payments_msg = empty($atts['no_payments']) ? esc_html__(
85
-            'No approved payments have been received.',
86
-            'event_espresso'
87
-        ) : $atts['no_payments'];
88
-
89
-        // made it here so we have an array of paymnets, so we should have what we need.
90
-        $payment_content = empty($payments) ? $no_payments_msg : '';
91
-
92
-        $payments = (array) $payments;
93
-
94
-        foreach ($payments as $payment) {
95
-            $payment_content .= $this->_shortcode_helper->parse_payment_list_template(
96
-                $templates['payment_list'],
97
-                $payment,
98
-                $valid_shortcodes,
99
-                $this->_extra_data
100
-            );
101
-        }
102
-
103
-        return $payment_content;
104
-    }
21
+	protected function _init_props()
22
+	{
23
+		$this->label = esc_html__('Payment List Shortcodes', 'event_espresso');
24
+		$this->description = esc_html__('All shortcodes specific to payment lists', 'event_espresso');
25
+		$this->_shortcodes = array(
26
+			'[PAYMENT_LIST_*]' => esc_html__(
27
+				'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:',
28
+				'event_espresso'
29
+			)
30
+								  . '<p><ul>' .
31
+								  '<li><strong>no_payments</strong>:' . sprintf(
32
+									  esc_html__(
33
+										  'Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"',
34
+										  'event_espresso'
35
+									  ),
36
+									  htmlspecialchars('<td class="aln-cntr" colspan="6">'),
37
+									  htmlspecialchars('</td>')
38
+								  ) . '</li>' .
39
+								  '</ul></p>',
40
+		);
41
+	}
42
+
43
+
44
+	protected function _parser($shortcode)
45
+	{
46
+
47
+		if (strpos($shortcode, '[PAYMENT_LIST_*') !== false) {
48
+			return $this->_get_payment_list($shortcode);
49
+		}
50
+		return '';
51
+	}
52
+
53
+
54
+	/**
55
+	 * verify incoming data contains what is needed for retrieving and parsing each payment for transaction.
56
+	 *
57
+	 * @since 4.5.0
58
+	 *
59
+	 * @param string $shortcode The incoming shortcode.
60
+	 *
61
+	 * @return string parsed ticket line item list.
62
+	 */
63
+	private function _get_payment_list($shortcode)
64
+	{
65
+		$this->_validate_list_requirements();
66
+
67
+
68
+		if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
69
+			return '';
70
+		}
71
+
72
+		$valid_shortcodes = array('payment');
73
+
74
+		$addressee_obj = $this->_data['data'];
75
+		$templates = $this->_extra_data['template'];
76
+		$payments = apply_filters(
77
+			'FHEE__Payment_List_Shortcodes___get_payments_list__payments',
78
+			$addressee_obj->payments
79
+		);
80
+
81
+		// let's get any attributes that may be present and set the defaults.
82
+		$atts = $this->_get_shortcode_attrs($shortcode);
83
+
84
+		$no_payments_msg = empty($atts['no_payments']) ? esc_html__(
85
+			'No approved payments have been received.',
86
+			'event_espresso'
87
+		) : $atts['no_payments'];
88
+
89
+		// made it here so we have an array of paymnets, so we should have what we need.
90
+		$payment_content = empty($payments) ? $no_payments_msg : '';
91
+
92
+		$payments = (array) $payments;
93
+
94
+		foreach ($payments as $payment) {
95
+			$payment_content .= $this->_shortcode_helper->parse_payment_list_template(
96
+				$templates['payment_list'],
97
+				$payment,
98
+				$valid_shortcodes,
99
+				$this->_extra_data
100
+			);
101
+		}
102
+
103
+		return $payment_content;
104
+	}
105 105
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Messenger_Shortcodes.lib.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         $action = $request->getRequestParam('action');
62 62
         // show error message about buttons/urls not working as expected if messenger deactivated.
63 63
         if ($action === 'update_message_template' && is_admin()) {
64
-            if (! isset($this->_active_messengers['pdf'])) {
64
+            if ( ! isset($this->_active_messengers['pdf'])) {
65 65
                 EE_Error::add_attention(
66 66
                     esc_html__(
67 67
                         'Be aware that the pdf messenger is inactive.  This means that any pdf related shortcodes will parse to an empty string.',
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
                 );
71 71
             }
72 72
 
73
-            if (! isset($this->_active_messengers['html'])) {
73
+            if ( ! isset($this->_active_messengers['html'])) {
74 74
                 EE_Error::add_attention(
75 75
                     esc_html__(
76 76
                         'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.',
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         $recipient = ! $recipient instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
94 94
             ? $this->_extra_data['data'] : $recipient;
95 95
 
96
-        if (! $recipient instanceof EE_Messages_Addressee) {
96
+        if ( ! $recipient instanceof EE_Messages_Addressee) {
97 97
             return '';
98 98
         }
99 99
 
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
                 'event_espresso'
133 133
             );
134 134
         $content = '
135
-<form method="post" action="' . $this->_get_url($recipient, $sending_messenger) . '" >
136
-	<input class="print_button" type="submit" value="' . $download_text . '" />
135
+<form method="post" action="' . $this->_get_url($recipient, $sending_messenger).'" >
136
+	<input class="print_button" type="submit" value="' . $download_text.'" />
137 137
 </form>
138 138
 		';
139 139
         return $content;
Please login to merge, or discard this patch.
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -22,157 +22,157 @@
 block discarded – undo
22 22
  */
23 23
 class EE_Messenger_Shortcodes extends EE_Shortcodes
24 24
 {
25
-    /**
26
-     * Hold array of active messengers indexed by messenger name.
27
-     *
28
-     * @since 4.5.0
29
-     *
30
-     * @var EE_messenger[]
31
-     */
32
-    protected $_active_messengers = array();
33
-
34
-
35
-    protected function _init_props()
36
-    {
37
-        $this->label = esc_html__('Messenger Shortcodes', 'event_espresso');
38
-        $this->description = esc_html__('All shortcodes that are messenger specific.', 'event_espresso');
39
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
40
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
41
-        // add messages about what happens  when the messenger is active.
42
-        $this->_active_messengers = $message_resource_manager->active_messengers();
43
-
44
-        $this->_shortcodes['[DISPLAY_HTML_URL]'] = esc_html__(
45
-            'This will return a link to view the template in a browser if the html messenger is active.',
46
-            'event_espresso'
47
-        );
48
-        $this->_shortcodes['[DISPLAY_PDF_URL]'] = esc_html__(
49
-            'This will return a link to generate a pdf for the template if the pdf messenger is active.',
50
-            'event_espresso'
51
-        );
52
-        $this->_shortcodes['[DISPLAY_PDF_BUTTON]'] = esc_html__(
53
-            'This will return html for a download pdf button trigger if the pdf messenger is active.',
54
-            'event_espresso'
55
-        );
56
-
57
-        /** @var RequestInterface $request */
58
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
59
-        $action = $request->getRequestParam('action');
60
-        // show error message about buttons/urls not working as expected if messenger deactivated.
61
-        if ($action === 'update_message_template' && is_admin()) {
62
-            if (! isset($this->_active_messengers['pdf'])) {
63
-                EE_Error::add_attention(
64
-                    esc_html__(
65
-                        'Be aware that the pdf messenger is inactive.  This means that any pdf related shortcodes will parse to an empty string.',
66
-                        'event_espresso'
67
-                    )
68
-                );
69
-            }
70
-
71
-            if (! isset($this->_active_messengers['html'])) {
72
-                EE_Error::add_attention(
73
-                    esc_html__(
74
-                        'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.',
75
-                        'event_espresso'
76
-                    )
77
-                );
78
-            }
79
-        }
80
-    }
81
-
82
-
83
-    protected function _parser($shortcode)
84
-    {
85
-        // make sure we end up with a copy of the EE_Messages_Addressee object
86
-        $recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
87
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && is_array(
88
-            $this->_data
89
-        ) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data']
90
-            : $recipient;
91
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
92
-            ? $this->_extra_data['data'] : $recipient;
93
-
94
-        if (! $recipient instanceof EE_Messages_Addressee) {
95
-            return '';
96
-        }
97
-
98
-        switch ($shortcode) {
99
-            case '[DISPLAY_HTML_URL]':
100
-                return isset($this->_active_messengers['html']) ? $this->_get_url($recipient, 'html') : '';
101
-                break;
102
-            case '[DISPLAY_PDF_URL]':
103
-                return isset($this->_active_messengers['pdf']) ? $this->_get_url($recipient, 'pdf') : '';
104
-                break;
105
-            case '[DISPLAY_PDF_BUTTON]':
106
-                return isset($this->_active_messengers['pdf']) ? $this->_get_button($recipient, 'pdf') : '';
107
-                break;
108
-        }
109
-        return '';
110
-    }
111
-
112
-
113
-    /**
114
-     * This method takes the incoming data and figures out from it what the message type is and evt_id/grp_id and uses
115
-     * that to generate the html for a button in the template.
116
-     *
117
-     * @since 4.5.0
118
-     *
119
-     * @param EE_Messages_Addressee $recipient
120
-     * @param string                $sending_messenger 'html' or 'pdf'
121
-     *
122
-     * @return string                Generated html
123
-     */
124
-    private function _get_button(EE_Messages_Addressee $recipient, $sending_messenger)
125
-    {
126
-        $download_text = $sending_messenger == 'pdf'
127
-            ? esc_html__('Download PDF', 'event_espresso')
128
-            : esc_html__(
129
-                'Show HTML',
130
-                'event_espresso'
131
-            );
132
-        $content = '
25
+	/**
26
+	 * Hold array of active messengers indexed by messenger name.
27
+	 *
28
+	 * @since 4.5.0
29
+	 *
30
+	 * @var EE_messenger[]
31
+	 */
32
+	protected $_active_messengers = array();
33
+
34
+
35
+	protected function _init_props()
36
+	{
37
+		$this->label = esc_html__('Messenger Shortcodes', 'event_espresso');
38
+		$this->description = esc_html__('All shortcodes that are messenger specific.', 'event_espresso');
39
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
40
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
41
+		// add messages about what happens  when the messenger is active.
42
+		$this->_active_messengers = $message_resource_manager->active_messengers();
43
+
44
+		$this->_shortcodes['[DISPLAY_HTML_URL]'] = esc_html__(
45
+			'This will return a link to view the template in a browser if the html messenger is active.',
46
+			'event_espresso'
47
+		);
48
+		$this->_shortcodes['[DISPLAY_PDF_URL]'] = esc_html__(
49
+			'This will return a link to generate a pdf for the template if the pdf messenger is active.',
50
+			'event_espresso'
51
+		);
52
+		$this->_shortcodes['[DISPLAY_PDF_BUTTON]'] = esc_html__(
53
+			'This will return html for a download pdf button trigger if the pdf messenger is active.',
54
+			'event_espresso'
55
+		);
56
+
57
+		/** @var RequestInterface $request */
58
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
59
+		$action = $request->getRequestParam('action');
60
+		// show error message about buttons/urls not working as expected if messenger deactivated.
61
+		if ($action === 'update_message_template' && is_admin()) {
62
+			if (! isset($this->_active_messengers['pdf'])) {
63
+				EE_Error::add_attention(
64
+					esc_html__(
65
+						'Be aware that the pdf messenger is inactive.  This means that any pdf related shortcodes will parse to an empty string.',
66
+						'event_espresso'
67
+					)
68
+				);
69
+			}
70
+
71
+			if (! isset($this->_active_messengers['html'])) {
72
+				EE_Error::add_attention(
73
+					esc_html__(
74
+						'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.',
75
+						'event_espresso'
76
+					)
77
+				);
78
+			}
79
+		}
80
+	}
81
+
82
+
83
+	protected function _parser($shortcode)
84
+	{
85
+		// make sure we end up with a copy of the EE_Messages_Addressee object
86
+		$recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
87
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && is_array(
88
+			$this->_data
89
+		) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data']
90
+			: $recipient;
91
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
92
+			? $this->_extra_data['data'] : $recipient;
93
+
94
+		if (! $recipient instanceof EE_Messages_Addressee) {
95
+			return '';
96
+		}
97
+
98
+		switch ($shortcode) {
99
+			case '[DISPLAY_HTML_URL]':
100
+				return isset($this->_active_messengers['html']) ? $this->_get_url($recipient, 'html') : '';
101
+				break;
102
+			case '[DISPLAY_PDF_URL]':
103
+				return isset($this->_active_messengers['pdf']) ? $this->_get_url($recipient, 'pdf') : '';
104
+				break;
105
+			case '[DISPLAY_PDF_BUTTON]':
106
+				return isset($this->_active_messengers['pdf']) ? $this->_get_button($recipient, 'pdf') : '';
107
+				break;
108
+		}
109
+		return '';
110
+	}
111
+
112
+
113
+	/**
114
+	 * This method takes the incoming data and figures out from it what the message type is and evt_id/grp_id and uses
115
+	 * that to generate the html for a button in the template.
116
+	 *
117
+	 * @since 4.5.0
118
+	 *
119
+	 * @param EE_Messages_Addressee $recipient
120
+	 * @param string                $sending_messenger 'html' or 'pdf'
121
+	 *
122
+	 * @return string                Generated html
123
+	 */
124
+	private function _get_button(EE_Messages_Addressee $recipient, $sending_messenger)
125
+	{
126
+		$download_text = $sending_messenger == 'pdf'
127
+			? esc_html__('Download PDF', 'event_espresso')
128
+			: esc_html__(
129
+				'Show HTML',
130
+				'event_espresso'
131
+			);
132
+		$content = '
133 133
 <form method="post" action="' . $this->_get_url($recipient, $sending_messenger) . '" >
134 134
 	<input class="print_button" type="submit" value="' . $download_text . '" />
135 135
 </form>
136 136
 		';
137
-        return $content;
138
-    }
139
-
140
-
141
-    /**
142
-     * This method takes the incoming data and figures out from it what the message type is and
143
-     * evt_id/grp_id and uses that to generate the url for displaying the template in a browser.
144
-     *
145
-     * @since 4.5.0
146
-     *
147
-     * @param EE_Messages_Addressee $recipient
148
-     * @param string                $sending_messenger
149
-     *
150
-     * @return string The generated url for displaying the link.
151
-     * @throws EE_Error
152
-     */
153
-    private function _get_url(EE_Messages_Addressee $recipient, $sending_messenger)
154
-    {
155
-
156
-        $reg = $recipient->reg_obj;
157
-        $reg = ! $reg instanceof EE_Registration ? $recipient->primary_reg_obj : $reg;
158
-
159
-
160
-        if ($this->_message_type instanceof EE_message_type && $this->_message instanceof EE_Message) {
161
-            EE_Registry::instance()->load_helper('MSG_Template');
162
-            try {
163
-                return EEH_MSG_Template::get_url_trigger(
164
-                    $this->_message_type,
165
-                    $this->_message,
166
-                    $reg,
167
-                    $sending_messenger
168
-                );
169
-            } catch (EE_Error $e) {
170
-                if (WP_DEBUG) {
171
-                    $e->get_error();
172
-                }
173
-            }
174
-        }
175
-
176
-        return '';
177
-    }
137
+		return $content;
138
+	}
139
+
140
+
141
+	/**
142
+	 * This method takes the incoming data and figures out from it what the message type is and
143
+	 * evt_id/grp_id and uses that to generate the url for displaying the template in a browser.
144
+	 *
145
+	 * @since 4.5.0
146
+	 *
147
+	 * @param EE_Messages_Addressee $recipient
148
+	 * @param string                $sending_messenger
149
+	 *
150
+	 * @return string The generated url for displaying the link.
151
+	 * @throws EE_Error
152
+	 */
153
+	private function _get_url(EE_Messages_Addressee $recipient, $sending_messenger)
154
+	{
155
+
156
+		$reg = $recipient->reg_obj;
157
+		$reg = ! $reg instanceof EE_Registration ? $recipient->primary_reg_obj : $reg;
158
+
159
+
160
+		if ($this->_message_type instanceof EE_message_type && $this->_message instanceof EE_Message) {
161
+			EE_Registry::instance()->load_helper('MSG_Template');
162
+			try {
163
+				return EEH_MSG_Template::get_url_trigger(
164
+					$this->_message_type,
165
+					$this->_message,
166
+					$reg,
167
+					$sending_messenger
168
+				);
169
+			} catch (EE_Error $e) {
170
+				if (WP_DEBUG) {
171
+					$e->get_error();
172
+				}
173
+			}
174
+		}
175
+
176
+		return '';
177
+	}
178 178
 }
Please login to merge, or discard this patch.