Completed
Branch FET/extract-activation-detecti... (285969)
by
unknown
02:37 queued 19s
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 = 'html', EE_Message_Resource_Manager $message_resource_manager)
39
-    {
40
-        $this->token = $token;
41
-        $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager);
42
-        $this->_message = $this->_generate_message();
43
-        // set params for parent from the message object
44
-        parent::__construct(
45
-            $this->_message->messenger(),
46
-            $this->_message->message_type(),
47
-            array(),
48
-            $this->_message->context(),
49
-            false
50
-        );
51
-    }
52
-
53
-
54
-
55
-    /**
56
-     * @param string                       $sending_messenger_slug
57
-     * @param \EE_Message_Resource_Manager $message_resource_manager
58
-     * @return \EE_messenger | string
59
-     */
60
-    protected function _set_sending_messenger(
61
-        $sending_messenger_slug,
62
-        EE_Message_Resource_Manager $message_resource_manager
63
-    ) {
64
-        $sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug);
65
-        return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug;
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * @return EE_messenger
72
-     */
73
-    public function sending_messenger()
74
-    {
75
-        return $this->_sending_messenger;
76
-    }
77
-
78
-
79
-
80
-    /**
81
-     * generates an EE_Message using the supplied arguments and some defaults
82
-     *
83
-     * @param array $properties
84
-     * @return EE_Message
85
-     * @throws \EE_Error
86
-     */
87
-    protected function _generate_message($properties = array())
88
-    {
89
-        // a message was generated immediately but the parent class will call this again
90
-        if ($this->_message instanceof EE_Message) {
91
-            return $this->_message;
92
-        }
93
-        $message = EEM_Message::instance()->get_one_by_token($this->token);
94
-        if (! $message instanceof EE_Message) {
95
-            throw new EE_Error(
96
-                sprintf(
97
-                    esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'),
98
-                    $this->token
99
-                )
100
-            );
101
-        }
102
-        $message->set_STS_ID(EEM_Message::status_idle);
103
-
104
-        if (! $this->_sending_messenger instanceof EE_messenger) {
105
-            $message->set_STS_ID(EEM_Message::status_failed);
106
-            $message->set_error_message(
107
-                sprintf(
108
-                    esc_html__('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'),
109
-                    $this->_sending_messenger
110
-                )
111
-            );
112
-        }
113
-
114
-        // set properties
115
-        $this->_valid = true;
116
-        $this->_messenger = $message->messenger_object();
117
-        $this->_message_type = $message->message_type_object();
118
-        $this->_send_now = $message->send_now();
119
-        return $message;
120
-    }
14
+	/**
15
+	 * Sending messenger
16
+	 *
17
+	 * @type EE_messenger | string
18
+	 */
19
+	protected $_sending_messenger = '';
20
+
21
+
22
+	/**
23
+	 * Holds the incoming token;
24
+	 * @type string
25
+	 */
26
+	public $token = '';
27
+
28
+
29
+	/**
30
+	 * Constructor
31
+	 *
32
+	 * @param   string    $sending_messenger_slug     This is used to set what messenger is used to "send"
33
+	 *                                                the EE_Message retrieved from the DB via the given token.
34
+	 * @param   string $token                         This is a token for a Message that should already exist int the db.
35
+	 *                                                This is then used to populate the properties in here.
36
+	 * @param   EE_Message_Resource_Manager $message_resource_manager
37
+	 */
38
+	public function __construct($token, $sending_messenger_slug = 'html', EE_Message_Resource_Manager $message_resource_manager)
39
+	{
40
+		$this->token = $token;
41
+		$this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager);
42
+		$this->_message = $this->_generate_message();
43
+		// set params for parent from the message object
44
+		parent::__construct(
45
+			$this->_message->messenger(),
46
+			$this->_message->message_type(),
47
+			array(),
48
+			$this->_message->context(),
49
+			false
50
+		);
51
+	}
52
+
53
+
54
+
55
+	/**
56
+	 * @param string                       $sending_messenger_slug
57
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
58
+	 * @return \EE_messenger | string
59
+	 */
60
+	protected function _set_sending_messenger(
61
+		$sending_messenger_slug,
62
+		EE_Message_Resource_Manager $message_resource_manager
63
+	) {
64
+		$sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug);
65
+		return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug;
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * @return EE_messenger
72
+	 */
73
+	public function sending_messenger()
74
+	{
75
+		return $this->_sending_messenger;
76
+	}
77
+
78
+
79
+
80
+	/**
81
+	 * generates an EE_Message using the supplied arguments and some defaults
82
+	 *
83
+	 * @param array $properties
84
+	 * @return EE_Message
85
+	 * @throws \EE_Error
86
+	 */
87
+	protected function _generate_message($properties = array())
88
+	{
89
+		// a message was generated immediately but the parent class will call this again
90
+		if ($this->_message instanceof EE_Message) {
91
+			return $this->_message;
92
+		}
93
+		$message = EEM_Message::instance()->get_one_by_token($this->token);
94
+		if (! $message instanceof EE_Message) {
95
+			throw new EE_Error(
96
+				sprintf(
97
+					esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'),
98
+					$this->token
99
+				)
100
+			);
101
+		}
102
+		$message->set_STS_ID(EEM_Message::status_idle);
103
+
104
+		if (! $this->_sending_messenger instanceof EE_messenger) {
105
+			$message->set_STS_ID(EEM_Message::status_failed);
106
+			$message->set_error_message(
107
+				sprintf(
108
+					esc_html__('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'),
109
+					$this->_sending_messenger
110
+				)
111
+			);
112
+		}
113
+
114
+		// set properties
115
+		$this->_valid = true;
116
+		$this->_messenger = $message->messenger_object();
117
+		$this->_message_type = $message->message_type_object();
118
+		$this->_send_now = $message->send_now();
119
+		return $message;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Registration_Base_message_type.lib.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
37 37
     {
38 38
         // this is just a test
39
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
39
+        return $this->name.' Message Type for '.$messenger->name.' Messenger ';
40 40
     }
41 41
 
42 42
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
                     if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) {
56 56
                         $regs = $data_type;
57 57
                     } else {
58
-                        $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg );
58
+                        $regs = is_array($data_type[0]) ? $data_type[0] : array($maybe_reg);
59 59
                     }
60 60
 
61 61
                     foreach ($regs as $reg) {
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                             $this->_regs_for_sending[] = $reg->ID();
64 64
                         }
65 65
                     }
66
-                    $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() );
66
+                    $this->_data = isset($this->_data[1]) ? array($maybe_reg->transaction(), null, $this->_data[1]) : array($maybe_reg->transaction());
67 67
                     $this->_data_handler = 'Gateways';
68 68
                 } else {
69 69
                     $this->_data_handler = 'Gateways';
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
 
83 83
     protected function _get_data_for_context($context, EE_Registration $registration, $id)
84 84
     {
85
-        if ($context  == 'admin') {
85
+        if ($context == 'admin') {
86 86
             // use the registration to get the transaction.
87 87
             $transaction = $registration->transaction();
88 88
 
89 89
             // bail early if no transaction
90
-            if (! $transaction instanceof EE_Transaction) {
90
+            if ( ! $transaction instanceof EE_Transaction) {
91 91
                 throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
92 92
             }
93 93
 
94
-            $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
95
-            return array( $transaction, $payment );
94
+            $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0;
95
+            return array($transaction, $payment);
96 96
         } else {
97 97
             return $registration;
98 98
         }
Please login to merge, or discard this patch.
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -12,126 +12,126 @@
 block discarded – undo
12 12
  */
13 13
 abstract class EE_Registration_Base_message_type extends EE_message_type
14 14
 {
15
-    /**
16
-     * @see parent::get_priority() for documentation.
17
-     * @return int
18
-     */
19
-    public function get_priority()
20
-    {
21
-        return EEM_Message::priority_medium;
22
-    }
23
-
24
-
25
-
26
-    protected function _set_admin_pages()
27
-    {
28
-        $this->admin_registered_pages = array(
29
-            'events_edit' => true
30
-            );
31
-    }
32
-
33
-
34
-    protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
35
-    {
36
-        // this is just a test
37
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
38
-    }
39
-
40
-
41
-
42
-
43
-    protected function _set_data_handler()
44
-    {
45
-        if (is_array($this->_data)) {
46
-            $data_type = reset($this->_data);
47
-
48
-            if (is_array($data_type)) {
49
-                // grab the first item and see if its a registration.
50
-                $maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type);
51
-                if ($maybe_reg instanceof EE_Registration) {
52
-                    // is $data_type itself just an array of registrations?
53
-                    if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) {
54
-                        $regs = $data_type;
55
-                    } else {
56
-                        $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg );
57
-                    }
58
-
59
-                    foreach ($regs as $reg) {
60
-                        if ($reg instanceof EE_Registration) {
61
-                            $this->_regs_for_sending[] = $reg->ID();
62
-                        }
63
-                    }
64
-                    $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() );
65
-                    $this->_data_handler = 'Gateways';
66
-                } else {
67
-                    $this->_data_handler = 'Gateways';
68
-                }
69
-            } else {
70
-                $this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways';
71
-            }
72
-        } else {
73
-            $this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways';
74
-        }
75
-
76
-        $this->_single_message = $this->_data_handler == 'REG' ? true : false;
77
-    }
78
-
79
-
80
-
81
-    protected function _get_data_for_context($context, EE_Registration $registration, $id)
82
-    {
83
-        if ($context  == 'admin') {
84
-            // use the registration to get the transaction.
85
-            $transaction = $registration->transaction();
86
-
87
-            // bail early if no transaction
88
-            if (! $transaction instanceof EE_Transaction) {
89
-                throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
90
-            }
91
-
92
-            $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
93
-            return array( $transaction, $payment );
94
-        } else {
95
-            return $registration;
96
-        }
97
-    }
98
-
99
-
100
-
101
-    /**
102
-     * Setup admin settings for this message type.
103
-     */
104
-    protected function _set_admin_settings_fields()
105
-    {
106
-        $this->_admin_settings_fields = array();
107
-    }
108
-
109
-
110
-
111
-
112
-
113
-    /**
114
-     * returns an array of addressee objects for event_admins
115
-     *
116
-     * @access protected
117
-     * @return array array of EE_Messages_Addressee objects
118
-     */
119
-    protected function _admin_addressees()
120
-    {
121
-        if ($this->_single_message) {
122
-            return array();
123
-        }
124
-        return parent::_admin_addressees();
125
-    }
126
-
127
-
128
-
129
-    protected function _primary_attendee_addressees()
130
-    {
131
-        if ($this->_single_message) {
132
-            return array();
133
-        }
134
-
135
-        return parent::_primary_attendee_addressees();
136
-    }
15
+	/**
16
+	 * @see parent::get_priority() for documentation.
17
+	 * @return int
18
+	 */
19
+	public function get_priority()
20
+	{
21
+		return EEM_Message::priority_medium;
22
+	}
23
+
24
+
25
+
26
+	protected function _set_admin_pages()
27
+	{
28
+		$this->admin_registered_pages = array(
29
+			'events_edit' => true
30
+			);
31
+	}
32
+
33
+
34
+	protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
35
+	{
36
+		// this is just a test
37
+		return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
38
+	}
39
+
40
+
41
+
42
+
43
+	protected function _set_data_handler()
44
+	{
45
+		if (is_array($this->_data)) {
46
+			$data_type = reset($this->_data);
47
+
48
+			if (is_array($data_type)) {
49
+				// grab the first item and see if its a registration.
50
+				$maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type);
51
+				if ($maybe_reg instanceof EE_Registration) {
52
+					// is $data_type itself just an array of registrations?
53
+					if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) {
54
+						$regs = $data_type;
55
+					} else {
56
+						$regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg );
57
+					}
58
+
59
+					foreach ($regs as $reg) {
60
+						if ($reg instanceof EE_Registration) {
61
+							$this->_regs_for_sending[] = $reg->ID();
62
+						}
63
+					}
64
+					$this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() );
65
+					$this->_data_handler = 'Gateways';
66
+				} else {
67
+					$this->_data_handler = 'Gateways';
68
+				}
69
+			} else {
70
+				$this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways';
71
+			}
72
+		} else {
73
+			$this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways';
74
+		}
75
+
76
+		$this->_single_message = $this->_data_handler == 'REG' ? true : false;
77
+	}
78
+
79
+
80
+
81
+	protected function _get_data_for_context($context, EE_Registration $registration, $id)
82
+	{
83
+		if ($context  == 'admin') {
84
+			// use the registration to get the transaction.
85
+			$transaction = $registration->transaction();
86
+
87
+			// bail early if no transaction
88
+			if (! $transaction instanceof EE_Transaction) {
89
+				throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
90
+			}
91
+
92
+			$payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
93
+			return array( $transaction, $payment );
94
+		} else {
95
+			return $registration;
96
+		}
97
+	}
98
+
99
+
100
+
101
+	/**
102
+	 * Setup admin settings for this message type.
103
+	 */
104
+	protected function _set_admin_settings_fields()
105
+	{
106
+		$this->_admin_settings_fields = array();
107
+	}
108
+
109
+
110
+
111
+
112
+
113
+	/**
114
+	 * returns an array of addressee objects for event_admins
115
+	 *
116
+	 * @access protected
117
+	 * @return array array of EE_Messages_Addressee objects
118
+	 */
119
+	protected function _admin_addressees()
120
+	{
121
+		if ($this->_single_message) {
122
+			return array();
123
+		}
124
+		return parent::_admin_addressees();
125
+	}
126
+
127
+
128
+
129
+	protected function _primary_attendee_addressees()
130
+	{
131
+		if ($this->_single_message) {
132
+			return array();
133
+		}
134
+
135
+		return parent::_primary_attendee_addressees();
136
+	}
137 137
 }
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/AttendeesReport.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
23 23
     public function create_job(JobParameters $job_parameters)
24 24
     {
25
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) {
25
+        if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) {
26 26
             throw new BatchRequestException(
27 27
                 esc_html__('You do not have permission to view contacts', 'event_espresso')
28 28
             );
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
             foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) {
106 106
                 if ($field_name == 'STA_ID') {
107 107
                     $state_name_field = \EEM_State::instance()->field_settings_for('STA_name');
108
-                    $csv_row[ esc_html__('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column() ];
108
+                    $csv_row[esc_html__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column()];
109 109
                 } elseif ($field_name == 'CNT_ISO') {
110 110
                     $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name');
111
-                    $csv_row[ esc_html__('Country', 'event_espresso') ] = $attendee_row[ $country_name_field->get_qualified_column() ];
111
+                    $csv_row[esc_html__('Country', 'event_espresso')] = $attendee_row[$country_name_field->get_qualified_column()];
112 112
                 } else {
113
-                    $csv_row[ wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES) ] = $attendee_row[ $field_obj->get_qualified_column() ];
113
+                    $csv_row[wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES)] = $attendee_row[$field_obj->get_qualified_column()];
114 114
                 }
115 115
             }
116 116
             $csv_data[] = apply_filters(
Please login to merge, or discard this patch.
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -18,106 +18,106 @@
 block discarded – undo
18 18
  */
19 19
 class AttendeesReport extends JobHandlerFile
20 20
 {
21
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
22
-    public function create_job(JobParameters $job_parameters)
23
-    {
24
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) {
25
-            throw new BatchRequestException(
26
-                esc_html__('You do not have permission to view contacts', 'event_espresso')
27
-            );
28
-        }
29
-        $filepath = $this->create_file_from_job_with_name(
30
-            $job_parameters->job_id(),
31
-            esc_html__('contact-list-report.csv', 'event_espresso')
32
-        );
33
-        $job_parameters->add_extra_data('filepath', $filepath);
34
-        $job_parameters->set_job_size($this->count_units_to_process());
35
-        // we should also set the header columns
36
-        $csv_data_for_row = $this->get_csv_data(0, 1);
37
-        \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
38
-        // if we actually processed a row there, record it
39
-        if ($job_parameters->job_size()) {
40
-            $job_parameters->mark_processed(1);
41
-        }
42
-        return new JobStepResponse(
43
-            $job_parameters,
44
-            esc_html__('Contacts report started successfully...', 'event_espresso')
45
-        );
46
-    }
21
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
22
+	public function create_job(JobParameters $job_parameters)
23
+	{
24
+		if (! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) {
25
+			throw new BatchRequestException(
26
+				esc_html__('You do not have permission to view contacts', 'event_espresso')
27
+			);
28
+		}
29
+		$filepath = $this->create_file_from_job_with_name(
30
+			$job_parameters->job_id(),
31
+			esc_html__('contact-list-report.csv', 'event_espresso')
32
+		);
33
+		$job_parameters->add_extra_data('filepath', $filepath);
34
+		$job_parameters->set_job_size($this->count_units_to_process());
35
+		// we should also set the header columns
36
+		$csv_data_for_row = $this->get_csv_data(0, 1);
37
+		\EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
38
+		// if we actually processed a row there, record it
39
+		if ($job_parameters->job_size()) {
40
+			$job_parameters->mark_processed(1);
41
+		}
42
+		return new JobStepResponse(
43
+			$job_parameters,
44
+			esc_html__('Contacts report started successfully...', 'event_espresso')
45
+		);
46
+	}
47 47
 
48 48
 
49
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
50
-    {
51
-        $csv_data = $this->get_csv_data($job_parameters->units_processed(), $batch_size);
52
-        \EEH_Export::write_data_array_to_csv(
53
-            $job_parameters->extra_datum('filepath'),
54
-            $csv_data,
55
-            false
56
-        );
57
-        $units_processed = count($csv_data);
58
-        $job_parameters->mark_processed($units_processed);
59
-        $extra_response_data = array(
60
-            'file_url' => '',
61
-        );
62
-        if ($units_processed < $batch_size) {
63
-            $job_parameters->set_status(JobParameters::status_complete);
64
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
65
-        }
66
-        return new JobStepResponse(
67
-            $job_parameters,
68
-            sprintf(
69
-                esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'),
70
-                count($csv_data)
71
-            ),
72
-            $extra_response_data
73
-        );
74
-    }
49
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
50
+	{
51
+		$csv_data = $this->get_csv_data($job_parameters->units_processed(), $batch_size);
52
+		\EEH_Export::write_data_array_to_csv(
53
+			$job_parameters->extra_datum('filepath'),
54
+			$csv_data,
55
+			false
56
+		);
57
+		$units_processed = count($csv_data);
58
+		$job_parameters->mark_processed($units_processed);
59
+		$extra_response_data = array(
60
+			'file_url' => '',
61
+		);
62
+		if ($units_processed < $batch_size) {
63
+			$job_parameters->set_status(JobParameters::status_complete);
64
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
65
+		}
66
+		return new JobStepResponse(
67
+			$job_parameters,
68
+			sprintf(
69
+				esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'),
70
+				count($csv_data)
71
+			),
72
+			$extra_response_data
73
+		);
74
+	}
75 75
 
76 76
 
77
-    public function cleanup_job(JobParameters $job_parameters)
78
-    {
79
-        $this->_file_helper->delete(
80
-            \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
81
-            true,
82
-            'd'
83
-        );
84
-        return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso'));
85
-    }
77
+	public function cleanup_job(JobParameters $job_parameters)
78
+	{
79
+		$this->_file_helper->delete(
80
+			\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
81
+			true,
82
+			'd'
83
+		);
84
+		return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso'));
85
+	}
86 86
 
87
-    public function count_units_to_process()
88
-    {
89
-        return \EEM_Attendee::instance()->count(array('caps' => \EEM_Base::caps_read_admin));
90
-    }
87
+	public function count_units_to_process()
88
+	{
89
+		return \EEM_Attendee::instance()->count(array('caps' => \EEM_Base::caps_read_admin));
90
+	}
91 91
 
92
-    public function get_csv_data($offset, $limit)
93
-    {
94
-        $attendee_rows = \EEM_Attendee::instance()->get_all_wpdb_results(
95
-            array(
96
-                'limit'      => array($offset, $limit),
97
-                'force_join' => array('State', 'Country'),
98
-                'caps'       => \EEM_Base::caps_read_admin,
99
-            )
100
-        );
101
-        $csv_data = array();
102
-        foreach ($attendee_rows as $attendee_row) {
103
-            $csv_row = array();
104
-            foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) {
105
-                if ($field_name == 'STA_ID') {
106
-                    $state_name_field = \EEM_State::instance()->field_settings_for('STA_name');
107
-                    $csv_row[ esc_html__('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column() ];
108
-                } elseif ($field_name == 'CNT_ISO') {
109
-                    $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name');
110
-                    $csv_row[ esc_html__('Country', 'event_espresso') ] = $attendee_row[ $country_name_field->get_qualified_column() ];
111
-                } else {
112
-                    $csv_row[ wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES) ] = $attendee_row[ $field_obj->get_qualified_column() ];
113
-                }
114
-            }
115
-            $csv_data[] = apply_filters(
116
-                'FHEE___EventEspresso_core_libraries_batch_JobHandlers_AttendeesReport__get_csv_data__row',
117
-                $csv_row,
118
-                $attendee_row
119
-            );
120
-        }
121
-        return $csv_data;
122
-    }
92
+	public function get_csv_data($offset, $limit)
93
+	{
94
+		$attendee_rows = \EEM_Attendee::instance()->get_all_wpdb_results(
95
+			array(
96
+				'limit'      => array($offset, $limit),
97
+				'force_join' => array('State', 'Country'),
98
+				'caps'       => \EEM_Base::caps_read_admin,
99
+			)
100
+		);
101
+		$csv_data = array();
102
+		foreach ($attendee_rows as $attendee_row) {
103
+			$csv_row = array();
104
+			foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) {
105
+				if ($field_name == 'STA_ID') {
106
+					$state_name_field = \EEM_State::instance()->field_settings_for('STA_name');
107
+					$csv_row[ esc_html__('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column() ];
108
+				} elseif ($field_name == 'CNT_ISO') {
109
+					$country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name');
110
+					$csv_row[ esc_html__('Country', 'event_espresso') ] = $attendee_row[ $country_name_field->get_qualified_column() ];
111
+				} else {
112
+					$csv_row[ wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES) ] = $attendee_row[ $field_obj->get_qualified_column() ];
113
+				}
114
+			}
115
+			$csv_data[] = apply_filters(
116
+				'FHEE___EventEspresso_core_libraries_batch_JobHandlers_AttendeesReport__get_csv_data__row',
117
+				$csv_row,
118
+				$attendee_row
119
+			);
120
+		}
121
+		return $csv_data;
122
+	}
123 123
 }
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlerBaseClasses/JobHandlerFile.php 2 patches
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -17,135 +17,135 @@
 block discarded – undo
17 17
  */
18 18
 abstract class JobHandlerFile extends JobHandler
19 19
 {
20
-    // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
21
-    const temp_folder_name = 'batch_temp_folder';
20
+	// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
21
+	const temp_folder_name = 'batch_temp_folder';
22 22
 
23
-    // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
24
-    /**
25
-     * @var \EEHI_File
26
-     */
27
-    protected $_file_helper = null;
23
+	// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
24
+	/**
25
+	 * @var \EEHI_File
26
+	 */
27
+	protected $_file_helper = null;
28 28
 
29 29
 
30
-    /**
31
-     * JobHandlerFile constructor.
32
-     *
33
-     * @param \EEHI_File|null $file_helper
34
-     */
35
-    public function __construct(\EEHI_File $file_helper = null)
36
-    {
37
-        if (! $file_helper) {
38
-            $this->_file_helper = new EEH_File();
39
-        }
40
-    }
30
+	/**
31
+	 * JobHandlerFile constructor.
32
+	 *
33
+	 * @param \EEHI_File|null $file_helper
34
+	 */
35
+	public function __construct(\EEHI_File $file_helper = null)
36
+	{
37
+		if (! $file_helper) {
38
+			$this->_file_helper = new EEH_File();
39
+		}
40
+	}
41 41
 
42
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
43
-    /**
44
-     * Creates a file
45
-     *
46
-     * @param string $job_id
47
-     * @param string $filename
48
-     * @param string $filetype
49
-     * @param string $bom initial content to place in the file.
50
-     * @return string
51
-     * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException
52
-     */
53
-    public function create_file_from_job_with_name(
54
-        $job_id,
55
-        $filename,
56
-        $filetype = 'application/ms-excel',
57
-        $bom = "\xEF\xBB\xBF"
58
-    ) {
59
-        $filepath = '';
60
-        try {
61
-            $base_folder = $this->get_base_folder();
62
-            $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
63
-                $base_folder . JobHandlerFile::temp_folder_name
64
-            );
65
-            if ($success) {
66
-                $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
67
-                    $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id
68
-                );
69
-            }
70
-            if ($success) {
71
-                $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename;
72
-                $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
73
-            }
74
-            // let's add the .htaccess file so safari will open the file properly
75
-            if ($success) {
76
-                $extension = EEH_File::get_file_extension($filepath);
77
-                EEH_File::write_to_file(
78
-                    $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess',
79
-                    'AddType ' . $filetype . ' ' . $extension,
80
-                    '.htaccess'
81
-                );
82
-            }
83
-            /**
84
-             * Filters what initial content will be added to the file.
85
-             * @param string $return_value. By default it's whatever was pased into
86
-             *                              JobHandlerFile::create_file_from_job_with_name()
87
-             * @param string $filename
88
-             * @param string $filetype default 'application/ms-excel'
89
-             * @param string $filepath
90
-             */
91
-            EEH_File::write_to_file(
92
-                $filepath,
93
-                apply_filters(
94
-                    'FHEE__EE_CSV__begin_sending_csv__start_writing',
95
-                    $bom,
96
-                    $filename,
97
-                    $filetype,
98
-                    $filepath
99
-                )
100
-            );
101
-            // those methods normally fail with an exception, but if not, let's do it
102
-            if (! $success) {
103
-                throw new \EE_Error(esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso'));
104
-            }
105
-        } catch (\EE_Error $e) {
106
-            throw new BatchRequestException(
107
-                sprintf(
108
-                    // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
109
-                    esc_html__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'),
110
-                    $job_id,
111
-                    $e->getMessage()
112
-                ),
113
-                500,
114
-                $e
115
-            );
116
-        }
117
-        return $filepath;
118
-    }
42
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
43
+	/**
44
+	 * Creates a file
45
+	 *
46
+	 * @param string $job_id
47
+	 * @param string $filename
48
+	 * @param string $filetype
49
+	 * @param string $bom initial content to place in the file.
50
+	 * @return string
51
+	 * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException
52
+	 */
53
+	public function create_file_from_job_with_name(
54
+		$job_id,
55
+		$filename,
56
+		$filetype = 'application/ms-excel',
57
+		$bom = "\xEF\xBB\xBF"
58
+	) {
59
+		$filepath = '';
60
+		try {
61
+			$base_folder = $this->get_base_folder();
62
+			$success = $this->_file_helper->ensure_folder_exists_and_is_writable(
63
+				$base_folder . JobHandlerFile::temp_folder_name
64
+			);
65
+			if ($success) {
66
+				$success = $this->_file_helper->ensure_folder_exists_and_is_writable(
67
+					$base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id
68
+				);
69
+			}
70
+			if ($success) {
71
+				$filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename;
72
+				$success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
73
+			}
74
+			// let's add the .htaccess file so safari will open the file properly
75
+			if ($success) {
76
+				$extension = EEH_File::get_file_extension($filepath);
77
+				EEH_File::write_to_file(
78
+					$base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess',
79
+					'AddType ' . $filetype . ' ' . $extension,
80
+					'.htaccess'
81
+				);
82
+			}
83
+			/**
84
+			 * Filters what initial content will be added to the file.
85
+			 * @param string $return_value. By default it's whatever was pased into
86
+			 *                              JobHandlerFile::create_file_from_job_with_name()
87
+			 * @param string $filename
88
+			 * @param string $filetype default 'application/ms-excel'
89
+			 * @param string $filepath
90
+			 */
91
+			EEH_File::write_to_file(
92
+				$filepath,
93
+				apply_filters(
94
+					'FHEE__EE_CSV__begin_sending_csv__start_writing',
95
+					$bom,
96
+					$filename,
97
+					$filetype,
98
+					$filepath
99
+				)
100
+			);
101
+			// those methods normally fail with an exception, but if not, let's do it
102
+			if (! $success) {
103
+				throw new \EE_Error(esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso'));
104
+			}
105
+		} catch (\EE_Error $e) {
106
+			throw new BatchRequestException(
107
+				sprintf(
108
+					// phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
109
+					esc_html__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'),
110
+					$job_id,
111
+					$e->getMessage()
112
+				),
113
+				500,
114
+				$e
115
+			);
116
+		}
117
+		return $filepath;
118
+	}
119 119
 
120
-    /**
121
-     * Gets the URL to download the file
122
-     *
123
-     * @param string $filepath
124
-     * @return string url to file
125
-     */
126
-    public function get_url_to_file($filepath)
127
-    {
128
-        return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath);
129
-    }
120
+	/**
121
+	 * Gets the URL to download the file
122
+	 *
123
+	 * @param string $filepath
124
+	 * @return string url to file
125
+	 */
126
+	public function get_url_to_file($filepath)
127
+	{
128
+		return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath);
129
+	}
130 130
 
131
-    /**
132
-     * Gets the folder which will contain the "batch_temp_folder"
133
-     *
134
-     * @return string
135
-     */
136
-    public function get_base_folder()
137
-    {
138
-        return apply_filters(
139
-            'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder',
140
-            EVENT_ESPRESSO_UPLOAD_DIR
141
-        );
142
-    }
131
+	/**
132
+	 * Gets the folder which will contain the "batch_temp_folder"
133
+	 *
134
+	 * @return string
135
+	 */
136
+	public function get_base_folder()
137
+	{
138
+		return apply_filters(
139
+			'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder',
140
+			EVENT_ESPRESSO_UPLOAD_DIR
141
+		);
142
+	}
143 143
 
144
-    public function get_base_url()
145
-    {
146
-        return apply_filters(
147
-            'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url',
148
-            EVENT_ESPRESSO_UPLOAD_URL
149
-        );
150
-    }
144
+	public function get_base_url()
145
+	{
146
+		return apply_filters(
147
+			'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url',
148
+			EVENT_ESPRESSO_UPLOAD_URL
149
+		);
150
+	}
151 151
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      */
35 35
     public function __construct(\EEHI_File $file_helper = null)
36 36
     {
37
-        if (! $file_helper) {
37
+        if ( ! $file_helper) {
38 38
             $this->_file_helper = new EEH_File();
39 39
         }
40 40
     }
@@ -60,23 +60,23 @@  discard block
 block discarded – undo
60 60
         try {
61 61
             $base_folder = $this->get_base_folder();
62 62
             $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
63
-                $base_folder . JobHandlerFile::temp_folder_name
63
+                $base_folder.JobHandlerFile::temp_folder_name
64 64
             );
65 65
             if ($success) {
66 66
                 $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
67
-                    $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id
67
+                    $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id
68 68
                 );
69 69
             }
70 70
             if ($success) {
71
-                $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename;
71
+                $filepath = $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/'.$filename;
72 72
                 $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
73 73
             }
74 74
             // let's add the .htaccess file so safari will open the file properly
75 75
             if ($success) {
76 76
                 $extension = EEH_File::get_file_extension($filepath);
77 77
                 EEH_File::write_to_file(
78
-                    $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess',
79
-                    'AddType ' . $filetype . ' ' . $extension,
78
+                    $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/.htaccess',
79
+                    'AddType '.$filetype.' '.$extension,
80 80
                     '.htaccess'
81 81
                 );
82 82
             }
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
                 )
100 100
             );
101 101
             // those methods normally fail with an exception, but if not, let's do it
102
-            if (! $success) {
102
+            if ( ! $success) {
103 103
                 throw new \EE_Error(esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso'));
104 104
             }
105 105
         } catch (\EE_Error $e) {
Please login to merge, or discard this patch.
core/libraries/batch/BatchRequestProcessor.php 2 patches
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -25,215 +25,215 @@
 block discarded – undo
25 25
  */
26 26
 class BatchRequestProcessor
27 27
 {
28
-    // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
29
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
30
-    /**
31
-     * Current job's ID (if assigned)
32
-     *
33
-     * @var string|null
34
-     */
35
-    protected $_job_id;
28
+	// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
29
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
30
+	/**
31
+	 * Current job's ID (if assigned)
32
+	 *
33
+	 * @var string|null
34
+	 */
35
+	protected $_job_id;
36 36
 
37
-    /**
38
-     * Current job's parameters
39
-     *
40
-     * @var JobParameters|null
41
-     */
42
-    protected $_job_parameters;
43
-    /**
44
-     * @var LoaderInterface
45
-     */
46
-    private $loader;
37
+	/**
38
+	 * Current job's parameters
39
+	 *
40
+	 * @var JobParameters|null
41
+	 */
42
+	protected $_job_parameters;
43
+	/**
44
+	 * @var LoaderInterface
45
+	 */
46
+	private $loader;
47 47
 
48
-    /**
49
-     * BatchRequestProcessor constructor.
50
-     * @param LoaderInterface $loader
51
-     */
52
-    public function __construct(LoaderInterface $loader)
53
-    {
54
-        $this->loader = $loader;
55
-    }
56
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
57
-    /**
58
-     * Creates a job for the specified batch handler class (which should be autoloaded)
59
-     * and the specified request data
60
-     *
61
-     * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface
62
-     * @param array  $request_data            to be used by the batch job handler
63
-     * @return JobStepResponse
64
-     */
65
-    public function create_job($batch_job_handler_class, $request_data)
66
-    {
67
-        try {
68
-            $this->_job_id = wp_generate_password(15, false);
69
-            $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class);
70
-            $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data);
71
-            $response = $obj->create_job($this->_job_parameters);
72
-            if (! $response instanceof JobStepResponse) {
73
-                throw new BatchRequestException(
74
-                    sprintf(
75
-                        esc_html__(
76
-                            'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception',
77
-                            'event_espresso'
78
-                        ),
79
-                        wp_json_encode($request_data)
80
-                    )
81
-                );
82
-            }
83
-            $success = $this->_job_parameters->save(true);
84
-            if (! $success) {
85
-                throw new BatchRequestException(
86
-                    sprintf(
87
-                        esc_html__(
88
-                            'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s',
89
-                            'event_espresso'
90
-                        ),
91
-                        $this->_job_id,
92
-                        wp_json_encode($request_data)
93
-                    )
94
-                );
95
-            }
96
-        } catch (\Exception $e) {
97
-            $response = $this->_get_error_response($e, 'create_job');
98
-        }
99
-        return $response;
100
-    }
48
+	/**
49
+	 * BatchRequestProcessor constructor.
50
+	 * @param LoaderInterface $loader
51
+	 */
52
+	public function __construct(LoaderInterface $loader)
53
+	{
54
+		$this->loader = $loader;
55
+	}
56
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
57
+	/**
58
+	 * Creates a job for the specified batch handler class (which should be autoloaded)
59
+	 * and the specified request data
60
+	 *
61
+	 * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface
62
+	 * @param array  $request_data            to be used by the batch job handler
63
+	 * @return JobStepResponse
64
+	 */
65
+	public function create_job($batch_job_handler_class, $request_data)
66
+	{
67
+		try {
68
+			$this->_job_id = wp_generate_password(15, false);
69
+			$obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class);
70
+			$this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data);
71
+			$response = $obj->create_job($this->_job_parameters);
72
+			if (! $response instanceof JobStepResponse) {
73
+				throw new BatchRequestException(
74
+					sprintf(
75
+						esc_html__(
76
+							'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception',
77
+							'event_espresso'
78
+						),
79
+						wp_json_encode($request_data)
80
+					)
81
+				);
82
+			}
83
+			$success = $this->_job_parameters->save(true);
84
+			if (! $success) {
85
+				throw new BatchRequestException(
86
+					sprintf(
87
+						esc_html__(
88
+							'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s',
89
+							'event_espresso'
90
+						),
91
+						$this->_job_id,
92
+						wp_json_encode($request_data)
93
+					)
94
+				);
95
+			}
96
+		} catch (\Exception $e) {
97
+			$response = $this->_get_error_response($e, 'create_job');
98
+		}
99
+		return $response;
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * Retrieves the job's arguments
105
-     *
106
-     * @param string $job_id
107
-     * @param int    $batch_size
108
-     * @return JobStepResponse
109
-     */
110
-    public function continue_job($job_id, $batch_size = 50)
111
-    {
112
-        try {
113
-            $this->_job_id = $job_id;
114
-            $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size;
115
-            // get the corresponding WordPress option for the job
116
-            $this->_job_parameters = JobParameters::load($this->_job_id);
117
-            $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname());
118
-            // continue it
119
-            $response = $handler_obj->continue_job($this->_job_parameters, $batch_size);
120
-            if (! $response instanceof JobStepResponse) {
121
-                throw new BatchRequestException(
122
-                    sprintf(
123
-                        esc_html__(
124
-                            'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception',
125
-                            'event_espresso'
126
-                        ),
127
-                        $this->_job_id
128
-                    )
129
-                );
130
-            }
131
-            $this->_job_parameters->save();
132
-        } catch (\Exception $e) {
133
-            $response = $this->_get_error_response($e, 'continue_job');
134
-        }
135
-        return $response;
136
-    }
103
+	/**
104
+	 * Retrieves the job's arguments
105
+	 *
106
+	 * @param string $job_id
107
+	 * @param int    $batch_size
108
+	 * @return JobStepResponse
109
+	 */
110
+	public function continue_job($job_id, $batch_size = 50)
111
+	{
112
+		try {
113
+			$this->_job_id = $job_id;
114
+			$batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size;
115
+			// get the corresponding WordPress option for the job
116
+			$this->_job_parameters = JobParameters::load($this->_job_id);
117
+			$handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname());
118
+			// continue it
119
+			$response = $handler_obj->continue_job($this->_job_parameters, $batch_size);
120
+			if (! $response instanceof JobStepResponse) {
121
+				throw new BatchRequestException(
122
+					sprintf(
123
+						esc_html__(
124
+							'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception',
125
+							'event_espresso'
126
+						),
127
+						$this->_job_id
128
+					)
129
+				);
130
+			}
131
+			$this->_job_parameters->save();
132
+		} catch (\Exception $e) {
133
+			$response = $this->_get_error_response($e, 'continue_job');
134
+		}
135
+		return $response;
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * Instantiates an object of type $classname, which implements
141
-     * JobHandlerInterface
142
-     *
143
-     * @param string $classname
144
-     * @return JobHandlerInterface
145
-     * @throws BatchRequestException
146
-     */
147
-    public function instantiate_batch_job_handler_from_classname($classname)
148
-    {
149
-        if (! class_exists($classname)) {
150
-            throw new BatchRequestException(
151
-                sprintf(
152
-                    esc_html__(
153
-                        'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.',
154
-                        'event_espresso'
155
-                    ),
156
-                    $classname
157
-                )
158
-            );
159
-        }
160
-        $obj = $this->loader->getNew($classname);
161
-        if (! $obj instanceof JobHandlerInterface) {
162
-            throw new BatchRequestException(
163
-                sprintf(
164
-                    esc_html__(
165
-                        'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job',
166
-                        'event_espresso'
167
-                    ),
168
-                    $classname
169
-                )
170
-            );
171
-        }
172
-        return $obj;
173
-    }
139
+	/**
140
+	 * Instantiates an object of type $classname, which implements
141
+	 * JobHandlerInterface
142
+	 *
143
+	 * @param string $classname
144
+	 * @return JobHandlerInterface
145
+	 * @throws BatchRequestException
146
+	 */
147
+	public function instantiate_batch_job_handler_from_classname($classname)
148
+	{
149
+		if (! class_exists($classname)) {
150
+			throw new BatchRequestException(
151
+				sprintf(
152
+					esc_html__(
153
+						'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.',
154
+						'event_espresso'
155
+					),
156
+					$classname
157
+				)
158
+			);
159
+		}
160
+		$obj = $this->loader->getNew($classname);
161
+		if (! $obj instanceof JobHandlerInterface) {
162
+			throw new BatchRequestException(
163
+				sprintf(
164
+					esc_html__(
165
+						'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job',
166
+						'event_espresso'
167
+					),
168
+					$classname
169
+				)
170
+			);
171
+		}
172
+		return $obj;
173
+	}
174 174
 
175 175
 
176
-    /**
177
-     * Forces a job to be cleaned up
178
-     *
179
-     * @param string $job_id
180
-     * @return JobStepResponse
181
-     * @throws BatchRequestException
182
-     */
183
-    public function cleanup_job($job_id)
184
-    {
185
-        try {
186
-            $this->_job_id = $job_id;
187
-            $job_parameters = JobParameters::load($this->_job_id);
188
-            $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname());
189
-            // continue it
190
-            $response = $handler_obj->cleanup_job($job_parameters);
191
-            if (! $response instanceof JobStepResponse) {
192
-                throw new BatchRequestException(
193
-                    sprintf(
194
-                        esc_html__(
195
-                            'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception',
196
-                            'event_espresso'
197
-                        ),
198
-                        $this->_job_id
199
-                    )
200
-                );
201
-            }
202
-            $job_parameters->set_status(JobParameters::status_cleaned_up);
203
-            $job_parameters->delete();
204
-            return $response;
205
-        } catch (\Exception $e) {
206
-            $response = $this->_get_error_response($e, 'cleanup_job');
207
-        }
208
-        return $response;
209
-    }
176
+	/**
177
+	 * Forces a job to be cleaned up
178
+	 *
179
+	 * @param string $job_id
180
+	 * @return JobStepResponse
181
+	 * @throws BatchRequestException
182
+	 */
183
+	public function cleanup_job($job_id)
184
+	{
185
+		try {
186
+			$this->_job_id = $job_id;
187
+			$job_parameters = JobParameters::load($this->_job_id);
188
+			$handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname());
189
+			// continue it
190
+			$response = $handler_obj->cleanup_job($job_parameters);
191
+			if (! $response instanceof JobStepResponse) {
192
+				throw new BatchRequestException(
193
+					sprintf(
194
+						esc_html__(
195
+							'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception',
196
+							'event_espresso'
197
+						),
198
+						$this->_job_id
199
+					)
200
+				);
201
+			}
202
+			$job_parameters->set_status(JobParameters::status_cleaned_up);
203
+			$job_parameters->delete();
204
+			return $response;
205
+		} catch (\Exception $e) {
206
+			$response = $this->_get_error_response($e, 'cleanup_job');
207
+		}
208
+		return $response;
209
+	}
210 210
 
211 211
 
212
-    /**
213
-     * Creates a valid JobStepResponse object from an exception and method name.
214
-     *
215
-     * @param \Exception $exception
216
-     * @param string     $method_name
217
-     * @return JobStepResponse
218
-     */
219
-    protected function _get_error_response(\Exception $exception, $method_name)
220
-    {
221
-        if (! $this->_job_parameters instanceof JobParameters) {
222
-            $this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), array());
223
-        }
224
-        $this->_job_parameters->set_status(JobParameters::status_error);
225
-        return new JobStepResponse(
226
-            $this->_job_parameters,
227
-            sprintf(
228
-                esc_html__(
229
-                    'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s',
230
-                    'event_espresso'
231
-                ),
232
-                get_class($exception),
233
-                'BatchRunner::' . $method_name . '()',
234
-                $exception->getMessage(),
235
-                $exception->getTraceAsString()
236
-            )
237
-        );
238
-    }
212
+	/**
213
+	 * Creates a valid JobStepResponse object from an exception and method name.
214
+	 *
215
+	 * @param \Exception $exception
216
+	 * @param string     $method_name
217
+	 * @return JobStepResponse
218
+	 */
219
+	protected function _get_error_response(\Exception $exception, $method_name)
220
+	{
221
+		if (! $this->_job_parameters instanceof JobParameters) {
222
+			$this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), array());
223
+		}
224
+		$this->_job_parameters->set_status(JobParameters::status_error);
225
+		return new JobStepResponse(
226
+			$this->_job_parameters,
227
+			sprintf(
228
+				esc_html__(
229
+					'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s',
230
+					'event_espresso'
231
+				),
232
+				get_class($exception),
233
+				'BatchRunner::' . $method_name . '()',
234
+				$exception->getMessage(),
235
+				$exception->getTraceAsString()
236
+			)
237
+		);
238
+	}
239 239
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
             $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class);
70 70
             $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data);
71 71
             $response = $obj->create_job($this->_job_parameters);
72
-            if (! $response instanceof JobStepResponse) {
72
+            if ( ! $response instanceof JobStepResponse) {
73 73
                 throw new BatchRequestException(
74 74
                     sprintf(
75 75
                         esc_html__(
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
                 );
82 82
             }
83 83
             $success = $this->_job_parameters->save(true);
84
-            if (! $success) {
84
+            if ( ! $success) {
85 85
                 throw new BatchRequestException(
86 86
                     sprintf(
87 87
                         esc_html__(
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
             $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname());
118 118
             // continue it
119 119
             $response = $handler_obj->continue_job($this->_job_parameters, $batch_size);
120
-            if (! $response instanceof JobStepResponse) {
120
+            if ( ! $response instanceof JobStepResponse) {
121 121
                 throw new BatchRequestException(
122 122
                     sprintf(
123 123
                         esc_html__(
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      */
147 147
     public function instantiate_batch_job_handler_from_classname($classname)
148 148
     {
149
-        if (! class_exists($classname)) {
149
+        if ( ! class_exists($classname)) {
150 150
             throw new BatchRequestException(
151 151
                 sprintf(
152 152
                     esc_html__(
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
             );
159 159
         }
160 160
         $obj = $this->loader->getNew($classname);
161
-        if (! $obj instanceof JobHandlerInterface) {
161
+        if ( ! $obj instanceof JobHandlerInterface) {
162 162
             throw new BatchRequestException(
163 163
                 sprintf(
164 164
                     esc_html__(
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
             $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname());
189 189
             // continue it
190 190
             $response = $handler_obj->cleanup_job($job_parameters);
191
-            if (! $response instanceof JobStepResponse) {
191
+            if ( ! $response instanceof JobStepResponse) {
192 192
                 throw new BatchRequestException(
193 193
                     sprintf(
194 194
                         esc_html__(
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      */
219 219
     protected function _get_error_response(\Exception $exception, $method_name)
220 220
     {
221
-        if (! $this->_job_parameters instanceof JobParameters) {
221
+        if ( ! $this->_job_parameters instanceof JobParameters) {
222 222
             $this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), array());
223 223
         }
224 224
         $this->_job_parameters->set_status(JobParameters::status_error);
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
                     'event_espresso'
231 231
                 ),
232 232
                 get_class($exception),
233
-                'BatchRunner::' . $method_name . '()',
233
+                'BatchRunner::'.$method_name.'()',
234 234
                 $exception->getMessage(),
235 235
                 $exception->getTraceAsString()
236 236
             )
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/EE_Register_Messages_Template_Variations.lib.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
         }
120 120
 
121 121
         // make sure we don't register twice
122
-        if (isset(self::$_registry[ $identifier ])) {
122
+        if (isset(self::$_registry[$identifier])) {
123 123
             return;
124 124
         }
125 125
 
126 126
         // make sure variation ref is unique.
127
-        if (isset(self::$_registry[ $identifier ])) {
128
-            $identifier = uniqid() . '_' . $identifier;
127
+        if (isset(self::$_registry[$identifier])) {
128
+            $identifier = uniqid().'_'.$identifier;
129 129
         }
130 130
 
131 131
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 
158 158
         // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack.  The former will throw an error.  The latter will remove the conflicting variation name but still register the others and will add EE_Error notice.
159 159
         $validated                      = self::_verify_variations($identifier, $validated);
160
-        self::$_registry[ $identifier ] = $validated;
160
+        self::$_registry[$identifier] = $validated;
161 161
 
162 162
         add_filter(
163 163
             'FHEE__EE_Messages_Template_Pack__get_variations',
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
             foreach ($messenger as $message_type => $variations) {
211 211
                 foreach ($variations as $slug => $label) {
212 212
                     foreach (self::$_registry as $registered_var => $reg_settings) {
213
-                        if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) {
214
-                            unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]);
213
+                        if (isset($reg_settings['variations'][$template_pack][$messenger][$message_type][$slug])) {
214
+                            unset($validated_variations['variations'][$template_pack][$messenger][$message_type][$slug]);
215 215
                             EE_Error::add_error(
216 216
                                 sprintf(
217 217
                                     esc_html__(
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
         // so let's loop through our registered variations and then pull any details matching the request.
264 264
         foreach (self::$_registry as $registry_settings) {
265 265
             $base        = $url ? $registry_settings['base_url'] : $registry_settings['base_path'];
266
-            $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension;
266
+            $file_string = $messenger.'_'.$type.'_'.$variation.$file_extension;
267 267
             // see if this file exists
268
-            if (is_readable($registry_settings['base_path'] . $file_string)) {
269
-                return $base . $file_string;
268
+            if (is_readable($registry_settings['base_path'].$file_string)) {
269
+                return $base.$file_string;
270 270
             }
271 271
         }
272 272
 
@@ -307,16 +307,16 @@  discard block
 block discarded – undo
307 307
                 return array_merge($registry_settings['variations'], $variations);
308 308
             }
309 309
             if (empty($message_type)) {
310
-                if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) {
310
+                if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger])) {
311 311
                     return array_merge(
312
-                        $registry_settings['variations'][ $template_pack->dbref ][ $messenger ],
312
+                        $registry_settings['variations'][$template_pack->dbref][$messenger],
313 313
                         $variations
314 314
                     );
315 315
                 }
316 316
             } else {
317
-                if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) {
317
+                if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger][$message_type])) {
318 318
                     return array_merge(
319
-                        $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ],
319
+                        $registry_settings['variations'][$template_pack->dbref][$messenger][$message_type],
320 320
                         $variations
321 321
                     );
322 322
                 }
@@ -337,6 +337,6 @@  discard block
 block discarded – undo
337 337
      */
338 338
     public static function deregister($identifier = '')
339 339
     {
340
-        unset(self::$_registry[ $identifier ]);
340
+        unset(self::$_registry[$identifier]);
341 341
     }
342 342
 }
Please login to merge, or discard this patch.
Indentation   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -10,332 +10,332 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Register_Messages_Template_Variations implements EEI_Plugin_API
12 12
 {
13
-    /**
14
-     * Holds values for registered variations
15
-     *
16
-     * @since 4.5.0
17
-     *
18
-     * @var array
19
-     */
20
-    protected static $_registry = [];
13
+	/**
14
+	 * Holds values for registered variations
15
+	 *
16
+	 * @since 4.5.0
17
+	 *
18
+	 * @var array
19
+	 */
20
+	protected static $_registry = [];
21 21
 
22 22
 
23
-    /**
24
-     * Used to register new variations
25
-     *
26
-     * Variations are attached to template packs and do not typically change any structural layout but merely tweak the
27
-     * style of the layout.  The most commonly known variation is css.  CSS does not affect html structure just the
28
-     * style of existing structure.
29
-     *
30
-     * It's important to remember that when variation files are loaded, the file structure looked for is:
31
-     * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'.
32
-     *
33
-     *    - Every variation applies to specific messengers.  That's why the variation file includes the messenger name
34
-     *    it.   This ensures that if a template pack the variation is registered with supports multiple variations that
35
-     *    you can have the correct variation loaded.
36
-     *    - EE_messengers also implicitly define variation "types" which typically are the context in which a specific
37
-     *    variation is loaded.  For instance the email messenger has: 'inline', which is the css added inline to the
38
-     *    email templates; 'preview', which is the same css only customized for when emails are previewed; and
39
-     *    'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to
40
-     *    give a accurate representation of the style in the wysiwyg editor.  This means that for each variation, if
41
-     *    you want it to be accurately represented in various template contexts you need to have that relevant
42
-     *    variation file available.
43
-     *    - $variation_slug  is simply the variation slug for that variation.
44
-     *    - $extension = whatever the extension is for the variation used for the messenger calling it.  In MOST cases
45
-     *    messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT
46
-     *    be loaded.  The EE messages template pack system will fallback to corresponding default template pack for the
47
-     *    given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any
48
-     *    variation (so the template pack would be unstyled)
49
-     *
50
-     * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html
51
-     *      messengers.
52
-     *
53
-     * @param string $identifier                      unique reference used to describe this variation registry. If
54
-     *                                                this ISN'T unique then this method will make it unique (and it
55
-     *                                                becomes harder to deregister).
56
-     * @param array  $setup_args                      {
57
-     *                                                an array of required values for registering the variations.
58
-     * @type array   $variations                      {
59
-     *                                                An array indexed by template_pack->dbref. and values are an array
60
-     *                                                indexed by messenger name and values are an array indexed by
61
-     *                                                message_type and values are an array indexed by variation_slug
62
-     *                                                and value  is the localized label for the variation.  Note this
63
-     *                                                api reserves the "default" variation name for the default
64
-     *                                                template pack so you can't register a default variation.  Also,
65
-     *                                                try to use unique variation slugs to reference your variations
66
-     *                                                because this api checks if any existing variations are in place
67
-     *                                                with that name.  If there are then subsequent variations for that
68
-     *                                                template pack with that same name will fail to register with a
69
-     *                                                persistent notice put up for the user. Required.
70
-     *                                                'default' => array(
71
-     *                                                'email' => array(
72
-     *                                                'registration_approved' => array(
73
-     *                                                my_ee_addon_blue_lagoon' => esc_html__('Blue Lagoon',
74
-     *                                                'text_domain'),
75
-     *                                                'my_ee_addon_red_sunset' => esc_html__('Red Sunset',
76
-     *                                                'text_domain')
77
-     *                                                )
78
-     *                                                )
79
-     *                                                )
80
-     *                                                }
81
-     * @type string  $base_path                       The base path for where all your variations are found.  Although
82
-     *                                                the full path to your variation files should include
83
-     *                                                '/variations/' in it, do not include the
84
-     *                                                'variations/' in this. Required.
85
-     * @type string  $base_url                        The base url for where all your variations are found. See note
86
-     *                                                above about the 'variations/' string. Required.
87
-     *                                                }
88
-     *                                                }
89
-     *
90
-     * @throws EE_Error
91
-     * @return void
92
-     */
93
-    public static function register($identifier = '', array $setup_args = [])
94
-    {
23
+	/**
24
+	 * Used to register new variations
25
+	 *
26
+	 * Variations are attached to template packs and do not typically change any structural layout but merely tweak the
27
+	 * style of the layout.  The most commonly known variation is css.  CSS does not affect html structure just the
28
+	 * style of existing structure.
29
+	 *
30
+	 * It's important to remember that when variation files are loaded, the file structure looked for is:
31
+	 * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'.
32
+	 *
33
+	 *    - Every variation applies to specific messengers.  That's why the variation file includes the messenger name
34
+	 *    it.   This ensures that if a template pack the variation is registered with supports multiple variations that
35
+	 *    you can have the correct variation loaded.
36
+	 *    - EE_messengers also implicitly define variation "types" which typically are the context in which a specific
37
+	 *    variation is loaded.  For instance the email messenger has: 'inline', which is the css added inline to the
38
+	 *    email templates; 'preview', which is the same css only customized for when emails are previewed; and
39
+	 *    'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to
40
+	 *    give a accurate representation of the style in the wysiwyg editor.  This means that for each variation, if
41
+	 *    you want it to be accurately represented in various template contexts you need to have that relevant
42
+	 *    variation file available.
43
+	 *    - $variation_slug  is simply the variation slug for that variation.
44
+	 *    - $extension = whatever the extension is for the variation used for the messenger calling it.  In MOST cases
45
+	 *    messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT
46
+	 *    be loaded.  The EE messages template pack system will fallback to corresponding default template pack for the
47
+	 *    given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any
48
+	 *    variation (so the template pack would be unstyled)
49
+	 *
50
+	 * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html
51
+	 *      messengers.
52
+	 *
53
+	 * @param string $identifier                      unique reference used to describe this variation registry. If
54
+	 *                                                this ISN'T unique then this method will make it unique (and it
55
+	 *                                                becomes harder to deregister).
56
+	 * @param array  $setup_args                      {
57
+	 *                                                an array of required values for registering the variations.
58
+	 * @type array   $variations                      {
59
+	 *                                                An array indexed by template_pack->dbref. and values are an array
60
+	 *                                                indexed by messenger name and values are an array indexed by
61
+	 *                                                message_type and values are an array indexed by variation_slug
62
+	 *                                                and value  is the localized label for the variation.  Note this
63
+	 *                                                api reserves the "default" variation name for the default
64
+	 *                                                template pack so you can't register a default variation.  Also,
65
+	 *                                                try to use unique variation slugs to reference your variations
66
+	 *                                                because this api checks if any existing variations are in place
67
+	 *                                                with that name.  If there are then subsequent variations for that
68
+	 *                                                template pack with that same name will fail to register with a
69
+	 *                                                persistent notice put up for the user. Required.
70
+	 *                                                'default' => array(
71
+	 *                                                'email' => array(
72
+	 *                                                'registration_approved' => array(
73
+	 *                                                my_ee_addon_blue_lagoon' => esc_html__('Blue Lagoon',
74
+	 *                                                'text_domain'),
75
+	 *                                                'my_ee_addon_red_sunset' => esc_html__('Red Sunset',
76
+	 *                                                'text_domain')
77
+	 *                                                )
78
+	 *                                                )
79
+	 *                                                )
80
+	 *                                                }
81
+	 * @type string  $base_path                       The base path for where all your variations are found.  Although
82
+	 *                                                the full path to your variation files should include
83
+	 *                                                '/variations/' in it, do not include the
84
+	 *                                                'variations/' in this. Required.
85
+	 * @type string  $base_url                        The base url for where all your variations are found. See note
86
+	 *                                                above about the 'variations/' string. Required.
87
+	 *                                                }
88
+	 *                                                }
89
+	 *
90
+	 * @throws EE_Error
91
+	 * @return void
92
+	 */
93
+	public static function register($identifier = '', array $setup_args = [])
94
+	{
95 95
 
96
-        // check for required params
97
-        if (empty($identifier)) {
98
-            throw new EE_Error(
99
-                esc_html__(
100
-                    'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered',
101
-                    'event_espresso'
102
-                )
103
-            );
104
-        }
96
+		// check for required params
97
+		if (empty($identifier)) {
98
+			throw new EE_Error(
99
+				esc_html__(
100
+					'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered',
101
+					'event_espresso'
102
+				)
103
+			);
104
+		}
105 105
 
106
-        if (
107
-            ! is_array($setup_args)
108
-            || empty($setup_args['variations'])
109
-            || empty($setup_args['base_path'])
110
-            || empty($setup_args['base_url'])
111
-        ) {
112
-            throw new EE_Error(
113
-                esc_html__(
114
-                    'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"',
115
-                    'event_espresso'
116
-                )
117
-            );
118
-        }
106
+		if (
107
+			! is_array($setup_args)
108
+			|| empty($setup_args['variations'])
109
+			|| empty($setup_args['base_path'])
110
+			|| empty($setup_args['base_url'])
111
+		) {
112
+			throw new EE_Error(
113
+				esc_html__(
114
+					'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"',
115
+					'event_espresso'
116
+				)
117
+			);
118
+		}
119 119
 
120
-        // make sure we don't register twice
121
-        if (isset(self::$_registry[ $identifier ])) {
122
-            return;
123
-        }
120
+		// make sure we don't register twice
121
+		if (isset(self::$_registry[ $identifier ])) {
122
+			return;
123
+		}
124 124
 
125
-        // make sure variation ref is unique.
126
-        if (isset(self::$_registry[ $identifier ])) {
127
-            $identifier = uniqid() . '_' . $identifier;
128
-        }
125
+		// make sure variation ref is unique.
126
+		if (isset(self::$_registry[ $identifier ])) {
127
+			$identifier = uniqid() . '_' . $identifier;
128
+		}
129 129
 
130 130
 
131
-        // make sure this was called in the right place!
132
-        if (
133
-            ! did_action('EE_Brewing_Regular___messages_caf')
134
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
135
-        ) {
136
-            EE_Error::doing_it_wrong(
137
-                __METHOD__,
138
-                sprintf(
139
-                    esc_html__(
140
-                        'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
141
-                        'event_espresso'
142
-                    ),
143
-                    $identifier
144
-                ),
145
-                '4.5.0'
146
-            );
147
-        }
131
+		// make sure this was called in the right place!
132
+		if (
133
+			! did_action('EE_Brewing_Regular___messages_caf')
134
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
135
+		) {
136
+			EE_Error::doing_it_wrong(
137
+				__METHOD__,
138
+				sprintf(
139
+					esc_html__(
140
+						'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
141
+						'event_espresso'
142
+					),
143
+					$identifier
144
+				),
145
+				'4.5.0'
146
+			);
147
+		}
148 148
 
149
-        // validate/sanitize incoming args.
150
-        $validated = [
151
-            'variations' => (array) $setup_args['variations'],
152
-            'base_path'  => (string) $setup_args['base_path'],
153
-            'base_url'   => (string) $setup_args['base_url'],
154
-        ];
149
+		// validate/sanitize incoming args.
150
+		$validated = [
151
+			'variations' => (array) $setup_args['variations'],
152
+			'base_path'  => (string) $setup_args['base_path'],
153
+			'base_url'   => (string) $setup_args['base_url'],
154
+		];
155 155
 
156 156
 
157
-        // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack.  The former will throw an error.  The latter will remove the conflicting variation name but still register the others and will add EE_Error notice.
158
-        $validated                      = self::_verify_variations($identifier, $validated);
159
-        self::$_registry[ $identifier ] = $validated;
157
+		// check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack.  The former will throw an error.  The latter will remove the conflicting variation name but still register the others and will add EE_Error notice.
158
+		$validated                      = self::_verify_variations($identifier, $validated);
159
+		self::$_registry[ $identifier ] = $validated;
160 160
 
161
-        add_filter(
162
-            'FHEE__EE_Messages_Template_Pack__get_variations',
163
-            ['EE_Register_Messages_Template_Variations', 'get_variations'],
164
-            10,
165
-            4
166
-        );
167
-        add_filter(
168
-            'FHEE__EE_Messages_Template_Pack__get_variation',
169
-            ['EE_Register_Messages_Template_Variations', 'get_variation'],
170
-            10,
171
-            8
172
-        );
173
-    }
161
+		add_filter(
162
+			'FHEE__EE_Messages_Template_Pack__get_variations',
163
+			['EE_Register_Messages_Template_Variations', 'get_variations'],
164
+			10,
165
+			4
166
+		);
167
+		add_filter(
168
+			'FHEE__EE_Messages_Template_Pack__get_variation',
169
+			['EE_Register_Messages_Template_Variations', 'get_variation'],
170
+			10,
171
+			8
172
+		);
173
+	}
174 174
 
175 175
 
176
-    /**
177
-     * Cycles through the variations registered and makes sure there are no reserved variations being registered which
178
-     * throws an error.  Also checks if there is already a
179
-     *
180
-     * @param string $identifier           the reference for the variations being registered
181
-     * @param array  $validated_variations The variations setup array that's being registered (and verified).
182
-     * @return array
183
-     * @throws EE_Error
184
-     * @since  4.5.0
185
-     *
186
-     */
187
-    private static function _verify_variations($identifier, array $validated_variations)
188
-    {
189
-        foreach (self::$_registry as $settings) {
190
-            foreach ($settings['variations'] as $messenger) {
191
-                foreach ($messenger as $all_variations) {
192
-                    if (isset($all_variations['default'])) {
193
-                        throw new EE_Error(
194
-                            sprintf(
195
-                                esc_html__(
196
-                                    'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template.  Please check the code registering variations with this reference, "%s" and modify.',
197
-                                    'event_espresso'
198
-                                ),
199
-                                $identifier
200
-                            )
201
-                        );
202
-                    }
203
-                }
204
-            }
205
-        }
176
+	/**
177
+	 * Cycles through the variations registered and makes sure there are no reserved variations being registered which
178
+	 * throws an error.  Also checks if there is already a
179
+	 *
180
+	 * @param string $identifier           the reference for the variations being registered
181
+	 * @param array  $validated_variations The variations setup array that's being registered (and verified).
182
+	 * @return array
183
+	 * @throws EE_Error
184
+	 * @since  4.5.0
185
+	 *
186
+	 */
187
+	private static function _verify_variations($identifier, array $validated_variations)
188
+	{
189
+		foreach (self::$_registry as $settings) {
190
+			foreach ($settings['variations'] as $messenger) {
191
+				foreach ($messenger as $all_variations) {
192
+					if (isset($all_variations['default'])) {
193
+						throw new EE_Error(
194
+							sprintf(
195
+								esc_html__(
196
+									'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template.  Please check the code registering variations with this reference, "%s" and modify.',
197
+									'event_espresso'
198
+								),
199
+								$identifier
200
+							)
201
+						);
202
+					}
203
+				}
204
+			}
205
+		}
206 206
 
207
-        // is there already a variation registered with a given variation slug?
208
-        foreach ($validated_variations['variations'] as $template_pack => $messenger) {
209
-            foreach ($messenger as $message_type => $variations) {
210
-                foreach ($variations as $slug => $label) {
211
-                    foreach (self::$_registry as $registered_var => $reg_settings) {
212
-                        if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) {
213
-                            unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]);
214
-                            EE_Error::add_error(
215
-                                sprintf(
216
-                                    esc_html__(
217
-                                        'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.',
218
-                                        'event_espresso'
219
-                                    ),
220
-                                    $label,
221
-                                    $template_pack,
222
-                                    $messenger,
223
-                                    $message_type,
224
-                                    $registered_var
225
-                                )
226
-                            );
227
-                        }
228
-                    }
229
-                }
230
-            }
231
-        }
232
-        return $validated_variations;
233
-    }
207
+		// is there already a variation registered with a given variation slug?
208
+		foreach ($validated_variations['variations'] as $template_pack => $messenger) {
209
+			foreach ($messenger as $message_type => $variations) {
210
+				foreach ($variations as $slug => $label) {
211
+					foreach (self::$_registry as $registered_var => $reg_settings) {
212
+						if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) {
213
+							unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]);
214
+							EE_Error::add_error(
215
+								sprintf(
216
+									esc_html__(
217
+										'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.',
218
+										'event_espresso'
219
+									),
220
+									$label,
221
+									$template_pack,
222
+									$messenger,
223
+									$message_type,
224
+									$registered_var
225
+								)
226
+							);
227
+						}
228
+					}
229
+				}
230
+			}
231
+		}
232
+		return $validated_variations;
233
+	}
234 234
 
235 235
 
236
-    /**
237
-     * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used.
238
-     *
239
-     * @param string                    $variation_path The path generated for the current variation
240
-     * @param string                    $messenger      The messenger the variation is for
241
-     * @param string                    $message_type   EE_message_type->name
242
-     * @param string                    $type           The type of variation being requested
243
-     * @param string                    $variation      The slug for the variation being requested
244
-     * @param string                    $file_extension What the file extension is for the variation
245
-     * @param bool                      $url            Whether url or path is being returned.
246
-     * @param EE_Messages_Template_Pack $template_pack
247
-     *
248
-     * @return string                    The path to the requested variation.
249
-     * @since 4.5.0
250
-     *
251
-     */
252
-    public static function get_variation(
253
-        $variation_path,
254
-        $messenger,
255
-        $message_type,
256
-        $type,
257
-        $variation,
258
-        $file_extension,
259
-        $url,
260
-        EE_Messages_Template_Pack $template_pack
261
-    ) {
262
-        // so let's loop through our registered variations and then pull any details matching the request.
263
-        foreach (self::$_registry as $registry_settings) {
264
-            $base        = $url ? $registry_settings['base_url'] : $registry_settings['base_path'];
265
-            $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension;
266
-            // see if this file exists
267
-            if (is_readable($registry_settings['base_path'] . $file_string)) {
268
-                return $base . $file_string;
269
-            }
270
-        }
236
+	/**
237
+	 * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used.
238
+	 *
239
+	 * @param string                    $variation_path The path generated for the current variation
240
+	 * @param string                    $messenger      The messenger the variation is for
241
+	 * @param string                    $message_type   EE_message_type->name
242
+	 * @param string                    $type           The type of variation being requested
243
+	 * @param string                    $variation      The slug for the variation being requested
244
+	 * @param string                    $file_extension What the file extension is for the variation
245
+	 * @param bool                      $url            Whether url or path is being returned.
246
+	 * @param EE_Messages_Template_Pack $template_pack
247
+	 *
248
+	 * @return string                    The path to the requested variation.
249
+	 * @since 4.5.0
250
+	 *
251
+	 */
252
+	public static function get_variation(
253
+		$variation_path,
254
+		$messenger,
255
+		$message_type,
256
+		$type,
257
+		$variation,
258
+		$file_extension,
259
+		$url,
260
+		EE_Messages_Template_Pack $template_pack
261
+	) {
262
+		// so let's loop through our registered variations and then pull any details matching the request.
263
+		foreach (self::$_registry as $registry_settings) {
264
+			$base        = $url ? $registry_settings['base_url'] : $registry_settings['base_path'];
265
+			$file_string = $messenger . '_' . $type . '_' . $variation . $file_extension;
266
+			// see if this file exists
267
+			if (is_readable($registry_settings['base_path'] . $file_string)) {
268
+				return $base . $file_string;
269
+			}
270
+		}
271 271
 
272
-        // no match
273
-        return $variation_path;
274
-    }
272
+		// no match
273
+		return $variation_path;
274
+	}
275 275
 
276 276
 
277
-    /**
278
-     * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter.
279
-     *
280
-     *
281
-     * @param array                     $variations The original contents for the template pack variations property.
282
-     * @param string                    $messenger  The messenger requesting the variations.
283
-     * @param string                    $message_type
284
-     * @param EE_Messages_Template_Pack $template_pack
285
-     *
286
-     * @return array                   new variations array (or existing one if nothing registered)
287
-     * @since 4.5.0
288
-     *
289
-     * @see   $_variation property definition in EE_Messages_Template_Pack
290
-     */
291
-    public static function get_variations(
292
-        array $variations,
293
-        $messenger,
294
-        $message_type,
295
-        EE_Messages_Template_Pack $template_pack
296
-    ) {
297
-        // first let's check if we even have registered variations and get out early.
298
-        if (empty(self::$_registry)) {
299
-            return $variations;
300
-        }
277
+	/**
278
+	 * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter.
279
+	 *
280
+	 *
281
+	 * @param array                     $variations The original contents for the template pack variations property.
282
+	 * @param string                    $messenger  The messenger requesting the variations.
283
+	 * @param string                    $message_type
284
+	 * @param EE_Messages_Template_Pack $template_pack
285
+	 *
286
+	 * @return array                   new variations array (or existing one if nothing registered)
287
+	 * @since 4.5.0
288
+	 *
289
+	 * @see   $_variation property definition in EE_Messages_Template_Pack
290
+	 */
291
+	public static function get_variations(
292
+		array $variations,
293
+		$messenger,
294
+		$message_type,
295
+		EE_Messages_Template_Pack $template_pack
296
+	) {
297
+		// first let's check if we even have registered variations and get out early.
298
+		if (empty(self::$_registry)) {
299
+			return $variations;
300
+		}
301 301
 
302
-        // do we have any new variations for the given messenger, $message_type, and template packs
303
-        foreach (self::$_registry as $registry_settings) {
304
-            // allow for different conditions.
305
-            if (empty($messenger)) {
306
-                return array_merge($registry_settings['variations'], $variations);
307
-            }
308
-            if (empty($message_type)) {
309
-                if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) {
310
-                    return array_merge(
311
-                        $registry_settings['variations'][ $template_pack->dbref ][ $messenger ],
312
-                        $variations
313
-                    );
314
-                }
315
-            } else {
316
-                if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) {
317
-                    return array_merge(
318
-                        $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ],
319
-                        $variations
320
-                    );
321
-                }
322
-            }
323
-        }
324
-        return $variations;
325
-    }
302
+		// do we have any new variations for the given messenger, $message_type, and template packs
303
+		foreach (self::$_registry as $registry_settings) {
304
+			// allow for different conditions.
305
+			if (empty($messenger)) {
306
+				return array_merge($registry_settings['variations'], $variations);
307
+			}
308
+			if (empty($message_type)) {
309
+				if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) {
310
+					return array_merge(
311
+						$registry_settings['variations'][ $template_pack->dbref ][ $messenger ],
312
+						$variations
313
+					);
314
+				}
315
+			} else {
316
+				if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) {
317
+					return array_merge(
318
+						$registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ],
319
+						$variations
320
+					);
321
+				}
322
+			}
323
+		}
324
+		return $variations;
325
+	}
326 326
 
327 327
 
328
-    /**
329
-     * This deregisters a variation set that was previously registered with the given slug.
330
-     *
331
-     * @param string $identifier The name for the variation set that was previously registered.
332
-     *
333
-     * @return void
334
-     * @since 4.5.0
335
-     *
336
-     */
337
-    public static function deregister($identifier = '')
338
-    {
339
-        unset(self::$_registry[ $identifier ]);
340
-    }
328
+	/**
329
+	 * This deregisters a variation set that was previously registered with the given slug.
330
+	 *
331
+	 * @param string $identifier The name for the variation set that was previously registered.
332
+	 *
333
+	 * @return void
334
+	 * @since 4.5.0
335
+	 *
336
+	 */
337
+	public static function deregister($identifier = '')
338
+	{
339
+		unset(self::$_registry[ $identifier ]);
340
+	}
341 341
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Capabilities.lib.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
             );
66 66
         }
67 67
         // make sure we don't register twice
68
-        if (isset(self::$_registry[ $identifier ])) {
68
+        if (isset(self::$_registry[$identifier])) {
69 69
             return;
70 70
         }
71 71
         // make sure this is not registered too late or too early.
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
             );
87 87
         }
88 88
         // some preliminary sanitization and setting to the $_registry property
89
-        self::$_registry[ $identifier ] = [
89
+        self::$_registry[$identifier] = [
90 90
             'caps'     => isset($setup_args['capabilities']) && is_array($setup_args['capabilities'])
91 91
                 ? $setup_args['capabilities']
92 92
                 : [],
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     {
136 136
         // loop through and instantiate cap maps.
137 137
         foreach (self::$_registry as $identifier => $setup) {
138
-            if (! isset($setup['cap_maps'])) {
138
+            if ( ! isset($setup['cap_maps'])) {
139 139
                 continue;
140 140
             }
141 141
             foreach ($setup['cap_maps'] as $cap_class => $args) {
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
                  */
165 165
                 if (is_numeric($cap_class)) {
166 166
                     $cap_class = key($args);
167
-                    $args      = $args[ $cap_class ];
167
+                    $args      = $args[$cap_class];
168 168
                 }
169 169
 
170
-                if (! class_exists($cap_class)) {
170
+                if ( ! class_exists($cap_class)) {
171 171
                     throw new EE_Error(
172 172
                         sprintf(
173 173
                             esc_html__(
@@ -205,17 +205,17 @@  discard block
 block discarded – undo
205 205
      */
206 206
     public static function deregister($identifier = '')
207 207
     {
208
-        if (! empty(self::$_registry[ $identifier ])) {
209
-            if (! empty(self::$_registry[ $identifier ]['caps'])) {
208
+        if ( ! empty(self::$_registry[$identifier])) {
209
+            if ( ! empty(self::$_registry[$identifier]['caps'])) {
210 210
                 // if it's too early to remove capabilities, wait to do this until core is loaded and ready
211
-                $caps_to_remove = self::$_registry[ $identifier ]['caps'];
211
+                $caps_to_remove = self::$_registry[$identifier]['caps'];
212 212
                 if (did_action('AHEE__EE_System__core_loaded_and_ready')) {
213 213
                     $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
214 214
                     $capabilities->removeCaps($caps_to_remove);
215 215
                 } else {
216 216
                     add_action(
217 217
                         'AHEE__EE_System__core_loaded_and_ready',
218
-                        function () use ($caps_to_remove) {
218
+                        function() use ($caps_to_remove) {
219 219
                             $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
220 220
                             $capabilities->removeCaps($caps_to_remove);
221 221
                         }
@@ -223,6 +223,6 @@  discard block
 block discarded – undo
223 223
                 }
224 224
             }
225 225
         }
226
-        unset(self::$_registry[ $identifier ]);
226
+        unset(self::$_registry[$identifier]);
227 227
     }
228 228
 }
Please login to merge, or discard this patch.
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -14,214 +14,214 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Register_Capabilities implements EEI_Plugin_API
16 16
 {
17
-    /**
18
-     * Holds the settings for a specific registration.
19
-     *
20
-     * @var array
21
-     */
22
-    protected static $_registry = [];
17
+	/**
18
+	 * Holds the settings for a specific registration.
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected static $_registry = [];
23 23
 
24 24
 
25
-    /**
26
-     * Used to register capability items with EE core.
27
-     *
28
-     * @param string $identifier                                                          usually will be a class name
29
-     *                                                                                    that references capability
30
-     *                                                                                    related items setup for
31
-     *                                                                                    something.
32
-     * @param array  $setup_args                                                          {
33
-     *                                                                                    An array of items related to
34
-     *                                                                                    registering capabilities.
35
-     * @type array   $capabilities                                                        An array mapping capability
36
-     *                                                                                    strings to core WP Role.
37
-     *                                                                                    Something like: array(
38
-     *                                                                                    'administrator'    => array(
39
-     *                                                                                    'read_cap', 'edit_cap',
40
-     *                                                                                    'delete_cap'),
41
-     *                                                                                    'author'                =>
42
-     *                                                                                    array( 'read_cap' )
43
-     *                                                                                    ).
44
-     * @type array   $capability_maps                                                     EE_Meta_Capability_Map[]
45
-     * @return void
46
-     * @throws EE_Error
47
-     * @since 4.5.0
48
-     * @see   EE_Capabilities.php for php docs on these objects.
49
-     *                                                                                    Should be indexed by the
50
-     *                                                                                    classname for the capability
51
-     *                                                                                    map and values representing
52
-     *                                                                                    the arguments for the map.
53
-     *                                                                                    }
54
-     */
55
-    public static function register($identifier = '', array $setup_args = [])
56
-    {
57
-        // required fields MUST be present, so let's make sure they are.
58
-        if ($identifier === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
59
-            throw new EE_Error(
60
-                esc_html__(
61
-                    'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".',
62
-                    'event_espresso'
63
-                )
64
-            );
65
-        }
66
-        // make sure we don't register twice
67
-        if (isset(self::$_registry[ $identifier ])) {
68
-            return;
69
-        }
70
-        // make sure this is not registered too late or too early.
71
-        if (
72
-            ! did_action('AHEE__EE_System__load_espresso_addons')
73
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
74
-        ) {
75
-            EE_Error::doing_it_wrong(
76
-                __METHOD__,
77
-                sprintf(
78
-                    esc_html__(
79
-                        '%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.',
80
-                        'event_espresso'
81
-                    ),
82
-                    $identifier
83
-                ),
84
-                '4.5.0'
85
-            );
86
-        }
87
-        // some preliminary sanitization and setting to the $_registry property
88
-        self::$_registry[ $identifier ] = [
89
-            'caps'     => isset($setup_args['capabilities']) && is_array($setup_args['capabilities'])
90
-                ? $setup_args['capabilities']
91
-                : [],
92
-            'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : [],
93
-        ];
94
-        // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once)
95
-        add_filter(
96
-            'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
97
-            ['EE_Register_Capabilities', 'register_capabilities']
98
-        );
99
-        // add filter for cap maps
100
-        add_filter(
101
-            'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
102
-            ['EE_Register_Capabilities', 'register_cap_maps']
103
-        );
104
-    }
25
+	/**
26
+	 * Used to register capability items with EE core.
27
+	 *
28
+	 * @param string $identifier                                                          usually will be a class name
29
+	 *                                                                                    that references capability
30
+	 *                                                                                    related items setup for
31
+	 *                                                                                    something.
32
+	 * @param array  $setup_args                                                          {
33
+	 *                                                                                    An array of items related to
34
+	 *                                                                                    registering capabilities.
35
+	 * @type array   $capabilities                                                        An array mapping capability
36
+	 *                                                                                    strings to core WP Role.
37
+	 *                                                                                    Something like: array(
38
+	 *                                                                                    'administrator'    => array(
39
+	 *                                                                                    'read_cap', 'edit_cap',
40
+	 *                                                                                    'delete_cap'),
41
+	 *                                                                                    'author'                =>
42
+	 *                                                                                    array( 'read_cap' )
43
+	 *                                                                                    ).
44
+	 * @type array   $capability_maps                                                     EE_Meta_Capability_Map[]
45
+	 * @return void
46
+	 * @throws EE_Error
47
+	 * @since 4.5.0
48
+	 * @see   EE_Capabilities.php for php docs on these objects.
49
+	 *                                                                                    Should be indexed by the
50
+	 *                                                                                    classname for the capability
51
+	 *                                                                                    map and values representing
52
+	 *                                                                                    the arguments for the map.
53
+	 *                                                                                    }
54
+	 */
55
+	public static function register($identifier = '', array $setup_args = [])
56
+	{
57
+		// required fields MUST be present, so let's make sure they are.
58
+		if ($identifier === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
59
+			throw new EE_Error(
60
+				esc_html__(
61
+					'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".',
62
+					'event_espresso'
63
+				)
64
+			);
65
+		}
66
+		// make sure we don't register twice
67
+		if (isset(self::$_registry[ $identifier ])) {
68
+			return;
69
+		}
70
+		// make sure this is not registered too late or too early.
71
+		if (
72
+			! did_action('AHEE__EE_System__load_espresso_addons')
73
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
74
+		) {
75
+			EE_Error::doing_it_wrong(
76
+				__METHOD__,
77
+				sprintf(
78
+					esc_html__(
79
+						'%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.',
80
+						'event_espresso'
81
+					),
82
+					$identifier
83
+				),
84
+				'4.5.0'
85
+			);
86
+		}
87
+		// some preliminary sanitization and setting to the $_registry property
88
+		self::$_registry[ $identifier ] = [
89
+			'caps'     => isset($setup_args['capabilities']) && is_array($setup_args['capabilities'])
90
+				? $setup_args['capabilities']
91
+				: [],
92
+			'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : [],
93
+		];
94
+		// set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once)
95
+		add_filter(
96
+			'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
97
+			['EE_Register_Capabilities', 'register_capabilities']
98
+		);
99
+		// add filter for cap maps
100
+		add_filter(
101
+			'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
102
+			['EE_Register_Capabilities', 'register_cap_maps']
103
+		);
104
+	}
105 105
 
106 106
 
107
-    /**
108
-     * callback for FHEE__EE_Capabilities__init_caps_map__caps filter.
109
-     * Takes care of registering additional capabilities to the caps map.   Note, that this also on the initial
110
-     * registration ensures that new capabilities are added to existing roles.
111
-     *
112
-     * @param array $incoming_caps The original caps map.
113
-     * @return array merged in new caps.
114
-     */
115
-    public static function register_capabilities(array $incoming_caps)
116
-    {
117
-        foreach (self::$_registry as $caps_and_cap_map) {
118
-            $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']);
119
-        }
120
-        return $incoming_caps;
121
-    }
107
+	/**
108
+	 * callback for FHEE__EE_Capabilities__init_caps_map__caps filter.
109
+	 * Takes care of registering additional capabilities to the caps map.   Note, that this also on the initial
110
+	 * registration ensures that new capabilities are added to existing roles.
111
+	 *
112
+	 * @param array $incoming_caps The original caps map.
113
+	 * @return array merged in new caps.
114
+	 */
115
+	public static function register_capabilities(array $incoming_caps)
116
+	{
117
+		foreach (self::$_registry as $caps_and_cap_map) {
118
+			$incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']);
119
+		}
120
+		return $incoming_caps;
121
+	}
122 122
 
123 123
 
124
-    /**
125
-     * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of
126
-     * capability maps for the WP meta_caps filter called in EE_Capabilities.
127
-     *
128
-     * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array.
129
-     * @return EE_Meta_Capability_Map[]
130
-     * @throws EE_Error
131
-     * @since 4.5.0
132
-     */
133
-    public static function register_cap_maps(array $cap_maps)
134
-    {
135
-        // loop through and instantiate cap maps.
136
-        foreach (self::$_registry as $identifier => $setup) {
137
-            if (! isset($setup['cap_maps'])) {
138
-                continue;
139
-            }
140
-            foreach ($setup['cap_maps'] as $cap_class => $args) {
124
+	/**
125
+	 * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of
126
+	 * capability maps for the WP meta_caps filter called in EE_Capabilities.
127
+	 *
128
+	 * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array.
129
+	 * @return EE_Meta_Capability_Map[]
130
+	 * @throws EE_Error
131
+	 * @since 4.5.0
132
+	 */
133
+	public static function register_cap_maps(array $cap_maps)
134
+	{
135
+		// loop through and instantiate cap maps.
136
+		foreach (self::$_registry as $identifier => $setup) {
137
+			if (! isset($setup['cap_maps'])) {
138
+				continue;
139
+			}
140
+			foreach ($setup['cap_maps'] as $cap_class => $args) {
141 141
 
142
-                /**
143
-                 * account for cases where capability maps may be indexed
144
-                 * numerically to allow for the same map class to be utilized
145
-                 * In those cases, maps will be setup in an array like:
146
-                 * array(
147
-                 *    0 => array( 'EE_Meta_Capability' => array(
148
-                 *        'ee_edit_cap', array( 'Object_Name',
149
-                 *        'ee_edit_published_cap',
150
-                 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
151
-                 *        ) )
152
-                 *    1 => ...
153
-                 * )
154
-                 * instead of:
155
-                 * array(
156
-                 *    'EE_Meta_Capability' => array(
157
-                 *        'ee_edit_cap', array( 'Object_Name',
158
-                 *        'ee_edit_published_cap',
159
-                 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
160
-                 *        ),
161
-                 *    ...
162
-                 * )
163
-                 */
164
-                if (is_numeric($cap_class)) {
165
-                    $cap_class = key($args);
166
-                    $args      = $args[ $cap_class ];
167
-                }
142
+				/**
143
+				 * account for cases where capability maps may be indexed
144
+				 * numerically to allow for the same map class to be utilized
145
+				 * In those cases, maps will be setup in an array like:
146
+				 * array(
147
+				 *    0 => array( 'EE_Meta_Capability' => array(
148
+				 *        'ee_edit_cap', array( 'Object_Name',
149
+				 *        'ee_edit_published_cap',
150
+				 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
151
+				 *        ) )
152
+				 *    1 => ...
153
+				 * )
154
+				 * instead of:
155
+				 * array(
156
+				 *    'EE_Meta_Capability' => array(
157
+				 *        'ee_edit_cap', array( 'Object_Name',
158
+				 *        'ee_edit_published_cap',
159
+				 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
160
+				 *        ),
161
+				 *    ...
162
+				 * )
163
+				 */
164
+				if (is_numeric($cap_class)) {
165
+					$cap_class = key($args);
166
+					$args      = $args[ $cap_class ];
167
+				}
168 168
 
169
-                if (! class_exists($cap_class)) {
170
-                    throw new EE_Error(
171
-                        sprintf(
172
-                            esc_html__(
173
-                                'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments',
174
-                                'event_espresso'
175
-                            ),
176
-                            $identifier
177
-                        )
178
-                    );
179
-                }
169
+				if (! class_exists($cap_class)) {
170
+					throw new EE_Error(
171
+						sprintf(
172
+							esc_html__(
173
+								'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments',
174
+								'event_espresso'
175
+							),
176
+							$identifier
177
+						)
178
+					);
179
+				}
180 180
 
181
-                if (count($args) !== 2) {
182
-                    throw new EE_Error(
183
-                        sprintf(
184
-                            esc_html__(
185
-                                'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.',
186
-                                'event_espresso'
187
-                            ),
188
-                            $identifier
189
-                        )
190
-                    );
191
-                }
192
-                $cap_maps[] = new $cap_class($args[0], $args[1]);
193
-            }
194
-        }
195
-        return $cap_maps;
196
-    }
181
+				if (count($args) !== 2) {
182
+					throw new EE_Error(
183
+						sprintf(
184
+							esc_html__(
185
+								'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.',
186
+								'event_espresso'
187
+							),
188
+							$identifier
189
+						)
190
+					);
191
+				}
192
+				$cap_maps[] = new $cap_class($args[0], $args[1]);
193
+			}
194
+		}
195
+		return $cap_maps;
196
+	}
197 197
 
198 198
 
199
-    /**
200
-     * @param string $identifier
201
-     * @throws InvalidArgumentException
202
-     * @throws InvalidDataTypeException
203
-     * @throws InvalidInterfaceException
204
-     */
205
-    public static function deregister($identifier = '')
206
-    {
207
-        if (! empty(self::$_registry[ $identifier ])) {
208
-            if (! empty(self::$_registry[ $identifier ]['caps'])) {
209
-                // if it's too early to remove capabilities, wait to do this until core is loaded and ready
210
-                $caps_to_remove = self::$_registry[ $identifier ]['caps'];
211
-                if (did_action('AHEE__EE_System__core_loaded_and_ready')) {
212
-                    $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
213
-                    $capabilities->removeCaps($caps_to_remove);
214
-                } else {
215
-                    add_action(
216
-                        'AHEE__EE_System__core_loaded_and_ready',
217
-                        function () use ($caps_to_remove) {
218
-                            $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
219
-                            $capabilities->removeCaps($caps_to_remove);
220
-                        }
221
-                    );
222
-                }
223
-            }
224
-        }
225
-        unset(self::$_registry[ $identifier ]);
226
-    }
199
+	/**
200
+	 * @param string $identifier
201
+	 * @throws InvalidArgumentException
202
+	 * @throws InvalidDataTypeException
203
+	 * @throws InvalidInterfaceException
204
+	 */
205
+	public static function deregister($identifier = '')
206
+	{
207
+		if (! empty(self::$_registry[ $identifier ])) {
208
+			if (! empty(self::$_registry[ $identifier ]['caps'])) {
209
+				// if it's too early to remove capabilities, wait to do this until core is loaded and ready
210
+				$caps_to_remove = self::$_registry[ $identifier ]['caps'];
211
+				if (did_action('AHEE__EE_System__core_loaded_and_ready')) {
212
+					$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
213
+					$capabilities->removeCaps($caps_to_remove);
214
+				} else {
215
+					add_action(
216
+						'AHEE__EE_System__core_loaded_and_ready',
217
+						function () use ($caps_to_remove) {
218
+							$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
219
+							$capabilities->removeCaps($caps_to_remove);
220
+						}
221
+					);
222
+				}
223
+			}
224
+		}
225
+		unset(self::$_registry[ $identifier ]);
226
+	}
227 227
 }
Please login to merge, or discard this patch.