Completed
Branch dependabot/npm_and_yarn/babel/... (4d99b1)
by
unknown
20:39 queued 17:53
created
core/EE_Session.core.php 2 patches
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -246,22 +246,22 @@  discard block
 block discarded – undo
246 246
         // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
247 247
         // (which currently fires on the init hook at priority 9),
248 248
         // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
249
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
249
+        if ( ! apply_filters('FHEE_load_EE_Session', true)) {
250 250
             return;
251 251
         }
252 252
         $this->session_start_handler = $session_start_handler;
253 253
         $this->session_lifespan = $lifespan;
254 254
         $this->request = $request;
255
-        if (! defined('ESPRESSO_SESSION')) {
255
+        if ( ! defined('ESPRESSO_SESSION')) {
256 256
             define('ESPRESSO_SESSION', true);
257 257
         }
258 258
         // retrieve session options from db
259 259
         $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
260
-        if (! empty($session_settings)) {
260
+        if ( ! empty($session_settings)) {
261 261
             // cycle though existing session options
262 262
             foreach ($session_settings as $var_name => $session_setting) {
263 263
                 // set values for class properties
264
-                $var_name = '_' . $var_name;
264
+                $var_name = '_'.$var_name;
265 265
                 $this->{$var_name} = $session_setting;
266 266
             }
267 267
         }
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
     public function open_session()
323 323
     {
324 324
         // check for existing session and retrieve it from db
325
-        if (! $this->_espresso_session()) {
325
+        if ( ! $this->_espresso_session()) {
326 326
             // or just start a new one
327 327
             $this->_create_espresso_session();
328 328
         }
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
             EE_Session::SAVE_STATE_CLEAN,
400 400
             EE_Session::SAVE_STATE_DIRTY,
401 401
         ];
402
-        if (! in_array($save_state, $valid_save_states, true)) {
402
+        if ( ! in_array($save_state, $valid_save_states, true)) {
403 403
             $save_state = EE_Session::SAVE_STATE_DIRTY;
404 404
         }
405 405
         $this->save_state = $save_state;
@@ -417,9 +417,9 @@  discard block
 block discarded – undo
417 417
         // set some defaults
418 418
         foreach ($this->_default_session_vars as $key => $default_var) {
419 419
             if (is_array($default_var)) {
420
-                $this->_session_data[ $key ] = array();
420
+                $this->_session_data[$key] = array();
421 421
             } else {
422
-                $this->_session_data[ $key ] = '';
422
+                $this->_session_data[$key] = '';
423 423
             }
424 424
         }
425 425
     }
@@ -555,8 +555,8 @@  discard block
 block discarded – undo
555 555
             $this->reset_checkout();
556 556
             $this->reset_transaction();
557 557
         }
558
-        if (! empty($key)) {
559
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
558
+        if ( ! empty($key)) {
559
+            return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null;
560 560
         }
561 561
         return $this->_session_data;
562 562
     }
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
             return false;
585 585
         }
586 586
         foreach ($data as $key => $value) {
587
-            if (isset($this->_default_session_vars[ $key ])) {
587
+            if (isset($this->_default_session_vars[$key])) {
588 588
                 EE_Error::add_error(
589 589
                     sprintf(
590 590
                         esc_html__(
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
                 );
600 600
                 return false;
601 601
             }
602
-            $this->_session_data[ $key ] = $value;
602
+            $this->_session_data[$key] = $value;
603 603
             $this->setSaveState();
604 604
         }
605 605
         return true;
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
         $this->_user_agent = $this->request->userAgent();
631 631
         // now let's retrieve what's in the db
632 632
         $session_data = $this->_retrieve_session_data();
633
-        if (! empty($session_data)) {
633
+        if ( ! empty($session_data)) {
634 634
             // get the current time in UTC
635 635
             $this->_time = $this->_time !== null ? $this->_time : time();
636 636
             // and reset the session expiration
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
             // set initial site access time and the session expiration
642 642
             $this->_set_init_access_and_expiration();
643 643
             // set referer
644
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = esc_attr(
644
+            $this->_session_data['pages_visited'][$this->_session_data['init_access']] = esc_attr(
645 645
                 $this->request->getServerParam('HTTP_REFERER')
646 646
             );
647 647
             // no previous session = go back and create one (on top of the data above)
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
      */
680 680
     protected function _retrieve_session_data()
681 681
     {
682
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
682
+        $ssn_key = EE_Session::session_id_prefix.$this->_sid;
683 683
         try {
684 684
             // we're using WP's Transient API to store session data using the PHP session ID as the option name
685 685
             $session_data = $this->cache_storage->get($ssn_key, false);
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
             }
689 689
             if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
690 690
                 $hash_check = $this->cache_storage->get(
691
-                    EE_Session::hash_check_prefix . $this->_sid,
691
+                    EE_Session::hash_check_prefix.$this->_sid,
692 692
                     false
693 693
                 );
694 694
                 if ($hash_check && $hash_check !== md5($session_data)) {
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
                                 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
699 699
                                 'event_espresso'
700 700
                             ),
701
-                            EE_Session::session_id_prefix . $this->_sid
701
+                            EE_Session::session_id_prefix.$this->_sid
702 702
                         ),
703 703
                         __FILE__,
704 704
                         __FUNCTION__,
@@ -712,17 +712,17 @@  discard block
 block discarded – undo
712 712
             $row = $wpdb->get_row(
713 713
                 $wpdb->prepare(
714 714
                     "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
715
-                    '_transient_' . $ssn_key
715
+                    '_transient_'.$ssn_key
716 716
                 )
717 717
             );
718 718
             $session_data = is_object($row) ? $row->option_value : null;
719 719
             if ($session_data) {
720 720
                 $session_data = preg_replace_callback(
721 721
                     '!s:(d+):"(.*?)";!',
722
-                    function ($match) {
722
+                    function($match) {
723 723
                         return $match[1] === strlen($match[2])
724 724
                             ? $match[0]
725
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
725
+                            : 's:'.strlen($match[2]).':"'.$match[2].'";';
726 726
                     },
727 727
                     $session_data
728 728
                 );
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
         $session_data = $this->encryption instanceof EE_Encryption
734 734
             ? $this->encryption->base64_string_decode($session_data)
735 735
             : $session_data;
736
-        if (! is_array($session_data)) {
736
+        if ( ! is_array($session_data)) {
737 737
             try {
738 738
                 $session_data = maybe_unserialize($session_data);
739 739
             } catch (Exception $e) {
@@ -747,21 +747,21 @@  discard block
 block discarded – undo
747 747
                       . '</pre><br>'
748 748
                       . $this->find_serialize_error($session_data)
749 749
                     : '';
750
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
750
+                $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
751 751
                 throw new InvalidSessionDataException($msg, 0, $e);
752 752
             }
753 753
         }
754 754
         // just a check to make sure the session array is indeed an array
755
-        if (! is_array($session_data)) {
755
+        if ( ! is_array($session_data)) {
756 756
             // no?!?! then something is wrong
757 757
             $msg = esc_html__(
758 758
                 'The session data is missing, invalid, or corrupted.',
759 759
                 'event_espresso'
760 760
             );
761 761
             $msg .= WP_DEBUG
762
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
762
+                ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
763 763
                 : '';
764
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
764
+            $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
765 765
             throw new InvalidSessionDataException($msg);
766 766
         }
767 767
         if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
         // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
788 788
         $session_id = $this->request->requestParamIsSet('EESID')
789 789
             ? $this->request->getRequestParam('EESID')
790
-            : md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
790
+            : md5(session_id().get_current_blog_id().$this->_get_sid_salt());
791 791
         return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
792 792
     }
793 793
 
@@ -889,19 +889,19 @@  discard block
 block discarded – undo
889 889
                     $page_visit = $this->_get_page_visit();
890 890
                     if ($page_visit) {
891 891
                         // set pages visited where the first will be the http referrer
892
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
892
+                        $this->_session_data['pages_visited'][$this->_time] = $page_visit;
893 893
                         // we'll only save the last 10 page visits.
894 894
                         $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
895 895
                     }
896 896
                     break;
897 897
                 default:
898 898
                     // carry any other data over
899
-                    $session_data[ $key ] = $this->_session_data[ $key ];
899
+                    $session_data[$key] = $this->_session_data[$key];
900 900
             }
901 901
         }
902 902
         $this->_session_data = $session_data;
903 903
         // creating a new session does not require saving to the db just yet
904
-        if (! $new_session) {
904
+        if ( ! $new_session) {
905 905
             // ready? let's save
906 906
             if ($this->_save_session_to_db()) {
907 907
                 return true;
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
         }
980 980
         $transaction = $this->transaction();
981 981
         if ($transaction instanceof EE_Transaction) {
982
-            if (! $transaction->ID()) {
982
+            if ( ! $transaction->ID()) {
983 983
                 $transaction->save();
984 984
             }
985 985
             $this->_session_data['transaction'] = $transaction->ID();
@@ -993,14 +993,14 @@  discard block
 block discarded – undo
993 993
         // maybe save hash check
994 994
         if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
995 995
             $this->cache_storage->add(
996
-                EE_Session::hash_check_prefix . $this->_sid,
996
+                EE_Session::hash_check_prefix.$this->_sid,
997 997
                 md5($session_data),
998 998
                 $this->session_lifespan->inSeconds()
999 999
             );
1000 1000
         }
1001 1001
         // we're using the Transient API for storing session data,
1002 1002
         $saved = $this->cache_storage->add(
1003
-            EE_Session::session_id_prefix . $this->_sid,
1003
+            EE_Session::session_id_prefix.$this->_sid,
1004 1004
             $session_data,
1005 1005
             $this->session_lifespan->inSeconds()
1006 1006
         );
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
      */
1016 1016
     public function _get_page_visit()
1017 1017
     {
1018
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
1018
+        $page_visit = home_url('/').'wp-admin/admin-ajax.php';
1019 1019
         // check for request url
1020 1020
         if ($this->request->serverParamIsSet('REQUEST_URI')) {
1021 1021
             $page_id = '?';
@@ -1027,14 +1027,14 @@  discard block
 block discarded – undo
1027 1027
             // check for page_id in SERVER REQUEST
1028 1028
             if ($this->request->requestParamIsSet('page_id')) {
1029 1029
                 // rebuild $e_reg without any of the extra parameters
1030
-                $page_id .= 'page_id=' . $this->request->getRequestParam('page_id', 0, 'int') . '&amp;';
1030
+                $page_id .= 'page_id='.$this->request->getRequestParam('page_id', 0, 'int').'&amp;';
1031 1031
             }
1032 1032
             // check for $e_reg in SERVER REQUEST
1033 1033
             if ($this->request->requestParamIsSet('ee')) {
1034 1034
                 // rebuild $e_reg without any of the extra parameters
1035
-                $e_reg = 'ee=' . $this->request->getRequestParam('ee');
1035
+                $e_reg = 'ee='.$this->request->getRequestParam('ee');
1036 1036
             }
1037
-            $page_visit = esc_url(rtrim($http_host . $request_uri . $page_id . $e_reg, '?'));
1037
+            $page_visit = esc_url(rtrim($http_host.$request_uri.$page_id.$e_reg, '?'));
1038 1038
         }
1039 1039
         return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
1040 1040
     }
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
 // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/>
1072 1072
 // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b>
1073 1073
 // </h3>';
1074
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1074
+        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
1075 1075
         $this->reset_cart();
1076 1076
         $this->reset_checkout();
1077 1077
         $this->reset_transaction();
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
     public function reset_data($data_to_reset = array(), $show_all_notices = false)
1095 1095
     {
1096 1096
         // if $data_to_reset is not in an array, then put it in one
1097
-        if (! is_array($data_to_reset)) {
1097
+        if ( ! is_array($data_to_reset)) {
1098 1098
             $data_to_reset = array($data_to_reset);
1099 1099
         }
1100 1100
         // nothing ??? go home!
@@ -1114,11 +1114,11 @@  discard block
 block discarded – undo
1114 1114
         // since $data_to_reset is an array, cycle through the values
1115 1115
         foreach ($data_to_reset as $reset) {
1116 1116
             // first check to make sure it is a valid session var
1117
-            if (isset($this->_session_data[ $reset ])) {
1117
+            if (isset($this->_session_data[$reset])) {
1118 1118
                 // then check to make sure it is not a default var
1119
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1119
+                if ( ! array_key_exists($reset, $this->_default_session_vars)) {
1120 1120
                     // remove session var
1121
-                    unset($this->_session_data[ $reset ]);
1121
+                    unset($this->_session_data[$reset]);
1122 1122
                     $this->setSaveState();
1123 1123
                     if ($show_all_notices) {
1124 1124
                         EE_Error::add_success(
@@ -1221,7 +1221,7 @@  discard block
 block discarded – undo
1221 1221
             // or use that for the new transient cleanup query limit
1222 1222
             add_filter(
1223 1223
                 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1224
-                function () use ($expired_session_transient_delete_query_limit) {
1224
+                function() use ($expired_session_transient_delete_query_limit) {
1225 1225
                     return $expired_session_transient_delete_query_limit;
1226 1226
                 }
1227 1227
             );
@@ -1239,7 +1239,7 @@  discard block
 block discarded – undo
1239 1239
         $error = '<pre>';
1240 1240
         $data2 = preg_replace_callback(
1241 1241
             '!s:(\d+):"(.*?)";!',
1242
-            function ($match) {
1242
+            function($match) {
1243 1243
                 return ($match[1] === strlen($match[2]))
1244 1244
                     ? $match[0]
1245 1245
                     : 's:'
@@ -1251,13 +1251,13 @@  discard block
 block discarded – undo
1251 1251
             $data1
1252 1252
         );
1253 1253
         $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1254
-        $error .= $data1 . PHP_EOL;
1255
-        $error .= $data2 . PHP_EOL;
1254
+        $error .= $data1.PHP_EOL;
1255
+        $error .= $data2.PHP_EOL;
1256 1256
         for ($i = 0; $i < $max; $i++) {
1257
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1258
-                $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1259
-                $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1260
-                $error .= "\t-> Line Number = $i" . PHP_EOL;
1257
+            if (@$data1[$i] !== @$data2[$i]) {
1258
+                $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL;
1259
+                $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL;
1260
+                $error .= "\t-> Line Number = $i".PHP_EOL;
1261 1261
                 $start = ($i - 20);
1262 1262
                 $start = ($start < 0) ? 0 : $start;
1263 1263
                 $length = 40;
@@ -1272,7 +1272,7 @@  discard block
 block discarded – undo
1272 1272
                 $error .= "\t-> Section Data1  = ";
1273 1273
                 $error .= substr_replace(
1274 1274
                     substr($data1, $start, $length),
1275
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1275
+                    "<b style=\"color:green\">{$data1[$i]}</b>",
1276 1276
                     $rpoint,
1277 1277
                     $rlength
1278 1278
                 );
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
                 $error .= "\t-> Section Data2  = ";
1281 1281
                 $error .= substr_replace(
1282 1282
                     substr($data2, $start, $length),
1283
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1283
+                    "<b style=\"color:red\">{$data2[$i]}</b>",
1284 1284
                     $rpoint,
1285 1285
                     $rlength
1286 1286
                 );
@@ -1311,7 +1311,7 @@  discard block
 block discarded – undo
1311 1311
     public function garbageCollection()
1312 1312
     {
1313 1313
         // only perform during regular requests if last garbage collection was over an hour ago
1314
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1314
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1315 1315
             $this->_last_gc = time();
1316 1316
             $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1317 1317
             /** @type WPDB $wpdb */
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
                 // AND option_value < 1508368198 LIMIT 50
1347 1347
                 $expired_sessions = $wpdb->get_col($SQL);
1348 1348
                 // valid results?
1349
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1349
+                if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1350 1350
                     $this->cache_storage->deleteMany($expired_sessions, true);
1351 1351
                 }
1352 1352
             }
Please login to merge, or discard this patch.
Indentation   +1312 added lines, -1312 removed lines patch added patch discarded remove patch
@@ -23,1310 +23,1310 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class EE_Session implements SessionIdentifierInterface
25 25
 {
26
-    const session_id_prefix = 'ee_ssn_';
27
-
28
-    const hash_check_prefix = 'ee_shc_';
29
-
30
-    const OPTION_NAME_SETTINGS = 'ee_session_settings';
31
-
32
-    const STATUS_CLOSED = 0;
33
-
34
-    const STATUS_OPEN = 1;
35
-
36
-    const SAVE_STATE_CLEAN = 'clean';
37
-    const SAVE_STATE_DIRTY = 'dirty';
38
-
39
-
40
-    /**
41
-     * instance of the EE_Session object
42
-     *
43
-     * @var EE_Session
44
-     */
45
-    private static $_instance;
46
-
47
-    /**
48
-     * @var CacheStorageInterface $cache_storage
49
-     */
50
-    protected $cache_storage;
51
-
52
-    /**
53
-     * @var EE_Encryption $encryption
54
-     */
55
-    protected $encryption;
56
-
57
-    /**
58
-     * @var SessionStartHandler $session_start_handler
59
-     */
60
-    protected $session_start_handler;
61
-
62
-    /**
63
-     * the session id
64
-     *
65
-     * @var string
66
-     */
67
-    private $_sid;
68
-
69
-    /**
70
-     * session id salt
71
-     *
72
-     * @var string
73
-     */
74
-    private $_sid_salt;
75
-
76
-    /**
77
-     * session data
78
-     *
79
-     * @var array
80
-     */
81
-    private $_session_data = array();
82
-
83
-    /**
84
-     * how long an EE session lasts
85
-     * default session lifespan of 1 hour (for not so instant IPNs)
86
-     *
87
-     * @var SessionLifespan $session_lifespan
88
-     */
89
-    private $session_lifespan;
90
-
91
-    /**
92
-     * session expiration time as Unix timestamp in GMT
93
-     *
94
-     * @var int
95
-     */
96
-    private $_expiration;
97
-
98
-    /**
99
-     * whether or not session has expired at some point
100
-     *
101
-     * @var boolean
102
-     */
103
-    private $_expired = false;
104
-
105
-    /**
106
-     * current time as Unix timestamp in GMT
107
-     *
108
-     * @var int
109
-     */
110
-    private $_time;
111
-
112
-    /**
113
-     * whether to encrypt session data
114
-     *
115
-     * @var bool
116
-     */
117
-    private $_use_encryption;
118
-
119
-    /**
120
-     * well... according to the server...
121
-     *
122
-     * @var null
123
-     */
124
-    private $_user_agent;
125
-
126
-    /**
127
-     * do you really trust the server ?
128
-     *
129
-     * @var null
130
-     */
131
-    private $_ip_address;
132
-
133
-    /**
134
-     * current WP user_id
135
-     *
136
-     * @var null
137
-     */
138
-    private $_wp_user_id;
139
-
140
-    /**
141
-     * array for defining default session vars
142
-     *
143
-     * @var array
144
-     */
145
-    private $_default_session_vars = array(
146
-        'id'            => null,
147
-        'user_id'       => null,
148
-        'ip_address'    => null,
149
-        'user_agent'    => null,
150
-        'init_access'   => null,
151
-        'last_access'   => null,
152
-        'expiration'    => null,
153
-        'pages_visited' => array(),
154
-    );
155
-
156
-    /**
157
-     * timestamp for when last garbage collection cycle was performed
158
-     *
159
-     * @var int $_last_gc
160
-     */
161
-    private $_last_gc;
162
-
163
-    /**
164
-     * @var RequestInterface $request
165
-     */
166
-    protected $request;
167
-
168
-    /**
169
-     * whether session is active or not
170
-     *
171
-     * @var int $status
172
-     */
173
-    private $status = EE_Session::STATUS_CLOSED;
174
-
175
-    /**
176
-     * whether session data has changed therefore requiring a session save
177
-     *
178
-     * @var string $save_state
179
-     */
180
-    private $save_state = EE_Session::SAVE_STATE_CLEAN;
181
-
182
-
183
-    /**
184
-     * @singleton method used to instantiate class object
185
-     * @param CacheStorageInterface $cache_storage
186
-     * @param SessionLifespan|null  $lifespan
187
-     * @param RequestInterface      $request
188
-     * @param SessionStartHandler   $session_start_handler
189
-     * @param EE_Encryption         $encryption
190
-     * @return EE_Session
191
-     * @throws InvalidArgumentException
192
-     * @throws InvalidDataTypeException
193
-     * @throws InvalidInterfaceException
194
-     */
195
-    public static function instance(
196
-        CacheStorageInterface $cache_storage = null,
197
-        SessionLifespan $lifespan = null,
198
-        RequestInterface $request = null,
199
-        SessionStartHandler $session_start_handler = null,
200
-        EE_Encryption $encryption = null
201
-    ) {
202
-        // check if class object is instantiated
203
-        // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
204
-        // add_filter( 'FHEE_load_EE_Session', '__return_false' );
205
-        if (
206
-            ! self::$_instance instanceof EE_Session
207
-            && $cache_storage instanceof CacheStorageInterface
208
-            && $lifespan instanceof SessionLifespan
209
-            && $request instanceof RequestInterface
210
-            && $session_start_handler instanceof SessionStartHandler
211
-            && apply_filters('FHEE_load_EE_Session', true)
212
-        ) {
213
-            self::$_instance = new self(
214
-                $cache_storage,
215
-                $lifespan,
216
-                $request,
217
-                $session_start_handler,
218
-                $encryption
219
-            );
220
-        }
221
-        return self::$_instance;
222
-    }
223
-
224
-
225
-    /**
226
-     * protected constructor to prevent direct creation
227
-     *
228
-     * @param CacheStorageInterface $cache_storage
229
-     * @param SessionLifespan       $lifespan
230
-     * @param RequestInterface      $request
231
-     * @param SessionStartHandler   $session_start_handler
232
-     * @param EE_Encryption         $encryption
233
-     * @throws InvalidArgumentException
234
-     * @throws InvalidDataTypeException
235
-     * @throws InvalidInterfaceException
236
-     */
237
-    protected function __construct(
238
-        CacheStorageInterface $cache_storage,
239
-        SessionLifespan $lifespan,
240
-        RequestInterface $request,
241
-        SessionStartHandler $session_start_handler,
242
-        EE_Encryption $encryption = null
243
-    ) {
244
-        // session loading is turned ON by default,
245
-        // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
246
-        // (which currently fires on the init hook at priority 9),
247
-        // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
248
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
249
-            return;
250
-        }
251
-        $this->session_start_handler = $session_start_handler;
252
-        $this->session_lifespan = $lifespan;
253
-        $this->request = $request;
254
-        if (! defined('ESPRESSO_SESSION')) {
255
-            define('ESPRESSO_SESSION', true);
256
-        }
257
-        // retrieve session options from db
258
-        $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
259
-        if (! empty($session_settings)) {
260
-            // cycle though existing session options
261
-            foreach ($session_settings as $var_name => $session_setting) {
262
-                // set values for class properties
263
-                $var_name = '_' . $var_name;
264
-                $this->{$var_name} = $session_setting;
265
-            }
266
-        }
267
-        $this->cache_storage = $cache_storage;
268
-        // are we using encryption?
269
-        $this->_use_encryption = $encryption instanceof EE_Encryption
270
-                                 && EE_Registry::instance()->CFG->admin->encode_session_data();
271
-        // encrypt data via: $this->encryption->encrypt();
272
-        $this->encryption = $encryption;
273
-        // filter hook allows outside functions/classes/plugins to change default empty cart
274
-        $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
275
-        array_merge($this->_default_session_vars, $extra_default_session_vars);
276
-        // apply default session vars
277
-        $this->_set_defaults();
278
-        add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
279
-        // check request for 'clear_session' param
280
-        add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
281
-        // once everything is all said and done,
282
-        add_action('shutdown', array($this, 'update'), 100);
283
-        add_action('shutdown', array($this, 'garbageCollection'), 1000);
284
-        $this->configure_garbage_collection_filters();
285
-    }
286
-
287
-
288
-    /**
289
-     * @return bool
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     */
294
-    public static function isLoadedAndActive()
295
-    {
296
-        return did_action('AHEE__EE_System__core_loaded_and_ready')
297
-               && EE_Session::instance() instanceof EE_Session
298
-               && EE_Session::instance()->isActive();
299
-    }
300
-
301
-
302
-    /**
303
-     * @return bool
304
-     */
305
-    public function isActive()
306
-    {
307
-        return $this->status === EE_Session::STATUS_OPEN;
308
-    }
309
-
310
-
311
-    /**
312
-     * @return void
313
-     * @throws EE_Error
314
-     * @throws InvalidArgumentException
315
-     * @throws InvalidDataTypeException
316
-     * @throws InvalidInterfaceException
317
-     * @throws InvalidSessionDataException
318
-     * @throws RuntimeException
319
-     * @throws ReflectionException
320
-     */
321
-    public function open_session()
322
-    {
323
-        // check for existing session and retrieve it from db
324
-        if (! $this->_espresso_session()) {
325
-            // or just start a new one
326
-            $this->_create_espresso_session();
327
-        }
328
-    }
329
-
330
-
331
-    /**
332
-     * @return bool
333
-     */
334
-    public function expired()
335
-    {
336
-        return $this->_expired;
337
-    }
338
-
339
-
340
-    /**
341
-     * @return void
342
-     */
343
-    public function reset_expired()
344
-    {
345
-        $this->_expired = false;
346
-    }
347
-
348
-
349
-    /**
350
-     * @return int
351
-     */
352
-    public function expiration()
353
-    {
354
-        return $this->_expiration;
355
-    }
356
-
357
-
358
-    /**
359
-     * @return int
360
-     */
361
-    public function extension()
362
-    {
363
-        return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
364
-    }
365
-
366
-
367
-    /**
368
-     * @param int $time number of seconds to add to session expiration
369
-     */
370
-    public function extend_expiration($time = 0)
371
-    {
372
-        $time = $time ? $time : $this->extension();
373
-        $this->_expiration += absint($time);
374
-    }
375
-
376
-
377
-    /**
378
-     * @return int
379
-     */
380
-    public function lifespan()
381
-    {
382
-        return $this->session_lifespan->inSeconds();
383
-    }
384
-
385
-
386
-    /**
387
-     * Marks whether the session data has been updated or not.
388
-     * Valid options are:
389
-     *      EE_Session::SAVE_STATE_CLEAN - session data remains unchanged and updating is not necessary
390
-     *      EE_Session::SAVE_STATE_DIRTY - session data has changed since last save and needs to be updated
391
-     * default value is EE_Session::SAVE_STATE_DIRTY
392
-     *
393
-     * @param string $save_state
394
-     */
395
-    public function setSaveState($save_state = EE_Session::SAVE_STATE_DIRTY)
396
-    {
397
-        $valid_save_states = [
398
-            EE_Session::SAVE_STATE_CLEAN,
399
-            EE_Session::SAVE_STATE_DIRTY,
400
-        ];
401
-        if (! in_array($save_state, $valid_save_states, true)) {
402
-            $save_state = EE_Session::SAVE_STATE_DIRTY;
403
-        }
404
-        $this->save_state = $save_state;
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * This just sets some defaults for the _session data property
411
-     *
412
-     * @return void
413
-     */
414
-    private function _set_defaults()
415
-    {
416
-        // set some defaults
417
-        foreach ($this->_default_session_vars as $key => $default_var) {
418
-            if (is_array($default_var)) {
419
-                $this->_session_data[ $key ] = array();
420
-            } else {
421
-                $this->_session_data[ $key ] = '';
422
-            }
423
-        }
424
-    }
425
-
426
-
427
-    /**
428
-     * @retrieve  session data
429
-     * @return    string
430
-     */
431
-    public function id()
432
-    {
433
-        return $this->_sid;
434
-    }
435
-
436
-
437
-    /**
438
-     * @param \EE_Cart $cart
439
-     * @return bool
440
-     */
441
-    public function set_cart(EE_Cart $cart)
442
-    {
443
-        $this->_session_data['cart'] = $cart;
444
-        $this->setSaveState();
445
-        return true;
446
-    }
447
-
448
-
449
-    /**
450
-     * reset_cart
451
-     */
452
-    public function reset_cart()
453
-    {
454
-        do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
455
-        $this->_session_data['cart'] = null;
456
-        $this->setSaveState();
457
-    }
458
-
459
-
460
-    /**
461
-     * @return \EE_Cart
462
-     */
463
-    public function cart()
464
-    {
465
-        return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
466
-            ? $this->_session_data['cart']
467
-            : null;
468
-    }
469
-
470
-
471
-    /**
472
-     * @param \EE_Checkout $checkout
473
-     * @return bool
474
-     */
475
-    public function set_checkout(EE_Checkout $checkout)
476
-    {
477
-        $this->_session_data['checkout'] = $checkout;
478
-        $this->setSaveState();
479
-        return true;
480
-    }
481
-
482
-
483
-    /**
484
-     * reset_checkout
485
-     */
486
-    public function reset_checkout()
487
-    {
488
-        do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
489
-        $this->_session_data['checkout'] = null;
490
-        $this->setSaveState();
491
-    }
492
-
493
-
494
-    /**
495
-     * @return \EE_Checkout
496
-     */
497
-    public function checkout()
498
-    {
499
-        return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
500
-            ? $this->_session_data['checkout']
501
-            : null;
502
-    }
503
-
504
-
505
-    /**
506
-     * @param \EE_Transaction $transaction
507
-     * @return bool
508
-     * @throws EE_Error
509
-     */
510
-    public function set_transaction(EE_Transaction $transaction)
511
-    {
512
-        // first remove the session from the transaction before we save the transaction in the session
513
-        $transaction->set_txn_session_data(null);
514
-        $this->_session_data['transaction'] = $transaction;
515
-        $this->setSaveState();
516
-        return true;
517
-    }
518
-
519
-
520
-    /**
521
-     * reset_transaction
522
-     */
523
-    public function reset_transaction()
524
-    {
525
-        do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
526
-        $this->_session_data['transaction'] = null;
527
-        $this->setSaveState();
528
-    }
529
-
530
-
531
-    /**
532
-     * @return \EE_Transaction
533
-     */
534
-    public function transaction()
535
-    {
536
-        return isset($this->_session_data['transaction'])
537
-               && $this->_session_data['transaction'] instanceof EE_Transaction
538
-            ? $this->_session_data['transaction']
539
-            : null;
540
-    }
541
-
542
-
543
-    /**
544
-     * retrieve session data
545
-     *
546
-     * @param null $key
547
-     * @param bool $reset_cache
548
-     * @return array
549
-     */
550
-    public function get_session_data($key = null, $reset_cache = false)
551
-    {
552
-        if ($reset_cache) {
553
-            $this->reset_cart();
554
-            $this->reset_checkout();
555
-            $this->reset_transaction();
556
-        }
557
-        if (! empty($key)) {
558
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
559
-        }
560
-        return $this->_session_data;
561
-    }
562
-
563
-
564
-    /**
565
-     * Returns TRUE on success, FALSE on fail
566
-     *
567
-     * @param array $data
568
-     * @return bool
569
-     */
570
-    public function set_session_data($data)
571
-    {
572
-        // nothing ??? bad data ??? go home!
573
-        if (empty($data) || ! is_array($data)) {
574
-            EE_Error::add_error(
575
-                esc_html__(
576
-                    'No session data or invalid session data was provided.',
577
-                    'event_espresso'
578
-                ),
579
-                __FILE__,
580
-                __FUNCTION__,
581
-                __LINE__
582
-            );
583
-            return false;
584
-        }
585
-        foreach ($data as $key => $value) {
586
-            if (isset($this->_default_session_vars[ $key ])) {
587
-                EE_Error::add_error(
588
-                    sprintf(
589
-                        esc_html__(
590
-                            'Sorry! %s is a default session datum and can not be reset.',
591
-                            'event_espresso'
592
-                        ),
593
-                        $key
594
-                    ),
595
-                    __FILE__,
596
-                    __FUNCTION__,
597
-                    __LINE__
598
-                );
599
-                return false;
600
-            }
601
-            $this->_session_data[ $key ] = $value;
602
-            $this->setSaveState();
603
-        }
604
-        return true;
605
-    }
606
-
607
-
608
-    /**
609
-     * @initiate session
610
-     * @return bool TRUE on success, FALSE on fail
611
-     * @throws EE_Error
612
-     * @throws InvalidArgumentException
613
-     * @throws InvalidDataTypeException
614
-     * @throws InvalidInterfaceException
615
-     * @throws InvalidSessionDataException
616
-     * @throws RuntimeException
617
-     * @throws ReflectionException
618
-     */
619
-    private function _espresso_session()
620
-    {
621
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
622
-        $this->session_start_handler->startSession();
623
-        $this->status = EE_Session::STATUS_OPEN;
624
-        // get our modified session ID
625
-        $this->_sid = $this->_generate_session_id();
626
-        // and the visitors IP
627
-        $this->_ip_address = $this->request->ipAddress();
628
-        // set the "user agent"
629
-        $this->_user_agent = $this->request->userAgent();
630
-        // now let's retrieve what's in the db
631
-        $session_data = $this->_retrieve_session_data();
632
-        if (! empty($session_data)) {
633
-            // get the current time in UTC
634
-            $this->_time = $this->_time !== null ? $this->_time : time();
635
-            // and reset the session expiration
636
-            $this->_expiration = isset($session_data['expiration'])
637
-                ? $session_data['expiration']
638
-                : $this->_time + $this->session_lifespan->inSeconds();
639
-        } else {
640
-            // set initial site access time and the session expiration
641
-            $this->_set_init_access_and_expiration();
642
-            // set referer
643
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = esc_attr(
644
-                $this->request->getServerParam('HTTP_REFERER')
645
-            );
646
-            // no previous session = go back and create one (on top of the data above)
647
-            return false;
648
-        }
649
-        // now the user agent
650
-        if ($session_data['user_agent'] !== $this->_user_agent) {
651
-            return false;
652
-        }
653
-        // wait a minute... how old are you?
654
-        if ($this->_time > $this->_expiration) {
655
-            // yer too old fer me!
656
-            $this->_expired = true;
657
-            // wipe out everything that isn't a default session datum
658
-            $this->clear_session(__CLASS__, __FUNCTION__);
659
-        }
660
-        // make event espresso session data available to plugin
661
-        $this->_session_data = array_merge($this->_session_data, $session_data);
662
-        return true;
663
-    }
664
-
665
-
666
-    /**
667
-     * _get_session_data
668
-     * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
669
-     * databases
670
-     *
671
-     * @return array
672
-     * @throws EE_Error
673
-     * @throws InvalidArgumentException
674
-     * @throws InvalidSessionDataException
675
-     * @throws InvalidDataTypeException
676
-     * @throws InvalidInterfaceException
677
-     * @throws RuntimeException
678
-     */
679
-    protected function _retrieve_session_data()
680
-    {
681
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
682
-        try {
683
-            // we're using WP's Transient API to store session data using the PHP session ID as the option name
684
-            $session_data = $this->cache_storage->get($ssn_key, false);
685
-            if (empty($session_data)) {
686
-                return array();
687
-            }
688
-            if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
689
-                $hash_check = $this->cache_storage->get(
690
-                    EE_Session::hash_check_prefix . $this->_sid,
691
-                    false
692
-                );
693
-                if ($hash_check && $hash_check !== md5($session_data)) {
694
-                    EE_Error::add_error(
695
-                        sprintf(
696
-                            esc_html__(
697
-                                'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
698
-                                'event_espresso'
699
-                            ),
700
-                            EE_Session::session_id_prefix . $this->_sid
701
-                        ),
702
-                        __FILE__,
703
-                        __FUNCTION__,
704
-                        __LINE__
705
-                    );
706
-                }
707
-            }
708
-        } catch (Exception $e) {
709
-            // let's just eat that error for now and attempt to correct any corrupted data
710
-            global $wpdb;
711
-            $row = $wpdb->get_row(
712
-                $wpdb->prepare(
713
-                    "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
714
-                    '_transient_' . $ssn_key
715
-                )
716
-            );
717
-            $session_data = is_object($row) ? $row->option_value : null;
718
-            if ($session_data) {
719
-                $session_data = preg_replace_callback(
720
-                    '!s:(d+):"(.*?)";!',
721
-                    function ($match) {
722
-                        return $match[1] === strlen($match[2])
723
-                            ? $match[0]
724
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
725
-                    },
726
-                    $session_data
727
-                );
728
-            }
729
-            $session_data = maybe_unserialize($session_data);
730
-        }
731
-        // in case the data is encoded... try to decode it
732
-        $session_data = $this->encryption instanceof EE_Encryption
733
-            ? $this->encryption->base64_string_decode($session_data)
734
-            : $session_data;
735
-        if (! is_array($session_data)) {
736
-            try {
737
-                $session_data = maybe_unserialize($session_data);
738
-            } catch (Exception $e) {
739
-                $msg = esc_html__(
740
-                    'An error occurred while attempting to unserialize the session data.',
741
-                    'event_espresso'
742
-                );
743
-                $msg .= WP_DEBUG
744
-                    ? '<br><pre>'
745
-                      . print_r($session_data, true)
746
-                      . '</pre><br>'
747
-                      . $this->find_serialize_error($session_data)
748
-                    : '';
749
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
750
-                throw new InvalidSessionDataException($msg, 0, $e);
751
-            }
752
-        }
753
-        // just a check to make sure the session array is indeed an array
754
-        if (! is_array($session_data)) {
755
-            // no?!?! then something is wrong
756
-            $msg = esc_html__(
757
-                'The session data is missing, invalid, or corrupted.',
758
-                'event_espresso'
759
-            );
760
-            $msg .= WP_DEBUG
761
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
762
-                : '';
763
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
764
-            throw new InvalidSessionDataException($msg);
765
-        }
766
-        if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
767
-            $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
768
-                $session_data['transaction']
769
-            );
770
-        }
771
-        return $session_data;
772
-    }
773
-
774
-
775
-    /**
776
-     * _generate_session_id
777
-     * Retrieves the PHP session id either directly from the PHP session,
778
-     * or from the request array if it was passed in from an AJAX request.
779
-     * The session id is then salted and hashed (mmm sounds tasty)
780
-     * so that it can be safely used as a request param
781
-     *
782
-     * @return string
783
-     */
784
-    protected function _generate_session_id()
785
-    {
786
-        // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
787
-        $session_id = $this->request->requestParamIsSet('EESID')
788
-            ? $this->request->getRequestParam('EESID')
789
-            : md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
790
-        return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
791
-    }
792
-
793
-
794
-    /**
795
-     * _get_sid_salt
796
-     *
797
-     * @return string
798
-     */
799
-    protected function _get_sid_salt()
800
-    {
801
-        // was session id salt already saved to db ?
802
-        if (empty($this->_sid_salt)) {
803
-            // no?  then maybe use WP defined constant
804
-            if (defined('AUTH_SALT')) {
805
-                $this->_sid_salt = AUTH_SALT;
806
-            }
807
-            // if salt doesn't exist or is too short
808
-            if (strlen($this->_sid_salt) < 32) {
809
-                // create a new one
810
-                $this->_sid_salt = wp_generate_password(64);
811
-            }
812
-            // and save it as a permanent session setting
813
-            $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
814
-        }
815
-        return $this->_sid_salt;
816
-    }
817
-
818
-
819
-    /**
820
-     * _set_init_access_and_expiration
821
-     *
822
-     * @return void
823
-     */
824
-    protected function _set_init_access_and_expiration()
825
-    {
826
-        $this->_time = time();
827
-        $this->_expiration = $this->_time + $this->session_lifespan->inSeconds();
828
-        // set initial site access time
829
-        $this->_session_data['init_access'] = $this->_time;
830
-        // and the session expiration
831
-        $this->_session_data['expiration'] = $this->_expiration;
832
-    }
833
-
834
-
835
-    /**
836
-     * @update session data  prior to saving to the db
837
-     * @param bool $new_session
838
-     * @return bool TRUE on success, FALSE on fail
839
-     * @throws EE_Error
840
-     * @throws InvalidArgumentException
841
-     * @throws InvalidDataTypeException
842
-     * @throws InvalidInterfaceException
843
-     * @throws ReflectionException
844
-     */
845
-    public function update($new_session = false)
846
-    {
847
-        $this->_session_data = is_array($this->_session_data) && isset($this->_session_data['id'])
848
-            ? $this->_session_data
849
-            : array();
850
-        if (empty($this->_session_data)) {
851
-            $this->_set_defaults();
852
-        }
853
-        $session_data = array();
854
-        foreach ($this->_session_data as $key => $value) {
855
-            switch ($key) {
856
-                case 'id':
857
-                    // session ID
858
-                    $session_data['id'] = $this->_sid;
859
-                    break;
860
-                case 'ip_address':
861
-                    // visitor ip address
862
-                    $session_data['ip_address'] = $this->request->ipAddress();
863
-                    break;
864
-                case 'user_agent':
865
-                    // visitor user_agent
866
-                    $session_data['user_agent'] = $this->_user_agent;
867
-                    break;
868
-                case 'init_access':
869
-                    $session_data['init_access'] = absint($value);
870
-                    break;
871
-                case 'last_access':
872
-                    // current access time
873
-                    $session_data['last_access'] = $this->_time;
874
-                    break;
875
-                case 'expiration':
876
-                    // when the session expires
877
-                    $session_data['expiration'] = ! empty($this->_expiration)
878
-                        ? $this->_expiration
879
-                        : $session_data['init_access'] + $this->session_lifespan->inSeconds();
880
-                    break;
881
-                case 'user_id':
882
-                    // current user if logged in
883
-                    $session_data['user_id'] = $this->_wp_user_id();
884
-                    break;
885
-                case 'pages_visited':
886
-                    $page_visit = $this->_get_page_visit();
887
-                    if ($page_visit) {
888
-                        // set pages visited where the first will be the http referrer
889
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
890
-                        // we'll only save the last 10 page visits.
891
-                        $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
892
-                    }
893
-                    break;
894
-                default:
895
-                    // carry any other data over
896
-                    $session_data[ $key ] = $this->_session_data[ $key ];
897
-            }
898
-        }
899
-        $this->_session_data = $session_data;
900
-        // creating a new session does not require saving to the db just yet
901
-        if (! $new_session) {
902
-            // ready? let's save
903
-            if ($this->_save_session_to_db()) {
904
-                return true;
905
-            }
906
-            return false;
907
-        }
908
-        // meh, why not?
909
-        return true;
910
-    }
911
-
912
-
913
-    /**
914
-     * @create session data array
915
-     * @throws EE_Error
916
-     * @throws InvalidArgumentException
917
-     * @throws InvalidDataTypeException
918
-     * @throws InvalidInterfaceException
919
-     * @throws ReflectionException
920
-     */
921
-    private function _create_espresso_session()
922
-    {
923
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
924
-        // use the update function for now with $new_session arg set to TRUE
925
-        $this->update(true);
926
-    }
927
-
928
-    /**
929
-     * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good
930
-     * too). This is used when determining if we want to save the session or not.
931
-     * @since 4.9.67.p
932
-     * @return bool
933
-     */
934
-    private function sessionHasStuffWorthSaving()
935
-    {
936
-        return $this->save_state === EE_Session::SAVE_STATE_DIRTY
937
-               // we may want to eventually remove the following
938
-               // on the assumption that the above check is enough
939
-               || $this->cart() instanceof EE_Cart
940
-               || (
941
-                   isset($this->_session_data['ee_notices'])
942
-                   && (
943
-                       ! empty($this->_session_data['ee_notices']['attention'])
944
-                       || ! empty($this->_session_data['ee_notices']['errors'])
945
-                       || ! empty($this->_session_data['ee_notices']['success'])
946
-                   )
947
-               );
948
-    }
949
-
950
-
951
-    /**
952
-     * _save_session_to_db
953
-     *
954
-     * @param bool $clear_session
955
-     * @return bool
956
-     * @throws EE_Error
957
-     * @throws InvalidArgumentException
958
-     * @throws InvalidDataTypeException
959
-     * @throws InvalidInterfaceException
960
-     * @throws ReflectionException
961
-     */
962
-    private function _save_session_to_db($clear_session = false)
963
-    {
964
-        // don't save sessions for crawlers
965
-        // and unless we're deleting the session data, don't save anything if there isn't a cart
966
-        if (
967
-            $this->request->isBot()
968
-            || (
969
-                ! $clear_session
970
-                && ! $this->sessionHasStuffWorthSaving()
971
-                && apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true)
972
-            )
973
-        ) {
974
-            return false;
975
-        }
976
-        $transaction = $this->transaction();
977
-        if ($transaction instanceof EE_Transaction) {
978
-            if (! $transaction->ID()) {
979
-                $transaction->save();
980
-            }
981
-            $this->_session_data['transaction'] = $transaction->ID();
982
-        }
983
-        // then serialize all of our session data
984
-        $session_data = serialize($this->_session_data);
985
-        // do we need to also encode it to avoid corrupted data when saved to the db?
986
-        $session_data = $this->_use_encryption
987
-            ? $this->encryption->base64_string_encode($session_data)
988
-            : $session_data;
989
-        // maybe save hash check
990
-        if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
991
-            $this->cache_storage->add(
992
-                EE_Session::hash_check_prefix . $this->_sid,
993
-                md5($session_data),
994
-                $this->session_lifespan->inSeconds()
995
-            );
996
-        }
997
-        // we're using the Transient API for storing session data,
998
-        $saved = $this->cache_storage->add(
999
-            EE_Session::session_id_prefix . $this->_sid,
1000
-            $session_data,
1001
-            $this->session_lifespan->inSeconds()
1002
-        );
1003
-        $this->setSaveState(EE_Session::SAVE_STATE_CLEAN);
1004
-        return $saved;
1005
-    }
1006
-
1007
-
1008
-    /**
1009
-     * @get    the full page request the visitor is accessing
1010
-     * @return string
1011
-     */
1012
-    public function _get_page_visit()
1013
-    {
1014
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
1015
-        // check for request url
1016
-        if ($this->request->serverParamIsSet('REQUEST_URI')) {
1017
-            $page_id = '?';
1018
-            $e_reg = '';
1019
-            $request_uri = $this->request->getServerParam('REQUEST_URI');
1020
-            $ru_bits = explode('?', $request_uri);
1021
-            $request_uri = $ru_bits[0];
1022
-            $http_host = $this->request->getServerParam('HTTP_HOST');
1023
-            // check for page_id in SERVER REQUEST
1024
-            if ($this->request->requestParamIsSet('page_id')) {
1025
-                // rebuild $e_reg without any of the extra parameters
1026
-                $page_id .= 'page_id=' . $this->request->getRequestParam('page_id', 0, 'int') . '&amp;';
1027
-            }
1028
-            // check for $e_reg in SERVER REQUEST
1029
-            if ($this->request->requestParamIsSet('ee')) {
1030
-                // rebuild $e_reg without any of the extra parameters
1031
-                $e_reg = 'ee=' . $this->request->getRequestParam('ee');
1032
-            }
1033
-            $page_visit = esc_url(rtrim($http_host . $request_uri . $page_id . $e_reg, '?'));
1034
-        }
1035
-        return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * @the    current wp user id
1041
-     * @return int
1042
-     */
1043
-    public function _wp_user_id()
1044
-    {
1045
-        // if I need to explain the following lines of code, then you shouldn't be looking at this!
1046
-        $this->_wp_user_id = get_current_user_id();
1047
-        return $this->_wp_user_id;
1048
-    }
1049
-
1050
-
1051
-    /**
1052
-     * Clear EE_Session data
1053
-     *
1054
-     * @param string $class
1055
-     * @param string $function
1056
-     * @return void
1057
-     * @throws EE_Error
1058
-     * @throws InvalidArgumentException
1059
-     * @throws InvalidDataTypeException
1060
-     * @throws InvalidInterfaceException
1061
-     * @throws ReflectionException
1062
-     */
1063
-    public function clear_session($class = '', $function = '')
1064
-    {
26
+	const session_id_prefix = 'ee_ssn_';
27
+
28
+	const hash_check_prefix = 'ee_shc_';
29
+
30
+	const OPTION_NAME_SETTINGS = 'ee_session_settings';
31
+
32
+	const STATUS_CLOSED = 0;
33
+
34
+	const STATUS_OPEN = 1;
35
+
36
+	const SAVE_STATE_CLEAN = 'clean';
37
+	const SAVE_STATE_DIRTY = 'dirty';
38
+
39
+
40
+	/**
41
+	 * instance of the EE_Session object
42
+	 *
43
+	 * @var EE_Session
44
+	 */
45
+	private static $_instance;
46
+
47
+	/**
48
+	 * @var CacheStorageInterface $cache_storage
49
+	 */
50
+	protected $cache_storage;
51
+
52
+	/**
53
+	 * @var EE_Encryption $encryption
54
+	 */
55
+	protected $encryption;
56
+
57
+	/**
58
+	 * @var SessionStartHandler $session_start_handler
59
+	 */
60
+	protected $session_start_handler;
61
+
62
+	/**
63
+	 * the session id
64
+	 *
65
+	 * @var string
66
+	 */
67
+	private $_sid;
68
+
69
+	/**
70
+	 * session id salt
71
+	 *
72
+	 * @var string
73
+	 */
74
+	private $_sid_salt;
75
+
76
+	/**
77
+	 * session data
78
+	 *
79
+	 * @var array
80
+	 */
81
+	private $_session_data = array();
82
+
83
+	/**
84
+	 * how long an EE session lasts
85
+	 * default session lifespan of 1 hour (for not so instant IPNs)
86
+	 *
87
+	 * @var SessionLifespan $session_lifespan
88
+	 */
89
+	private $session_lifespan;
90
+
91
+	/**
92
+	 * session expiration time as Unix timestamp in GMT
93
+	 *
94
+	 * @var int
95
+	 */
96
+	private $_expiration;
97
+
98
+	/**
99
+	 * whether or not session has expired at some point
100
+	 *
101
+	 * @var boolean
102
+	 */
103
+	private $_expired = false;
104
+
105
+	/**
106
+	 * current time as Unix timestamp in GMT
107
+	 *
108
+	 * @var int
109
+	 */
110
+	private $_time;
111
+
112
+	/**
113
+	 * whether to encrypt session data
114
+	 *
115
+	 * @var bool
116
+	 */
117
+	private $_use_encryption;
118
+
119
+	/**
120
+	 * well... according to the server...
121
+	 *
122
+	 * @var null
123
+	 */
124
+	private $_user_agent;
125
+
126
+	/**
127
+	 * do you really trust the server ?
128
+	 *
129
+	 * @var null
130
+	 */
131
+	private $_ip_address;
132
+
133
+	/**
134
+	 * current WP user_id
135
+	 *
136
+	 * @var null
137
+	 */
138
+	private $_wp_user_id;
139
+
140
+	/**
141
+	 * array for defining default session vars
142
+	 *
143
+	 * @var array
144
+	 */
145
+	private $_default_session_vars = array(
146
+		'id'            => null,
147
+		'user_id'       => null,
148
+		'ip_address'    => null,
149
+		'user_agent'    => null,
150
+		'init_access'   => null,
151
+		'last_access'   => null,
152
+		'expiration'    => null,
153
+		'pages_visited' => array(),
154
+	);
155
+
156
+	/**
157
+	 * timestamp for when last garbage collection cycle was performed
158
+	 *
159
+	 * @var int $_last_gc
160
+	 */
161
+	private $_last_gc;
162
+
163
+	/**
164
+	 * @var RequestInterface $request
165
+	 */
166
+	protected $request;
167
+
168
+	/**
169
+	 * whether session is active or not
170
+	 *
171
+	 * @var int $status
172
+	 */
173
+	private $status = EE_Session::STATUS_CLOSED;
174
+
175
+	/**
176
+	 * whether session data has changed therefore requiring a session save
177
+	 *
178
+	 * @var string $save_state
179
+	 */
180
+	private $save_state = EE_Session::SAVE_STATE_CLEAN;
181
+
182
+
183
+	/**
184
+	 * @singleton method used to instantiate class object
185
+	 * @param CacheStorageInterface $cache_storage
186
+	 * @param SessionLifespan|null  $lifespan
187
+	 * @param RequestInterface      $request
188
+	 * @param SessionStartHandler   $session_start_handler
189
+	 * @param EE_Encryption         $encryption
190
+	 * @return EE_Session
191
+	 * @throws InvalidArgumentException
192
+	 * @throws InvalidDataTypeException
193
+	 * @throws InvalidInterfaceException
194
+	 */
195
+	public static function instance(
196
+		CacheStorageInterface $cache_storage = null,
197
+		SessionLifespan $lifespan = null,
198
+		RequestInterface $request = null,
199
+		SessionStartHandler $session_start_handler = null,
200
+		EE_Encryption $encryption = null
201
+	) {
202
+		// check if class object is instantiated
203
+		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
204
+		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
205
+		if (
206
+			! self::$_instance instanceof EE_Session
207
+			&& $cache_storage instanceof CacheStorageInterface
208
+			&& $lifespan instanceof SessionLifespan
209
+			&& $request instanceof RequestInterface
210
+			&& $session_start_handler instanceof SessionStartHandler
211
+			&& apply_filters('FHEE_load_EE_Session', true)
212
+		) {
213
+			self::$_instance = new self(
214
+				$cache_storage,
215
+				$lifespan,
216
+				$request,
217
+				$session_start_handler,
218
+				$encryption
219
+			);
220
+		}
221
+		return self::$_instance;
222
+	}
223
+
224
+
225
+	/**
226
+	 * protected constructor to prevent direct creation
227
+	 *
228
+	 * @param CacheStorageInterface $cache_storage
229
+	 * @param SessionLifespan       $lifespan
230
+	 * @param RequestInterface      $request
231
+	 * @param SessionStartHandler   $session_start_handler
232
+	 * @param EE_Encryption         $encryption
233
+	 * @throws InvalidArgumentException
234
+	 * @throws InvalidDataTypeException
235
+	 * @throws InvalidInterfaceException
236
+	 */
237
+	protected function __construct(
238
+		CacheStorageInterface $cache_storage,
239
+		SessionLifespan $lifespan,
240
+		RequestInterface $request,
241
+		SessionStartHandler $session_start_handler,
242
+		EE_Encryption $encryption = null
243
+	) {
244
+		// session loading is turned ON by default,
245
+		// but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
246
+		// (which currently fires on the init hook at priority 9),
247
+		// can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
248
+		if (! apply_filters('FHEE_load_EE_Session', true)) {
249
+			return;
250
+		}
251
+		$this->session_start_handler = $session_start_handler;
252
+		$this->session_lifespan = $lifespan;
253
+		$this->request = $request;
254
+		if (! defined('ESPRESSO_SESSION')) {
255
+			define('ESPRESSO_SESSION', true);
256
+		}
257
+		// retrieve session options from db
258
+		$session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
259
+		if (! empty($session_settings)) {
260
+			// cycle though existing session options
261
+			foreach ($session_settings as $var_name => $session_setting) {
262
+				// set values for class properties
263
+				$var_name = '_' . $var_name;
264
+				$this->{$var_name} = $session_setting;
265
+			}
266
+		}
267
+		$this->cache_storage = $cache_storage;
268
+		// are we using encryption?
269
+		$this->_use_encryption = $encryption instanceof EE_Encryption
270
+								 && EE_Registry::instance()->CFG->admin->encode_session_data();
271
+		// encrypt data via: $this->encryption->encrypt();
272
+		$this->encryption = $encryption;
273
+		// filter hook allows outside functions/classes/plugins to change default empty cart
274
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
275
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
276
+		// apply default session vars
277
+		$this->_set_defaults();
278
+		add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
279
+		// check request for 'clear_session' param
280
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
281
+		// once everything is all said and done,
282
+		add_action('shutdown', array($this, 'update'), 100);
283
+		add_action('shutdown', array($this, 'garbageCollection'), 1000);
284
+		$this->configure_garbage_collection_filters();
285
+	}
286
+
287
+
288
+	/**
289
+	 * @return bool
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 */
294
+	public static function isLoadedAndActive()
295
+	{
296
+		return did_action('AHEE__EE_System__core_loaded_and_ready')
297
+			   && EE_Session::instance() instanceof EE_Session
298
+			   && EE_Session::instance()->isActive();
299
+	}
300
+
301
+
302
+	/**
303
+	 * @return bool
304
+	 */
305
+	public function isActive()
306
+	{
307
+		return $this->status === EE_Session::STATUS_OPEN;
308
+	}
309
+
310
+
311
+	/**
312
+	 * @return void
313
+	 * @throws EE_Error
314
+	 * @throws InvalidArgumentException
315
+	 * @throws InvalidDataTypeException
316
+	 * @throws InvalidInterfaceException
317
+	 * @throws InvalidSessionDataException
318
+	 * @throws RuntimeException
319
+	 * @throws ReflectionException
320
+	 */
321
+	public function open_session()
322
+	{
323
+		// check for existing session and retrieve it from db
324
+		if (! $this->_espresso_session()) {
325
+			// or just start a new one
326
+			$this->_create_espresso_session();
327
+		}
328
+	}
329
+
330
+
331
+	/**
332
+	 * @return bool
333
+	 */
334
+	public function expired()
335
+	{
336
+		return $this->_expired;
337
+	}
338
+
339
+
340
+	/**
341
+	 * @return void
342
+	 */
343
+	public function reset_expired()
344
+	{
345
+		$this->_expired = false;
346
+	}
347
+
348
+
349
+	/**
350
+	 * @return int
351
+	 */
352
+	public function expiration()
353
+	{
354
+		return $this->_expiration;
355
+	}
356
+
357
+
358
+	/**
359
+	 * @return int
360
+	 */
361
+	public function extension()
362
+	{
363
+		return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
364
+	}
365
+
366
+
367
+	/**
368
+	 * @param int $time number of seconds to add to session expiration
369
+	 */
370
+	public function extend_expiration($time = 0)
371
+	{
372
+		$time = $time ? $time : $this->extension();
373
+		$this->_expiration += absint($time);
374
+	}
375
+
376
+
377
+	/**
378
+	 * @return int
379
+	 */
380
+	public function lifespan()
381
+	{
382
+		return $this->session_lifespan->inSeconds();
383
+	}
384
+
385
+
386
+	/**
387
+	 * Marks whether the session data has been updated or not.
388
+	 * Valid options are:
389
+	 *      EE_Session::SAVE_STATE_CLEAN - session data remains unchanged and updating is not necessary
390
+	 *      EE_Session::SAVE_STATE_DIRTY - session data has changed since last save and needs to be updated
391
+	 * default value is EE_Session::SAVE_STATE_DIRTY
392
+	 *
393
+	 * @param string $save_state
394
+	 */
395
+	public function setSaveState($save_state = EE_Session::SAVE_STATE_DIRTY)
396
+	{
397
+		$valid_save_states = [
398
+			EE_Session::SAVE_STATE_CLEAN,
399
+			EE_Session::SAVE_STATE_DIRTY,
400
+		];
401
+		if (! in_array($save_state, $valid_save_states, true)) {
402
+			$save_state = EE_Session::SAVE_STATE_DIRTY;
403
+		}
404
+		$this->save_state = $save_state;
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * This just sets some defaults for the _session data property
411
+	 *
412
+	 * @return void
413
+	 */
414
+	private function _set_defaults()
415
+	{
416
+		// set some defaults
417
+		foreach ($this->_default_session_vars as $key => $default_var) {
418
+			if (is_array($default_var)) {
419
+				$this->_session_data[ $key ] = array();
420
+			} else {
421
+				$this->_session_data[ $key ] = '';
422
+			}
423
+		}
424
+	}
425
+
426
+
427
+	/**
428
+	 * @retrieve  session data
429
+	 * @return    string
430
+	 */
431
+	public function id()
432
+	{
433
+		return $this->_sid;
434
+	}
435
+
436
+
437
+	/**
438
+	 * @param \EE_Cart $cart
439
+	 * @return bool
440
+	 */
441
+	public function set_cart(EE_Cart $cart)
442
+	{
443
+		$this->_session_data['cart'] = $cart;
444
+		$this->setSaveState();
445
+		return true;
446
+	}
447
+
448
+
449
+	/**
450
+	 * reset_cart
451
+	 */
452
+	public function reset_cart()
453
+	{
454
+		do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
455
+		$this->_session_data['cart'] = null;
456
+		$this->setSaveState();
457
+	}
458
+
459
+
460
+	/**
461
+	 * @return \EE_Cart
462
+	 */
463
+	public function cart()
464
+	{
465
+		return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
466
+			? $this->_session_data['cart']
467
+			: null;
468
+	}
469
+
470
+
471
+	/**
472
+	 * @param \EE_Checkout $checkout
473
+	 * @return bool
474
+	 */
475
+	public function set_checkout(EE_Checkout $checkout)
476
+	{
477
+		$this->_session_data['checkout'] = $checkout;
478
+		$this->setSaveState();
479
+		return true;
480
+	}
481
+
482
+
483
+	/**
484
+	 * reset_checkout
485
+	 */
486
+	public function reset_checkout()
487
+	{
488
+		do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
489
+		$this->_session_data['checkout'] = null;
490
+		$this->setSaveState();
491
+	}
492
+
493
+
494
+	/**
495
+	 * @return \EE_Checkout
496
+	 */
497
+	public function checkout()
498
+	{
499
+		return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
500
+			? $this->_session_data['checkout']
501
+			: null;
502
+	}
503
+
504
+
505
+	/**
506
+	 * @param \EE_Transaction $transaction
507
+	 * @return bool
508
+	 * @throws EE_Error
509
+	 */
510
+	public function set_transaction(EE_Transaction $transaction)
511
+	{
512
+		// first remove the session from the transaction before we save the transaction in the session
513
+		$transaction->set_txn_session_data(null);
514
+		$this->_session_data['transaction'] = $transaction;
515
+		$this->setSaveState();
516
+		return true;
517
+	}
518
+
519
+
520
+	/**
521
+	 * reset_transaction
522
+	 */
523
+	public function reset_transaction()
524
+	{
525
+		do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
526
+		$this->_session_data['transaction'] = null;
527
+		$this->setSaveState();
528
+	}
529
+
530
+
531
+	/**
532
+	 * @return \EE_Transaction
533
+	 */
534
+	public function transaction()
535
+	{
536
+		return isset($this->_session_data['transaction'])
537
+			   && $this->_session_data['transaction'] instanceof EE_Transaction
538
+			? $this->_session_data['transaction']
539
+			: null;
540
+	}
541
+
542
+
543
+	/**
544
+	 * retrieve session data
545
+	 *
546
+	 * @param null $key
547
+	 * @param bool $reset_cache
548
+	 * @return array
549
+	 */
550
+	public function get_session_data($key = null, $reset_cache = false)
551
+	{
552
+		if ($reset_cache) {
553
+			$this->reset_cart();
554
+			$this->reset_checkout();
555
+			$this->reset_transaction();
556
+		}
557
+		if (! empty($key)) {
558
+			return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
559
+		}
560
+		return $this->_session_data;
561
+	}
562
+
563
+
564
+	/**
565
+	 * Returns TRUE on success, FALSE on fail
566
+	 *
567
+	 * @param array $data
568
+	 * @return bool
569
+	 */
570
+	public function set_session_data($data)
571
+	{
572
+		// nothing ??? bad data ??? go home!
573
+		if (empty($data) || ! is_array($data)) {
574
+			EE_Error::add_error(
575
+				esc_html__(
576
+					'No session data or invalid session data was provided.',
577
+					'event_espresso'
578
+				),
579
+				__FILE__,
580
+				__FUNCTION__,
581
+				__LINE__
582
+			);
583
+			return false;
584
+		}
585
+		foreach ($data as $key => $value) {
586
+			if (isset($this->_default_session_vars[ $key ])) {
587
+				EE_Error::add_error(
588
+					sprintf(
589
+						esc_html__(
590
+							'Sorry! %s is a default session datum and can not be reset.',
591
+							'event_espresso'
592
+						),
593
+						$key
594
+					),
595
+					__FILE__,
596
+					__FUNCTION__,
597
+					__LINE__
598
+				);
599
+				return false;
600
+			}
601
+			$this->_session_data[ $key ] = $value;
602
+			$this->setSaveState();
603
+		}
604
+		return true;
605
+	}
606
+
607
+
608
+	/**
609
+	 * @initiate session
610
+	 * @return bool TRUE on success, FALSE on fail
611
+	 * @throws EE_Error
612
+	 * @throws InvalidArgumentException
613
+	 * @throws InvalidDataTypeException
614
+	 * @throws InvalidInterfaceException
615
+	 * @throws InvalidSessionDataException
616
+	 * @throws RuntimeException
617
+	 * @throws ReflectionException
618
+	 */
619
+	private function _espresso_session()
620
+	{
621
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
622
+		$this->session_start_handler->startSession();
623
+		$this->status = EE_Session::STATUS_OPEN;
624
+		// get our modified session ID
625
+		$this->_sid = $this->_generate_session_id();
626
+		// and the visitors IP
627
+		$this->_ip_address = $this->request->ipAddress();
628
+		// set the "user agent"
629
+		$this->_user_agent = $this->request->userAgent();
630
+		// now let's retrieve what's in the db
631
+		$session_data = $this->_retrieve_session_data();
632
+		if (! empty($session_data)) {
633
+			// get the current time in UTC
634
+			$this->_time = $this->_time !== null ? $this->_time : time();
635
+			// and reset the session expiration
636
+			$this->_expiration = isset($session_data['expiration'])
637
+				? $session_data['expiration']
638
+				: $this->_time + $this->session_lifespan->inSeconds();
639
+		} else {
640
+			// set initial site access time and the session expiration
641
+			$this->_set_init_access_and_expiration();
642
+			// set referer
643
+			$this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = esc_attr(
644
+				$this->request->getServerParam('HTTP_REFERER')
645
+			);
646
+			// no previous session = go back and create one (on top of the data above)
647
+			return false;
648
+		}
649
+		// now the user agent
650
+		if ($session_data['user_agent'] !== $this->_user_agent) {
651
+			return false;
652
+		}
653
+		// wait a minute... how old are you?
654
+		if ($this->_time > $this->_expiration) {
655
+			// yer too old fer me!
656
+			$this->_expired = true;
657
+			// wipe out everything that isn't a default session datum
658
+			$this->clear_session(__CLASS__, __FUNCTION__);
659
+		}
660
+		// make event espresso session data available to plugin
661
+		$this->_session_data = array_merge($this->_session_data, $session_data);
662
+		return true;
663
+	}
664
+
665
+
666
+	/**
667
+	 * _get_session_data
668
+	 * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
669
+	 * databases
670
+	 *
671
+	 * @return array
672
+	 * @throws EE_Error
673
+	 * @throws InvalidArgumentException
674
+	 * @throws InvalidSessionDataException
675
+	 * @throws InvalidDataTypeException
676
+	 * @throws InvalidInterfaceException
677
+	 * @throws RuntimeException
678
+	 */
679
+	protected function _retrieve_session_data()
680
+	{
681
+		$ssn_key = EE_Session::session_id_prefix . $this->_sid;
682
+		try {
683
+			// we're using WP's Transient API to store session data using the PHP session ID as the option name
684
+			$session_data = $this->cache_storage->get($ssn_key, false);
685
+			if (empty($session_data)) {
686
+				return array();
687
+			}
688
+			if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
689
+				$hash_check = $this->cache_storage->get(
690
+					EE_Session::hash_check_prefix . $this->_sid,
691
+					false
692
+				);
693
+				if ($hash_check && $hash_check !== md5($session_data)) {
694
+					EE_Error::add_error(
695
+						sprintf(
696
+							esc_html__(
697
+								'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
698
+								'event_espresso'
699
+							),
700
+							EE_Session::session_id_prefix . $this->_sid
701
+						),
702
+						__FILE__,
703
+						__FUNCTION__,
704
+						__LINE__
705
+					);
706
+				}
707
+			}
708
+		} catch (Exception $e) {
709
+			// let's just eat that error for now and attempt to correct any corrupted data
710
+			global $wpdb;
711
+			$row = $wpdb->get_row(
712
+				$wpdb->prepare(
713
+					"SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
714
+					'_transient_' . $ssn_key
715
+				)
716
+			);
717
+			$session_data = is_object($row) ? $row->option_value : null;
718
+			if ($session_data) {
719
+				$session_data = preg_replace_callback(
720
+					'!s:(d+):"(.*?)";!',
721
+					function ($match) {
722
+						return $match[1] === strlen($match[2])
723
+							? $match[0]
724
+							: 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
725
+					},
726
+					$session_data
727
+				);
728
+			}
729
+			$session_data = maybe_unserialize($session_data);
730
+		}
731
+		// in case the data is encoded... try to decode it
732
+		$session_data = $this->encryption instanceof EE_Encryption
733
+			? $this->encryption->base64_string_decode($session_data)
734
+			: $session_data;
735
+		if (! is_array($session_data)) {
736
+			try {
737
+				$session_data = maybe_unserialize($session_data);
738
+			} catch (Exception $e) {
739
+				$msg = esc_html__(
740
+					'An error occurred while attempting to unserialize the session data.',
741
+					'event_espresso'
742
+				);
743
+				$msg .= WP_DEBUG
744
+					? '<br><pre>'
745
+					  . print_r($session_data, true)
746
+					  . '</pre><br>'
747
+					  . $this->find_serialize_error($session_data)
748
+					: '';
749
+				$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
750
+				throw new InvalidSessionDataException($msg, 0, $e);
751
+			}
752
+		}
753
+		// just a check to make sure the session array is indeed an array
754
+		if (! is_array($session_data)) {
755
+			// no?!?! then something is wrong
756
+			$msg = esc_html__(
757
+				'The session data is missing, invalid, or corrupted.',
758
+				'event_espresso'
759
+			);
760
+			$msg .= WP_DEBUG
761
+				? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
762
+				: '';
763
+			$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
764
+			throw new InvalidSessionDataException($msg);
765
+		}
766
+		if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
767
+			$session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
768
+				$session_data['transaction']
769
+			);
770
+		}
771
+		return $session_data;
772
+	}
773
+
774
+
775
+	/**
776
+	 * _generate_session_id
777
+	 * Retrieves the PHP session id either directly from the PHP session,
778
+	 * or from the request array if it was passed in from an AJAX request.
779
+	 * The session id is then salted and hashed (mmm sounds tasty)
780
+	 * so that it can be safely used as a request param
781
+	 *
782
+	 * @return string
783
+	 */
784
+	protected function _generate_session_id()
785
+	{
786
+		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
787
+		$session_id = $this->request->requestParamIsSet('EESID')
788
+			? $this->request->getRequestParam('EESID')
789
+			: md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
790
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
791
+	}
792
+
793
+
794
+	/**
795
+	 * _get_sid_salt
796
+	 *
797
+	 * @return string
798
+	 */
799
+	protected function _get_sid_salt()
800
+	{
801
+		// was session id salt already saved to db ?
802
+		if (empty($this->_sid_salt)) {
803
+			// no?  then maybe use WP defined constant
804
+			if (defined('AUTH_SALT')) {
805
+				$this->_sid_salt = AUTH_SALT;
806
+			}
807
+			// if salt doesn't exist or is too short
808
+			if (strlen($this->_sid_salt) < 32) {
809
+				// create a new one
810
+				$this->_sid_salt = wp_generate_password(64);
811
+			}
812
+			// and save it as a permanent session setting
813
+			$this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
814
+		}
815
+		return $this->_sid_salt;
816
+	}
817
+
818
+
819
+	/**
820
+	 * _set_init_access_and_expiration
821
+	 *
822
+	 * @return void
823
+	 */
824
+	protected function _set_init_access_and_expiration()
825
+	{
826
+		$this->_time = time();
827
+		$this->_expiration = $this->_time + $this->session_lifespan->inSeconds();
828
+		// set initial site access time
829
+		$this->_session_data['init_access'] = $this->_time;
830
+		// and the session expiration
831
+		$this->_session_data['expiration'] = $this->_expiration;
832
+	}
833
+
834
+
835
+	/**
836
+	 * @update session data  prior to saving to the db
837
+	 * @param bool $new_session
838
+	 * @return bool TRUE on success, FALSE on fail
839
+	 * @throws EE_Error
840
+	 * @throws InvalidArgumentException
841
+	 * @throws InvalidDataTypeException
842
+	 * @throws InvalidInterfaceException
843
+	 * @throws ReflectionException
844
+	 */
845
+	public function update($new_session = false)
846
+	{
847
+		$this->_session_data = is_array($this->_session_data) && isset($this->_session_data['id'])
848
+			? $this->_session_data
849
+			: array();
850
+		if (empty($this->_session_data)) {
851
+			$this->_set_defaults();
852
+		}
853
+		$session_data = array();
854
+		foreach ($this->_session_data as $key => $value) {
855
+			switch ($key) {
856
+				case 'id':
857
+					// session ID
858
+					$session_data['id'] = $this->_sid;
859
+					break;
860
+				case 'ip_address':
861
+					// visitor ip address
862
+					$session_data['ip_address'] = $this->request->ipAddress();
863
+					break;
864
+				case 'user_agent':
865
+					// visitor user_agent
866
+					$session_data['user_agent'] = $this->_user_agent;
867
+					break;
868
+				case 'init_access':
869
+					$session_data['init_access'] = absint($value);
870
+					break;
871
+				case 'last_access':
872
+					// current access time
873
+					$session_data['last_access'] = $this->_time;
874
+					break;
875
+				case 'expiration':
876
+					// when the session expires
877
+					$session_data['expiration'] = ! empty($this->_expiration)
878
+						? $this->_expiration
879
+						: $session_data['init_access'] + $this->session_lifespan->inSeconds();
880
+					break;
881
+				case 'user_id':
882
+					// current user if logged in
883
+					$session_data['user_id'] = $this->_wp_user_id();
884
+					break;
885
+				case 'pages_visited':
886
+					$page_visit = $this->_get_page_visit();
887
+					if ($page_visit) {
888
+						// set pages visited where the first will be the http referrer
889
+						$this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
890
+						// we'll only save the last 10 page visits.
891
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
892
+					}
893
+					break;
894
+				default:
895
+					// carry any other data over
896
+					$session_data[ $key ] = $this->_session_data[ $key ];
897
+			}
898
+		}
899
+		$this->_session_data = $session_data;
900
+		// creating a new session does not require saving to the db just yet
901
+		if (! $new_session) {
902
+			// ready? let's save
903
+			if ($this->_save_session_to_db()) {
904
+				return true;
905
+			}
906
+			return false;
907
+		}
908
+		// meh, why not?
909
+		return true;
910
+	}
911
+
912
+
913
+	/**
914
+	 * @create session data array
915
+	 * @throws EE_Error
916
+	 * @throws InvalidArgumentException
917
+	 * @throws InvalidDataTypeException
918
+	 * @throws InvalidInterfaceException
919
+	 * @throws ReflectionException
920
+	 */
921
+	private function _create_espresso_session()
922
+	{
923
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
924
+		// use the update function for now with $new_session arg set to TRUE
925
+		$this->update(true);
926
+	}
927
+
928
+	/**
929
+	 * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good
930
+	 * too). This is used when determining if we want to save the session or not.
931
+	 * @since 4.9.67.p
932
+	 * @return bool
933
+	 */
934
+	private function sessionHasStuffWorthSaving()
935
+	{
936
+		return $this->save_state === EE_Session::SAVE_STATE_DIRTY
937
+			   // we may want to eventually remove the following
938
+			   // on the assumption that the above check is enough
939
+			   || $this->cart() instanceof EE_Cart
940
+			   || (
941
+				   isset($this->_session_data['ee_notices'])
942
+				   && (
943
+					   ! empty($this->_session_data['ee_notices']['attention'])
944
+					   || ! empty($this->_session_data['ee_notices']['errors'])
945
+					   || ! empty($this->_session_data['ee_notices']['success'])
946
+				   )
947
+			   );
948
+	}
949
+
950
+
951
+	/**
952
+	 * _save_session_to_db
953
+	 *
954
+	 * @param bool $clear_session
955
+	 * @return bool
956
+	 * @throws EE_Error
957
+	 * @throws InvalidArgumentException
958
+	 * @throws InvalidDataTypeException
959
+	 * @throws InvalidInterfaceException
960
+	 * @throws ReflectionException
961
+	 */
962
+	private function _save_session_to_db($clear_session = false)
963
+	{
964
+		// don't save sessions for crawlers
965
+		// and unless we're deleting the session data, don't save anything if there isn't a cart
966
+		if (
967
+			$this->request->isBot()
968
+			|| (
969
+				! $clear_session
970
+				&& ! $this->sessionHasStuffWorthSaving()
971
+				&& apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true)
972
+			)
973
+		) {
974
+			return false;
975
+		}
976
+		$transaction = $this->transaction();
977
+		if ($transaction instanceof EE_Transaction) {
978
+			if (! $transaction->ID()) {
979
+				$transaction->save();
980
+			}
981
+			$this->_session_data['transaction'] = $transaction->ID();
982
+		}
983
+		// then serialize all of our session data
984
+		$session_data = serialize($this->_session_data);
985
+		// do we need to also encode it to avoid corrupted data when saved to the db?
986
+		$session_data = $this->_use_encryption
987
+			? $this->encryption->base64_string_encode($session_data)
988
+			: $session_data;
989
+		// maybe save hash check
990
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
991
+			$this->cache_storage->add(
992
+				EE_Session::hash_check_prefix . $this->_sid,
993
+				md5($session_data),
994
+				$this->session_lifespan->inSeconds()
995
+			);
996
+		}
997
+		// we're using the Transient API for storing session data,
998
+		$saved = $this->cache_storage->add(
999
+			EE_Session::session_id_prefix . $this->_sid,
1000
+			$session_data,
1001
+			$this->session_lifespan->inSeconds()
1002
+		);
1003
+		$this->setSaveState(EE_Session::SAVE_STATE_CLEAN);
1004
+		return $saved;
1005
+	}
1006
+
1007
+
1008
+	/**
1009
+	 * @get    the full page request the visitor is accessing
1010
+	 * @return string
1011
+	 */
1012
+	public function _get_page_visit()
1013
+	{
1014
+		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
1015
+		// check for request url
1016
+		if ($this->request->serverParamIsSet('REQUEST_URI')) {
1017
+			$page_id = '?';
1018
+			$e_reg = '';
1019
+			$request_uri = $this->request->getServerParam('REQUEST_URI');
1020
+			$ru_bits = explode('?', $request_uri);
1021
+			$request_uri = $ru_bits[0];
1022
+			$http_host = $this->request->getServerParam('HTTP_HOST');
1023
+			// check for page_id in SERVER REQUEST
1024
+			if ($this->request->requestParamIsSet('page_id')) {
1025
+				// rebuild $e_reg without any of the extra parameters
1026
+				$page_id .= 'page_id=' . $this->request->getRequestParam('page_id', 0, 'int') . '&amp;';
1027
+			}
1028
+			// check for $e_reg in SERVER REQUEST
1029
+			if ($this->request->requestParamIsSet('ee')) {
1030
+				// rebuild $e_reg without any of the extra parameters
1031
+				$e_reg = 'ee=' . $this->request->getRequestParam('ee');
1032
+			}
1033
+			$page_visit = esc_url(rtrim($http_host . $request_uri . $page_id . $e_reg, '?'));
1034
+		}
1035
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * @the    current wp user id
1041
+	 * @return int
1042
+	 */
1043
+	public function _wp_user_id()
1044
+	{
1045
+		// if I need to explain the following lines of code, then you shouldn't be looking at this!
1046
+		$this->_wp_user_id = get_current_user_id();
1047
+		return $this->_wp_user_id;
1048
+	}
1049
+
1050
+
1051
+	/**
1052
+	 * Clear EE_Session data
1053
+	 *
1054
+	 * @param string $class
1055
+	 * @param string $function
1056
+	 * @return void
1057
+	 * @throws EE_Error
1058
+	 * @throws InvalidArgumentException
1059
+	 * @throws InvalidDataTypeException
1060
+	 * @throws InvalidInterfaceException
1061
+	 * @throws ReflectionException
1062
+	 */
1063
+	public function clear_session($class = '', $function = '')
1064
+	{
1065 1065
 //         echo '
1066 1066
 // <h3 style="color:#999;line-height:.9em;">
1067 1067
 // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/>
1068 1068
 // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b>
1069 1069
 // </h3>';
1070
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1071
-        $this->reset_cart();
1072
-        $this->reset_checkout();
1073
-        $this->reset_transaction();
1074
-        // wipe out everything that isn't a default session datum
1075
-        $this->reset_data(array_keys($this->_session_data));
1076
-        // reset initial site access time and the session expiration
1077
-        $this->_set_init_access_and_expiration();
1078
-        $this->setSaveState();
1079
-        $this->_save_session_to_db(true);
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     * resets all non-default session vars. Returns TRUE on success, FALSE on fail
1085
-     *
1086
-     * @param array|mixed $data_to_reset
1087
-     * @param bool        $show_all_notices
1088
-     * @return bool
1089
-     */
1090
-    public function reset_data($data_to_reset = array(), $show_all_notices = false)
1091
-    {
1092
-        // if $data_to_reset is not in an array, then put it in one
1093
-        if (! is_array($data_to_reset)) {
1094
-            $data_to_reset = array($data_to_reset);
1095
-        }
1096
-        // nothing ??? go home!
1097
-        if (empty($data_to_reset)) {
1098
-            EE_Error::add_error(
1099
-                esc_html__(
1100
-                    'No session data could be reset, because no session var name was provided.',
1101
-                    'event_espresso'
1102
-                ),
1103
-                __FILE__,
1104
-                __FUNCTION__,
1105
-                __LINE__
1106
-            );
1107
-            return false;
1108
-        }
1109
-        $return_value = true;
1110
-        // since $data_to_reset is an array, cycle through the values
1111
-        foreach ($data_to_reset as $reset) {
1112
-            // first check to make sure it is a valid session var
1113
-            if (isset($this->_session_data[ $reset ])) {
1114
-                // then check to make sure it is not a default var
1115
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1116
-                    // remove session var
1117
-                    unset($this->_session_data[ $reset ]);
1118
-                    $this->setSaveState();
1119
-                    if ($show_all_notices) {
1120
-                        EE_Error::add_success(
1121
-                            sprintf(
1122
-                                esc_html__('The session variable %s was removed.', 'event_espresso'),
1123
-                                $reset
1124
-                            ),
1125
-                            __FILE__,
1126
-                            __FUNCTION__,
1127
-                            __LINE__
1128
-                        );
1129
-                    }
1130
-                } else {
1131
-                    // yeeeeeeeeerrrrrrrrrrr OUT !!!!
1132
-                    if ($show_all_notices) {
1133
-                        EE_Error::add_error(
1134
-                            sprintf(
1135
-                                esc_html__(
1136
-                                    'Sorry! %s is a default session datum and can not be reset.',
1137
-                                    'event_espresso'
1138
-                                ),
1139
-                                $reset
1140
-                            ),
1141
-                            __FILE__,
1142
-                            __FUNCTION__,
1143
-                            __LINE__
1144
-                        );
1145
-                    }
1146
-                    $return_value = false;
1147
-                }
1148
-            } elseif ($show_all_notices) {
1149
-                // oops! that session var does not exist!
1150
-                EE_Error::add_error(
1151
-                    sprintf(
1152
-                        esc_html__(
1153
-                            'The session item provided, %s, is invalid or does not exist.',
1154
-                            'event_espresso'
1155
-                        ),
1156
-                        $reset
1157
-                    ),
1158
-                    __FILE__,
1159
-                    __FUNCTION__,
1160
-                    __LINE__
1161
-                );
1162
-                $return_value = false;
1163
-            }
1164
-        } // end of foreach
1165
-        return $return_value;
1166
-    }
1167
-
1168
-
1169
-    /**
1170
-     *   wp_loaded
1171
-     *
1172
-     * @throws EE_Error
1173
-     * @throws InvalidDataTypeException
1174
-     * @throws InvalidInterfaceException
1175
-     * @throws InvalidArgumentException
1176
-     * @throws ReflectionException
1177
-     */
1178
-    public function wp_loaded()
1179
-    {
1180
-        if ($this->request->requestParamIsSet('clear_session')) {
1181
-            $this->clear_session(__CLASS__, __FUNCTION__);
1182
-        }
1183
-    }
1184
-
1185
-
1186
-    /**
1187
-     * Used to reset the entire object (for tests).
1188
-     *
1189
-     * @since 4.3.0
1190
-     * @throws EE_Error
1191
-     * @throws InvalidDataTypeException
1192
-     * @throws InvalidInterfaceException
1193
-     * @throws InvalidArgumentException
1194
-     * @throws ReflectionException
1195
-     */
1196
-    public function reset_instance()
1197
-    {
1198
-        $this->clear_session();
1199
-        self::$_instance = null;
1200
-    }
1201
-
1202
-
1203
-    public function configure_garbage_collection_filters()
1204
-    {
1205
-        // run old filter we had for controlling session cleanup
1206
-        $expired_session_transient_delete_query_limit = absint(
1207
-            apply_filters(
1208
-                'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1209
-                50
1210
-            )
1211
-        );
1212
-        // is there a value? or one that is different than the default 50 records?
1213
-        if ($expired_session_transient_delete_query_limit === 0) {
1214
-            // hook into TransientCacheStorage in case Session cleanup was turned off
1215
-            add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1216
-        } elseif ($expired_session_transient_delete_query_limit !== 50) {
1217
-            // or use that for the new transient cleanup query limit
1218
-            add_filter(
1219
-                'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1220
-                function () use ($expired_session_transient_delete_query_limit) {
1221
-                    return $expired_session_transient_delete_query_limit;
1222
-                }
1223
-            );
1224
-        }
1225
-    }
1226
-
1227
-
1228
-    /**
1229
-     * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1230
-     * @param $data1
1231
-     * @return string
1232
-     */
1233
-    private function find_serialize_error($data1)
1234
-    {
1235
-        $error = '<pre>';
1236
-        $data2 = preg_replace_callback(
1237
-            '!s:(\d+):"(.*?)";!',
1238
-            function ($match) {
1239
-                return ($match[1] === strlen($match[2]))
1240
-                    ? $match[0]
1241
-                    : 's:'
1242
-                      . strlen($match[2])
1243
-                      . ':"'
1244
-                      . $match[2]
1245
-                      . '";';
1246
-            },
1247
-            $data1
1248
-        );
1249
-        $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1250
-        $error .= $data1 . PHP_EOL;
1251
-        $error .= $data2 . PHP_EOL;
1252
-        for ($i = 0; $i < $max; $i++) {
1253
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1254
-                $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1255
-                $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1256
-                $error .= "\t-> Line Number = $i" . PHP_EOL;
1257
-                $start = ($i - 20);
1258
-                $start = ($start < 0) ? 0 : $start;
1259
-                $length = 40;
1260
-                $point = $max - $i;
1261
-                if ($point < 20) {
1262
-                    $rlength = 1;
1263
-                    $rpoint = -$point;
1264
-                } else {
1265
-                    $rpoint = $length - 20;
1266
-                    $rlength = 1;
1267
-                }
1268
-                $error .= "\t-> Section Data1  = ";
1269
-                $error .= substr_replace(
1270
-                    substr($data1, $start, $length),
1271
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1272
-                    $rpoint,
1273
-                    $rlength
1274
-                );
1275
-                $error .= PHP_EOL;
1276
-                $error .= "\t-> Section Data2  = ";
1277
-                $error .= substr_replace(
1278
-                    substr($data2, $start, $length),
1279
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1280
-                    $rpoint,
1281
-                    $rlength
1282
-                );
1283
-                $error .= PHP_EOL;
1284
-            }
1285
-        }
1286
-        $error .= '</pre>';
1287
-        return $error;
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * Saves an  array of settings used for configuring aspects of session behaviour
1293
-     *
1294
-     * @param array $updated_settings
1295
-     */
1296
-    private function updateSessionSettings(array $updated_settings = array())
1297
-    {
1298
-        // add existing settings, but only if not included in incoming $updated_settings array
1299
-        $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1300
-        update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1301
-    }
1302
-
1303
-
1304
-    /**
1305
-     * garbage_collection
1306
-     */
1307
-    public function garbageCollection()
1308
-    {
1309
-        // only perform during regular requests if last garbage collection was over an hour ago
1310
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1311
-            $this->_last_gc = time();
1312
-            $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1313
-            /** @type WPDB $wpdb */
1314
-            global $wpdb;
1315
-            // filter the query limit. Set to 0 to turn off garbage collection
1316
-            $expired_session_transient_delete_query_limit = absint(
1317
-                apply_filters(
1318
-                    'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1319
-                    50
1320
-                )
1321
-            );
1322
-            // non-zero LIMIT means take out the trash
1323
-            if ($expired_session_transient_delete_query_limit) {
1324
-                $session_key = str_replace('_', '\_', EE_Session::session_id_prefix);
1325
-                $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1326
-                // since transient expiration timestamps are set in the future, we can compare against NOW
1327
-                // but we only want to pick up any trash that's been around for more than a day
1328
-                $expiration = time() - DAY_IN_SECONDS;
1329
-                $SQL = "
1070
+		do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1071
+		$this->reset_cart();
1072
+		$this->reset_checkout();
1073
+		$this->reset_transaction();
1074
+		// wipe out everything that isn't a default session datum
1075
+		$this->reset_data(array_keys($this->_session_data));
1076
+		// reset initial site access time and the session expiration
1077
+		$this->_set_init_access_and_expiration();
1078
+		$this->setSaveState();
1079
+		$this->_save_session_to_db(true);
1080
+	}
1081
+
1082
+
1083
+	/**
1084
+	 * resets all non-default session vars. Returns TRUE on success, FALSE on fail
1085
+	 *
1086
+	 * @param array|mixed $data_to_reset
1087
+	 * @param bool        $show_all_notices
1088
+	 * @return bool
1089
+	 */
1090
+	public function reset_data($data_to_reset = array(), $show_all_notices = false)
1091
+	{
1092
+		// if $data_to_reset is not in an array, then put it in one
1093
+		if (! is_array($data_to_reset)) {
1094
+			$data_to_reset = array($data_to_reset);
1095
+		}
1096
+		// nothing ??? go home!
1097
+		if (empty($data_to_reset)) {
1098
+			EE_Error::add_error(
1099
+				esc_html__(
1100
+					'No session data could be reset, because no session var name was provided.',
1101
+					'event_espresso'
1102
+				),
1103
+				__FILE__,
1104
+				__FUNCTION__,
1105
+				__LINE__
1106
+			);
1107
+			return false;
1108
+		}
1109
+		$return_value = true;
1110
+		// since $data_to_reset is an array, cycle through the values
1111
+		foreach ($data_to_reset as $reset) {
1112
+			// first check to make sure it is a valid session var
1113
+			if (isset($this->_session_data[ $reset ])) {
1114
+				// then check to make sure it is not a default var
1115
+				if (! array_key_exists($reset, $this->_default_session_vars)) {
1116
+					// remove session var
1117
+					unset($this->_session_data[ $reset ]);
1118
+					$this->setSaveState();
1119
+					if ($show_all_notices) {
1120
+						EE_Error::add_success(
1121
+							sprintf(
1122
+								esc_html__('The session variable %s was removed.', 'event_espresso'),
1123
+								$reset
1124
+							),
1125
+							__FILE__,
1126
+							__FUNCTION__,
1127
+							__LINE__
1128
+						);
1129
+					}
1130
+				} else {
1131
+					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
1132
+					if ($show_all_notices) {
1133
+						EE_Error::add_error(
1134
+							sprintf(
1135
+								esc_html__(
1136
+									'Sorry! %s is a default session datum and can not be reset.',
1137
+									'event_espresso'
1138
+								),
1139
+								$reset
1140
+							),
1141
+							__FILE__,
1142
+							__FUNCTION__,
1143
+							__LINE__
1144
+						);
1145
+					}
1146
+					$return_value = false;
1147
+				}
1148
+			} elseif ($show_all_notices) {
1149
+				// oops! that session var does not exist!
1150
+				EE_Error::add_error(
1151
+					sprintf(
1152
+						esc_html__(
1153
+							'The session item provided, %s, is invalid or does not exist.',
1154
+							'event_espresso'
1155
+						),
1156
+						$reset
1157
+					),
1158
+					__FILE__,
1159
+					__FUNCTION__,
1160
+					__LINE__
1161
+				);
1162
+				$return_value = false;
1163
+			}
1164
+		} // end of foreach
1165
+		return $return_value;
1166
+	}
1167
+
1168
+
1169
+	/**
1170
+	 *   wp_loaded
1171
+	 *
1172
+	 * @throws EE_Error
1173
+	 * @throws InvalidDataTypeException
1174
+	 * @throws InvalidInterfaceException
1175
+	 * @throws InvalidArgumentException
1176
+	 * @throws ReflectionException
1177
+	 */
1178
+	public function wp_loaded()
1179
+	{
1180
+		if ($this->request->requestParamIsSet('clear_session')) {
1181
+			$this->clear_session(__CLASS__, __FUNCTION__);
1182
+		}
1183
+	}
1184
+
1185
+
1186
+	/**
1187
+	 * Used to reset the entire object (for tests).
1188
+	 *
1189
+	 * @since 4.3.0
1190
+	 * @throws EE_Error
1191
+	 * @throws InvalidDataTypeException
1192
+	 * @throws InvalidInterfaceException
1193
+	 * @throws InvalidArgumentException
1194
+	 * @throws ReflectionException
1195
+	 */
1196
+	public function reset_instance()
1197
+	{
1198
+		$this->clear_session();
1199
+		self::$_instance = null;
1200
+	}
1201
+
1202
+
1203
+	public function configure_garbage_collection_filters()
1204
+	{
1205
+		// run old filter we had for controlling session cleanup
1206
+		$expired_session_transient_delete_query_limit = absint(
1207
+			apply_filters(
1208
+				'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1209
+				50
1210
+			)
1211
+		);
1212
+		// is there a value? or one that is different than the default 50 records?
1213
+		if ($expired_session_transient_delete_query_limit === 0) {
1214
+			// hook into TransientCacheStorage in case Session cleanup was turned off
1215
+			add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1216
+		} elseif ($expired_session_transient_delete_query_limit !== 50) {
1217
+			// or use that for the new transient cleanup query limit
1218
+			add_filter(
1219
+				'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1220
+				function () use ($expired_session_transient_delete_query_limit) {
1221
+					return $expired_session_transient_delete_query_limit;
1222
+				}
1223
+			);
1224
+		}
1225
+	}
1226
+
1227
+
1228
+	/**
1229
+	 * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1230
+	 * @param $data1
1231
+	 * @return string
1232
+	 */
1233
+	private function find_serialize_error($data1)
1234
+	{
1235
+		$error = '<pre>';
1236
+		$data2 = preg_replace_callback(
1237
+			'!s:(\d+):"(.*?)";!',
1238
+			function ($match) {
1239
+				return ($match[1] === strlen($match[2]))
1240
+					? $match[0]
1241
+					: 's:'
1242
+					  . strlen($match[2])
1243
+					  . ':"'
1244
+					  . $match[2]
1245
+					  . '";';
1246
+			},
1247
+			$data1
1248
+		);
1249
+		$max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1250
+		$error .= $data1 . PHP_EOL;
1251
+		$error .= $data2 . PHP_EOL;
1252
+		for ($i = 0; $i < $max; $i++) {
1253
+			if (@$data1[ $i ] !== @$data2[ $i ]) {
1254
+				$error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1255
+				$error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1256
+				$error .= "\t-> Line Number = $i" . PHP_EOL;
1257
+				$start = ($i - 20);
1258
+				$start = ($start < 0) ? 0 : $start;
1259
+				$length = 40;
1260
+				$point = $max - $i;
1261
+				if ($point < 20) {
1262
+					$rlength = 1;
1263
+					$rpoint = -$point;
1264
+				} else {
1265
+					$rpoint = $length - 20;
1266
+					$rlength = 1;
1267
+				}
1268
+				$error .= "\t-> Section Data1  = ";
1269
+				$error .= substr_replace(
1270
+					substr($data1, $start, $length),
1271
+					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1272
+					$rpoint,
1273
+					$rlength
1274
+				);
1275
+				$error .= PHP_EOL;
1276
+				$error .= "\t-> Section Data2  = ";
1277
+				$error .= substr_replace(
1278
+					substr($data2, $start, $length),
1279
+					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1280
+					$rpoint,
1281
+					$rlength
1282
+				);
1283
+				$error .= PHP_EOL;
1284
+			}
1285
+		}
1286
+		$error .= '</pre>';
1287
+		return $error;
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * Saves an  array of settings used for configuring aspects of session behaviour
1293
+	 *
1294
+	 * @param array $updated_settings
1295
+	 */
1296
+	private function updateSessionSettings(array $updated_settings = array())
1297
+	{
1298
+		// add existing settings, but only if not included in incoming $updated_settings array
1299
+		$updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1300
+		update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1301
+	}
1302
+
1303
+
1304
+	/**
1305
+	 * garbage_collection
1306
+	 */
1307
+	public function garbageCollection()
1308
+	{
1309
+		// only perform during regular requests if last garbage collection was over an hour ago
1310
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1311
+			$this->_last_gc = time();
1312
+			$this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1313
+			/** @type WPDB $wpdb */
1314
+			global $wpdb;
1315
+			// filter the query limit. Set to 0 to turn off garbage collection
1316
+			$expired_session_transient_delete_query_limit = absint(
1317
+				apply_filters(
1318
+					'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1319
+					50
1320
+				)
1321
+			);
1322
+			// non-zero LIMIT means take out the trash
1323
+			if ($expired_session_transient_delete_query_limit) {
1324
+				$session_key = str_replace('_', '\_', EE_Session::session_id_prefix);
1325
+				$hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1326
+				// since transient expiration timestamps are set in the future, we can compare against NOW
1327
+				// but we only want to pick up any trash that's been around for more than a day
1328
+				$expiration = time() - DAY_IN_SECONDS;
1329
+				$SQL = "
1330 1330
                     SELECT option_name
1331 1331
                     FROM {$wpdb->options}
1332 1332
                     WHERE
@@ -1335,17 +1335,17 @@  discard block
 block discarded – undo
1335 1335
                     AND option_value < {$expiration}
1336 1336
                     LIMIT {$expired_session_transient_delete_query_limit}
1337 1337
                 ";
1338
-                // produces something like:
1339
-                // SELECT option_name FROM wp_options
1340
-                // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1341
-                // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1342
-                // AND option_value < 1508368198 LIMIT 50
1343
-                $expired_sessions = $wpdb->get_col($SQL);
1344
-                // valid results?
1345
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1346
-                    $this->cache_storage->deleteMany($expired_sessions, true);
1347
-                }
1348
-            }
1349
-        }
1350
-    }
1338
+				// produces something like:
1339
+				// SELECT option_name FROM wp_options
1340
+				// WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1341
+				// OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1342
+				// AND option_value < 1508368198 LIMIT 50
1343
+				$expired_sessions = $wpdb->get_col($SQL);
1344
+				// valid results?
1345
+				if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1346
+					$this->cache_storage->deleteMany($expired_sessions, true);
1347
+				}
1348
+			}
1349
+		}
1350
+	}
1351 1351
 }
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/ModelObjNode.php 2 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -22,206 +22,206 @@
 block discarded – undo
22 22
  */
23 23
 class ModelObjNode extends BaseNode
24 24
 {
25
-    /**
26
-     * @var int|string
27
-     */
28
-    protected $id;
25
+	/**
26
+	 * @var int|string
27
+	 */
28
+	protected $id;
29 29
 
30
-    /**
31
-     * @var EEM_Base
32
-     */
33
-    protected $model;
30
+	/**
31
+	 * @var EEM_Base
32
+	 */
33
+	protected $model;
34 34
 
35
-    /**
36
-     * @var RelationNode[]
37
-     */
38
-    protected $nodes;
35
+	/**
36
+	 * @var RelationNode[]
37
+	 */
38
+	protected $nodes;
39 39
 
40
-    /**
41
-     * We don't pass the model objects because this needs to serialize to something tiny for effiency.
42
-     * @param $model_obj_id
43
-     * @param EEM_Base $model
44
-     * @param array $dont_traverse_models array of model names we DON'T want to traverse.
45
-     */
46
-    public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = [])
47
-    {
48
-        $this->id = $model_obj_id;
49
-        $this->model = $model;
50
-        $this->dont_traverse_models = $dont_traverse_models;
51
-    }
40
+	/**
41
+	 * We don't pass the model objects because this needs to serialize to something tiny for effiency.
42
+	 * @param $model_obj_id
43
+	 * @param EEM_Base $model
44
+	 * @param array $dont_traverse_models array of model names we DON'T want to traverse.
45
+	 */
46
+	public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = [])
47
+	{
48
+		$this->id = $model_obj_id;
49
+		$this->model = $model;
50
+		$this->dont_traverse_models = $dont_traverse_models;
51
+	}
52 52
 
53
-    /**
54
-     * Creates a relation node for each relation of this model's relations.
55
-     * Does NOT call `discover` on them yet though.
56
-     * @since 4.10.12.p
57
-     * @throws \EE_Error
58
-     * @throws InvalidDataTypeException
59
-     * @throws InvalidInterfaceException
60
-     * @throws InvalidArgumentException
61
-     * @throws ReflectionException
62
-     */
63
-    protected function discover()
64
-    {
65
-        $this->nodes = [];
66
-        foreach ($this->model->relation_settings() as $relationName => $relation) {
67
-            // Make sure this isn't one of the models we were told to not traverse into.
68
-            if (in_array($relationName, $this->dont_traverse_models)) {
69
-                continue;
70
-            }
71
-            if ($relation instanceof EE_Has_Many_Relation) {
72
-                $this->nodes[ $relationName ] = new RelationNode(
73
-                    $this->id,
74
-                    $this->model,
75
-                    $relation->get_other_model(),
76
-                    $this->dont_traverse_models
77
-                );
78
-            } elseif (
79
-                $relation instanceof EE_HABTM_Relation &&
80
-                ! in_array(
81
-                    $relation->get_join_model()->get_this_model_name(),
82
-                    $this->dont_traverse_models
83
-                )
84
-            ) {
85
-                $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode(
86
-                    $this->id,
87
-                    $this->model,
88
-                    $relation->get_join_model(),
89
-                    $this->dont_traverse_models
90
-                );
91
-            }
92
-        }
93
-        ksort($this->nodes);
94
-    }
53
+	/**
54
+	 * Creates a relation node for each relation of this model's relations.
55
+	 * Does NOT call `discover` on them yet though.
56
+	 * @since 4.10.12.p
57
+	 * @throws \EE_Error
58
+	 * @throws InvalidDataTypeException
59
+	 * @throws InvalidInterfaceException
60
+	 * @throws InvalidArgumentException
61
+	 * @throws ReflectionException
62
+	 */
63
+	protected function discover()
64
+	{
65
+		$this->nodes = [];
66
+		foreach ($this->model->relation_settings() as $relationName => $relation) {
67
+			// Make sure this isn't one of the models we were told to not traverse into.
68
+			if (in_array($relationName, $this->dont_traverse_models)) {
69
+				continue;
70
+			}
71
+			if ($relation instanceof EE_Has_Many_Relation) {
72
+				$this->nodes[ $relationName ] = new RelationNode(
73
+					$this->id,
74
+					$this->model,
75
+					$relation->get_other_model(),
76
+					$this->dont_traverse_models
77
+				);
78
+			} elseif (
79
+				$relation instanceof EE_HABTM_Relation &&
80
+				! in_array(
81
+					$relation->get_join_model()->get_this_model_name(),
82
+					$this->dont_traverse_models
83
+				)
84
+			) {
85
+				$this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode(
86
+					$this->id,
87
+					$this->model,
88
+					$relation->get_join_model(),
89
+					$this->dont_traverse_models
90
+				);
91
+			}
92
+		}
93
+		ksort($this->nodes);
94
+	}
95 95
 
96 96
 
97
-    /**
98
-     * Whether this item has already been initialized
99
-     */
100
-    protected function isDiscovered()
101
-    {
102
-        return $this->nodes !== null && is_array($this->nodes);
103
-    }
97
+	/**
98
+	 * Whether this item has already been initialized
99
+	 */
100
+	protected function isDiscovered()
101
+	{
102
+		return $this->nodes !== null && is_array($this->nodes);
103
+	}
104 104
 
105
-    /**
106
-     * @since 4.10.12.p
107
-     * @return boolean
108
-     */
109
-    public function isComplete()
110
-    {
111
-        if ($this->complete === null) {
112
-            $this->complete = false;
113
-        }
114
-        return $this->complete;
115
-    }
105
+	/**
106
+	 * @since 4.10.12.p
107
+	 * @return boolean
108
+	 */
109
+	public function isComplete()
110
+	{
111
+		if ($this->complete === null) {
112
+			$this->complete = false;
113
+		}
114
+		return $this->complete;
115
+	}
116 116
 
117
-    /**
118
-     * Triggers working on each child relation node that has work to do.
119
-     * @since 4.10.12.p
120
-     * @param $model_objects_to_identify
121
-     * @return int units of work done
122
-     */
123
-    protected function work($model_objects_to_identify)
124
-    {
125
-        $num_identified = 0;
126
-        // Begin assuming we'll finish all the work on this node and its children...
127
-        $this->complete = true;
128
-        foreach ($this->nodes as $model_name => $relation_node) {
129
-            $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified);
130
-            // To save on space when serializing, only bother keeping a record of relation nodes that actually found
131
-            // related model objects.
132
-            if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) {
133
-                unset($this->nodes[ $model_name ]);
134
-            }
135
-            if ($num_identified >= $model_objects_to_identify) {
136
-                // ...but admit we're wrong if the work exceeded the budget.
137
-                $this->complete = false;
138
-                break;
139
-            }
140
-        }
141
-        return $num_identified;
142
-    }
117
+	/**
118
+	 * Triggers working on each child relation node that has work to do.
119
+	 * @since 4.10.12.p
120
+	 * @param $model_objects_to_identify
121
+	 * @return int units of work done
122
+	 */
123
+	protected function work($model_objects_to_identify)
124
+	{
125
+		$num_identified = 0;
126
+		// Begin assuming we'll finish all the work on this node and its children...
127
+		$this->complete = true;
128
+		foreach ($this->nodes as $model_name => $relation_node) {
129
+			$num_identified += $relation_node->visit($model_objects_to_identify - $num_identified);
130
+			// To save on space when serializing, only bother keeping a record of relation nodes that actually found
131
+			// related model objects.
132
+			if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) {
133
+				unset($this->nodes[ $model_name ]);
134
+			}
135
+			if ($num_identified >= $model_objects_to_identify) {
136
+				// ...but admit we're wrong if the work exceeded the budget.
137
+				$this->complete = false;
138
+				break;
139
+			}
140
+		}
141
+		return $num_identified;
142
+	}
143 143
 
144
-    /**
145
-     * @since 4.10.12.p
146
-     * @return array
147
-     * @throws \EE_Error
148
-     * @throws InvalidDataTypeException
149
-     * @throws InvalidInterfaceException
150
-     * @throws InvalidArgumentException
151
-     * @throws ReflectionException
152
-     */
153
-    public function toArray()
154
-    {
155
-        $tree = [
156
-            'id' => $this->id,
157
-            'complete' => $this->isComplete(),
158
-            'rels' => []
159
-        ];
160
-        if ($this->nodes === null) {
161
-            $tree['rels'] = null;
162
-        } else {
163
-            foreach ($this->nodes as $relation_name => $relation_node) {
164
-                $tree['rels'][ $relation_name ] = $relation_node->toArray();
165
-            }
166
-        }
167
-        return $tree;
168
-    }
144
+	/**
145
+	 * @since 4.10.12.p
146
+	 * @return array
147
+	 * @throws \EE_Error
148
+	 * @throws InvalidDataTypeException
149
+	 * @throws InvalidInterfaceException
150
+	 * @throws InvalidArgumentException
151
+	 * @throws ReflectionException
152
+	 */
153
+	public function toArray()
154
+	{
155
+		$tree = [
156
+			'id' => $this->id,
157
+			'complete' => $this->isComplete(),
158
+			'rels' => []
159
+		];
160
+		if ($this->nodes === null) {
161
+			$tree['rels'] = null;
162
+		} else {
163
+			foreach ($this->nodes as $relation_name => $relation_node) {
164
+				$tree['rels'][ $relation_name ] = $relation_node->toArray();
165
+			}
166
+		}
167
+		return $tree;
168
+	}
169 169
 
170
-    /**
171
-     * @since 4.10.12.p
172
-     * @return array|mixed
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     * @throws ReflectionException
177
-     * @throws \EE_Error
178
-     */
179
-    public function getIds()
180
-    {
181
-        $ids = [
182
-            $this->model->get_this_model_name() => [
183
-                $this->id => $this->id
184
-            ]
185
-        ];
186
-        if ($this->nodes && is_array($this->nodes)) {
187
-            foreach ($this->nodes as $relation_node) {
188
-                $ids = array_replace_recursive($ids, $relation_node->getIds());
189
-            }
190
-        }
191
-        return $ids;
192
-    }
170
+	/**
171
+	 * @since 4.10.12.p
172
+	 * @return array|mixed
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 * @throws ReflectionException
177
+	 * @throws \EE_Error
178
+	 */
179
+	public function getIds()
180
+	{
181
+		$ids = [
182
+			$this->model->get_this_model_name() => [
183
+				$this->id => $this->id
184
+			]
185
+		];
186
+		if ($this->nodes && is_array($this->nodes)) {
187
+			foreach ($this->nodes as $relation_node) {
188
+				$ids = array_replace_recursive($ids, $relation_node->getIds());
189
+			}
190
+		}
191
+		return $ids;
192
+	}
193 193
 
194
-    /**
195
-     * Don't serialize the models. Just record their names on some dynamic properties.
196
-     * @since 4.10.12.p
197
-     */
198
-    public function __sleep()
199
-    {
200
-        $this->m = $this->model->get_this_model_name();
201
-        return array_merge(
202
-            [
203
-                'm',
204
-                'id',
205
-                'nodes',
206
-            ],
207
-            parent::__sleep()
208
-        );
209
-    }
194
+	/**
195
+	 * Don't serialize the models. Just record their names on some dynamic properties.
196
+	 * @since 4.10.12.p
197
+	 */
198
+	public function __sleep()
199
+	{
200
+		$this->m = $this->model->get_this_model_name();
201
+		return array_merge(
202
+			[
203
+				'm',
204
+				'id',
205
+				'nodes',
206
+			],
207
+			parent::__sleep()
208
+		);
209
+	}
210 210
 
211
-    /**
212
-     * Use the dynamic properties to instantiate the models we use.
213
-     * @since 4.10.12.p
214
-     * @throws EE_Error
215
-     * @throws InvalidArgumentException
216
-     * @throws InvalidDataTypeException
217
-     * @throws InvalidInterfaceException
218
-     * @throws ReflectionException
219
-     */
220
-    public function __wakeup()
221
-    {
222
-        $this->model = EE_Registry::instance()->load_model($this->m);
223
-        parent::__wakeup();
224
-    }
211
+	/**
212
+	 * Use the dynamic properties to instantiate the models we use.
213
+	 * @since 4.10.12.p
214
+	 * @throws EE_Error
215
+	 * @throws InvalidArgumentException
216
+	 * @throws InvalidDataTypeException
217
+	 * @throws InvalidInterfaceException
218
+	 * @throws ReflectionException
219
+	 */
220
+	public function __wakeup()
221
+	{
222
+		$this->model = EE_Registry::instance()->load_model($this->m);
223
+		parent::__wakeup();
224
+	}
225 225
 }
226 226
 // End of file Visitor.php
227 227
 // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
                 continue;
70 70
             }
71 71
             if ($relation instanceof EE_Has_Many_Relation) {
72
-                $this->nodes[ $relationName ] = new RelationNode(
72
+                $this->nodes[$relationName] = new RelationNode(
73 73
                     $this->id,
74 74
                     $this->model,
75 75
                     $relation->get_other_model(),
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                     $this->dont_traverse_models
83 83
                 )
84 84
             ) {
85
-                $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode(
85
+                $this->nodes[$relation->get_join_model()->get_this_model_name()] = new RelationNode(
86 86
                     $this->id,
87 87
                     $this->model,
88 88
                     $relation->get_join_model(),
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             // To save on space when serializing, only bother keeping a record of relation nodes that actually found
131 131
             // related model objects.
132 132
             if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) {
133
-                unset($this->nodes[ $model_name ]);
133
+                unset($this->nodes[$model_name]);
134 134
             }
135 135
             if ($num_identified >= $model_objects_to_identify) {
136 136
                 // ...but admit we're wrong if the work exceeded the budget.
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
             $tree['rels'] = null;
162 162
         } else {
163 163
             foreach ($this->nodes as $relation_name => $relation_node) {
164
-                $tree['rels'][ $relation_name ] = $relation_node->toArray();
164
+                $tree['rels'][$relation_name] = $relation_node->toArray();
165 165
             }
166 166
         }
167 167
         return $tree;
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model_Extensions.lib.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
         }
69 69
 
70 70
         // make sure we don't register twice
71
-        if (isset(self::$_registry[ $identifier ])) {
71
+        if (isset(self::$_registry[$identifier])) {
72 72
             return;
73 73
         }
74 74
         // check correct loading
75
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
75
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
76 76
             EE_Error::doing_it_wrong(
77 77
                 __METHOD__,
78 78
                 sprintf(
@@ -89,30 +89,30 @@  discard block
 block discarded – undo
89 89
             );
90 90
         }
91 91
 
92
-        self::$_registry[ $identifier ]   = $setup_args;
93
-        self::$_extensions[ $identifier ] = [];
92
+        self::$_registry[$identifier]   = $setup_args;
93
+        self::$_extensions[$identifier] = [];
94 94
 
95 95
         if (isset($setup_args['model_extension_paths'])) {
96
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
96
+            require_once(EE_LIBRARIES.'plugin_api/db/EEME_Base.lib.php');
97 97
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
98 98
             // remove all files that are not PHP
99 99
             foreach ($class_to_filepath_map as $class => $path) {
100 100
                 if (substr($path, strlen($path) - 3) !== 'php') {
101
-                    unset($class_to_filepath_map[ $class ]);
101
+                    unset($class_to_filepath_map[$class]);
102 102
                 }
103 103
             }
104 104
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
105 105
             foreach (array_keys($class_to_filepath_map) as $classname) {
106
-                self::$_extensions[ $identifier ]['models'][ $classname ] = new $classname();
106
+                self::$_extensions[$identifier]['models'][$classname] = new $classname();
107 107
             }
108 108
             unset($setup_args['model_extension_paths']);
109 109
         }
110 110
         if (isset($setup_args['class_extension_paths'])) {
111
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
111
+            require_once(EE_LIBRARIES.'plugin_api/db/EEE_Base_Class.lib.php');
112 112
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
113 113
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
114 114
             foreach (array_keys($class_to_filepath_map) as $classname) {
115
-                self::$_extensions[ $identifier ]['classes'][ $classname ] = new $classname();
115
+                self::$_extensions[$identifier]['classes'][$classname] = new $classname();
116 116
             }
117 117
             unset($setup_args['class_extension_paths']);
118 118
         }
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public static function deregister($identifier = '')
133 133
     {
134
-        if (isset(self::$_registry[ $identifier ])) {
135
-            unset(self::$_registry[ $identifier ]);
136
-            foreach (self::$_extensions[ $identifier ] as $extension_of_type) {
134
+        if (isset(self::$_registry[$identifier])) {
135
+            unset(self::$_registry[$identifier]);
136
+            foreach (self::$_extensions[$identifier] as $extension_of_type) {
137 137
                 foreach ($extension_of_type as $extension) {
138 138
                     $extension->deregister();
139 139
                 }
Please login to merge, or discard this patch.
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -11,132 +11,132 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Register_Model_Extensions implements EEI_Plugin_API
13 13
 {
14
-    protected static $_registry;
14
+	protected static $_registry;
15 15
 
16
-    protected static $_extensions = [];
16
+	protected static $_extensions = [];
17 17
 
18 18
 
19
-    /**
20
-     * register method for setting up model extensions
21
-     *
22
-     * @param string $identifier            unique id for the extensions being setup
23
-     * @param array  $setup_args            {
24
-     * @return void
25
-     * @throws EE_Error
26
-     * @type  array  $model_extension_paths array of folders containing DB model extensions, where each file follows
27
-     *                                      the models naming convention, which is:
28
-     *                                      EEME_{your_plugin_slug}_model_name_extended}.model_ext.php.
29
-     *                                      Where {your_plugin_slug} is really anything you want (but something having
30
-     *                                      to do with your addon, like 'Calendar' or '3D_View') and
31
-     *                                      model_name_extended} is the model extended.
32
-     *                                      The class contained in teh file should extend
33
-     *                                      EEME_Base_{model_name_extended}.model_ext.php.
34
-     *                                      Where {your_plugin_slug} is really anything you want (but something
35
-     *                                      having to do with your addon, like 'Calendar' or '3D_View') and
36
-     *                                      {model_name_extended} is the model extended. The class contained in teh
37
-     *                                      file should extend EEME_Base
38
-     * @type array   $class_extension_paths array of folders containing DB class extensions, where each file follows
39
-     *                                      the model class extension naming convention, which is:
40
-     *                                      EEE_{your_plugin_slug}_model_name_extended}.class_ext.php.
41
-     *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
42
-     *                                      and model_name_extended} is the name of the model extended, eg
43
-     *                                      'Attendee','Event',etc.
44
-     *                                      The class contained in the file should extend EEE_Base_Class
45
-     *                                      ._{model_name_extended}.class_ext.php.
46
-     *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
47
-     *                                      and {model_name_extended} is the name of the model extended, eg
48
-     *                                      'Attendee','Event',etc. The class contained in the file should extend
49
-     *                                      EEE_Base_Class.
50
-     *                                      }
51
-     *
52
-     */
53
-    public static function register($identifier = '', array $setup_args = [])
54
-    {
55
-        // required fields MUST be present, so let's make sure they are.
56
-        if (
57
-            empty($identifier)
58
-            || ! is_array($setup_args)
59
-            || (empty($setup_args['model_extension_paths']) && empty($setup_args['class_extension_paths']))
60
-        ) {
61
-            throw new EE_Error(
62
-                esc_html__(
63
-                    'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)',
64
-                    'event_espresso'
65
-                )
66
-            );
67
-        }
19
+	/**
20
+	 * register method for setting up model extensions
21
+	 *
22
+	 * @param string $identifier            unique id for the extensions being setup
23
+	 * @param array  $setup_args            {
24
+	 * @return void
25
+	 * @throws EE_Error
26
+	 * @type  array  $model_extension_paths array of folders containing DB model extensions, where each file follows
27
+	 *                                      the models naming convention, which is:
28
+	 *                                      EEME_{your_plugin_slug}_model_name_extended}.model_ext.php.
29
+	 *                                      Where {your_plugin_slug} is really anything you want (but something having
30
+	 *                                      to do with your addon, like 'Calendar' or '3D_View') and
31
+	 *                                      model_name_extended} is the model extended.
32
+	 *                                      The class contained in teh file should extend
33
+	 *                                      EEME_Base_{model_name_extended}.model_ext.php.
34
+	 *                                      Where {your_plugin_slug} is really anything you want (but something
35
+	 *                                      having to do with your addon, like 'Calendar' or '3D_View') and
36
+	 *                                      {model_name_extended} is the model extended. The class contained in teh
37
+	 *                                      file should extend EEME_Base
38
+	 * @type array   $class_extension_paths array of folders containing DB class extensions, where each file follows
39
+	 *                                      the model class extension naming convention, which is:
40
+	 *                                      EEE_{your_plugin_slug}_model_name_extended}.class_ext.php.
41
+	 *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
42
+	 *                                      and model_name_extended} is the name of the model extended, eg
43
+	 *                                      'Attendee','Event',etc.
44
+	 *                                      The class contained in the file should extend EEE_Base_Class
45
+	 *                                      ._{model_name_extended}.class_ext.php.
46
+	 *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
47
+	 *                                      and {model_name_extended} is the name of the model extended, eg
48
+	 *                                      'Attendee','Event',etc. The class contained in the file should extend
49
+	 *                                      EEE_Base_Class.
50
+	 *                                      }
51
+	 *
52
+	 */
53
+	public static function register($identifier = '', array $setup_args = [])
54
+	{
55
+		// required fields MUST be present, so let's make sure they are.
56
+		if (
57
+			empty($identifier)
58
+			|| ! is_array($setup_args)
59
+			|| (empty($setup_args['model_extension_paths']) && empty($setup_args['class_extension_paths']))
60
+		) {
61
+			throw new EE_Error(
62
+				esc_html__(
63
+					'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)',
64
+					'event_espresso'
65
+				)
66
+			);
67
+		}
68 68
 
69
-        // make sure we don't register twice
70
-        if (isset(self::$_registry[ $identifier ])) {
71
-            return;
72
-        }
73
-        // check correct loading
74
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
75
-            EE_Error::doing_it_wrong(
76
-                __METHOD__,
77
-                sprintf(
78
-                    esc_html__(
79
-                        'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s',
80
-                        'event_espresso'
81
-                    ),
82
-                    $identifier,
83
-                    '<br />',
84
-                    did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done',
85
-                    did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done'
86
-                ),
87
-                '4.3'
88
-            );
89
-        }
69
+		// make sure we don't register twice
70
+		if (isset(self::$_registry[ $identifier ])) {
71
+			return;
72
+		}
73
+		// check correct loading
74
+		if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
75
+			EE_Error::doing_it_wrong(
76
+				__METHOD__,
77
+				sprintf(
78
+					esc_html__(
79
+						'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s',
80
+						'event_espresso'
81
+					),
82
+					$identifier,
83
+					'<br />',
84
+					did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done',
85
+					did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done'
86
+				),
87
+				'4.3'
88
+			);
89
+		}
90 90
 
91
-        self::$_registry[ $identifier ]   = $setup_args;
92
-        self::$_extensions[ $identifier ] = [];
91
+		self::$_registry[ $identifier ]   = $setup_args;
92
+		self::$_extensions[ $identifier ] = [];
93 93
 
94
-        if (isset($setup_args['model_extension_paths'])) {
95
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
96
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
97
-            // remove all files that are not PHP
98
-            foreach ($class_to_filepath_map as $class => $path) {
99
-                if (substr($path, strlen($path) - 3) !== 'php') {
100
-                    unset($class_to_filepath_map[ $class ]);
101
-                }
102
-            }
103
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
104
-            foreach (array_keys($class_to_filepath_map) as $classname) {
105
-                self::$_extensions[ $identifier ]['models'][ $classname ] = new $classname();
106
-            }
107
-            unset($setup_args['model_extension_paths']);
108
-        }
109
-        if (isset($setup_args['class_extension_paths'])) {
110
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
111
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
112
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
113
-            foreach (array_keys($class_to_filepath_map) as $classname) {
114
-                self::$_extensions[ $identifier ]['classes'][ $classname ] = new $classname();
115
-            }
116
-            unset($setup_args['class_extension_paths']);
117
-        }
118
-        foreach ($setup_args as $unknown_key => $unknown_config) {
119
-            throw new EE_Error(
120
-                sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
121
-            );
122
-        }
123
-    }
94
+		if (isset($setup_args['model_extension_paths'])) {
95
+			require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
96
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
97
+			// remove all files that are not PHP
98
+			foreach ($class_to_filepath_map as $class => $path) {
99
+				if (substr($path, strlen($path) - 3) !== 'php') {
100
+					unset($class_to_filepath_map[ $class ]);
101
+				}
102
+			}
103
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
104
+			foreach (array_keys($class_to_filepath_map) as $classname) {
105
+				self::$_extensions[ $identifier ]['models'][ $classname ] = new $classname();
106
+			}
107
+			unset($setup_args['model_extension_paths']);
108
+		}
109
+		if (isset($setup_args['class_extension_paths'])) {
110
+			require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
111
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
112
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
113
+			foreach (array_keys($class_to_filepath_map) as $classname) {
114
+				self::$_extensions[ $identifier ]['classes'][ $classname ] = new $classname();
115
+			}
116
+			unset($setup_args['class_extension_paths']);
117
+		}
118
+		foreach ($setup_args as $unknown_key => $unknown_config) {
119
+			throw new EE_Error(
120
+				sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
121
+			);
122
+		}
123
+	}
124 124
 
125 125
 
126
-    /**
127
-     * deregister
128
-     *
129
-     * @param string $identifier
130
-     */
131
-    public static function deregister($identifier = '')
132
-    {
133
-        if (isset(self::$_registry[ $identifier ])) {
134
-            unset(self::$_registry[ $identifier ]);
135
-            foreach (self::$_extensions[ $identifier ] as $extension_of_type) {
136
-                foreach ($extension_of_type as $extension) {
137
-                    $extension->deregister();
138
-                }
139
-            }
140
-        }
141
-    }
126
+	/**
127
+	 * deregister
128
+	 *
129
+	 * @param string $identifier
130
+	 */
131
+	public static function deregister($identifier = '')
132
+	{
133
+		if (isset(self::$_registry[ $identifier ])) {
134
+			unset(self::$_registry[ $identifier ]);
135
+			foreach (self::$_extensions[ $identifier ] as $extension_of_type) {
136
+				foreach ($extension_of_type as $extension) {
137
+					$extension->deregister();
138
+				}
139
+			}
140
+		}
141
+	}
142 142
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Payment_Method.lib.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             );
60 60
         }
61 61
         // make sure we don't register twice
62
-        if (isset(self::$_settings[ $identifier ])) {
62
+        if (isset(self::$_settings[$identifier])) {
63 63
             return;
64 64
         }
65 65
         // make sure this was called in the right place!
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             );
78 78
         }
79 79
         // setup $_settings array from incoming values.
80
-        self::$_settings[ $identifier ] = [
80
+        self::$_settings[$identifier] = [
81 81
             // array of full server paths to any EE_PMT_Base children used
82 82
             'payment_method_paths' => isset($setup_args['payment_method_paths'])
83 83
                 ? (array) $setup_args['payment_method_paths']
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
         if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
94 94
             $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
95 95
             // register payment methods directly
96
-            foreach (self::$_settings[ $identifier ]['payment_method_paths'] as $payment_method_path) {
96
+            foreach (self::$_settings[$identifier]['payment_method_paths'] as $payment_method_path) {
97 97
                 $payment_method_manager->register_payment_method($payment_method_path);
98 98
             }
99 99
             $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
100 100
             $capabilities->addCaps(
101
-                self::getPaymentMethodCapabilities(self::$_settings[ $identifier ])
101
+                self::getPaymentMethodCapabilities(self::$_settings[$identifier])
102 102
             );
103 103
         }
104 104
     }
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public static function deregister($identifier = '')
137 137
     {
138
-        if (isset(self::$_settings[ $identifier ])) {
138
+        if (isset(self::$_settings[$identifier])) {
139 139
             // set action for just this module id to delay deregistration until core is loaded and ready.
140
-            $module_settings = self::$_settings[ $identifier ];
141
-            unset(self::$_settings[ $identifier ]);
140
+            $module_settings = self::$_settings[$identifier];
141
+            unset(self::$_settings[$identifier]);
142 142
             add_action(
143 143
                 'AHEE__EE_System__core_loaded_and_ready',
144
-                function () use ($module_settings) {
144
+                function() use ($module_settings) {
145 145
                     $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
146 146
                     $capabilities->removeCaps(
147 147
                         EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings)
Please login to merge, or discard this patch.
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -18,163 +18,163 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Register_Payment_Method implements EEI_Plugin_API
20 20
 {
21
-    /**
22
-     * Holds values for registered payment methods
23
-     *
24
-     * @var array
25
-     */
26
-    protected static $_settings = [];
21
+	/**
22
+	 * Holds values for registered payment methods
23
+	 *
24
+	 * @var array
25
+	 */
26
+	protected static $_settings = [];
27 27
 
28 28
 
29
-    /**
30
-     * Method for registering new EE_PMT_Base children
31
-     *
32
-     * @param string  $identifier           a unique identifier for this set of modules Required.
33
-     * @param array   $setup_args           an array of arguments provided for registering modules Required.{
34
-     * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
35
-     *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
36
-     *                                      the files EE_PMT_Payomatic.pm.php)
37
-     *                                      }
38
-     * @return void
39
-     * @throws EE_Error
40
-     * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
41
-     *                                      children, or to the EED_Module files themselves
42
-     * @throws InvalidDataTypeException
43
-     * @throws DomainException
44
-     * @throws InvalidArgumentException
45
-     * @throws InvalidInterfaceException
46
-     * @throws InvalidDataTypeException
47
-     * @since    4.5.0
48
-     */
49
-    public static function register($identifier = '', array $setup_args = [])
50
-    {
51
-        // required fields MUST be present, so let's make sure they are.
52
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
53
-            throw new EE_Error(
54
-                esc_html__(
55
-                    'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
56
-                    'event_espresso'
57
-                )
58
-            );
59
-        }
60
-        // make sure we don't register twice
61
-        if (isset(self::$_settings[ $identifier ])) {
62
-            return;
63
-        }
64
-        // make sure this was called in the right place!
65
-        if (
66
-            ! did_action('AHEE__EE_System__load_espresso_addons')
67
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
68
-        ) {
69
-            EE_Error::doing_it_wrong(
70
-                __METHOD__,
71
-                esc_html__(
72
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
73
-                    'event_espresso'
74
-                ),
75
-                '4.3.0'
76
-            );
77
-        }
78
-        // setup $_settings array from incoming values.
79
-        self::$_settings[ $identifier ] = [
80
-            // array of full server paths to any EE_PMT_Base children used
81
-            'payment_method_paths' => isset($setup_args['payment_method_paths'])
82
-                ? (array) $setup_args['payment_method_paths']
83
-                : [],
84
-        ];
85
-        // add to list of modules to be registered
86
-        add_filter(
87
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
88
-            ['EE_Register_Payment_Method', 'add_payment_methods']
89
-        );
90
-        // If EE_Payment_Method_Manager::register_payment_methods has already been called,
91
-        // then we need to add our caps for this payment method manually
92
-        if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
93
-            $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
94
-            // register payment methods directly
95
-            foreach (self::$_settings[ $identifier ]['payment_method_paths'] as $payment_method_path) {
96
-                $payment_method_manager->register_payment_method($payment_method_path);
97
-            }
98
-            $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
99
-            $capabilities->addCaps(
100
-                self::getPaymentMethodCapabilities(self::$_settings[ $identifier ])
101
-            );
102
-        }
103
-    }
29
+	/**
30
+	 * Method for registering new EE_PMT_Base children
31
+	 *
32
+	 * @param string  $identifier           a unique identifier for this set of modules Required.
33
+	 * @param array   $setup_args           an array of arguments provided for registering modules Required.{
34
+	 * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
35
+	 *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
36
+	 *                                      the files EE_PMT_Payomatic.pm.php)
37
+	 *                                      }
38
+	 * @return void
39
+	 * @throws EE_Error
40
+	 * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
41
+	 *                                      children, or to the EED_Module files themselves
42
+	 * @throws InvalidDataTypeException
43
+	 * @throws DomainException
44
+	 * @throws InvalidArgumentException
45
+	 * @throws InvalidInterfaceException
46
+	 * @throws InvalidDataTypeException
47
+	 * @since    4.5.0
48
+	 */
49
+	public static function register($identifier = '', array $setup_args = [])
50
+	{
51
+		// required fields MUST be present, so let's make sure they are.
52
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
53
+			throw new EE_Error(
54
+				esc_html__(
55
+					'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
56
+					'event_espresso'
57
+				)
58
+			);
59
+		}
60
+		// make sure we don't register twice
61
+		if (isset(self::$_settings[ $identifier ])) {
62
+			return;
63
+		}
64
+		// make sure this was called in the right place!
65
+		if (
66
+			! did_action('AHEE__EE_System__load_espresso_addons')
67
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
68
+		) {
69
+			EE_Error::doing_it_wrong(
70
+				__METHOD__,
71
+				esc_html__(
72
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
73
+					'event_espresso'
74
+				),
75
+				'4.3.0'
76
+			);
77
+		}
78
+		// setup $_settings array from incoming values.
79
+		self::$_settings[ $identifier ] = [
80
+			// array of full server paths to any EE_PMT_Base children used
81
+			'payment_method_paths' => isset($setup_args['payment_method_paths'])
82
+				? (array) $setup_args['payment_method_paths']
83
+				: [],
84
+		];
85
+		// add to list of modules to be registered
86
+		add_filter(
87
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
88
+			['EE_Register_Payment_Method', 'add_payment_methods']
89
+		);
90
+		// If EE_Payment_Method_Manager::register_payment_methods has already been called,
91
+		// then we need to add our caps for this payment method manually
92
+		if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
93
+			$payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
94
+			// register payment methods directly
95
+			foreach (self::$_settings[ $identifier ]['payment_method_paths'] as $payment_method_path) {
96
+				$payment_method_manager->register_payment_method($payment_method_path);
97
+			}
98
+			$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
99
+			$capabilities->addCaps(
100
+				self::getPaymentMethodCapabilities(self::$_settings[ $identifier ])
101
+			);
102
+		}
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * Filters the list of payment methods to add ours.
108
-     * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
109
-     *
110
-     * @param array $payment_method_folders array of paths to all payment methods that require registering
111
-     * @return array
112
-     */
113
-    public static function add_payment_methods(array $payment_method_folders)
114
-    {
115
-        foreach (self::$_settings as $settings) {
116
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
117
-                $payment_method_folders[] = $payment_method_path;
118
-            }
119
-        }
120
-        return $payment_method_folders;
121
-    }
106
+	/**
107
+	 * Filters the list of payment methods to add ours.
108
+	 * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
109
+	 *
110
+	 * @param array $payment_method_folders array of paths to all payment methods that require registering
111
+	 * @return array
112
+	 */
113
+	public static function add_payment_methods(array $payment_method_folders)
114
+	{
115
+		foreach (self::$_settings as $settings) {
116
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
117
+				$payment_method_folders[] = $payment_method_path;
118
+			}
119
+		}
120
+		return $payment_method_folders;
121
+	}
122 122
 
123 123
 
124
-    /**
125
-     * This deregisters a module that was previously registered with a specific $identifier.
126
-     *
127
-     * @param string $identifier the name for the module that was previously registered
128
-     * @return void
129
-     * @throws DomainException
130
-     * @throws InvalidArgumentException
131
-     * @throws InvalidInterfaceException
132
-     * @throws InvalidDataTypeException
133
-     * @since    4.3.0
134
-     */
135
-    public static function deregister($identifier = '')
136
-    {
137
-        if (isset(self::$_settings[ $identifier ])) {
138
-            // set action for just this module id to delay deregistration until core is loaded and ready.
139
-            $module_settings = self::$_settings[ $identifier ];
140
-            unset(self::$_settings[ $identifier ]);
141
-            add_action(
142
-                'AHEE__EE_System__core_loaded_and_ready',
143
-                function () use ($module_settings) {
144
-                    $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
145
-                    $capabilities->removeCaps(
146
-                        EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings)
147
-                    );
148
-                }
149
-            );
150
-        }
151
-    }
124
+	/**
125
+	 * This deregisters a module that was previously registered with a specific $identifier.
126
+	 *
127
+	 * @param string $identifier the name for the module that was previously registered
128
+	 * @return void
129
+	 * @throws DomainException
130
+	 * @throws InvalidArgumentException
131
+	 * @throws InvalidInterfaceException
132
+	 * @throws InvalidDataTypeException
133
+	 * @since    4.3.0
134
+	 */
135
+	public static function deregister($identifier = '')
136
+	{
137
+		if (isset(self::$_settings[ $identifier ])) {
138
+			// set action for just this module id to delay deregistration until core is loaded and ready.
139
+			$module_settings = self::$_settings[ $identifier ];
140
+			unset(self::$_settings[ $identifier ]);
141
+			add_action(
142
+				'AHEE__EE_System__core_loaded_and_ready',
143
+				function () use ($module_settings) {
144
+					$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
145
+					$capabilities->removeCaps(
146
+						EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings)
147
+					);
148
+				}
149
+			);
150
+		}
151
+	}
152 152
 
153 153
 
154
-    /**
155
-     * returns an array of the caps that get added when a Payment Method is registered
156
-     *
157
-     * @param array $settings
158
-     * @return array
159
-     * @throws DomainException
160
-     * @throws InvalidArgumentException
161
-     * @throws InvalidInterfaceException
162
-     * @throws InvalidDataTypeException
163
-     * @access private  Developers do NOT use this method.  It's only public for PHP5.3 closure support (see deregister)
164
-     *                  When we drop support for PHP5.3 this will be made private again.  You have been warned.
165
-     */
166
-    public static function getPaymentMethodCapabilities(array $settings)
167
-    {
168
-        $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
169
-        $payment_method_caps    = ['administrator' => []];
170
-        if (isset($settings['payment_method_paths'])) {
171
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
172
-                $payment_method_caps = $payment_method_manager->addPaymentMethodCap(
173
-                    strtolower(basename($payment_method_path)),
174
-                    $payment_method_caps
175
-                );
176
-            }
177
-        }
178
-        return $payment_method_caps;
179
-    }
154
+	/**
155
+	 * returns an array of the caps that get added when a Payment Method is registered
156
+	 *
157
+	 * @param array $settings
158
+	 * @return array
159
+	 * @throws DomainException
160
+	 * @throws InvalidArgumentException
161
+	 * @throws InvalidInterfaceException
162
+	 * @throws InvalidDataTypeException
163
+	 * @access private  Developers do NOT use this method.  It's only public for PHP5.3 closure support (see deregister)
164
+	 *                  When we drop support for PHP5.3 this will be made private again.  You have been warned.
165
+	 */
166
+	public static function getPaymentMethodCapabilities(array $settings)
167
+	{
168
+		$payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
169
+		$payment_method_caps    = ['administrator' => []];
170
+		if (isset($settings['payment_method_paths'])) {
171
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
172
+				$payment_method_caps = $payment_method_manager->addPaymentMethodCap(
173
+					strtolower(basename($payment_method_path)),
174
+					$payment_method_caps
175
+				);
176
+			}
177
+		}
178
+		return $payment_method_caps;
179
+	}
180 180
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Messages_Template_Pack.lib.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
         }
71 71
 
72 72
         // make sure we don't register twice
73
-        if (isset(self::$_registry[ $identifier ])) {
73
+        if (isset(self::$_registry[$identifier])) {
74 74
             return;
75 75
         }
76 76
 
77 77
         // check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack.
78
-        if (isset(self::$_registry[ $identifier ])) {
79
-            $identifier = uniqid() . '_' . $identifier;
78
+        if (isset(self::$_registry[$identifier])) {
79
+            $identifier = uniqid().'_'.$identifier;
80 80
         }
81 81
 
82 82
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         }
100 100
 
101 101
         if (self::_verify_class_not_exist($setup_args['classname'])) {
102
-            self::$_registry[ $identifier ] = [
102
+            self::$_registry[$identifier] = [
103 103
                 'path'      => (string) $setup_args['path'],
104 104
                 'classname' => (string) $setup_args['classname'],
105 105
             ];
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
     {
152 152
         foreach (self::$_registry as $args) {
153 153
             // verify class_exists
154
-            if (! class_exists($args['classname'])) {
155
-                require_once($args['path'] . '/' . $args['classname'] . '.class.php');
154
+            if ( ! class_exists($args['classname'])) {
155
+                require_once($args['path'].'/'.$args['classname'].'.class.php');
156 156
             }
157 157
 
158 158
             // check again!
159 159
             if (class_exists($args['classname'])) {
160 160
                 $template_pack                           = new $args['classname']();
161
-                $template_packs[ $template_pack->dbref ] = $template_pack;
161
+                $template_packs[$template_pack->dbref] = $template_pack;
162 162
             }
163 163
         }
164 164
 
@@ -208,6 +208,6 @@  discard block
 block discarded – undo
208 208
      */
209 209
     public static function deregister($identifier = '')
210 210
     {
211
-        unset(self::$_registry[ $identifier ]);
211
+        unset(self::$_registry[$identifier]);
212 212
     }
213 213
 }
Please login to merge, or discard this patch.
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -10,202 +10,202 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Register_Messages_Template_Pack implements EEI_Plugin_API
12 12
 {
13
-    /**
14
-     * Holds values for registered template pack
15
-     *
16
-     * @since 4.5.0
17
-     *
18
-     * @var array
19
-     */
20
-    protected static $_registry = [];
21
-
22
-
23
-    /**
24
-     * Used to register a new template pack with the messages system.
25
-     *
26
-     * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to
27
-     * change entire layouts for a set of message templates.  This method is used to register the new template pack and
28
-     * automatically have it loaded in the appropriate places.
29
-     *
30
-     * This registry also verifies that there isn't already a template pack registered with the same name and if there
31
-     * is then it will add an EE_Error notice.
32
-     *
33
-     * Note that this only handles registering the your Template Pack class with the message template pack system.
34
-     * However, there is also a naming schema you must follow for templates you are providing with your template pack.
35
-     *
36
-     * @param string $identifier The internal reference used to refer to this template pack.  Note, this is first come,
37
-     *                           first serve.  If there is already a template pack registered with this name then the
38
-     *                           registry will assign a unique reference for it so it can still be activated (but this
39
-     *                           makes it harder to deregister as it will be unique per load - so its best to try to
40
-     *                           make this a unique string!)
41
-     * @param array  $setup_args array {
42
-     *                           An array of required values for registering the template pack.
43
-     * @type string  $path       The path for the new template pack class.
44
-     * @type string  $classname  The name of the new Template Pack Class.
45
-     *                           }
46
-     *
47
-     * @return void
48
-     * @throws EE_Error
49
-     *
50
-     * @see    core/libraries/messages/defaults/default/* for all the example templates the default template pack
51
-     *         supports.
52
-     *
53
-     *
54
-     * @since  4.5.0
55
-     * @see    EE_Messages_Template_Pack_Default for an example class
56
-     */
57
-    public static function register($identifier = '', array $setup_args = [])
58
-    {
59
-
60
-        // check for required params
61
-        if (empty($identifier) || empty($setup_args['path']) || empty($setup_args['classname'])) {
62
-            throw new EE_Error(
63
-                esc_html__(
64
-                    'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ',
65
-                    'event_espresso'
66
-                )
67
-            );
68
-        }
69
-
70
-        // make sure we don't register twice
71
-        if (isset(self::$_registry[ $identifier ])) {
72
-            return;
73
-        }
74
-
75
-        // check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack.
76
-        if (isset(self::$_registry[ $identifier ])) {
77
-            $identifier = uniqid() . '_' . $identifier;
78
-        }
79
-
80
-
81
-        // make sure this was called in the right place!
82
-        if (
83
-            ! did_action('EE_Brewing_Regular___messages_caf')
84
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
85
-        ) {
86
-            EE_Error::doing_it_wrong(
87
-                __METHOD__,
88
-                sprintf(
89
-                    esc_html__(
90
-                        'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
91
-                        'event_espresso'
92
-                    ),
93
-                    $identifier
94
-                ),
95
-                '4.5.0'
96
-            );
97
-        }
98
-
99
-        if (self::_verify_class_not_exist($setup_args['classname'])) {
100
-            self::$_registry[ $identifier ] = [
101
-                'path'      => (string) $setup_args['path'],
102
-                'classname' => (string) $setup_args['classname'],
103
-            ];
104
-        }
105
-
106
-        // hook into the system
107
-        add_filter(
108
-            'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
109
-            ['EE_Register_Messages_Template_Pack', 'set_template_pack_path'],
110
-            10
111
-        );
112
-        add_filter(
113
-            'FHEE__EED_Messages__get_template_packs__template_packs',
114
-            ['EE_Register_Messages_Template_Pack', 'set_template_pack'],
115
-            10
116
-        );
117
-    }
118
-
119
-
120
-    /**
121
-     * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.  This adds this template packs path
122
-     * to the messages autoloader paths.
123
-     *
124
-     * @param array $paths Array of paths already registered with the messages autoloader
125
-     *
126
-     * @return array
127
-     * @since  4.5.0
128
-     *
129
-     */
130
-    public static function set_template_pack_path(array $paths)
131
-    {
132
-        foreach (self::$_registry as $args) {
133
-            $paths[] = $args['path'];
134
-        }
135
-        return $paths;
136
-    }
137
-
138
-
139
-    /**
140
-     * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated,
141
-     * registered template pack to the template packs array when requested by client code.
142
-     *
143
-     * @param EE_Messages_Template_Pack[] $template_packs
144
-     * @return EE_Messages_Template_Pack[]
145
-     * @since 4.5.0
146
-     *
147
-     */
148
-    public static function set_template_pack(array $template_packs)
149
-    {
150
-        foreach (self::$_registry as $args) {
151
-            // verify class_exists
152
-            if (! class_exists($args['classname'])) {
153
-                require_once($args['path'] . '/' . $args['classname'] . '.class.php');
154
-            }
155
-
156
-            // check again!
157
-            if (class_exists($args['classname'])) {
158
-                $template_pack                           = new $args['classname']();
159
-                $template_packs[ $template_pack->dbref ] = $template_pack;
160
-            }
161
-        }
162
-
163
-        return $template_packs;
164
-    }
165
-
166
-
167
-    /**
168
-     * This verifies that the classes for each registered template pack are unique  names.
169
-     *
170
-     * @param string $classname The classname being checked
171
-     *
172
-     * @return bool
173
-     */
174
-    private static function _verify_class_not_exist($classname)
175
-    {
176
-        // loop through the existing registry and see if the classname is already present.
177
-        foreach (self::$_registry as $args) {
178
-            if ($args['classname'] == $classname) {
179
-                EE_Error::add_error(
180
-                    sprintf(
181
-                        esc_html__(
182
-                            'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname.  Contact the author of this template pack to let them know of the conflict.  To stop seeing this message you will need to deactivate this template pack.',
183
-                            'event_espresso'
184
-                        ),
185
-                        $classname
186
-                    ),
187
-                    __FILE__,
188
-                    __LINE__,
189
-                    __FUNCTION__
190
-                );
191
-                return false;
192
-            }
193
-        }
194
-        return true;
195
-    }
196
-
197
-
198
-    /**
199
-     * This deregisters a variation set that was previously registered with the given slug.
200
-     *
201
-     * @param string $identifier The name for the variation set that was previously registered.
202
-     *
203
-     * @return void
204
-     * @since 4.5.0
205
-     *
206
-     */
207
-    public static function deregister($identifier = '')
208
-    {
209
-        unset(self::$_registry[ $identifier ]);
210
-    }
13
+	/**
14
+	 * Holds values for registered template pack
15
+	 *
16
+	 * @since 4.5.0
17
+	 *
18
+	 * @var array
19
+	 */
20
+	protected static $_registry = [];
21
+
22
+
23
+	/**
24
+	 * Used to register a new template pack with the messages system.
25
+	 *
26
+	 * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to
27
+	 * change entire layouts for a set of message templates.  This method is used to register the new template pack and
28
+	 * automatically have it loaded in the appropriate places.
29
+	 *
30
+	 * This registry also verifies that there isn't already a template pack registered with the same name and if there
31
+	 * is then it will add an EE_Error notice.
32
+	 *
33
+	 * Note that this only handles registering the your Template Pack class with the message template pack system.
34
+	 * However, there is also a naming schema you must follow for templates you are providing with your template pack.
35
+	 *
36
+	 * @param string $identifier The internal reference used to refer to this template pack.  Note, this is first come,
37
+	 *                           first serve.  If there is already a template pack registered with this name then the
38
+	 *                           registry will assign a unique reference for it so it can still be activated (but this
39
+	 *                           makes it harder to deregister as it will be unique per load - so its best to try to
40
+	 *                           make this a unique string!)
41
+	 * @param array  $setup_args array {
42
+	 *                           An array of required values for registering the template pack.
43
+	 * @type string  $path       The path for the new template pack class.
44
+	 * @type string  $classname  The name of the new Template Pack Class.
45
+	 *                           }
46
+	 *
47
+	 * @return void
48
+	 * @throws EE_Error
49
+	 *
50
+	 * @see    core/libraries/messages/defaults/default/* for all the example templates the default template pack
51
+	 *         supports.
52
+	 *
53
+	 *
54
+	 * @since  4.5.0
55
+	 * @see    EE_Messages_Template_Pack_Default for an example class
56
+	 */
57
+	public static function register($identifier = '', array $setup_args = [])
58
+	{
59
+
60
+		// check for required params
61
+		if (empty($identifier) || empty($setup_args['path']) || empty($setup_args['classname'])) {
62
+			throw new EE_Error(
63
+				esc_html__(
64
+					'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ',
65
+					'event_espresso'
66
+				)
67
+			);
68
+		}
69
+
70
+		// make sure we don't register twice
71
+		if (isset(self::$_registry[ $identifier ])) {
72
+			return;
73
+		}
74
+
75
+		// check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack.
76
+		if (isset(self::$_registry[ $identifier ])) {
77
+			$identifier = uniqid() . '_' . $identifier;
78
+		}
79
+
80
+
81
+		// make sure this was called in the right place!
82
+		if (
83
+			! did_action('EE_Brewing_Regular___messages_caf')
84
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
85
+		) {
86
+			EE_Error::doing_it_wrong(
87
+				__METHOD__,
88
+				sprintf(
89
+					esc_html__(
90
+						'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
91
+						'event_espresso'
92
+					),
93
+					$identifier
94
+				),
95
+				'4.5.0'
96
+			);
97
+		}
98
+
99
+		if (self::_verify_class_not_exist($setup_args['classname'])) {
100
+			self::$_registry[ $identifier ] = [
101
+				'path'      => (string) $setup_args['path'],
102
+				'classname' => (string) $setup_args['classname'],
103
+			];
104
+		}
105
+
106
+		// hook into the system
107
+		add_filter(
108
+			'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
109
+			['EE_Register_Messages_Template_Pack', 'set_template_pack_path'],
110
+			10
111
+		);
112
+		add_filter(
113
+			'FHEE__EED_Messages__get_template_packs__template_packs',
114
+			['EE_Register_Messages_Template_Pack', 'set_template_pack'],
115
+			10
116
+		);
117
+	}
118
+
119
+
120
+	/**
121
+	 * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.  This adds this template packs path
122
+	 * to the messages autoloader paths.
123
+	 *
124
+	 * @param array $paths Array of paths already registered with the messages autoloader
125
+	 *
126
+	 * @return array
127
+	 * @since  4.5.0
128
+	 *
129
+	 */
130
+	public static function set_template_pack_path(array $paths)
131
+	{
132
+		foreach (self::$_registry as $args) {
133
+			$paths[] = $args['path'];
134
+		}
135
+		return $paths;
136
+	}
137
+
138
+
139
+	/**
140
+	 * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated,
141
+	 * registered template pack to the template packs array when requested by client code.
142
+	 *
143
+	 * @param EE_Messages_Template_Pack[] $template_packs
144
+	 * @return EE_Messages_Template_Pack[]
145
+	 * @since 4.5.0
146
+	 *
147
+	 */
148
+	public static function set_template_pack(array $template_packs)
149
+	{
150
+		foreach (self::$_registry as $args) {
151
+			// verify class_exists
152
+			if (! class_exists($args['classname'])) {
153
+				require_once($args['path'] . '/' . $args['classname'] . '.class.php');
154
+			}
155
+
156
+			// check again!
157
+			if (class_exists($args['classname'])) {
158
+				$template_pack                           = new $args['classname']();
159
+				$template_packs[ $template_pack->dbref ] = $template_pack;
160
+			}
161
+		}
162
+
163
+		return $template_packs;
164
+	}
165
+
166
+
167
+	/**
168
+	 * This verifies that the classes for each registered template pack are unique  names.
169
+	 *
170
+	 * @param string $classname The classname being checked
171
+	 *
172
+	 * @return bool
173
+	 */
174
+	private static function _verify_class_not_exist($classname)
175
+	{
176
+		// loop through the existing registry and see if the classname is already present.
177
+		foreach (self::$_registry as $args) {
178
+			if ($args['classname'] == $classname) {
179
+				EE_Error::add_error(
180
+					sprintf(
181
+						esc_html__(
182
+							'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname.  Contact the author of this template pack to let them know of the conflict.  To stop seeing this message you will need to deactivate this template pack.',
183
+							'event_espresso'
184
+						),
185
+						$classname
186
+					),
187
+					__FILE__,
188
+					__LINE__,
189
+					__FUNCTION__
190
+				);
191
+				return false;
192
+			}
193
+		}
194
+		return true;
195
+	}
196
+
197
+
198
+	/**
199
+	 * This deregisters a variation set that was previously registered with the given slug.
200
+	 *
201
+	 * @param string $identifier The name for the variation set that was previously registered.
202
+	 *
203
+	 * @return void
204
+	 * @since 4.5.0
205
+	 *
206
+	 */
207
+	public static function deregister($identifier = '')
208
+	{
209
+		unset(self::$_registry[ $identifier ]);
210
+	}
211 211
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Message_Type.lib.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         }
61 61
 
62 62
         // make sure we don't register twice
63
-        if (isset(self::$_ee_message_type_registry[ $identifier ])) {
63
+        if (isset(self::$_ee_message_type_registry[$identifier])) {
64 64
             return;
65 65
         }
66 66
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             );
83 83
         }
84 84
         // setup $__ee_message_type_registry array from incoming values.
85
-        self::$_ee_message_type_registry[ $identifier ] = [
85
+        self::$_ee_message_type_registry[$identifier] = [
86 86
             /**
87 87
              * The file name for the message type being registered.
88 88
              * Required.
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      */
266 266
     public static function deregister($identifier = '')
267 267
     {
268
-        if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
268
+        if ( ! empty(self::$_ee_message_type_registry[$identifier])) {
269 269
             // let's make sure that we remove any place this message type was made active
270 270
             /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
271 271
             $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
             );
278 278
             $Message_Resource_Manager->deactivate_message_type($identifier, false);
279 279
         }
280
-        unset(self::$_ee_message_type_registry[ $identifier ]);
280
+        unset(self::$_ee_message_type_registry[$identifier]);
281 281
     }
282 282
 
283 283
 
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      */
313 313
     public static function register_msgs_autoload_paths(array $paths)
314 314
     {
315
-        if (! empty(self::$_ee_message_type_registry)) {
315
+        if ( ! empty(self::$_ee_message_type_registry)) {
316 316
             foreach (self::$_ee_message_type_registry as $mt_reg) {
317 317
                 if (empty($mt_reg['autoloadpaths'])) {
318 318
                     continue;
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
                 continue;
402 402
             }
403 403
             foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
404
-                $supports[ $messenger_slug ][] = $identifier;
404
+                $supports[$messenger_slug][] = $identifier;
405 405
             }
406 406
         }
407 407
         return $supports;
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
         $file_extension,
474 474
         EE_Messages_Template_Pack $template_pack
475 475
     ) {
476
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
476
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
477 477
             return $base_path_or_url;
478 478
         }
479 479
         foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
Please login to merge, or discard this patch.
Indentation   +457 added lines, -457 removed lines patch added patch discarded remove patch
@@ -10,487 +10,487 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Register_Message_Type implements EEI_Plugin_API
12 12
 {
13
-    /**
14
-     * Holds values for registered message types
15
-     *
16
-     * @var array
17
-     */
18
-    protected static $_ee_message_type_registry = [];
13
+	/**
14
+	 * Holds values for registered message types
15
+	 *
16
+	 * @var array
17
+	 */
18
+	protected static $_ee_message_type_registry = [];
19 19
 
20 20
 
21
-    /**
22
-     * Method for registering new message types in the EE_messages system.
23
-     * Note:  All message types must have the following files in order to work:
24
-     * Template files for default templates getting setup.
25
-     * See /core/libraries/messages/defaults/default/ for examples
26
-     * (note that template files match a specific naming schema).
27
-     * These templates will need to be registered with the default template pack.
28
-     * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
29
-     *      for examples.  Note for any new message types, there will need to be a validator for each
30
-     *      messenger combo this message type can activate with.
31
-     * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
32
-     *      message type and its properties.
33
-     *
34
-     * @param string $identifier    Whatever is defined for the $name property of
35
-     *                              the message type you are registering (eg.
36
-     *                              declined_registration). Required.
37
-     * @param array  $setup_args    An array of arguments provided for registering the message type.
38
-     * @throws EE_Error
39
-     *                              }
40
-     * @see      inline docs in the register method for what can be passed in as arguments.
41
-     * @since    4.3.0
42
-     */
43
-    public static function register($identifier = '', array $setup_args = [])
44
-    {
45
-        // required fields MUST be present, so let's make sure they are.
46
-        if (
47
-            ! isset($identifier)
48
-            || ! is_array($setup_args)
49
-            || empty($setup_args['mtfilename'])
50
-            || empty($setup_args['autoloadpaths'])
51
-        ) {
52
-            throw new EE_Error(
53
-                esc_html__(
54
-                    'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
55
-                    'event_espresso'
56
-                )
57
-            );
58
-        }
21
+	/**
22
+	 * Method for registering new message types in the EE_messages system.
23
+	 * Note:  All message types must have the following files in order to work:
24
+	 * Template files for default templates getting setup.
25
+	 * See /core/libraries/messages/defaults/default/ for examples
26
+	 * (note that template files match a specific naming schema).
27
+	 * These templates will need to be registered with the default template pack.
28
+	 * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
29
+	 *      for examples.  Note for any new message types, there will need to be a validator for each
30
+	 *      messenger combo this message type can activate with.
31
+	 * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
32
+	 *      message type and its properties.
33
+	 *
34
+	 * @param string $identifier    Whatever is defined for the $name property of
35
+	 *                              the message type you are registering (eg.
36
+	 *                              declined_registration). Required.
37
+	 * @param array  $setup_args    An array of arguments provided for registering the message type.
38
+	 * @throws EE_Error
39
+	 *                              }
40
+	 * @see      inline docs in the register method for what can be passed in as arguments.
41
+	 * @since    4.3.0
42
+	 */
43
+	public static function register($identifier = '', array $setup_args = [])
44
+	{
45
+		// required fields MUST be present, so let's make sure they are.
46
+		if (
47
+			! isset($identifier)
48
+			|| ! is_array($setup_args)
49
+			|| empty($setup_args['mtfilename'])
50
+			|| empty($setup_args['autoloadpaths'])
51
+		) {
52
+			throw new EE_Error(
53
+				esc_html__(
54
+					'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
55
+					'event_espresso'
56
+				)
57
+			);
58
+		}
59 59
 
60
-        // make sure we don't register twice
61
-        if (isset(self::$_ee_message_type_registry[ $identifier ])) {
62
-            return;
63
-        }
60
+		// make sure we don't register twice
61
+		if (isset(self::$_ee_message_type_registry[ $identifier ])) {
62
+			return;
63
+		}
64 64
 
65
-        // make sure this was called in the right place!
66
-        if (
67
-            ! did_action('EE_Brewing_Regular___messages_caf')
68
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69
-        ) {
70
-            EE_Error::doing_it_wrong(
71
-                __METHOD__,
72
-                sprintf(
73
-                    esc_html__(
74
-                        'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
75
-                        'event_espresso'
76
-                    ),
77
-                    $identifier
78
-                ),
79
-                '4.3.0'
80
-            );
81
-        }
82
-        // setup $__ee_message_type_registry array from incoming values.
83
-        self::$_ee_message_type_registry[ $identifier ] = [
84
-            /**
85
-             * The file name for the message type being registered.
86
-             * Required.
87
-             *
88
-             * @type string
89
-             */
90
-            'mtfilename'                                       => (string) $setup_args['mtfilename'],
91
-            /**
92
-             * Autoload paths for classes used by the message type.
93
-             * Required.
94
-             *
95
-             * @type array
96
-             */
97
-            'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
98
-            /**
99
-             * Messengers that the message type should be able to activate with.
100
-             * Use messenger slugs.
101
-             *
102
-             * @type array
103
-             */
104
-            'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
105
-                ? (array) $setup_args['messengers_to_activate_with']
106
-                : [],
107
-            /**
108
-             * Messengers that the message type should validate with.
109
-             * Use messenger slugs.
110
-             *
111
-             * @type array
112
-             */
113
-            'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
114
-                ? (array) $setup_args['messengers_to_validate_with']
115
-                : [],
116
-            /**
117
-             * Whether to force activate this message type the first time it is registered.
118
-             *
119
-             * @type bool   False means its not activated by default and left up to the end user to activate.
120
-             */
121
-            'force_activation'                                 => ! empty($setup_args['force_activation'])
122
-                                                                  && $setup_args['force_activation'],
123
-            /**
124
-             * What messengers this message type supports the default template pack for.
125
-             * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
126
-             * then it is expected that the message type being registered is doing its own custom default template
127
-             * pack/variation registration.
128
-             *
129
-             * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
130
-             * $setup_arguments array as well:
131
-             * - 'base_path_for_default_templates'
132
-             *
133
-             * @type array   Expect an array of messengers this supports default template packs for.
134
-             */
135
-            'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
136
-                ? (array) $setup_args['messengers_supporting_default_template_pack_with']
137
-                : [],
138
-            /**
139
-             * The base path where the default templates for this message type can be found.
140
-             *
141
-             * @type string
142
-             */
143
-            'base_path_for_default_templates'                  => isset($setup_args['base_path_for_default_templates'])
144
-                ? $setup_args['base_path_for_default_templates'] : '',
145
-            /**
146
-             * The base path where the default variations for this message type can be found.
147
-             *
148
-             * @type string
149
-             */
150
-            'base_path_for_default_variation'                  => isset($setup_args['base_path_for_default_variation'])
151
-                ? $setup_args['base_path_for_default_variation'] : '',
152
-            /**
153
-             * The base url for the default variations for this message type.
154
-             *
155
-             * @type string
156
-             */
157
-            'base_url_for_default_variation'                   => isset($setup_args['base_url_for_default_variation'])
158
-                ? $setup_args['base_url_for_default_variation'] : '',
159
-        ];
160
-        // add filters but only if they haven't already been set (these filters only need to be registered ONCE because
161
-        // the callback handles all registered message types.
162
-        if (
163
-            false === has_filter(
164
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
165
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths']
166
-            )
167
-        ) {
168
-            add_filter(
169
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
170
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
171
-                10
172
-            );
173
-            add_filter(
174
-                'FHEE__EE_messages__get_installed__messagetype_files',
175
-                ['EE_Register_Message_Type', 'register_messagetype_files'],
176
-                10,
177
-                1
178
-            );
179
-            add_filter(
180
-                'FHEE__EE_messenger__get_default_message_types__default_types',
181
-                ['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
182
-                10,
183
-                2
184
-            );
185
-            add_filter(
186
-                'FHEE__EE_messenger__get_valid_message_types__valid_types',
187
-                ['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
188
-                10,
189
-                2
190
-            );
191
-            // actions
192
-            add_action(
193
-                'AHEE__EE_Addon__initialize_default_data__begin',
194
-                ['EE_Register_Message_Type', 'set_defaults']
195
-            );
65
+		// make sure this was called in the right place!
66
+		if (
67
+			! did_action('EE_Brewing_Regular___messages_caf')
68
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69
+		) {
70
+			EE_Error::doing_it_wrong(
71
+				__METHOD__,
72
+				sprintf(
73
+					esc_html__(
74
+						'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
75
+						'event_espresso'
76
+					),
77
+					$identifier
78
+				),
79
+				'4.3.0'
80
+			);
81
+		}
82
+		// setup $__ee_message_type_registry array from incoming values.
83
+		self::$_ee_message_type_registry[ $identifier ] = [
84
+			/**
85
+			 * The file name for the message type being registered.
86
+			 * Required.
87
+			 *
88
+			 * @type string
89
+			 */
90
+			'mtfilename'                                       => (string) $setup_args['mtfilename'],
91
+			/**
92
+			 * Autoload paths for classes used by the message type.
93
+			 * Required.
94
+			 *
95
+			 * @type array
96
+			 */
97
+			'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
98
+			/**
99
+			 * Messengers that the message type should be able to activate with.
100
+			 * Use messenger slugs.
101
+			 *
102
+			 * @type array
103
+			 */
104
+			'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
105
+				? (array) $setup_args['messengers_to_activate_with']
106
+				: [],
107
+			/**
108
+			 * Messengers that the message type should validate with.
109
+			 * Use messenger slugs.
110
+			 *
111
+			 * @type array
112
+			 */
113
+			'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
114
+				? (array) $setup_args['messengers_to_validate_with']
115
+				: [],
116
+			/**
117
+			 * Whether to force activate this message type the first time it is registered.
118
+			 *
119
+			 * @type bool   False means its not activated by default and left up to the end user to activate.
120
+			 */
121
+			'force_activation'                                 => ! empty($setup_args['force_activation'])
122
+																  && $setup_args['force_activation'],
123
+			/**
124
+			 * What messengers this message type supports the default template pack for.
125
+			 * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
126
+			 * then it is expected that the message type being registered is doing its own custom default template
127
+			 * pack/variation registration.
128
+			 *
129
+			 * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
130
+			 * $setup_arguments array as well:
131
+			 * - 'base_path_for_default_templates'
132
+			 *
133
+			 * @type array   Expect an array of messengers this supports default template packs for.
134
+			 */
135
+			'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
136
+				? (array) $setup_args['messengers_supporting_default_template_pack_with']
137
+				: [],
138
+			/**
139
+			 * The base path where the default templates for this message type can be found.
140
+			 *
141
+			 * @type string
142
+			 */
143
+			'base_path_for_default_templates'                  => isset($setup_args['base_path_for_default_templates'])
144
+				? $setup_args['base_path_for_default_templates'] : '',
145
+			/**
146
+			 * The base path where the default variations for this message type can be found.
147
+			 *
148
+			 * @type string
149
+			 */
150
+			'base_path_for_default_variation'                  => isset($setup_args['base_path_for_default_variation'])
151
+				? $setup_args['base_path_for_default_variation'] : '',
152
+			/**
153
+			 * The base url for the default variations for this message type.
154
+			 *
155
+			 * @type string
156
+			 */
157
+			'base_url_for_default_variation'                   => isset($setup_args['base_url_for_default_variation'])
158
+				? $setup_args['base_url_for_default_variation'] : '',
159
+		];
160
+		// add filters but only if they haven't already been set (these filters only need to be registered ONCE because
161
+		// the callback handles all registered message types.
162
+		if (
163
+			false === has_filter(
164
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
165
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths']
166
+			)
167
+		) {
168
+			add_filter(
169
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
170
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
171
+				10
172
+			);
173
+			add_filter(
174
+				'FHEE__EE_messages__get_installed__messagetype_files',
175
+				['EE_Register_Message_Type', 'register_messagetype_files'],
176
+				10,
177
+				1
178
+			);
179
+			add_filter(
180
+				'FHEE__EE_messenger__get_default_message_types__default_types',
181
+				['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
182
+				10,
183
+				2
184
+			);
185
+			add_filter(
186
+				'FHEE__EE_messenger__get_valid_message_types__valid_types',
187
+				['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
188
+				10,
189
+				2
190
+			);
191
+			// actions
192
+			add_action(
193
+				'AHEE__EE_Addon__initialize_default_data__begin',
194
+				['EE_Register_Message_Type', 'set_defaults']
195
+			);
196 196
 
197
-            // default template packs and variations related
198
-            add_filter(
199
-                'FHEE__EE_Messages_Template_Pack_Default__get_supports',
200
-                ['EE_Register_Message_Type', 'register_default_template_pack_supports']
201
-            );
202
-            add_filter(
203
-                'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
204
-                ['EE_Register_Message_Type', 'register_base_template_path'],
205
-                10,
206
-                6
207
-            );
208
-            add_filter(
209
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
210
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
211
-                10,
212
-                8
213
-            );
214
-            add_filter(
215
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
216
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
217
-                10,
218
-                8
219
-            );
220
-        }
221
-    }
197
+			// default template packs and variations related
198
+			add_filter(
199
+				'FHEE__EE_Messages_Template_Pack_Default__get_supports',
200
+				['EE_Register_Message_Type', 'register_default_template_pack_supports']
201
+			);
202
+			add_filter(
203
+				'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
204
+				['EE_Register_Message_Type', 'register_base_template_path'],
205
+				10,
206
+				6
207
+			);
208
+			add_filter(
209
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
210
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
211
+				10,
212
+				8
213
+			);
214
+			add_filter(
215
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
216
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
217
+				10,
218
+				8
219
+			);
220
+		}
221
+	}
222 222
 
223 223
 
224
-    /**
225
-     * This just ensures that when an addon registers a message type that on initial activation/reactivation the
226
-     * defaults the addon sets are taken care of.
227
-     *
228
-     * @throws EE_Error
229
-     * @throws ReflectionException
230
-     */
231
-    public static function set_defaults()
232
-    {
233
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
234
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
224
+	/**
225
+	 * This just ensures that when an addon registers a message type that on initial activation/reactivation the
226
+	 * defaults the addon sets are taken care of.
227
+	 *
228
+	 * @throws EE_Error
229
+	 * @throws ReflectionException
230
+	 */
231
+	public static function set_defaults()
232
+	{
233
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
234
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
235 235
 
236
-        // for any message types with force activation, let's ensure they are activated
237
-        foreach (self::$_ee_message_type_registry as $identifier => $settings) {
238
-            if ($settings['force_activation']) {
239
-                foreach ($settings['messengers_to_activate_with'] as $messenger) {
240
-                    // DO not force activation if this message type has already been activated in the system
241
-                    if (
242
-                        ! $message_resource_manager->has_message_type_been_activated_for_messenger(
243
-                            $identifier,
244
-                            $messenger
245
-                        )
246
-                    ) {
247
-                        $message_resource_manager->ensure_message_type_is_active($identifier, $messenger);
248
-                    }
249
-                }
250
-            }
251
-        }
252
-    }
236
+		// for any message types with force activation, let's ensure they are activated
237
+		foreach (self::$_ee_message_type_registry as $identifier => $settings) {
238
+			if ($settings['force_activation']) {
239
+				foreach ($settings['messengers_to_activate_with'] as $messenger) {
240
+					// DO not force activation if this message type has already been activated in the system
241
+					if (
242
+						! $message_resource_manager->has_message_type_been_activated_for_messenger(
243
+							$identifier,
244
+							$messenger
245
+						)
246
+					) {
247
+						$message_resource_manager->ensure_message_type_is_active($identifier, $messenger);
248
+					}
249
+				}
250
+			}
251
+		}
252
+	}
253 253
 
254 254
 
255
-    /**
256
-     * This deregisters a message type that was previously registered with a specific message_type_name.
257
-     *
258
-     * @param string $identifier the name for the message type that was previously registered
259
-     * @return void
260
-     * @throws EE_Error
261
-     * @throws ReflectionException
262
-     * @since    4.3.0
263
-     */
264
-    public static function deregister($identifier = '')
265
-    {
266
-        if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
267
-            // let's make sure that we remove any place this message type was made active
268
-            /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
269
-            $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
270
-            // ensures that if this message type is registered again that it retains its previous active state vs
271
-            // remaining inactive.
272
-            $Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
273
-                $identifier,
274
-                true
275
-            );
276
-            $Message_Resource_Manager->deactivate_message_type($identifier, false);
277
-        }
278
-        unset(self::$_ee_message_type_registry[ $identifier ]);
279
-    }
255
+	/**
256
+	 * This deregisters a message type that was previously registered with a specific message_type_name.
257
+	 *
258
+	 * @param string $identifier the name for the message type that was previously registered
259
+	 * @return void
260
+	 * @throws EE_Error
261
+	 * @throws ReflectionException
262
+	 * @since    4.3.0
263
+	 */
264
+	public static function deregister($identifier = '')
265
+	{
266
+		if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
267
+			// let's make sure that we remove any place this message type was made active
268
+			/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
269
+			$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
270
+			// ensures that if this message type is registered again that it retains its previous active state vs
271
+			// remaining inactive.
272
+			$Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
273
+				$identifier,
274
+				true
275
+			);
276
+			$Message_Resource_Manager->deactivate_message_type($identifier, false);
277
+		}
278
+		unset(self::$_ee_message_type_registry[ $identifier ]);
279
+	}
280 280
 
281 281
 
282
-    /**
283
-     * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
284
-     *
285
-     * @param array $messagetype_files The current array of message type file names
286
-     * @return  array                                 Array of message type file names
287
-     * @since   4.3.0
288
-     */
289
-    public static function register_messagetype_files(array $messagetype_files)
290
-    {
291
-        if (empty(self::$_ee_message_type_registry)) {
292
-            return $messagetype_files;
293
-        }
294
-        foreach (self::$_ee_message_type_registry as $mt_reg) {
295
-            if (empty($mt_reg['mtfilename'])) {
296
-                continue;
297
-            }
298
-            $messagetype_files[] = $mt_reg['mtfilename'];
299
-        }
300
-        return $messagetype_files;
301
-    }
282
+	/**
283
+	 * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
284
+	 *
285
+	 * @param array $messagetype_files The current array of message type file names
286
+	 * @return  array                                 Array of message type file names
287
+	 * @since   4.3.0
288
+	 */
289
+	public static function register_messagetype_files(array $messagetype_files)
290
+	{
291
+		if (empty(self::$_ee_message_type_registry)) {
292
+			return $messagetype_files;
293
+		}
294
+		foreach (self::$_ee_message_type_registry as $mt_reg) {
295
+			if (empty($mt_reg['mtfilename'])) {
296
+				continue;
297
+			}
298
+			$messagetype_files[] = $mt_reg['mtfilename'];
299
+		}
300
+		return $messagetype_files;
301
+	}
302 302
 
303 303
 
304
-    /**
305
-     * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
306
-     *
307
-     * @param array $paths array of paths to be checked by EE_messages autoloader.
308
-     * @return array
309
-     * @since    4.3.0
310
-     */
311
-    public static function register_msgs_autoload_paths(array $paths)
312
-    {
313
-        if (! empty(self::$_ee_message_type_registry)) {
314
-            foreach (self::$_ee_message_type_registry as $mt_reg) {
315
-                if (empty($mt_reg['autoloadpaths'])) {
316
-                    continue;
317
-                }
318
-                $paths = array_merge($paths, $mt_reg['autoloadpaths']);
319
-            }
320
-        }
321
-        return $paths;
322
-    }
304
+	/**
305
+	 * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
306
+	 *
307
+	 * @param array $paths array of paths to be checked by EE_messages autoloader.
308
+	 * @return array
309
+	 * @since    4.3.0
310
+	 */
311
+	public static function register_msgs_autoload_paths(array $paths)
312
+	{
313
+		if (! empty(self::$_ee_message_type_registry)) {
314
+			foreach (self::$_ee_message_type_registry as $mt_reg) {
315
+				if (empty($mt_reg['autoloadpaths'])) {
316
+					continue;
317
+				}
318
+				$paths = array_merge($paths, $mt_reg['autoloadpaths']);
319
+			}
320
+		}
321
+		return $paths;
322
+	}
323 323
 
324 324
 
325
-    /**
326
-     * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
327
-     *
328
-     * @param array        $default_types   array of message types activated with messenger (
329
-     *                                      corresponds to the $name property of message type)
330
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
331
-     * @return array
332
-     * @since  4.3.0
333
-     */
334
-    public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger)
335
-    {
336
-        if (empty(self::$_ee_message_type_registry)) {
337
-            return $default_types;
338
-        }
339
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
340
-            if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
341
-                continue;
342
-            }
343
-            // loop through each of the messengers and if it matches the loaded class
344
-            // then we add this message type to the
345
-            foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
346
-                if ($messenger->name == $msgr) {
347
-                    $default_types[] = $identifier;
348
-                }
349
-            }
350
-        }
325
+	/**
326
+	 * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
327
+	 *
328
+	 * @param array        $default_types   array of message types activated with messenger (
329
+	 *                                      corresponds to the $name property of message type)
330
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
331
+	 * @return array
332
+	 * @since  4.3.0
333
+	 */
334
+	public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger)
335
+	{
336
+		if (empty(self::$_ee_message_type_registry)) {
337
+			return $default_types;
338
+		}
339
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
340
+			if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
341
+				continue;
342
+			}
343
+			// loop through each of the messengers and if it matches the loaded class
344
+			// then we add this message type to the
345
+			foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
346
+				if ($messenger->name == $msgr) {
347
+					$default_types[] = $identifier;
348
+				}
349
+			}
350
+		}
351 351
 
352
-        return $default_types;
353
-    }
352
+		return $default_types;
353
+	}
354 354
 
355 355
 
356
-    /**
357
-     * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
358
-     *
359
-     * @param array        $valid_types     array of message types valid with messenger (
360
-     *                                      corresponds to the $name property of message type)
361
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
362
-     * @return  array
363
-     * @since   4.3.0
364
-     */
365
-    public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger)
366
-    {
367
-        if (empty(self::$_ee_message_type_registry)) {
368
-            return $valid_types;
369
-        }
370
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
371
-            if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
372
-                continue;
373
-            }
374
-            // loop through each of the messengers and if it matches the loaded class
375
-            // then we add this message type to the
376
-            foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
377
-                if ($messenger->name == $msgr) {
378
-                    $valid_types[] = $identifier;
379
-                }
380
-            }
381
-        }
356
+	/**
357
+	 * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
358
+	 *
359
+	 * @param array        $valid_types     array of message types valid with messenger (
360
+	 *                                      corresponds to the $name property of message type)
361
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
362
+	 * @return  array
363
+	 * @since   4.3.0
364
+	 */
365
+	public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger)
366
+	{
367
+		if (empty(self::$_ee_message_type_registry)) {
368
+			return $valid_types;
369
+		}
370
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
371
+			if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
372
+				continue;
373
+			}
374
+			// loop through each of the messengers and if it matches the loaded class
375
+			// then we add this message type to the
376
+			foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
377
+				if ($messenger->name == $msgr) {
378
+					$valid_types[] = $identifier;
379
+				}
380
+			}
381
+		}
382 382
 
383
-        return $valid_types;
384
-    }
383
+		return $valid_types;
384
+	}
385 385
 
386 386
 
387
-    /**
388
-     * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
389
-     * supporting the default template pack
390
-     *
391
-     * @param array $supports
392
-     *
393
-     * @return array
394
-     */
395
-    public static function register_default_template_pack_supports(array $supports)
396
-    {
397
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
398
-            if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
399
-                continue;
400
-            }
401
-            foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
402
-                $supports[ $messenger_slug ][] = $identifier;
403
-            }
404
-        }
405
-        return $supports;
406
-    }
387
+	/**
388
+	 * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
389
+	 * supporting the default template pack
390
+	 *
391
+	 * @param array $supports
392
+	 *
393
+	 * @return array
394
+	 */
395
+	public static function register_default_template_pack_supports(array $supports)
396
+	{
397
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
398
+			if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
399
+				continue;
400
+			}
401
+			foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
402
+				$supports[ $messenger_slug ][] = $identifier;
403
+			}
404
+		}
405
+		return $supports;
406
+	}
407 407
 
408 408
 
409
-    /**
410
-     * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
411
-     *
412
-     * @param string                    $base_path The original base path for message templates
413
-     * @param EE_messenger              $messenger
414
-     * @param EE_message_type           $message_type
415
-     * @param string                    $field     The field requesting a template
416
-     * @param string                    $context   The context requesting a template
417
-     * @param EE_Messages_Template_Pack $template_pack
418
-     *
419
-     * @return string
420
-     */
421
-    public static function register_base_template_path(
422
-        $base_path,
423
-        EE_messenger $messenger,
424
-        EE_message_type $message_type,
425
-        $field,
426
-        $context,
427
-        EE_Messages_Template_Pack $template_pack
428
-    ) {
429
-        if (
430
-            ! $template_pack instanceof EE_Messages_Template_Pack_Default
431
-            || ! $message_type instanceof EE_message_type
432
-        ) {
433
-            return $base_path;
434
-        }
435
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
436
-            if (
437
-                $message_type->name === $identifier
438
-                && ! empty($mt_reg['base_path_for_default_templates'])
439
-            ) {
440
-                return $mt_reg['base_path_for_default_templates'];
441
-            }
442
-        }
443
-        return $base_path;
444
-    }
409
+	/**
410
+	 * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
411
+	 *
412
+	 * @param string                    $base_path The original base path for message templates
413
+	 * @param EE_messenger              $messenger
414
+	 * @param EE_message_type           $message_type
415
+	 * @param string                    $field     The field requesting a template
416
+	 * @param string                    $context   The context requesting a template
417
+	 * @param EE_Messages_Template_Pack $template_pack
418
+	 *
419
+	 * @return string
420
+	 */
421
+	public static function register_base_template_path(
422
+		$base_path,
423
+		EE_messenger $messenger,
424
+		EE_message_type $message_type,
425
+		$field,
426
+		$context,
427
+		EE_Messages_Template_Pack $template_pack
428
+	) {
429
+		if (
430
+			! $template_pack instanceof EE_Messages_Template_Pack_Default
431
+			|| ! $message_type instanceof EE_message_type
432
+		) {
433
+			return $base_path;
434
+		}
435
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
436
+			if (
437
+				$message_type->name === $identifier
438
+				&& ! empty($mt_reg['base_path_for_default_templates'])
439
+			) {
440
+				return $mt_reg['base_path_for_default_templates'];
441
+			}
442
+		}
443
+		return $base_path;
444
+	}
445 445
 
446 446
 
447
-    /**
448
-     * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
449
-     * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
450
-     *
451
-     * @param string                    $base_path_or_url  The original incoming base url or path
452
-     * @param string                    $messenger_slug    The slug of the messenger the template is being generated
453
-     *                                                     for.
454
-     * @param string                    $message_type_slug The slug of the message type the template is being generated
455
-     *                                                     for.
456
-     * @param string                    $type              The "type" of css being requested.
457
-     * @param string                    $variation         The variation being requested.
458
-     * @param bool                      $url               whether a url or path is being requested.
459
-     * @param string                    $file_extension    What file extension is expected for the variation file.
460
-     * @param EE_Messages_Template_Pack $template_pack
461
-     *
462
-     * @return string
463
-     */
464
-    public static function register_variation_base_path_or_url(
465
-        $base_path_or_url,
466
-        $messenger_slug,
467
-        $message_type_slug,
468
-        $type,
469
-        $variation,
470
-        $url,
471
-        $file_extension,
472
-        EE_Messages_Template_Pack $template_pack
473
-    ) {
474
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
475
-            return $base_path_or_url;
476
-        }
477
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
478
-            if (
479
-                $identifier === $message_type_slug
480
-            ) {
481
-                if (
482
-                    $url
483
-                    && ! empty($mt_reg['base_url_for_default_variation'])
484
-                ) {
485
-                    return $mt_reg['base_url_for_default_variation'];
486
-                } elseif (
487
-                    ! $url
488
-                          && ! empty($mt_reg['base_path_for_default_variation'])
489
-                ) {
490
-                    return $mt_reg['base_path_for_default_variation'];
491
-                }
492
-            }
493
-        }
494
-        return $base_path_or_url;
495
-    }
447
+	/**
448
+	 * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
449
+	 * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
450
+	 *
451
+	 * @param string                    $base_path_or_url  The original incoming base url or path
452
+	 * @param string                    $messenger_slug    The slug of the messenger the template is being generated
453
+	 *                                                     for.
454
+	 * @param string                    $message_type_slug The slug of the message type the template is being generated
455
+	 *                                                     for.
456
+	 * @param string                    $type              The "type" of css being requested.
457
+	 * @param string                    $variation         The variation being requested.
458
+	 * @param bool                      $url               whether a url or path is being requested.
459
+	 * @param string                    $file_extension    What file extension is expected for the variation file.
460
+	 * @param EE_Messages_Template_Pack $template_pack
461
+	 *
462
+	 * @return string
463
+	 */
464
+	public static function register_variation_base_path_or_url(
465
+		$base_path_or_url,
466
+		$messenger_slug,
467
+		$message_type_slug,
468
+		$type,
469
+		$variation,
470
+		$url,
471
+		$file_extension,
472
+		EE_Messages_Template_Pack $template_pack
473
+	) {
474
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
475
+			return $base_path_or_url;
476
+		}
477
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
478
+			if (
479
+				$identifier === $message_type_slug
480
+			) {
481
+				if (
482
+					$url
483
+					&& ! empty($mt_reg['base_url_for_default_variation'])
484
+				) {
485
+					return $mt_reg['base_url_for_default_variation'];
486
+				} elseif (
487
+					! $url
488
+						  && ! empty($mt_reg['base_path_for_default_variation'])
489
+				) {
490
+					return $mt_reg['base_path_for_default_variation'];
491
+				}
492
+			}
493
+		}
494
+		return $base_path_or_url;
495
+	}
496 496
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Module.lib.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         }
49 49
 
50 50
         // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
51
+        if (isset(self::$_settings[$identifier])) {
52 52
             return;
53 53
         }
54 54
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             );
68 68
         }
69 69
         // setup $_settings array from incoming values.
70
-        self::$_settings[ $identifier ] = [
70
+        self::$_settings[$identifier] = [
71 71
             // array of full server paths to any EED_Modules used by the module
72 72
             'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
73 73
         ];
@@ -105,6 +105,6 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public static function deregister($identifier = '')
107 107
     {
108
-        unset(self::$_settings[ $identifier ]);
108
+        unset(self::$_settings[$identifier]);
109 109
     }
110 110
 }
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -14,96 +14,96 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Register_Module implements EEI_Plugin_API
16 16
 {
17
-    /**
18
-     * Holds values for registered modules
19
-     *
20
-     * @var array
21
-     */
22
-    protected static $_settings = [];
17
+	/**
18
+	 * Holds values for registered modules
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected static $_settings = [];
23 23
 
24 24
 
25
-    /**
26
-     *    Method for registering new EED_Modules
27
-     *
28
-     * @param string $identifier a unique identifier for this set of modules Required.
29
-     * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
30
-     *                           EED_Module files themselves Required.
31
-     * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
32
-     *                           EED_Module files themselves
33
-     * @return void
34
-     * @throws EE_Error
35
-     * @since    4.3.0
36
-     */
37
-    public static function register($identifier = '', array $setup_args = [])
38
-    {
39
-        // required fields MUST be present, so let's make sure they are.
40
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
41
-            throw new EE_Error(
42
-                esc_html__(
43
-                    'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
44
-                    'event_espresso'
45
-                )
46
-            );
47
-        }
25
+	/**
26
+	 *    Method for registering new EED_Modules
27
+	 *
28
+	 * @param string $identifier a unique identifier for this set of modules Required.
29
+	 * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
30
+	 *                           EED_Module files themselves Required.
31
+	 * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
32
+	 *                           EED_Module files themselves
33
+	 * @return void
34
+	 * @throws EE_Error
35
+	 * @since    4.3.0
36
+	 */
37
+	public static function register($identifier = '', array $setup_args = [])
38
+	{
39
+		// required fields MUST be present, so let's make sure they are.
40
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
41
+			throw new EE_Error(
42
+				esc_html__(
43
+					'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
44
+					'event_espresso'
45
+				)
46
+			);
47
+		}
48 48
 
49
-        // make sure we don't register twice
50
-        if (isset(self::$_settings[ $identifier ])) {
51
-            return;
52
-        }
49
+		// make sure we don't register twice
50
+		if (isset(self::$_settings[ $identifier ])) {
51
+			return;
52
+		}
53 53
 
54
-        // make sure this was called in the right place!
55
-        if (
56
-            ! did_action('AHEE__EE_System__load_espresso_addons')
57
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58
-        ) {
59
-            EE_Error::doing_it_wrong(
60
-                __METHOD__,
61
-                esc_html__(
62
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
63
-                    'event_espresso'
64
-                ),
65
-                '4.3.0'
66
-            );
67
-        }
68
-        // setup $_settings array from incoming values.
69
-        self::$_settings[ $identifier ] = [
70
-            // array of full server paths to any EED_Modules used by the module
71
-            'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72
-        ];
73
-        // add to list of modules to be registered
74
-        add_filter(
75
-            'FHEE__EE_Config__register_modules__modules_to_register',
76
-            ['EE_Register_Module', 'add_modules']
77
-        );
78
-    }
54
+		// make sure this was called in the right place!
55
+		if (
56
+			! did_action('AHEE__EE_System__load_espresso_addons')
57
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58
+		) {
59
+			EE_Error::doing_it_wrong(
60
+				__METHOD__,
61
+				esc_html__(
62
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
63
+					'event_espresso'
64
+				),
65
+				'4.3.0'
66
+			);
67
+		}
68
+		// setup $_settings array from incoming values.
69
+		self::$_settings[ $identifier ] = [
70
+			// array of full server paths to any EED_Modules used by the module
71
+			'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72
+		];
73
+		// add to list of modules to be registered
74
+		add_filter(
75
+			'FHEE__EE_Config__register_modules__modules_to_register',
76
+			['EE_Register_Module', 'add_modules']
77
+		);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * Filters the list of modules to add ours.
83
-     * and they're just full filepaths to FOLDERS containing a module class file. Eg.
84
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
85
-     *
86
-     * @param array $modules_to_register array of paths to all modules that require registering
87
-     * @return array
88
-     */
89
-    public static function add_modules(array $modules_to_register)
90
-    {
91
-        foreach (self::$_settings as $settings) {
92
-            $modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
93
-        }
94
-        return $modules_to_register;
95
-    }
81
+	/**
82
+	 * Filters the list of modules to add ours.
83
+	 * and they're just full filepaths to FOLDERS containing a module class file. Eg.
84
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
85
+	 *
86
+	 * @param array $modules_to_register array of paths to all modules that require registering
87
+	 * @return array
88
+	 */
89
+	public static function add_modules(array $modules_to_register)
90
+	{
91
+		foreach (self::$_settings as $settings) {
92
+			$modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
93
+		}
94
+		return $modules_to_register;
95
+	}
96 96
 
97 97
 
98
-    /**
99
-     * This deregisters a module that was previously registered with a specific $identifier.
100
-     *
101
-     * @param string $identifier the name for the module that was previously registered
102
-     * @return void
103
-     * @since    4.3.0
104
-     */
105
-    public static function deregister($identifier = '')
106
-    {
107
-        unset(self::$_settings[ $identifier ]);
108
-    }
98
+	/**
99
+	 * This deregisters a module that was previously registered with a specific $identifier.
100
+	 *
101
+	 * @param string $identifier the name for the module that was previously registered
102
+	 * @return void
103
+	 * @since    4.3.0
104
+	 */
105
+	public static function deregister($identifier = '')
106
+	{
107
+		unset(self::$_settings[ $identifier ]);
108
+	}
109 109
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model.lib.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         }
59 59
 
60 60
         // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
61
+        if (isset(self::$_model_registry[$identifier])) {
62 62
             return;
63 63
         }
64 64
 
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
                 '4.5'
80 80
             );
81 81
         }
82
-        self::$_model_registry[ $identifier ] = $setup_args;
82
+        self::$_model_registry[$identifier] = $setup_args;
83 83
 
84 84
         if (
85 85
             (isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
86
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
86
+            || ( ! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
87 87
         ) {
88 88
             throw new EE_Error(
89 89
                 sprintf(
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         }
98 98
         if (isset($setup_args['model_paths'])) {
99 99
             // make sure they passed in an array
100
-            if (! is_array($setup_args['model_paths'])) {
100
+            if ( ! is_array($setup_args['model_paths'])) {
101 101
                 $setup_args['model_paths'] = [$setup_args['model_paths']];
102 102
             }
103 103
             // we want to add this as a model folder
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
107 107
             $model_name_to_classname_map = [];
108 108
             foreach (array_keys($class_to_filepath_map) as $classname) {
109
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
109
+                $model_name_to_classname_map[str_replace("EEM_", "", $classname)] = $classname;
110 110
             }
111
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
111
+            self::$_model_name_to_classname_map[$identifier] = $model_name_to_classname_map;
112 112
             add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
113 113
             add_filter(
114 114
                 'FHEE__EE_System__parse_implemented_model_names',
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         }
120 120
         if (isset($setup_args['class_paths'])) {
121 121
             // make sure they passed in an array
122
-            if (! is_array($setup_args['class_paths'])) {
122
+            if ( ! is_array($setup_args['class_paths'])) {
123 123
                 $setup_args['class_paths'] = [$setup_args['class_paths']];
124 124
             }
125 125
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
@@ -192,6 +192,6 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public static function deregister($identifier = '')
194 194
     {
195
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
195
+        unset(self::$_model_registry[$identifier], self::$_model_name_to_classname_map[$identifier]);
196 196
     }
197 197
 }
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -11,187 +11,187 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Register_Model implements EEI_Plugin_API
13 13
 {
14
-    /**
15
-     *
16
-     * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
-     *      like EE_Register_Model::register()'s 2nd arg
18
-     */
19
-    protected static $_model_registry;
14
+	/**
15
+	 *
16
+	 * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
+	 *      like EE_Register_Model::register()'s 2nd arg
18
+	 */
19
+	protected static $_model_registry;
20 20
 
21
-    /**
22
-     *
23
-     * @var array keys are model names, values are their class names. Stored on registration and used
24
-     * on a hook
25
-     */
26
-    protected static $_model_name_to_classname_map;
21
+	/**
22
+	 *
23
+	 * @var array keys are model names, values are their class names. Stored on registration and used
24
+	 * on a hook
25
+	 */
26
+	protected static $_model_name_to_classname_map;
27 27
 
28 28
 
29
-    /**
30
-     * @param string $identifier  unique id for it
31
-     * @param array  $setup_args  {
32
-     * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
-     *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
-     *                            EEM_{model_name}. Eg. you could pass
35
-     *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
-     *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
-     *                            contains the class "EEM_Food" and
38
-     *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
-     *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
-     *                            class contained in each file should extend EEM_Base.
41
-     * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
-     *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
-     *                            file should extend EE_Base_Class
44
-     *
45
-     * }
46
-     * @throws EE_Error
47
-     */
48
-    public static function register($identifier = '', array $setup_args = [])
49
-    {
50
-        // required fields MUST be present, so let's make sure they are.
51
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
-            throw new EE_Error(
53
-                esc_html__(
54
-                    'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
-                    'event_espresso'
56
-                )
57
-            );
58
-        }
29
+	/**
30
+	 * @param string $identifier  unique id for it
31
+	 * @param array  $setup_args  {
32
+	 * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
+	 *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
+	 *                            EEM_{model_name}. Eg. you could pass
35
+	 *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
+	 *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
+	 *                            contains the class "EEM_Food" and
38
+	 *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
+	 *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
+	 *                            class contained in each file should extend EEM_Base.
41
+	 * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
+	 *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
+	 *                            file should extend EE_Base_Class
44
+	 *
45
+	 * }
46
+	 * @throws EE_Error
47
+	 */
48
+	public static function register($identifier = '', array $setup_args = [])
49
+	{
50
+		// required fields MUST be present, so let's make sure they are.
51
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
+			throw new EE_Error(
53
+				esc_html__(
54
+					'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
+					'event_espresso'
56
+				)
57
+			);
58
+		}
59 59
 
60
-        // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
62
-            return;
63
-        }
60
+		// make sure we don't register twice
61
+		if (isset(self::$_model_registry[ $identifier ])) {
62
+			return;
63
+		}
64 64
 
65
-        if (
66
-            ! did_action('AHEE__EE_System__load_espresso_addons')
67
-            || did_action('FHEE__EE_System__parse_model_names')
68
-            || did_action('FHEE__EE_System__parse_implemented_model_names')
69
-        ) {
70
-            EE_Error::doing_it_wrong(
71
-                __METHOD__,
72
-                sprintf(
73
-                    esc_html__(
74
-                        'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
75
-                        'event_espresso'
76
-                    ),
77
-                    $identifier
78
-                ),
79
-                '4.5'
80
-            );
81
-        }
82
-        self::$_model_registry[ $identifier ] = $setup_args;
65
+		if (
66
+			! did_action('AHEE__EE_System__load_espresso_addons')
67
+			|| did_action('FHEE__EE_System__parse_model_names')
68
+			|| did_action('FHEE__EE_System__parse_implemented_model_names')
69
+		) {
70
+			EE_Error::doing_it_wrong(
71
+				__METHOD__,
72
+				sprintf(
73
+					esc_html__(
74
+						'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
75
+						'event_espresso'
76
+					),
77
+					$identifier
78
+				),
79
+				'4.5'
80
+			);
81
+		}
82
+		self::$_model_registry[ $identifier ] = $setup_args;
83 83
 
84
-        if (
85
-            (isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
86
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
87
-        ) {
88
-            throw new EE_Error(
89
-                sprintf(
90
-                    esc_html__(
91
-                        'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
92
-                        'event_espresso'
93
-                    ),
94
-                    implode(", ", array_keys($setup_args))
95
-                )
96
-            );
97
-        }
98
-        if (isset($setup_args['model_paths'])) {
99
-            // make sure they passed in an array
100
-            if (! is_array($setup_args['model_paths'])) {
101
-                $setup_args['model_paths'] = [$setup_args['model_paths']];
102
-            }
103
-            // we want to add this as a model folder
104
-            // and autoload them all
105
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
106
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
107
-            $model_name_to_classname_map = [];
108
-            foreach (array_keys($class_to_filepath_map) as $classname) {
109
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
110
-            }
111
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
112
-            add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
113
-            add_filter(
114
-                'FHEE__EE_System__parse_implemented_model_names',
115
-                ['EE_Register_Model', 'add_addon_models']
116
-            );
117
-            add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
118
-            unset($setup_args['model_paths']);
119
-        }
120
-        if (isset($setup_args['class_paths'])) {
121
-            // make sure they passed in an array
122
-            if (! is_array($setup_args['class_paths'])) {
123
-                $setup_args['class_paths'] = [$setup_args['class_paths']];
124
-            }
125
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
126
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
127
-            add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
128
-            unset($setup_args['class_paths']);
129
-        }
130
-        foreach ($setup_args as $unknown_key => $unknown_config) {
131
-            self::deregister($identifier);
132
-            throw new EE_Error(
133
-                sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
134
-            );
135
-        }
136
-    }
84
+		if (
85
+			(isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
86
+			|| (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
87
+		) {
88
+			throw new EE_Error(
89
+				sprintf(
90
+					esc_html__(
91
+						'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
92
+						'event_espresso'
93
+					),
94
+					implode(", ", array_keys($setup_args))
95
+				)
96
+			);
97
+		}
98
+		if (isset($setup_args['model_paths'])) {
99
+			// make sure they passed in an array
100
+			if (! is_array($setup_args['model_paths'])) {
101
+				$setup_args['model_paths'] = [$setup_args['model_paths']];
102
+			}
103
+			// we want to add this as a model folder
104
+			// and autoload them all
105
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
106
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
107
+			$model_name_to_classname_map = [];
108
+			foreach (array_keys($class_to_filepath_map) as $classname) {
109
+				$model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
110
+			}
111
+			self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
112
+			add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
113
+			add_filter(
114
+				'FHEE__EE_System__parse_implemented_model_names',
115
+				['EE_Register_Model', 'add_addon_models']
116
+			);
117
+			add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
118
+			unset($setup_args['model_paths']);
119
+		}
120
+		if (isset($setup_args['class_paths'])) {
121
+			// make sure they passed in an array
122
+			if (! is_array($setup_args['class_paths'])) {
123
+				$setup_args['class_paths'] = [$setup_args['class_paths']];
124
+			}
125
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
126
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
127
+			add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
128
+			unset($setup_args['class_paths']);
129
+		}
130
+		foreach ($setup_args as $unknown_key => $unknown_config) {
131
+			self::deregister($identifier);
132
+			throw new EE_Error(
133
+				sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
134
+			);
135
+		}
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * Filters the core list of models
141
-     *
142
-     * @param array $core_models
143
-     * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
144
-     */
145
-    public static function add_addon_models(array $core_models = [])
146
-    {
147
-        foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
148
-            $core_models = array_merge($core_models, $model_name_to_class_map);
149
-        }
150
-        return $core_models;
151
-    }
139
+	/**
140
+	 * Filters the core list of models
141
+	 *
142
+	 * @param array $core_models
143
+	 * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
144
+	 */
145
+	public static function add_addon_models(array $core_models = [])
146
+	{
147
+		foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
148
+			$core_models = array_merge($core_models, $model_name_to_class_map);
149
+		}
150
+		return $core_models;
151
+	}
152 152
 
153 153
 
154
-    /**
155
-     * Filters the list of model folders
156
-     *
157
-     * @param array $folders
158
-     * @return array of folder paths
159
-     */
160
-    public static function add_model_folders(array $folders = [])
161
-    {
162
-        foreach (self::$_model_registry as $setup_args) {
163
-            if (isset($setup_args['model_paths'])) {
164
-                $folders = array_merge($folders, $setup_args['model_paths']);
165
-            }
166
-        }
167
-        return $folders;
168
-    }
154
+	/**
155
+	 * Filters the list of model folders
156
+	 *
157
+	 * @param array $folders
158
+	 * @return array of folder paths
159
+	 */
160
+	public static function add_model_folders(array $folders = [])
161
+	{
162
+		foreach (self::$_model_registry as $setup_args) {
163
+			if (isset($setup_args['model_paths'])) {
164
+				$folders = array_merge($folders, $setup_args['model_paths']);
165
+			}
166
+		}
167
+		return $folders;
168
+	}
169 169
 
170 170
 
171
-    /**
172
-     * Filters the array of model class paths
173
-     *
174
-     * @param array $folders
175
-     * @return array of folder paths
176
-     */
177
-    public static function add_class_folders(array $folders = [])
178
-    {
179
-        foreach (self::$_model_registry as $setup_args) {
180
-            if (isset($setup_args['class_paths'])) {
181
-                $folders = array_merge($folders, $setup_args['class_paths']);
182
-            }
183
-        }
184
-        return $folders;
185
-    }
171
+	/**
172
+	 * Filters the array of model class paths
173
+	 *
174
+	 * @param array $folders
175
+	 * @return array of folder paths
176
+	 */
177
+	public static function add_class_folders(array $folders = [])
178
+	{
179
+		foreach (self::$_model_registry as $setup_args) {
180
+			if (isset($setup_args['class_paths'])) {
181
+				$folders = array_merge($folders, $setup_args['class_paths']);
182
+			}
183
+		}
184
+		return $folders;
185
+	}
186 186
 
187 187
 
188
-    /**
189
-     * deregister
190
-     *
191
-     * @param string $identifier
192
-     */
193
-    public static function deregister($identifier = '')
194
-    {
195
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
196
-    }
188
+	/**
189
+	 * deregister
190
+	 *
191
+	 * @param string $identifier
192
+	 */
193
+	public static function deregister($identifier = '')
194
+	{
195
+		unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
196
+	}
197 197
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Widget.lib.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         }
49 49
 
50 50
         // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
51
+        if (isset(self::$_settings[$identifier])) {
52 52
             return;
53 53
         }
54 54
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
             );
69 69
         }
70 70
         // setup $_settings array from incoming values.
71
-        self::$_settings[ $identifier ] = [
71
+        self::$_settings[$identifier] = [
72 72
             // array of full server paths to any EED_Widgets used by the widget
73 73
             'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [],
74 74
         ];
@@ -107,6 +107,6 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public static function deregister($identifier = '')
109 109
     {
110
-        unset(self::$_settings[ $identifier ]);
110
+        unset(self::$_settings[$identifier]);
111 111
     }
112 112
 }
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -14,98 +14,98 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Register_Widget implements EEI_Plugin_API
16 16
 {
17
-    /**
18
-     * Holds values for registered widgets
19
-     *
20
-     * @var array
21
-     */
22
-    protected static $_settings = [];
17
+	/**
18
+	 * Holds values for registered widgets
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected static $_settings = [];
23 23
 
24 24
 
25
-    /**
26
-     *    Method for registering new EED_Widgets
27
-     *
28
-     * @param string $identifier a unique identifier for this set of widgets
29
-     * @param array  $setup_args an array of arguments provided for registering widgets
30
-     * @type array widget_paths        an array of full server paths to folders containing any EED_Widgets, or to the
31
-     *                           EED_Widget files themselves
32
-     * @return void
33
-     * @throws EE_Error
34
-     * @since    4.3.0
35
-     */
36
-    public static function register($identifier = '', array $setup_args = [])
37
-    {
25
+	/**
26
+	 *    Method for registering new EED_Widgets
27
+	 *
28
+	 * @param string $identifier a unique identifier for this set of widgets
29
+	 * @param array  $setup_args an array of arguments provided for registering widgets
30
+	 * @type array widget_paths        an array of full server paths to folders containing any EED_Widgets, or to the
31
+	 *                           EED_Widget files themselves
32
+	 * @return void
33
+	 * @throws EE_Error
34
+	 * @since    4.3.0
35
+	 */
36
+	public static function register($identifier = '', array $setup_args = [])
37
+	{
38 38
 
39
-        // required fields MUST be present, so let's make sure they are.
40
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['widget_paths'])) {
41
-            throw new EE_Error(
42
-                esc_html__(
43
-                    'In order to register Widgets with EE_Register_Widget::register(), you must include a "widget_id" (a unique identifier for this set of widgets), and an array containing the following keys: "widget_paths" (an array of full server paths to folders that contain widgets, or to the widget files themselves)',
44
-                    'event_espresso'
45
-                )
46
-            );
47
-        }
39
+		// required fields MUST be present, so let's make sure they are.
40
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['widget_paths'])) {
41
+			throw new EE_Error(
42
+				esc_html__(
43
+					'In order to register Widgets with EE_Register_Widget::register(), you must include a "widget_id" (a unique identifier for this set of widgets), and an array containing the following keys: "widget_paths" (an array of full server paths to folders that contain widgets, or to the widget files themselves)',
44
+					'event_espresso'
45
+				)
46
+			);
47
+		}
48 48
 
49
-        // make sure we don't register twice
50
-        if (isset(self::$_settings[ $identifier ])) {
51
-            return;
52
-        }
49
+		// make sure we don't register twice
50
+		if (isset(self::$_settings[ $identifier ])) {
51
+			return;
52
+		}
53 53
 
54 54
 
55
-        // make sure this was called in the right place!
56
-        if (
57
-            ! did_action('AHEE__EE_System__load_espresso_addons')
58
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
59
-        ) {
60
-            EE_Error::doing_it_wrong(
61
-                __METHOD__,
62
-                esc_html__(
63
-                    'An attempt to register widgets has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register widgets.',
64
-                    'event_espresso'
65
-                ),
66
-                '4.3.0'
67
-            );
68
-        }
69
-        // setup $_settings array from incoming values.
70
-        self::$_settings[ $identifier ] = [
71
-            // array of full server paths to any EED_Widgets used by the widget
72
-            'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [],
73
-        ];
74
-        // add to list of widgets to be registered
75
-        add_filter(
76
-            'FHEE__EE_Config__register_widgets__widgets_to_register',
77
-            ['EE_Register_Widget', 'add_widgets']
78
-        );
79
-    }
55
+		// make sure this was called in the right place!
56
+		if (
57
+			! did_action('AHEE__EE_System__load_espresso_addons')
58
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
59
+		) {
60
+			EE_Error::doing_it_wrong(
61
+				__METHOD__,
62
+				esc_html__(
63
+					'An attempt to register widgets has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register widgets.',
64
+					'event_espresso'
65
+				),
66
+				'4.3.0'
67
+			);
68
+		}
69
+		// setup $_settings array from incoming values.
70
+		self::$_settings[ $identifier ] = [
71
+			// array of full server paths to any EED_Widgets used by the widget
72
+			'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [],
73
+		];
74
+		// add to list of widgets to be registered
75
+		add_filter(
76
+			'FHEE__EE_Config__register_widgets__widgets_to_register',
77
+			['EE_Register_Widget', 'add_widgets']
78
+		);
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * Filters the list of widgets to add ours.
84
-     * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
85
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/widgets/espresso_monkey'...)
86
-     *
87
-     * @param array $widgets_to_register array of paths to all widgets that require registering
88
-     * @return array
89
-     */
90
-    public static function add_widgets(array $widgets_to_register = [])
91
-    {
92
-        foreach (self::$_settings as $settings) {
93
-            $widgets_to_register = array_merge($widgets_to_register, $settings['widget_paths']);
94
-        }
95
-        return $widgets_to_register;
96
-    }
82
+	/**
83
+	 * Filters the list of widgets to add ours.
84
+	 * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
85
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/widgets/espresso_monkey'...)
86
+	 *
87
+	 * @param array $widgets_to_register array of paths to all widgets that require registering
88
+	 * @return array
89
+	 */
90
+	public static function add_widgets(array $widgets_to_register = [])
91
+	{
92
+		foreach (self::$_settings as $settings) {
93
+			$widgets_to_register = array_merge($widgets_to_register, $settings['widget_paths']);
94
+		}
95
+		return $widgets_to_register;
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * This deregisters a widget that was previously registered with a specific $identifier.
101
-     *
102
-     * @param string $identifier the name for the widget that was previously registered
103
-     * @return void
104
-     * @since    4.3.0
105
-     *
106
-     */
107
-    public static function deregister($identifier = '')
108
-    {
109
-        unset(self::$_settings[ $identifier ]);
110
-    }
99
+	/**
100
+	 * This deregisters a widget that was previously registered with a specific $identifier.
101
+	 *
102
+	 * @param string $identifier the name for the widget that was previously registered
103
+	 * @return void
104
+	 * @since    4.3.0
105
+	 *
106
+	 */
107
+	public static function deregister($identifier = '')
108
+	{
109
+		unset(self::$_settings[ $identifier ]);
110
+	}
111 111
 }
Please login to merge, or discard this patch.