Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
created
core/EE_Config.core.php 2 patches
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     public static function instance()
148 148
     {
149 149
         // check if class object is instantiated, and instantiated properly
150
-        if (! self::$_instance instanceof EE_Config) {
150
+        if ( ! self::$_instance instanceof EE_Config) {
151 151
             self::$_instance = new self();
152 152
         }
153 153
         return self::$_instance;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
                 $this
286 286
             );
287 287
             if (is_object($settings) && property_exists($this, $config)) {
288
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
288
+                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings);
289 289
                 // call configs populate method to ensure any defaults are set for empty values.
290 290
                 if (method_exists($settings, 'populate')) {
291 291
                     $this->{$config}->populate();
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
                         break;
561 561
                     // TEST #2 : check that settings section exists
562 562
                     case 2:
563
-                        if (! isset($this->{$section})) {
563
+                        if ( ! isset($this->{$section})) {
564 564
                             if ($display_errors) {
565 565
                                 throw new EE_Error(
566 566
                                     sprintf(
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
                         break;
622 622
                     // TEST #6 : verify config class is accessible
623 623
                     case 6:
624
-                        if (! class_exists($config_class)) {
624
+                        if ( ! class_exists($config_class)) {
625 625
                             if ($display_errors) {
626 626
                                 throw new EE_Error(
627 627
                                     sprintf(
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
                         break;
639 639
                     // TEST #7 : check that config has even been set
640 640
                     case 7:
641
-                        if (! isset($this->{$section}->{$name})) {
641
+                        if ( ! isset($this->{$section}->{$name})) {
642 642
                             if ($display_errors) {
643 643
                                 throw new EE_Error(
644 644
                                     sprintf(
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
                         break;
657 657
                     // TEST #8 : check that config is the requested type
658 658
                     case 8:
659
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
659
+                        if ( ! $this->{$section}->{$name} instanceof $config_class) {
660 660
                             if ($display_errors) {
661 661
                                 throw new EE_Error(
662 662
                                     sprintf(
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
                         break;
676 676
                     // TEST #9 : verify config object
677 677
                     case 9:
678
-                        if (! $config_obj instanceof EE_Config_Base) {
678
+                        if ( ! $config_obj instanceof EE_Config_Base) {
679 679
                             if ($display_errors) {
680 680
                                 throw new EE_Error(
681 681
                                     sprintf(
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
      */
708 708
     private function _generate_config_option_name($section = '', $name = '')
709 709
     {
710
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
710
+        return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name));
711 711
     }
712 712
 
713 713
 
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
     {
725 725
         return ! empty($config_class)
726 726
             ? $config_class
727
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
727
+            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config';
728 728
     }
729 729
 
730 730
 
@@ -743,17 +743,17 @@  discard block
 block discarded – undo
743 743
         // ensure config class is set to something
744 744
         $config_class = $this->_set_config_class($config_class, $name);
745 745
         // run tests 1-4, 6, and 7 to verify all config params are set and valid
746
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
746
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
747 747
             return null;
748 748
         }
749 749
         $config_option_name = $this->_generate_config_option_name($section, $name);
750 750
         // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
751
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
752
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
751
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
752
+            $this->_addon_option_names[$config_option_name] = $config_class;
753 753
             $this->update_addon_option_names();
754 754
         }
755 755
         // verify the incoming config object but suppress errors
756
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
756
+        if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
757 757
             $config_obj = new $config_class();
758 758
         }
759 759
         if (get_option($config_option_name)) {
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
         }
816 816
         $config_option_name = $this->_generate_config_option_name($section, $name);
817 817
         // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
818
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
818
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
819 819
             // save new config to db
820 820
             if ($this->set_config($section, $name, $config_class, $config_obj)) {
821 821
                 return true;
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
                             'event_espresso'
842 842
                         ),
843 843
                         $config_class,
844
-                        'EE_Config->' . $section . '->' . $name
844
+                        'EE_Config->'.$section.'->'.$name
845 845
                     ),
846 846
                     __FILE__,
847 847
                     __FUNCTION__,
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
         // ensure config class is set to something
868 868
         $config_class = $this->_set_config_class($config_class, $name);
869 869
         // run tests 1-4, 6 and 7 to verify that all params have been set
870
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
870
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
871 871
             return null;
872 872
         }
873 873
         // now test if the requested config object exists, but suppress errors
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
         // retrieve the wp-option for this config class.
913 913
         $config_option = maybe_unserialize(get_option($config_option_name, array()));
914 914
         if (empty($config_option)) {
915
-            EE_Config::log($config_option_name . '-NOT-FOUND');
915
+            EE_Config::log($config_option_name.'-NOT-FOUND');
916 916
         }
917 917
         return $config_option;
918 918
     }
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
             $config_log = get_option(EE_Config::LOG_NAME, array());
930 930
             /** @var RequestParams $request */
931 931
             $request = LoaderFactory::getLoader()->getShared(RequestParams::class);
932
-            $config_log[ (string) microtime(true) ] = array(
932
+            $config_log[(string) microtime(true)] = array(
933 933
                 'config_name' => $config_option_name,
934 934
                 'request'     => $request->requestParams(),
935 935
             );
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
      */
945 945
     public static function trim_log()
946 946
     {
947
-        if (! EE_Config::logging_enabled()) {
947
+        if ( ! EE_Config::logging_enabled()) {
948 948
             return;
949 949
         }
950 950
         $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
     public static function get_page_for_posts()
969 969
     {
970 970
         $page_for_posts = get_option('page_for_posts');
971
-        if (! $page_for_posts) {
971
+        if ( ! $page_for_posts) {
972 972
             return 'posts';
973 973
         }
974 974
         global $wpdb;
@@ -1025,13 +1025,13 @@  discard block
 block discarded – undo
1025 1025
             )
1026 1026
         ) {
1027 1027
             // grab list of installed widgets
1028
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1028
+            $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR);
1029 1029
             // filter list of modules to register
1030 1030
             $widgets_to_register = apply_filters(
1031 1031
                 'FHEE__EE_Config__register_widgets__widgets_to_register',
1032 1032
                 $widgets_to_register
1033 1033
             );
1034
-            if (! empty($widgets_to_register)) {
1034
+            if ( ! empty($widgets_to_register)) {
1035 1035
                 // cycle thru widget folders
1036 1036
                 foreach ($widgets_to_register as $widget_path) {
1037 1037
                     // add to list of installed widget modules
@@ -1081,31 +1081,31 @@  discard block
 block discarded – undo
1081 1081
         // create classname from widget directory name
1082 1082
         $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1083 1083
         // add class prefix
1084
-        $widget_class = 'EEW_' . $widget;
1084
+        $widget_class = 'EEW_'.$widget;
1085 1085
         // does the widget exist ?
1086
-        if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1086
+        if ( ! is_readable($widget_path.'/'.$widget_class.$widget_ext)) {
1087 1087
             $msg = sprintf(
1088 1088
                 esc_html__(
1089 1089
                     'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1090 1090
                     'event_espresso'
1091 1091
                 ),
1092 1092
                 $widget_class,
1093
-                $widget_path . '/' . $widget_class . $widget_ext
1093
+                $widget_path.'/'.$widget_class.$widget_ext
1094 1094
             );
1095
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1095
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1096 1096
             return;
1097 1097
         }
1098 1098
         // load the widget class file
1099
-        require_once($widget_path . '/' . $widget_class . $widget_ext);
1099
+        require_once($widget_path.'/'.$widget_class.$widget_ext);
1100 1100
         // verify that class exists
1101
-        if (! class_exists($widget_class)) {
1101
+        if ( ! class_exists($widget_class)) {
1102 1102
             $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1103
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1103
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1104 1104
             return;
1105 1105
         }
1106 1106
         register_widget($widget_class);
1107 1107
         // add to array of registered widgets
1108
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1108
+        EE_Registry::instance()->widgets->{$widget_class} = $widget_path.'/'.$widget_class.$widget_ext;
1109 1109
     }
1110 1110
 
1111 1111
 
@@ -1118,19 +1118,19 @@  discard block
 block discarded – undo
1118 1118
     private function _register_modules()
1119 1119
     {
1120 1120
         // grab list of installed modules
1121
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1121
+        $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR);
1122 1122
         // filter list of modules to register
1123 1123
         $modules_to_register = apply_filters(
1124 1124
             'FHEE__EE_Config__register_modules__modules_to_register',
1125 1125
             $modules_to_register
1126 1126
         );
1127
-        if (! empty($modules_to_register)) {
1127
+        if ( ! empty($modules_to_register)) {
1128 1128
             // loop through folders
1129 1129
             foreach ($modules_to_register as $module_path) {
1130 1130
                 /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1131 1131
                 if (
1132
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1133
-                    && $module_path !== EE_MODULES . 'gateways'
1132
+                    $module_path !== EE_MODULES.'zzz-copy-this-module-template'
1133
+                    && $module_path !== EE_MODULES.'gateways'
1134 1134
                 ) {
1135 1135
                     // add to list of installed modules
1136 1136
                     EE_Config::register_module($module_path);
@@ -1167,25 +1167,25 @@  discard block
 block discarded – undo
1167 1167
             // remove last segment
1168 1168
             array_pop($module_path);
1169 1169
             // glue it back together
1170
-            $module_path = implode('/', $module_path) . '/';
1170
+            $module_path = implode('/', $module_path).'/';
1171 1171
             // take first segment from file name pieces and sanitize it
1172 1172
             $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1173 1173
             // ensure class prefix is added
1174
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1174
+            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module;
1175 1175
         } else {
1176 1176
             // we need to generate the filename based off of the folder name
1177 1177
             // grab and sanitize module name
1178 1178
             $module = strtolower(basename($module_path));
1179 1179
             $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1180 1180
             // like trailingslashit()
1181
-            $module_path = rtrim($module_path, '/') . '/';
1181
+            $module_path = rtrim($module_path, '/').'/';
1182 1182
             // create classname from module directory name
1183 1183
             $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1184 1184
             // add class prefix
1185
-            $module_class = 'EED_' . $module;
1185
+            $module_class = 'EED_'.$module;
1186 1186
         }
1187 1187
         // does the module exist ?
1188
-        if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1188
+        if ( ! is_readable($module_path.'/'.$module_class.$module_ext)) {
1189 1189
             $msg = sprintf(
1190 1190
                 esc_html__(
1191 1191
                     'The requested %s module file could not be found or is not readable due to file permissions.',
@@ -1193,19 +1193,19 @@  discard block
 block discarded – undo
1193 1193
                 ),
1194 1194
                 $module
1195 1195
             );
1196
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1196
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1197 1197
             return false;
1198 1198
         }
1199 1199
         // load the module class file
1200
-        require_once($module_path . $module_class . $module_ext);
1200
+        require_once($module_path.$module_class.$module_ext);
1201 1201
         // verify that class exists
1202
-        if (! class_exists($module_class)) {
1202
+        if ( ! class_exists($module_class)) {
1203 1203
             $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1204
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1204
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1205 1205
             return false;
1206 1206
         }
1207 1207
         // add to array of registered modules
1208
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1208
+        EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext;
1209 1209
         do_action(
1210 1210
             'AHEE__EE_Config__register_module__complete',
1211 1211
             $module_class,
@@ -1256,26 +1256,26 @@  discard block
 block discarded – undo
1256 1256
     {
1257 1257
         do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1258 1258
         $module = str_replace('EED_', '', $module);
1259
-        $module_class = 'EED_' . $module;
1260
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1259
+        $module_class = 'EED_'.$module;
1260
+        if ( ! isset(EE_Registry::instance()->modules->{$module_class})) {
1261 1261
             $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1262
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1262
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1263 1263
             return false;
1264 1264
         }
1265 1265
         if (empty($route)) {
1266 1266
             $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1267
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1267
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1268 1268
             return false;
1269 1269
         }
1270
-        if (! method_exists('EED_' . $module, $method_name)) {
1270
+        if ( ! method_exists('EED_'.$module, $method_name)) {
1271 1271
             $msg = sprintf(
1272 1272
                 esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1273 1273
                 $route
1274 1274
             );
1275
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1275
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1276 1276
             return false;
1277 1277
         }
1278
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1278
+        EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name);
1279 1279
         return true;
1280 1280
     }
1281 1281
 
@@ -1292,8 +1292,8 @@  discard block
 block discarded – undo
1292 1292
     {
1293 1293
         do_action('AHEE__EE_Config__get_route__begin', $route);
1294 1294
         $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1295
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1296
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1295
+        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1296
+            return EE_Config::$_module_route_map[$key][$route];
1297 1297
         }
1298 1298
         return null;
1299 1299
     }
@@ -1325,47 +1325,47 @@  discard block
 block discarded – undo
1325 1325
     public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1326 1326
     {
1327 1327
         do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1328
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1328
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1329 1329
             $msg = sprintf(
1330 1330
                 esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1331 1331
                 $route
1332 1332
             );
1333
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1333
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1334 1334
             return false;
1335 1335
         }
1336 1336
         if (empty($forward)) {
1337 1337
             $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1338
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1338
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1339 1339
             return false;
1340 1340
         }
1341 1341
         if (is_array($forward)) {
1342
-            if (! isset($forward[1])) {
1342
+            if ( ! isset($forward[1])) {
1343 1343
                 $msg = sprintf(
1344 1344
                     esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1345 1345
                     $route
1346 1346
                 );
1347
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1347
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1348 1348
                 return false;
1349 1349
             }
1350
-            if (! method_exists($forward[0], $forward[1])) {
1350
+            if ( ! method_exists($forward[0], $forward[1])) {
1351 1351
                 $msg = sprintf(
1352 1352
                     esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1353 1353
                     $forward[1],
1354 1354
                     $route
1355 1355
                 );
1356
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1356
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1357 1357
                 return false;
1358 1358
             }
1359
-        } elseif (! function_exists($forward)) {
1359
+        } elseif ( ! function_exists($forward)) {
1360 1360
             $msg = sprintf(
1361 1361
                 esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1362 1362
                 $forward,
1363 1363
                 $route
1364 1364
             );
1365
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1366 1366
             return false;
1367 1367
         }
1368
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1368
+        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1369 1369
         return true;
1370 1370
     }
1371 1371
 
@@ -1383,10 +1383,10 @@  discard block
 block discarded – undo
1383 1383
     public static function get_forward($route = null, $status = 0, $key = 'ee')
1384 1384
     {
1385 1385
         do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1386
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1386
+        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1387 1387
             return apply_filters(
1388 1388
                 'FHEE__EE_Config__get_forward',
1389
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1389
+                EE_Config::$_module_forward_map[$key][$route][$status],
1390 1390
                 $route,
1391 1391
                 $status
1392 1392
             );
@@ -1410,15 +1410,15 @@  discard block
 block discarded – undo
1410 1410
     public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1411 1411
     {
1412 1412
         do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1413
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1413
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1414 1414
             $msg = sprintf(
1415 1415
                 esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1416 1416
                 $route
1417 1417
             );
1418
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1418
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1419 1419
             return false;
1420 1420
         }
1421
-        if (! is_readable($view)) {
1421
+        if ( ! is_readable($view)) {
1422 1422
             $msg = sprintf(
1423 1423
                 esc_html__(
1424 1424
                     'The %s view file could not be found or is not readable due to file permissions.',
@@ -1426,10 +1426,10 @@  discard block
 block discarded – undo
1426 1426
                 ),
1427 1427
                 $view
1428 1428
             );
1429
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1429
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1430 1430
             return false;
1431 1431
         }
1432
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1432
+        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1433 1433
         return true;
1434 1434
     }
1435 1435
 
@@ -1447,10 +1447,10 @@  discard block
 block discarded – undo
1447 1447
     public static function get_view($route = null, $status = 0, $key = 'ee')
1448 1448
     {
1449 1449
         do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1450
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1450
+        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1451 1451
             return apply_filters(
1452 1452
                 'FHEE__EE_Config__get_view',
1453
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1453
+                EE_Config::$_module_view_map[$key][$route][$status],
1454 1454
                 $route,
1455 1455
                 $status
1456 1456
             );
@@ -1476,7 +1476,7 @@  discard block
 block discarded – undo
1476 1476
      */
1477 1477
     public static function getLegacyShortcodesManager()
1478 1478
     {
1479
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1479
+        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1480 1480
             EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1481 1481
                 LegacyShortcodesManager::class
1482 1482
             );
@@ -1523,7 +1523,7 @@  discard block
 block discarded – undo
1523 1523
      */
1524 1524
     public function get_pretty($property)
1525 1525
     {
1526
-        if (! property_exists($this, $property)) {
1526
+        if ( ! property_exists($this, $property)) {
1527 1527
             throw new EE_Error(
1528 1528
                 sprintf(
1529 1529
                     esc_html__(
@@ -1752,11 +1752,11 @@  discard block
 block discarded – undo
1752 1752
      */
1753 1753
     public function reg_page_url()
1754 1754
     {
1755
-        if (! $this->reg_page_url) {
1755
+        if ( ! $this->reg_page_url) {
1756 1756
             $this->reg_page_url = add_query_arg(
1757 1757
                 array('uts' => time()),
1758 1758
                 get_permalink($this->reg_page_id)
1759
-            ) . '#checkout';
1759
+            ).'#checkout';
1760 1760
         }
1761 1761
         return $this->reg_page_url;
1762 1762
     }
@@ -1772,7 +1772,7 @@  discard block
 block discarded – undo
1772 1772
      */
1773 1773
     public function txn_page_url($query_args = array())
1774 1774
     {
1775
-        if (! $this->txn_page_url) {
1775
+        if ( ! $this->txn_page_url) {
1776 1776
             $this->txn_page_url = get_permalink($this->txn_page_id);
1777 1777
         }
1778 1778
         if ($query_args) {
@@ -1793,7 +1793,7 @@  discard block
 block discarded – undo
1793 1793
      */
1794 1794
     public function thank_you_page_url($query_args = array())
1795 1795
     {
1796
-        if (! $this->thank_you_page_url) {
1796
+        if ( ! $this->thank_you_page_url) {
1797 1797
             $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1798 1798
         }
1799 1799
         if ($query_args) {
@@ -1812,7 +1812,7 @@  discard block
 block discarded – undo
1812 1812
      */
1813 1813
     public function cancel_page_url()
1814 1814
     {
1815
-        if (! $this->cancel_page_url) {
1815
+        if ( ! $this->cancel_page_url) {
1816 1816
             $this->cancel_page_url = get_permalink($this->cancel_page_id);
1817 1817
         }
1818 1818
         return $this->cancel_page_url;
@@ -1855,13 +1855,13 @@  discard block
 block discarded – undo
1855 1855
         $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1856 1856
         $option = self::OPTION_NAME_UXIP;
1857 1857
         // set correct table for query
1858
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1858
+        $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options';
1859 1859
         // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1860 1860
         // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1861 1861
         // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1862 1862
         // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1863 1863
         // for the purpose of caching.
1864
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1864
+        $pre = apply_filters('pre_option_'.$option, false, $option);
1865 1865
         if (false !== $pre) {
1866 1866
             EE_Core_Config::$ee_ueip_option = $pre;
1867 1867
             return EE_Core_Config::$ee_ueip_option;
@@ -1875,10 +1875,10 @@  discard block
 block discarded – undo
1875 1875
         if (is_object($row)) {
1876 1876
             $value = $row->option_value;
1877 1877
         } else { // option does not exist so use default.
1878
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1878
+            EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option);
1879 1879
             return EE_Core_Config::$ee_ueip_option;
1880 1880
         }
1881
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1881
+        EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option);
1882 1882
         return EE_Core_Config::$ee_ueip_option;
1883 1883
     }
1884 1884
 
@@ -2140,30 +2140,30 @@  discard block
 block discarded – undo
2140 2140
             // retrieve the country settings from the db, just in case they have been customized
2141 2141
             $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2142 2142
             if ($country instanceof EE_Country) {
2143
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2144
-                $this->name = $country->currency_name_single();    // Dollar
2145
-                $this->plural = $country->currency_name_plural();    // Dollars
2146
-                $this->sign = $country->currency_sign();            // currency sign: $
2143
+                $this->code = $country->currency_code(); // currency code: USD, CAD, EUR
2144
+                $this->name = $country->currency_name_single(); // Dollar
2145
+                $this->plural = $country->currency_name_plural(); // Dollars
2146
+                $this->sign = $country->currency_sign(); // currency sign: $
2147 2147
                 $this->sign_b4 = $country->currency_sign_before(
2148
-                );        // currency sign before or after: $TRUE  or  FALSE$
2149
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2148
+                ); // currency sign before or after: $TRUE  or  FALSE$
2149
+                $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00  3 = 0.000
2150 2150
                 $this->dec_mrk = $country->currency_decimal_mark(
2151
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2151
+                ); // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2152 2152
                 $this->thsnds = $country->currency_thousands_separator(
2153
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2153
+                ); // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2154 2154
             }
2155 2155
         }
2156 2156
         // fallback to hardcoded defaults, in case the above failed
2157 2157
         if (empty($this->code)) {
2158 2158
             // set default currency settings
2159
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2160
-            $this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2161
-            $this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2162
-            $this->sign = '$';    // currency sign: $
2163
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2164
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2165
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2166
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
+            $this->code = 'USD'; // currency code: USD, CAD, EUR
2160
+            $this->name = esc_html__('Dollar', 'event_espresso'); // Dollar
2161
+            $this->plural = esc_html__('Dollars', 'event_espresso'); // Dollars
2162
+            $this->sign = '$'; // currency sign: $
2163
+            $this->sign_b4 = true; // currency sign before or after: $TRUE  or  FALSE$
2164
+            $this->dec_plc = 2; // decimal places: 2 = 0.00  3 = 0.000
2165
+            $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2166
+            $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2167 2167
         }
2168 2168
     }
2169 2169
 }
@@ -2432,8 +2432,8 @@  discard block
 block discarded – undo
2432 2432
             $closing_a_tag = '';
2433 2433
             if (function_exists('get_privacy_policy_url')) {
2434 2434
                 $privacy_page_url = get_privacy_policy_url();
2435
-                if (! empty($privacy_page_url)) {
2436
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2435
+                if ( ! empty($privacy_page_url)) {
2436
+                    $opening_a_tag = '<a href="'.$privacy_page_url.'" target="_blank">';
2437 2437
                     $closing_a_tag = '</a>';
2438 2438
                 }
2439 2439
             }
@@ -2662,7 +2662,7 @@  discard block
 block discarded – undo
2662 2662
     public function log_file_name($reset = false)
2663 2663
     {
2664 2664
         if (empty($this->log_file_name) || $reset) {
2665
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2665
+            $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt';
2666 2666
             EE_Config::instance()->update_espresso_config(false, false);
2667 2667
         }
2668 2668
         return $this->log_file_name;
@@ -2676,7 +2676,7 @@  discard block
 block discarded – undo
2676 2676
     public function debug_file_name($reset = false)
2677 2677
     {
2678 2678
         if (empty($this->debug_file_name) || $reset) {
2679
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2679
+            $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt';
2680 2680
             EE_Config::instance()->update_espresso_config(false, false);
2681 2681
         }
2682 2682
         return $this->debug_file_name;
@@ -2880,21 +2880,21 @@  discard block
 block discarded – undo
2880 2880
         $this->use_google_maps = true;
2881 2881
         $this->google_map_api_key = '';
2882 2882
         // for event details pages (reg page)
2883
-        $this->event_details_map_width = 585;            // ee_map_width_single
2884
-        $this->event_details_map_height = 362;            // ee_map_height_single
2885
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2886
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2887
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2888
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2889
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2883
+        $this->event_details_map_width = 585; // ee_map_width_single
2884
+        $this->event_details_map_height = 362; // ee_map_height_single
2885
+        $this->event_details_map_zoom = 14; // ee_map_zoom_single
2886
+        $this->event_details_display_nav = true; // ee_map_nav_display_single
2887
+        $this->event_details_nav_size = false; // ee_map_nav_size_single
2888
+        $this->event_details_control_type = 'default'; // ee_map_type_control_single
2889
+        $this->event_details_map_align = 'center'; // ee_map_align_single
2890 2890
         // for event list pages
2891
-        $this->event_list_map_width = 300;            // ee_map_width
2892
-        $this->event_list_map_height = 185;        // ee_map_height
2893
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2894
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2895
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2896
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2897
-        $this->event_list_map_align = 'center';            // ee_map_align
2891
+        $this->event_list_map_width = 300; // ee_map_width
2892
+        $this->event_list_map_height = 185; // ee_map_height
2893
+        $this->event_list_map_zoom = 12; // ee_map_zoom
2894
+        $this->event_list_display_nav = false; // ee_map_nav_display
2895
+        $this->event_list_nav_size = true; // ee_map_nav_size
2896
+        $this->event_list_control_type = 'dropdown'; // ee_map_type_control
2897
+        $this->event_list_map_align = 'center'; // ee_map_align
2898 2898
     }
2899 2899
 }
2900 2900
 
Please login to merge, or discard this patch.
Indentation   +3180 added lines, -3180 removed lines patch added patch discarded remove patch
@@ -18,2541 +18,2541 @@  discard block
 block discarded – undo
18 18
  */
19 19
 final class EE_Config implements ResettableInterface
20 20
 {
21
-    const OPTION_NAME = 'ee_config';
22
-
23
-    const LOG_NAME = 'ee_config_log';
24
-
25
-    const LOG_LENGTH = 100;
26
-
27
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
28
-
29
-    /**
30
-     *    instance of the EE_Config object
31
-     *
32
-     * @var    EE_Config $_instance
33
-     * @access    private
34
-     */
35
-    private static $_instance;
36
-
37
-    /**
38
-     * @var boolean $_logging_enabled
39
-     */
40
-    private static $_logging_enabled = false;
41
-
42
-    /**
43
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
-     */
45
-    private $legacy_shortcodes_manager;
46
-
47
-    /**
48
-     * An StdClass whose property names are addon slugs,
49
-     * and values are their config classes
50
-     *
51
-     * @var StdClass
52
-     */
53
-    public $addons;
54
-
55
-    /**
56
-     * @var EE_Admin_Config
57
-     */
58
-    public $admin;
59
-
60
-    /**
61
-     * @var EE_Core_Config
62
-     */
63
-    public $core;
64
-
65
-    /**
66
-     * @var EE_Currency_Config
67
-     */
68
-    public $currency;
69
-
70
-    /**
71
-     * @var EE_Organization_Config
72
-     */
73
-    public $organization;
74
-
75
-    /**
76
-     * @var EE_Registration_Config
77
-     */
78
-    public $registration;
79
-
80
-    /**
81
-     * @var EE_Template_Config
82
-     */
83
-    public $template_settings;
84
-
85
-    /**
86
-     * Holds EE environment values.
87
-     *
88
-     * @var EE_Environment_Config
89
-     */
90
-    public $environment;
91
-
92
-    /**
93
-     * settings pertaining to Google maps
94
-     *
95
-     * @var EE_Map_Config
96
-     */
97
-    public $map_settings;
98
-
99
-    /**
100
-     * settings pertaining to Taxes
101
-     *
102
-     * @var EE_Tax_Config
103
-     */
104
-    public $tax_settings;
105
-
106
-    /**
107
-     * Settings pertaining to global messages settings.
108
-     *
109
-     * @var EE_Messages_Config
110
-     */
111
-    public $messages;
112
-
113
-    /**
114
-     * @deprecated
115
-     * @var EE_Gateway_Config
116
-     */
117
-    public $gateway;
118
-
119
-    /**
120
-     * @var    array $_addon_option_names
121
-     * @access    private
122
-     */
123
-    private $_addon_option_names = array();
124
-
125
-    /**
126
-     * @var    array $_module_route_map
127
-     * @access    private
128
-     */
129
-    private static $_module_route_map = array();
130
-
131
-    /**
132
-     * @var    array $_module_forward_map
133
-     * @access    private
134
-     */
135
-    private static $_module_forward_map = array();
136
-
137
-    /**
138
-     * @var    array $_module_view_map
139
-     * @access    private
140
-     */
141
-    private static $_module_view_map = array();
142
-
143
-
144
-    /**
145
-     * @singleton method used to instantiate class object
146
-     * @access    public
147
-     * @return EE_Config instance
148
-     */
149
-    public static function instance()
150
-    {
151
-        // check if class object is instantiated, and instantiated properly
152
-        if (! self::$_instance instanceof EE_Config) {
153
-            self::$_instance = new self();
154
-        }
155
-        return self::$_instance;
156
-    }
157
-
158
-
159
-    /**
160
-     * Resets the config
161
-     *
162
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
163
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
164
-     *                               reflect its state in the database
165
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
166
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
167
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
168
-     *                               site was put into maintenance mode)
169
-     * @return EE_Config
170
-     */
171
-    public static function reset($hard_reset = false, $reinstantiate = true)
172
-    {
173
-        if (self::$_instance instanceof EE_Config) {
174
-            if ($hard_reset) {
175
-                self::$_instance->legacy_shortcodes_manager = null;
176
-                self::$_instance->_addon_option_names = array();
177
-                self::$_instance->_initialize_config();
178
-                self::$_instance->update_espresso_config();
179
-            }
180
-            self::$_instance->update_addon_option_names();
181
-        }
182
-        self::$_instance = null;
183
-        // we don't need to reset the static properties imo because those should
184
-        // only change when a module is added or removed. Currently we don't
185
-        // support removing a module during a request when it previously existed
186
-        if ($reinstantiate) {
187
-            return self::instance();
188
-        } else {
189
-            return null;
190
-        }
191
-    }
192
-
193
-
194
-    /**
195
-     *    class constructor
196
-     *
197
-     * @access    private
198
-     */
199
-    private function __construct()
200
-    {
201
-        do_action('AHEE__EE_Config__construct__begin', $this);
202
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
203
-        // setup empty config classes
204
-        $this->_initialize_config();
205
-        // load existing EE site settings
206
-        $this->_load_core_config();
207
-        // confirm everything loaded correctly and set filtered defaults if not
208
-        $this->_verify_config();
209
-        //  register shortcodes and modules
210
-        add_action(
211
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
212
-            array($this, 'register_shortcodes_and_modules'),
213
-            999
214
-        );
215
-        //  initialize shortcodes and modules
216
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
217
-        // register widgets
218
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
219
-        // shutdown
220
-        add_action('shutdown', array($this, 'shutdown'), 10);
221
-        // construct__end hook
222
-        do_action('AHEE__EE_Config__construct__end', $this);
223
-        // hardcoded hack
224
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
225
-    }
226
-
227
-
228
-    /**
229
-     * @return boolean
230
-     */
231
-    public static function logging_enabled()
232
-    {
233
-        return self::$_logging_enabled;
234
-    }
235
-
236
-
237
-    /**
238
-     * use to get the current theme if needed from static context
239
-     *
240
-     * @return string current theme set.
241
-     */
242
-    public static function get_current_theme()
243
-    {
244
-        return isset(self::$_instance->template_settings->current_espresso_theme)
245
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
246
-    }
247
-
248
-
249
-    /**
250
-     *        _initialize_config
251
-     *
252
-     * @access private
253
-     * @return void
254
-     */
255
-    private function _initialize_config()
256
-    {
257
-        EE_Config::trim_log();
258
-        // set defaults
259
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
260
-        $this->addons = new stdClass();
261
-        // set _module_route_map
262
-        EE_Config::$_module_route_map = array();
263
-        // set _module_forward_map
264
-        EE_Config::$_module_forward_map = array();
265
-        // set _module_view_map
266
-        EE_Config::$_module_view_map = array();
267
-    }
268
-
269
-
270
-    /**
271
-     *        load core plugin configuration
272
-     *
273
-     * @access private
274
-     * @return void
275
-     */
276
-    private function _load_core_config()
277
-    {
278
-        // load_core_config__start hook
279
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
280
-        $espresso_config = $this->get_espresso_config();
281
-        foreach ($espresso_config as $config => $settings) {
282
-            // load_core_config__start hook
283
-            $settings = apply_filters(
284
-                'FHEE__EE_Config___load_core_config__config_settings',
285
-                $settings,
286
-                $config,
287
-                $this
288
-            );
289
-            if (is_object($settings) && property_exists($this, $config)) {
290
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
291
-                // call configs populate method to ensure any defaults are set for empty values.
292
-                if (method_exists($settings, 'populate')) {
293
-                    $this->{$config}->populate();
294
-                }
295
-                if (method_exists($settings, 'do_hooks')) {
296
-                    $this->{$config}->do_hooks();
297
-                }
298
-            }
299
-        }
300
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
301
-            $this->update_espresso_config();
302
-        }
303
-        // load_core_config__end hook
304
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
305
-    }
306
-
307
-
308
-    /**
309
-     *    _verify_config
310
-     *
311
-     * @access    protected
312
-     * @return    void
313
-     */
314
-    protected function _verify_config()
315
-    {
316
-        $this->core = $this->core instanceof EE_Core_Config
317
-            ? $this->core
318
-            : new EE_Core_Config();
319
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
320
-        $this->organization = $this->organization instanceof EE_Organization_Config
321
-            ? $this->organization
322
-            : new EE_Organization_Config();
323
-        $this->organization = apply_filters(
324
-            'FHEE__EE_Config___initialize_config__organization',
325
-            $this->organization
326
-        );
327
-        $this->currency = $this->currency instanceof EE_Currency_Config
328
-            ? $this->currency
329
-            : new EE_Currency_Config();
330
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
331
-        $this->registration = $this->registration instanceof EE_Registration_Config
332
-            ? $this->registration
333
-            : new EE_Registration_Config();
334
-        $this->registration = apply_filters(
335
-            'FHEE__EE_Config___initialize_config__registration',
336
-            $this->registration
337
-        );
338
-        $this->admin = $this->admin instanceof EE_Admin_Config
339
-            ? $this->admin
340
-            : new EE_Admin_Config();
341
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
342
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
343
-            ? $this->template_settings
344
-            : new EE_Template_Config();
345
-        $this->template_settings = apply_filters(
346
-            'FHEE__EE_Config___initialize_config__template_settings',
347
-            $this->template_settings
348
-        );
349
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
350
-            ? $this->map_settings
351
-            : new EE_Map_Config();
352
-        $this->map_settings = apply_filters(
353
-            'FHEE__EE_Config___initialize_config__map_settings',
354
-            $this->map_settings
355
-        );
356
-        $this->environment = $this->environment instanceof EE_Environment_Config
357
-            ? $this->environment
358
-            : new EE_Environment_Config();
359
-        $this->environment = apply_filters(
360
-            'FHEE__EE_Config___initialize_config__environment',
361
-            $this->environment
362
-        );
363
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
364
-            ? $this->tax_settings
365
-            : new EE_Tax_Config();
366
-        $this->tax_settings = apply_filters(
367
-            'FHEE__EE_Config___initialize_config__tax_settings',
368
-            $this->tax_settings
369
-        );
370
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
371
-        $this->messages = $this->messages instanceof EE_Messages_Config
372
-            ? $this->messages
373
-            : new EE_Messages_Config();
374
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
375
-            ? $this->gateway
376
-            : new EE_Gateway_Config();
377
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
378
-        $this->legacy_shortcodes_manager = null;
379
-    }
380
-
381
-
382
-    /**
383
-     *    get_espresso_config
384
-     *
385
-     * @access    public
386
-     * @return    array of espresso config stuff
387
-     */
388
-    public function get_espresso_config()
389
-    {
390
-        // grab espresso configuration
391
-        return apply_filters(
392
-            'FHEE__EE_Config__get_espresso_config__CFG',
393
-            get_option(EE_Config::OPTION_NAME, array())
394
-        );
395
-    }
396
-
397
-
398
-    /**
399
-     *    double_check_config_comparison
400
-     *
401
-     * @access    public
402
-     * @param string $option
403
-     * @param        $old_value
404
-     * @param        $value
405
-     */
406
-    public function double_check_config_comparison($option, $old_value, $value)
407
-    {
408
-        // make sure we're checking the ee config
409
-        if ($option === EE_Config::OPTION_NAME) {
410
-            // run a loose comparison of the old value against the new value for type and properties,
411
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
412
-            if ($value != $old_value) {
413
-                // if they are NOT the same, then remove the hook,
414
-                // which means the subsequent update results will be based solely on the update query results
415
-                // the reason we do this is because, as stated above,
416
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
417
-                // this happens PRIOR to serialization and any subsequent update.
418
-                // If values are found to match their previous old value,
419
-                // then WP bails before performing any update.
420
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
421
-                // it just pulled from the db, with the one being passed to it (which will not match).
422
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
423
-                // MySQL MAY ALSO NOT perform the update because
424
-                // the string it sees in the db looks the same as the new one it has been passed!!!
425
-                // This results in the query returning an "affected rows" value of ZERO,
426
-                // which gets returned immediately by WP update_option and looks like an error.
427
-                remove_action('update_option', array($this, 'check_config_updated'));
428
-            }
429
-        }
430
-    }
431
-
432
-
433
-    /**
434
-     *    update_espresso_config
435
-     *
436
-     * @access   public
437
-     */
438
-    protected function _reset_espresso_addon_config()
439
-    {
440
-        $this->_addon_option_names = array();
441
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
442
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
443
-            if ($addon_config_obj instanceof EE_Config_Base) {
444
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
445
-            }
446
-            $this->addons->{$addon_name} = null;
447
-        }
448
-    }
449
-
450
-
451
-    /**
452
-     *    update_espresso_config
453
-     *
454
-     * @access   public
455
-     * @param   bool $add_success
456
-     * @param   bool $add_error
457
-     * @return   bool
458
-     */
459
-    public function update_espresso_config($add_success = false, $add_error = true)
460
-    {
461
-        // don't allow config updates during WP heartbeats
462
-        /** @var RequestInterface $request */
463
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
464
-        if ($request->isWordPressHeartbeat()) {
465
-            return false;
466
-        }
467
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
468
-        // $clone = clone( self::$_instance );
469
-        // self::$_instance = NULL;
470
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
471
-        $this->_reset_espresso_addon_config();
472
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
473
-        // but BEFORE the actual update occurs
474
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
475
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
476
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
477
-        $this->legacy_shortcodes_manager = null;
478
-        // now update "ee_config"
479
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
480
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
481
-        EE_Config::log(EE_Config::OPTION_NAME);
482
-        // if not saved... check if the hook we just added still exists;
483
-        // if it does, it means one of two things:
484
-        // that update_option bailed at the($value === $old_value) conditional,
485
-        // or...
486
-        // the db update query returned 0 rows affected
487
-        // (probably because the data  value was the same from it's perspective)
488
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
489
-        // but just means no update occurred, so don't display an error to the user.
490
-        // BUT... if update_option returns FALSE, AND the hook is missing,
491
-        // then it means that something truly went wrong
492
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
493
-        // remove our action since we don't want it in the system anymore
494
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
495
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
496
-        // self::$_instance = $clone;
497
-        // unset( $clone );
498
-        // if config remains the same or was updated successfully
499
-        if ($saved) {
500
-            if ($add_success) {
501
-                EE_Error::add_success(
502
-                    esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
503
-                    __FILE__,
504
-                    __FUNCTION__,
505
-                    __LINE__
506
-                );
507
-            }
508
-            return true;
509
-        } else {
510
-            if ($add_error) {
511
-                EE_Error::add_error(
512
-                    esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
513
-                    __FILE__,
514
-                    __FUNCTION__,
515
-                    __LINE__
516
-                );
517
-            }
518
-            return false;
519
-        }
520
-    }
521
-
522
-
523
-    /**
524
-     *    _verify_config_params
525
-     *
526
-     * @access    private
527
-     * @param    string         $section
528
-     * @param    string         $name
529
-     * @param    string         $config_class
530
-     * @param    EE_Config_Base $config_obj
531
-     * @param    array          $tests_to_run
532
-     * @param    bool           $display_errors
533
-     * @return    bool    TRUE on success, FALSE on fail
534
-     */
535
-    private function _verify_config_params(
536
-        $section = '',
537
-        $name = '',
538
-        $config_class = '',
539
-        $config_obj = null,
540
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
541
-        $display_errors = true
542
-    ) {
543
-        try {
544
-            foreach ($tests_to_run as $test) {
545
-                switch ($test) {
546
-                    // TEST #1 : check that section was set
547
-                    case 1:
548
-                        if (empty($section)) {
549
-                            if ($display_errors) {
550
-                                throw new EE_Error(
551
-                                    sprintf(
552
-                                        esc_html__(
553
-                                            'No configuration section has been provided while attempting to save "%s".',
554
-                                            'event_espresso'
555
-                                        ),
556
-                                        $config_class
557
-                                    )
558
-                                );
559
-                            }
560
-                            return false;
561
-                        }
562
-                        break;
563
-                    // TEST #2 : check that settings section exists
564
-                    case 2:
565
-                        if (! isset($this->{$section})) {
566
-                            if ($display_errors) {
567
-                                throw new EE_Error(
568
-                                    sprintf(
569
-                                        esc_html__('The "%s" configuration section does not exist.', 'event_espresso'),
570
-                                        $section
571
-                                    )
572
-                                );
573
-                            }
574
-                            return false;
575
-                        }
576
-                        break;
577
-                    // TEST #3 : check that section is the proper format
578
-                    case 3:
579
-                        if (
580
-                            ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
581
-                        ) {
582
-                            if ($display_errors) {
583
-                                throw new EE_Error(
584
-                                    sprintf(
585
-                                        esc_html__(
586
-                                            'The "%s" configuration settings have not been formatted correctly.',
587
-                                            'event_espresso'
588
-                                        ),
589
-                                        $section
590
-                                    )
591
-                                );
592
-                            }
593
-                            return false;
594
-                        }
595
-                        break;
596
-                    // TEST #4 : check that config section name has been set
597
-                    case 4:
598
-                        if (empty($name)) {
599
-                            if ($display_errors) {
600
-                                throw new EE_Error(
601
-                                    esc_html__(
602
-                                        'No name has been provided for the specific configuration section.',
603
-                                        'event_espresso'
604
-                                    )
605
-                                );
606
-                            }
607
-                            return false;
608
-                        }
609
-                        break;
610
-                    // TEST #5 : check that a config class name has been set
611
-                    case 5:
612
-                        if (empty($config_class)) {
613
-                            if ($display_errors) {
614
-                                throw new EE_Error(
615
-                                    esc_html__(
616
-                                        'No class name has been provided for the specific configuration section.',
617
-                                        'event_espresso'
618
-                                    )
619
-                                );
620
-                            }
621
-                            return false;
622
-                        }
623
-                        break;
624
-                    // TEST #6 : verify config class is accessible
625
-                    case 6:
626
-                        if (! class_exists($config_class)) {
627
-                            if ($display_errors) {
628
-                                throw new EE_Error(
629
-                                    sprintf(
630
-                                        esc_html__(
631
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
632
-                                            'event_espresso'
633
-                                        ),
634
-                                        $config_class
635
-                                    )
636
-                                );
637
-                            }
638
-                            return false;
639
-                        }
640
-                        break;
641
-                    // TEST #7 : check that config has even been set
642
-                    case 7:
643
-                        if (! isset($this->{$section}->{$name})) {
644
-                            if ($display_errors) {
645
-                                throw new EE_Error(
646
-                                    sprintf(
647
-                                        esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
648
-                                        $section,
649
-                                        $name
650
-                                    )
651
-                                );
652
-                            }
653
-                            return false;
654
-                        } else {
655
-                            // and make sure it's not serialized
656
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
657
-                        }
658
-                        break;
659
-                    // TEST #8 : check that config is the requested type
660
-                    case 8:
661
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
662
-                            if ($display_errors) {
663
-                                throw new EE_Error(
664
-                                    sprintf(
665
-                                        esc_html__(
666
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
667
-                                            'event_espresso'
668
-                                        ),
669
-                                        $section,
670
-                                        $name,
671
-                                        $config_class
672
-                                    )
673
-                                );
674
-                            }
675
-                            return false;
676
-                        }
677
-                        break;
678
-                    // TEST #9 : verify config object
679
-                    case 9:
680
-                        if (! $config_obj instanceof EE_Config_Base) {
681
-                            if ($display_errors) {
682
-                                throw new EE_Error(
683
-                                    sprintf(
684
-                                        esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
685
-                                        print_r($config_obj, true)
686
-                                    )
687
-                                );
688
-                            }
689
-                            return false;
690
-                        }
691
-                        break;
692
-                }
693
-            }
694
-        } catch (EE_Error $e) {
695
-            $e->get_error();
696
-        }
697
-        // you have successfully run the gauntlet
698
-        return true;
699
-    }
700
-
701
-
702
-    /**
703
-     *    _generate_config_option_name
704
-     *
705
-     * @access        protected
706
-     * @param        string $section
707
-     * @param        string $name
708
-     * @return        string
709
-     */
710
-    private function _generate_config_option_name($section = '', $name = '')
711
-    {
712
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
713
-    }
714
-
715
-
716
-    /**
717
-     *    _set_config_class
718
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
719
-     *
720
-     * @access    private
721
-     * @param    string $config_class
722
-     * @param    string $name
723
-     * @return    string
724
-     */
725
-    private function _set_config_class($config_class = '', $name = '')
726
-    {
727
-        return ! empty($config_class)
728
-            ? $config_class
729
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
730
-    }
731
-
732
-
733
-    /**
734
-     *    set_config
735
-     *
736
-     * @access    protected
737
-     * @param    string         $section
738
-     * @param    string         $name
739
-     * @param    string         $config_class
740
-     * @param    EE_Config_Base $config_obj
741
-     * @return    EE_Config_Base
742
-     */
743
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
744
-    {
745
-        // ensure config class is set to something
746
-        $config_class = $this->_set_config_class($config_class, $name);
747
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
748
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
749
-            return null;
750
-        }
751
-        $config_option_name = $this->_generate_config_option_name($section, $name);
752
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
753
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
754
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
755
-            $this->update_addon_option_names();
756
-        }
757
-        // verify the incoming config object but suppress errors
758
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
759
-            $config_obj = new $config_class();
760
-        }
761
-        if (get_option($config_option_name)) {
762
-            EE_Config::log($config_option_name);
763
-            update_option($config_option_name, $config_obj);
764
-            $this->{$section}->{$name} = $config_obj;
765
-            return $this->{$section}->{$name};
766
-        } else {
767
-            // create a wp-option for this config
768
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
769
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
770
-                return $this->{$section}->{$name};
771
-            } else {
772
-                EE_Error::add_error(
773
-                    sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
774
-                    __FILE__,
775
-                    __FUNCTION__,
776
-                    __LINE__
777
-                );
778
-                return null;
779
-            }
780
-        }
781
-    }
782
-
783
-
784
-    /**
785
-     *    update_config
786
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
787
-     *
788
-     * @access    public
789
-     * @param    string                $section
790
-     * @param    string                $name
791
-     * @param    EE_Config_Base|string $config_obj
792
-     * @param    bool                  $throw_errors
793
-     * @return    bool
794
-     */
795
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
796
-    {
797
-        // don't allow config updates during WP heartbeats
798
-        /** @var RequestInterface $request */
799
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
800
-        if ($request->isWordPressHeartbeat()) {
801
-            return false;
802
-        }
803
-        $config_obj = maybe_unserialize($config_obj);
804
-        // get class name of the incoming object
805
-        $config_class = get_class($config_obj);
806
-        // run tests 1-5 and 9 to verify config
807
-        if (
808
-            ! $this->_verify_config_params(
809
-                $section,
810
-                $name,
811
-                $config_class,
812
-                $config_obj,
813
-                array(1, 2, 3, 4, 7, 9)
814
-            )
815
-        ) {
816
-            return false;
817
-        }
818
-        $config_option_name = $this->_generate_config_option_name($section, $name);
819
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
820
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
821
-            // save new config to db
822
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
823
-                return true;
824
-            }
825
-        } else {
826
-            // first check if the record already exists
827
-            $existing_config = get_option($config_option_name);
828
-            $config_obj = serialize($config_obj);
829
-            // just return if db record is already up to date (NOT type safe comparison)
830
-            if ($existing_config == $config_obj) {
831
-                $this->{$section}->{$name} = $config_obj;
832
-                return true;
833
-            } elseif (update_option($config_option_name, $config_obj)) {
834
-                EE_Config::log($config_option_name);
835
-                // update wp-option for this config class
836
-                $this->{$section}->{$name} = $config_obj;
837
-                return true;
838
-            } elseif ($throw_errors) {
839
-                EE_Error::add_error(
840
-                    sprintf(
841
-                        esc_html__(
842
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
843
-                            'event_espresso'
844
-                        ),
845
-                        $config_class,
846
-                        'EE_Config->' . $section . '->' . $name
847
-                    ),
848
-                    __FILE__,
849
-                    __FUNCTION__,
850
-                    __LINE__
851
-                );
852
-            }
853
-        }
854
-        return false;
855
-    }
856
-
857
-
858
-    /**
859
-     *    get_config
860
-     *
861
-     * @access    public
862
-     * @param    string $section
863
-     * @param    string $name
864
-     * @param    string $config_class
865
-     * @return    mixed EE_Config_Base | NULL
866
-     */
867
-    public function get_config($section = '', $name = '', $config_class = '')
868
-    {
869
-        // ensure config class is set to something
870
-        $config_class = $this->_set_config_class($config_class, $name);
871
-        // run tests 1-4, 6 and 7 to verify that all params have been set
872
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
873
-            return null;
874
-        }
875
-        // now test if the requested config object exists, but suppress errors
876
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
877
-            // config already exists, so pass it back
878
-            return $this->{$section}->{$name};
879
-        }
880
-        // load config option from db if it exists
881
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
882
-        // verify the newly retrieved config object, but suppress errors
883
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
884
-            // config is good, so set it and pass it back
885
-            $this->{$section}->{$name} = $config_obj;
886
-            return $this->{$section}->{$name};
887
-        }
888
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
889
-        $config_obj = $this->set_config($section, $name, $config_class);
890
-        // verify the newly created config object
891
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
892
-            return $this->{$section}->{$name};
893
-        } else {
894
-            EE_Error::add_error(
895
-                sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
896
-                __FILE__,
897
-                __FUNCTION__,
898
-                __LINE__
899
-            );
900
-        }
901
-        return null;
902
-    }
903
-
904
-
905
-    /**
906
-     *    get_config_option
907
-     *
908
-     * @access    public
909
-     * @param    string $config_option_name
910
-     * @return    mixed EE_Config_Base | FALSE
911
-     */
912
-    public function get_config_option($config_option_name = '')
913
-    {
914
-        // retrieve the wp-option for this config class.
915
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
916
-        if (empty($config_option)) {
917
-            EE_Config::log($config_option_name . '-NOT-FOUND');
918
-        }
919
-        return $config_option;
920
-    }
921
-
922
-
923
-    /**
924
-     * log
925
-     *
926
-     * @param string $config_option_name
927
-     */
928
-    public static function log($config_option_name = '')
929
-    {
930
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
931
-            $config_log = get_option(EE_Config::LOG_NAME, array());
932
-            /** @var RequestParams $request */
933
-            $request = LoaderFactory::getLoader()->getShared(RequestParams::class);
934
-            $config_log[ (string) microtime(true) ] = array(
935
-                'config_name' => $config_option_name,
936
-                'request'     => $request->requestParams(),
937
-            );
938
-            update_option(EE_Config::LOG_NAME, $config_log);
939
-        }
940
-    }
941
-
942
-
943
-    /**
944
-     * trim_log
945
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
946
-     */
947
-    public static function trim_log()
948
-    {
949
-        if (! EE_Config::logging_enabled()) {
950
-            return;
951
-        }
952
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
953
-        $log_length = count($config_log);
954
-        if ($log_length > EE_Config::LOG_LENGTH) {
955
-            ksort($config_log);
956
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
957
-            update_option(EE_Config::LOG_NAME, $config_log);
958
-        }
959
-    }
960
-
961
-
962
-    /**
963
-     *    get_page_for_posts
964
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
965
-     *    wp-option "page_for_posts", or "posts" if no page is selected
966
-     *
967
-     * @access    public
968
-     * @return    string
969
-     */
970
-    public static function get_page_for_posts()
971
-    {
972
-        $page_for_posts = get_option('page_for_posts');
973
-        if (! $page_for_posts) {
974
-            return 'posts';
975
-        }
976
-        global $wpdb;
977
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
978
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
979
-    }
980
-
981
-
982
-    /**
983
-     *    register_shortcodes_and_modules.
984
-     *    At this point, it's too early to tell if we're maintenance mode or not.
985
-     *    In fact, this is where we give modules a chance to let core know they exist
986
-     *    so they can help trigger maintenance mode if it's needed
987
-     *
988
-     * @access    public
989
-     * @return    void
990
-     */
991
-    public function register_shortcodes_and_modules()
992
-    {
993
-        // allow modules to set hooks for the rest of the system
994
-        EE_Registry::instance()->modules = $this->_register_modules();
995
-    }
996
-
997
-
998
-    /**
999
-     *    initialize_shortcodes_and_modules
1000
-     *    meaning they can start adding their hooks to get stuff done
1001
-     *
1002
-     * @access    public
1003
-     * @return    void
1004
-     */
1005
-    public function initialize_shortcodes_and_modules()
1006
-    {
1007
-        // allow modules to set hooks for the rest of the system
1008
-        $this->_initialize_modules();
1009
-    }
1010
-
1011
-
1012
-    /**
1013
-     *    widgets_init
1014
-     *
1015
-     * @access private
1016
-     * @return void
1017
-     */
1018
-    public function widgets_init()
1019
-    {
1020
-        // only init widgets on admin pages when not in complete maintenance, and
1021
-        // on frontend when not in any maintenance mode
1022
-        if (
1023
-            ! EE_Maintenance_Mode::instance()->level()
1024
-            || (
1025
-                is_admin()
1026
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1027
-            )
1028
-        ) {
1029
-            // grab list of installed widgets
1030
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1031
-            // filter list of modules to register
1032
-            $widgets_to_register = apply_filters(
1033
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1034
-                $widgets_to_register
1035
-            );
1036
-            if (! empty($widgets_to_register)) {
1037
-                // cycle thru widget folders
1038
-                foreach ($widgets_to_register as $widget_path) {
1039
-                    // add to list of installed widget modules
1040
-                    EE_Config::register_ee_widget($widget_path);
1041
-                }
1042
-            }
1043
-            // filter list of installed modules
1044
-            EE_Registry::instance()->widgets = apply_filters(
1045
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1046
-                EE_Registry::instance()->widgets
1047
-            );
1048
-        }
1049
-    }
1050
-
1051
-
1052
-    /**
1053
-     *    register_ee_widget - makes core aware of this widget
1054
-     *
1055
-     * @access    public
1056
-     * @param    string $widget_path - full path up to and including widget folder
1057
-     * @return    void
1058
-     */
1059
-    public static function register_ee_widget($widget_path = null)
1060
-    {
1061
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1062
-        $widget_ext = '.widget.php';
1063
-        // make all separators match
1064
-        $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1065
-        // does the file path INCLUDE the actual file name as part of the path ?
1066
-        if (strpos($widget_path, $widget_ext) !== false) {
1067
-            // grab and shortcode file name from directory name and break apart at dots
1068
-            $file_name = explode('.', basename($widget_path));
1069
-            // take first segment from file name pieces and remove class prefix if it exists
1070
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1071
-            // sanitize shortcode directory name
1072
-            $widget = sanitize_key($widget);
1073
-            // now we need to rebuild the shortcode path
1074
-            $widget_path = explode('/', $widget_path);
1075
-            // remove last segment
1076
-            array_pop($widget_path);
1077
-            // glue it back together
1078
-            $widget_path = implode(DS, $widget_path);
1079
-        } else {
1080
-            // grab and sanitize widget directory name
1081
-            $widget = sanitize_key(basename($widget_path));
1082
-        }
1083
-        // create classname from widget directory name
1084
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1085
-        // add class prefix
1086
-        $widget_class = 'EEW_' . $widget;
1087
-        // does the widget exist ?
1088
-        if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1089
-            $msg = sprintf(
1090
-                esc_html__(
1091
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1092
-                    'event_espresso'
1093
-                ),
1094
-                $widget_class,
1095
-                $widget_path . '/' . $widget_class . $widget_ext
1096
-            );
1097
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1098
-            return;
1099
-        }
1100
-        // load the widget class file
1101
-        require_once($widget_path . '/' . $widget_class . $widget_ext);
1102
-        // verify that class exists
1103
-        if (! class_exists($widget_class)) {
1104
-            $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1105
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1106
-            return;
1107
-        }
1108
-        register_widget($widget_class);
1109
-        // add to array of registered widgets
1110
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1111
-    }
1112
-
1113
-
1114
-    /**
1115
-     *        _register_modules
1116
-     *
1117
-     * @access private
1118
-     * @return array
1119
-     */
1120
-    private function _register_modules()
1121
-    {
1122
-        // grab list of installed modules
1123
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1124
-        // filter list of modules to register
1125
-        $modules_to_register = apply_filters(
1126
-            'FHEE__EE_Config__register_modules__modules_to_register',
1127
-            $modules_to_register
1128
-        );
1129
-        if (! empty($modules_to_register)) {
1130
-            // loop through folders
1131
-            foreach ($modules_to_register as $module_path) {
1132
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1133
-                if (
1134
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1135
-                    && $module_path !== EE_MODULES . 'gateways'
1136
-                ) {
1137
-                    // add to list of installed modules
1138
-                    EE_Config::register_module($module_path);
1139
-                }
1140
-            }
1141
-        }
1142
-        // filter list of installed modules
1143
-        return apply_filters(
1144
-            'FHEE__EE_Config___register_modules__installed_modules',
1145
-            EE_Registry::instance()->modules
1146
-        );
1147
-    }
1148
-
1149
-
1150
-    /**
1151
-     *    register_module - makes core aware of this module
1152
-     *
1153
-     * @access    public
1154
-     * @param    string $module_path - full path up to and including module folder
1155
-     * @return    bool
1156
-     */
1157
-    public static function register_module($module_path = null)
1158
-    {
1159
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1160
-        $module_ext = '.module.php';
1161
-        // make all separators match
1162
-        $module_path = str_replace(array('\\', '/'), '/', $module_path);
1163
-        // does the file path INCLUDE the actual file name as part of the path ?
1164
-        if (strpos($module_path, $module_ext) !== false) {
1165
-            // grab and shortcode file name from directory name and break apart at dots
1166
-            $module_file = explode('.', basename($module_path));
1167
-            // now we need to rebuild the shortcode path
1168
-            $module_path = explode('/', $module_path);
1169
-            // remove last segment
1170
-            array_pop($module_path);
1171
-            // glue it back together
1172
-            $module_path = implode('/', $module_path) . '/';
1173
-            // take first segment from file name pieces and sanitize it
1174
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1175
-            // ensure class prefix is added
1176
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1177
-        } else {
1178
-            // we need to generate the filename based off of the folder name
1179
-            // grab and sanitize module name
1180
-            $module = strtolower(basename($module_path));
1181
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1182
-            // like trailingslashit()
1183
-            $module_path = rtrim($module_path, '/') . '/';
1184
-            // create classname from module directory name
1185
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1186
-            // add class prefix
1187
-            $module_class = 'EED_' . $module;
1188
-        }
1189
-        // does the module exist ?
1190
-        if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1191
-            $msg = sprintf(
1192
-                esc_html__(
1193
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1194
-                    'event_espresso'
1195
-                ),
1196
-                $module
1197
-            );
1198
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1199
-            return false;
1200
-        }
1201
-        // load the module class file
1202
-        require_once($module_path . $module_class . $module_ext);
1203
-        // verify that class exists
1204
-        if (! class_exists($module_class)) {
1205
-            $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1206
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1207
-            return false;
1208
-        }
1209
-        // add to array of registered modules
1210
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1211
-        do_action(
1212
-            'AHEE__EE_Config__register_module__complete',
1213
-            $module_class,
1214
-            EE_Registry::instance()->modules->{$module_class}
1215
-        );
1216
-        return true;
1217
-    }
1218
-
1219
-
1220
-    /**
1221
-     *    _initialize_modules
1222
-     *    allow modules to set hooks for the rest of the system
1223
-     *
1224
-     * @access private
1225
-     * @return void
1226
-     */
1227
-    private function _initialize_modules()
1228
-    {
1229
-        // cycle thru shortcode folders
1230
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1231
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1232
-            // which set hooks ?
1233
-            if (is_admin()) {
1234
-                // fire immediately
1235
-                call_user_func(array($module_class, 'set_hooks_admin'));
1236
-            } else {
1237
-                // delay until other systems are online
1238
-                add_action(
1239
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1240
-                    array($module_class, 'set_hooks')
1241
-                );
1242
-            }
1243
-        }
1244
-    }
1245
-
1246
-
1247
-    /**
1248
-     *    register_route - adds module method routes to route_map
1249
-     *
1250
-     * @access    public
1251
-     * @param    string $route       - "pretty" public alias for module method
1252
-     * @param    string $module      - module name (classname without EED_ prefix)
1253
-     * @param    string $method_name - the actual module method to be routed to
1254
-     * @param    string $key         - url param key indicating a route is being called
1255
-     * @return    bool
1256
-     */
1257
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1258
-    {
1259
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1260
-        $module = str_replace('EED_', '', $module);
1261
-        $module_class = 'EED_' . $module;
1262
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1263
-            $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1264
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1265
-            return false;
1266
-        }
1267
-        if (empty($route)) {
1268
-            $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1269
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1270
-            return false;
1271
-        }
1272
-        if (! method_exists('EED_' . $module, $method_name)) {
1273
-            $msg = sprintf(
1274
-                esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1275
-                $route
1276
-            );
1277
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1278
-            return false;
1279
-        }
1280
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1281
-        return true;
1282
-    }
1283
-
1284
-
1285
-    /**
1286
-     *    get_route - get module method route
1287
-     *
1288
-     * @access    public
1289
-     * @param    string $route - "pretty" public alias for module method
1290
-     * @param    string $key   - url param key indicating a route is being called
1291
-     * @return    string
1292
-     */
1293
-    public static function get_route($route = null, $key = 'ee')
1294
-    {
1295
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1296
-        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1297
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1298
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1299
-        }
1300
-        return null;
1301
-    }
1302
-
1303
-
1304
-    /**
1305
-     *    get_routes - get ALL module method routes
1306
-     *
1307
-     * @access    public
1308
-     * @return    array
1309
-     */
1310
-    public static function get_routes()
1311
-    {
1312
-        return EE_Config::$_module_route_map;
1313
-    }
1314
-
1315
-
1316
-    /**
1317
-     *    register_forward - allows modules to forward request to another module for further processing
1318
-     *
1319
-     * @access    public
1320
-     * @param    string       $route   - "pretty" public alias for module method
1321
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1322
-     *                                 class, allows different forwards to be served based on status
1323
-     * @param    array|string $forward - function name or array( class, method )
1324
-     * @param    string       $key     - url param key indicating a route is being called
1325
-     * @return    bool
1326
-     */
1327
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1328
-    {
1329
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1330
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1331
-            $msg = sprintf(
1332
-                esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1333
-                $route
1334
-            );
1335
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1336
-            return false;
1337
-        }
1338
-        if (empty($forward)) {
1339
-            $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1340
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1341
-            return false;
1342
-        }
1343
-        if (is_array($forward)) {
1344
-            if (! isset($forward[1])) {
1345
-                $msg = sprintf(
1346
-                    esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1347
-                    $route
1348
-                );
1349
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1350
-                return false;
1351
-            }
1352
-            if (! method_exists($forward[0], $forward[1])) {
1353
-                $msg = sprintf(
1354
-                    esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1355
-                    $forward[1],
1356
-                    $route
1357
-                );
1358
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1359
-                return false;
1360
-            }
1361
-        } elseif (! function_exists($forward)) {
1362
-            $msg = sprintf(
1363
-                esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1364
-                $forward,
1365
-                $route
1366
-            );
1367
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1368
-            return false;
1369
-        }
1370
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1371
-        return true;
1372
-    }
1373
-
1374
-
1375
-    /**
1376
-     *    get_forward - get forwarding route
1377
-     *
1378
-     * @access    public
1379
-     * @param    string  $route  - "pretty" public alias for module method
1380
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1381
-     *                           allows different forwards to be served based on status
1382
-     * @param    string  $key    - url param key indicating a route is being called
1383
-     * @return    string
1384
-     */
1385
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1386
-    {
1387
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1388
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1389
-            return apply_filters(
1390
-                'FHEE__EE_Config__get_forward',
1391
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1392
-                $route,
1393
-                $status
1394
-            );
1395
-        }
1396
-        return null;
1397
-    }
1398
-
1399
-
1400
-    /**
1401
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1402
-     *    results
1403
-     *
1404
-     * @access    public
1405
-     * @param    string  $route  - "pretty" public alias for module method
1406
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1407
-     *                           allows different views to be served based on status
1408
-     * @param    string  $view
1409
-     * @param    string  $key    - url param key indicating a route is being called
1410
-     * @return    bool
1411
-     */
1412
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1413
-    {
1414
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1415
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1416
-            $msg = sprintf(
1417
-                esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1418
-                $route
1419
-            );
1420
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1421
-            return false;
1422
-        }
1423
-        if (! is_readable($view)) {
1424
-            $msg = sprintf(
1425
-                esc_html__(
1426
-                    'The %s view file could not be found or is not readable due to file permissions.',
1427
-                    'event_espresso'
1428
-                ),
1429
-                $view
1430
-            );
1431
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1432
-            return false;
1433
-        }
1434
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1435
-        return true;
1436
-    }
1437
-
1438
-
1439
-    /**
1440
-     *    get_view - get view for route and status
1441
-     *
1442
-     * @access    public
1443
-     * @param    string  $route  - "pretty" public alias for module method
1444
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1445
-     *                           allows different views to be served based on status
1446
-     * @param    string  $key    - url param key indicating a route is being called
1447
-     * @return    string
1448
-     */
1449
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1450
-    {
1451
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1452
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1453
-            return apply_filters(
1454
-                'FHEE__EE_Config__get_view',
1455
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1456
-                $route,
1457
-                $status
1458
-            );
1459
-        }
1460
-        return null;
1461
-    }
1462
-
1463
-
1464
-    public function update_addon_option_names()
1465
-    {
1466
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1467
-    }
1468
-
1469
-
1470
-    public function shutdown()
1471
-    {
1472
-        $this->update_addon_option_names();
1473
-    }
1474
-
1475
-
1476
-    /**
1477
-     * @return LegacyShortcodesManager
1478
-     */
1479
-    public static function getLegacyShortcodesManager()
1480
-    {
1481
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1482
-            EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1483
-                LegacyShortcodesManager::class
1484
-            );
1485
-        }
1486
-        return EE_Config::instance()->legacy_shortcodes_manager;
1487
-    }
1488
-
1489
-
1490
-    /**
1491
-     * register_shortcode - makes core aware of this shortcode
1492
-     *
1493
-     * @deprecated 4.9.26
1494
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1495
-     * @return    bool
1496
-     */
1497
-    public static function register_shortcode($shortcode_path = null)
1498
-    {
1499
-        EE_Error::doing_it_wrong(
1500
-            __METHOD__,
1501
-            esc_html__(
1502
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1503
-                'event_espresso'
1504
-            ),
1505
-            '4.9.26'
1506
-        );
1507
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1508
-    }
1509
-}
1510
-
1511
-/**
1512
- * Base class used for config classes. These classes should generally not have
1513
- * magic functions in use, except we'll allow them to magically set and get stuff...
1514
- * basically, they should just be well-defined stdClasses
1515
- */
1516
-class EE_Config_Base
1517
-{
1518
-    /**
1519
-     * Utility function for escaping the value of a property and returning.
1520
-     *
1521
-     * @param string $property property name (checks to see if exists).
1522
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1523
-     * @throws EE_Error
1524
-     */
1525
-    public function get_pretty($property)
1526
-    {
1527
-        if (! property_exists($this, $property)) {
1528
-            throw new EE_Error(
1529
-                sprintf(
1530
-                    esc_html__(
1531
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1532
-                        'event_espresso'
1533
-                    ),
1534
-                    get_class($this),
1535
-                    $property
1536
-                )
1537
-            );
1538
-        }
1539
-        // just handling escaping of strings for now.
1540
-        if (is_string($this->{$property})) {
1541
-            return stripslashes($this->{$property});
1542
-        }
1543
-        return $this->{$property};
1544
-    }
1545
-
1546
-
1547
-    public function populate()
1548
-    {
1549
-        // grab defaults via a new instance of this class.
1550
-        $class_name = get_class($this);
1551
-        $defaults = new $class_name();
1552
-        // loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1553
-        // default from our $defaults object.
1554
-        foreach (get_object_vars($defaults) as $property => $value) {
1555
-            if ($this->{$property} === null) {
1556
-                $this->{$property} = $value;
1557
-            }
1558
-        }
1559
-        // cleanup
1560
-        unset($defaults);
1561
-    }
1562
-
1563
-
1564
-    /**
1565
-     *        __isset
1566
-     *
1567
-     * @param $a
1568
-     * @return bool
1569
-     */
1570
-    public function __isset($a)
1571
-    {
1572
-        return false;
1573
-    }
1574
-
1575
-
1576
-    /**
1577
-     *        __unset
1578
-     *
1579
-     * @param $a
1580
-     * @return bool
1581
-     */
1582
-    public function __unset($a)
1583
-    {
1584
-        return false;
1585
-    }
1586
-
1587
-
1588
-    /**
1589
-     *        __clone
1590
-     */
1591
-    public function __clone()
1592
-    {
1593
-    }
1594
-
1595
-
1596
-    /**
1597
-     *        __wakeup
1598
-     */
1599
-    public function __wakeup()
1600
-    {
1601
-    }
1602
-
1603
-
1604
-    /**
1605
-     *        __destruct
1606
-     */
1607
-    public function __destruct()
1608
-    {
1609
-    }
1610
-}
1611
-
1612
-/**
1613
- * Class for defining what's in the EE_Config relating to registration settings
1614
- */
1615
-class EE_Core_Config extends EE_Config_Base
1616
-{
1617
-    const OPTION_NAME_UXIP = 'ee_ueip_optin';
1618
-
1619
-
1620
-    public $current_blog_id;
1621
-
1622
-    public $ee_ueip_optin;
1623
-
1624
-    public $ee_ueip_has_notified;
1625
-
1626
-    /**
1627
-     * Not to be confused with the 4 critical page variables (See
1628
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1629
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1630
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1631
-     *
1632
-     * @var array
1633
-     */
1634
-    public $post_shortcodes;
1635
-
1636
-    public $module_route_map;
1637
-
1638
-    public $module_forward_map;
1639
-
1640
-    public $module_view_map;
1641
-
1642
-    /**
1643
-     * The next 4 vars are the IDs of critical EE pages.
1644
-     *
1645
-     * @var int
1646
-     */
1647
-    public $reg_page_id;
1648
-
1649
-    public $txn_page_id;
1650
-
1651
-    public $thank_you_page_id;
1652
-
1653
-    public $cancel_page_id;
1654
-
1655
-    /**
1656
-     * The next 4 vars are the URLs of critical EE pages.
1657
-     *
1658
-     * @var int
1659
-     */
1660
-    public $reg_page_url;
1661
-
1662
-    public $txn_page_url;
1663
-
1664
-    public $thank_you_page_url;
1665
-
1666
-    public $cancel_page_url;
1667
-
1668
-    /**
1669
-     * The next vars relate to the custom slugs for EE CPT routes
1670
-     */
1671
-    public $event_cpt_slug;
1672
-
1673
-    /**
1674
-     * This caches the _ee_ueip_option in case this config is reset in the same
1675
-     * request across blog switches in a multisite context.
1676
-     * Avoids extra queries to the db for this option.
1677
-     *
1678
-     * @var bool
1679
-     */
1680
-    public static $ee_ueip_option;
1681
-
1682
-
1683
-    /**
1684
-     *    class constructor
1685
-     *
1686
-     * @access    public
1687
-     */
1688
-    public function __construct()
1689
-    {
1690
-        // set default organization settings
1691
-        $this->current_blog_id = get_current_blog_id();
1692
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1693
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1694
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1695
-        $this->post_shortcodes = array();
1696
-        $this->module_route_map = array();
1697
-        $this->module_forward_map = array();
1698
-        $this->module_view_map = array();
1699
-        // critical EE page IDs
1700
-        $this->reg_page_id = 0;
1701
-        $this->txn_page_id = 0;
1702
-        $this->thank_you_page_id = 0;
1703
-        $this->cancel_page_id = 0;
1704
-        // critical EE page URLs
1705
-        $this->reg_page_url = '';
1706
-        $this->txn_page_url = '';
1707
-        $this->thank_you_page_url = '';
1708
-        $this->cancel_page_url = '';
1709
-        // cpt slugs
1710
-        $this->event_cpt_slug = esc_html__('events', 'event_espresso');
1711
-        // ueip constant check
1712
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1713
-            $this->ee_ueip_optin = false;
1714
-            $this->ee_ueip_has_notified = true;
1715
-        }
1716
-    }
1717
-
1718
-
1719
-    /**
1720
-     * @return array
1721
-     */
1722
-    public function get_critical_pages_array()
1723
-    {
1724
-        return array(
1725
-            $this->reg_page_id,
1726
-            $this->txn_page_id,
1727
-            $this->thank_you_page_id,
1728
-            $this->cancel_page_id,
1729
-        );
1730
-    }
1731
-
1732
-
1733
-    /**
1734
-     * @return array
1735
-     */
1736
-    public function get_critical_pages_shortcodes_array()
1737
-    {
1738
-        return array(
1739
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1740
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1741
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1742
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1743
-        );
1744
-    }
1745
-
1746
-
1747
-    /**
1748
-     *  gets/returns URL for EE reg_page
1749
-     *
1750
-     * @access    public
1751
-     * @return    string
1752
-     */
1753
-    public function reg_page_url()
1754
-    {
1755
-        if (! $this->reg_page_url) {
1756
-            $this->reg_page_url = add_query_arg(
1757
-                array('uts' => time()),
1758
-                get_permalink($this->reg_page_id)
1759
-            ) . '#checkout';
1760
-        }
1761
-        return $this->reg_page_url;
1762
-    }
1763
-
1764
-
1765
-    /**
1766
-     *  gets/returns URL for EE txn_page
1767
-     *
1768
-     * @param array $query_args like what gets passed to
1769
-     *                          add_query_arg() as the first argument
1770
-     * @access    public
1771
-     * @return    string
1772
-     */
1773
-    public function txn_page_url($query_args = array())
1774
-    {
1775
-        if (! $this->txn_page_url) {
1776
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1777
-        }
1778
-        if ($query_args) {
1779
-            return add_query_arg($query_args, $this->txn_page_url);
1780
-        } else {
1781
-            return $this->txn_page_url;
1782
-        }
1783
-    }
1784
-
1785
-
1786
-    /**
1787
-     *  gets/returns URL for EE thank_you_page
1788
-     *
1789
-     * @param array $query_args like what gets passed to
1790
-     *                          add_query_arg() as the first argument
1791
-     * @access    public
1792
-     * @return    string
1793
-     */
1794
-    public function thank_you_page_url($query_args = array())
1795
-    {
1796
-        if (! $this->thank_you_page_url) {
1797
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1798
-        }
1799
-        if ($query_args) {
1800
-            return add_query_arg($query_args, $this->thank_you_page_url);
1801
-        } else {
1802
-            return $this->thank_you_page_url;
1803
-        }
1804
-    }
1805
-
1806
-
1807
-    /**
1808
-     *  gets/returns URL for EE cancel_page
1809
-     *
1810
-     * @access    public
1811
-     * @return    string
1812
-     */
1813
-    public function cancel_page_url()
1814
-    {
1815
-        if (! $this->cancel_page_url) {
1816
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1817
-        }
1818
-        return $this->cancel_page_url;
1819
-    }
1820
-
1821
-
1822
-    /**
1823
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1824
-     *
1825
-     * @since 4.7.5
1826
-     */
1827
-    protected function _reset_urls()
1828
-    {
1829
-        $this->reg_page_url = '';
1830
-        $this->txn_page_url = '';
1831
-        $this->cancel_page_url = '';
1832
-        $this->thank_you_page_url = '';
1833
-    }
1834
-
1835
-
1836
-    /**
1837
-     * Used to return what the optin value is set for the EE User Experience Program.
1838
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1839
-     * on the main site only.
1840
-     *
1841
-     * @return bool
1842
-     */
1843
-    protected function _get_main_ee_ueip_optin()
1844
-    {
1845
-        // if this is the main site then we can just bypass our direct query.
1846
-        if (is_main_site()) {
1847
-            return get_option(self::OPTION_NAME_UXIP, false);
1848
-        }
1849
-        // is this already cached for this request?  If so use it.
1850
-        if (EE_Core_Config::$ee_ueip_option !== null) {
1851
-            return EE_Core_Config::$ee_ueip_option;
1852
-        }
1853
-        global $wpdb;
1854
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1855
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1856
-        $option = self::OPTION_NAME_UXIP;
1857
-        // set correct table for query
1858
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1859
-        // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1860
-        // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1861
-        // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1862
-        // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1863
-        // for the purpose of caching.
1864
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1865
-        if (false !== $pre) {
1866
-            EE_Core_Config::$ee_ueip_option = $pre;
1867
-            return EE_Core_Config::$ee_ueip_option;
1868
-        }
1869
-        $row = $wpdb->get_row(
1870
-            $wpdb->prepare(
1871
-                "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1872
-                $option
1873
-            )
1874
-        );
1875
-        if (is_object($row)) {
1876
-            $value = $row->option_value;
1877
-        } else { // option does not exist so use default.
1878
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1879
-            return EE_Core_Config::$ee_ueip_option;
1880
-        }
1881
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1882
-        return EE_Core_Config::$ee_ueip_option;
1883
-    }
1884
-
1885
-
1886
-    /**
1887
-     * Utility function for escaping the value of a property and returning.
1888
-     *
1889
-     * @param string $property property name (checks to see if exists).
1890
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1891
-     * @throws EE_Error
1892
-     */
1893
-    public function get_pretty($property)
1894
-    {
1895
-        if ($property === self::OPTION_NAME_UXIP) {
1896
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1897
-        }
1898
-        return parent::get_pretty($property);
1899
-    }
1900
-
1901
-
1902
-    /**
1903
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1904
-     * on the object.
1905
-     *
1906
-     * @return array
1907
-     */
1908
-    public function __sleep()
1909
-    {
1910
-        // reset all url properties
1911
-        $this->_reset_urls();
1912
-        // return what to save to db
1913
-        return array_keys(get_object_vars($this));
1914
-    }
1915
-}
1916
-
1917
-/**
1918
- * Config class for storing info on the Organization
1919
- */
1920
-class EE_Organization_Config extends EE_Config_Base
1921
-{
1922
-    /**
1923
-     * @var string $name
1924
-     * eg EE4.1
1925
-     */
1926
-    public $name;
1927
-
1928
-    /**
1929
-     * @var string $address_1
1930
-     * eg 123 Onna Road
1931
-     */
1932
-    public $address_1 = '';
1933
-
1934
-    /**
1935
-     * @var string $address_2
1936
-     * eg PO Box 123
1937
-     */
1938
-    public $address_2 = '';
1939
-
1940
-    /**
1941
-     * @var string $city
1942
-     * eg Inna City
1943
-     */
1944
-    public $city = '';
1945
-
1946
-    /**
1947
-     * @var int $STA_ID
1948
-     * eg 4
1949
-     */
1950
-    public $STA_ID = 0;
1951
-
1952
-    /**
1953
-     * @var string $CNT_ISO
1954
-     * eg US
1955
-     */
1956
-    public $CNT_ISO = '';
1957
-
1958
-    /**
1959
-     * @var string $zip
1960
-     * eg 12345  or V1A 2B3
1961
-     */
1962
-    public $zip = '';
1963
-
1964
-    /**
1965
-     * @var string $email
1966
-     * eg [email protected]
1967
-     */
1968
-    public $email;
1969
-
1970
-    /**
1971
-     * @var string $phone
1972
-     * eg. 111-111-1111
1973
-     */
1974
-    public $phone = '';
1975
-
1976
-    /**
1977
-     * @var string $vat
1978
-     * VAT/Tax Number
1979
-     */
1980
-    public $vat = '';
1981
-
1982
-    /**
1983
-     * @var string $logo_url
1984
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1985
-     */
1986
-    public $logo_url = '';
1987
-
1988
-    /**
1989
-     * The below are all various properties for holding links to organization social network profiles
1990
-     *
1991
-     * @var string
1992
-     */
1993
-    /**
1994
-     * facebook (facebook.com/profile.name)
1995
-     *
1996
-     * @var string
1997
-     */
1998
-    public $facebook = '';
1999
-
2000
-    /**
2001
-     * twitter (twitter.com/twitter_handle)
2002
-     *
2003
-     * @var string
2004
-     */
2005
-    public $twitter = '';
2006
-
2007
-    /**
2008
-     * linkedin (linkedin.com/in/profile_name)
2009
-     *
2010
-     * @var string
2011
-     */
2012
-    public $linkedin = '';
2013
-
2014
-    /**
2015
-     * pinterest (www.pinterest.com/profile_name)
2016
-     *
2017
-     * @var string
2018
-     */
2019
-    public $pinterest = '';
2020
-
2021
-    /**
2022
-     * google+ (google.com/+profileName)
2023
-     *
2024
-     * @var string
2025
-     */
2026
-    public $google = '';
2027
-
2028
-    /**
2029
-     * instagram (instagram.com/handle)
2030
-     *
2031
-     * @var string
2032
-     */
2033
-    public $instagram = '';
2034
-
2035
-
2036
-    /**
2037
-     *    class constructor
2038
-     *
2039
-     * @access    public
2040
-     */
2041
-    public function __construct()
2042
-    {
2043
-        // set default organization settings
2044
-        // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2045
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2046
-        $this->email = get_bloginfo('admin_email');
2047
-    }
2048
-}
2049
-
2050
-/**
2051
- * Class for defining what's in the EE_Config relating to currency
2052
- */
2053
-class EE_Currency_Config extends EE_Config_Base
2054
-{
2055
-    /**
2056
-     * @var string $code
2057
-     * eg 'US'
2058
-     */
2059
-    public $code;
2060
-
2061
-    /**
2062
-     * @var string $name
2063
-     * eg 'Dollar'
2064
-     */
2065
-    public $name;
2066
-
2067
-    /**
2068
-     * plural name
2069
-     *
2070
-     * @var string $plural
2071
-     * eg 'Dollars'
2072
-     */
2073
-    public $plural;
2074
-
2075
-    /**
2076
-     * currency sign
2077
-     *
2078
-     * @var string $sign
2079
-     * eg '$'
2080
-     */
2081
-    public $sign;
2082
-
2083
-    /**
2084
-     * Whether the currency sign should come before the number or not
2085
-     *
2086
-     * @var boolean $sign_b4
2087
-     */
2088
-    public $sign_b4;
2089
-
2090
-    /**
2091
-     * How many digits should come after the decimal place
2092
-     *
2093
-     * @var int $dec_plc
2094
-     */
2095
-    public $dec_plc;
2096
-
2097
-    /**
2098
-     * Symbol to use for decimal mark
2099
-     *
2100
-     * @var string $dec_mrk
2101
-     * eg '.'
2102
-     */
2103
-    public $dec_mrk;
2104
-
2105
-    /**
2106
-     * Symbol to use for thousands
2107
-     *
2108
-     * @var string $thsnds
2109
-     * eg ','
2110
-     */
2111
-    public $thsnds;
2112
-
2113
-
2114
-    /**
2115
-     *    class constructor
2116
-     *
2117
-     * @access    public
2118
-     * @param string $CNT_ISO
2119
-     * @throws EE_Error
2120
-     * @throws ReflectionException
2121
-     */
2122
-    public function __construct($CNT_ISO = '')
2123
-    {
2124
-        /** @var TableAnalysis $table_analysis */
2125
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2126
-        // get country code from organization settings or use default
2127
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2128
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2129
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2130
-            : '';
2131
-        // but override if requested
2132
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2133
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2134
-        if (
2135
-            ! empty($CNT_ISO)
2136
-            && EE_Maintenance_Mode::instance()->models_can_query()
2137
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2138
-        ) {
2139
-            // retrieve the country settings from the db, just in case they have been customized
2140
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2141
-            if ($country instanceof EE_Country) {
2142
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2143
-                $this->name = $country->currency_name_single();    // Dollar
2144
-                $this->plural = $country->currency_name_plural();    // Dollars
2145
-                $this->sign = $country->currency_sign();            // currency sign: $
2146
-                $this->sign_b4 = $country->currency_sign_before(
2147
-                );        // currency sign before or after: $TRUE  or  FALSE$
2148
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2149
-                $this->dec_mrk = $country->currency_decimal_mark(
2150
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2151
-                $this->thsnds = $country->currency_thousands_separator(
2152
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2153
-            }
2154
-        }
2155
-        // fallback to hardcoded defaults, in case the above failed
2156
-        if (empty($this->code)) {
2157
-            // set default currency settings
2158
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2159
-            $this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2160
-            $this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2161
-            $this->sign = '$';    // currency sign: $
2162
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2163
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2164
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2165
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2166
-        }
2167
-    }
2168
-}
2169
-
2170
-/**
2171
- * Class for defining what's in the EE_Config relating to registration settings
2172
- */
2173
-class EE_Registration_Config extends EE_Config_Base
2174
-{
2175
-    /**
2176
-     * Default registration status
2177
-     *
2178
-     * @var string $default_STS_ID
2179
-     * eg 'RPP'
2180
-     */
2181
-    public $default_STS_ID;
2182
-
2183
-    /**
2184
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2185
-     * registrations)
2186
-     *
2187
-     * @var int
2188
-     */
2189
-    public $default_maximum_number_of_tickets;
2190
-
2191
-    /**
2192
-     * level of validation to apply to email addresses
2193
-     *
2194
-     * @var string $email_validation_level
2195
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2196
-     */
2197
-    public $email_validation_level;
2198
-
2199
-    /**
2200
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2201
-     *
2202
-     * @var boolean $show_pending_payment_options
2203
-     */
2204
-    public $show_pending_payment_options;
2205
-
2206
-    /**
2207
-     * Whether to skip the registration confirmation page
2208
-     *
2209
-     * @var boolean $skip_reg_confirmation
2210
-     */
2211
-    public $skip_reg_confirmation;
2212
-
2213
-    /**
2214
-     * an array of SPCO reg steps where:
2215
-     *        the keys denotes the reg step order
2216
-     *        each element consists of an array with the following elements:
2217
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2218
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2219
-     *            "slug" => the URL param used to trigger the reg step
2220
-     *
2221
-     * @var array $reg_steps
2222
-     */
2223
-    public $reg_steps;
2224
-
2225
-    /**
2226
-     * Whether registration confirmation should be the last page of SPCO
2227
-     *
2228
-     * @var boolean $reg_confirmation_last
2229
-     */
2230
-    public $reg_confirmation_last;
2231
-
2232
-    /**
2233
-     * Whether or not to enable the EE Bot Trap
2234
-     *
2235
-     * @var boolean $use_bot_trap
2236
-     */
2237
-    public $use_bot_trap;
2238
-
2239
-    /**
2240
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2241
-     *
2242
-     * @var boolean $use_encryption
2243
-     */
2244
-    public $use_encryption;
2245
-
2246
-    /**
2247
-     * Whether or not to use ReCaptcha
2248
-     *
2249
-     * @var boolean $use_captcha
2250
-     */
2251
-    public $use_captcha;
2252
-
2253
-    /**
2254
-     * ReCaptcha Theme
2255
-     *
2256
-     * @var string $recaptcha_theme
2257
-     *    options: 'dark', 'light', 'invisible'
2258
-     */
2259
-    public $recaptcha_theme;
2260
-
2261
-    /**
2262
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2263
-     *
2264
-     * @var string $recaptcha_badge
2265
-     *    options: 'bottomright', 'bottomleft', 'inline'
2266
-     */
2267
-    public $recaptcha_badge;
2268
-
2269
-    /**
2270
-     * ReCaptcha Type
2271
-     *
2272
-     * @var string $recaptcha_type
2273
-     *    options: 'audio', 'image'
2274
-     */
2275
-    public $recaptcha_type;
2276
-
2277
-    /**
2278
-     * ReCaptcha language
2279
-     *
2280
-     * @var string $recaptcha_language
2281
-     * eg 'en'
2282
-     */
2283
-    public $recaptcha_language;
2284
-
2285
-    /**
2286
-     * ReCaptcha public key
2287
-     *
2288
-     * @var string $recaptcha_publickey
2289
-     */
2290
-    public $recaptcha_publickey;
2291
-
2292
-    /**
2293
-     * ReCaptcha private key
2294
-     *
2295
-     * @var string $recaptcha_privatekey
2296
-     */
2297
-    public $recaptcha_privatekey;
2298
-
2299
-    /**
2300
-     * array of form names protected by ReCaptcha
2301
-     *
2302
-     * @var array $recaptcha_protected_forms
2303
-     */
2304
-    public $recaptcha_protected_forms;
21
+	const OPTION_NAME = 'ee_config';
22
+
23
+	const LOG_NAME = 'ee_config_log';
24
+
25
+	const LOG_LENGTH = 100;
26
+
27
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
28
+
29
+	/**
30
+	 *    instance of the EE_Config object
31
+	 *
32
+	 * @var    EE_Config $_instance
33
+	 * @access    private
34
+	 */
35
+	private static $_instance;
36
+
37
+	/**
38
+	 * @var boolean $_logging_enabled
39
+	 */
40
+	private static $_logging_enabled = false;
41
+
42
+	/**
43
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
+	 */
45
+	private $legacy_shortcodes_manager;
46
+
47
+	/**
48
+	 * An StdClass whose property names are addon slugs,
49
+	 * and values are their config classes
50
+	 *
51
+	 * @var StdClass
52
+	 */
53
+	public $addons;
54
+
55
+	/**
56
+	 * @var EE_Admin_Config
57
+	 */
58
+	public $admin;
59
+
60
+	/**
61
+	 * @var EE_Core_Config
62
+	 */
63
+	public $core;
64
+
65
+	/**
66
+	 * @var EE_Currency_Config
67
+	 */
68
+	public $currency;
69
+
70
+	/**
71
+	 * @var EE_Organization_Config
72
+	 */
73
+	public $organization;
74
+
75
+	/**
76
+	 * @var EE_Registration_Config
77
+	 */
78
+	public $registration;
79
+
80
+	/**
81
+	 * @var EE_Template_Config
82
+	 */
83
+	public $template_settings;
84
+
85
+	/**
86
+	 * Holds EE environment values.
87
+	 *
88
+	 * @var EE_Environment_Config
89
+	 */
90
+	public $environment;
91
+
92
+	/**
93
+	 * settings pertaining to Google maps
94
+	 *
95
+	 * @var EE_Map_Config
96
+	 */
97
+	public $map_settings;
98
+
99
+	/**
100
+	 * settings pertaining to Taxes
101
+	 *
102
+	 * @var EE_Tax_Config
103
+	 */
104
+	public $tax_settings;
105
+
106
+	/**
107
+	 * Settings pertaining to global messages settings.
108
+	 *
109
+	 * @var EE_Messages_Config
110
+	 */
111
+	public $messages;
112
+
113
+	/**
114
+	 * @deprecated
115
+	 * @var EE_Gateway_Config
116
+	 */
117
+	public $gateway;
118
+
119
+	/**
120
+	 * @var    array $_addon_option_names
121
+	 * @access    private
122
+	 */
123
+	private $_addon_option_names = array();
124
+
125
+	/**
126
+	 * @var    array $_module_route_map
127
+	 * @access    private
128
+	 */
129
+	private static $_module_route_map = array();
130
+
131
+	/**
132
+	 * @var    array $_module_forward_map
133
+	 * @access    private
134
+	 */
135
+	private static $_module_forward_map = array();
136
+
137
+	/**
138
+	 * @var    array $_module_view_map
139
+	 * @access    private
140
+	 */
141
+	private static $_module_view_map = array();
142
+
143
+
144
+	/**
145
+	 * @singleton method used to instantiate class object
146
+	 * @access    public
147
+	 * @return EE_Config instance
148
+	 */
149
+	public static function instance()
150
+	{
151
+		// check if class object is instantiated, and instantiated properly
152
+		if (! self::$_instance instanceof EE_Config) {
153
+			self::$_instance = new self();
154
+		}
155
+		return self::$_instance;
156
+	}
157
+
158
+
159
+	/**
160
+	 * Resets the config
161
+	 *
162
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
163
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
164
+	 *                               reflect its state in the database
165
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
166
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
167
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
168
+	 *                               site was put into maintenance mode)
169
+	 * @return EE_Config
170
+	 */
171
+	public static function reset($hard_reset = false, $reinstantiate = true)
172
+	{
173
+		if (self::$_instance instanceof EE_Config) {
174
+			if ($hard_reset) {
175
+				self::$_instance->legacy_shortcodes_manager = null;
176
+				self::$_instance->_addon_option_names = array();
177
+				self::$_instance->_initialize_config();
178
+				self::$_instance->update_espresso_config();
179
+			}
180
+			self::$_instance->update_addon_option_names();
181
+		}
182
+		self::$_instance = null;
183
+		// we don't need to reset the static properties imo because those should
184
+		// only change when a module is added or removed. Currently we don't
185
+		// support removing a module during a request when it previously existed
186
+		if ($reinstantiate) {
187
+			return self::instance();
188
+		} else {
189
+			return null;
190
+		}
191
+	}
192
+
193
+
194
+	/**
195
+	 *    class constructor
196
+	 *
197
+	 * @access    private
198
+	 */
199
+	private function __construct()
200
+	{
201
+		do_action('AHEE__EE_Config__construct__begin', $this);
202
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
203
+		// setup empty config classes
204
+		$this->_initialize_config();
205
+		// load existing EE site settings
206
+		$this->_load_core_config();
207
+		// confirm everything loaded correctly and set filtered defaults if not
208
+		$this->_verify_config();
209
+		//  register shortcodes and modules
210
+		add_action(
211
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
212
+			array($this, 'register_shortcodes_and_modules'),
213
+			999
214
+		);
215
+		//  initialize shortcodes and modules
216
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
217
+		// register widgets
218
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
219
+		// shutdown
220
+		add_action('shutdown', array($this, 'shutdown'), 10);
221
+		// construct__end hook
222
+		do_action('AHEE__EE_Config__construct__end', $this);
223
+		// hardcoded hack
224
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
225
+	}
226
+
227
+
228
+	/**
229
+	 * @return boolean
230
+	 */
231
+	public static function logging_enabled()
232
+	{
233
+		return self::$_logging_enabled;
234
+	}
235
+
236
+
237
+	/**
238
+	 * use to get the current theme if needed from static context
239
+	 *
240
+	 * @return string current theme set.
241
+	 */
242
+	public static function get_current_theme()
243
+	{
244
+		return isset(self::$_instance->template_settings->current_espresso_theme)
245
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
246
+	}
247
+
248
+
249
+	/**
250
+	 *        _initialize_config
251
+	 *
252
+	 * @access private
253
+	 * @return void
254
+	 */
255
+	private function _initialize_config()
256
+	{
257
+		EE_Config::trim_log();
258
+		// set defaults
259
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
260
+		$this->addons = new stdClass();
261
+		// set _module_route_map
262
+		EE_Config::$_module_route_map = array();
263
+		// set _module_forward_map
264
+		EE_Config::$_module_forward_map = array();
265
+		// set _module_view_map
266
+		EE_Config::$_module_view_map = array();
267
+	}
268
+
269
+
270
+	/**
271
+	 *        load core plugin configuration
272
+	 *
273
+	 * @access private
274
+	 * @return void
275
+	 */
276
+	private function _load_core_config()
277
+	{
278
+		// load_core_config__start hook
279
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
280
+		$espresso_config = $this->get_espresso_config();
281
+		foreach ($espresso_config as $config => $settings) {
282
+			// load_core_config__start hook
283
+			$settings = apply_filters(
284
+				'FHEE__EE_Config___load_core_config__config_settings',
285
+				$settings,
286
+				$config,
287
+				$this
288
+			);
289
+			if (is_object($settings) && property_exists($this, $config)) {
290
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
291
+				// call configs populate method to ensure any defaults are set for empty values.
292
+				if (method_exists($settings, 'populate')) {
293
+					$this->{$config}->populate();
294
+				}
295
+				if (method_exists($settings, 'do_hooks')) {
296
+					$this->{$config}->do_hooks();
297
+				}
298
+			}
299
+		}
300
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
301
+			$this->update_espresso_config();
302
+		}
303
+		// load_core_config__end hook
304
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
305
+	}
306
+
307
+
308
+	/**
309
+	 *    _verify_config
310
+	 *
311
+	 * @access    protected
312
+	 * @return    void
313
+	 */
314
+	protected function _verify_config()
315
+	{
316
+		$this->core = $this->core instanceof EE_Core_Config
317
+			? $this->core
318
+			: new EE_Core_Config();
319
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
320
+		$this->organization = $this->organization instanceof EE_Organization_Config
321
+			? $this->organization
322
+			: new EE_Organization_Config();
323
+		$this->organization = apply_filters(
324
+			'FHEE__EE_Config___initialize_config__organization',
325
+			$this->organization
326
+		);
327
+		$this->currency = $this->currency instanceof EE_Currency_Config
328
+			? $this->currency
329
+			: new EE_Currency_Config();
330
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
331
+		$this->registration = $this->registration instanceof EE_Registration_Config
332
+			? $this->registration
333
+			: new EE_Registration_Config();
334
+		$this->registration = apply_filters(
335
+			'FHEE__EE_Config___initialize_config__registration',
336
+			$this->registration
337
+		);
338
+		$this->admin = $this->admin instanceof EE_Admin_Config
339
+			? $this->admin
340
+			: new EE_Admin_Config();
341
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
342
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
343
+			? $this->template_settings
344
+			: new EE_Template_Config();
345
+		$this->template_settings = apply_filters(
346
+			'FHEE__EE_Config___initialize_config__template_settings',
347
+			$this->template_settings
348
+		);
349
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
350
+			? $this->map_settings
351
+			: new EE_Map_Config();
352
+		$this->map_settings = apply_filters(
353
+			'FHEE__EE_Config___initialize_config__map_settings',
354
+			$this->map_settings
355
+		);
356
+		$this->environment = $this->environment instanceof EE_Environment_Config
357
+			? $this->environment
358
+			: new EE_Environment_Config();
359
+		$this->environment = apply_filters(
360
+			'FHEE__EE_Config___initialize_config__environment',
361
+			$this->environment
362
+		);
363
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
364
+			? $this->tax_settings
365
+			: new EE_Tax_Config();
366
+		$this->tax_settings = apply_filters(
367
+			'FHEE__EE_Config___initialize_config__tax_settings',
368
+			$this->tax_settings
369
+		);
370
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
371
+		$this->messages = $this->messages instanceof EE_Messages_Config
372
+			? $this->messages
373
+			: new EE_Messages_Config();
374
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
375
+			? $this->gateway
376
+			: new EE_Gateway_Config();
377
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
378
+		$this->legacy_shortcodes_manager = null;
379
+	}
380
+
381
+
382
+	/**
383
+	 *    get_espresso_config
384
+	 *
385
+	 * @access    public
386
+	 * @return    array of espresso config stuff
387
+	 */
388
+	public function get_espresso_config()
389
+	{
390
+		// grab espresso configuration
391
+		return apply_filters(
392
+			'FHEE__EE_Config__get_espresso_config__CFG',
393
+			get_option(EE_Config::OPTION_NAME, array())
394
+		);
395
+	}
396
+
397
+
398
+	/**
399
+	 *    double_check_config_comparison
400
+	 *
401
+	 * @access    public
402
+	 * @param string $option
403
+	 * @param        $old_value
404
+	 * @param        $value
405
+	 */
406
+	public function double_check_config_comparison($option, $old_value, $value)
407
+	{
408
+		// make sure we're checking the ee config
409
+		if ($option === EE_Config::OPTION_NAME) {
410
+			// run a loose comparison of the old value against the new value for type and properties,
411
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
412
+			if ($value != $old_value) {
413
+				// if they are NOT the same, then remove the hook,
414
+				// which means the subsequent update results will be based solely on the update query results
415
+				// the reason we do this is because, as stated above,
416
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
417
+				// this happens PRIOR to serialization and any subsequent update.
418
+				// If values are found to match their previous old value,
419
+				// then WP bails before performing any update.
420
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
421
+				// it just pulled from the db, with the one being passed to it (which will not match).
422
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
423
+				// MySQL MAY ALSO NOT perform the update because
424
+				// the string it sees in the db looks the same as the new one it has been passed!!!
425
+				// This results in the query returning an "affected rows" value of ZERO,
426
+				// which gets returned immediately by WP update_option and looks like an error.
427
+				remove_action('update_option', array($this, 'check_config_updated'));
428
+			}
429
+		}
430
+	}
431
+
432
+
433
+	/**
434
+	 *    update_espresso_config
435
+	 *
436
+	 * @access   public
437
+	 */
438
+	protected function _reset_espresso_addon_config()
439
+	{
440
+		$this->_addon_option_names = array();
441
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
442
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
443
+			if ($addon_config_obj instanceof EE_Config_Base) {
444
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
445
+			}
446
+			$this->addons->{$addon_name} = null;
447
+		}
448
+	}
449
+
450
+
451
+	/**
452
+	 *    update_espresso_config
453
+	 *
454
+	 * @access   public
455
+	 * @param   bool $add_success
456
+	 * @param   bool $add_error
457
+	 * @return   bool
458
+	 */
459
+	public function update_espresso_config($add_success = false, $add_error = true)
460
+	{
461
+		// don't allow config updates during WP heartbeats
462
+		/** @var RequestInterface $request */
463
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
464
+		if ($request->isWordPressHeartbeat()) {
465
+			return false;
466
+		}
467
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
468
+		// $clone = clone( self::$_instance );
469
+		// self::$_instance = NULL;
470
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
471
+		$this->_reset_espresso_addon_config();
472
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
473
+		// but BEFORE the actual update occurs
474
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
475
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
476
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
477
+		$this->legacy_shortcodes_manager = null;
478
+		// now update "ee_config"
479
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
480
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
481
+		EE_Config::log(EE_Config::OPTION_NAME);
482
+		// if not saved... check if the hook we just added still exists;
483
+		// if it does, it means one of two things:
484
+		// that update_option bailed at the($value === $old_value) conditional,
485
+		// or...
486
+		// the db update query returned 0 rows affected
487
+		// (probably because the data  value was the same from it's perspective)
488
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
489
+		// but just means no update occurred, so don't display an error to the user.
490
+		// BUT... if update_option returns FALSE, AND the hook is missing,
491
+		// then it means that something truly went wrong
492
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
493
+		// remove our action since we don't want it in the system anymore
494
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
495
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
496
+		// self::$_instance = $clone;
497
+		// unset( $clone );
498
+		// if config remains the same or was updated successfully
499
+		if ($saved) {
500
+			if ($add_success) {
501
+				EE_Error::add_success(
502
+					esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
503
+					__FILE__,
504
+					__FUNCTION__,
505
+					__LINE__
506
+				);
507
+			}
508
+			return true;
509
+		} else {
510
+			if ($add_error) {
511
+				EE_Error::add_error(
512
+					esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
513
+					__FILE__,
514
+					__FUNCTION__,
515
+					__LINE__
516
+				);
517
+			}
518
+			return false;
519
+		}
520
+	}
521
+
522
+
523
+	/**
524
+	 *    _verify_config_params
525
+	 *
526
+	 * @access    private
527
+	 * @param    string         $section
528
+	 * @param    string         $name
529
+	 * @param    string         $config_class
530
+	 * @param    EE_Config_Base $config_obj
531
+	 * @param    array          $tests_to_run
532
+	 * @param    bool           $display_errors
533
+	 * @return    bool    TRUE on success, FALSE on fail
534
+	 */
535
+	private function _verify_config_params(
536
+		$section = '',
537
+		$name = '',
538
+		$config_class = '',
539
+		$config_obj = null,
540
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
541
+		$display_errors = true
542
+	) {
543
+		try {
544
+			foreach ($tests_to_run as $test) {
545
+				switch ($test) {
546
+					// TEST #1 : check that section was set
547
+					case 1:
548
+						if (empty($section)) {
549
+							if ($display_errors) {
550
+								throw new EE_Error(
551
+									sprintf(
552
+										esc_html__(
553
+											'No configuration section has been provided while attempting to save "%s".',
554
+											'event_espresso'
555
+										),
556
+										$config_class
557
+									)
558
+								);
559
+							}
560
+							return false;
561
+						}
562
+						break;
563
+					// TEST #2 : check that settings section exists
564
+					case 2:
565
+						if (! isset($this->{$section})) {
566
+							if ($display_errors) {
567
+								throw new EE_Error(
568
+									sprintf(
569
+										esc_html__('The "%s" configuration section does not exist.', 'event_espresso'),
570
+										$section
571
+									)
572
+								);
573
+							}
574
+							return false;
575
+						}
576
+						break;
577
+					// TEST #3 : check that section is the proper format
578
+					case 3:
579
+						if (
580
+							! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
581
+						) {
582
+							if ($display_errors) {
583
+								throw new EE_Error(
584
+									sprintf(
585
+										esc_html__(
586
+											'The "%s" configuration settings have not been formatted correctly.',
587
+											'event_espresso'
588
+										),
589
+										$section
590
+									)
591
+								);
592
+							}
593
+							return false;
594
+						}
595
+						break;
596
+					// TEST #4 : check that config section name has been set
597
+					case 4:
598
+						if (empty($name)) {
599
+							if ($display_errors) {
600
+								throw new EE_Error(
601
+									esc_html__(
602
+										'No name has been provided for the specific configuration section.',
603
+										'event_espresso'
604
+									)
605
+								);
606
+							}
607
+							return false;
608
+						}
609
+						break;
610
+					// TEST #5 : check that a config class name has been set
611
+					case 5:
612
+						if (empty($config_class)) {
613
+							if ($display_errors) {
614
+								throw new EE_Error(
615
+									esc_html__(
616
+										'No class name has been provided for the specific configuration section.',
617
+										'event_espresso'
618
+									)
619
+								);
620
+							}
621
+							return false;
622
+						}
623
+						break;
624
+					// TEST #6 : verify config class is accessible
625
+					case 6:
626
+						if (! class_exists($config_class)) {
627
+							if ($display_errors) {
628
+								throw new EE_Error(
629
+									sprintf(
630
+										esc_html__(
631
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
632
+											'event_espresso'
633
+										),
634
+										$config_class
635
+									)
636
+								);
637
+							}
638
+							return false;
639
+						}
640
+						break;
641
+					// TEST #7 : check that config has even been set
642
+					case 7:
643
+						if (! isset($this->{$section}->{$name})) {
644
+							if ($display_errors) {
645
+								throw new EE_Error(
646
+									sprintf(
647
+										esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
648
+										$section,
649
+										$name
650
+									)
651
+								);
652
+							}
653
+							return false;
654
+						} else {
655
+							// and make sure it's not serialized
656
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
657
+						}
658
+						break;
659
+					// TEST #8 : check that config is the requested type
660
+					case 8:
661
+						if (! $this->{$section}->{$name} instanceof $config_class) {
662
+							if ($display_errors) {
663
+								throw new EE_Error(
664
+									sprintf(
665
+										esc_html__(
666
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
667
+											'event_espresso'
668
+										),
669
+										$section,
670
+										$name,
671
+										$config_class
672
+									)
673
+								);
674
+							}
675
+							return false;
676
+						}
677
+						break;
678
+					// TEST #9 : verify config object
679
+					case 9:
680
+						if (! $config_obj instanceof EE_Config_Base) {
681
+							if ($display_errors) {
682
+								throw new EE_Error(
683
+									sprintf(
684
+										esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
685
+										print_r($config_obj, true)
686
+									)
687
+								);
688
+							}
689
+							return false;
690
+						}
691
+						break;
692
+				}
693
+			}
694
+		} catch (EE_Error $e) {
695
+			$e->get_error();
696
+		}
697
+		// you have successfully run the gauntlet
698
+		return true;
699
+	}
700
+
701
+
702
+	/**
703
+	 *    _generate_config_option_name
704
+	 *
705
+	 * @access        protected
706
+	 * @param        string $section
707
+	 * @param        string $name
708
+	 * @return        string
709
+	 */
710
+	private function _generate_config_option_name($section = '', $name = '')
711
+	{
712
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
713
+	}
714
+
715
+
716
+	/**
717
+	 *    _set_config_class
718
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
719
+	 *
720
+	 * @access    private
721
+	 * @param    string $config_class
722
+	 * @param    string $name
723
+	 * @return    string
724
+	 */
725
+	private function _set_config_class($config_class = '', $name = '')
726
+	{
727
+		return ! empty($config_class)
728
+			? $config_class
729
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
730
+	}
731
+
732
+
733
+	/**
734
+	 *    set_config
735
+	 *
736
+	 * @access    protected
737
+	 * @param    string         $section
738
+	 * @param    string         $name
739
+	 * @param    string         $config_class
740
+	 * @param    EE_Config_Base $config_obj
741
+	 * @return    EE_Config_Base
742
+	 */
743
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
744
+	{
745
+		// ensure config class is set to something
746
+		$config_class = $this->_set_config_class($config_class, $name);
747
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
748
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
749
+			return null;
750
+		}
751
+		$config_option_name = $this->_generate_config_option_name($section, $name);
752
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
753
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
754
+			$this->_addon_option_names[ $config_option_name ] = $config_class;
755
+			$this->update_addon_option_names();
756
+		}
757
+		// verify the incoming config object but suppress errors
758
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
759
+			$config_obj = new $config_class();
760
+		}
761
+		if (get_option($config_option_name)) {
762
+			EE_Config::log($config_option_name);
763
+			update_option($config_option_name, $config_obj);
764
+			$this->{$section}->{$name} = $config_obj;
765
+			return $this->{$section}->{$name};
766
+		} else {
767
+			// create a wp-option for this config
768
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
769
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
770
+				return $this->{$section}->{$name};
771
+			} else {
772
+				EE_Error::add_error(
773
+					sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
774
+					__FILE__,
775
+					__FUNCTION__,
776
+					__LINE__
777
+				);
778
+				return null;
779
+			}
780
+		}
781
+	}
782
+
783
+
784
+	/**
785
+	 *    update_config
786
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
787
+	 *
788
+	 * @access    public
789
+	 * @param    string                $section
790
+	 * @param    string                $name
791
+	 * @param    EE_Config_Base|string $config_obj
792
+	 * @param    bool                  $throw_errors
793
+	 * @return    bool
794
+	 */
795
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
796
+	{
797
+		// don't allow config updates during WP heartbeats
798
+		/** @var RequestInterface $request */
799
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
800
+		if ($request->isWordPressHeartbeat()) {
801
+			return false;
802
+		}
803
+		$config_obj = maybe_unserialize($config_obj);
804
+		// get class name of the incoming object
805
+		$config_class = get_class($config_obj);
806
+		// run tests 1-5 and 9 to verify config
807
+		if (
808
+			! $this->_verify_config_params(
809
+				$section,
810
+				$name,
811
+				$config_class,
812
+				$config_obj,
813
+				array(1, 2, 3, 4, 7, 9)
814
+			)
815
+		) {
816
+			return false;
817
+		}
818
+		$config_option_name = $this->_generate_config_option_name($section, $name);
819
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
820
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
821
+			// save new config to db
822
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
823
+				return true;
824
+			}
825
+		} else {
826
+			// first check if the record already exists
827
+			$existing_config = get_option($config_option_name);
828
+			$config_obj = serialize($config_obj);
829
+			// just return if db record is already up to date (NOT type safe comparison)
830
+			if ($existing_config == $config_obj) {
831
+				$this->{$section}->{$name} = $config_obj;
832
+				return true;
833
+			} elseif (update_option($config_option_name, $config_obj)) {
834
+				EE_Config::log($config_option_name);
835
+				// update wp-option for this config class
836
+				$this->{$section}->{$name} = $config_obj;
837
+				return true;
838
+			} elseif ($throw_errors) {
839
+				EE_Error::add_error(
840
+					sprintf(
841
+						esc_html__(
842
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
843
+							'event_espresso'
844
+						),
845
+						$config_class,
846
+						'EE_Config->' . $section . '->' . $name
847
+					),
848
+					__FILE__,
849
+					__FUNCTION__,
850
+					__LINE__
851
+				);
852
+			}
853
+		}
854
+		return false;
855
+	}
856
+
857
+
858
+	/**
859
+	 *    get_config
860
+	 *
861
+	 * @access    public
862
+	 * @param    string $section
863
+	 * @param    string $name
864
+	 * @param    string $config_class
865
+	 * @return    mixed EE_Config_Base | NULL
866
+	 */
867
+	public function get_config($section = '', $name = '', $config_class = '')
868
+	{
869
+		// ensure config class is set to something
870
+		$config_class = $this->_set_config_class($config_class, $name);
871
+		// run tests 1-4, 6 and 7 to verify that all params have been set
872
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
873
+			return null;
874
+		}
875
+		// now test if the requested config object exists, but suppress errors
876
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
877
+			// config already exists, so pass it back
878
+			return $this->{$section}->{$name};
879
+		}
880
+		// load config option from db if it exists
881
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
882
+		// verify the newly retrieved config object, but suppress errors
883
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
884
+			// config is good, so set it and pass it back
885
+			$this->{$section}->{$name} = $config_obj;
886
+			return $this->{$section}->{$name};
887
+		}
888
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
889
+		$config_obj = $this->set_config($section, $name, $config_class);
890
+		// verify the newly created config object
891
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
892
+			return $this->{$section}->{$name};
893
+		} else {
894
+			EE_Error::add_error(
895
+				sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
896
+				__FILE__,
897
+				__FUNCTION__,
898
+				__LINE__
899
+			);
900
+		}
901
+		return null;
902
+	}
903
+
904
+
905
+	/**
906
+	 *    get_config_option
907
+	 *
908
+	 * @access    public
909
+	 * @param    string $config_option_name
910
+	 * @return    mixed EE_Config_Base | FALSE
911
+	 */
912
+	public function get_config_option($config_option_name = '')
913
+	{
914
+		// retrieve the wp-option for this config class.
915
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
916
+		if (empty($config_option)) {
917
+			EE_Config::log($config_option_name . '-NOT-FOUND');
918
+		}
919
+		return $config_option;
920
+	}
921
+
922
+
923
+	/**
924
+	 * log
925
+	 *
926
+	 * @param string $config_option_name
927
+	 */
928
+	public static function log($config_option_name = '')
929
+	{
930
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
931
+			$config_log = get_option(EE_Config::LOG_NAME, array());
932
+			/** @var RequestParams $request */
933
+			$request = LoaderFactory::getLoader()->getShared(RequestParams::class);
934
+			$config_log[ (string) microtime(true) ] = array(
935
+				'config_name' => $config_option_name,
936
+				'request'     => $request->requestParams(),
937
+			);
938
+			update_option(EE_Config::LOG_NAME, $config_log);
939
+		}
940
+	}
941
+
942
+
943
+	/**
944
+	 * trim_log
945
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
946
+	 */
947
+	public static function trim_log()
948
+	{
949
+		if (! EE_Config::logging_enabled()) {
950
+			return;
951
+		}
952
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
953
+		$log_length = count($config_log);
954
+		if ($log_length > EE_Config::LOG_LENGTH) {
955
+			ksort($config_log);
956
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
957
+			update_option(EE_Config::LOG_NAME, $config_log);
958
+		}
959
+	}
960
+
961
+
962
+	/**
963
+	 *    get_page_for_posts
964
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
965
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
966
+	 *
967
+	 * @access    public
968
+	 * @return    string
969
+	 */
970
+	public static function get_page_for_posts()
971
+	{
972
+		$page_for_posts = get_option('page_for_posts');
973
+		if (! $page_for_posts) {
974
+			return 'posts';
975
+		}
976
+		global $wpdb;
977
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
978
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
979
+	}
980
+
981
+
982
+	/**
983
+	 *    register_shortcodes_and_modules.
984
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
985
+	 *    In fact, this is where we give modules a chance to let core know they exist
986
+	 *    so they can help trigger maintenance mode if it's needed
987
+	 *
988
+	 * @access    public
989
+	 * @return    void
990
+	 */
991
+	public function register_shortcodes_and_modules()
992
+	{
993
+		// allow modules to set hooks for the rest of the system
994
+		EE_Registry::instance()->modules = $this->_register_modules();
995
+	}
996
+
997
+
998
+	/**
999
+	 *    initialize_shortcodes_and_modules
1000
+	 *    meaning they can start adding their hooks to get stuff done
1001
+	 *
1002
+	 * @access    public
1003
+	 * @return    void
1004
+	 */
1005
+	public function initialize_shortcodes_and_modules()
1006
+	{
1007
+		// allow modules to set hooks for the rest of the system
1008
+		$this->_initialize_modules();
1009
+	}
1010
+
1011
+
1012
+	/**
1013
+	 *    widgets_init
1014
+	 *
1015
+	 * @access private
1016
+	 * @return void
1017
+	 */
1018
+	public function widgets_init()
1019
+	{
1020
+		// only init widgets on admin pages when not in complete maintenance, and
1021
+		// on frontend when not in any maintenance mode
1022
+		if (
1023
+			! EE_Maintenance_Mode::instance()->level()
1024
+			|| (
1025
+				is_admin()
1026
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1027
+			)
1028
+		) {
1029
+			// grab list of installed widgets
1030
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1031
+			// filter list of modules to register
1032
+			$widgets_to_register = apply_filters(
1033
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1034
+				$widgets_to_register
1035
+			);
1036
+			if (! empty($widgets_to_register)) {
1037
+				// cycle thru widget folders
1038
+				foreach ($widgets_to_register as $widget_path) {
1039
+					// add to list of installed widget modules
1040
+					EE_Config::register_ee_widget($widget_path);
1041
+				}
1042
+			}
1043
+			// filter list of installed modules
1044
+			EE_Registry::instance()->widgets = apply_filters(
1045
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1046
+				EE_Registry::instance()->widgets
1047
+			);
1048
+		}
1049
+	}
1050
+
1051
+
1052
+	/**
1053
+	 *    register_ee_widget - makes core aware of this widget
1054
+	 *
1055
+	 * @access    public
1056
+	 * @param    string $widget_path - full path up to and including widget folder
1057
+	 * @return    void
1058
+	 */
1059
+	public static function register_ee_widget($widget_path = null)
1060
+	{
1061
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1062
+		$widget_ext = '.widget.php';
1063
+		// make all separators match
1064
+		$widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1065
+		// does the file path INCLUDE the actual file name as part of the path ?
1066
+		if (strpos($widget_path, $widget_ext) !== false) {
1067
+			// grab and shortcode file name from directory name and break apart at dots
1068
+			$file_name = explode('.', basename($widget_path));
1069
+			// take first segment from file name pieces and remove class prefix if it exists
1070
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1071
+			// sanitize shortcode directory name
1072
+			$widget = sanitize_key($widget);
1073
+			// now we need to rebuild the shortcode path
1074
+			$widget_path = explode('/', $widget_path);
1075
+			// remove last segment
1076
+			array_pop($widget_path);
1077
+			// glue it back together
1078
+			$widget_path = implode(DS, $widget_path);
1079
+		} else {
1080
+			// grab and sanitize widget directory name
1081
+			$widget = sanitize_key(basename($widget_path));
1082
+		}
1083
+		// create classname from widget directory name
1084
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1085
+		// add class prefix
1086
+		$widget_class = 'EEW_' . $widget;
1087
+		// does the widget exist ?
1088
+		if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1089
+			$msg = sprintf(
1090
+				esc_html__(
1091
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1092
+					'event_espresso'
1093
+				),
1094
+				$widget_class,
1095
+				$widget_path . '/' . $widget_class . $widget_ext
1096
+			);
1097
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1098
+			return;
1099
+		}
1100
+		// load the widget class file
1101
+		require_once($widget_path . '/' . $widget_class . $widget_ext);
1102
+		// verify that class exists
1103
+		if (! class_exists($widget_class)) {
1104
+			$msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1105
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1106
+			return;
1107
+		}
1108
+		register_widget($widget_class);
1109
+		// add to array of registered widgets
1110
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1111
+	}
1112
+
1113
+
1114
+	/**
1115
+	 *        _register_modules
1116
+	 *
1117
+	 * @access private
1118
+	 * @return array
1119
+	 */
1120
+	private function _register_modules()
1121
+	{
1122
+		// grab list of installed modules
1123
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1124
+		// filter list of modules to register
1125
+		$modules_to_register = apply_filters(
1126
+			'FHEE__EE_Config__register_modules__modules_to_register',
1127
+			$modules_to_register
1128
+		);
1129
+		if (! empty($modules_to_register)) {
1130
+			// loop through folders
1131
+			foreach ($modules_to_register as $module_path) {
1132
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1133
+				if (
1134
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1135
+					&& $module_path !== EE_MODULES . 'gateways'
1136
+				) {
1137
+					// add to list of installed modules
1138
+					EE_Config::register_module($module_path);
1139
+				}
1140
+			}
1141
+		}
1142
+		// filter list of installed modules
1143
+		return apply_filters(
1144
+			'FHEE__EE_Config___register_modules__installed_modules',
1145
+			EE_Registry::instance()->modules
1146
+		);
1147
+	}
1148
+
1149
+
1150
+	/**
1151
+	 *    register_module - makes core aware of this module
1152
+	 *
1153
+	 * @access    public
1154
+	 * @param    string $module_path - full path up to and including module folder
1155
+	 * @return    bool
1156
+	 */
1157
+	public static function register_module($module_path = null)
1158
+	{
1159
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1160
+		$module_ext = '.module.php';
1161
+		// make all separators match
1162
+		$module_path = str_replace(array('\\', '/'), '/', $module_path);
1163
+		// does the file path INCLUDE the actual file name as part of the path ?
1164
+		if (strpos($module_path, $module_ext) !== false) {
1165
+			// grab and shortcode file name from directory name and break apart at dots
1166
+			$module_file = explode('.', basename($module_path));
1167
+			// now we need to rebuild the shortcode path
1168
+			$module_path = explode('/', $module_path);
1169
+			// remove last segment
1170
+			array_pop($module_path);
1171
+			// glue it back together
1172
+			$module_path = implode('/', $module_path) . '/';
1173
+			// take first segment from file name pieces and sanitize it
1174
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1175
+			// ensure class prefix is added
1176
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1177
+		} else {
1178
+			// we need to generate the filename based off of the folder name
1179
+			// grab and sanitize module name
1180
+			$module = strtolower(basename($module_path));
1181
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1182
+			// like trailingslashit()
1183
+			$module_path = rtrim($module_path, '/') . '/';
1184
+			// create classname from module directory name
1185
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1186
+			// add class prefix
1187
+			$module_class = 'EED_' . $module;
1188
+		}
1189
+		// does the module exist ?
1190
+		if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1191
+			$msg = sprintf(
1192
+				esc_html__(
1193
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1194
+					'event_espresso'
1195
+				),
1196
+				$module
1197
+			);
1198
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1199
+			return false;
1200
+		}
1201
+		// load the module class file
1202
+		require_once($module_path . $module_class . $module_ext);
1203
+		// verify that class exists
1204
+		if (! class_exists($module_class)) {
1205
+			$msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1206
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1207
+			return false;
1208
+		}
1209
+		// add to array of registered modules
1210
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1211
+		do_action(
1212
+			'AHEE__EE_Config__register_module__complete',
1213
+			$module_class,
1214
+			EE_Registry::instance()->modules->{$module_class}
1215
+		);
1216
+		return true;
1217
+	}
1218
+
1219
+
1220
+	/**
1221
+	 *    _initialize_modules
1222
+	 *    allow modules to set hooks for the rest of the system
1223
+	 *
1224
+	 * @access private
1225
+	 * @return void
1226
+	 */
1227
+	private function _initialize_modules()
1228
+	{
1229
+		// cycle thru shortcode folders
1230
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1231
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1232
+			// which set hooks ?
1233
+			if (is_admin()) {
1234
+				// fire immediately
1235
+				call_user_func(array($module_class, 'set_hooks_admin'));
1236
+			} else {
1237
+				// delay until other systems are online
1238
+				add_action(
1239
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1240
+					array($module_class, 'set_hooks')
1241
+				);
1242
+			}
1243
+		}
1244
+	}
1245
+
1246
+
1247
+	/**
1248
+	 *    register_route - adds module method routes to route_map
1249
+	 *
1250
+	 * @access    public
1251
+	 * @param    string $route       - "pretty" public alias for module method
1252
+	 * @param    string $module      - module name (classname without EED_ prefix)
1253
+	 * @param    string $method_name - the actual module method to be routed to
1254
+	 * @param    string $key         - url param key indicating a route is being called
1255
+	 * @return    bool
1256
+	 */
1257
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1258
+	{
1259
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1260
+		$module = str_replace('EED_', '', $module);
1261
+		$module_class = 'EED_' . $module;
1262
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1263
+			$msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1264
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1265
+			return false;
1266
+		}
1267
+		if (empty($route)) {
1268
+			$msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1269
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1270
+			return false;
1271
+		}
1272
+		if (! method_exists('EED_' . $module, $method_name)) {
1273
+			$msg = sprintf(
1274
+				esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1275
+				$route
1276
+			);
1277
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1278
+			return false;
1279
+		}
1280
+		EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1281
+		return true;
1282
+	}
1283
+
1284
+
1285
+	/**
1286
+	 *    get_route - get module method route
1287
+	 *
1288
+	 * @access    public
1289
+	 * @param    string $route - "pretty" public alias for module method
1290
+	 * @param    string $key   - url param key indicating a route is being called
1291
+	 * @return    string
1292
+	 */
1293
+	public static function get_route($route = null, $key = 'ee')
1294
+	{
1295
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1296
+		$route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1297
+		if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1298
+			return EE_Config::$_module_route_map[ $key ][ $route ];
1299
+		}
1300
+		return null;
1301
+	}
1302
+
1303
+
1304
+	/**
1305
+	 *    get_routes - get ALL module method routes
1306
+	 *
1307
+	 * @access    public
1308
+	 * @return    array
1309
+	 */
1310
+	public static function get_routes()
1311
+	{
1312
+		return EE_Config::$_module_route_map;
1313
+	}
1314
+
1315
+
1316
+	/**
1317
+	 *    register_forward - allows modules to forward request to another module for further processing
1318
+	 *
1319
+	 * @access    public
1320
+	 * @param    string       $route   - "pretty" public alias for module method
1321
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1322
+	 *                                 class, allows different forwards to be served based on status
1323
+	 * @param    array|string $forward - function name or array( class, method )
1324
+	 * @param    string       $key     - url param key indicating a route is being called
1325
+	 * @return    bool
1326
+	 */
1327
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1328
+	{
1329
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1330
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1331
+			$msg = sprintf(
1332
+				esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1333
+				$route
1334
+			);
1335
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1336
+			return false;
1337
+		}
1338
+		if (empty($forward)) {
1339
+			$msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1340
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1341
+			return false;
1342
+		}
1343
+		if (is_array($forward)) {
1344
+			if (! isset($forward[1])) {
1345
+				$msg = sprintf(
1346
+					esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1347
+					$route
1348
+				);
1349
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1350
+				return false;
1351
+			}
1352
+			if (! method_exists($forward[0], $forward[1])) {
1353
+				$msg = sprintf(
1354
+					esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1355
+					$forward[1],
1356
+					$route
1357
+				);
1358
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1359
+				return false;
1360
+			}
1361
+		} elseif (! function_exists($forward)) {
1362
+			$msg = sprintf(
1363
+				esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1364
+				$forward,
1365
+				$route
1366
+			);
1367
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1368
+			return false;
1369
+		}
1370
+		EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1371
+		return true;
1372
+	}
1373
+
1374
+
1375
+	/**
1376
+	 *    get_forward - get forwarding route
1377
+	 *
1378
+	 * @access    public
1379
+	 * @param    string  $route  - "pretty" public alias for module method
1380
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1381
+	 *                           allows different forwards to be served based on status
1382
+	 * @param    string  $key    - url param key indicating a route is being called
1383
+	 * @return    string
1384
+	 */
1385
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1386
+	{
1387
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1388
+		if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1389
+			return apply_filters(
1390
+				'FHEE__EE_Config__get_forward',
1391
+				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1392
+				$route,
1393
+				$status
1394
+			);
1395
+		}
1396
+		return null;
1397
+	}
1398
+
1399
+
1400
+	/**
1401
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1402
+	 *    results
1403
+	 *
1404
+	 * @access    public
1405
+	 * @param    string  $route  - "pretty" public alias for module method
1406
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1407
+	 *                           allows different views to be served based on status
1408
+	 * @param    string  $view
1409
+	 * @param    string  $key    - url param key indicating a route is being called
1410
+	 * @return    bool
1411
+	 */
1412
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1413
+	{
1414
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1415
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1416
+			$msg = sprintf(
1417
+				esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1418
+				$route
1419
+			);
1420
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1421
+			return false;
1422
+		}
1423
+		if (! is_readable($view)) {
1424
+			$msg = sprintf(
1425
+				esc_html__(
1426
+					'The %s view file could not be found or is not readable due to file permissions.',
1427
+					'event_espresso'
1428
+				),
1429
+				$view
1430
+			);
1431
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1432
+			return false;
1433
+		}
1434
+		EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1435
+		return true;
1436
+	}
1437
+
1438
+
1439
+	/**
1440
+	 *    get_view - get view for route and status
1441
+	 *
1442
+	 * @access    public
1443
+	 * @param    string  $route  - "pretty" public alias for module method
1444
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1445
+	 *                           allows different views to be served based on status
1446
+	 * @param    string  $key    - url param key indicating a route is being called
1447
+	 * @return    string
1448
+	 */
1449
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1450
+	{
1451
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1452
+		if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1453
+			return apply_filters(
1454
+				'FHEE__EE_Config__get_view',
1455
+				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1456
+				$route,
1457
+				$status
1458
+			);
1459
+		}
1460
+		return null;
1461
+	}
1462
+
1463
+
1464
+	public function update_addon_option_names()
1465
+	{
1466
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1467
+	}
1468
+
1469
+
1470
+	public function shutdown()
1471
+	{
1472
+		$this->update_addon_option_names();
1473
+	}
1474
+
1475
+
1476
+	/**
1477
+	 * @return LegacyShortcodesManager
1478
+	 */
1479
+	public static function getLegacyShortcodesManager()
1480
+	{
1481
+		if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1482
+			EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1483
+				LegacyShortcodesManager::class
1484
+			);
1485
+		}
1486
+		return EE_Config::instance()->legacy_shortcodes_manager;
1487
+	}
1488
+
1489
+
1490
+	/**
1491
+	 * register_shortcode - makes core aware of this shortcode
1492
+	 *
1493
+	 * @deprecated 4.9.26
1494
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1495
+	 * @return    bool
1496
+	 */
1497
+	public static function register_shortcode($shortcode_path = null)
1498
+	{
1499
+		EE_Error::doing_it_wrong(
1500
+			__METHOD__,
1501
+			esc_html__(
1502
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1503
+				'event_espresso'
1504
+			),
1505
+			'4.9.26'
1506
+		);
1507
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1508
+	}
1509
+}
2305 1510
 
2306
-    /**
2307
-     * ReCaptcha width
2308
-     *
2309
-     * @var int $recaptcha_width
2310
-     * @deprecated
2311
-     */
2312
-    public $recaptcha_width;
1511
+/**
1512
+ * Base class used for config classes. These classes should generally not have
1513
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1514
+ * basically, they should just be well-defined stdClasses
1515
+ */
1516
+class EE_Config_Base
1517
+{
1518
+	/**
1519
+	 * Utility function for escaping the value of a property and returning.
1520
+	 *
1521
+	 * @param string $property property name (checks to see if exists).
1522
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1523
+	 * @throws EE_Error
1524
+	 */
1525
+	public function get_pretty($property)
1526
+	{
1527
+		if (! property_exists($this, $property)) {
1528
+			throw new EE_Error(
1529
+				sprintf(
1530
+					esc_html__(
1531
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1532
+						'event_espresso'
1533
+					),
1534
+					get_class($this),
1535
+					$property
1536
+				)
1537
+			);
1538
+		}
1539
+		// just handling escaping of strings for now.
1540
+		if (is_string($this->{$property})) {
1541
+			return stripslashes($this->{$property});
1542
+		}
1543
+		return $this->{$property};
1544
+	}
1545
+
1546
+
1547
+	public function populate()
1548
+	{
1549
+		// grab defaults via a new instance of this class.
1550
+		$class_name = get_class($this);
1551
+		$defaults = new $class_name();
1552
+		// loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1553
+		// default from our $defaults object.
1554
+		foreach (get_object_vars($defaults) as $property => $value) {
1555
+			if ($this->{$property} === null) {
1556
+				$this->{$property} = $value;
1557
+			}
1558
+		}
1559
+		// cleanup
1560
+		unset($defaults);
1561
+	}
1562
+
1563
+
1564
+	/**
1565
+	 *        __isset
1566
+	 *
1567
+	 * @param $a
1568
+	 * @return bool
1569
+	 */
1570
+	public function __isset($a)
1571
+	{
1572
+		return false;
1573
+	}
1574
+
1575
+
1576
+	/**
1577
+	 *        __unset
1578
+	 *
1579
+	 * @param $a
1580
+	 * @return bool
1581
+	 */
1582
+	public function __unset($a)
1583
+	{
1584
+		return false;
1585
+	}
1586
+
1587
+
1588
+	/**
1589
+	 *        __clone
1590
+	 */
1591
+	public function __clone()
1592
+	{
1593
+	}
1594
+
1595
+
1596
+	/**
1597
+	 *        __wakeup
1598
+	 */
1599
+	public function __wakeup()
1600
+	{
1601
+	}
1602
+
1603
+
1604
+	/**
1605
+	 *        __destruct
1606
+	 */
1607
+	public function __destruct()
1608
+	{
1609
+	}
1610
+}
2313 1611
 
2314
-    /**
2315
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2316
-     *
2317
-     * @var boolean $track_invalid_checkout_access
2318
-     */
2319
-    protected $track_invalid_checkout_access = true;
1612
+/**
1613
+ * Class for defining what's in the EE_Config relating to registration settings
1614
+ */
1615
+class EE_Core_Config extends EE_Config_Base
1616
+{
1617
+	const OPTION_NAME_UXIP = 'ee_ueip_optin';
1618
+
1619
+
1620
+	public $current_blog_id;
1621
+
1622
+	public $ee_ueip_optin;
1623
+
1624
+	public $ee_ueip_has_notified;
1625
+
1626
+	/**
1627
+	 * Not to be confused with the 4 critical page variables (See
1628
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1629
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1630
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1631
+	 *
1632
+	 * @var array
1633
+	 */
1634
+	public $post_shortcodes;
1635
+
1636
+	public $module_route_map;
1637
+
1638
+	public $module_forward_map;
1639
+
1640
+	public $module_view_map;
1641
+
1642
+	/**
1643
+	 * The next 4 vars are the IDs of critical EE pages.
1644
+	 *
1645
+	 * @var int
1646
+	 */
1647
+	public $reg_page_id;
1648
+
1649
+	public $txn_page_id;
1650
+
1651
+	public $thank_you_page_id;
1652
+
1653
+	public $cancel_page_id;
1654
+
1655
+	/**
1656
+	 * The next 4 vars are the URLs of critical EE pages.
1657
+	 *
1658
+	 * @var int
1659
+	 */
1660
+	public $reg_page_url;
1661
+
1662
+	public $txn_page_url;
1663
+
1664
+	public $thank_you_page_url;
1665
+
1666
+	public $cancel_page_url;
1667
+
1668
+	/**
1669
+	 * The next vars relate to the custom slugs for EE CPT routes
1670
+	 */
1671
+	public $event_cpt_slug;
1672
+
1673
+	/**
1674
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1675
+	 * request across blog switches in a multisite context.
1676
+	 * Avoids extra queries to the db for this option.
1677
+	 *
1678
+	 * @var bool
1679
+	 */
1680
+	public static $ee_ueip_option;
1681
+
1682
+
1683
+	/**
1684
+	 *    class constructor
1685
+	 *
1686
+	 * @access    public
1687
+	 */
1688
+	public function __construct()
1689
+	{
1690
+		// set default organization settings
1691
+		$this->current_blog_id = get_current_blog_id();
1692
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1693
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1694
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1695
+		$this->post_shortcodes = array();
1696
+		$this->module_route_map = array();
1697
+		$this->module_forward_map = array();
1698
+		$this->module_view_map = array();
1699
+		// critical EE page IDs
1700
+		$this->reg_page_id = 0;
1701
+		$this->txn_page_id = 0;
1702
+		$this->thank_you_page_id = 0;
1703
+		$this->cancel_page_id = 0;
1704
+		// critical EE page URLs
1705
+		$this->reg_page_url = '';
1706
+		$this->txn_page_url = '';
1707
+		$this->thank_you_page_url = '';
1708
+		$this->cancel_page_url = '';
1709
+		// cpt slugs
1710
+		$this->event_cpt_slug = esc_html__('events', 'event_espresso');
1711
+		// ueip constant check
1712
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1713
+			$this->ee_ueip_optin = false;
1714
+			$this->ee_ueip_has_notified = true;
1715
+		}
1716
+	}
1717
+
1718
+
1719
+	/**
1720
+	 * @return array
1721
+	 */
1722
+	public function get_critical_pages_array()
1723
+	{
1724
+		return array(
1725
+			$this->reg_page_id,
1726
+			$this->txn_page_id,
1727
+			$this->thank_you_page_id,
1728
+			$this->cancel_page_id,
1729
+		);
1730
+	}
1731
+
1732
+
1733
+	/**
1734
+	 * @return array
1735
+	 */
1736
+	public function get_critical_pages_shortcodes_array()
1737
+	{
1738
+		return array(
1739
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1740
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1741
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1742
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1743
+		);
1744
+	}
1745
+
1746
+
1747
+	/**
1748
+	 *  gets/returns URL for EE reg_page
1749
+	 *
1750
+	 * @access    public
1751
+	 * @return    string
1752
+	 */
1753
+	public function reg_page_url()
1754
+	{
1755
+		if (! $this->reg_page_url) {
1756
+			$this->reg_page_url = add_query_arg(
1757
+				array('uts' => time()),
1758
+				get_permalink($this->reg_page_id)
1759
+			) . '#checkout';
1760
+		}
1761
+		return $this->reg_page_url;
1762
+	}
1763
+
1764
+
1765
+	/**
1766
+	 *  gets/returns URL for EE txn_page
1767
+	 *
1768
+	 * @param array $query_args like what gets passed to
1769
+	 *                          add_query_arg() as the first argument
1770
+	 * @access    public
1771
+	 * @return    string
1772
+	 */
1773
+	public function txn_page_url($query_args = array())
1774
+	{
1775
+		if (! $this->txn_page_url) {
1776
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1777
+		}
1778
+		if ($query_args) {
1779
+			return add_query_arg($query_args, $this->txn_page_url);
1780
+		} else {
1781
+			return $this->txn_page_url;
1782
+		}
1783
+	}
1784
+
1785
+
1786
+	/**
1787
+	 *  gets/returns URL for EE thank_you_page
1788
+	 *
1789
+	 * @param array $query_args like what gets passed to
1790
+	 *                          add_query_arg() as the first argument
1791
+	 * @access    public
1792
+	 * @return    string
1793
+	 */
1794
+	public function thank_you_page_url($query_args = array())
1795
+	{
1796
+		if (! $this->thank_you_page_url) {
1797
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1798
+		}
1799
+		if ($query_args) {
1800
+			return add_query_arg($query_args, $this->thank_you_page_url);
1801
+		} else {
1802
+			return $this->thank_you_page_url;
1803
+		}
1804
+	}
1805
+
1806
+
1807
+	/**
1808
+	 *  gets/returns URL for EE cancel_page
1809
+	 *
1810
+	 * @access    public
1811
+	 * @return    string
1812
+	 */
1813
+	public function cancel_page_url()
1814
+	{
1815
+		if (! $this->cancel_page_url) {
1816
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1817
+		}
1818
+		return $this->cancel_page_url;
1819
+	}
1820
+
1821
+
1822
+	/**
1823
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1824
+	 *
1825
+	 * @since 4.7.5
1826
+	 */
1827
+	protected function _reset_urls()
1828
+	{
1829
+		$this->reg_page_url = '';
1830
+		$this->txn_page_url = '';
1831
+		$this->cancel_page_url = '';
1832
+		$this->thank_you_page_url = '';
1833
+	}
1834
+
1835
+
1836
+	/**
1837
+	 * Used to return what the optin value is set for the EE User Experience Program.
1838
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1839
+	 * on the main site only.
1840
+	 *
1841
+	 * @return bool
1842
+	 */
1843
+	protected function _get_main_ee_ueip_optin()
1844
+	{
1845
+		// if this is the main site then we can just bypass our direct query.
1846
+		if (is_main_site()) {
1847
+			return get_option(self::OPTION_NAME_UXIP, false);
1848
+		}
1849
+		// is this already cached for this request?  If so use it.
1850
+		if (EE_Core_Config::$ee_ueip_option !== null) {
1851
+			return EE_Core_Config::$ee_ueip_option;
1852
+		}
1853
+		global $wpdb;
1854
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1855
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1856
+		$option = self::OPTION_NAME_UXIP;
1857
+		// set correct table for query
1858
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1859
+		// rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1860
+		// get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1861
+		// re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1862
+		// this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1863
+		// for the purpose of caching.
1864
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1865
+		if (false !== $pre) {
1866
+			EE_Core_Config::$ee_ueip_option = $pre;
1867
+			return EE_Core_Config::$ee_ueip_option;
1868
+		}
1869
+		$row = $wpdb->get_row(
1870
+			$wpdb->prepare(
1871
+				"SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1872
+				$option
1873
+			)
1874
+		);
1875
+		if (is_object($row)) {
1876
+			$value = $row->option_value;
1877
+		} else { // option does not exist so use default.
1878
+			EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1879
+			return EE_Core_Config::$ee_ueip_option;
1880
+		}
1881
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1882
+		return EE_Core_Config::$ee_ueip_option;
1883
+	}
1884
+
1885
+
1886
+	/**
1887
+	 * Utility function for escaping the value of a property and returning.
1888
+	 *
1889
+	 * @param string $property property name (checks to see if exists).
1890
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1891
+	 * @throws EE_Error
1892
+	 */
1893
+	public function get_pretty($property)
1894
+	{
1895
+		if ($property === self::OPTION_NAME_UXIP) {
1896
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1897
+		}
1898
+		return parent::get_pretty($property);
1899
+	}
1900
+
1901
+
1902
+	/**
1903
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1904
+	 * on the object.
1905
+	 *
1906
+	 * @return array
1907
+	 */
1908
+	public function __sleep()
1909
+	{
1910
+		// reset all url properties
1911
+		$this->_reset_urls();
1912
+		// return what to save to db
1913
+		return array_keys(get_object_vars($this));
1914
+	}
1915
+}
2320 1916
 
2321
-    /**
2322
-     * Whether or not to show the privacy policy consent checkbox
2323
-     *
2324
-     * @var bool
2325
-     */
2326
-    public $consent_checkbox_enabled;
1917
+/**
1918
+ * Config class for storing info on the Organization
1919
+ */
1920
+class EE_Organization_Config extends EE_Config_Base
1921
+{
1922
+	/**
1923
+	 * @var string $name
1924
+	 * eg EE4.1
1925
+	 */
1926
+	public $name;
1927
+
1928
+	/**
1929
+	 * @var string $address_1
1930
+	 * eg 123 Onna Road
1931
+	 */
1932
+	public $address_1 = '';
1933
+
1934
+	/**
1935
+	 * @var string $address_2
1936
+	 * eg PO Box 123
1937
+	 */
1938
+	public $address_2 = '';
1939
+
1940
+	/**
1941
+	 * @var string $city
1942
+	 * eg Inna City
1943
+	 */
1944
+	public $city = '';
1945
+
1946
+	/**
1947
+	 * @var int $STA_ID
1948
+	 * eg 4
1949
+	 */
1950
+	public $STA_ID = 0;
1951
+
1952
+	/**
1953
+	 * @var string $CNT_ISO
1954
+	 * eg US
1955
+	 */
1956
+	public $CNT_ISO = '';
1957
+
1958
+	/**
1959
+	 * @var string $zip
1960
+	 * eg 12345  or V1A 2B3
1961
+	 */
1962
+	public $zip = '';
1963
+
1964
+	/**
1965
+	 * @var string $email
1966
+	 * eg [email protected]
1967
+	 */
1968
+	public $email;
1969
+
1970
+	/**
1971
+	 * @var string $phone
1972
+	 * eg. 111-111-1111
1973
+	 */
1974
+	public $phone = '';
1975
+
1976
+	/**
1977
+	 * @var string $vat
1978
+	 * VAT/Tax Number
1979
+	 */
1980
+	public $vat = '';
1981
+
1982
+	/**
1983
+	 * @var string $logo_url
1984
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1985
+	 */
1986
+	public $logo_url = '';
1987
+
1988
+	/**
1989
+	 * The below are all various properties for holding links to organization social network profiles
1990
+	 *
1991
+	 * @var string
1992
+	 */
1993
+	/**
1994
+	 * facebook (facebook.com/profile.name)
1995
+	 *
1996
+	 * @var string
1997
+	 */
1998
+	public $facebook = '';
1999
+
2000
+	/**
2001
+	 * twitter (twitter.com/twitter_handle)
2002
+	 *
2003
+	 * @var string
2004
+	 */
2005
+	public $twitter = '';
2006
+
2007
+	/**
2008
+	 * linkedin (linkedin.com/in/profile_name)
2009
+	 *
2010
+	 * @var string
2011
+	 */
2012
+	public $linkedin = '';
2013
+
2014
+	/**
2015
+	 * pinterest (www.pinterest.com/profile_name)
2016
+	 *
2017
+	 * @var string
2018
+	 */
2019
+	public $pinterest = '';
2020
+
2021
+	/**
2022
+	 * google+ (google.com/+profileName)
2023
+	 *
2024
+	 * @var string
2025
+	 */
2026
+	public $google = '';
2027
+
2028
+	/**
2029
+	 * instagram (instagram.com/handle)
2030
+	 *
2031
+	 * @var string
2032
+	 */
2033
+	public $instagram = '';
2034
+
2035
+
2036
+	/**
2037
+	 *    class constructor
2038
+	 *
2039
+	 * @access    public
2040
+	 */
2041
+	public function __construct()
2042
+	{
2043
+		// set default organization settings
2044
+		// decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2045
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2046
+		$this->email = get_bloginfo('admin_email');
2047
+	}
2048
+}
2327 2049
 
2328
-    /**
2329
-     * Label text to show on the checkbox
2330
-     *
2331
-     * @var string
2332
-     */
2333
-    public $consent_checkbox_label_text;
2050
+/**
2051
+ * Class for defining what's in the EE_Config relating to currency
2052
+ */
2053
+class EE_Currency_Config extends EE_Config_Base
2054
+{
2055
+	/**
2056
+	 * @var string $code
2057
+	 * eg 'US'
2058
+	 */
2059
+	public $code;
2060
+
2061
+	/**
2062
+	 * @var string $name
2063
+	 * eg 'Dollar'
2064
+	 */
2065
+	public $name;
2066
+
2067
+	/**
2068
+	 * plural name
2069
+	 *
2070
+	 * @var string $plural
2071
+	 * eg 'Dollars'
2072
+	 */
2073
+	public $plural;
2074
+
2075
+	/**
2076
+	 * currency sign
2077
+	 *
2078
+	 * @var string $sign
2079
+	 * eg '$'
2080
+	 */
2081
+	public $sign;
2082
+
2083
+	/**
2084
+	 * Whether the currency sign should come before the number or not
2085
+	 *
2086
+	 * @var boolean $sign_b4
2087
+	 */
2088
+	public $sign_b4;
2089
+
2090
+	/**
2091
+	 * How many digits should come after the decimal place
2092
+	 *
2093
+	 * @var int $dec_plc
2094
+	 */
2095
+	public $dec_plc;
2096
+
2097
+	/**
2098
+	 * Symbol to use for decimal mark
2099
+	 *
2100
+	 * @var string $dec_mrk
2101
+	 * eg '.'
2102
+	 */
2103
+	public $dec_mrk;
2104
+
2105
+	/**
2106
+	 * Symbol to use for thousands
2107
+	 *
2108
+	 * @var string $thsnds
2109
+	 * eg ','
2110
+	 */
2111
+	public $thsnds;
2112
+
2113
+
2114
+	/**
2115
+	 *    class constructor
2116
+	 *
2117
+	 * @access    public
2118
+	 * @param string $CNT_ISO
2119
+	 * @throws EE_Error
2120
+	 * @throws ReflectionException
2121
+	 */
2122
+	public function __construct($CNT_ISO = '')
2123
+	{
2124
+		/** @var TableAnalysis $table_analysis */
2125
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2126
+		// get country code from organization settings or use default
2127
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2128
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2129
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2130
+			: '';
2131
+		// but override if requested
2132
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2133
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2134
+		if (
2135
+			! empty($CNT_ISO)
2136
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2137
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2138
+		) {
2139
+			// retrieve the country settings from the db, just in case they have been customized
2140
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2141
+			if ($country instanceof EE_Country) {
2142
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2143
+				$this->name = $country->currency_name_single();    // Dollar
2144
+				$this->plural = $country->currency_name_plural();    // Dollars
2145
+				$this->sign = $country->currency_sign();            // currency sign: $
2146
+				$this->sign_b4 = $country->currency_sign_before(
2147
+				);        // currency sign before or after: $TRUE  or  FALSE$
2148
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2149
+				$this->dec_mrk = $country->currency_decimal_mark(
2150
+				);    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2151
+				$this->thsnds = $country->currency_thousands_separator(
2152
+				);    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2153
+			}
2154
+		}
2155
+		// fallback to hardcoded defaults, in case the above failed
2156
+		if (empty($this->code)) {
2157
+			// set default currency settings
2158
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2159
+			$this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2160
+			$this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2161
+			$this->sign = '$';    // currency sign: $
2162
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2163
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2164
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2165
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2166
+		}
2167
+	}
2168
+}
2334 2169
 
2335
-    /*
2170
+/**
2171
+ * Class for defining what's in the EE_Config relating to registration settings
2172
+ */
2173
+class EE_Registration_Config extends EE_Config_Base
2174
+{
2175
+	/**
2176
+	 * Default registration status
2177
+	 *
2178
+	 * @var string $default_STS_ID
2179
+	 * eg 'RPP'
2180
+	 */
2181
+	public $default_STS_ID;
2182
+
2183
+	/**
2184
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2185
+	 * registrations)
2186
+	 *
2187
+	 * @var int
2188
+	 */
2189
+	public $default_maximum_number_of_tickets;
2190
+
2191
+	/**
2192
+	 * level of validation to apply to email addresses
2193
+	 *
2194
+	 * @var string $email_validation_level
2195
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2196
+	 */
2197
+	public $email_validation_level;
2198
+
2199
+	/**
2200
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2201
+	 *
2202
+	 * @var boolean $show_pending_payment_options
2203
+	 */
2204
+	public $show_pending_payment_options;
2205
+
2206
+	/**
2207
+	 * Whether to skip the registration confirmation page
2208
+	 *
2209
+	 * @var boolean $skip_reg_confirmation
2210
+	 */
2211
+	public $skip_reg_confirmation;
2212
+
2213
+	/**
2214
+	 * an array of SPCO reg steps where:
2215
+	 *        the keys denotes the reg step order
2216
+	 *        each element consists of an array with the following elements:
2217
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2218
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2219
+	 *            "slug" => the URL param used to trigger the reg step
2220
+	 *
2221
+	 * @var array $reg_steps
2222
+	 */
2223
+	public $reg_steps;
2224
+
2225
+	/**
2226
+	 * Whether registration confirmation should be the last page of SPCO
2227
+	 *
2228
+	 * @var boolean $reg_confirmation_last
2229
+	 */
2230
+	public $reg_confirmation_last;
2231
+
2232
+	/**
2233
+	 * Whether or not to enable the EE Bot Trap
2234
+	 *
2235
+	 * @var boolean $use_bot_trap
2236
+	 */
2237
+	public $use_bot_trap;
2238
+
2239
+	/**
2240
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2241
+	 *
2242
+	 * @var boolean $use_encryption
2243
+	 */
2244
+	public $use_encryption;
2245
+
2246
+	/**
2247
+	 * Whether or not to use ReCaptcha
2248
+	 *
2249
+	 * @var boolean $use_captcha
2250
+	 */
2251
+	public $use_captcha;
2252
+
2253
+	/**
2254
+	 * ReCaptcha Theme
2255
+	 *
2256
+	 * @var string $recaptcha_theme
2257
+	 *    options: 'dark', 'light', 'invisible'
2258
+	 */
2259
+	public $recaptcha_theme;
2260
+
2261
+	/**
2262
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2263
+	 *
2264
+	 * @var string $recaptcha_badge
2265
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2266
+	 */
2267
+	public $recaptcha_badge;
2268
+
2269
+	/**
2270
+	 * ReCaptcha Type
2271
+	 *
2272
+	 * @var string $recaptcha_type
2273
+	 *    options: 'audio', 'image'
2274
+	 */
2275
+	public $recaptcha_type;
2276
+
2277
+	/**
2278
+	 * ReCaptcha language
2279
+	 *
2280
+	 * @var string $recaptcha_language
2281
+	 * eg 'en'
2282
+	 */
2283
+	public $recaptcha_language;
2284
+
2285
+	/**
2286
+	 * ReCaptcha public key
2287
+	 *
2288
+	 * @var string $recaptcha_publickey
2289
+	 */
2290
+	public $recaptcha_publickey;
2291
+
2292
+	/**
2293
+	 * ReCaptcha private key
2294
+	 *
2295
+	 * @var string $recaptcha_privatekey
2296
+	 */
2297
+	public $recaptcha_privatekey;
2298
+
2299
+	/**
2300
+	 * array of form names protected by ReCaptcha
2301
+	 *
2302
+	 * @var array $recaptcha_protected_forms
2303
+	 */
2304
+	public $recaptcha_protected_forms;
2305
+
2306
+	/**
2307
+	 * ReCaptcha width
2308
+	 *
2309
+	 * @var int $recaptcha_width
2310
+	 * @deprecated
2311
+	 */
2312
+	public $recaptcha_width;
2313
+
2314
+	/**
2315
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2316
+	 *
2317
+	 * @var boolean $track_invalid_checkout_access
2318
+	 */
2319
+	protected $track_invalid_checkout_access = true;
2320
+
2321
+	/**
2322
+	 * Whether or not to show the privacy policy consent checkbox
2323
+	 *
2324
+	 * @var bool
2325
+	 */
2326
+	public $consent_checkbox_enabled;
2327
+
2328
+	/**
2329
+	 * Label text to show on the checkbox
2330
+	 *
2331
+	 * @var string
2332
+	 */
2333
+	public $consent_checkbox_label_text;
2334
+
2335
+	/*
2336 2336
      * String describing how long to keep payment logs. Passed into DateTime constructor
2337 2337
      * @var string
2338 2338
      */
2339
-    public $gateway_log_lifespan = '1 week';
2340
-
2341
-    /**
2342
-     * Enable copy attendee info at form
2343
-     *
2344
-     * @var boolean $enable_copy_attendee
2345
-     */
2346
-    protected $copy_attendee_info = true;
2347
-
2348
-
2349
-    /**
2350
-     *    class constructor
2351
-     *
2352
-     * @access    public
2353
-     */
2354
-    public function __construct()
2355
-    {
2356
-        // set default registration settings
2357
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2358
-        $this->email_validation_level = 'wp_default';
2359
-        $this->show_pending_payment_options = true;
2360
-        $this->skip_reg_confirmation = true;
2361
-        $this->reg_steps = array();
2362
-        $this->reg_confirmation_last = false;
2363
-        $this->use_bot_trap = true;
2364
-        $this->use_encryption = true;
2365
-        $this->use_captcha = false;
2366
-        $this->recaptcha_theme = 'light';
2367
-        $this->recaptcha_badge = 'bottomleft';
2368
-        $this->recaptcha_type = 'image';
2369
-        $this->recaptcha_language = 'en';
2370
-        $this->recaptcha_publickey = null;
2371
-        $this->recaptcha_privatekey = null;
2372
-        $this->recaptcha_protected_forms = array();
2373
-        $this->recaptcha_width = 500;
2374
-        $this->default_maximum_number_of_tickets = 10;
2375
-        $this->consent_checkbox_enabled = false;
2376
-        $this->consent_checkbox_label_text = '';
2377
-        $this->gateway_log_lifespan = '7 days';
2378
-        $this->copy_attendee_info = true;
2379
-    }
2380
-
2381
-
2382
-    /**
2383
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2384
-     *
2385
-     * @since 4.8.8.rc.019
2386
-     */
2387
-    public function do_hooks()
2388
-    {
2389
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2390
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2391
-        add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2392
-    }
2393
-
2394
-
2395
-    /**
2396
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2397
-     * EVT_default_registration_status field matches the config setting for default_STS_ID.
2398
-     */
2399
-    public function set_default_reg_status_on_EEM_Event()
2400
-    {
2401
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2402
-    }
2403
-
2404
-
2405
-    /**
2406
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2407
-     * for Events matches the config setting for default_maximum_number_of_tickets
2408
-     */
2409
-    public function set_default_max_ticket_on_EEM_Event()
2410
-    {
2411
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2412
-    }
2413
-
2414
-
2415
-    /**
2416
-     * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2417
-     * constructed because that happens before we can get the privacy policy page's permalink.
2418
-     *
2419
-     * @throws InvalidArgumentException
2420
-     * @throws InvalidDataTypeException
2421
-     * @throws InvalidInterfaceException
2422
-     */
2423
-    public function setDefaultCheckboxLabelText()
2424
-    {
2425
-        if (
2426
-            $this->getConsentCheckboxLabelText() === null
2427
-            || $this->getConsentCheckboxLabelText() === ''
2428
-        ) {
2429
-            $opening_a_tag = '';
2430
-            $closing_a_tag = '';
2431
-            if (function_exists('get_privacy_policy_url')) {
2432
-                $privacy_page_url = get_privacy_policy_url();
2433
-                if (! empty($privacy_page_url)) {
2434
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2435
-                    $closing_a_tag = '</a>';
2436
-                }
2437
-            }
2438
-            $loader = LoaderFactory::getLoader();
2439
-            $org_config = $loader->getShared('EE_Organization_Config');
2440
-            /**
2441
-             * @var $org_config EE_Organization_Config
2442
-             */
2443
-
2444
-            $this->setConsentCheckboxLabelText(
2445
-                sprintf(
2446
-                    esc_html__(
2447
-                        'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2448
-                        'event_espresso'
2449
-                    ),
2450
-                    $org_config->name,
2451
-                    $opening_a_tag,
2452
-                    $closing_a_tag
2453
-                )
2454
-            );
2455
-        }
2456
-    }
2457
-
2458
-
2459
-    /**
2460
-     * @return boolean
2461
-     */
2462
-    public function track_invalid_checkout_access()
2463
-    {
2464
-        return $this->track_invalid_checkout_access;
2465
-    }
2466
-
2467
-
2468
-    /**
2469
-     * @param boolean $track_invalid_checkout_access
2470
-     */
2471
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2472
-    {
2473
-        $this->track_invalid_checkout_access = filter_var(
2474
-            $track_invalid_checkout_access,
2475
-            FILTER_VALIDATE_BOOLEAN
2476
-        );
2477
-    }
2478
-
2479
-    /**
2480
-     * @return boolean
2481
-     */
2482
-    public function copyAttendeeInfo()
2483
-    {
2484
-        return $this->copy_attendee_info;
2485
-    }
2486
-
2487
-
2488
-    /**
2489
-     * @param boolean $copy_attendee_info
2490
-     */
2491
-    public function setCopyAttendeeInfo($copy_attendee_info)
2492
-    {
2493
-        $this->copy_attendee_info = filter_var(
2494
-            $copy_attendee_info,
2495
-            FILTER_VALIDATE_BOOLEAN
2496
-        );
2497
-    }
2498
-
2499
-
2500
-    /**
2501
-     * Gets the options to make availalbe for the gateway log lifespan
2502
-     * @return array
2503
-     */
2504
-    public function gatewayLogLifespanOptions()
2505
-    {
2506
-        return (array) apply_filters(
2507
-            'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2508
-            array(
2509
-                '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2510
-                '1 day' => esc_html__('1 Day', 'event_espresso'),
2511
-                '7 days' => esc_html__('7 Days', 'event_espresso'),
2512
-                '14 days' => esc_html__('14 Days', 'event_espresso'),
2513
-                '30 days' => esc_html__('30 Days', 'event_espresso')
2514
-            )
2515
-        );
2516
-    }
2517
-
2518
-
2519
-    /**
2520
-     * @return bool
2521
-     */
2522
-    public function isConsentCheckboxEnabled()
2523
-    {
2524
-        return $this->consent_checkbox_enabled;
2525
-    }
2526
-
2527
-
2528
-    /**
2529
-     * @param bool $consent_checkbox_enabled
2530
-     */
2531
-    public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2532
-    {
2533
-        $this->consent_checkbox_enabled = filter_var(
2534
-            $consent_checkbox_enabled,
2535
-            FILTER_VALIDATE_BOOLEAN
2536
-        );
2537
-    }
2538
-
2539
-
2540
-    /**
2541
-     * @return string
2542
-     */
2543
-    public function getConsentCheckboxLabelText()
2544
-    {
2545
-        return $this->consent_checkbox_label_text;
2546
-    }
2547
-
2548
-
2549
-    /**
2550
-     * @param string $consent_checkbox_label_text
2551
-     */
2552
-    public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2553
-    {
2554
-        $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2555
-    }
2339
+	public $gateway_log_lifespan = '1 week';
2340
+
2341
+	/**
2342
+	 * Enable copy attendee info at form
2343
+	 *
2344
+	 * @var boolean $enable_copy_attendee
2345
+	 */
2346
+	protected $copy_attendee_info = true;
2347
+
2348
+
2349
+	/**
2350
+	 *    class constructor
2351
+	 *
2352
+	 * @access    public
2353
+	 */
2354
+	public function __construct()
2355
+	{
2356
+		// set default registration settings
2357
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2358
+		$this->email_validation_level = 'wp_default';
2359
+		$this->show_pending_payment_options = true;
2360
+		$this->skip_reg_confirmation = true;
2361
+		$this->reg_steps = array();
2362
+		$this->reg_confirmation_last = false;
2363
+		$this->use_bot_trap = true;
2364
+		$this->use_encryption = true;
2365
+		$this->use_captcha = false;
2366
+		$this->recaptcha_theme = 'light';
2367
+		$this->recaptcha_badge = 'bottomleft';
2368
+		$this->recaptcha_type = 'image';
2369
+		$this->recaptcha_language = 'en';
2370
+		$this->recaptcha_publickey = null;
2371
+		$this->recaptcha_privatekey = null;
2372
+		$this->recaptcha_protected_forms = array();
2373
+		$this->recaptcha_width = 500;
2374
+		$this->default_maximum_number_of_tickets = 10;
2375
+		$this->consent_checkbox_enabled = false;
2376
+		$this->consent_checkbox_label_text = '';
2377
+		$this->gateway_log_lifespan = '7 days';
2378
+		$this->copy_attendee_info = true;
2379
+	}
2380
+
2381
+
2382
+	/**
2383
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2384
+	 *
2385
+	 * @since 4.8.8.rc.019
2386
+	 */
2387
+	public function do_hooks()
2388
+	{
2389
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2390
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2391
+		add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2392
+	}
2393
+
2394
+
2395
+	/**
2396
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2397
+	 * EVT_default_registration_status field matches the config setting for default_STS_ID.
2398
+	 */
2399
+	public function set_default_reg_status_on_EEM_Event()
2400
+	{
2401
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2402
+	}
2403
+
2404
+
2405
+	/**
2406
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2407
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2408
+	 */
2409
+	public function set_default_max_ticket_on_EEM_Event()
2410
+	{
2411
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2412
+	}
2413
+
2414
+
2415
+	/**
2416
+	 * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2417
+	 * constructed because that happens before we can get the privacy policy page's permalink.
2418
+	 *
2419
+	 * @throws InvalidArgumentException
2420
+	 * @throws InvalidDataTypeException
2421
+	 * @throws InvalidInterfaceException
2422
+	 */
2423
+	public function setDefaultCheckboxLabelText()
2424
+	{
2425
+		if (
2426
+			$this->getConsentCheckboxLabelText() === null
2427
+			|| $this->getConsentCheckboxLabelText() === ''
2428
+		) {
2429
+			$opening_a_tag = '';
2430
+			$closing_a_tag = '';
2431
+			if (function_exists('get_privacy_policy_url')) {
2432
+				$privacy_page_url = get_privacy_policy_url();
2433
+				if (! empty($privacy_page_url)) {
2434
+					$opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2435
+					$closing_a_tag = '</a>';
2436
+				}
2437
+			}
2438
+			$loader = LoaderFactory::getLoader();
2439
+			$org_config = $loader->getShared('EE_Organization_Config');
2440
+			/**
2441
+			 * @var $org_config EE_Organization_Config
2442
+			 */
2443
+
2444
+			$this->setConsentCheckboxLabelText(
2445
+				sprintf(
2446
+					esc_html__(
2447
+						'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2448
+						'event_espresso'
2449
+					),
2450
+					$org_config->name,
2451
+					$opening_a_tag,
2452
+					$closing_a_tag
2453
+				)
2454
+			);
2455
+		}
2456
+	}
2457
+
2458
+
2459
+	/**
2460
+	 * @return boolean
2461
+	 */
2462
+	public function track_invalid_checkout_access()
2463
+	{
2464
+		return $this->track_invalid_checkout_access;
2465
+	}
2466
+
2467
+
2468
+	/**
2469
+	 * @param boolean $track_invalid_checkout_access
2470
+	 */
2471
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2472
+	{
2473
+		$this->track_invalid_checkout_access = filter_var(
2474
+			$track_invalid_checkout_access,
2475
+			FILTER_VALIDATE_BOOLEAN
2476
+		);
2477
+	}
2478
+
2479
+	/**
2480
+	 * @return boolean
2481
+	 */
2482
+	public function copyAttendeeInfo()
2483
+	{
2484
+		return $this->copy_attendee_info;
2485
+	}
2486
+
2487
+
2488
+	/**
2489
+	 * @param boolean $copy_attendee_info
2490
+	 */
2491
+	public function setCopyAttendeeInfo($copy_attendee_info)
2492
+	{
2493
+		$this->copy_attendee_info = filter_var(
2494
+			$copy_attendee_info,
2495
+			FILTER_VALIDATE_BOOLEAN
2496
+		);
2497
+	}
2498
+
2499
+
2500
+	/**
2501
+	 * Gets the options to make availalbe for the gateway log lifespan
2502
+	 * @return array
2503
+	 */
2504
+	public function gatewayLogLifespanOptions()
2505
+	{
2506
+		return (array) apply_filters(
2507
+			'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2508
+			array(
2509
+				'1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2510
+				'1 day' => esc_html__('1 Day', 'event_espresso'),
2511
+				'7 days' => esc_html__('7 Days', 'event_espresso'),
2512
+				'14 days' => esc_html__('14 Days', 'event_espresso'),
2513
+				'30 days' => esc_html__('30 Days', 'event_espresso')
2514
+			)
2515
+		);
2516
+	}
2517
+
2518
+
2519
+	/**
2520
+	 * @return bool
2521
+	 */
2522
+	public function isConsentCheckboxEnabled()
2523
+	{
2524
+		return $this->consent_checkbox_enabled;
2525
+	}
2526
+
2527
+
2528
+	/**
2529
+	 * @param bool $consent_checkbox_enabled
2530
+	 */
2531
+	public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2532
+	{
2533
+		$this->consent_checkbox_enabled = filter_var(
2534
+			$consent_checkbox_enabled,
2535
+			FILTER_VALIDATE_BOOLEAN
2536
+		);
2537
+	}
2538
+
2539
+
2540
+	/**
2541
+	 * @return string
2542
+	 */
2543
+	public function getConsentCheckboxLabelText()
2544
+	{
2545
+		return $this->consent_checkbox_label_text;
2546
+	}
2547
+
2548
+
2549
+	/**
2550
+	 * @param string $consent_checkbox_label_text
2551
+	 */
2552
+	public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2553
+	{
2554
+		$this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2555
+	}
2556 2556
 }
2557 2557
 
2558 2558
 /**
@@ -2560,143 +2560,143 @@  discard block
 block discarded – undo
2560 2560
  */
2561 2561
 class EE_Admin_Config extends EE_Config_Base
2562 2562
 {
2563
-    /**
2564
-     * @var boolean $use_personnel_manager
2565
-     */
2566
-    public $use_personnel_manager;
2567
-
2568
-    /**
2569
-     * @var boolean $use_dashboard_widget
2570
-     */
2571
-    public $use_dashboard_widget;
2572
-
2573
-    /**
2574
-     * @var int $events_in_dashboard
2575
-     */
2576
-    public $events_in_dashboard;
2577
-
2578
-    /**
2579
-     * @var boolean $use_event_timezones
2580
-     */
2581
-    public $use_event_timezones;
2582
-
2583
-    /**
2584
-     * @var string $log_file_name
2585
-     */
2586
-    public $log_file_name;
2587
-
2588
-    /**
2589
-     * @var string $debug_file_name
2590
-     */
2591
-    public $debug_file_name;
2592
-
2593
-    /**
2594
-     * @var boolean $use_remote_logging
2595
-     */
2596
-    public $use_remote_logging;
2597
-
2598
-    /**
2599
-     * @var string $remote_logging_url
2600
-     */
2601
-    public $remote_logging_url;
2602
-
2603
-    /**
2604
-     * @var boolean $show_reg_footer
2605
-     */
2606
-    public $show_reg_footer;
2607
-
2608
-    /**
2609
-     * @var string $affiliate_id
2610
-     */
2611
-    public $affiliate_id;
2612
-
2613
-    /**
2614
-     * adds extra layer of encoding to session data to prevent serialization errors
2615
-     * but is incompatible with some server configuration errors
2616
-     * if you get "500 internal server errors" during registration, try turning this on
2617
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2618
-     *
2619
-     * @var boolean $encode_session_data
2620
-     */
2621
-    private $encode_session_data = false;
2622
-
2623
-
2624
-    /**
2625
-     *    class constructor
2626
-     *
2627
-     * @access    public
2628
-     */
2629
-    public function __construct()
2630
-    {
2631
-        // set default general admin settings
2632
-        $this->use_personnel_manager = true;
2633
-        $this->use_dashboard_widget = true;
2634
-        $this->events_in_dashboard = 30;
2635
-        $this->use_event_timezones = false;
2636
-        $this->use_remote_logging = false;
2637
-        $this->remote_logging_url = null;
2638
-        $this->show_reg_footer = apply_filters(
2639
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
2640
-            false
2641
-        );
2642
-        $this->affiliate_id = 'default';
2643
-        $this->encode_session_data = false;
2644
-    }
2645
-
2646
-
2647
-    /**
2648
-     * @param bool $reset
2649
-     * @return string
2650
-     */
2651
-    public function log_file_name($reset = false)
2652
-    {
2653
-        if (empty($this->log_file_name) || $reset) {
2654
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2655
-            EE_Config::instance()->update_espresso_config(false, false);
2656
-        }
2657
-        return $this->log_file_name;
2658
-    }
2659
-
2660
-
2661
-    /**
2662
-     * @param bool $reset
2663
-     * @return string
2664
-     */
2665
-    public function debug_file_name($reset = false)
2666
-    {
2667
-        if (empty($this->debug_file_name) || $reset) {
2668
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2669
-            EE_Config::instance()->update_espresso_config(false, false);
2670
-        }
2671
-        return $this->debug_file_name;
2672
-    }
2673
-
2674
-
2675
-    /**
2676
-     * @return string
2677
-     */
2678
-    public function affiliate_id()
2679
-    {
2680
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2681
-    }
2682
-
2683
-
2684
-    /**
2685
-     * @return boolean
2686
-     */
2687
-    public function encode_session_data()
2688
-    {
2689
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2690
-    }
2691
-
2692
-
2693
-    /**
2694
-     * @param boolean $encode_session_data
2695
-     */
2696
-    public function set_encode_session_data($encode_session_data)
2697
-    {
2698
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2699
-    }
2563
+	/**
2564
+	 * @var boolean $use_personnel_manager
2565
+	 */
2566
+	public $use_personnel_manager;
2567
+
2568
+	/**
2569
+	 * @var boolean $use_dashboard_widget
2570
+	 */
2571
+	public $use_dashboard_widget;
2572
+
2573
+	/**
2574
+	 * @var int $events_in_dashboard
2575
+	 */
2576
+	public $events_in_dashboard;
2577
+
2578
+	/**
2579
+	 * @var boolean $use_event_timezones
2580
+	 */
2581
+	public $use_event_timezones;
2582
+
2583
+	/**
2584
+	 * @var string $log_file_name
2585
+	 */
2586
+	public $log_file_name;
2587
+
2588
+	/**
2589
+	 * @var string $debug_file_name
2590
+	 */
2591
+	public $debug_file_name;
2592
+
2593
+	/**
2594
+	 * @var boolean $use_remote_logging
2595
+	 */
2596
+	public $use_remote_logging;
2597
+
2598
+	/**
2599
+	 * @var string $remote_logging_url
2600
+	 */
2601
+	public $remote_logging_url;
2602
+
2603
+	/**
2604
+	 * @var boolean $show_reg_footer
2605
+	 */
2606
+	public $show_reg_footer;
2607
+
2608
+	/**
2609
+	 * @var string $affiliate_id
2610
+	 */
2611
+	public $affiliate_id;
2612
+
2613
+	/**
2614
+	 * adds extra layer of encoding to session data to prevent serialization errors
2615
+	 * but is incompatible with some server configuration errors
2616
+	 * if you get "500 internal server errors" during registration, try turning this on
2617
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2618
+	 *
2619
+	 * @var boolean $encode_session_data
2620
+	 */
2621
+	private $encode_session_data = false;
2622
+
2623
+
2624
+	/**
2625
+	 *    class constructor
2626
+	 *
2627
+	 * @access    public
2628
+	 */
2629
+	public function __construct()
2630
+	{
2631
+		// set default general admin settings
2632
+		$this->use_personnel_manager = true;
2633
+		$this->use_dashboard_widget = true;
2634
+		$this->events_in_dashboard = 30;
2635
+		$this->use_event_timezones = false;
2636
+		$this->use_remote_logging = false;
2637
+		$this->remote_logging_url = null;
2638
+		$this->show_reg_footer = apply_filters(
2639
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
2640
+			false
2641
+		);
2642
+		$this->affiliate_id = 'default';
2643
+		$this->encode_session_data = false;
2644
+	}
2645
+
2646
+
2647
+	/**
2648
+	 * @param bool $reset
2649
+	 * @return string
2650
+	 */
2651
+	public function log_file_name($reset = false)
2652
+	{
2653
+		if (empty($this->log_file_name) || $reset) {
2654
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2655
+			EE_Config::instance()->update_espresso_config(false, false);
2656
+		}
2657
+		return $this->log_file_name;
2658
+	}
2659
+
2660
+
2661
+	/**
2662
+	 * @param bool $reset
2663
+	 * @return string
2664
+	 */
2665
+	public function debug_file_name($reset = false)
2666
+	{
2667
+		if (empty($this->debug_file_name) || $reset) {
2668
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2669
+			EE_Config::instance()->update_espresso_config(false, false);
2670
+		}
2671
+		return $this->debug_file_name;
2672
+	}
2673
+
2674
+
2675
+	/**
2676
+	 * @return string
2677
+	 */
2678
+	public function affiliate_id()
2679
+	{
2680
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2681
+	}
2682
+
2683
+
2684
+	/**
2685
+	 * @return boolean
2686
+	 */
2687
+	public function encode_session_data()
2688
+	{
2689
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2690
+	}
2691
+
2692
+
2693
+	/**
2694
+	 * @param boolean $encode_session_data
2695
+	 */
2696
+	public function set_encode_session_data($encode_session_data)
2697
+	{
2698
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2699
+	}
2700 2700
 }
2701 2701
 
2702 2702
 /**
@@ -2704,70 +2704,70 @@  discard block
 block discarded – undo
2704 2704
  */
2705 2705
 class EE_Template_Config extends EE_Config_Base
2706 2706
 {
2707
-    /**
2708
-     * @var boolean $enable_default_style
2709
-     */
2710
-    public $enable_default_style;
2711
-
2712
-    /**
2713
-     * @var string $custom_style_sheet
2714
-     */
2715
-    public $custom_style_sheet;
2716
-
2717
-    /**
2718
-     * @var boolean $display_address_in_regform
2719
-     */
2720
-    public $display_address_in_regform;
2721
-
2722
-    /**
2723
-     * @var int $display_description_on_multi_reg_page
2724
-     */
2725
-    public $display_description_on_multi_reg_page;
2726
-
2727
-    /**
2728
-     * @var boolean $use_custom_templates
2729
-     */
2730
-    public $use_custom_templates;
2731
-
2732
-    /**
2733
-     * @var string $current_espresso_theme
2734
-     */
2735
-    public $current_espresso_theme;
2736
-
2737
-    /**
2738
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2739
-     */
2740
-    public $EED_Ticket_Selector;
2741
-
2742
-    /**
2743
-     * @var EE_Event_Single_Config $EED_Event_Single
2744
-     */
2745
-    public $EED_Event_Single;
2746
-
2747
-    /**
2748
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2749
-     */
2750
-    public $EED_Events_Archive;
2751
-
2752
-
2753
-    /**
2754
-     *    class constructor
2755
-     *
2756
-     * @access    public
2757
-     */
2758
-    public function __construct()
2759
-    {
2760
-        // set default template settings
2761
-        $this->enable_default_style = true;
2762
-        $this->custom_style_sheet = null;
2763
-        $this->display_address_in_regform = true;
2764
-        $this->display_description_on_multi_reg_page = false;
2765
-        $this->use_custom_templates = false;
2766
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2767
-        $this->EED_Event_Single = null;
2768
-        $this->EED_Events_Archive = null;
2769
-        $this->EED_Ticket_Selector = null;
2770
-    }
2707
+	/**
2708
+	 * @var boolean $enable_default_style
2709
+	 */
2710
+	public $enable_default_style;
2711
+
2712
+	/**
2713
+	 * @var string $custom_style_sheet
2714
+	 */
2715
+	public $custom_style_sheet;
2716
+
2717
+	/**
2718
+	 * @var boolean $display_address_in_regform
2719
+	 */
2720
+	public $display_address_in_regform;
2721
+
2722
+	/**
2723
+	 * @var int $display_description_on_multi_reg_page
2724
+	 */
2725
+	public $display_description_on_multi_reg_page;
2726
+
2727
+	/**
2728
+	 * @var boolean $use_custom_templates
2729
+	 */
2730
+	public $use_custom_templates;
2731
+
2732
+	/**
2733
+	 * @var string $current_espresso_theme
2734
+	 */
2735
+	public $current_espresso_theme;
2736
+
2737
+	/**
2738
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2739
+	 */
2740
+	public $EED_Ticket_Selector;
2741
+
2742
+	/**
2743
+	 * @var EE_Event_Single_Config $EED_Event_Single
2744
+	 */
2745
+	public $EED_Event_Single;
2746
+
2747
+	/**
2748
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2749
+	 */
2750
+	public $EED_Events_Archive;
2751
+
2752
+
2753
+	/**
2754
+	 *    class constructor
2755
+	 *
2756
+	 * @access    public
2757
+	 */
2758
+	public function __construct()
2759
+	{
2760
+		// set default template settings
2761
+		$this->enable_default_style = true;
2762
+		$this->custom_style_sheet = null;
2763
+		$this->display_address_in_regform = true;
2764
+		$this->display_description_on_multi_reg_page = false;
2765
+		$this->use_custom_templates = false;
2766
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2767
+		$this->EED_Event_Single = null;
2768
+		$this->EED_Events_Archive = null;
2769
+		$this->EED_Ticket_Selector = null;
2770
+	}
2771 2771
 }
2772 2772
 
2773 2773
 /**
@@ -2775,114 +2775,114 @@  discard block
 block discarded – undo
2775 2775
  */
2776 2776
 class EE_Map_Config extends EE_Config_Base
2777 2777
 {
2778
-    /**
2779
-     * @var boolean $use_google_maps
2780
-     */
2781
-    public $use_google_maps;
2782
-
2783
-    /**
2784
-     * @var string $api_key
2785
-     */
2786
-    public $google_map_api_key;
2787
-
2788
-    /**
2789
-     * @var int $event_details_map_width
2790
-     */
2791
-    public $event_details_map_width;
2792
-
2793
-    /**
2794
-     * @var int $event_details_map_height
2795
-     */
2796
-    public $event_details_map_height;
2797
-
2798
-    /**
2799
-     * @var int $event_details_map_zoom
2800
-     */
2801
-    public $event_details_map_zoom;
2802
-
2803
-    /**
2804
-     * @var boolean $event_details_display_nav
2805
-     */
2806
-    public $event_details_display_nav;
2807
-
2808
-    /**
2809
-     * @var boolean $event_details_nav_size
2810
-     */
2811
-    public $event_details_nav_size;
2812
-
2813
-    /**
2814
-     * @var string $event_details_control_type
2815
-     */
2816
-    public $event_details_control_type;
2817
-
2818
-    /**
2819
-     * @var string $event_details_map_align
2820
-     */
2821
-    public $event_details_map_align;
2822
-
2823
-    /**
2824
-     * @var int $event_list_map_width
2825
-     */
2826
-    public $event_list_map_width;
2827
-
2828
-    /**
2829
-     * @var int $event_list_map_height
2830
-     */
2831
-    public $event_list_map_height;
2832
-
2833
-    /**
2834
-     * @var int $event_list_map_zoom
2835
-     */
2836
-    public $event_list_map_zoom;
2837
-
2838
-    /**
2839
-     * @var boolean $event_list_display_nav
2840
-     */
2841
-    public $event_list_display_nav;
2842
-
2843
-    /**
2844
-     * @var boolean $event_list_nav_size
2845
-     */
2846
-    public $event_list_nav_size;
2847
-
2848
-    /**
2849
-     * @var string $event_list_control_type
2850
-     */
2851
-    public $event_list_control_type;
2852
-
2853
-    /**
2854
-     * @var string $event_list_map_align
2855
-     */
2856
-    public $event_list_map_align;
2857
-
2858
-
2859
-    /**
2860
-     *    class constructor
2861
-     *
2862
-     * @access    public
2863
-     */
2864
-    public function __construct()
2865
-    {
2866
-        // set default map settings
2867
-        $this->use_google_maps = true;
2868
-        $this->google_map_api_key = '';
2869
-        // for event details pages (reg page)
2870
-        $this->event_details_map_width = 585;            // ee_map_width_single
2871
-        $this->event_details_map_height = 362;            // ee_map_height_single
2872
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2873
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2874
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2875
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2876
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2877
-        // for event list pages
2878
-        $this->event_list_map_width = 300;            // ee_map_width
2879
-        $this->event_list_map_height = 185;        // ee_map_height
2880
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2881
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2882
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2883
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2884
-        $this->event_list_map_align = 'center';            // ee_map_align
2885
-    }
2778
+	/**
2779
+	 * @var boolean $use_google_maps
2780
+	 */
2781
+	public $use_google_maps;
2782
+
2783
+	/**
2784
+	 * @var string $api_key
2785
+	 */
2786
+	public $google_map_api_key;
2787
+
2788
+	/**
2789
+	 * @var int $event_details_map_width
2790
+	 */
2791
+	public $event_details_map_width;
2792
+
2793
+	/**
2794
+	 * @var int $event_details_map_height
2795
+	 */
2796
+	public $event_details_map_height;
2797
+
2798
+	/**
2799
+	 * @var int $event_details_map_zoom
2800
+	 */
2801
+	public $event_details_map_zoom;
2802
+
2803
+	/**
2804
+	 * @var boolean $event_details_display_nav
2805
+	 */
2806
+	public $event_details_display_nav;
2807
+
2808
+	/**
2809
+	 * @var boolean $event_details_nav_size
2810
+	 */
2811
+	public $event_details_nav_size;
2812
+
2813
+	/**
2814
+	 * @var string $event_details_control_type
2815
+	 */
2816
+	public $event_details_control_type;
2817
+
2818
+	/**
2819
+	 * @var string $event_details_map_align
2820
+	 */
2821
+	public $event_details_map_align;
2822
+
2823
+	/**
2824
+	 * @var int $event_list_map_width
2825
+	 */
2826
+	public $event_list_map_width;
2827
+
2828
+	/**
2829
+	 * @var int $event_list_map_height
2830
+	 */
2831
+	public $event_list_map_height;
2832
+
2833
+	/**
2834
+	 * @var int $event_list_map_zoom
2835
+	 */
2836
+	public $event_list_map_zoom;
2837
+
2838
+	/**
2839
+	 * @var boolean $event_list_display_nav
2840
+	 */
2841
+	public $event_list_display_nav;
2842
+
2843
+	/**
2844
+	 * @var boolean $event_list_nav_size
2845
+	 */
2846
+	public $event_list_nav_size;
2847
+
2848
+	/**
2849
+	 * @var string $event_list_control_type
2850
+	 */
2851
+	public $event_list_control_type;
2852
+
2853
+	/**
2854
+	 * @var string $event_list_map_align
2855
+	 */
2856
+	public $event_list_map_align;
2857
+
2858
+
2859
+	/**
2860
+	 *    class constructor
2861
+	 *
2862
+	 * @access    public
2863
+	 */
2864
+	public function __construct()
2865
+	{
2866
+		// set default map settings
2867
+		$this->use_google_maps = true;
2868
+		$this->google_map_api_key = '';
2869
+		// for event details pages (reg page)
2870
+		$this->event_details_map_width = 585;            // ee_map_width_single
2871
+		$this->event_details_map_height = 362;            // ee_map_height_single
2872
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2873
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2874
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2875
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2876
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2877
+		// for event list pages
2878
+		$this->event_list_map_width = 300;            // ee_map_width
2879
+		$this->event_list_map_height = 185;        // ee_map_height
2880
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2881
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2882
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2883
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2884
+		$this->event_list_map_align = 'center';            // ee_map_align
2885
+	}
2886 2886
 }
2887 2887
 
2888 2888
 /**
@@ -2890,46 +2890,46 @@  discard block
 block discarded – undo
2890 2890
  */
2891 2891
 class EE_Events_Archive_Config extends EE_Config_Base
2892 2892
 {
2893
-    public $display_status_banner;
2893
+	public $display_status_banner;
2894 2894
 
2895
-    public $display_description;
2895
+	public $display_description;
2896 2896
 
2897
-    public $display_ticket_selector;
2897
+	public $display_ticket_selector;
2898 2898
 
2899
-    public $display_datetimes;
2899
+	public $display_datetimes;
2900 2900
 
2901
-    public $display_venue;
2901
+	public $display_venue;
2902 2902
 
2903
-    public $display_expired_events;
2903
+	public $display_expired_events;
2904 2904
 
2905
-    public $use_sortable_display_order;
2905
+	public $use_sortable_display_order;
2906 2906
 
2907
-    public $display_order_tickets;
2907
+	public $display_order_tickets;
2908 2908
 
2909
-    public $display_order_datetimes;
2909
+	public $display_order_datetimes;
2910 2910
 
2911
-    public $display_order_event;
2911
+	public $display_order_event;
2912 2912
 
2913
-    public $display_order_venue;
2913
+	public $display_order_venue;
2914 2914
 
2915 2915
 
2916
-    /**
2917
-     *    class constructor
2918
-     */
2919
-    public function __construct()
2920
-    {
2921
-        $this->display_status_banner = 0;
2922
-        $this->display_description = 1;
2923
-        $this->display_ticket_selector = 0;
2924
-        $this->display_datetimes = 1;
2925
-        $this->display_venue = 0;
2926
-        $this->display_expired_events = 0;
2927
-        $this->use_sortable_display_order = false;
2928
-        $this->display_order_tickets = 100;
2929
-        $this->display_order_datetimes = 110;
2930
-        $this->display_order_event = 120;
2931
-        $this->display_order_venue = 130;
2932
-    }
2916
+	/**
2917
+	 *    class constructor
2918
+	 */
2919
+	public function __construct()
2920
+	{
2921
+		$this->display_status_banner = 0;
2922
+		$this->display_description = 1;
2923
+		$this->display_ticket_selector = 0;
2924
+		$this->display_datetimes = 1;
2925
+		$this->display_venue = 0;
2926
+		$this->display_expired_events = 0;
2927
+		$this->use_sortable_display_order = false;
2928
+		$this->display_order_tickets = 100;
2929
+		$this->display_order_datetimes = 110;
2930
+		$this->display_order_event = 120;
2931
+		$this->display_order_venue = 130;
2932
+	}
2933 2933
 }
2934 2934
 
2935 2935
 /**
@@ -2937,34 +2937,34 @@  discard block
 block discarded – undo
2937 2937
  */
2938 2938
 class EE_Event_Single_Config extends EE_Config_Base
2939 2939
 {
2940
-    public $display_status_banner_single;
2940
+	public $display_status_banner_single;
2941 2941
 
2942
-    public $display_venue;
2942
+	public $display_venue;
2943 2943
 
2944
-    public $use_sortable_display_order;
2944
+	public $use_sortable_display_order;
2945 2945
 
2946
-    public $display_order_tickets;
2946
+	public $display_order_tickets;
2947 2947
 
2948
-    public $display_order_datetimes;
2948
+	public $display_order_datetimes;
2949 2949
 
2950
-    public $display_order_event;
2950
+	public $display_order_event;
2951 2951
 
2952
-    public $display_order_venue;
2952
+	public $display_order_venue;
2953 2953
 
2954 2954
 
2955
-    /**
2956
-     *    class constructor
2957
-     */
2958
-    public function __construct()
2959
-    {
2960
-        $this->display_status_banner_single = 0;
2961
-        $this->display_venue = 1;
2962
-        $this->use_sortable_display_order = false;
2963
-        $this->display_order_tickets = 100;
2964
-        $this->display_order_datetimes = 110;
2965
-        $this->display_order_event = 120;
2966
-        $this->display_order_venue = 130;
2967
-    }
2955
+	/**
2956
+	 *    class constructor
2957
+	 */
2958
+	public function __construct()
2959
+	{
2960
+		$this->display_status_banner_single = 0;
2961
+		$this->display_venue = 1;
2962
+		$this->use_sortable_display_order = false;
2963
+		$this->display_order_tickets = 100;
2964
+		$this->display_order_datetimes = 110;
2965
+		$this->display_order_event = 120;
2966
+		$this->display_order_venue = 130;
2967
+	}
2968 2968
 }
2969 2969
 
2970 2970
 /**
@@ -2972,172 +2972,172 @@  discard block
 block discarded – undo
2972 2972
  */
2973 2973
 class EE_Ticket_Selector_Config extends EE_Config_Base
2974 2974
 {
2975
-    /**
2976
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2977
-     */
2978
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2979
-
2980
-    /**
2981
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2982
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2983
-     */
2984
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2985
-
2986
-    /**
2987
-     * @var boolean $show_ticket_sale_columns
2988
-     */
2989
-    public $show_ticket_sale_columns;
2990
-
2991
-    /**
2992
-     * @var boolean $show_ticket_details
2993
-     */
2994
-    public $show_ticket_details;
2995
-
2996
-    /**
2997
-     * @var boolean $show_expired_tickets
2998
-     */
2999
-    public $show_expired_tickets;
3000
-
3001
-    /**
3002
-     * whether or not to display a dropdown box populated with event datetimes
3003
-     * that toggles which tickets are displayed for a ticket selector.
3004
-     * uses one of the *_DATETIME_SELECTOR constants defined above
3005
-     *
3006
-     * @var string $show_datetime_selector
3007
-     */
3008
-    private $show_datetime_selector = 'no_datetime_selector';
3009
-
3010
-    /**
3011
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
3012
-     *
3013
-     * @var int $datetime_selector_threshold
3014
-     */
3015
-    private $datetime_selector_threshold = 3;
3016
-
3017
-    /**
3018
-     * determines the maximum number of "checked" dates in the date and time filter
3019
-     *
3020
-     * @var int $datetime_selector_checked
3021
-     */
3022
-    private $datetime_selector_max_checked = 10;
3023
-
3024
-
3025
-    /**
3026
-     *    class constructor
3027
-     */
3028
-    public function __construct()
3029
-    {
3030
-        $this->show_ticket_sale_columns = true;
3031
-        $this->show_ticket_details = true;
3032
-        $this->show_expired_tickets = true;
3033
-        $this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3034
-        $this->datetime_selector_threshold = 3;
3035
-        $this->datetime_selector_max_checked = 10;
3036
-    }
3037
-
3038
-
3039
-    /**
3040
-     * returns true if a datetime selector should be displayed
3041
-     *
3042
-     * @param array $datetimes
3043
-     * @return bool
3044
-     */
3045
-    public function showDatetimeSelector(array $datetimes)
3046
-    {
3047
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3048
-        return ! (
3049
-            $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3050
-            || (
3051
-                $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3052
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3053
-            )
3054
-        );
3055
-    }
3056
-
3057
-
3058
-    /**
3059
-     * @return string
3060
-     */
3061
-    public function getShowDatetimeSelector()
3062
-    {
3063
-        return $this->show_datetime_selector;
3064
-    }
3065
-
3066
-
3067
-    /**
3068
-     * @param bool $keys_only
3069
-     * @return array
3070
-     */
3071
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3072
-    {
3073
-        return $keys_only
3074
-            ? array(
3075
-                EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3076
-                EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3077
-            )
3078
-            : array(
3079
-                EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3080
-                    'Do not show date & time filter',
3081
-                    'event_espresso'
3082
-                ),
3083
-                EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3084
-                    'Maybe show date & time filter',
3085
-                    'event_espresso'
3086
-                ),
3087
-            );
3088
-    }
3089
-
3090
-
3091
-    /**
3092
-     * @param string $show_datetime_selector
3093
-     */
3094
-    public function setShowDatetimeSelector($show_datetime_selector)
3095
-    {
3096
-        $this->show_datetime_selector = in_array(
3097
-            $show_datetime_selector,
3098
-            $this->getShowDatetimeSelectorOptions(),
3099
-            true
3100
-        )
3101
-            ? $show_datetime_selector
3102
-            : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3103
-    }
3104
-
3105
-
3106
-    /**
3107
-     * @return int
3108
-     */
3109
-    public function getDatetimeSelectorThreshold()
3110
-    {
3111
-        return $this->datetime_selector_threshold;
3112
-    }
3113
-
3114
-
3115
-    /**
3116
-     * @param int $datetime_selector_threshold
3117
-     */
3118
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3119
-    {
3120
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3121
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3122
-    }
3123
-
3124
-
3125
-    /**
3126
-     * @return int
3127
-     */
3128
-    public function getDatetimeSelectorMaxChecked()
3129
-    {
3130
-        return $this->datetime_selector_max_checked;
3131
-    }
3132
-
3133
-
3134
-    /**
3135
-     * @param int $datetime_selector_max_checked
3136
-     */
3137
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3138
-    {
3139
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3140
-    }
2975
+	/**
2976
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2977
+	 */
2978
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2979
+
2980
+	/**
2981
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2982
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2983
+	 */
2984
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2985
+
2986
+	/**
2987
+	 * @var boolean $show_ticket_sale_columns
2988
+	 */
2989
+	public $show_ticket_sale_columns;
2990
+
2991
+	/**
2992
+	 * @var boolean $show_ticket_details
2993
+	 */
2994
+	public $show_ticket_details;
2995
+
2996
+	/**
2997
+	 * @var boolean $show_expired_tickets
2998
+	 */
2999
+	public $show_expired_tickets;
3000
+
3001
+	/**
3002
+	 * whether or not to display a dropdown box populated with event datetimes
3003
+	 * that toggles which tickets are displayed for a ticket selector.
3004
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
3005
+	 *
3006
+	 * @var string $show_datetime_selector
3007
+	 */
3008
+	private $show_datetime_selector = 'no_datetime_selector';
3009
+
3010
+	/**
3011
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
3012
+	 *
3013
+	 * @var int $datetime_selector_threshold
3014
+	 */
3015
+	private $datetime_selector_threshold = 3;
3016
+
3017
+	/**
3018
+	 * determines the maximum number of "checked" dates in the date and time filter
3019
+	 *
3020
+	 * @var int $datetime_selector_checked
3021
+	 */
3022
+	private $datetime_selector_max_checked = 10;
3023
+
3024
+
3025
+	/**
3026
+	 *    class constructor
3027
+	 */
3028
+	public function __construct()
3029
+	{
3030
+		$this->show_ticket_sale_columns = true;
3031
+		$this->show_ticket_details = true;
3032
+		$this->show_expired_tickets = true;
3033
+		$this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3034
+		$this->datetime_selector_threshold = 3;
3035
+		$this->datetime_selector_max_checked = 10;
3036
+	}
3037
+
3038
+
3039
+	/**
3040
+	 * returns true if a datetime selector should be displayed
3041
+	 *
3042
+	 * @param array $datetimes
3043
+	 * @return bool
3044
+	 */
3045
+	public function showDatetimeSelector(array $datetimes)
3046
+	{
3047
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3048
+		return ! (
3049
+			$this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3050
+			|| (
3051
+				$this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3052
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3053
+			)
3054
+		);
3055
+	}
3056
+
3057
+
3058
+	/**
3059
+	 * @return string
3060
+	 */
3061
+	public function getShowDatetimeSelector()
3062
+	{
3063
+		return $this->show_datetime_selector;
3064
+	}
3065
+
3066
+
3067
+	/**
3068
+	 * @param bool $keys_only
3069
+	 * @return array
3070
+	 */
3071
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3072
+	{
3073
+		return $keys_only
3074
+			? array(
3075
+				EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3076
+				EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3077
+			)
3078
+			: array(
3079
+				EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3080
+					'Do not show date & time filter',
3081
+					'event_espresso'
3082
+				),
3083
+				EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3084
+					'Maybe show date & time filter',
3085
+					'event_espresso'
3086
+				),
3087
+			);
3088
+	}
3089
+
3090
+
3091
+	/**
3092
+	 * @param string $show_datetime_selector
3093
+	 */
3094
+	public function setShowDatetimeSelector($show_datetime_selector)
3095
+	{
3096
+		$this->show_datetime_selector = in_array(
3097
+			$show_datetime_selector,
3098
+			$this->getShowDatetimeSelectorOptions(),
3099
+			true
3100
+		)
3101
+			? $show_datetime_selector
3102
+			: EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3103
+	}
3104
+
3105
+
3106
+	/**
3107
+	 * @return int
3108
+	 */
3109
+	public function getDatetimeSelectorThreshold()
3110
+	{
3111
+		return $this->datetime_selector_threshold;
3112
+	}
3113
+
3114
+
3115
+	/**
3116
+	 * @param int $datetime_selector_threshold
3117
+	 */
3118
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3119
+	{
3120
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3121
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3122
+	}
3123
+
3124
+
3125
+	/**
3126
+	 * @return int
3127
+	 */
3128
+	public function getDatetimeSelectorMaxChecked()
3129
+	{
3130
+		return $this->datetime_selector_max_checked;
3131
+	}
3132
+
3133
+
3134
+	/**
3135
+	 * @param int $datetime_selector_max_checked
3136
+	 */
3137
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3138
+	{
3139
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3140
+	}
3141 3141
 }
3142 3142
 
3143 3143
 /**
@@ -3149,87 +3149,87 @@  discard block
 block discarded – undo
3149 3149
  */
3150 3150
 class EE_Environment_Config extends EE_Config_Base
3151 3151
 {
3152
-    /**
3153
-     * Hold any php environment variables that we want to track.
3154
-     *
3155
-     * @var stdClass;
3156
-     */
3157
-    public $php;
3158
-
3159
-
3160
-    /**
3161
-     *    constructor
3162
-     */
3163
-    public function __construct()
3164
-    {
3165
-        $this->php = new stdClass();
3166
-        $this->_set_php_values();
3167
-    }
3168
-
3169
-
3170
-    /**
3171
-     * This sets the php environment variables.
3172
-     *
3173
-     * @since 4.4.0
3174
-     * @return void
3175
-     */
3176
-    protected function _set_php_values()
3177
-    {
3178
-        $this->php->max_input_vars = ini_get('max_input_vars');
3179
-        $this->php->version = phpversion();
3180
-    }
3181
-
3182
-
3183
-    /**
3184
-     * helper method for determining whether input_count is
3185
-     * reaching the potential maximum the server can handle
3186
-     * according to max_input_vars
3187
-     *
3188
-     * @param int   $input_count the count of input vars.
3189
-     * @return array {
3190
-     *                           An array that represents whether available space and if no available space the error
3191
-     *                           message.
3192
-     * @type bool   $has_space   whether more inputs can be added.
3193
-     * @type string $msg         Any message to be displayed.
3194
-     *                           }
3195
-     */
3196
-    public function max_input_vars_limit_check($input_count = 0)
3197
-    {
3198
-        if (
3199
-            ! empty($this->php->max_input_vars)
3200
-            && ($input_count >= $this->php->max_input_vars)
3201
-        ) {
3202
-            // check the server setting because the config value could be stale
3203
-            $max_input_vars = ini_get('max_input_vars');
3204
-            if ($input_count >= $max_input_vars) {
3205
-                return sprintf(
3206
-                    esc_html__(
3207
-                        'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3208
-                        'event_espresso'
3209
-                    ),
3210
-                    '<br>',
3211
-                    $input_count,
3212
-                    $max_input_vars
3213
-                );
3214
-            } else {
3215
-                return '';
3216
-            }
3217
-        } else {
3218
-            return '';
3219
-        }
3220
-    }
3221
-
3222
-
3223
-    /**
3224
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3225
-     *
3226
-     * @since 4.4.1
3227
-     * @return void
3228
-     */
3229
-    public function recheck_values()
3230
-    {
3231
-        $this->_set_php_values();
3232
-    }
3152
+	/**
3153
+	 * Hold any php environment variables that we want to track.
3154
+	 *
3155
+	 * @var stdClass;
3156
+	 */
3157
+	public $php;
3158
+
3159
+
3160
+	/**
3161
+	 *    constructor
3162
+	 */
3163
+	public function __construct()
3164
+	{
3165
+		$this->php = new stdClass();
3166
+		$this->_set_php_values();
3167
+	}
3168
+
3169
+
3170
+	/**
3171
+	 * This sets the php environment variables.
3172
+	 *
3173
+	 * @since 4.4.0
3174
+	 * @return void
3175
+	 */
3176
+	protected function _set_php_values()
3177
+	{
3178
+		$this->php->max_input_vars = ini_get('max_input_vars');
3179
+		$this->php->version = phpversion();
3180
+	}
3181
+
3182
+
3183
+	/**
3184
+	 * helper method for determining whether input_count is
3185
+	 * reaching the potential maximum the server can handle
3186
+	 * according to max_input_vars
3187
+	 *
3188
+	 * @param int   $input_count the count of input vars.
3189
+	 * @return array {
3190
+	 *                           An array that represents whether available space and if no available space the error
3191
+	 *                           message.
3192
+	 * @type bool   $has_space   whether more inputs can be added.
3193
+	 * @type string $msg         Any message to be displayed.
3194
+	 *                           }
3195
+	 */
3196
+	public function max_input_vars_limit_check($input_count = 0)
3197
+	{
3198
+		if (
3199
+			! empty($this->php->max_input_vars)
3200
+			&& ($input_count >= $this->php->max_input_vars)
3201
+		) {
3202
+			// check the server setting because the config value could be stale
3203
+			$max_input_vars = ini_get('max_input_vars');
3204
+			if ($input_count >= $max_input_vars) {
3205
+				return sprintf(
3206
+					esc_html__(
3207
+						'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3208
+						'event_espresso'
3209
+					),
3210
+					'<br>',
3211
+					$input_count,
3212
+					$max_input_vars
3213
+				);
3214
+			} else {
3215
+				return '';
3216
+			}
3217
+		} else {
3218
+			return '';
3219
+		}
3220
+	}
3221
+
3222
+
3223
+	/**
3224
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3225
+	 *
3226
+	 * @since 4.4.1
3227
+	 * @return void
3228
+	 */
3229
+	public function recheck_values()
3230
+	{
3231
+		$this->_set_php_values();
3232
+	}
3233 3233
 }
3234 3234
 
3235 3235
 /**
@@ -3241,21 +3241,21 @@  discard block
 block discarded – undo
3241 3241
  */
3242 3242
 class EE_Tax_Config extends EE_Config_Base
3243 3243
 {
3244
-    /*
3244
+	/*
3245 3245
      * flag to indicate whether or not to display ticket prices with the taxes included
3246 3246
      *
3247 3247
      * @var boolean $prices_displayed_including_taxes
3248 3248
      */
3249
-    public $prices_displayed_including_taxes;
3249
+	public $prices_displayed_including_taxes;
3250 3250
 
3251 3251
 
3252
-    /**
3253
-     *    class constructor
3254
-     */
3255
-    public function __construct()
3256
-    {
3257
-        $this->prices_displayed_including_taxes = true;
3258
-    }
3252
+	/**
3253
+	 *    class constructor
3254
+	 */
3255
+	public function __construct()
3256
+	{
3257
+		$this->prices_displayed_including_taxes = true;
3258
+	}
3259 3259
 }
3260 3260
 
3261 3261
 /**
@@ -3268,19 +3268,19 @@  discard block
 block discarded – undo
3268 3268
  */
3269 3269
 class EE_Messages_Config extends EE_Config_Base
3270 3270
 {
3271
-    /**
3272
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3273
-     * A value of 0 represents never deleting.  Default is 0.
3274
-     *
3275
-     * @var integer
3276
-     */
3277
-    public $delete_threshold;
3278
-
3279
-
3280
-    public function __construct()
3281
-    {
3282
-        $this->delete_threshold = 0;
3283
-    }
3271
+	/**
3272
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3273
+	 * A value of 0 represents never deleting.  Default is 0.
3274
+	 *
3275
+	 * @var integer
3276
+	 */
3277
+	public $delete_threshold;
3278
+
3279
+
3280
+	public function __construct()
3281
+	{
3282
+		$this->delete_threshold = 0;
3283
+	}
3284 3284
 }
3285 3285
 
3286 3286
 /**
@@ -3290,31 +3290,31 @@  discard block
 block discarded – undo
3290 3290
  */
3291 3291
 class EE_Gateway_Config extends EE_Config_Base
3292 3292
 {
3293
-    /**
3294
-     * Array with keys that are payment gateways slugs, and values are arrays
3295
-     * with any config info the gateway wants to store
3296
-     *
3297
-     * @var array
3298
-     */
3299
-    public $payment_settings;
3300
-
3301
-    /**
3302
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3303
-     * the gateway is stored in the uploads directory
3304
-     *
3305
-     * @var array
3306
-     */
3307
-    public $active_gateways;
3308
-
3309
-
3310
-    /**
3311
-     *    class constructor
3312
-     *
3313
-     * @deprecated
3314
-     */
3315
-    public function __construct()
3316
-    {
3317
-        $this->payment_settings = array();
3318
-        $this->active_gateways = array('Invoice' => false);
3319
-    }
3293
+	/**
3294
+	 * Array with keys that are payment gateways slugs, and values are arrays
3295
+	 * with any config info the gateway wants to store
3296
+	 *
3297
+	 * @var array
3298
+	 */
3299
+	public $payment_settings;
3300
+
3301
+	/**
3302
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3303
+	 * the gateway is stored in the uploads directory
3304
+	 *
3305
+	 * @var array
3306
+	 */
3307
+	public $active_gateways;
3308
+
3309
+
3310
+	/**
3311
+	 *    class constructor
3312
+	 *
3313
+	 * @deprecated
3314
+	 */
3315
+	public function __construct()
3316
+	{
3317
+		$this->payment_settings = array();
3318
+		$this->active_gateways = array('Invoice' => false);
3319
+	}
3320 3320
 }
Please login to merge, or discard this patch.
core/CPTs/CptQueryModifier.php 2 patches
Indentation   +578 added lines, -578 removed lines patch added patch discarded remove patch
@@ -30,582 +30,582 @@
 block discarded – undo
30 30
  */
31 31
 class CptQueryModifier
32 32
 {
33
-    /**
34
-     * @var CurrentPage $current_page
35
-     */
36
-    protected $current_page;
37
-
38
-    /**
39
-     * @var string $post_type
40
-     */
41
-    protected $post_type = '';
42
-
43
-    /**
44
-     * CPT details from CustomPostTypeDefinitions for specific post type
45
-     *
46
-     * @var array $cpt_details
47
-     */
48
-    protected $cpt_details = array();
49
-
50
-    /**
51
-     * @var EE_Table_Base[] $model_tables
52
-     */
53
-    protected $model_tables = array();
54
-
55
-    /**
56
-     * @var array $taxonomies
57
-     */
58
-    protected $taxonomies = array();
59
-
60
-    /**
61
-     * meta table for the related CPT
62
-     *
63
-     * @var EE_Secondary_Table $meta_table
64
-     */
65
-    protected $meta_table;
66
-
67
-    /**
68
-     * EEM_CPT_Base model for the related CPT
69
-     *
70
-     * @var EEM_CPT_Base $model
71
-     */
72
-    protected $model;
73
-
74
-    /**
75
-     * @var EE_Request_Handler $request_handler
76
-     */
77
-    protected $request_handler;
78
-
79
-    /**
80
-     * @var WP_Query $wp_query
81
-     */
82
-    protected $wp_query;
83
-
84
-    /**
85
-     * @var LoaderInterface $loader
86
-     */
87
-    protected $loader;
88
-
89
-    /**
90
-     * @var RequestInterface $request
91
-     */
92
-    protected $request;
93
-
94
-
95
-    /**
96
-     * CptQueryModifier constructor
97
-     *
98
-     * @param string             $post_type
99
-     * @param array              $cpt_details
100
-     * @param WP_Query           $WP_Query
101
-     * @param CurrentPage $current_page
102
-     * @param RequestInterface   $request
103
-     * @param LoaderInterface    $loader
104
-     * @throws EE_Error
105
-     */
106
-    public function __construct(
107
-        $post_type,
108
-        array $cpt_details,
109
-        WP_Query $WP_Query,
110
-        CurrentPage $current_page,
111
-        RequestInterface $request,
112
-        LoaderInterface $loader
113
-    ) {
114
-        $this->loader = $loader;
115
-        $this->request = $request;
116
-        $this->current_page = $current_page;
117
-        $this->setWpQuery($WP_Query);
118
-        $this->setPostType($post_type);
119
-        $this->setCptDetails($cpt_details);
120
-        $this->init();
121
-    }
122
-
123
-
124
-    /**
125
-     * @return string
126
-     */
127
-    public function postType()
128
-    {
129
-        return $this->post_type;
130
-    }
131
-
132
-
133
-    /**
134
-     * @param string $post_type
135
-     */
136
-    protected function setPostType($post_type)
137
-    {
138
-        $this->post_type = $post_type;
139
-    }
140
-
141
-
142
-    /**
143
-     * @return array
144
-     */
145
-    public function cptDetails()
146
-    {
147
-        return $this->cpt_details;
148
-    }
149
-
150
-
151
-    /**
152
-     * @param array $cpt_details
153
-     */
154
-    protected function setCptDetails($cpt_details)
155
-    {
156
-        $this->cpt_details = $cpt_details;
157
-    }
158
-
159
-
160
-    /**
161
-     * @return EE_Table_Base[]
162
-     */
163
-    public function modelTables()
164
-    {
165
-        return $this->model_tables;
166
-    }
167
-
168
-
169
-    /**
170
-     * @param EE_Table_Base[] $model_tables
171
-     */
172
-    protected function setModelTables($model_tables)
173
-    {
174
-        $this->model_tables = $model_tables;
175
-    }
176
-
177
-
178
-    /**
179
-     * @return array
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidDataTypeException
182
-     * @throws InvalidInterfaceException
183
-     */
184
-    public function taxonomies()
185
-    {
186
-        if (empty($this->taxonomies)) {
187
-            $this->initializeTaxonomies();
188
-        }
189
-        return $this->taxonomies;
190
-    }
191
-
192
-
193
-    /**
194
-     * @param array $taxonomies
195
-     */
196
-    protected function setTaxonomies(array $taxonomies)
197
-    {
198
-        $this->taxonomies = $taxonomies;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return EE_Secondary_Table
204
-     */
205
-    public function metaTable()
206
-    {
207
-        return $this->meta_table;
208
-    }
209
-
210
-
211
-    /**
212
-     * @param EE_Secondary_Table $meta_table
213
-     */
214
-    public function setMetaTable(EE_Secondary_Table $meta_table)
215
-    {
216
-        $this->meta_table = $meta_table;
217
-    }
218
-
219
-
220
-    /**
221
-     * @return EEM_Base
222
-     */
223
-    public function model()
224
-    {
225
-        return $this->model;
226
-    }
227
-
228
-
229
-    /**
230
-     * @param EEM_Base $CPT_model
231
-     */
232
-    protected function setModel(EEM_Base $CPT_model)
233
-    {
234
-        $this->model = $CPT_model;
235
-    }
236
-
237
-
238
-    /**
239
-     * @deprecated 4.9.63.p
240
-     * @return EE_Request_Handler
241
-     */
242
-    public function request()
243
-    {
244
-        if (! $this->request_handler instanceof EE_Request_Handler) {
245
-            $this->request_handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
246
-        }
247
-        return $this->request_handler;
248
-    }
249
-
250
-
251
-
252
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
253
-
254
-
255
-    /**
256
-     * @return WP_Query
257
-     */
258
-    public function WpQuery()
259
-    {
260
-        return $this->wp_query;
261
-    }
262
-    // phpcs:enable
263
-
264
-
265
-    /**
266
-     * @param WP_Query $wp_query
267
-     */
268
-    public function setWpQuery(WP_Query $wp_query)
269
-    {
270
-        $this->wp_query = $wp_query;
271
-    }
272
-
273
-
274
-    /**
275
-     * @return void
276
-     * @throws InvalidDataTypeException
277
-     * @throws InvalidInterfaceException
278
-     * @throws InvalidArgumentException
279
-     */
280
-    protected function initializeTaxonomies()
281
-    {
282
-        // check if taxonomies have already been set and that this CPT has taxonomies registered for it
283
-        if (
284
-            empty($this->taxonomies)
285
-            && isset($this->cpt_details['args']['taxonomies'])
286
-        ) {
287
-            // if so then grab them, but we want the taxonomy name as the key
288
-            $taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
289
-            // then grab the list of ALL taxonomies
290
-            /** @var CustomTaxonomyDefinitions
291
-             * $taxonomy_definitions
292
-             */
293
-            $taxonomy_definitions = $this->loader->getShared(
294
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
295
-            );
296
-            $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
297
-            foreach ($taxonomies as $taxonomy => &$details) {
298
-                // add details to our taxonomies if they exist
299
-                $details = isset($all_taxonomies[ $taxonomy ])
300
-                    ? $all_taxonomies[ $taxonomy ]
301
-                    : array();
302
-            }
303
-            // ALWAYS unset() variables that were passed by reference
304
-            unset($details);
305
-            $this->setTaxonomies($taxonomies);
306
-        }
307
-    }
308
-
309
-
310
-    /**
311
-     * @since 4.9.63.p
312
-     * @throws EE_Error
313
-     */
314
-    protected function init()
315
-    {
316
-        $this->setAdditionalCptDetails();
317
-        $this->setRequestVarsIfCpt();
318
-        // convert post_type to model name
319
-        $model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
320
-        // load all tables related to CPT
321
-        $this->setupModelsAndTables($model_name);
322
-        // load and instantiate CPT_*_Strategy
323
-        $CPT_Strategy = $this->cptStrategyClass($model_name);
324
-        // !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
325
-        // here's the list of available filters in the WP_Query object
326
-        // 'posts_where_paged'
327
-        // 'posts_groupby'
328
-        // 'posts_join_paged'
329
-        // 'posts_orderby'
330
-        // 'posts_distinct'
331
-        // 'post_limits'
332
-        // 'posts_fields'
333
-        // 'posts_join'
334
-        add_filter('posts_fields', array($this, 'postsFields'));
335
-        add_filter('posts_join', array($this, 'postsJoin'));
336
-        add_filter(
337
-            'get_' . $this->post_type . '_metadata',
338
-            array($CPT_Strategy, 'get_EE_post_type_metadata'),
339
-            1,
340
-            4
341
-        );
342
-        add_filter('the_posts', array($this, 'thePosts'), 1, 1);
343
-        if ($this->wp_query->is_main_query()) {
344
-            add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
345
-            $this->addTemplateFilters();
346
-        }
347
-    }
348
-
349
-
350
-    /**
351
-     * sets some basic query vars that pertain to the CPT
352
-     *
353
-     * @access protected
354
-     * @return void
355
-     */
356
-    protected function setAdditionalCptDetails()
357
-    {
358
-        // the post or category or term that is triggering EE
359
-        $this->cpt_details['espresso_page'] = $this->current_page->isEspressoPage();
360
-        // requested post name
361
-        $this->cpt_details['post_name'] = $this->request->getRequestParam('post_name');
362
-        // add support for viewing 'private', 'draft', or 'pending' posts
363
-        if (
364
-            isset($this->wp_query->query_vars['p'])
365
-            && $this->wp_query->query_vars['p'] !== 0
366
-            && is_user_logged_in()
367
-            && current_user_can('edit_post', $this->wp_query->query_vars['p'])
368
-        ) {
369
-            // we can just inject directly into the WP_Query object
370
-            $this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
371
-            // now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
372
-            $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
373
-        }
374
-    }
375
-
376
-
377
-    /**
378
-     * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
379
-     * If so, sets the 'ee' request variable
380
-     * so other parts of EE can know what CPT is getting queried.
381
-     * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
382
-     * in order for is_archive() and is_single() methods to work properly.
383
-     *
384
-     * @return void
385
-     */
386
-    public function setRequestVarsIfCpt()
387
-    {
388
-        // check if ee action var has been set
389
-        if (! $this->request->requestParamIsSet('ee')) {
390
-            // check that route exists for CPT archive slug
391
-            if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
392
-                // ie: set "ee" to "events"
393
-                $this->request->setRequestParam('ee', $this->cpt_details['plural_slug']);
394
-                // or does it match a single page CPT like /event/
395
-            } elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) {
396
-                // ie: set "ee" to "event"
397
-                $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
398
-            }
399
-        }
400
-    }
401
-
402
-
403
-    /**
404
-     * setupModelsAndTables
405
-     *
406
-     * @access protected
407
-     * @param string $model_name
408
-     * @throws EE_Error
409
-     */
410
-    protected function setupModelsAndTables($model_name)
411
-    {
412
-        // get CPT table data via CPT Model
413
-        $full_model_name = strpos($model_name, 'EEM_') !== 0
414
-            ? 'EEM_' . $model_name
415
-            : $model_name;
416
-        $model = $this->loader->getShared($full_model_name);
417
-        if (! $model instanceof EEM_Base) {
418
-            throw new EE_Error(
419
-                sprintf(
420
-                    esc_html__(
421
-                        'The "%1$s" model could not be loaded.',
422
-                        'event_espresso'
423
-                    ),
424
-                    $full_model_name
425
-                )
426
-            );
427
-        }
428
-        $this->setModel($model);
429
-        $this->setModelTables($this->model->get_tables());
430
-        $meta_model = $model_name . '_Meta';
431
-        // is there a Meta Table for this CPT?
432
-        if (
433
-            isset($this->cpt_details['tables'][ $meta_model ])
434
-            && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
435
-        ) {
436
-            $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
437
-        }
438
-    }
439
-
440
-
441
-    /**
442
-     * cptStrategyClass
443
-     *
444
-     * @access protected
445
-     * @param  string $model_name
446
-     * @return string
447
-     */
448
-    protected function cptStrategyClass($model_name)
449
-    {
450
-        // creates classname like:  CPT_Event_Strategy
451
-        $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
452
-        // load and instantiate
453
-        $CPT_Strategy = $this->loader->getShared(
454
-            $CPT_Strategy_class_name,
455
-            array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
456
-        );
457
-        if ($CPT_Strategy === null) {
458
-            $CPT_Strategy = $this->loader->getShared(
459
-                'EE_CPT_Default_Strategy',
460
-                array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
461
-            );
462
-        }
463
-        return $CPT_Strategy;
464
-    }
465
-
466
-
467
-    /**
468
-     * postsFields
469
-     *
470
-     * @access public
471
-     * @param  $SQL
472
-     * @return string
473
-     */
474
-    public function postsFields($SQL)
475
-    {
476
-        // does this CPT have a meta table ?
477
-        if ($this->meta_table instanceof EE_Secondary_Table) {
478
-            // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
479
-            $SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
480
-        }
481
-        remove_filter('posts_fields', array($this, 'postsFields'));
482
-        return $SQL;
483
-    }
484
-
485
-
486
-    /**
487
-     * postsJoin
488
-     *
489
-     * @access public
490
-     * @param  $SQL
491
-     * @return string
492
-     */
493
-    public function postsJoin($SQL)
494
-    {
495
-        // does this CPT have a meta table ?
496
-        if ($this->meta_table instanceof EE_Secondary_Table) {
497
-            global $wpdb;
498
-            // adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
499
-            $SQL .= ' LEFT JOIN '
500
-                    . $this->meta_table->get_table_name()
501
-                    . ' ON ( '
502
-                    . $this->meta_table->get_table_name()
503
-                    . '.'
504
-                    . $this->meta_table->get_fk_on_table()
505
-                    . ' = '
506
-                    . $wpdb->posts
507
-                    . '.ID ) ';
508
-        }
509
-        remove_filter('posts_join', array($this, 'postsJoin'));
510
-        return $SQL;
511
-    }
512
-
513
-
514
-    /**
515
-     * thePosts
516
-     *
517
-     * @access public
518
-     * @param  WP_Post[] $posts
519
-     * @return WP_Post[]
520
-     */
521
-    public function thePosts($posts)
522
-    {
523
-        $CPT_class = $this->cpt_details['class_name'];
524
-        // loop thru posts
525
-        if (is_array($posts) && $this->model instanceof EEM_CPT_Base) {
526
-            foreach ($posts as $post) {
527
-                if ($post->post_type === $this->post_type) {
528
-                    $post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
529
-                }
530
-            }
531
-        }
532
-        remove_filter('the_posts', array($this, 'thePosts'), 1);
533
-        return $posts;
534
-    }
535
-
536
-
537
-    /**
538
-     * @param $url
539
-     * @param $ID
540
-     * @return string
541
-     */
542
-    public function getEditPostLink($url, $ID)
543
-    {
544
-        // need to make sure we only edit links if our cpt
545
-        global $post;
546
-        // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
547
-        // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
548
-        if (
549
-            ! $post instanceof WP_Post
550
-            || $post->post_type !== $this->post_type
551
-            || (
552
-                isset($this->cpt_details['args']['show_ee_ui'])
553
-                && ! $this->cpt_details['args']['show_ee_ui']
554
-            )
555
-        ) {
556
-            return $url;
557
-        }
558
-        // k made it here so all is good.
559
-        return wp_nonce_url(
560
-            add_query_arg(
561
-                array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
562
-                admin_url('admin.php')
563
-            ),
564
-            'edit',
565
-            'edit_nonce'
566
-        );
567
-    }
568
-
569
-
570
-    /**
571
-     * Execute any template filters.
572
-     * This method is only called if in main query.
573
-     *
574
-     * @return void
575
-     */
576
-    public function addTemplateFilters()
577
-    {
578
-        // if requested cpt supports page_templates and it's the main query
579
-        if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
580
-            // then let's hook into the appropriate query_template hook
581
-            add_filter('single_template', array($this, 'singleCptTemplate'));
582
-        }
583
-    }
584
-
585
-
586
-    /**
587
-     * Callback for single_template wp filter.
588
-     * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
589
-     * hierarchy.
590
-     *
591
-     * @access public
592
-     * @param string $current_template Existing default template path derived for this page call.
593
-     * @return string the path to the full template file.
594
-     */
595
-    public function singleCptTemplate($current_template)
596
-    {
597
-        $object = get_queried_object();
598
-        // does this called object HAVE a page template set that is something other than the default.
599
-        $template = get_post_meta($object->ID, '_wp_page_template', true);
600
-        // exit early if default or not set or invalid path (accounts for theme changes)
601
-        if (
602
-            $template === 'default'
603
-            || empty($template)
604
-            || ! is_readable(get_stylesheet_directory() . '/' . $template)
605
-        ) {
606
-            return $current_template;
607
-        }
608
-        // made it here so we SHOULD be able to just locate the template and then return it.
609
-        return locate_template(array($template));
610
-    }
33
+	/**
34
+	 * @var CurrentPage $current_page
35
+	 */
36
+	protected $current_page;
37
+
38
+	/**
39
+	 * @var string $post_type
40
+	 */
41
+	protected $post_type = '';
42
+
43
+	/**
44
+	 * CPT details from CustomPostTypeDefinitions for specific post type
45
+	 *
46
+	 * @var array $cpt_details
47
+	 */
48
+	protected $cpt_details = array();
49
+
50
+	/**
51
+	 * @var EE_Table_Base[] $model_tables
52
+	 */
53
+	protected $model_tables = array();
54
+
55
+	/**
56
+	 * @var array $taxonomies
57
+	 */
58
+	protected $taxonomies = array();
59
+
60
+	/**
61
+	 * meta table for the related CPT
62
+	 *
63
+	 * @var EE_Secondary_Table $meta_table
64
+	 */
65
+	protected $meta_table;
66
+
67
+	/**
68
+	 * EEM_CPT_Base model for the related CPT
69
+	 *
70
+	 * @var EEM_CPT_Base $model
71
+	 */
72
+	protected $model;
73
+
74
+	/**
75
+	 * @var EE_Request_Handler $request_handler
76
+	 */
77
+	protected $request_handler;
78
+
79
+	/**
80
+	 * @var WP_Query $wp_query
81
+	 */
82
+	protected $wp_query;
83
+
84
+	/**
85
+	 * @var LoaderInterface $loader
86
+	 */
87
+	protected $loader;
88
+
89
+	/**
90
+	 * @var RequestInterface $request
91
+	 */
92
+	protected $request;
93
+
94
+
95
+	/**
96
+	 * CptQueryModifier constructor
97
+	 *
98
+	 * @param string             $post_type
99
+	 * @param array              $cpt_details
100
+	 * @param WP_Query           $WP_Query
101
+	 * @param CurrentPage $current_page
102
+	 * @param RequestInterface   $request
103
+	 * @param LoaderInterface    $loader
104
+	 * @throws EE_Error
105
+	 */
106
+	public function __construct(
107
+		$post_type,
108
+		array $cpt_details,
109
+		WP_Query $WP_Query,
110
+		CurrentPage $current_page,
111
+		RequestInterface $request,
112
+		LoaderInterface $loader
113
+	) {
114
+		$this->loader = $loader;
115
+		$this->request = $request;
116
+		$this->current_page = $current_page;
117
+		$this->setWpQuery($WP_Query);
118
+		$this->setPostType($post_type);
119
+		$this->setCptDetails($cpt_details);
120
+		$this->init();
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return string
126
+	 */
127
+	public function postType()
128
+	{
129
+		return $this->post_type;
130
+	}
131
+
132
+
133
+	/**
134
+	 * @param string $post_type
135
+	 */
136
+	protected function setPostType($post_type)
137
+	{
138
+		$this->post_type = $post_type;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return array
144
+	 */
145
+	public function cptDetails()
146
+	{
147
+		return $this->cpt_details;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @param array $cpt_details
153
+	 */
154
+	protected function setCptDetails($cpt_details)
155
+	{
156
+		$this->cpt_details = $cpt_details;
157
+	}
158
+
159
+
160
+	/**
161
+	 * @return EE_Table_Base[]
162
+	 */
163
+	public function modelTables()
164
+	{
165
+		return $this->model_tables;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param EE_Table_Base[] $model_tables
171
+	 */
172
+	protected function setModelTables($model_tables)
173
+	{
174
+		$this->model_tables = $model_tables;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @return array
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidDataTypeException
182
+	 * @throws InvalidInterfaceException
183
+	 */
184
+	public function taxonomies()
185
+	{
186
+		if (empty($this->taxonomies)) {
187
+			$this->initializeTaxonomies();
188
+		}
189
+		return $this->taxonomies;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param array $taxonomies
195
+	 */
196
+	protected function setTaxonomies(array $taxonomies)
197
+	{
198
+		$this->taxonomies = $taxonomies;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return EE_Secondary_Table
204
+	 */
205
+	public function metaTable()
206
+	{
207
+		return $this->meta_table;
208
+	}
209
+
210
+
211
+	/**
212
+	 * @param EE_Secondary_Table $meta_table
213
+	 */
214
+	public function setMetaTable(EE_Secondary_Table $meta_table)
215
+	{
216
+		$this->meta_table = $meta_table;
217
+	}
218
+
219
+
220
+	/**
221
+	 * @return EEM_Base
222
+	 */
223
+	public function model()
224
+	{
225
+		return $this->model;
226
+	}
227
+
228
+
229
+	/**
230
+	 * @param EEM_Base $CPT_model
231
+	 */
232
+	protected function setModel(EEM_Base $CPT_model)
233
+	{
234
+		$this->model = $CPT_model;
235
+	}
236
+
237
+
238
+	/**
239
+	 * @deprecated 4.9.63.p
240
+	 * @return EE_Request_Handler
241
+	 */
242
+	public function request()
243
+	{
244
+		if (! $this->request_handler instanceof EE_Request_Handler) {
245
+			$this->request_handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
246
+		}
247
+		return $this->request_handler;
248
+	}
249
+
250
+
251
+
252
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
253
+
254
+
255
+	/**
256
+	 * @return WP_Query
257
+	 */
258
+	public function WpQuery()
259
+	{
260
+		return $this->wp_query;
261
+	}
262
+	// phpcs:enable
263
+
264
+
265
+	/**
266
+	 * @param WP_Query $wp_query
267
+	 */
268
+	public function setWpQuery(WP_Query $wp_query)
269
+	{
270
+		$this->wp_query = $wp_query;
271
+	}
272
+
273
+
274
+	/**
275
+	 * @return void
276
+	 * @throws InvalidDataTypeException
277
+	 * @throws InvalidInterfaceException
278
+	 * @throws InvalidArgumentException
279
+	 */
280
+	protected function initializeTaxonomies()
281
+	{
282
+		// check if taxonomies have already been set and that this CPT has taxonomies registered for it
283
+		if (
284
+			empty($this->taxonomies)
285
+			&& isset($this->cpt_details['args']['taxonomies'])
286
+		) {
287
+			// if so then grab them, but we want the taxonomy name as the key
288
+			$taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
289
+			// then grab the list of ALL taxonomies
290
+			/** @var CustomTaxonomyDefinitions
291
+			 * $taxonomy_definitions
292
+			 */
293
+			$taxonomy_definitions = $this->loader->getShared(
294
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
295
+			);
296
+			$all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
297
+			foreach ($taxonomies as $taxonomy => &$details) {
298
+				// add details to our taxonomies if they exist
299
+				$details = isset($all_taxonomies[ $taxonomy ])
300
+					? $all_taxonomies[ $taxonomy ]
301
+					: array();
302
+			}
303
+			// ALWAYS unset() variables that were passed by reference
304
+			unset($details);
305
+			$this->setTaxonomies($taxonomies);
306
+		}
307
+	}
308
+
309
+
310
+	/**
311
+	 * @since 4.9.63.p
312
+	 * @throws EE_Error
313
+	 */
314
+	protected function init()
315
+	{
316
+		$this->setAdditionalCptDetails();
317
+		$this->setRequestVarsIfCpt();
318
+		// convert post_type to model name
319
+		$model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
320
+		// load all tables related to CPT
321
+		$this->setupModelsAndTables($model_name);
322
+		// load and instantiate CPT_*_Strategy
323
+		$CPT_Strategy = $this->cptStrategyClass($model_name);
324
+		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
325
+		// here's the list of available filters in the WP_Query object
326
+		// 'posts_where_paged'
327
+		// 'posts_groupby'
328
+		// 'posts_join_paged'
329
+		// 'posts_orderby'
330
+		// 'posts_distinct'
331
+		// 'post_limits'
332
+		// 'posts_fields'
333
+		// 'posts_join'
334
+		add_filter('posts_fields', array($this, 'postsFields'));
335
+		add_filter('posts_join', array($this, 'postsJoin'));
336
+		add_filter(
337
+			'get_' . $this->post_type . '_metadata',
338
+			array($CPT_Strategy, 'get_EE_post_type_metadata'),
339
+			1,
340
+			4
341
+		);
342
+		add_filter('the_posts', array($this, 'thePosts'), 1, 1);
343
+		if ($this->wp_query->is_main_query()) {
344
+			add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
345
+			$this->addTemplateFilters();
346
+		}
347
+	}
348
+
349
+
350
+	/**
351
+	 * sets some basic query vars that pertain to the CPT
352
+	 *
353
+	 * @access protected
354
+	 * @return void
355
+	 */
356
+	protected function setAdditionalCptDetails()
357
+	{
358
+		// the post or category or term that is triggering EE
359
+		$this->cpt_details['espresso_page'] = $this->current_page->isEspressoPage();
360
+		// requested post name
361
+		$this->cpt_details['post_name'] = $this->request->getRequestParam('post_name');
362
+		// add support for viewing 'private', 'draft', or 'pending' posts
363
+		if (
364
+			isset($this->wp_query->query_vars['p'])
365
+			&& $this->wp_query->query_vars['p'] !== 0
366
+			&& is_user_logged_in()
367
+			&& current_user_can('edit_post', $this->wp_query->query_vars['p'])
368
+		) {
369
+			// we can just inject directly into the WP_Query object
370
+			$this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
371
+			// now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
372
+			$this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
373
+		}
374
+	}
375
+
376
+
377
+	/**
378
+	 * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
379
+	 * If so, sets the 'ee' request variable
380
+	 * so other parts of EE can know what CPT is getting queried.
381
+	 * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
382
+	 * in order for is_archive() and is_single() methods to work properly.
383
+	 *
384
+	 * @return void
385
+	 */
386
+	public function setRequestVarsIfCpt()
387
+	{
388
+		// check if ee action var has been set
389
+		if (! $this->request->requestParamIsSet('ee')) {
390
+			// check that route exists for CPT archive slug
391
+			if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
392
+				// ie: set "ee" to "events"
393
+				$this->request->setRequestParam('ee', $this->cpt_details['plural_slug']);
394
+				// or does it match a single page CPT like /event/
395
+			} elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) {
396
+				// ie: set "ee" to "event"
397
+				$this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
398
+			}
399
+		}
400
+	}
401
+
402
+
403
+	/**
404
+	 * setupModelsAndTables
405
+	 *
406
+	 * @access protected
407
+	 * @param string $model_name
408
+	 * @throws EE_Error
409
+	 */
410
+	protected function setupModelsAndTables($model_name)
411
+	{
412
+		// get CPT table data via CPT Model
413
+		$full_model_name = strpos($model_name, 'EEM_') !== 0
414
+			? 'EEM_' . $model_name
415
+			: $model_name;
416
+		$model = $this->loader->getShared($full_model_name);
417
+		if (! $model instanceof EEM_Base) {
418
+			throw new EE_Error(
419
+				sprintf(
420
+					esc_html__(
421
+						'The "%1$s" model could not be loaded.',
422
+						'event_espresso'
423
+					),
424
+					$full_model_name
425
+				)
426
+			);
427
+		}
428
+		$this->setModel($model);
429
+		$this->setModelTables($this->model->get_tables());
430
+		$meta_model = $model_name . '_Meta';
431
+		// is there a Meta Table for this CPT?
432
+		if (
433
+			isset($this->cpt_details['tables'][ $meta_model ])
434
+			&& $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
435
+		) {
436
+			$this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
437
+		}
438
+	}
439
+
440
+
441
+	/**
442
+	 * cptStrategyClass
443
+	 *
444
+	 * @access protected
445
+	 * @param  string $model_name
446
+	 * @return string
447
+	 */
448
+	protected function cptStrategyClass($model_name)
449
+	{
450
+		// creates classname like:  CPT_Event_Strategy
451
+		$CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
452
+		// load and instantiate
453
+		$CPT_Strategy = $this->loader->getShared(
454
+			$CPT_Strategy_class_name,
455
+			array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
456
+		);
457
+		if ($CPT_Strategy === null) {
458
+			$CPT_Strategy = $this->loader->getShared(
459
+				'EE_CPT_Default_Strategy',
460
+				array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
461
+			);
462
+		}
463
+		return $CPT_Strategy;
464
+	}
465
+
466
+
467
+	/**
468
+	 * postsFields
469
+	 *
470
+	 * @access public
471
+	 * @param  $SQL
472
+	 * @return string
473
+	 */
474
+	public function postsFields($SQL)
475
+	{
476
+		// does this CPT have a meta table ?
477
+		if ($this->meta_table instanceof EE_Secondary_Table) {
478
+			// adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
479
+			$SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
480
+		}
481
+		remove_filter('posts_fields', array($this, 'postsFields'));
482
+		return $SQL;
483
+	}
484
+
485
+
486
+	/**
487
+	 * postsJoin
488
+	 *
489
+	 * @access public
490
+	 * @param  $SQL
491
+	 * @return string
492
+	 */
493
+	public function postsJoin($SQL)
494
+	{
495
+		// does this CPT have a meta table ?
496
+		if ($this->meta_table instanceof EE_Secondary_Table) {
497
+			global $wpdb;
498
+			// adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
499
+			$SQL .= ' LEFT JOIN '
500
+					. $this->meta_table->get_table_name()
501
+					. ' ON ( '
502
+					. $this->meta_table->get_table_name()
503
+					. '.'
504
+					. $this->meta_table->get_fk_on_table()
505
+					. ' = '
506
+					. $wpdb->posts
507
+					. '.ID ) ';
508
+		}
509
+		remove_filter('posts_join', array($this, 'postsJoin'));
510
+		return $SQL;
511
+	}
512
+
513
+
514
+	/**
515
+	 * thePosts
516
+	 *
517
+	 * @access public
518
+	 * @param  WP_Post[] $posts
519
+	 * @return WP_Post[]
520
+	 */
521
+	public function thePosts($posts)
522
+	{
523
+		$CPT_class = $this->cpt_details['class_name'];
524
+		// loop thru posts
525
+		if (is_array($posts) && $this->model instanceof EEM_CPT_Base) {
526
+			foreach ($posts as $post) {
527
+				if ($post->post_type === $this->post_type) {
528
+					$post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
529
+				}
530
+			}
531
+		}
532
+		remove_filter('the_posts', array($this, 'thePosts'), 1);
533
+		return $posts;
534
+	}
535
+
536
+
537
+	/**
538
+	 * @param $url
539
+	 * @param $ID
540
+	 * @return string
541
+	 */
542
+	public function getEditPostLink($url, $ID)
543
+	{
544
+		// need to make sure we only edit links if our cpt
545
+		global $post;
546
+		// notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
547
+		// for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
548
+		if (
549
+			! $post instanceof WP_Post
550
+			|| $post->post_type !== $this->post_type
551
+			|| (
552
+				isset($this->cpt_details['args']['show_ee_ui'])
553
+				&& ! $this->cpt_details['args']['show_ee_ui']
554
+			)
555
+		) {
556
+			return $url;
557
+		}
558
+		// k made it here so all is good.
559
+		return wp_nonce_url(
560
+			add_query_arg(
561
+				array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
562
+				admin_url('admin.php')
563
+			),
564
+			'edit',
565
+			'edit_nonce'
566
+		);
567
+	}
568
+
569
+
570
+	/**
571
+	 * Execute any template filters.
572
+	 * This method is only called if in main query.
573
+	 *
574
+	 * @return void
575
+	 */
576
+	public function addTemplateFilters()
577
+	{
578
+		// if requested cpt supports page_templates and it's the main query
579
+		if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
580
+			// then let's hook into the appropriate query_template hook
581
+			add_filter('single_template', array($this, 'singleCptTemplate'));
582
+		}
583
+	}
584
+
585
+
586
+	/**
587
+	 * Callback for single_template wp filter.
588
+	 * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
589
+	 * hierarchy.
590
+	 *
591
+	 * @access public
592
+	 * @param string $current_template Existing default template path derived for this page call.
593
+	 * @return string the path to the full template file.
594
+	 */
595
+	public function singleCptTemplate($current_template)
596
+	{
597
+		$object = get_queried_object();
598
+		// does this called object HAVE a page template set that is something other than the default.
599
+		$template = get_post_meta($object->ID, '_wp_page_template', true);
600
+		// exit early if default or not set or invalid path (accounts for theme changes)
601
+		if (
602
+			$template === 'default'
603
+			|| empty($template)
604
+			|| ! is_readable(get_stylesheet_directory() . '/' . $template)
605
+		) {
606
+			return $current_template;
607
+		}
608
+		// made it here so we SHOULD be able to just locate the template and then return it.
609
+		return locate_template(array($template));
610
+	}
611 611
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      */
242 242
     public function request()
243 243
     {
244
-        if (! $this->request_handler instanceof EE_Request_Handler) {
244
+        if ( ! $this->request_handler instanceof EE_Request_Handler) {
245 245
             $this->request_handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
246 246
         }
247 247
         return $this->request_handler;
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
             $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
297 297
             foreach ($taxonomies as $taxonomy => &$details) {
298 298
                 // add details to our taxonomies if they exist
299
-                $details = isset($all_taxonomies[ $taxonomy ])
300
-                    ? $all_taxonomies[ $taxonomy ]
299
+                $details = isset($all_taxonomies[$taxonomy])
300
+                    ? $all_taxonomies[$taxonomy]
301 301
                     : array();
302 302
             }
303 303
             // ALWAYS unset() variables that were passed by reference
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
         add_filter('posts_fields', array($this, 'postsFields'));
335 335
         add_filter('posts_join', array($this, 'postsJoin'));
336 336
         add_filter(
337
-            'get_' . $this->post_type . '_metadata',
337
+            'get_'.$this->post_type.'_metadata',
338 338
             array($CPT_Strategy, 'get_EE_post_type_metadata'),
339 339
             1,
340 340
             4
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
     public function setRequestVarsIfCpt()
387 387
     {
388 388
         // check if ee action var has been set
389
-        if (! $this->request->requestParamIsSet('ee')) {
389
+        if ( ! $this->request->requestParamIsSet('ee')) {
390 390
             // check that route exists for CPT archive slug
391 391
             if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
392 392
                 // ie: set "ee" to "events"
@@ -411,10 +411,10 @@  discard block
 block discarded – undo
411 411
     {
412 412
         // get CPT table data via CPT Model
413 413
         $full_model_name = strpos($model_name, 'EEM_') !== 0
414
-            ? 'EEM_' . $model_name
414
+            ? 'EEM_'.$model_name
415 415
             : $model_name;
416 416
         $model = $this->loader->getShared($full_model_name);
417
-        if (! $model instanceof EEM_Base) {
417
+        if ( ! $model instanceof EEM_Base) {
418 418
             throw new EE_Error(
419 419
                 sprintf(
420 420
                     esc_html__(
@@ -427,13 +427,13 @@  discard block
 block discarded – undo
427 427
         }
428 428
         $this->setModel($model);
429 429
         $this->setModelTables($this->model->get_tables());
430
-        $meta_model = $model_name . '_Meta';
430
+        $meta_model = $model_name.'_Meta';
431 431
         // is there a Meta Table for this CPT?
432 432
         if (
433
-            isset($this->cpt_details['tables'][ $meta_model ])
434
-            && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
433
+            isset($this->cpt_details['tables'][$meta_model])
434
+            && $this->cpt_details['tables'][$meta_model] instanceof EE_Secondary_Table
435 435
         ) {
436
-            $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
436
+            $this->setMetaTable($this->cpt_details['tables'][$meta_model]);
437 437
         }
438 438
     }
439 439
 
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
     protected function cptStrategyClass($model_name)
449 449
     {
450 450
         // creates classname like:  CPT_Event_Strategy
451
-        $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
451
+        $CPT_Strategy_class_name = 'EE_CPT_'.$model_name.'_Strategy';
452 452
         // load and instantiate
453 453
         $CPT_Strategy = $this->loader->getShared(
454 454
             $CPT_Strategy_class_name,
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
         // does this CPT have a meta table ?
477 477
         if ($this->meta_table instanceof EE_Secondary_Table) {
478 478
             // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
479
-            $SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
479
+            $SQL .= ', '.$this->meta_table->get_table_name().'.* ';
480 480
         }
481 481
         remove_filter('posts_fields', array($this, 'postsFields'));
482 482
         return $SQL;
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
     public function addTemplateFilters()
577 577
     {
578 578
         // if requested cpt supports page_templates and it's the main query
579
-        if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
579
+        if ( ! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
580 580
             // then let's hook into the appropriate query_template hook
581 581
             add_filter('single_template', array($this, 'singleCptTemplate'));
582 582
         }
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
         if (
602 602
             $template === 'default'
603 603
             || empty($template)
604
-            || ! is_readable(get_stylesheet_directory() . '/' . $template)
604
+            || ! is_readable(get_stylesheet_directory().'/'.$template)
605 605
         ) {
606 606
             return $current_template;
607 607
         }
Please login to merge, or discard this patch.
core/EE_Cron_Tasks.core.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public static function instance()
40 40
     {
41
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
41
+        if ( ! self::$_instance instanceof EE_Cron_Tasks) {
42 42
             self::$_instance = new self();
43 43
         }
44 44
         return self::$_instance;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
              */
73 73
             add_action(
74 74
                 'AHEE__EE_System__load_core_configuration__complete',
75
-                function () {
75
+                function() {
76 76
                     EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
77 77
                     EE_Registry::instance()->NET_CFG->update_config(true, false);
78 78
                     add_option('ee_disabled_wp_cron_check', 1, '', false);
@@ -124,16 +124,16 @@  discard block
 block discarded – undo
124 124
             'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
125 125
         );
126 126
         $crons = (array) get_option('cron');
127
-        if (! is_array($crons)) {
127
+        if ( ! is_array($crons)) {
128 128
             return;
129 129
         }
130 130
         foreach ($crons as $timestamp => $cron) {
131 131
             /** @var array[] $cron */
132 132
             foreach ($ee_crons as $ee_cron) {
133
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
133
+                if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) {
134 134
                     do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
135
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
136
-                        if (! empty($ee_cron_details['args'])) {
135
+                    foreach ($cron[$ee_cron] as $ee_cron_details) {
136
+                        if ( ! empty($ee_cron_details['args'])) {
137 137
                             do_action(
138 138
                                 'AHEE_log',
139 139
                                 __CLASS__,
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
      */
161 161
     public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
162 162
     {
163
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
163
+        if ( ! method_exists('EE_Cron_Tasks', $cron_task)) {
164 164
             throw new DomainException(
165 165
                 sprintf(
166 166
                     esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             );
170 170
         }
171 171
         // reschedule the cron if we can't hit the db right now
172
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
172
+        if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
173 173
             foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
174 174
                 // ensure $additional_vars is an array
175 175
                 $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
     {
251 251
         do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
252 252
         if (absint($TXN_ID)) {
253
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
253
+            self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID;
254 254
             add_action(
255 255
                 'shutdown',
256 256
                 array('EE_Cron_Tasks', 'update_transaction_with_payment'),
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
         EE_Registry::instance()->load_model('Transaction');
298 298
         foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
299 299
             // reschedule the cron if we can't hit the db right now
300
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
300
+            if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
301 301
                 // reset cron job for updating the TXN
302 302
                 EE_Cron_Tasks::schedule_update_transaction_with_payment(
303 303
                     time() + EE_Cron_Tasks::reschedule_timeout,
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
                 // now try to update the TXN with any payments
314 314
                 $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
315 315
             }
316
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
316
+            unset(self::$_update_transactions_with_payment[$TXN_ID]);
317 317
         }
318 318
     }
319 319
 
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
     public static function expired_transaction_check($TXN_ID = 0)
375 375
     {
376 376
         if (absint($TXN_ID)) {
377
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
377
+            self::$_expired_transactions[$TXN_ID] = $TXN_ID;
378 378
             add_action(
379 379
                 'shutdown',
380 380
                 array('EE_Cron_Tasks', 'process_expired_transactions'),
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
                         break;
503 503
                 }
504 504
             }
505
-            unset(self::$_expired_transactions[ $TXN_ID ]);
505
+            unset(self::$_expired_transactions[$TXN_ID]);
506 506
         }
507 507
     }
508 508
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
550 550
             $time_diff_for_comparison = apply_filters(
551 551
                 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
552
-                '-' . $reg_config->gateway_log_lifespan
552
+                '-'.$reg_config->gateway_log_lifespan
553 553
             );
554 554
             EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
555 555
         }
Please login to merge, or discard this patch.
Indentation   +600 added lines, -600 removed lines patch added patch discarded remove patch
@@ -14,607 +14,607 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Cron_Tasks extends EE_Base
16 16
 {
17
-    /**
18
-     * WordPress doesn't allow duplicate crons within 10 minutes of the original,
19
-     * so we'll set our retry time for just over 10 minutes to avoid that
20
-     */
21
-    const reschedule_timeout = 605;
22
-
23
-
24
-    /**
25
-     * @var EE_Cron_Tasks
26
-     */
27
-    private static $_instance;
28
-
29
-
30
-    /**
31
-     * @return EE_Cron_Tasks
32
-     * @throws ReflectionException
33
-     * @throws EE_Error
34
-     * @throws InvalidArgumentException
35
-     * @throws InvalidInterfaceException
36
-     * @throws InvalidDataTypeException
37
-     */
38
-    public static function instance()
39
-    {
40
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
41
-            self::$_instance = new self();
42
-        }
43
-        return self::$_instance;
44
-    }
45
-
46
-
47
-    /**
48
-     * @access private
49
-     * @throws InvalidDataTypeException
50
-     * @throws InvalidInterfaceException
51
-     * @throws InvalidArgumentException
52
-     * @throws EE_Error
53
-     * @throws ReflectionException
54
-     */
55
-    private function __construct()
56
-    {
57
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
58
-        // verify that WP Cron is enabled
59
-        if (
60
-            defined('DISABLE_WP_CRON')
61
-            && DISABLE_WP_CRON
62
-            && is_admin()
63
-            && ! get_option('ee_disabled_wp_cron_check')
64
-        ) {
65
-            /**
66
-             * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
67
-             * config is loaded.
68
-             * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
69
-             * wanting to not have this functionality can just register its own action at a priority after this one to
70
-             * reverse any changes.
71
-             */
72
-            add_action(
73
-                'AHEE__EE_System__load_core_configuration__complete',
74
-                function () {
75
-                    EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
76
-                    EE_Registry::instance()->NET_CFG->update_config(true, false);
77
-                    add_option('ee_disabled_wp_cron_check', 1, '', false);
78
-                }
79
-            );
80
-        }
81
-        // UPDATE TRANSACTION WITH PAYMENT
82
-        add_action(
83
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
84
-            array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
85
-            10,
86
-            2
87
-        );
88
-        // ABANDONED / EXPIRED TRANSACTION CHECK
89
-        add_action(
90
-            'AHEE__EE_Cron_Tasks__expired_transaction_check',
91
-            array('EE_Cron_Tasks', 'expired_transaction_check'),
92
-            10,
93
-            1
94
-        );
95
-        // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
96
-        add_action(
97
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
98
-            array('EE_Cron_Tasks', 'clean_out_junk_transactions')
99
-        );
100
-        // logging
101
-        add_action(
102
-            'AHEE__EE_System__load_core_configuration__complete',
103
-            array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
104
-        );
105
-        EE_Registry::instance()->load_lib('Messages_Scheduler');
106
-        // clean out old gateway logs
107
-        add_action(
108
-            'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
109
-            array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
110
-        );
111
-    }
112
-
113
-
114
-    /**
115
-     * @access protected
116
-     * @return void
117
-     */
118
-    public static function log_scheduled_ee_crons()
119
-    {
120
-        $ee_crons = array(
121
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
122
-            'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
123
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
124
-        );
125
-        $crons = (array) get_option('cron');
126
-        if (! is_array($crons)) {
127
-            return;
128
-        }
129
-        foreach ($crons as $timestamp => $cron) {
130
-            /** @var array[] $cron */
131
-            foreach ($ee_crons as $ee_cron) {
132
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
133
-                    do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
134
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
135
-                        if (! empty($ee_cron_details['args'])) {
136
-                            do_action(
137
-                                'AHEE_log',
138
-                                __CLASS__,
139
-                                __FUNCTION__,
140
-                                print_r($ee_cron_details['args'], true),
141
-                                "{$ee_cron} args"
142
-                            );
143
-                        }
144
-                    }
145
-                }
146
-            }
147
-        }
148
-    }
149
-
150
-
151
-    /**
152
-     * reschedule_cron_for_transactions_if_maintenance_mode
153
-     * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
154
-     *
155
-     * @param string $cron_task
156
-     * @param array  $TXN_IDs
157
-     * @return bool
158
-     * @throws DomainException
159
-     */
160
-    public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
161
-    {
162
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
163
-            throw new DomainException(
164
-                sprintf(
165
-                    esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
166
-                    $cron_task
167
-                )
168
-            );
169
-        }
170
-        // reschedule the cron if we can't hit the db right now
171
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
172
-            foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
173
-                // ensure $additional_vars is an array
174
-                $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
175
-                // reset cron job for the TXN
176
-                call_user_func_array(
177
-                    array('EE_Cron_Tasks', $cron_task),
178
-                    array_merge(
179
-                        array(
180
-                            time() + (10 * MINUTE_IN_SECONDS),
181
-                            $TXN_ID,
182
-                        ),
183
-                        $additional_vars
184
-                    )
185
-                );
186
-            }
187
-            return true;
188
-        }
189
-        return false;
190
-    }
191
-
192
-
193
-
194
-
195
-    /****************  UPDATE TRANSACTION WITH PAYMENT ****************/
196
-
197
-
198
-    /**
199
-     * array of TXN IDs and the payment
200
-     *
201
-     * @var array
202
-     */
203
-    protected static $_update_transactions_with_payment = array();
204
-
205
-
206
-    /**
207
-     * schedule_update_transaction_with_payment
208
-     * sets a wp_schedule_single_event() for updating any TXNs that may
209
-     * require updating due to recently received payments
210
-     *
211
-     * @param int $timestamp
212
-     * @param int $TXN_ID
213
-     * @param int $PAY_ID
214
-     */
215
-    public static function schedule_update_transaction_with_payment(
216
-        $timestamp,
217
-        $TXN_ID,
218
-        $PAY_ID
219
-    ) {
220
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
221
-        // validate $TXN_ID and $timestamp
222
-        $TXN_ID = absint($TXN_ID);
223
-        $timestamp = absint($timestamp);
224
-        if ($TXN_ID && $timestamp) {
225
-            wp_schedule_single_event(
226
-                $timestamp,
227
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
228
-                array($TXN_ID, $PAY_ID)
229
-            );
230
-        }
231
-    }
232
-
233
-
234
-    /**
235
-     * setup_update_for_transaction_with_payment
236
-     * this is the callback for the action hook:
237
-     * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
238
-     * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
239
-     * The passed TXN_ID and associated payment gets added to an array, and then
240
-     * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
241
-     * 'shutdown' which will actually handle the processing of any
242
-     * transactions requiring updating, because doing so now would be too early
243
-     * and the required resources may not be available
244
-     *
245
-     * @param int $TXN_ID
246
-     * @param int $PAY_ID
247
-     */
248
-    public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0)
249
-    {
250
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
251
-        if (absint($TXN_ID)) {
252
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
253
-            add_action(
254
-                'shutdown',
255
-                array('EE_Cron_Tasks', 'update_transaction_with_payment'),
256
-                5
257
-            );
258
-        }
259
-    }
260
-
261
-
262
-    /**
263
-     * update_transaction_with_payment
264
-     * loops through the self::$_abandoned_transactions array
265
-     * and attempts to finalize any TXNs that have not been completed
266
-     * but have had their sessions expired, most likely due to a user not
267
-     * returning from an off-site payment gateway
268
-     *
269
-     * @throws EE_Error
270
-     * @throws DomainException
271
-     * @throws InvalidDataTypeException
272
-     * @throws InvalidInterfaceException
273
-     * @throws InvalidArgumentException
274
-     * @throws ReflectionException
275
-     * @throws RuntimeException
276
-     */
277
-    public static function update_transaction_with_payment()
278
-    {
279
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
280
-        if (
17
+	/**
18
+	 * WordPress doesn't allow duplicate crons within 10 minutes of the original,
19
+	 * so we'll set our retry time for just over 10 minutes to avoid that
20
+	 */
21
+	const reschedule_timeout = 605;
22
+
23
+
24
+	/**
25
+	 * @var EE_Cron_Tasks
26
+	 */
27
+	private static $_instance;
28
+
29
+
30
+	/**
31
+	 * @return EE_Cron_Tasks
32
+	 * @throws ReflectionException
33
+	 * @throws EE_Error
34
+	 * @throws InvalidArgumentException
35
+	 * @throws InvalidInterfaceException
36
+	 * @throws InvalidDataTypeException
37
+	 */
38
+	public static function instance()
39
+	{
40
+		if (! self::$_instance instanceof EE_Cron_Tasks) {
41
+			self::$_instance = new self();
42
+		}
43
+		return self::$_instance;
44
+	}
45
+
46
+
47
+	/**
48
+	 * @access private
49
+	 * @throws InvalidDataTypeException
50
+	 * @throws InvalidInterfaceException
51
+	 * @throws InvalidArgumentException
52
+	 * @throws EE_Error
53
+	 * @throws ReflectionException
54
+	 */
55
+	private function __construct()
56
+	{
57
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
58
+		// verify that WP Cron is enabled
59
+		if (
60
+			defined('DISABLE_WP_CRON')
61
+			&& DISABLE_WP_CRON
62
+			&& is_admin()
63
+			&& ! get_option('ee_disabled_wp_cron_check')
64
+		) {
65
+			/**
66
+			 * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
67
+			 * config is loaded.
68
+			 * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
69
+			 * wanting to not have this functionality can just register its own action at a priority after this one to
70
+			 * reverse any changes.
71
+			 */
72
+			add_action(
73
+				'AHEE__EE_System__load_core_configuration__complete',
74
+				function () {
75
+					EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
76
+					EE_Registry::instance()->NET_CFG->update_config(true, false);
77
+					add_option('ee_disabled_wp_cron_check', 1, '', false);
78
+				}
79
+			);
80
+		}
81
+		// UPDATE TRANSACTION WITH PAYMENT
82
+		add_action(
83
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
84
+			array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
85
+			10,
86
+			2
87
+		);
88
+		// ABANDONED / EXPIRED TRANSACTION CHECK
89
+		add_action(
90
+			'AHEE__EE_Cron_Tasks__expired_transaction_check',
91
+			array('EE_Cron_Tasks', 'expired_transaction_check'),
92
+			10,
93
+			1
94
+		);
95
+		// CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
96
+		add_action(
97
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
98
+			array('EE_Cron_Tasks', 'clean_out_junk_transactions')
99
+		);
100
+		// logging
101
+		add_action(
102
+			'AHEE__EE_System__load_core_configuration__complete',
103
+			array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
104
+		);
105
+		EE_Registry::instance()->load_lib('Messages_Scheduler');
106
+		// clean out old gateway logs
107
+		add_action(
108
+			'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
109
+			array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
110
+		);
111
+	}
112
+
113
+
114
+	/**
115
+	 * @access protected
116
+	 * @return void
117
+	 */
118
+	public static function log_scheduled_ee_crons()
119
+	{
120
+		$ee_crons = array(
121
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
122
+			'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
123
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
124
+		);
125
+		$crons = (array) get_option('cron');
126
+		if (! is_array($crons)) {
127
+			return;
128
+		}
129
+		foreach ($crons as $timestamp => $cron) {
130
+			/** @var array[] $cron */
131
+			foreach ($ee_crons as $ee_cron) {
132
+				if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
133
+					do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
134
+					foreach ($cron[ $ee_cron ] as $ee_cron_details) {
135
+						if (! empty($ee_cron_details['args'])) {
136
+							do_action(
137
+								'AHEE_log',
138
+								__CLASS__,
139
+								__FUNCTION__,
140
+								print_r($ee_cron_details['args'], true),
141
+								"{$ee_cron} args"
142
+							);
143
+						}
144
+					}
145
+				}
146
+			}
147
+		}
148
+	}
149
+
150
+
151
+	/**
152
+	 * reschedule_cron_for_transactions_if_maintenance_mode
153
+	 * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
154
+	 *
155
+	 * @param string $cron_task
156
+	 * @param array  $TXN_IDs
157
+	 * @return bool
158
+	 * @throws DomainException
159
+	 */
160
+	public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
161
+	{
162
+		if (! method_exists('EE_Cron_Tasks', $cron_task)) {
163
+			throw new DomainException(
164
+				sprintf(
165
+					esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
166
+					$cron_task
167
+				)
168
+			);
169
+		}
170
+		// reschedule the cron if we can't hit the db right now
171
+		if (! EE_Maintenance_Mode::instance()->models_can_query()) {
172
+			foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
173
+				// ensure $additional_vars is an array
174
+				$additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
175
+				// reset cron job for the TXN
176
+				call_user_func_array(
177
+					array('EE_Cron_Tasks', $cron_task),
178
+					array_merge(
179
+						array(
180
+							time() + (10 * MINUTE_IN_SECONDS),
181
+							$TXN_ID,
182
+						),
183
+						$additional_vars
184
+					)
185
+				);
186
+			}
187
+			return true;
188
+		}
189
+		return false;
190
+	}
191
+
192
+
193
+
194
+
195
+	/****************  UPDATE TRANSACTION WITH PAYMENT ****************/
196
+
197
+
198
+	/**
199
+	 * array of TXN IDs and the payment
200
+	 *
201
+	 * @var array
202
+	 */
203
+	protected static $_update_transactions_with_payment = array();
204
+
205
+
206
+	/**
207
+	 * schedule_update_transaction_with_payment
208
+	 * sets a wp_schedule_single_event() for updating any TXNs that may
209
+	 * require updating due to recently received payments
210
+	 *
211
+	 * @param int $timestamp
212
+	 * @param int $TXN_ID
213
+	 * @param int $PAY_ID
214
+	 */
215
+	public static function schedule_update_transaction_with_payment(
216
+		$timestamp,
217
+		$TXN_ID,
218
+		$PAY_ID
219
+	) {
220
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
221
+		// validate $TXN_ID and $timestamp
222
+		$TXN_ID = absint($TXN_ID);
223
+		$timestamp = absint($timestamp);
224
+		if ($TXN_ID && $timestamp) {
225
+			wp_schedule_single_event(
226
+				$timestamp,
227
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
228
+				array($TXN_ID, $PAY_ID)
229
+			);
230
+		}
231
+	}
232
+
233
+
234
+	/**
235
+	 * setup_update_for_transaction_with_payment
236
+	 * this is the callback for the action hook:
237
+	 * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
238
+	 * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
239
+	 * The passed TXN_ID and associated payment gets added to an array, and then
240
+	 * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
241
+	 * 'shutdown' which will actually handle the processing of any
242
+	 * transactions requiring updating, because doing so now would be too early
243
+	 * and the required resources may not be available
244
+	 *
245
+	 * @param int $TXN_ID
246
+	 * @param int $PAY_ID
247
+	 */
248
+	public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0)
249
+	{
250
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
251
+		if (absint($TXN_ID)) {
252
+			self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
253
+			add_action(
254
+				'shutdown',
255
+				array('EE_Cron_Tasks', 'update_transaction_with_payment'),
256
+				5
257
+			);
258
+		}
259
+	}
260
+
261
+
262
+	/**
263
+	 * update_transaction_with_payment
264
+	 * loops through the self::$_abandoned_transactions array
265
+	 * and attempts to finalize any TXNs that have not been completed
266
+	 * but have had their sessions expired, most likely due to a user not
267
+	 * returning from an off-site payment gateway
268
+	 *
269
+	 * @throws EE_Error
270
+	 * @throws DomainException
271
+	 * @throws InvalidDataTypeException
272
+	 * @throws InvalidInterfaceException
273
+	 * @throws InvalidArgumentException
274
+	 * @throws ReflectionException
275
+	 * @throws RuntimeException
276
+	 */
277
+	public static function update_transaction_with_payment()
278
+	{
279
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
280
+		if (
281 281
 // are there any TXNs that need cleaning up ?
282
-            empty(self::$_update_transactions_with_payment)
283
-            // reschedule the cron if we can't hit the db right now
284
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
285
-                'schedule_update_transaction_with_payment',
286
-                self::$_update_transactions_with_payment
287
-            )
288
-        ) {
289
-            return;
290
-        }
291
-        /** @type EE_Payment_Processor $payment_processor */
292
-        $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
293
-        // set revisit flag for payment processor
294
-        $payment_processor->set_revisit();
295
-        // load EEM_Transaction
296
-        EE_Registry::instance()->load_model('Transaction');
297
-        foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
298
-            // reschedule the cron if we can't hit the db right now
299
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
300
-                // reset cron job for updating the TXN
301
-                EE_Cron_Tasks::schedule_update_transaction_with_payment(
302
-                    time() + EE_Cron_Tasks::reschedule_timeout,
303
-                    $TXN_ID,
304
-                    $PAY_ID
305
-                );
306
-                continue;
307
-            }
308
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
309
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
310
-            // verify transaction
311
-            if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
312
-                // now try to update the TXN with any payments
313
-                $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
314
-            }
315
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
316
-        }
317
-    }
318
-
319
-
320
-
321
-    /************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
322
-
323
-
324
-    /*****************  EXPIRED TRANSACTION CHECK *****************/
325
-
326
-
327
-    /**
328
-     * array of TXN IDs
329
-     *
330
-     * @var array
331
-     */
332
-    protected static $_expired_transactions = array();
333
-
334
-
335
-    /**
336
-     * schedule_expired_transaction_check
337
-     * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
338
-     *
339
-     * @param int $timestamp
340
-     * @param int $TXN_ID
341
-     */
342
-    public static function schedule_expired_transaction_check(
343
-        $timestamp,
344
-        $TXN_ID
345
-    ) {
346
-        // validate $TXN_ID and $timestamp
347
-        $TXN_ID = absint($TXN_ID);
348
-        $timestamp = absint($timestamp);
349
-        if ($TXN_ID && $timestamp) {
350
-            wp_schedule_single_event(
351
-                $timestamp,
352
-                'AHEE__EE_Cron_Tasks__expired_transaction_check',
353
-                array($TXN_ID)
354
-            );
355
-        }
356
-    }
357
-
358
-
359
-    /**
360
-     * expired_transaction_check
361
-     * this is the callback for the action hook:
362
-     * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
363
-     * which is utilized by wp_schedule_single_event()
364
-     * in \EED_Single_Page_Checkout::_initialize_transaction().
365
-     * The passed TXN_ID gets added to an array, and then the
366
-     * process_expired_transactions() function is hooked into
367
-     * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
368
-     * processing of any failed transactions, because doing so now would be
369
-     * too early and the required resources may not be available
370
-     *
371
-     * @param int $TXN_ID
372
-     */
373
-    public static function expired_transaction_check($TXN_ID = 0)
374
-    {
375
-        if (absint($TXN_ID)) {
376
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
377
-            add_action(
378
-                'shutdown',
379
-                array('EE_Cron_Tasks', 'process_expired_transactions'),
380
-                5
381
-            );
382
-        }
383
-    }
384
-
385
-
386
-    /**
387
-     * process_expired_transactions
388
-     * loops through the self::$_expired_transactions array and processes any failed TXNs
389
-     *
390
-     * @throws EE_Error
391
-     * @throws InvalidDataTypeException
392
-     * @throws InvalidInterfaceException
393
-     * @throws InvalidArgumentException
394
-     * @throws ReflectionException
395
-     * @throws DomainException
396
-     * @throws RuntimeException
397
-     */
398
-    public static function process_expired_transactions()
399
-    {
400
-        if (
282
+			empty(self::$_update_transactions_with_payment)
283
+			// reschedule the cron if we can't hit the db right now
284
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
285
+				'schedule_update_transaction_with_payment',
286
+				self::$_update_transactions_with_payment
287
+			)
288
+		) {
289
+			return;
290
+		}
291
+		/** @type EE_Payment_Processor $payment_processor */
292
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
293
+		// set revisit flag for payment processor
294
+		$payment_processor->set_revisit();
295
+		// load EEM_Transaction
296
+		EE_Registry::instance()->load_model('Transaction');
297
+		foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
298
+			// reschedule the cron if we can't hit the db right now
299
+			if (! EE_Maintenance_Mode::instance()->models_can_query()) {
300
+				// reset cron job for updating the TXN
301
+				EE_Cron_Tasks::schedule_update_transaction_with_payment(
302
+					time() + EE_Cron_Tasks::reschedule_timeout,
303
+					$TXN_ID,
304
+					$PAY_ID
305
+				);
306
+				continue;
307
+			}
308
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
309
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
310
+			// verify transaction
311
+			if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
312
+				// now try to update the TXN with any payments
313
+				$payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
314
+			}
315
+			unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
316
+		}
317
+	}
318
+
319
+
320
+
321
+	/************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
322
+
323
+
324
+	/*****************  EXPIRED TRANSACTION CHECK *****************/
325
+
326
+
327
+	/**
328
+	 * array of TXN IDs
329
+	 *
330
+	 * @var array
331
+	 */
332
+	protected static $_expired_transactions = array();
333
+
334
+
335
+	/**
336
+	 * schedule_expired_transaction_check
337
+	 * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
338
+	 *
339
+	 * @param int $timestamp
340
+	 * @param int $TXN_ID
341
+	 */
342
+	public static function schedule_expired_transaction_check(
343
+		$timestamp,
344
+		$TXN_ID
345
+	) {
346
+		// validate $TXN_ID and $timestamp
347
+		$TXN_ID = absint($TXN_ID);
348
+		$timestamp = absint($timestamp);
349
+		if ($TXN_ID && $timestamp) {
350
+			wp_schedule_single_event(
351
+				$timestamp,
352
+				'AHEE__EE_Cron_Tasks__expired_transaction_check',
353
+				array($TXN_ID)
354
+			);
355
+		}
356
+	}
357
+
358
+
359
+	/**
360
+	 * expired_transaction_check
361
+	 * this is the callback for the action hook:
362
+	 * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
363
+	 * which is utilized by wp_schedule_single_event()
364
+	 * in \EED_Single_Page_Checkout::_initialize_transaction().
365
+	 * The passed TXN_ID gets added to an array, and then the
366
+	 * process_expired_transactions() function is hooked into
367
+	 * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
368
+	 * processing of any failed transactions, because doing so now would be
369
+	 * too early and the required resources may not be available
370
+	 *
371
+	 * @param int $TXN_ID
372
+	 */
373
+	public static function expired_transaction_check($TXN_ID = 0)
374
+	{
375
+		if (absint($TXN_ID)) {
376
+			self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
377
+			add_action(
378
+				'shutdown',
379
+				array('EE_Cron_Tasks', 'process_expired_transactions'),
380
+				5
381
+			);
382
+		}
383
+	}
384
+
385
+
386
+	/**
387
+	 * process_expired_transactions
388
+	 * loops through the self::$_expired_transactions array and processes any failed TXNs
389
+	 *
390
+	 * @throws EE_Error
391
+	 * @throws InvalidDataTypeException
392
+	 * @throws InvalidInterfaceException
393
+	 * @throws InvalidArgumentException
394
+	 * @throws ReflectionException
395
+	 * @throws DomainException
396
+	 * @throws RuntimeException
397
+	 */
398
+	public static function process_expired_transactions()
399
+	{
400
+		if (
401 401
 // are there any TXNs that need cleaning up ?
402
-            empty(self::$_expired_transactions)
403
-            // reschedule the cron if we can't hit the db right now
404
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
405
-                'schedule_expired_transaction_check',
406
-                self::$_expired_transactions
407
-            )
408
-        ) {
409
-            return;
410
-        }
411
-        /** @type EE_Transaction_Processor $transaction_processor */
412
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
413
-        // set revisit flag for txn processor
414
-        $transaction_processor->set_revisit();
415
-        // load EEM_Transaction
416
-        EE_Registry::instance()->load_model('Transaction');
417
-        foreach (self::$_expired_transactions as $TXN_ID) {
418
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
419
-            // verify transaction and whether it is failed or not
420
-            if ($transaction instanceof EE_Transaction) {
421
-                switch ($transaction->status_ID()) {
422
-                    // Completed TXNs
423
-                    case EEM_Transaction::complete_status_code:
424
-                        // Don't update the transaction/registrations if the Primary Registration is Not Approved.
425
-                        $primary_registration = $transaction->primary_registration();
426
-                        if (
427
-                            $primary_registration instanceof EE_Registration
428
-                            && $primary_registration->status_ID() !== EEM_Registration::status_id_not_approved
429
-                        ) {
430
-                            /** @type EE_Transaction_Processor $transaction_processor */
431
-                            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
432
-                            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
433
-                                $transaction,
434
-                                $transaction->last_payment()
435
-                            );
436
-                            do_action(
437
-                                'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
438
-                                $transaction
439
-                            );
440
-                        }
441
-                        break;
442
-                    // Overpaid TXNs
443
-                    case EEM_Transaction::overpaid_status_code:
444
-                        do_action(
445
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
446
-                            $transaction
447
-                        );
448
-                        break;
449
-                    // Incomplete TXNs
450
-                    case EEM_Transaction::incomplete_status_code:
451
-                        do_action(
452
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
453
-                            $transaction
454
-                        );
455
-                        // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
456
-                        break;
457
-                    // Abandoned TXNs
458
-                    case EEM_Transaction::abandoned_status_code:
459
-                        // run hook before updating transaction, primarily so
460
-                        // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
461
-                        do_action(
462
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
463
-                            $transaction
464
-                        );
465
-                        // don't finalize the TXN if it has already been completed
466
-                        if ($transaction->all_reg_steps_completed() !== true) {
467
-                            /** @type EE_Payment_Processor $payment_processor */
468
-                            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
469
-                            // let's simulate an IPN here which will trigger any notifications that need to go out
470
-                            $payment_processor->update_txn_based_on_payment(
471
-                                $transaction,
472
-                                $transaction->last_payment(),
473
-                                true,
474
-                                true
475
-                            );
476
-                        }
477
-                        break;
478
-                    // Failed TXNs
479
-                    case EEM_Transaction::failed_status_code:
480
-                        do_action(
481
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
482
-                            $transaction
483
-                        );
484
-                        // todo :
485
-                        // perform garbage collection here and remove clean_out_junk_transactions()
486
-                        // $registrations = $transaction->registrations();
487
-                        // if (! empty($registrations)) {
488
-                        //     foreach ($registrations as $registration) {
489
-                        //         if ($registration instanceof EE_Registration) {
490
-                        //             $delete_registration = true;
491
-                        //             if ($registration->attendee() instanceof EE_Attendee) {
492
-                        //                 $delete_registration = false;
493
-                        //             }
494
-                        //             if ($delete_registration) {
495
-                        //                 $registration->delete_permanently();
496
-                        //                 $registration->delete_related_permanently();
497
-                        //             }
498
-                        //         }
499
-                        //     }
500
-                        // }
501
-                        break;
502
-                }
503
-            }
504
-            unset(self::$_expired_transactions[ $TXN_ID ]);
505
-        }
506
-    }
507
-
508
-
509
-
510
-    /*************  END OF EXPIRED TRANSACTION CHECK  *************/
511
-
512
-
513
-    /************* START CLEAN UP BOT TRANSACTIONS **********************/
514
-
515
-
516
-    /**
517
-     * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
518
-     * which is setup during activation to run on an hourly cron
519
-     *
520
-     * @throws EE_Error
521
-     * @throws InvalidArgumentException
522
-     * @throws InvalidDataTypeException
523
-     * @throws InvalidInterfaceException
524
-     * @throws DomainException
525
-     */
526
-    public static function clean_out_junk_transactions()
527
-    {
528
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
529
-            EED_Ticket_Sales_Monitor::reset_reservation_counts();
530
-            EEM_Transaction::instance('')->delete_junk_transactions();
531
-            EEM_Registration::instance('')->delete_registrations_with_no_transaction();
532
-            EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
533
-        }
534
-    }
535
-
536
-
537
-    /**
538
-     * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
539
-     *
540
-     * @throws EE_Error
541
-     * @throws InvalidDataTypeException
542
-     * @throws InvalidInterfaceException
543
-     * @throws InvalidArgumentException
544
-     */
545
-    public static function clean_out_old_gateway_logs()
546
-    {
547
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
548
-            $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
549
-            $time_diff_for_comparison = apply_filters(
550
-                'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
551
-                '-' . $reg_config->gateway_log_lifespan
552
-            );
553
-            EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
554
-        }
555
-    }
556
-
557
-
558
-    /*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
559
-
560
-
561
-    /**
562
-     * @var array
563
-     */
564
-    protected static $_abandoned_transactions = array();
565
-
566
-
567
-    /**
568
-     * @deprecated
569
-     * @param int $timestamp
570
-     * @param int $TXN_ID
571
-     */
572
-    public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
573
-    {
574
-        EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
575
-    }
576
-
577
-
578
-    /**
579
-     * @deprecated
580
-     * @param int $TXN_ID
581
-     */
582
-    public static function check_for_abandoned_transactions($TXN_ID = 0)
583
-    {
584
-        EE_Cron_Tasks::expired_transaction_check($TXN_ID);
585
-    }
586
-
587
-
588
-    /**
589
-     * @deprecated
590
-     * @throws EE_Error
591
-     * @throws DomainException
592
-     * @throws InvalidDataTypeException
593
-     * @throws InvalidInterfaceException
594
-     * @throws InvalidArgumentException
595
-     * @throws ReflectionException
596
-     * @throws RuntimeException
597
-     */
598
-    public static function finalize_abandoned_transactions()
599
-    {
600
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
601
-        if (
402
+			empty(self::$_expired_transactions)
403
+			// reschedule the cron if we can't hit the db right now
404
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
405
+				'schedule_expired_transaction_check',
406
+				self::$_expired_transactions
407
+			)
408
+		) {
409
+			return;
410
+		}
411
+		/** @type EE_Transaction_Processor $transaction_processor */
412
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
413
+		// set revisit flag for txn processor
414
+		$transaction_processor->set_revisit();
415
+		// load EEM_Transaction
416
+		EE_Registry::instance()->load_model('Transaction');
417
+		foreach (self::$_expired_transactions as $TXN_ID) {
418
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
419
+			// verify transaction and whether it is failed or not
420
+			if ($transaction instanceof EE_Transaction) {
421
+				switch ($transaction->status_ID()) {
422
+					// Completed TXNs
423
+					case EEM_Transaction::complete_status_code:
424
+						// Don't update the transaction/registrations if the Primary Registration is Not Approved.
425
+						$primary_registration = $transaction->primary_registration();
426
+						if (
427
+							$primary_registration instanceof EE_Registration
428
+							&& $primary_registration->status_ID() !== EEM_Registration::status_id_not_approved
429
+						) {
430
+							/** @type EE_Transaction_Processor $transaction_processor */
431
+							$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
432
+							$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
433
+								$transaction,
434
+								$transaction->last_payment()
435
+							);
436
+							do_action(
437
+								'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
438
+								$transaction
439
+							);
440
+						}
441
+						break;
442
+					// Overpaid TXNs
443
+					case EEM_Transaction::overpaid_status_code:
444
+						do_action(
445
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
446
+							$transaction
447
+						);
448
+						break;
449
+					// Incomplete TXNs
450
+					case EEM_Transaction::incomplete_status_code:
451
+						do_action(
452
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
453
+							$transaction
454
+						);
455
+						// todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
456
+						break;
457
+					// Abandoned TXNs
458
+					case EEM_Transaction::abandoned_status_code:
459
+						// run hook before updating transaction, primarily so
460
+						// EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
461
+						do_action(
462
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
463
+							$transaction
464
+						);
465
+						// don't finalize the TXN if it has already been completed
466
+						if ($transaction->all_reg_steps_completed() !== true) {
467
+							/** @type EE_Payment_Processor $payment_processor */
468
+							$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
469
+							// let's simulate an IPN here which will trigger any notifications that need to go out
470
+							$payment_processor->update_txn_based_on_payment(
471
+								$transaction,
472
+								$transaction->last_payment(),
473
+								true,
474
+								true
475
+							);
476
+						}
477
+						break;
478
+					// Failed TXNs
479
+					case EEM_Transaction::failed_status_code:
480
+						do_action(
481
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
482
+							$transaction
483
+						);
484
+						// todo :
485
+						// perform garbage collection here and remove clean_out_junk_transactions()
486
+						// $registrations = $transaction->registrations();
487
+						// if (! empty($registrations)) {
488
+						//     foreach ($registrations as $registration) {
489
+						//         if ($registration instanceof EE_Registration) {
490
+						//             $delete_registration = true;
491
+						//             if ($registration->attendee() instanceof EE_Attendee) {
492
+						//                 $delete_registration = false;
493
+						//             }
494
+						//             if ($delete_registration) {
495
+						//                 $registration->delete_permanently();
496
+						//                 $registration->delete_related_permanently();
497
+						//             }
498
+						//         }
499
+						//     }
500
+						// }
501
+						break;
502
+				}
503
+			}
504
+			unset(self::$_expired_transactions[ $TXN_ID ]);
505
+		}
506
+	}
507
+
508
+
509
+
510
+	/*************  END OF EXPIRED TRANSACTION CHECK  *************/
511
+
512
+
513
+	/************* START CLEAN UP BOT TRANSACTIONS **********************/
514
+
515
+
516
+	/**
517
+	 * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
518
+	 * which is setup during activation to run on an hourly cron
519
+	 *
520
+	 * @throws EE_Error
521
+	 * @throws InvalidArgumentException
522
+	 * @throws InvalidDataTypeException
523
+	 * @throws InvalidInterfaceException
524
+	 * @throws DomainException
525
+	 */
526
+	public static function clean_out_junk_transactions()
527
+	{
528
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
529
+			EED_Ticket_Sales_Monitor::reset_reservation_counts();
530
+			EEM_Transaction::instance('')->delete_junk_transactions();
531
+			EEM_Registration::instance('')->delete_registrations_with_no_transaction();
532
+			EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
533
+		}
534
+	}
535
+
536
+
537
+	/**
538
+	 * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
539
+	 *
540
+	 * @throws EE_Error
541
+	 * @throws InvalidDataTypeException
542
+	 * @throws InvalidInterfaceException
543
+	 * @throws InvalidArgumentException
544
+	 */
545
+	public static function clean_out_old_gateway_logs()
546
+	{
547
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
548
+			$reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
549
+			$time_diff_for_comparison = apply_filters(
550
+				'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
551
+				'-' . $reg_config->gateway_log_lifespan
552
+			);
553
+			EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
554
+		}
555
+	}
556
+
557
+
558
+	/*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
559
+
560
+
561
+	/**
562
+	 * @var array
563
+	 */
564
+	protected static $_abandoned_transactions = array();
565
+
566
+
567
+	/**
568
+	 * @deprecated
569
+	 * @param int $timestamp
570
+	 * @param int $TXN_ID
571
+	 */
572
+	public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
573
+	{
574
+		EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
575
+	}
576
+
577
+
578
+	/**
579
+	 * @deprecated
580
+	 * @param int $TXN_ID
581
+	 */
582
+	public static function check_for_abandoned_transactions($TXN_ID = 0)
583
+	{
584
+		EE_Cron_Tasks::expired_transaction_check($TXN_ID);
585
+	}
586
+
587
+
588
+	/**
589
+	 * @deprecated
590
+	 * @throws EE_Error
591
+	 * @throws DomainException
592
+	 * @throws InvalidDataTypeException
593
+	 * @throws InvalidInterfaceException
594
+	 * @throws InvalidArgumentException
595
+	 * @throws ReflectionException
596
+	 * @throws RuntimeException
597
+	 */
598
+	public static function finalize_abandoned_transactions()
599
+	{
600
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
601
+		if (
602 602
 // are there any TXNs that need cleaning up ?
603
-            empty(self::$_abandoned_transactions)
604
-            // reschedule the cron if we can't hit the db right now
605
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
606
-                'schedule_expired_transaction_check',
607
-                self::$_abandoned_transactions
608
-            )
609
-        ) {
610
-            return;
611
-        }
612
-        // combine our arrays of transaction IDs
613
-        self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
614
-        // and deal with abandoned transactions here now...
615
-        EE_Cron_Tasks::process_expired_transactions();
616
-    }
617
-
618
-
619
-    /*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
603
+			empty(self::$_abandoned_transactions)
604
+			// reschedule the cron if we can't hit the db right now
605
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
606
+				'schedule_expired_transaction_check',
607
+				self::$_abandoned_transactions
608
+			)
609
+		) {
610
+			return;
611
+		}
612
+		// combine our arrays of transaction IDs
613
+		self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
614
+		// and deal with abandoned transactions here now...
615
+		EE_Cron_Tasks::process_expired_transactions();
616
+	}
617
+
618
+
619
+	/*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
620 620
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Address.helper.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
         $add_wrapper = true
31 31
     ) {
32 32
         // check that incoming object implements the EEI_Address interface
33
-        if (! $obj_with_address instanceof EEI_Address) {
33
+        if ( ! $obj_with_address instanceof EEI_Address) {
34 34
             $msg = esc_html__('The address could not be formatted.', 'event_espresso');
35 35
             $dev_msg = esc_html__(
36 36
                 'The Address Formatter requires passed objects to implement the EEI_Address interface.',
37 37
                 'event_espresso'
38 38
             );
39
-            EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
39
+            EE_Error::add_error($msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
40 40
             return null;
41 41
         }
42 42
         // obtain an address formatter
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             ? EEH_Address::_schema_formatting($formatter, $obj_with_address)
48 48
             : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper);
49 49
         $formatted_address = $add_wrapper && ! $use_schema
50
-            ? '<div class="espresso-address-dv">' . $formatted_address . '</div>'
50
+            ? '<div class="espresso-address-dv">'.$formatted_address.'</div>'
51 51
             : $formatted_address;
52 52
         // return the formatted address
53 53
         return $formatted_address;
Please login to merge, or discard this patch.
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -10,124 +10,124 @@
 block discarded – undo
10 10
  */
11 11
 class EEH_Address
12 12
 {
13
-    /**
14
-     *    format - output formatted EE object address information
15
-     *
16
-     * @access public
17
-     * @param         object      EEI_Address $obj_with_address
18
-     * @param string  $type       how the address is formatted. for example: 'multiline' or 'inline'
19
-     * @param boolean $use_schema whether to apply schema.org formatting to the address
20
-     * @param bool    $add_wrapper
21
-     * @return string
22
-     */
23
-    public static function format(
24
-        $obj_with_address = null,
25
-        $type = 'multiline',
26
-        $use_schema = true,
27
-        $add_wrapper = true
28
-    ) {
29
-        // check that incoming object implements the EEI_Address interface
30
-        if (! $obj_with_address instanceof EEI_Address) {
31
-            $msg = esc_html__('The address could not be formatted.', 'event_espresso');
32
-            $dev_msg = esc_html__(
33
-                'The Address Formatter requires passed objects to implement the EEI_Address interface.',
34
-                'event_espresso'
35
-            );
36
-            EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
37
-            return null;
38
-        }
39
-        // obtain an address formatter
40
-        $formatter = EEH_Address::_get_formatter($type);
41
-        // apply schema.org formatting ?
42
-        $use_schema = ! is_admin() ? $use_schema : false;
43
-        $formatted_address = $use_schema
44
-            ? EEH_Address::_schema_formatting($formatter, $obj_with_address)
45
-            : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper);
46
-        $formatted_address = $add_wrapper && ! $use_schema
47
-            ? '<div class="espresso-address-dv">' . $formatted_address . '</div>'
48
-            : $formatted_address;
49
-        // return the formatted address
50
-        return $formatted_address;
51
-    }
13
+	/**
14
+	 *    format - output formatted EE object address information
15
+	 *
16
+	 * @access public
17
+	 * @param         object      EEI_Address $obj_with_address
18
+	 * @param string  $type       how the address is formatted. for example: 'multiline' or 'inline'
19
+	 * @param boolean $use_schema whether to apply schema.org formatting to the address
20
+	 * @param bool    $add_wrapper
21
+	 * @return string
22
+	 */
23
+	public static function format(
24
+		$obj_with_address = null,
25
+		$type = 'multiline',
26
+		$use_schema = true,
27
+		$add_wrapper = true
28
+	) {
29
+		// check that incoming object implements the EEI_Address interface
30
+		if (! $obj_with_address instanceof EEI_Address) {
31
+			$msg = esc_html__('The address could not be formatted.', 'event_espresso');
32
+			$dev_msg = esc_html__(
33
+				'The Address Formatter requires passed objects to implement the EEI_Address interface.',
34
+				'event_espresso'
35
+			);
36
+			EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
37
+			return null;
38
+		}
39
+		// obtain an address formatter
40
+		$formatter = EEH_Address::_get_formatter($type);
41
+		// apply schema.org formatting ?
42
+		$use_schema = ! is_admin() ? $use_schema : false;
43
+		$formatted_address = $use_schema
44
+			? EEH_Address::_schema_formatting($formatter, $obj_with_address)
45
+			: EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper);
46
+		$formatted_address = $add_wrapper && ! $use_schema
47
+			? '<div class="espresso-address-dv">' . $formatted_address . '</div>'
48
+			: $formatted_address;
49
+		// return the formatted address
50
+		return $formatted_address;
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     *    _get_formatter - obtain the requester formatter class
57
-     *
58
-     * @access private
59
-     * @param string $type how the address is formatted. for example: 'multiline' or 'inline'
60
-     * @return EEI_Address_Formatter
61
-     */
62
-    private static function _get_formatter($type)
63
-    {
64
-        switch ($type) {
65
-            case 'multiline':
66
-                return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter();
67
-            case 'inline':
68
-                return new EventEspresso\core\services\address\formatters\InlineAddressFormatter();
69
-            default:
70
-                return new EventEspresso\core\services\address\formatters\NullAddressFormatter();
71
-        }
72
-    }
55
+	/**
56
+	 *    _get_formatter - obtain the requester formatter class
57
+	 *
58
+	 * @access private
59
+	 * @param string $type how the address is formatted. for example: 'multiline' or 'inline'
60
+	 * @return EEI_Address_Formatter
61
+	 */
62
+	private static function _get_formatter($type)
63
+	{
64
+		switch ($type) {
65
+			case 'multiline':
66
+				return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter();
67
+			case 'inline':
68
+				return new EventEspresso\core\services\address\formatters\InlineAddressFormatter();
69
+			default:
70
+				return new EventEspresso\core\services\address\formatters\NullAddressFormatter();
71
+		}
72
+	}
73 73
 
74 74
 
75 75
 
76
-    /**
77
-     *    _regular_formatting
78
-     *    adds formatting to an address
79
-     *
80
-     * @access private
81
-     * @param      object EEI_Address_Formatter $formatter
82
-     * @param      object EEI_Address $obj_with_address
83
-     * @param bool $add_wrapper
84
-     * @return string
85
-     */
86
-    private static function _regular_formatting(
87
-        EEI_Address_Formatter $formatter,
88
-        EEI_Address $obj_with_address,
89
-        $add_wrapper = true
90
-    ) {
91
-        $formatted_address = $add_wrapper ? '<div>' : '';
92
-        $formatted_address .= $formatter->format(
93
-            $obj_with_address->address(),
94
-            $obj_with_address->address2(),
95
-            $obj_with_address->city(),
96
-            $obj_with_address->state_name(),
97
-            $obj_with_address->zip(),
98
-            $obj_with_address->country_name(),
99
-            $obj_with_address->country_ID()
100
-        );
101
-        $formatted_address .= $add_wrapper ? '</div>' : '';
102
-        // return the formatted address
103
-        return $formatted_address;
104
-    }
76
+	/**
77
+	 *    _regular_formatting
78
+	 *    adds formatting to an address
79
+	 *
80
+	 * @access private
81
+	 * @param      object EEI_Address_Formatter $formatter
82
+	 * @param      object EEI_Address $obj_with_address
83
+	 * @param bool $add_wrapper
84
+	 * @return string
85
+	 */
86
+	private static function _regular_formatting(
87
+		EEI_Address_Formatter $formatter,
88
+		EEI_Address $obj_with_address,
89
+		$add_wrapper = true
90
+	) {
91
+		$formatted_address = $add_wrapper ? '<div>' : '';
92
+		$formatted_address .= $formatter->format(
93
+			$obj_with_address->address(),
94
+			$obj_with_address->address2(),
95
+			$obj_with_address->city(),
96
+			$obj_with_address->state_name(),
97
+			$obj_with_address->zip(),
98
+			$obj_with_address->country_name(),
99
+			$obj_with_address->country_ID()
100
+		);
101
+		$formatted_address .= $add_wrapper ? '</div>' : '';
102
+		// return the formatted address
103
+		return $formatted_address;
104
+	}
105 105
 
106 106
 
107 107
 
108
-    /**
109
-     *    _schema_formatting
110
-     *    adds schema.org formatting to an address
111
-     *
112
-     * @access private
113
-     * @param object EEI_Address_Formatter $formatter
114
-     * @param object EEI_Address $obj_with_address
115
-     * @return string
116
-     */
117
-    private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address)
118
-    {
119
-        $formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">';
120
-        $formatted_address .= $formatter->format(
121
-            EEH_Schema::streetAddress($obj_with_address),
122
-            EEH_Schema::postOfficeBoxNumber($obj_with_address),
123
-            EEH_Schema::addressLocality($obj_with_address),
124
-            EEH_Schema::addressRegion($obj_with_address),
125
-            EEH_Schema::postalCode($obj_with_address),
126
-            EEH_Schema::addressCountry($obj_with_address),
127
-            $obj_with_address->country_ID()
128
-        );
129
-        $formatted_address .= '</div>';
130
-        // return the formatted address
131
-        return $formatted_address;
132
-    }
108
+	/**
109
+	 *    _schema_formatting
110
+	 *    adds schema.org formatting to an address
111
+	 *
112
+	 * @access private
113
+	 * @param object EEI_Address_Formatter $formatter
114
+	 * @param object EEI_Address $obj_with_address
115
+	 * @return string
116
+	 */
117
+	private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address)
118
+	{
119
+		$formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">';
120
+		$formatted_address .= $formatter->format(
121
+			EEH_Schema::streetAddress($obj_with_address),
122
+			EEH_Schema::postOfficeBoxNumber($obj_with_address),
123
+			EEH_Schema::addressLocality($obj_with_address),
124
+			EEH_Schema::addressRegion($obj_with_address),
125
+			EEH_Schema::postalCode($obj_with_address),
126
+			EEH_Schema::addressCountry($obj_with_address),
127
+			$obj_with_address->country_ID()
128
+		);
129
+		$formatted_address .= '</div>';
130
+		// return the formatted address
131
+		return $formatted_address;
132
+	}
133 133
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Sideloader.helper.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
             '_upload_to' => $this->_get_wp_uploads_dir(),
63 63
             '_download_from' => '',
64 64
             '_permissions' => 0644,
65
-            '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'
65
+            '_new_file_name' => 'EE_Sideloader_'.uniqid().'.default'
66 66
             );
67 67
 
68 68
         $props = array_merge($defaults, $init);
69 69
 
70 70
         foreach ($props as $property => $val) {
71
-            $setter = 'set' . $property;
71
+            $setter = 'set'.$property;
72 72
             if (method_exists($this, $setter)) {
73 73
                 $this->$setter($val);
74 74
             } else {
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         }
91 91
 
92 92
         // make sure we include the required wp file for needed functions
93
-        require_once(ABSPATH . 'wp-admin/includes/file.php');
93
+        require_once(ABSPATH.'wp-admin/includes/file.php');
94 94
     }
95 95
 
96 96
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         // setup temp dir
217 217
         $temp_file = wp_tempnam($this->_download_from);
218 218
 
219
-        if (!$temp_file) {
219
+        if ( ! $temp_file) {
220 220
             EE_Error::add_error(
221 221
                 esc_html__('Something went wrong with the upload.  Unable to create a tmp file for the uploaded file on the server', 'event_espresso'),
222 222
                 __FILE__,
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
         do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file);
230 230
 
231
-        $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file);
231
+        $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array('timeout' => 500, 'stream' => true, 'filename' => $temp_file), $this, $temp_file);
232 232
 
233 233
         $response = wp_safe_remote_get($this->_download_from, $wp_remote_args);
234 234
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
         $file = $temp_file;
268 268
 
269 269
         // now we have the file, let's get it in the right directory with the right name.
270
-        $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this);
270
+        $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to.$this->_new_file_name, $this);
271 271
 
272 272
         // move file in
273 273
         if (false === @ rename($file, $path)) {
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
     public function set_upload_from($upload_from)
309 309
     {
310 310
         EE_Error::doing_it_wrong(
311
-            __CLASS__ . '::' . __FUNCTION__,
311
+            __CLASS__.'::'.__FUNCTION__,
312 312
             esc_html__(
313 313
                 'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from',
314 314
                 'event_espresso'
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     public function get_upload_from()
328 328
     {
329 329
         EE_Error::doing_it_wrong(
330
-            __CLASS__ . '::' . __FUNCTION__,
330
+            __CLASS__.'::'.__FUNCTION__,
331 331
             esc_html__(
332 332
                 'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from',
333 333
                 'event_espresso'
Please login to merge, or discard this patch.
Indentation   +324 added lines, -324 removed lines patch added patch discarded remove patch
@@ -11,328 +11,328 @@
 block discarded – undo
11 11
  */
12 12
 class EEH_Sideloader extends EEH_Base
13 13
 {
14
-    /**
15
-     * @since   4.1.0
16
-     * @var     string
17
-     */
18
-    private $_upload_to;
19
-
20
-    /**
21
-     * @since   4.10.5.p
22
-     * @var     string
23
-     */
24
-    private $_download_from;
25
-
26
-    /**
27
-     * @since   4.1.0
28
-     * @var     string
29
-     */
30
-    private $_permissions;
31
-
32
-    /**
33
-     * @since   4.1.0
34
-     * @var     string
35
-     */
36
-    private $_new_file_name;
37
-
38
-
39
-    /**
40
-     * constructor allows the user to set the properties on the sideloader on construct.  However, there are also setters for doing so.
41
-     *
42
-     * @since 4.1.0
43
-     * @param array $init array fo initializing the sideloader if keys match the properties.
44
-     */
45
-    public function __construct($init = array())
46
-    {
47
-        $this->_init($init);
48
-    }
49
-
50
-
51
-    /**
52
-     * sets the properties for class either to defaults or using incoming initialization array
53
-     *
54
-     * @since 4.1.0
55
-     * @param  array  $init array on init (keys match properties others ignored)
56
-     * @return void
57
-     */
58
-    private function _init($init)
59
-    {
60
-        $defaults = array(
61
-            '_upload_to' => $this->_get_wp_uploads_dir(),
62
-            '_download_from' => '',
63
-            '_permissions' => 0644,
64
-            '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'
65
-            );
66
-
67
-        $props = array_merge($defaults, $init);
68
-
69
-        foreach ($props as $property => $val) {
70
-            $setter = 'set' . $property;
71
-            if (method_exists($this, $setter)) {
72
-                $this->$setter($val);
73
-            } else {
74
-                 // No setter found.
75
-                EE_Error::add_error(
76
-                    sprintf(
77
-                        esc_html__(
78
-                            'EEH_Sideloader::%1$s not found. There is no setter for the %2$s property.',
79
-                            'event_espresso'
80
-                        ),
81
-                        $setter,
82
-                        $property
83
-                    ),
84
-                    __FILE__,
85
-                    __FUNCTION__,
86
-                    __LINE__
87
-                );
88
-            }
89
-        }
90
-
91
-        // make sure we include the required wp file for needed functions
92
-        require_once(ABSPATH . 'wp-admin/includes/file.php');
93
-    }
94
-
95
-
96
-    // utilities
97
-
98
-
99
-    /**
100
-     * @since 4.1.0
101
-     * @return void
102
-     */
103
-    private function _get_wp_uploads_dir()
104
-    {
105
-    }
106
-
107
-    // setters
108
-
109
-
110
-    /**
111
-     * sets the _upload_to property to the directory to upload to.
112
-     *
113
-     * @since 4.1.0
114
-     * @param $upload_to_folder
115
-     * @return void
116
-     */
117
-    public function set_upload_to($upload_to_folder)
118
-    {
119
-        $this->_upload_to = $upload_to_folder;
120
-    }
121
-
122
-
123
-    /**
124
-     * sets the _download_from property to the location we should download the file from.
125
-     *
126
-     * @since 4.10.5.p
127
-     * @param string $download_from The full path to the file we should sideload.
128
-     * @return void
129
-     */
130
-    public function set_download_from($download_from)
131
-    {
132
-        $this->_download_from = $download_from;
133
-    }
134
-
135
-
136
-    /**
137
-     * sets the _permissions property used on the sideloaded file.
138
-     *
139
-     * @since 4.1.0
140
-     * @param int $permissions
141
-     * @return void
142
-     */
143
-    public function set_permissions($permissions)
144
-    {
145
-        $this->_permissions = $permissions;
146
-    }
147
-
148
-
149
-    /**
150
-     * sets the _new_file_name property used on the sideloaded file.
151
-     *
152
-     * @since 4.1.0
153
-     * @param string $new_file_name
154
-     * @return void
155
-     */
156
-    public function set_new_file_name($new_file_name)
157
-    {
158
-        $this->_new_file_name = $new_file_name;
159
-    }
160
-
161
-    // getters
162
-
163
-
164
-    /**
165
-     * @since 4.1.0
166
-     * @return string
167
-     */
168
-    public function get_upload_to()
169
-    {
170
-        return $this->_upload_to;
171
-    }
172
-
173
-
174
-    /**
175
-     * @since 4.10.5.p
176
-     * @return string
177
-     */
178
-    public function get_download_from()
179
-    {
180
-        return $this->_download_from;
181
-    }
182
-
183
-
184
-    /**
185
-     * @since 4.1.0
186
-     * @return int
187
-     */
188
-    public function get_permissions()
189
-    {
190
-        return $this->_permissions;
191
-    }
192
-
193
-
194
-    /**
195
-     * @since 4.1.0
196
-     * @return string
197
-     */
198
-    public function get_new_file_name()
199
-    {
200
-        return $this->_new_file_name;
201
-    }
202
-
203
-
204
-    // upload methods
205
-
206
-
207
-    /**
208
-     * Downloads the file using the WordPress HTTP API.
209
-     *
210
-     * @since 4.1.0
211
-     * @return bool
212
-     */
213
-    public function sideload()
214
-    {
215
-        // setup temp dir
216
-        $temp_file = wp_tempnam($this->_download_from);
217
-
218
-        if (!$temp_file) {
219
-            EE_Error::add_error(
220
-                esc_html__('Something went wrong with the upload.  Unable to create a tmp file for the uploaded file on the server', 'event_espresso'),
221
-                __FILE__,
222
-                __FUNCTION__,
223
-                __LINE__
224
-            );
225
-            return false;
226
-        }
227
-
228
-        do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file);
229
-
230
-        $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file);
231
-
232
-        $response = wp_safe_remote_get($this->_download_from, $wp_remote_args);
233
-
234
-        if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) {
235
-            unlink($temp_file);
236
-            if (defined('WP_DEBUG') && WP_DEBUG) {
237
-                EE_Error::add_error(
238
-                    sprintf(
239
-                        esc_html__('Unable to upload the file. Either the path given to download from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'),
240
-                        $this->_download_from
241
-                    ),
242
-                    __FILE__,
243
-                    __FUNCTION__,
244
-                    __LINE__
245
-                );
246
-            }
247
-            return false;
248
-        }
249
-
250
-        // possible md5 check
251
-        $content_md5 = wp_remote_retrieve_header($response, 'content-md5');
252
-        if ($content_md5) {
253
-            $md5_check = verify_file_md5($temp_file, $content_md5);
254
-            if (is_wp_error($md5_check)) {
255
-                unlink($temp_file);
256
-                EE_Error::add_error(
257
-                    $md5_check->get_error_message(),
258
-                    __FILE__,
259
-                    __FUNCTION__,
260
-                    __LINE__
261
-                );
262
-                return false;
263
-            }
264
-        }
265
-
266
-        $file = $temp_file;
267
-
268
-        // now we have the file, let's get it in the right directory with the right name.
269
-        $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this);
270
-
271
-        // move file in
272
-        if (false === @ rename($file, $path)) {
273
-            unlink($temp_file);
274
-            EE_Error::add_error(
275
-                sprintf(
276
-                    esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'),
277
-                    $path
278
-                ),
279
-                __FILE__,
280
-                __FUNCTION__,
281
-                __LINE__
282
-            );
283
-            return false;
284
-        }
285
-
286
-        // set permissions
287
-        $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this);
288
-        chmod($path, $permissions);
289
-
290
-        // that's it.  let's allow for actions after file uploaded.
291
-        do_action('AHEE__EE_Sideloader__sideload_after', $this, $path);
292
-
293
-        // unlink tempfile
294
-        @unlink($temp_file);
295
-        return true;
296
-    }
297
-
298
-    // deprecated
299
-
300
-    /**
301
-     * sets the _upload_from property to the location we should download the file from.
302
-     *
303
-     * @param string $upload_from The full path to the file we should sideload.
304
-     * @return void
305
-     * @deprecated since version 4.10.5.p
306
-     */
307
-    public function set_upload_from($upload_from)
308
-    {
309
-        EE_Error::doing_it_wrong(
310
-            __CLASS__ . '::' . __FUNCTION__,
311
-            esc_html__(
312
-                'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from',
313
-                'event_espresso'
314
-            ),
315
-            '4.10.5.p'
316
-        );
317
-        $this->set_download_from($upload_from);
318
-    }
319
-
320
-
321
-    /**
322
-     * @since 4.1.0
323
-     * @return string
324
-     * @deprecated since version 4.10.5.p
325
-     */
326
-    public function get_upload_from()
327
-    {
328
-        EE_Error::doing_it_wrong(
329
-            __CLASS__ . '::' . __FUNCTION__,
330
-            esc_html__(
331
-                'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from',
332
-                'event_espresso'
333
-            ),
334
-            '4.10.5.p'
335
-        );
336
-        return $this->_download_from;
337
-    }
14
+	/**
15
+	 * @since   4.1.0
16
+	 * @var     string
17
+	 */
18
+	private $_upload_to;
19
+
20
+	/**
21
+	 * @since   4.10.5.p
22
+	 * @var     string
23
+	 */
24
+	private $_download_from;
25
+
26
+	/**
27
+	 * @since   4.1.0
28
+	 * @var     string
29
+	 */
30
+	private $_permissions;
31
+
32
+	/**
33
+	 * @since   4.1.0
34
+	 * @var     string
35
+	 */
36
+	private $_new_file_name;
37
+
38
+
39
+	/**
40
+	 * constructor allows the user to set the properties on the sideloader on construct.  However, there are also setters for doing so.
41
+	 *
42
+	 * @since 4.1.0
43
+	 * @param array $init array fo initializing the sideloader if keys match the properties.
44
+	 */
45
+	public function __construct($init = array())
46
+	{
47
+		$this->_init($init);
48
+	}
49
+
50
+
51
+	/**
52
+	 * sets the properties for class either to defaults or using incoming initialization array
53
+	 *
54
+	 * @since 4.1.0
55
+	 * @param  array  $init array on init (keys match properties others ignored)
56
+	 * @return void
57
+	 */
58
+	private function _init($init)
59
+	{
60
+		$defaults = array(
61
+			'_upload_to' => $this->_get_wp_uploads_dir(),
62
+			'_download_from' => '',
63
+			'_permissions' => 0644,
64
+			'_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'
65
+			);
66
+
67
+		$props = array_merge($defaults, $init);
68
+
69
+		foreach ($props as $property => $val) {
70
+			$setter = 'set' . $property;
71
+			if (method_exists($this, $setter)) {
72
+				$this->$setter($val);
73
+			} else {
74
+				 // No setter found.
75
+				EE_Error::add_error(
76
+					sprintf(
77
+						esc_html__(
78
+							'EEH_Sideloader::%1$s not found. There is no setter for the %2$s property.',
79
+							'event_espresso'
80
+						),
81
+						$setter,
82
+						$property
83
+					),
84
+					__FILE__,
85
+					__FUNCTION__,
86
+					__LINE__
87
+				);
88
+			}
89
+		}
90
+
91
+		// make sure we include the required wp file for needed functions
92
+		require_once(ABSPATH . 'wp-admin/includes/file.php');
93
+	}
94
+
95
+
96
+	// utilities
97
+
98
+
99
+	/**
100
+	 * @since 4.1.0
101
+	 * @return void
102
+	 */
103
+	private function _get_wp_uploads_dir()
104
+	{
105
+	}
106
+
107
+	// setters
108
+
109
+
110
+	/**
111
+	 * sets the _upload_to property to the directory to upload to.
112
+	 *
113
+	 * @since 4.1.0
114
+	 * @param $upload_to_folder
115
+	 * @return void
116
+	 */
117
+	public function set_upload_to($upload_to_folder)
118
+	{
119
+		$this->_upload_to = $upload_to_folder;
120
+	}
121
+
122
+
123
+	/**
124
+	 * sets the _download_from property to the location we should download the file from.
125
+	 *
126
+	 * @since 4.10.5.p
127
+	 * @param string $download_from The full path to the file we should sideload.
128
+	 * @return void
129
+	 */
130
+	public function set_download_from($download_from)
131
+	{
132
+		$this->_download_from = $download_from;
133
+	}
134
+
135
+
136
+	/**
137
+	 * sets the _permissions property used on the sideloaded file.
138
+	 *
139
+	 * @since 4.1.0
140
+	 * @param int $permissions
141
+	 * @return void
142
+	 */
143
+	public function set_permissions($permissions)
144
+	{
145
+		$this->_permissions = $permissions;
146
+	}
147
+
148
+
149
+	/**
150
+	 * sets the _new_file_name property used on the sideloaded file.
151
+	 *
152
+	 * @since 4.1.0
153
+	 * @param string $new_file_name
154
+	 * @return void
155
+	 */
156
+	public function set_new_file_name($new_file_name)
157
+	{
158
+		$this->_new_file_name = $new_file_name;
159
+	}
160
+
161
+	// getters
162
+
163
+
164
+	/**
165
+	 * @since 4.1.0
166
+	 * @return string
167
+	 */
168
+	public function get_upload_to()
169
+	{
170
+		return $this->_upload_to;
171
+	}
172
+
173
+
174
+	/**
175
+	 * @since 4.10.5.p
176
+	 * @return string
177
+	 */
178
+	public function get_download_from()
179
+	{
180
+		return $this->_download_from;
181
+	}
182
+
183
+
184
+	/**
185
+	 * @since 4.1.0
186
+	 * @return int
187
+	 */
188
+	public function get_permissions()
189
+	{
190
+		return $this->_permissions;
191
+	}
192
+
193
+
194
+	/**
195
+	 * @since 4.1.0
196
+	 * @return string
197
+	 */
198
+	public function get_new_file_name()
199
+	{
200
+		return $this->_new_file_name;
201
+	}
202
+
203
+
204
+	// upload methods
205
+
206
+
207
+	/**
208
+	 * Downloads the file using the WordPress HTTP API.
209
+	 *
210
+	 * @since 4.1.0
211
+	 * @return bool
212
+	 */
213
+	public function sideload()
214
+	{
215
+		// setup temp dir
216
+		$temp_file = wp_tempnam($this->_download_from);
217
+
218
+		if (!$temp_file) {
219
+			EE_Error::add_error(
220
+				esc_html__('Something went wrong with the upload.  Unable to create a tmp file for the uploaded file on the server', 'event_espresso'),
221
+				__FILE__,
222
+				__FUNCTION__,
223
+				__LINE__
224
+			);
225
+			return false;
226
+		}
227
+
228
+		do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file);
229
+
230
+		$wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file);
231
+
232
+		$response = wp_safe_remote_get($this->_download_from, $wp_remote_args);
233
+
234
+		if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) {
235
+			unlink($temp_file);
236
+			if (defined('WP_DEBUG') && WP_DEBUG) {
237
+				EE_Error::add_error(
238
+					sprintf(
239
+						esc_html__('Unable to upload the file. Either the path given to download from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'),
240
+						$this->_download_from
241
+					),
242
+					__FILE__,
243
+					__FUNCTION__,
244
+					__LINE__
245
+				);
246
+			}
247
+			return false;
248
+		}
249
+
250
+		// possible md5 check
251
+		$content_md5 = wp_remote_retrieve_header($response, 'content-md5');
252
+		if ($content_md5) {
253
+			$md5_check = verify_file_md5($temp_file, $content_md5);
254
+			if (is_wp_error($md5_check)) {
255
+				unlink($temp_file);
256
+				EE_Error::add_error(
257
+					$md5_check->get_error_message(),
258
+					__FILE__,
259
+					__FUNCTION__,
260
+					__LINE__
261
+				);
262
+				return false;
263
+			}
264
+		}
265
+
266
+		$file = $temp_file;
267
+
268
+		// now we have the file, let's get it in the right directory with the right name.
269
+		$path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this);
270
+
271
+		// move file in
272
+		if (false === @ rename($file, $path)) {
273
+			unlink($temp_file);
274
+			EE_Error::add_error(
275
+				sprintf(
276
+					esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'),
277
+					$path
278
+				),
279
+				__FILE__,
280
+				__FUNCTION__,
281
+				__LINE__
282
+			);
283
+			return false;
284
+		}
285
+
286
+		// set permissions
287
+		$permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this);
288
+		chmod($path, $permissions);
289
+
290
+		// that's it.  let's allow for actions after file uploaded.
291
+		do_action('AHEE__EE_Sideloader__sideload_after', $this, $path);
292
+
293
+		// unlink tempfile
294
+		@unlink($temp_file);
295
+		return true;
296
+	}
297
+
298
+	// deprecated
299
+
300
+	/**
301
+	 * sets the _upload_from property to the location we should download the file from.
302
+	 *
303
+	 * @param string $upload_from The full path to the file we should sideload.
304
+	 * @return void
305
+	 * @deprecated since version 4.10.5.p
306
+	 */
307
+	public function set_upload_from($upload_from)
308
+	{
309
+		EE_Error::doing_it_wrong(
310
+			__CLASS__ . '::' . __FUNCTION__,
311
+			esc_html__(
312
+				'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from',
313
+				'event_espresso'
314
+			),
315
+			'4.10.5.p'
316
+		);
317
+		$this->set_download_from($upload_from);
318
+	}
319
+
320
+
321
+	/**
322
+	 * @since 4.1.0
323
+	 * @return string
324
+	 * @deprecated since version 4.10.5.p
325
+	 */
326
+	public function get_upload_from()
327
+	{
328
+		EE_Error::doing_it_wrong(
329
+			__CLASS__ . '::' . __FUNCTION__,
330
+			esc_html__(
331
+				'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from',
332
+				'event_espresso'
333
+			),
334
+			'4.10.5.p'
335
+		);
336
+		return $this->_download_from;
337
+	}
338 338
 }
Please login to merge, or discard this patch.
core/helpers/EEH_MSG_Template.helper.php 2 patches
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             }
96 96
             $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
97 97
 
98
-            if (! $new_message_template_group) {
98
+            if ( ! $new_message_template_group) {
99 99
                 continue;
100 100
             }
101 101
             $templates[] = $new_message_template_group;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
                     )
131 131
                 )
132 132
             )
133
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
133
+            : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID)));
134 134
 
135 135
         return $count > 0;
136 136
     }
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
      */
148 148
     public static function update_to_active($messenger_names, $message_type_names)
149 149
     {
150
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
151
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
150
+        $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names);
151
+        $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names);
152 152
         return EEM_Message_Template_Group::instance()->update(
153
-            array( 'MTP_is_active' => 1 ),
153
+            array('MTP_is_active' => 1),
154 154
             array(
155 155
                 array(
156
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
157
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
156
+                    'MTP_messenger'     => array('IN', $messenger_names),
157
+                    'MTP_message_type'  => array('IN', $message_type_names)
158 158
                 )
159 159
             )
160 160
         );
@@ -242,13 +242,13 @@  discard block
 block discarded – undo
242 242
         $messenger = $message_resource_manager->get_messenger($messenger);
243 243
 
244 244
         // if messenger isn't a EE_messenger resource then bail.
245
-        if (! $messenger instanceof EE_messenger) {
245
+        if ( ! $messenger instanceof EE_messenger) {
246 246
             return array();
247 247
         }
248 248
 
249 249
         // validate class for getting our list of shortcodes
250
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
251
-        if (! class_exists($classname)) {
250
+        $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator';
251
+        if ( ! class_exists($classname)) {
252 252
             $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
253 253
             $msg[] = sprintf(
254 254
                 esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
@@ -264,44 +264,44 @@  discard block
 block discarded – undo
264 264
         // let's make sure we're only getting the shortcode part of the validators
265 265
         $shortcodes = array();
266 266
         foreach ($valid_shortcodes as $field => $validators) {
267
-            $shortcodes[ $field ] = $validators['shortcodes'];
267
+            $shortcodes[$field] = $validators['shortcodes'];
268 268
         }
269 269
         $valid_shortcodes = $shortcodes;
270 270
 
271 271
         // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
272
-        if (! empty($fields)) {
272
+        if ( ! empty($fields)) {
273 273
             $specified_shortcodes = array();
274 274
             foreach ($fields as $field) {
275
-                if (isset($valid_shortcodes[ $field ])) {
276
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
275
+                if (isset($valid_shortcodes[$field])) {
276
+                    $specified_shortcodes[$field] = $valid_shortcodes[$field];
277 277
                 }
278 278
             }
279 279
             $valid_shortcodes = $specified_shortcodes;
280 280
         }
281 281
 
282 282
         // if not merged then let's replace the fields with the localized fields
283
-        if (! $merged) {
283
+        if ( ! $merged) {
284 284
             // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
285 285
             $field_settings = $messenger->get_template_fields();
286 286
             $localized = array();
287 287
             foreach ($valid_shortcodes as $field => $shortcodes) {
288 288
                 // get localized field label
289
-                if (isset($field_settings[ $field ])) {
289
+                if (isset($field_settings[$field])) {
290 290
                     // possible that this is used as a main field.
291
-                    if (empty($field_settings[ $field ])) {
292
-                        if (isset($field_settings['extra'][ $field ])) {
293
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
291
+                    if (empty($field_settings[$field])) {
292
+                        if (isset($field_settings['extra'][$field])) {
293
+                            $_field = $field_settings['extra'][$field]['main']['label'];
294 294
                         } else {
295 295
                             $_field = $field;
296 296
                         }
297 297
                     } else {
298
-                        $_field = $field_settings[ $field ]['label'];
298
+                        $_field = $field_settings[$field]['label'];
299 299
                     }
300 300
                 } elseif (isset($field_settings['extra'])) {
301 301
                     // loop through extra "main fields" and see if any of their children have our field
302 302
                     foreach ($field_settings['extra'] as $fields) {
303
-                        if (isset($fields[ $field ])) {
304
-                            $_field = $fields[ $field ]['label'];
303
+                        if (isset($fields[$field])) {
304
+                            $_field = $fields[$field]['label'];
305 305
                         } else {
306 306
                             $_field = $field;
307 307
                         }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
                     $_field = $field;
311 311
                 }
312 312
                 if (isset($_field)) {
313
-                    $localized[ (string) $_field ] = $shortcodes;
313
+                    $localized[(string) $_field] = $shortcodes;
314 314
                 }
315 315
             }
316 316
             $valid_shortcodes = $localized;
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
             $merged_codes = array();
322 322
             foreach ($valid_shortcodes as $shortcode) {
323 323
                 foreach ($shortcode as $code => $label) {
324
-                    if (isset($merged_codes[ $code ])) {
324
+                    if (isset($merged_codes[$code])) {
325 325
                         continue;
326 326
                     } else {
327
-                        $merged_codes[ $code ] = $label;
327
+                        $merged_codes[$code] = $label;
328 328
                     }
329 329
                 }
330 330
             }
@@ -475,12 +475,12 @@  discard block
 block discarded – undo
475 475
         $sending_messenger = ''
476 476
     ) {
477 477
         // first determine if the url can be to the EE_Message object.
478
-        if (! $message_type->always_generate()) {
478
+        if ( ! $message_type->always_generate()) {
479 479
             return EEH_MSG_Template::generate_browser_trigger($message);
480 480
         }
481 481
 
482 482
         // if $registration object is not valid then exit early because there's nothing that can be generated.
483
-        if (! $registration instanceof EE_Registration) {
483
+        if ( ! $registration instanceof EE_Registration) {
484 484
             throw new EE_Error(
485 485
                 esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
486 486
             );
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 
489 489
         // validate given context
490 490
         $contexts = $message_type->get_contexts();
491
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
491
+        if ($message->context() !== '' && ! isset($contexts[$message->context()])) {
492 492
             throw new EE_Error(
493 493
                 sprintf(
494 494
                     esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
@@ -499,11 +499,11 @@  discard block
 block discarded – undo
499 499
         }
500 500
 
501 501
         // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
502
-        if (! empty($sending_messenger)) {
502
+        if ( ! empty($sending_messenger)) {
503 503
             $with_messengers = $message_type->with_messengers();
504 504
             if (
505
-                ! isset($with_messengers[ $message->messenger() ])
506
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
505
+                ! isset($with_messengers[$message->messenger()])
506
+                 || ! in_array($sending_messenger, $with_messengers[$message->messenger()])
507 507
             ) {
508 508
                 throw new EE_Error(
509 509
                     sprintf(
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
     public static function get_message_action_icon($type)
637 637
     {
638 638
         $action_icons = self::get_message_action_icons();
639
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
639
+        return isset($action_icons[$type]) ? $action_icons[$type] : [];
640 640
     }
641 641
 
642 642
 
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
     public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
702 702
     {
703 703
         $action_urls = self::get_message_action_urls($message, $query_params);
704
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
704
+        return isset($action_urls[$type]) ? $action_urls[$type] : '';
705 705
     }
706 706
 
707 707
 
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
         EE_Registry::instance()->load_helper('URL');
723 723
         // if $message is not an instance of EE_Message then let's just do a dummy.
724 724
         $message = empty($message) ? EE_Message_Factory::create() : $message;
725
-        $action_urls =  apply_filters(
725
+        $action_urls = apply_filters(
726 726
             'FHEE__EEH_MSG_Template__get_message_action_url',
727 727
             array(
728 728
                 'view' => EEH_MSG_Template::generate_browser_trigger($message),
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
     {
806 806
         $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
807 807
         $icon_css = EEH_MSG_Template::get_message_action_icon($type);
808
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
808
+        $title = isset($icon_css['label']) ? 'title="'.$icon_css['label'].'"' : '';
809 809
 
810 810
         if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
811 811
             return '';
@@ -814,14 +814,14 @@  discard block
 block discarded – undo
814 814
         $icon_css['css_class'] .= esc_attr(
815 815
             apply_filters(
816 816
                 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
817
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
817
+                ' js-ee-message-action-link ee-message-action-link-'.$type,
818 818
                 $type,
819 819
                 $message,
820 820
                 $query_params
821 821
             )
822 822
         );
823 823
 
824
-        return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
824
+        return '<a href="'.$url.'" '.$title.'><span class="'.esc_attr($icon_css['css_class']).'"></span></a>';
825 825
     }
826 826
 
827 827
 
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
     public static function convert_reg_status_to_message_type($reg_status)
863 863
     {
864 864
         $reg_status_array = self::reg_status_to_message_type_array();
865
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
865
+        return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : '';
866 866
     }
867 867
 
868 868
 
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
     public static function convert_payment_status_to_message_type($payment_status)
901 901
     {
902 902
         $payment_status_array = self::payment_status_to_message_type_array();
903
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
903
+        return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : '';
904 904
     }
905 905
 
906 906
 
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
      */
914 914
     public static function get_template_pack($template_pack_name)
915 915
     {
916
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
916
+        if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) {
917 917
             self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
918 918
         }
919 919
 
@@ -926,14 +926,14 @@  discard block
 block discarded – undo
926 926
 
927 927
         // nope...let's get it.
928 928
         // not set yet so let's attempt to get it.
929
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
929
+        $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(
930 930
             ' ',
931 931
             '_',
932 932
             ucwords(
933 933
                 str_replace('_', ' ', $template_pack_name)
934 934
             )
935 935
         );
936
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
936
+        if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') {
937 937
             return self::get_template_pack('default');
938 938
         } else {
939 939
             $template_pack = new $pack_class_name();
@@ -956,18 +956,18 @@  discard block
 block discarded – undo
956 956
     public static function get_template_pack_collection()
957 957
     {
958 958
         $new_collection = false;
959
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
959
+        if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
960 960
             self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
961 961
             $new_collection = true;
962 962
         }
963 963
 
964 964
         // glob the defaults directory for messages
965
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
965
+        $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR);
966 966
         foreach ($templates as $template_path) {
967 967
             // grab folder name
968 968
             $template = basename($template_path);
969 969
 
970
-            if (! $new_collection) {
970
+            if ( ! $new_collection) {
971 971
                 // already have it?
972 972
                 if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
973 973
                     continue;
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
             }
976 976
 
977 977
             // setup classname.
978
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
978
+            $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(
979 979
                 ' ',
980 980
                 '_',
981 981
                 ucwords(
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
                     )
987 987
                 )
988 988
             );
989
-            if (! class_exists($template_pack_class_name)) {
989
+            if ( ! class_exists($template_pack_class_name)) {
990 990
                 continue;
991 991
             }
992 992
             self::$_template_pack_collection->add(new $template_pack_class_name());
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1029 1029
         $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1030 1030
         $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1031
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1031
+        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1032 1032
             return array();
1033 1033
         }
1034 1034
         // whew made it this far!  Okay, let's go ahead and create the templates then
@@ -1048,13 +1048,13 @@  discard block
 block discarded – undo
1048 1048
     protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1049 1049
     {
1050 1050
         // if we're creating a custom template then we don't need to use the defaults class
1051
-        if (! $global) {
1051
+        if ( ! $global) {
1052 1052
             return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1053 1053
         }
1054 1054
         /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1055 1055
         $Message_Template_Defaults = EE_Registry::factory(
1056 1056
             'EE_Messages_Template_Defaults',
1057
-            array( $messenger, $message_type, $GRP_ID )
1057
+            array($messenger, $message_type, $GRP_ID)
1058 1058
         );
1059 1059
         // generate templates
1060 1060
         $success = $Message_Template_Defaults->create_new_templates();
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
         // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1063 1063
         // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1064 1064
         // attempts.
1065
-        if (! $success) {
1065
+        if ( ! $success) {
1066 1066
             /** @var EE_Message_Resource_Manager $message_resource_manager */
1067 1067
             $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1068 1068
             $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
     private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1098 1098
     {
1099 1099
         // defaults
1100
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1100
+        $success = array('GRP_ID' => null, 'MTP_context' => '');
1101 1101
         // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1102 1102
         $Message_Template_Group = empty($GRP_ID)
1103 1103
             ? EEM_Message_Template_Group::instance()->get_one(
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
             )
1112 1112
             : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1113 1113
         // if we don't have a mtg at this point then we need to bail.
1114
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1114
+        if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) {
1115 1115
             EE_Error::add_error(
1116 1116
                 sprintf(
1117 1117
                     esc_html__(
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
         $success['template_name'] = $template_name;
1158 1158
         // add new message templates and add relation to.
1159 1159
         foreach ($message_templates as $message_template) {
1160
-            if (! $message_template instanceof EE_Message_Template) {
1160
+            if ( ! $message_template instanceof EE_Message_Template) {
1161 1161
                 continue;
1162 1162
             }
1163 1163
             $new_message_template = clone $message_template;
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1237 1237
         $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1238 1238
         $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1239
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1239
+        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1240 1240
             return array();
1241 1241
         }
1242 1242
 
@@ -1248,7 +1248,7 @@  discard block
 block discarded – undo
1248 1248
                 if (in_array($field, $excluded_fields_for_messenger, true)) {
1249 1249
                     continue;
1250 1250
                 }
1251
-                $template_fields[ $context ][ $field ] = $value;
1251
+                $template_fields[$context][$field] = $value;
1252 1252
             }
1253 1253
         }
1254 1254
         if (empty($template_fields)) {
Please login to merge, or discard this patch.
Indentation   +1249 added lines, -1249 removed lines patch added patch discarded remove patch
@@ -13,1253 +13,1253 @@
 block discarded – undo
13 13
  */
14 14
 class EEH_MSG_Template
15 15
 {
16
-    /**
17
-     * Holds a collection of EE_Message_Template_Pack objects.
18
-     * @type EE_Messages_Template_Pack_Collection
19
-     */
20
-    protected static $_template_pack_collection;
21
-
22
-
23
-    /**
24
-     * @throws EE_Error
25
-     */
26
-    private static function _set_autoloader()
27
-    {
28
-        EED_Messages::set_autoloaders();
29
-    }
30
-
31
-
32
-    /**
33
-     * generate_new_templates
34
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
35
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
36
-     * for the event.
37
-     *
38
-     * @access protected
39
-     * @param string $messenger     the messenger we are generating templates for
40
-     * @param array  $message_types array of message types that the templates are generated for.
41
-     * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
42
-     *                              to use as the base for the new generated template.
43
-     * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
44
-     *                              for event specific template generation.
45
-     * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
46
-     *                for templates that are generated.  If this is an empty array then it means no templates were
47
-     *                generated which usually means there was an error.  Anything in the array with an empty value for
48
-     *                `MTP_context` means that it was not a new generated template but just reactivated (which only
49
-     *                happens for global templates that already exist in the database.
50
-     * @throws EE_Error
51
-     * @throws ReflectionException
52
-     */
53
-    public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
54
-    {
55
-        // make sure message_type is an array.
56
-        $message_types = (array) $message_types;
57
-        $templates = array();
58
-
59
-        if (empty($messenger)) {
60
-            throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
61
-        }
62
-
63
-        // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
64
-        if (empty($message_types)) {
65
-            throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
66
-        }
67
-
68
-        EEH_MSG_Template::_set_autoloader();
69
-        foreach ($message_types as $message_type) {
70
-            // if this is global template generation.
71
-            if ($global) {
72
-                // let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
73
-                if (empty($GRP_ID)) {
74
-                    $GRP_ID = EEM_Message_Template_Group::instance()->get_one(
75
-                        array(
76
-                            array(
77
-                                'MTP_messenger'    => $messenger,
78
-                                'MTP_message_type' => $message_type,
79
-                                'MTP_is_global'    => true,
80
-                            ),
81
-                        )
82
-                    );
83
-                    $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
84
-                }
85
-                // First let's determine if we already HAVE global templates for this messenger and message_type combination.
86
-                //  If we do then NO generation!!
87
-                if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
88
-                    $templates[] = array(
89
-                        'GRP_ID' => $GRP_ID,
90
-                        'MTP_context' => '',
91
-                    );
92
-                    // we already have generated templates for this so let's go to the next message type.
93
-                    continue;
94
-                }
95
-            }
96
-            $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
97
-
98
-            if (! $new_message_template_group) {
99
-                continue;
100
-            }
101
-            $templates[] = $new_message_template_group;
102
-        }
103
-
104
-        return $templates;
105
-    }
106
-
107
-
108
-    /**
109
-     * The purpose of this method is to determine if there are already generated templates in the database for the
110
-     * given variables.
111
-     *
112
-     * @param string $messenger    messenger
113
-     * @param string $message_type message type
114
-     * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
115
-     *                             template check)
116
-     * @return bool                true = generated, false = hasn't been generated.
117
-     * @throws EE_Error
118
-     */
119
-    public static function already_generated($messenger, $message_type, $GRP_ID = 0)
120
-    {
121
-        EEH_MSG_Template::_set_autoloader();
122
-        // what method we use depends on whether we have an GRP_ID or not
123
-        $count = empty($GRP_ID)
124
-            ? EEM_Message_Template::instance()->count(
125
-                array(
126
-                    array(
127
-                        'Message_Template_Group.MTP_messenger'    => $messenger,
128
-                        'Message_Template_Group.MTP_message_type' => $message_type,
129
-                        'Message_Template_Group.MTP_is_global'    => true
130
-                    )
131
-                )
132
-            )
133
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
134
-
135
-        return $count > 0;
136
-    }
137
-
138
-
139
-    /**
140
-     * Updates all message templates matching the incoming messengers and message types to active status.
141
-     *
142
-     * @static
143
-     * @param array $messenger_names    Messenger slug
144
-     * @param array $message_type_names Message type slug
145
-     * @return  int                         count of updated records.
146
-     * @throws EE_Error
147
-     */
148
-    public static function update_to_active($messenger_names, $message_type_names)
149
-    {
150
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
151
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
152
-        return EEM_Message_Template_Group::instance()->update(
153
-            array( 'MTP_is_active' => 1 ),
154
-            array(
155
-                array(
156
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
157
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
158
-                )
159
-            )
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * Updates all message template groups matching the incoming arguments to inactive status.
166
-     *
167
-     * @static
168
-     * @param array $messenger_names    The messenger slugs.
169
-     *                                  If empty then all templates matching the message types are marked inactive.
170
-     *                                  Otherwise only templates matching the messengers and message types.
171
-     * @param array $message_type_names The message type slugs.
172
-     *                                  If empty then all templates matching the messengers are marked inactive.
173
-     *                                  Otherwise only templates matching the messengers and message types.
174
-     *
175
-     * @return int  count of updated records.
176
-     * @throws EE_Error
177
-     */
178
-    public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
179
-    {
180
-        return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
181
-            $messenger_names,
182
-            $message_type_names
183
-        );
184
-    }
185
-
186
-
187
-    /**
188
-     * The purpose of this function is to return all installed message objects
189
-     * (messengers and message type regardless of whether they are ACTIVE or not)
190
-     *
191
-     * @param string $type
192
-     * @return array array consisting of installed messenger objects and installed message type objects.
193
-     * @throws EE_Error
194
-     * @throws ReflectionException
195
-     * @deprecated 4.9.0
196
-     * @static
197
-     */
198
-    public static function get_installed_message_objects($type = 'all')
199
-    {
200
-        self::_set_autoloader();
201
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
202
-        return array(
203
-            'messenger' => $message_resource_manager->installed_messengers(),
204
-            'message_type' => $message_resource_manager->installed_message_types()
205
-        );
206
-    }
207
-
208
-
209
-    /**
210
-     * This will return an array of shortcodes => labels from the
211
-     * messenger and message_type objects associated with this
212
-     * template.
213
-     *
214
-     * @param string $message_type
215
-     * @param string $messenger
216
-     * @param array  $fields                        What fields we're returning valid shortcodes for.
217
-     *                                              If empty then we assume all fields are to be returned. Optional.
218
-     * @param string $context                       What context we're going to return shortcodes for. Optional.
219
-     * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
220
-     *                                              but instead an array of the unique shortcodes for all the given (
221
-     *                                              or all) fields. Optional.
222
-     * @return array                                an array of shortcodes in the format
223
-     *                                              array( '[shortcode] => 'label')
224
-     *                                              OR
225
-     *                                              FALSE if no shortcodes found.
226
-     * @throws ReflectionException
227
-     * @throws EE_Error*@since 4.3.0
228
-     *
229
-     */
230
-    public static function get_shortcodes(
231
-        $message_type,
232
-        $messenger,
233
-        $fields = array(),
234
-        $context = 'admin',
235
-        $merged = false
236
-    ) {
237
-        $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
238
-        $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
239
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
240
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
241
-        // convert slug to object
242
-        $messenger = $message_resource_manager->get_messenger($messenger);
243
-
244
-        // if messenger isn't a EE_messenger resource then bail.
245
-        if (! $messenger instanceof EE_messenger) {
246
-            return array();
247
-        }
248
-
249
-        // validate class for getting our list of shortcodes
250
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
251
-        if (! class_exists($classname)) {
252
-            $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
253
-            $msg[] = sprintf(
254
-                esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
255
-                $classname
256
-            );
257
-            throw new EE_Error(implode('||', $msg));
258
-        }
259
-
260
-        /** @type EE_Messages_Validator $_VLD */
261
-        $_VLD = new $classname(array(), $context);
262
-        $valid_shortcodes = $_VLD->get_validators();
263
-
264
-        // let's make sure we're only getting the shortcode part of the validators
265
-        $shortcodes = array();
266
-        foreach ($valid_shortcodes as $field => $validators) {
267
-            $shortcodes[ $field ] = $validators['shortcodes'];
268
-        }
269
-        $valid_shortcodes = $shortcodes;
270
-
271
-        // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
272
-        if (! empty($fields)) {
273
-            $specified_shortcodes = array();
274
-            foreach ($fields as $field) {
275
-                if (isset($valid_shortcodes[ $field ])) {
276
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
277
-                }
278
-            }
279
-            $valid_shortcodes = $specified_shortcodes;
280
-        }
281
-
282
-        // if not merged then let's replace the fields with the localized fields
283
-        if (! $merged) {
284
-            // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
285
-            $field_settings = $messenger->get_template_fields();
286
-            $localized = array();
287
-            foreach ($valid_shortcodes as $field => $shortcodes) {
288
-                // get localized field label
289
-                if (isset($field_settings[ $field ])) {
290
-                    // possible that this is used as a main field.
291
-                    if (empty($field_settings[ $field ])) {
292
-                        if (isset($field_settings['extra'][ $field ])) {
293
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
294
-                        } else {
295
-                            $_field = $field;
296
-                        }
297
-                    } else {
298
-                        $_field = $field_settings[ $field ]['label'];
299
-                    }
300
-                } elseif (isset($field_settings['extra'])) {
301
-                    // loop through extra "main fields" and see if any of their children have our field
302
-                    foreach ($field_settings['extra'] as $fields) {
303
-                        if (isset($fields[ $field ])) {
304
-                            $_field = $fields[ $field ]['label'];
305
-                        } else {
306
-                            $_field = $field;
307
-                        }
308
-                    }
309
-                } else {
310
-                    $_field = $field;
311
-                }
312
-                if (isset($_field)) {
313
-                    $localized[ (string) $_field ] = $shortcodes;
314
-                }
315
-            }
316
-            $valid_shortcodes = $localized;
317
-        }
318
-
319
-        // if $merged then let's merge all the shortcodes into one list NOT indexed by field.
320
-        if ($merged) {
321
-            $merged_codes = array();
322
-            foreach ($valid_shortcodes as $shortcode) {
323
-                foreach ($shortcode as $code => $label) {
324
-                    if (isset($merged_codes[ $code ])) {
325
-                        continue;
326
-                    } else {
327
-                        $merged_codes[ $code ] = $label;
328
-                    }
329
-                }
330
-            }
331
-            $valid_shortcodes = $merged_codes;
332
-        }
333
-
334
-        return $valid_shortcodes;
335
-    }
336
-
337
-
338
-    /**
339
-     * Get Messenger object.
340
-     *
341
-     * @param string $messenger messenger slug for the messenger object we want to retrieve.
342
-     * @return EE_messenger
343
-     * @throws ReflectionException
344
-     * @throws EE_Error*@since 4.3.0
345
-     * @deprecated 4.9.0
346
-     */
347
-    public static function messenger_obj($messenger)
348
-    {
349
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
350
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
351
-        return $Message_Resource_Manager->get_messenger($messenger);
352
-    }
353
-
354
-
355
-    /**
356
-     * get Message type object
357
-     *
358
-     * @param string $message_type the slug for the message type object to retrieve
359
-     * @return EE_message_type
360
-     * @throws ReflectionException
361
-     * @throws EE_Error*@since 4.3.0
362
-     * @deprecated 4.9.0
363
-     */
364
-    public static function message_type_obj($message_type)
365
-    {
366
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
367
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
368
-        return $Message_Resource_Manager->get_message_type($message_type);
369
-    }
370
-
371
-
372
-    /**
373
-     * Given a message_type slug, will return whether that message type is active in the system or not.
374
-     *
375
-     * @since    4.3.0
376
-     * @param string $message_type message type to check for.
377
-     * @return boolean
378
-     * @throws EE_Error
379
-     * @throws ReflectionException
380
-     */
381
-    public static function is_mt_active($message_type)
382
-    {
383
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
384
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
385
-        $active_mts = $Message_Resource_Manager->list_of_active_message_types();
386
-        return in_array($message_type, $active_mts);
387
-    }
388
-
389
-
390
-    /**
391
-     * Given a messenger slug, will return whether that messenger is active in the system or not.
392
-     *
393
-     * @since    4.3.0
394
-     *
395
-     * @param string $messenger slug for messenger to check.
396
-     * @return boolean
397
-     * @throws EE_Error
398
-     * @throws ReflectionException
399
-     */
400
-    public static function is_messenger_active($messenger)
401
-    {
402
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
403
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
404
-        $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
405
-        return $active_messenger instanceof EE_messenger;
406
-    }
407
-
408
-
409
-    /**
410
-     * Used to return active messengers array stored in the wp options table.
411
-     * If no value is present in the option then an empty array is returned.
412
-     *
413
-     * @deprecated 4.9
414
-     * @since      4.3.1
415
-     *
416
-     * @return array
417
-     * @throws EE_Error
418
-     * @throws ReflectionException
419
-     */
420
-    public static function get_active_messengers_in_db()
421
-    {
422
-        EE_Error::doing_it_wrong(
423
-            __METHOD__,
424
-            esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
425
-            '4.9.0'
426
-        );
427
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
428
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
429
-        return $Message_Resource_Manager->get_active_messengers_option();
430
-    }
431
-
432
-
433
-    /**
434
-     * Used to update the active messengers array stored in the wp options table.
435
-     *
436
-     * @since      4.3.1
437
-     * @deprecated 4.9.0
438
-     *
439
-     * @param array $data_to_save Incoming data to save.
440
-     *
441
-     * @return bool FALSE if not updated, TRUE if updated.
442
-     * @throws EE_Error
443
-     * @throws ReflectionException
444
-     */
445
-    public static function update_active_messengers_in_db($data_to_save)
446
-    {
447
-        EE_Error::doing_it_wrong(
448
-            __METHOD__,
449
-            esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
450
-            '4.9.0'
451
-        );
452
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
453
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
454
-        return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
455
-    }
456
-
457
-
458
-    /**
459
-     * This does some validation of incoming params, determines what type of url is being prepped and returns the
460
-     * appropriate url trigger
461
-     *
462
-     * @param EE_message_type $message_type
463
-     * @param EE_Message $message
464
-     * @param EE_Registration | null $registration  The registration object must be included if this
465
-     *                                              is going to be a registration trigger url.
466
-     * @param string $sending_messenger             The (optional) sending messenger for the url.
467
-     *
468
-     * @return string
469
-     * @throws EE_Error
470
-     */
471
-    public static function get_url_trigger(
472
-        EE_message_type $message_type,
473
-        EE_Message $message,
474
-        $registration = null,
475
-        $sending_messenger = ''
476
-    ) {
477
-        // first determine if the url can be to the EE_Message object.
478
-        if (! $message_type->always_generate()) {
479
-            return EEH_MSG_Template::generate_browser_trigger($message);
480
-        }
481
-
482
-        // if $registration object is not valid then exit early because there's nothing that can be generated.
483
-        if (! $registration instanceof EE_Registration) {
484
-            throw new EE_Error(
485
-                esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
486
-            );
487
-        }
488
-
489
-        // validate given context
490
-        $contexts = $message_type->get_contexts();
491
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
492
-            throw new EE_Error(
493
-                sprintf(
494
-                    esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
495
-                    $message->context(),
496
-                    get_class($message_type)
497
-                )
498
-            );
499
-        }
500
-
501
-        // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
502
-        if (! empty($sending_messenger)) {
503
-            $with_messengers = $message_type->with_messengers();
504
-            if (
505
-                ! isset($with_messengers[ $message->messenger() ])
506
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
507
-            ) {
508
-                throw new EE_Error(
509
-                    sprintf(
510
-                        esc_html__(
511
-                            'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
512
-                            'event_espresso'
513
-                        ),
514
-                        $sending_messenger,
515
-                        get_class($message_type)
516
-                    )
517
-                );
518
-            }
519
-        } else {
520
-            $sending_messenger = $message->messenger();
521
-        }
522
-        return EEH_MSG_Template::generate_url_trigger(
523
-            $sending_messenger,
524
-            $message->messenger(),
525
-            $message->context(),
526
-            $message->message_type(),
527
-            $registration,
528
-            $message->GRP_ID()
529
-        );
530
-    }
531
-
532
-
533
-    /**
534
-     * This returns the url for triggering a in browser view of a specific EE_Message object.
535
-     * @param EE_Message $message
536
-     * @return string.
537
-     */
538
-    public static function generate_browser_trigger(EE_Message $message)
539
-    {
540
-        $query_args = array(
541
-            'ee' => 'msg_browser_trigger',
542
-            'token' => $message->MSG_token()
543
-        );
544
-        return apply_filters(
545
-            'FHEE__EEH_MSG_Template__generate_browser_trigger',
546
-            add_query_arg($query_args, site_url()),
547
-            $message
548
-        );
549
-    }
550
-
551
-
552
-
553
-
554
-
555
-
556
-    /**
557
-     * This returns the url for triggering an in browser view of the error saved on the incoming message object.
558
-     * @param EE_Message $message
559
-     * @return string
560
-     */
561
-    public static function generate_error_display_trigger(EE_Message $message)
562
-    {
563
-        return apply_filters(
564
-            'FHEE__EEH_MSG_Template__generate_error_display_trigger',
565
-            add_query_arg(
566
-                array(
567
-                    'ee' => 'msg_browser_error_trigger',
568
-                    'token' => $message->MSG_token()
569
-                ),
570
-                site_url()
571
-            ),
572
-            $message
573
-        );
574
-    }
575
-
576
-
577
-    /**
578
-     * This generates a url trigger for the msg_url_trigger route using the given arguments
579
-     *
580
-     * @param string          $sending_messenger      The sending messenger slug.
581
-     * @param string          $generating_messenger   The generating messenger slug.
582
-     * @param string          $context                The context for the template.
583
-     * @param string          $message_type           The message type slug
584
-     * @param EE_Registration $registration
585
-     * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
586
-     * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
587
-     *                                                trigger.
588
-     * @return string          The generated url.
589
-     * @throws EE_Error
590
-     */
591
-    public static function generate_url_trigger(
592
-        $sending_messenger,
593
-        $generating_messenger,
594
-        $context,
595
-        $message_type,
596
-        EE_Registration $registration,
597
-        $message_template_group,
598
-        $data_id = 0
599
-    ) {
600
-        $query_args = array(
601
-            'ee' => 'msg_url_trigger',
602
-            'snd_msgr' => $sending_messenger,
603
-            'gen_msgr' => $generating_messenger,
604
-            'message_type' => $message_type,
605
-            'context' => $context,
606
-            'token' => $registration->reg_url_link(),
607
-            'GRP_ID' => $message_template_group,
608
-            'id' => $data_id
609
-            );
610
-        $url = add_query_arg($query_args, get_home_url());
611
-
612
-        // made it here so now we can just get the url and filter it.  Filtered globally and by message type.
613
-        return apply_filters(
614
-            'FHEE__EEH_MSG_Template__generate_url_trigger',
615
-            $url,
616
-            $sending_messenger,
617
-            $generating_messenger,
618
-            $context,
619
-            $message_type,
620
-            $registration,
621
-            $message_template_group,
622
-            $data_id
623
-        );
624
-    }
625
-
626
-
627
-
628
-
629
-    /**
630
-     * Return the specific css for the action icon given.
631
-     *
632
-     * @param string $type  What action to return.
633
-     * @return string[]
634
-     * @since 4.9.0
635
-     */
636
-    public static function get_message_action_icon($type)
637
-    {
638
-        $action_icons = self::get_message_action_icons();
639
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
640
-    }
641
-
642
-
643
-    /**
644
-     * This is used for retrieving the css classes used for the icons representing message actions.
645
-     *
646
-     * @since 4.9.0
647
-     *
648
-     * @return array
649
-     */
650
-    public static function get_message_action_icons()
651
-    {
652
-        return apply_filters(
653
-            'FHEE__EEH_MSG_Template__message_action_icons',
654
-            array(
655
-                'view' => array(
656
-                    'label' => esc_html__('View Message', 'event_espresso'),
657
-                    'css_class' => 'dashicons dashicons-welcome-view-site',
658
-                ),
659
-                'error' => array(
660
-                    'label' => esc_html__('View Error Message', 'event_espresso'),
661
-                    'css_class' => 'dashicons dashicons-info',
662
-                ),
663
-                'see_notifications_for' => array(
664
-                    'label' => esc_html__('View Related Messages', 'event_espresso'),
665
-                    'css_class' => 'dashicons dashicons-megaphone',
666
-                ),
667
-                'generate_now' => array(
668
-                    'label' => esc_html__('Generate the message now.', 'event_espresso'),
669
-                    'css_class' => 'dashicons dashicons-admin-tools',
670
-                ),
671
-                'send_now' => array(
672
-                    'label' => esc_html__('Send Immediately', 'event_espresso'),
673
-                    'css_class' => 'dashicons dashicons-controls-forward',
674
-                ),
675
-                'queue_for_resending' => array(
676
-                    'label' => esc_html__('Queue for Resending', 'event_espresso'),
677
-                    'css_class' => 'dashicons dashicons-controls-repeat',
678
-                ),
679
-                'view_transaction' => array(
680
-                    'label' => esc_html__('View related Transaction', 'event_espresso'),
681
-                    'css_class' => 'dashicons dashicons-cart',
682
-                )
683
-            )
684
-        );
685
-    }
686
-
687
-
688
-    /**
689
-     * This returns the url for a given action related to EE_Message.
690
-     *
691
-     * @param string     $type         What type of action to return the url for.
692
-     * @param EE_Message $message      Required for generating the correct url for some types.
693
-     * @param array      $query_params Any additional query params to be included with the generated url.
694
-     *
695
-     * @return string
696
-     * @throws EE_Error
697
-     * @throws ReflectionException
698
-     * @since 4.9.0
699
-     *
700
-     */
701
-    public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
702
-    {
703
-        $action_urls = self::get_message_action_urls($message, $query_params);
704
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
705
-    }
706
-
707
-
708
-    /**
709
-     * This returns all the current urls for EE_Message actions.
710
-     *
711
-     * @since 4.9.0
712
-     *
713
-     * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
714
-     * @param array      $query_params Any additional query_params to be included with the generated url.
715
-     *
716
-     * @return array
717
-     * @throws EE_Error
718
-     * @throws ReflectionException
719
-     */
720
-    public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
721
-    {
722
-        EE_Registry::instance()->load_helper('URL');
723
-        // if $message is not an instance of EE_Message then let's just do a dummy.
724
-        $message = empty($message) ? EE_Message_Factory::create() : $message;
725
-        $action_urls =  apply_filters(
726
-            'FHEE__EEH_MSG_Template__get_message_action_url',
727
-            array(
728
-                'view' => EEH_MSG_Template::generate_browser_trigger($message),
729
-                'error' => EEH_MSG_Template::generate_error_display_trigger($message),
730
-                'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
731
-                    array_merge(
732
-                        array(
733
-                            'page' => 'espresso_messages',
734
-                            'action' => 'default',
735
-                            'filterby' => 1,
736
-                        ),
737
-                        $query_params
738
-                    ),
739
-                    admin_url('admin.php')
740
-                ),
741
-                'generate_now' => EEH_URL::add_query_args_and_nonce(
742
-                    array(
743
-                        'page' => 'espresso_messages',
744
-                        'action' => 'generate_now',
745
-                        'MSG_ID' => $message->ID()
746
-                    ),
747
-                    admin_url('admin.php')
748
-                ),
749
-                'send_now' => EEH_URL::add_query_args_and_nonce(
750
-                    array(
751
-                        'page' => 'espresso_messages',
752
-                        'action' => 'send_now',
753
-                        'MSG_ID' => $message->ID()
754
-                    ),
755
-                    admin_url('admin.php')
756
-                ),
757
-                'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
758
-                    array(
759
-                        'page' => 'espresso_messages',
760
-                        'action' => 'queue_for_resending',
761
-                        'MSG_ID' => $message->ID()
762
-                    ),
763
-                    admin_url('admin.php')
764
-                ),
765
-            )
766
-        );
767
-        if (
768
-            $message->TXN_ID() > 0
769
-            && EE_Registry::instance()->CAP->current_user_can(
770
-                'ee_read_transaction',
771
-                'espresso_transactions_default',
772
-                $message->TXN_ID()
773
-            )
774
-        ) {
775
-            $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
776
-                array(
777
-                    'page' => 'espresso_transactions',
778
-                    'action' => 'view_transaction',
779
-                    'TXN_ID' => $message->TXN_ID()
780
-                ),
781
-                admin_url('admin.php')
782
-            );
783
-        } else {
784
-            $action_urls['view_transaction'] = '';
785
-        }
786
-        return $action_urls;
787
-    }
788
-
789
-
790
-    /**
791
-     * This returns a generated link html including the icon used for the action link for EE_Message actions.
792
-     *
793
-     * @param string          $type         What type of action the link is for (if invalid type is passed in then an
794
-     *                                      empty string is returned)
795
-     * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
796
-     * @param array           $query_params Any extra query params to include in the generated link.
797
-     *
798
-     * @return string
799
-     * @throws EE_Error
800
-     * @throws ReflectionException
801
-     * @since 4.9.0
802
-     *
803
-     */
804
-    public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
805
-    {
806
-        $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
807
-        $icon_css = EEH_MSG_Template::get_message_action_icon($type);
808
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
809
-
810
-        if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
811
-            return '';
812
-        }
813
-
814
-        $icon_css['css_class'] .= esc_attr(
815
-            apply_filters(
816
-                'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
817
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
818
-                $type,
819
-                $message,
820
-                $query_params
821
-            )
822
-        );
823
-
824
-        return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
825
-    }
826
-
827
-
828
-
829
-
830
-
831
-    /**
832
-     * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
833
-     *
834
-     * @since 4.9.0
835
-     * @return array
836
-     */
837
-    public static function reg_status_to_message_type_array()
838
-    {
839
-        return (array) apply_filters(
840
-            'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
841
-            array(
842
-                EEM_Registration::status_id_approved => 'registration',
843
-                EEM_Registration::status_id_pending_payment => 'pending_approval',
844
-                EEM_Registration::status_id_not_approved => 'not_approved_registration',
845
-                EEM_Registration::status_id_cancelled => 'cancelled_registration',
846
-                EEM_Registration::status_id_declined => 'declined_registration'
847
-            )
848
-        );
849
-    }
850
-
851
-
852
-
853
-
854
-    /**
855
-     * This returns the corresponding registration message type slug to the given reg status. If there isn't a
856
-     * match, then returns an empty string.
857
-     *
858
-     * @since 4.9.0
859
-     * @param $reg_status
860
-     * @return string
861
-     */
862
-    public static function convert_reg_status_to_message_type($reg_status)
863
-    {
864
-        $reg_status_array = self::reg_status_to_message_type_array();
865
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
866
-    }
867
-
868
-
869
-    /**
870
-     * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
871
-     *
872
-     * @since 4.9.0
873
-     * @return array
874
-     */
875
-    public static function payment_status_to_message_type_array()
876
-    {
877
-        return (array) apply_filters(
878
-            'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
879
-            array(
880
-                EEM_Payment::status_id_approved => 'payment',
881
-                EEM_Payment::status_id_pending => 'payment_pending',
882
-                EEM_Payment::status_id_cancelled => 'payment_cancelled',
883
-                EEM_Payment::status_id_declined => 'payment_declined',
884
-                EEM_Payment::status_id_failed => 'payment_failed'
885
-            )
886
-        );
887
-    }
888
-
889
-
890
-
891
-
892
-    /**
893
-     * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
894
-     * an empty string is returned
895
-     *
896
-     * @since 4.9.0
897
-     * @param $payment_status
898
-     * @return string
899
-     */
900
-    public static function convert_payment_status_to_message_type($payment_status)
901
-    {
902
-        $payment_status_array = self::payment_status_to_message_type_array();
903
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
904
-    }
905
-
906
-
907
-    /**
908
-     * This is used to retrieve the template pack for the given name.
909
-     *
910
-     * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
911
-     *
912
-     * @return EE_Messages_Template_Pack
913
-     */
914
-    public static function get_template_pack($template_pack_name)
915
-    {
916
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
917
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
918
-        }
919
-
920
-        // first see if in collection already
921
-        $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
922
-
923
-        if ($template_pack instanceof EE_Messages_Template_Pack) {
924
-            return $template_pack;
925
-        }
926
-
927
-        // nope...let's get it.
928
-        // not set yet so let's attempt to get it.
929
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
930
-            ' ',
931
-            '_',
932
-            ucwords(
933
-                str_replace('_', ' ', $template_pack_name)
934
-            )
935
-        );
936
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
937
-            return self::get_template_pack('default');
938
-        } else {
939
-            $template_pack = new $pack_class_name();
940
-            self::$_template_pack_collection->add($template_pack);
941
-            return $template_pack;
942
-        }
943
-    }
944
-
945
-
946
-
947
-
948
-    /**
949
-     * Globs template packs installed in core and returns the template pack collection with all installed template packs
950
-     * in it.
951
-     *
952
-     * @since 4.9.0
953
-     *
954
-     * @return EE_Messages_Template_Pack_Collection
955
-     */
956
-    public static function get_template_pack_collection()
957
-    {
958
-        $new_collection = false;
959
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
960
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
961
-            $new_collection = true;
962
-        }
963
-
964
-        // glob the defaults directory for messages
965
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
966
-        foreach ($templates as $template_path) {
967
-            // grab folder name
968
-            $template = basename($template_path);
969
-
970
-            if (! $new_collection) {
971
-                // already have it?
972
-                if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
973
-                    continue;
974
-                }
975
-            }
976
-
977
-            // setup classname.
978
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
979
-                ' ',
980
-                '_',
981
-                ucwords(
982
-                    str_replace(
983
-                        '_',
984
-                        ' ',
985
-                        $template
986
-                    )
987
-                )
988
-            );
989
-            if (! class_exists($template_pack_class_name)) {
990
-                continue;
991
-            }
992
-            self::$_template_pack_collection->add(new $template_pack_class_name());
993
-        }
994
-
995
-        /**
996
-         * Filter for plugins to add in any additional template packs
997
-         * Note the filter name here is for backward compat, this used to be found in EED_Messages.
998
-         */
999
-        $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1000
-        foreach ((array) $additional_template_packs as $template_pack) {
1001
-            if (
1002
-                self::$_template_pack_collection->get_by_name(
1003
-                    $template_pack->dbref
1004
-                ) instanceof EE_Messages_Template_Pack
1005
-            ) {
1006
-                continue;
1007
-            }
1008
-            self::$_template_pack_collection->add($template_pack);
1009
-        }
1010
-        return self::$_template_pack_collection;
1011
-    }
1012
-
1013
-
1014
-    /**
1015
-     * This is a wrapper for the protected _create_new_templates function
1016
-     *
1017
-     * @param string $messenger_name
1018
-     * @param string $message_type_name message type that the templates are being created for
1019
-     * @param int    $GRP_ID
1020
-     * @param bool   $global
1021
-     * @return array
1022
-     * @throws EE_Error
1023
-     * @throws ReflectionException
1024
-     */
1025
-    public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1026
-    {
1027
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1028
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1029
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1030
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1031
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1032
-            return array();
1033
-        }
1034
-        // whew made it this far!  Okay, let's go ahead and create the templates then
1035
-        return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * @param EE_messenger     $messenger
1041
-     * @param EE_message_type  $message_type
1042
-     * @param                  $GRP_ID
1043
-     * @param                  $global
1044
-     * @return array|mixed
1045
-     * @throws EE_Error
1046
-     * @throws ReflectionException
1047
-     */
1048
-    protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1049
-    {
1050
-        // if we're creating a custom template then we don't need to use the defaults class
1051
-        if (! $global) {
1052
-            return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1053
-        }
1054
-        /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1055
-        $Message_Template_Defaults = EE_Registry::factory(
1056
-            'EE_Messages_Template_Defaults',
1057
-            array( $messenger, $message_type, $GRP_ID )
1058
-        );
1059
-        // generate templates
1060
-        $success = $Message_Template_Defaults->create_new_templates();
1061
-
1062
-        // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1063
-        // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1064
-        // attempts.
1065
-        if (! $success) {
1066
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
1067
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1068
-            $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1069
-        }
1070
-
1071
-        /**
1072
-         * $success is in an array in the following format
1073
-         * array(
1074
-         *    'GRP_ID' => $new_grp_id,
1075
-         *    'MTP_context' => $first_context_in_new_templates,
1076
-         * )
1077
-         */
1078
-        return $success;
1079
-    }
1080
-
1081
-
1082
-    /**
1083
-     * This creates a custom template using the incoming GRP_ID
1084
-     *
1085
-     * @param EE_messenger    $messenger
1086
-     * @param EE_message_type $message_type
1087
-     * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1088
-     * @return  array $success              This will be an array in the format:
1089
-     *                                          array(
1090
-     *                                          'GRP_ID' => $new_grp_id,
1091
-     *                                          'MTP_context' => $first_context_in_created_template
1092
-     *                                          )
1093
-     * @throws EE_Error
1094
-     * @throws ReflectionException
1095
-     * @access private
1096
-     */
1097
-    private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1098
-    {
1099
-        // defaults
1100
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1101
-        // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1102
-        $Message_Template_Group = empty($GRP_ID)
1103
-            ? EEM_Message_Template_Group::instance()->get_one(
1104
-                array(
1105
-                    array(
1106
-                        'MTP_messenger'    => $messenger->name,
1107
-                        'MTP_message_type' => $message_type->name,
1108
-                        'MTP_is_global'    => true
1109
-                    )
1110
-                )
1111
-            )
1112
-            : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1113
-        // if we don't have a mtg at this point then we need to bail.
1114
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1115
-            EE_Error::add_error(
1116
-                sprintf(
1117
-                    esc_html__(
1118
-                        'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1119
-                        'event_espresso'
1120
-                    ),
1121
-                    $GRP_ID
1122
-                ),
1123
-                __FILE__,
1124
-                __FUNCTION__,
1125
-                __LINE__
1126
-            );
1127
-            return $success;
1128
-        }
1129
-        // let's get all the related message_template objects for this group.
1130
-        $message_templates = $Message_Template_Group->message_templates();
1131
-        // now we have what we need to setup the new template
1132
-        $new_mtg = clone $Message_Template_Group;
1133
-        $new_mtg->set('GRP_ID', 0);
1134
-        $new_mtg->set('MTP_is_global', false);
1135
-
1136
-        /** @var RequestInterface $request */
1137
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1138
-        $template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1139
-            ? $request->getRequestParam('templateName')
1140
-            : esc_html__('New Custom Template', 'event_espresso');
1141
-        $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1142
-            ? $request->getRequestParam('templateDescription')
1143
-            : sprintf(
1144
-                esc_html__(
1145
-                    'This is a custom template that was created for the %s messenger and %s message type.',
1146
-                    'event_espresso'
1147
-                ),
1148
-                $new_mtg->messenger_obj()->label['singular'],
1149
-                $new_mtg->message_type_obj()->label['singular']
1150
-            );
1151
-        $new_mtg->set('MTP_name', $template_name);
1152
-        $new_mtg->set('MTP_description', $template_description);
1153
-        // remove ALL relations on this template group so they don't get saved!
1154
-        $new_mtg->_remove_relations('Message_Template');
1155
-        $new_mtg->save();
1156
-        $success['GRP_ID'] = $new_mtg->ID();
1157
-        $success['template_name'] = $template_name;
1158
-        // add new message templates and add relation to.
1159
-        foreach ($message_templates as $message_template) {
1160
-            if (! $message_template instanceof EE_Message_Template) {
1161
-                continue;
1162
-            }
1163
-            $new_message_template = clone $message_template;
1164
-            $new_message_template->set('MTP_ID', 0);
1165
-            $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1166
-            $new_message_template->save();
1167
-            if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') {
1168
-                $success['MTP_context'] = $new_message_template->get('MTP_context');
1169
-            }
1170
-        }
1171
-        return $success;
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * message_type_has_active_templates_for_messenger
1177
-     *
1178
-     * @param EE_messenger    $messenger
1179
-     * @param EE_message_type $message_type
1180
-     * @param bool            $global
1181
-     * @return bool
1182
-     * @throws EE_Error
1183
-     */
1184
-    public static function message_type_has_active_templates_for_messenger(
1185
-        EE_messenger $messenger,
1186
-        EE_message_type $message_type,
1187
-        $global = false
1188
-    ) {
1189
-        // is given message_type valid for given messenger (if this is not a global save)
1190
-        if ($global) {
1191
-            return true;
1192
-        }
1193
-        $active_templates = EEM_Message_Template_Group::instance()->count(
1194
-            array(
1195
-                array(
1196
-                    'MTP_is_active'    => true,
1197
-                    'MTP_messenger'    => $messenger->name,
1198
-                    'MTP_message_type' => $message_type->name
1199
-                )
1200
-            )
1201
-        );
1202
-        if ($active_templates > 0) {
1203
-            return true;
1204
-        }
1205
-        EE_Error::add_error(
1206
-            sprintf(
1207
-                esc_html__(
1208
-                    'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1209
-                    'event_espresso'
1210
-                ),
1211
-                $message_type->name,
1212
-                $messenger->name
1213
-            ),
1214
-            __FILE__,
1215
-            __FUNCTION__,
1216
-            __LINE__
1217
-        );
1218
-        return false;
1219
-    }
1220
-
1221
-
1222
-    /**
1223
-     * get_fields
1224
-     * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1225
-     *
1226
-     * @param string $messenger_name    name of EE_messenger
1227
-     * @param string $message_type_name name of EE_message_type
1228
-     * @return array
1229
-     * @throws EE_Error
1230
-     * @throws ReflectionException
1231
-     */
1232
-    public static function get_fields($messenger_name, $message_type_name)
1233
-    {
1234
-        $template_fields = array();
1235
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1236
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1237
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1238
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1239
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1240
-            return array();
1241
-        }
1242
-
1243
-        $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1244
-
1245
-        // okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1246
-        foreach ($message_type->get_contexts() as $context => $details) {
1247
-            foreach ($messenger->get_template_fields() as $field => $value) {
1248
-                if (in_array($field, $excluded_fields_for_messenger, true)) {
1249
-                    continue;
1250
-                }
1251
-                $template_fields[ $context ][ $field ] = $value;
1252
-            }
1253
-        }
1254
-        if (empty($template_fields)) {
1255
-            EE_Error::add_error(
1256
-                esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1257
-                __FILE__,
1258
-                __FUNCTION__,
1259
-                __LINE__
1260
-            );
1261
-            return array();
1262
-        }
1263
-        return $template_fields;
1264
-    }
16
+	/**
17
+	 * Holds a collection of EE_Message_Template_Pack objects.
18
+	 * @type EE_Messages_Template_Pack_Collection
19
+	 */
20
+	protected static $_template_pack_collection;
21
+
22
+
23
+	/**
24
+	 * @throws EE_Error
25
+	 */
26
+	private static function _set_autoloader()
27
+	{
28
+		EED_Messages::set_autoloaders();
29
+	}
30
+
31
+
32
+	/**
33
+	 * generate_new_templates
34
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
35
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
36
+	 * for the event.
37
+	 *
38
+	 * @access protected
39
+	 * @param string $messenger     the messenger we are generating templates for
40
+	 * @param array  $message_types array of message types that the templates are generated for.
41
+	 * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
42
+	 *                              to use as the base for the new generated template.
43
+	 * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
44
+	 *                              for event specific template generation.
45
+	 * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
46
+	 *                for templates that are generated.  If this is an empty array then it means no templates were
47
+	 *                generated which usually means there was an error.  Anything in the array with an empty value for
48
+	 *                `MTP_context` means that it was not a new generated template but just reactivated (which only
49
+	 *                happens for global templates that already exist in the database.
50
+	 * @throws EE_Error
51
+	 * @throws ReflectionException
52
+	 */
53
+	public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
54
+	{
55
+		// make sure message_type is an array.
56
+		$message_types = (array) $message_types;
57
+		$templates = array();
58
+
59
+		if (empty($messenger)) {
60
+			throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
61
+		}
62
+
63
+		// if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
64
+		if (empty($message_types)) {
65
+			throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
66
+		}
67
+
68
+		EEH_MSG_Template::_set_autoloader();
69
+		foreach ($message_types as $message_type) {
70
+			// if this is global template generation.
71
+			if ($global) {
72
+				// let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
73
+				if (empty($GRP_ID)) {
74
+					$GRP_ID = EEM_Message_Template_Group::instance()->get_one(
75
+						array(
76
+							array(
77
+								'MTP_messenger'    => $messenger,
78
+								'MTP_message_type' => $message_type,
79
+								'MTP_is_global'    => true,
80
+							),
81
+						)
82
+					);
83
+					$GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
84
+				}
85
+				// First let's determine if we already HAVE global templates for this messenger and message_type combination.
86
+				//  If we do then NO generation!!
87
+				if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
88
+					$templates[] = array(
89
+						'GRP_ID' => $GRP_ID,
90
+						'MTP_context' => '',
91
+					);
92
+					// we already have generated templates for this so let's go to the next message type.
93
+					continue;
94
+				}
95
+			}
96
+			$new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
97
+
98
+			if (! $new_message_template_group) {
99
+				continue;
100
+			}
101
+			$templates[] = $new_message_template_group;
102
+		}
103
+
104
+		return $templates;
105
+	}
106
+
107
+
108
+	/**
109
+	 * The purpose of this method is to determine if there are already generated templates in the database for the
110
+	 * given variables.
111
+	 *
112
+	 * @param string $messenger    messenger
113
+	 * @param string $message_type message type
114
+	 * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
115
+	 *                             template check)
116
+	 * @return bool                true = generated, false = hasn't been generated.
117
+	 * @throws EE_Error
118
+	 */
119
+	public static function already_generated($messenger, $message_type, $GRP_ID = 0)
120
+	{
121
+		EEH_MSG_Template::_set_autoloader();
122
+		// what method we use depends on whether we have an GRP_ID or not
123
+		$count = empty($GRP_ID)
124
+			? EEM_Message_Template::instance()->count(
125
+				array(
126
+					array(
127
+						'Message_Template_Group.MTP_messenger'    => $messenger,
128
+						'Message_Template_Group.MTP_message_type' => $message_type,
129
+						'Message_Template_Group.MTP_is_global'    => true
130
+					)
131
+				)
132
+			)
133
+			: EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
134
+
135
+		return $count > 0;
136
+	}
137
+
138
+
139
+	/**
140
+	 * Updates all message templates matching the incoming messengers and message types to active status.
141
+	 *
142
+	 * @static
143
+	 * @param array $messenger_names    Messenger slug
144
+	 * @param array $message_type_names Message type slug
145
+	 * @return  int                         count of updated records.
146
+	 * @throws EE_Error
147
+	 */
148
+	public static function update_to_active($messenger_names, $message_type_names)
149
+	{
150
+		$messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
151
+		$message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
152
+		return EEM_Message_Template_Group::instance()->update(
153
+			array( 'MTP_is_active' => 1 ),
154
+			array(
155
+				array(
156
+					'MTP_messenger'     => array( 'IN', $messenger_names ),
157
+					'MTP_message_type'  => array( 'IN', $message_type_names )
158
+				)
159
+			)
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * Updates all message template groups matching the incoming arguments to inactive status.
166
+	 *
167
+	 * @static
168
+	 * @param array $messenger_names    The messenger slugs.
169
+	 *                                  If empty then all templates matching the message types are marked inactive.
170
+	 *                                  Otherwise only templates matching the messengers and message types.
171
+	 * @param array $message_type_names The message type slugs.
172
+	 *                                  If empty then all templates matching the messengers are marked inactive.
173
+	 *                                  Otherwise only templates matching the messengers and message types.
174
+	 *
175
+	 * @return int  count of updated records.
176
+	 * @throws EE_Error
177
+	 */
178
+	public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
179
+	{
180
+		return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
181
+			$messenger_names,
182
+			$message_type_names
183
+		);
184
+	}
185
+
186
+
187
+	/**
188
+	 * The purpose of this function is to return all installed message objects
189
+	 * (messengers and message type regardless of whether they are ACTIVE or not)
190
+	 *
191
+	 * @param string $type
192
+	 * @return array array consisting of installed messenger objects and installed message type objects.
193
+	 * @throws EE_Error
194
+	 * @throws ReflectionException
195
+	 * @deprecated 4.9.0
196
+	 * @static
197
+	 */
198
+	public static function get_installed_message_objects($type = 'all')
199
+	{
200
+		self::_set_autoloader();
201
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
202
+		return array(
203
+			'messenger' => $message_resource_manager->installed_messengers(),
204
+			'message_type' => $message_resource_manager->installed_message_types()
205
+		);
206
+	}
207
+
208
+
209
+	/**
210
+	 * This will return an array of shortcodes => labels from the
211
+	 * messenger and message_type objects associated with this
212
+	 * template.
213
+	 *
214
+	 * @param string $message_type
215
+	 * @param string $messenger
216
+	 * @param array  $fields                        What fields we're returning valid shortcodes for.
217
+	 *                                              If empty then we assume all fields are to be returned. Optional.
218
+	 * @param string $context                       What context we're going to return shortcodes for. Optional.
219
+	 * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
220
+	 *                                              but instead an array of the unique shortcodes for all the given (
221
+	 *                                              or all) fields. Optional.
222
+	 * @return array                                an array of shortcodes in the format
223
+	 *                                              array( '[shortcode] => 'label')
224
+	 *                                              OR
225
+	 *                                              FALSE if no shortcodes found.
226
+	 * @throws ReflectionException
227
+	 * @throws EE_Error*@since 4.3.0
228
+	 *
229
+	 */
230
+	public static function get_shortcodes(
231
+		$message_type,
232
+		$messenger,
233
+		$fields = array(),
234
+		$context = 'admin',
235
+		$merged = false
236
+	) {
237
+		$messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
238
+		$mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
239
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
240
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
241
+		// convert slug to object
242
+		$messenger = $message_resource_manager->get_messenger($messenger);
243
+
244
+		// if messenger isn't a EE_messenger resource then bail.
245
+		if (! $messenger instanceof EE_messenger) {
246
+			return array();
247
+		}
248
+
249
+		// validate class for getting our list of shortcodes
250
+		$classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
251
+		if (! class_exists($classname)) {
252
+			$msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
253
+			$msg[] = sprintf(
254
+				esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
255
+				$classname
256
+			);
257
+			throw new EE_Error(implode('||', $msg));
258
+		}
259
+
260
+		/** @type EE_Messages_Validator $_VLD */
261
+		$_VLD = new $classname(array(), $context);
262
+		$valid_shortcodes = $_VLD->get_validators();
263
+
264
+		// let's make sure we're only getting the shortcode part of the validators
265
+		$shortcodes = array();
266
+		foreach ($valid_shortcodes as $field => $validators) {
267
+			$shortcodes[ $field ] = $validators['shortcodes'];
268
+		}
269
+		$valid_shortcodes = $shortcodes;
270
+
271
+		// if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
272
+		if (! empty($fields)) {
273
+			$specified_shortcodes = array();
274
+			foreach ($fields as $field) {
275
+				if (isset($valid_shortcodes[ $field ])) {
276
+					$specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
277
+				}
278
+			}
279
+			$valid_shortcodes = $specified_shortcodes;
280
+		}
281
+
282
+		// if not merged then let's replace the fields with the localized fields
283
+		if (! $merged) {
284
+			// let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
285
+			$field_settings = $messenger->get_template_fields();
286
+			$localized = array();
287
+			foreach ($valid_shortcodes as $field => $shortcodes) {
288
+				// get localized field label
289
+				if (isset($field_settings[ $field ])) {
290
+					// possible that this is used as a main field.
291
+					if (empty($field_settings[ $field ])) {
292
+						if (isset($field_settings['extra'][ $field ])) {
293
+							$_field = $field_settings['extra'][ $field ]['main']['label'];
294
+						} else {
295
+							$_field = $field;
296
+						}
297
+					} else {
298
+						$_field = $field_settings[ $field ]['label'];
299
+					}
300
+				} elseif (isset($field_settings['extra'])) {
301
+					// loop through extra "main fields" and see if any of their children have our field
302
+					foreach ($field_settings['extra'] as $fields) {
303
+						if (isset($fields[ $field ])) {
304
+							$_field = $fields[ $field ]['label'];
305
+						} else {
306
+							$_field = $field;
307
+						}
308
+					}
309
+				} else {
310
+					$_field = $field;
311
+				}
312
+				if (isset($_field)) {
313
+					$localized[ (string) $_field ] = $shortcodes;
314
+				}
315
+			}
316
+			$valid_shortcodes = $localized;
317
+		}
318
+
319
+		// if $merged then let's merge all the shortcodes into one list NOT indexed by field.
320
+		if ($merged) {
321
+			$merged_codes = array();
322
+			foreach ($valid_shortcodes as $shortcode) {
323
+				foreach ($shortcode as $code => $label) {
324
+					if (isset($merged_codes[ $code ])) {
325
+						continue;
326
+					} else {
327
+						$merged_codes[ $code ] = $label;
328
+					}
329
+				}
330
+			}
331
+			$valid_shortcodes = $merged_codes;
332
+		}
333
+
334
+		return $valid_shortcodes;
335
+	}
336
+
337
+
338
+	/**
339
+	 * Get Messenger object.
340
+	 *
341
+	 * @param string $messenger messenger slug for the messenger object we want to retrieve.
342
+	 * @return EE_messenger
343
+	 * @throws ReflectionException
344
+	 * @throws EE_Error*@since 4.3.0
345
+	 * @deprecated 4.9.0
346
+	 */
347
+	public static function messenger_obj($messenger)
348
+	{
349
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
350
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
351
+		return $Message_Resource_Manager->get_messenger($messenger);
352
+	}
353
+
354
+
355
+	/**
356
+	 * get Message type object
357
+	 *
358
+	 * @param string $message_type the slug for the message type object to retrieve
359
+	 * @return EE_message_type
360
+	 * @throws ReflectionException
361
+	 * @throws EE_Error*@since 4.3.0
362
+	 * @deprecated 4.9.0
363
+	 */
364
+	public static function message_type_obj($message_type)
365
+	{
366
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
367
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
368
+		return $Message_Resource_Manager->get_message_type($message_type);
369
+	}
370
+
371
+
372
+	/**
373
+	 * Given a message_type slug, will return whether that message type is active in the system or not.
374
+	 *
375
+	 * @since    4.3.0
376
+	 * @param string $message_type message type to check for.
377
+	 * @return boolean
378
+	 * @throws EE_Error
379
+	 * @throws ReflectionException
380
+	 */
381
+	public static function is_mt_active($message_type)
382
+	{
383
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
384
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
385
+		$active_mts = $Message_Resource_Manager->list_of_active_message_types();
386
+		return in_array($message_type, $active_mts);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Given a messenger slug, will return whether that messenger is active in the system or not.
392
+	 *
393
+	 * @since    4.3.0
394
+	 *
395
+	 * @param string $messenger slug for messenger to check.
396
+	 * @return boolean
397
+	 * @throws EE_Error
398
+	 * @throws ReflectionException
399
+	 */
400
+	public static function is_messenger_active($messenger)
401
+	{
402
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
403
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
404
+		$active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
405
+		return $active_messenger instanceof EE_messenger;
406
+	}
407
+
408
+
409
+	/**
410
+	 * Used to return active messengers array stored in the wp options table.
411
+	 * If no value is present in the option then an empty array is returned.
412
+	 *
413
+	 * @deprecated 4.9
414
+	 * @since      4.3.1
415
+	 *
416
+	 * @return array
417
+	 * @throws EE_Error
418
+	 * @throws ReflectionException
419
+	 */
420
+	public static function get_active_messengers_in_db()
421
+	{
422
+		EE_Error::doing_it_wrong(
423
+			__METHOD__,
424
+			esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
425
+			'4.9.0'
426
+		);
427
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
428
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
429
+		return $Message_Resource_Manager->get_active_messengers_option();
430
+	}
431
+
432
+
433
+	/**
434
+	 * Used to update the active messengers array stored in the wp options table.
435
+	 *
436
+	 * @since      4.3.1
437
+	 * @deprecated 4.9.0
438
+	 *
439
+	 * @param array $data_to_save Incoming data to save.
440
+	 *
441
+	 * @return bool FALSE if not updated, TRUE if updated.
442
+	 * @throws EE_Error
443
+	 * @throws ReflectionException
444
+	 */
445
+	public static function update_active_messengers_in_db($data_to_save)
446
+	{
447
+		EE_Error::doing_it_wrong(
448
+			__METHOD__,
449
+			esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
450
+			'4.9.0'
451
+		);
452
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
453
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
454
+		return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
455
+	}
456
+
457
+
458
+	/**
459
+	 * This does some validation of incoming params, determines what type of url is being prepped and returns the
460
+	 * appropriate url trigger
461
+	 *
462
+	 * @param EE_message_type $message_type
463
+	 * @param EE_Message $message
464
+	 * @param EE_Registration | null $registration  The registration object must be included if this
465
+	 *                                              is going to be a registration trigger url.
466
+	 * @param string $sending_messenger             The (optional) sending messenger for the url.
467
+	 *
468
+	 * @return string
469
+	 * @throws EE_Error
470
+	 */
471
+	public static function get_url_trigger(
472
+		EE_message_type $message_type,
473
+		EE_Message $message,
474
+		$registration = null,
475
+		$sending_messenger = ''
476
+	) {
477
+		// first determine if the url can be to the EE_Message object.
478
+		if (! $message_type->always_generate()) {
479
+			return EEH_MSG_Template::generate_browser_trigger($message);
480
+		}
481
+
482
+		// if $registration object is not valid then exit early because there's nothing that can be generated.
483
+		if (! $registration instanceof EE_Registration) {
484
+			throw new EE_Error(
485
+				esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
486
+			);
487
+		}
488
+
489
+		// validate given context
490
+		$contexts = $message_type->get_contexts();
491
+		if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
492
+			throw new EE_Error(
493
+				sprintf(
494
+					esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
495
+					$message->context(),
496
+					get_class($message_type)
497
+				)
498
+			);
499
+		}
500
+
501
+		// valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
502
+		if (! empty($sending_messenger)) {
503
+			$with_messengers = $message_type->with_messengers();
504
+			if (
505
+				! isset($with_messengers[ $message->messenger() ])
506
+				 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
507
+			) {
508
+				throw new EE_Error(
509
+					sprintf(
510
+						esc_html__(
511
+							'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
512
+							'event_espresso'
513
+						),
514
+						$sending_messenger,
515
+						get_class($message_type)
516
+					)
517
+				);
518
+			}
519
+		} else {
520
+			$sending_messenger = $message->messenger();
521
+		}
522
+		return EEH_MSG_Template::generate_url_trigger(
523
+			$sending_messenger,
524
+			$message->messenger(),
525
+			$message->context(),
526
+			$message->message_type(),
527
+			$registration,
528
+			$message->GRP_ID()
529
+		);
530
+	}
531
+
532
+
533
+	/**
534
+	 * This returns the url for triggering a in browser view of a specific EE_Message object.
535
+	 * @param EE_Message $message
536
+	 * @return string.
537
+	 */
538
+	public static function generate_browser_trigger(EE_Message $message)
539
+	{
540
+		$query_args = array(
541
+			'ee' => 'msg_browser_trigger',
542
+			'token' => $message->MSG_token()
543
+		);
544
+		return apply_filters(
545
+			'FHEE__EEH_MSG_Template__generate_browser_trigger',
546
+			add_query_arg($query_args, site_url()),
547
+			$message
548
+		);
549
+	}
550
+
551
+
552
+
553
+
554
+
555
+
556
+	/**
557
+	 * This returns the url for triggering an in browser view of the error saved on the incoming message object.
558
+	 * @param EE_Message $message
559
+	 * @return string
560
+	 */
561
+	public static function generate_error_display_trigger(EE_Message $message)
562
+	{
563
+		return apply_filters(
564
+			'FHEE__EEH_MSG_Template__generate_error_display_trigger',
565
+			add_query_arg(
566
+				array(
567
+					'ee' => 'msg_browser_error_trigger',
568
+					'token' => $message->MSG_token()
569
+				),
570
+				site_url()
571
+			),
572
+			$message
573
+		);
574
+	}
575
+
576
+
577
+	/**
578
+	 * This generates a url trigger for the msg_url_trigger route using the given arguments
579
+	 *
580
+	 * @param string          $sending_messenger      The sending messenger slug.
581
+	 * @param string          $generating_messenger   The generating messenger slug.
582
+	 * @param string          $context                The context for the template.
583
+	 * @param string          $message_type           The message type slug
584
+	 * @param EE_Registration $registration
585
+	 * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
586
+	 * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
587
+	 *                                                trigger.
588
+	 * @return string          The generated url.
589
+	 * @throws EE_Error
590
+	 */
591
+	public static function generate_url_trigger(
592
+		$sending_messenger,
593
+		$generating_messenger,
594
+		$context,
595
+		$message_type,
596
+		EE_Registration $registration,
597
+		$message_template_group,
598
+		$data_id = 0
599
+	) {
600
+		$query_args = array(
601
+			'ee' => 'msg_url_trigger',
602
+			'snd_msgr' => $sending_messenger,
603
+			'gen_msgr' => $generating_messenger,
604
+			'message_type' => $message_type,
605
+			'context' => $context,
606
+			'token' => $registration->reg_url_link(),
607
+			'GRP_ID' => $message_template_group,
608
+			'id' => $data_id
609
+			);
610
+		$url = add_query_arg($query_args, get_home_url());
611
+
612
+		// made it here so now we can just get the url and filter it.  Filtered globally and by message type.
613
+		return apply_filters(
614
+			'FHEE__EEH_MSG_Template__generate_url_trigger',
615
+			$url,
616
+			$sending_messenger,
617
+			$generating_messenger,
618
+			$context,
619
+			$message_type,
620
+			$registration,
621
+			$message_template_group,
622
+			$data_id
623
+		);
624
+	}
625
+
626
+
627
+
628
+
629
+	/**
630
+	 * Return the specific css for the action icon given.
631
+	 *
632
+	 * @param string $type  What action to return.
633
+	 * @return string[]
634
+	 * @since 4.9.0
635
+	 */
636
+	public static function get_message_action_icon($type)
637
+	{
638
+		$action_icons = self::get_message_action_icons();
639
+		return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
640
+	}
641
+
642
+
643
+	/**
644
+	 * This is used for retrieving the css classes used for the icons representing message actions.
645
+	 *
646
+	 * @since 4.9.0
647
+	 *
648
+	 * @return array
649
+	 */
650
+	public static function get_message_action_icons()
651
+	{
652
+		return apply_filters(
653
+			'FHEE__EEH_MSG_Template__message_action_icons',
654
+			array(
655
+				'view' => array(
656
+					'label' => esc_html__('View Message', 'event_espresso'),
657
+					'css_class' => 'dashicons dashicons-welcome-view-site',
658
+				),
659
+				'error' => array(
660
+					'label' => esc_html__('View Error Message', 'event_espresso'),
661
+					'css_class' => 'dashicons dashicons-info',
662
+				),
663
+				'see_notifications_for' => array(
664
+					'label' => esc_html__('View Related Messages', 'event_espresso'),
665
+					'css_class' => 'dashicons dashicons-megaphone',
666
+				),
667
+				'generate_now' => array(
668
+					'label' => esc_html__('Generate the message now.', 'event_espresso'),
669
+					'css_class' => 'dashicons dashicons-admin-tools',
670
+				),
671
+				'send_now' => array(
672
+					'label' => esc_html__('Send Immediately', 'event_espresso'),
673
+					'css_class' => 'dashicons dashicons-controls-forward',
674
+				),
675
+				'queue_for_resending' => array(
676
+					'label' => esc_html__('Queue for Resending', 'event_espresso'),
677
+					'css_class' => 'dashicons dashicons-controls-repeat',
678
+				),
679
+				'view_transaction' => array(
680
+					'label' => esc_html__('View related Transaction', 'event_espresso'),
681
+					'css_class' => 'dashicons dashicons-cart',
682
+				)
683
+			)
684
+		);
685
+	}
686
+
687
+
688
+	/**
689
+	 * This returns the url for a given action related to EE_Message.
690
+	 *
691
+	 * @param string     $type         What type of action to return the url for.
692
+	 * @param EE_Message $message      Required for generating the correct url for some types.
693
+	 * @param array      $query_params Any additional query params to be included with the generated url.
694
+	 *
695
+	 * @return string
696
+	 * @throws EE_Error
697
+	 * @throws ReflectionException
698
+	 * @since 4.9.0
699
+	 *
700
+	 */
701
+	public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
702
+	{
703
+		$action_urls = self::get_message_action_urls($message, $query_params);
704
+		return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
705
+	}
706
+
707
+
708
+	/**
709
+	 * This returns all the current urls for EE_Message actions.
710
+	 *
711
+	 * @since 4.9.0
712
+	 *
713
+	 * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
714
+	 * @param array      $query_params Any additional query_params to be included with the generated url.
715
+	 *
716
+	 * @return array
717
+	 * @throws EE_Error
718
+	 * @throws ReflectionException
719
+	 */
720
+	public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
721
+	{
722
+		EE_Registry::instance()->load_helper('URL');
723
+		// if $message is not an instance of EE_Message then let's just do a dummy.
724
+		$message = empty($message) ? EE_Message_Factory::create() : $message;
725
+		$action_urls =  apply_filters(
726
+			'FHEE__EEH_MSG_Template__get_message_action_url',
727
+			array(
728
+				'view' => EEH_MSG_Template::generate_browser_trigger($message),
729
+				'error' => EEH_MSG_Template::generate_error_display_trigger($message),
730
+				'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
731
+					array_merge(
732
+						array(
733
+							'page' => 'espresso_messages',
734
+							'action' => 'default',
735
+							'filterby' => 1,
736
+						),
737
+						$query_params
738
+					),
739
+					admin_url('admin.php')
740
+				),
741
+				'generate_now' => EEH_URL::add_query_args_and_nonce(
742
+					array(
743
+						'page' => 'espresso_messages',
744
+						'action' => 'generate_now',
745
+						'MSG_ID' => $message->ID()
746
+					),
747
+					admin_url('admin.php')
748
+				),
749
+				'send_now' => EEH_URL::add_query_args_and_nonce(
750
+					array(
751
+						'page' => 'espresso_messages',
752
+						'action' => 'send_now',
753
+						'MSG_ID' => $message->ID()
754
+					),
755
+					admin_url('admin.php')
756
+				),
757
+				'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
758
+					array(
759
+						'page' => 'espresso_messages',
760
+						'action' => 'queue_for_resending',
761
+						'MSG_ID' => $message->ID()
762
+					),
763
+					admin_url('admin.php')
764
+				),
765
+			)
766
+		);
767
+		if (
768
+			$message->TXN_ID() > 0
769
+			&& EE_Registry::instance()->CAP->current_user_can(
770
+				'ee_read_transaction',
771
+				'espresso_transactions_default',
772
+				$message->TXN_ID()
773
+			)
774
+		) {
775
+			$action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
776
+				array(
777
+					'page' => 'espresso_transactions',
778
+					'action' => 'view_transaction',
779
+					'TXN_ID' => $message->TXN_ID()
780
+				),
781
+				admin_url('admin.php')
782
+			);
783
+		} else {
784
+			$action_urls['view_transaction'] = '';
785
+		}
786
+		return $action_urls;
787
+	}
788
+
789
+
790
+	/**
791
+	 * This returns a generated link html including the icon used for the action link for EE_Message actions.
792
+	 *
793
+	 * @param string          $type         What type of action the link is for (if invalid type is passed in then an
794
+	 *                                      empty string is returned)
795
+	 * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
796
+	 * @param array           $query_params Any extra query params to include in the generated link.
797
+	 *
798
+	 * @return string
799
+	 * @throws EE_Error
800
+	 * @throws ReflectionException
801
+	 * @since 4.9.0
802
+	 *
803
+	 */
804
+	public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
805
+	{
806
+		$url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
807
+		$icon_css = EEH_MSG_Template::get_message_action_icon($type);
808
+		$title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
809
+
810
+		if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
811
+			return '';
812
+		}
813
+
814
+		$icon_css['css_class'] .= esc_attr(
815
+			apply_filters(
816
+				'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
817
+				' js-ee-message-action-link ee-message-action-link-' . $type,
818
+				$type,
819
+				$message,
820
+				$query_params
821
+			)
822
+		);
823
+
824
+		return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
825
+	}
826
+
827
+
828
+
829
+
830
+
831
+	/**
832
+	 * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
833
+	 *
834
+	 * @since 4.9.0
835
+	 * @return array
836
+	 */
837
+	public static function reg_status_to_message_type_array()
838
+	{
839
+		return (array) apply_filters(
840
+			'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
841
+			array(
842
+				EEM_Registration::status_id_approved => 'registration',
843
+				EEM_Registration::status_id_pending_payment => 'pending_approval',
844
+				EEM_Registration::status_id_not_approved => 'not_approved_registration',
845
+				EEM_Registration::status_id_cancelled => 'cancelled_registration',
846
+				EEM_Registration::status_id_declined => 'declined_registration'
847
+			)
848
+		);
849
+	}
850
+
851
+
852
+
853
+
854
+	/**
855
+	 * This returns the corresponding registration message type slug to the given reg status. If there isn't a
856
+	 * match, then returns an empty string.
857
+	 *
858
+	 * @since 4.9.0
859
+	 * @param $reg_status
860
+	 * @return string
861
+	 */
862
+	public static function convert_reg_status_to_message_type($reg_status)
863
+	{
864
+		$reg_status_array = self::reg_status_to_message_type_array();
865
+		return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
866
+	}
867
+
868
+
869
+	/**
870
+	 * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
871
+	 *
872
+	 * @since 4.9.0
873
+	 * @return array
874
+	 */
875
+	public static function payment_status_to_message_type_array()
876
+	{
877
+		return (array) apply_filters(
878
+			'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
879
+			array(
880
+				EEM_Payment::status_id_approved => 'payment',
881
+				EEM_Payment::status_id_pending => 'payment_pending',
882
+				EEM_Payment::status_id_cancelled => 'payment_cancelled',
883
+				EEM_Payment::status_id_declined => 'payment_declined',
884
+				EEM_Payment::status_id_failed => 'payment_failed'
885
+			)
886
+		);
887
+	}
888
+
889
+
890
+
891
+
892
+	/**
893
+	 * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
894
+	 * an empty string is returned
895
+	 *
896
+	 * @since 4.9.0
897
+	 * @param $payment_status
898
+	 * @return string
899
+	 */
900
+	public static function convert_payment_status_to_message_type($payment_status)
901
+	{
902
+		$payment_status_array = self::payment_status_to_message_type_array();
903
+		return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
904
+	}
905
+
906
+
907
+	/**
908
+	 * This is used to retrieve the template pack for the given name.
909
+	 *
910
+	 * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
911
+	 *
912
+	 * @return EE_Messages_Template_Pack
913
+	 */
914
+	public static function get_template_pack($template_pack_name)
915
+	{
916
+		if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
917
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
918
+		}
919
+
920
+		// first see if in collection already
921
+		$template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
922
+
923
+		if ($template_pack instanceof EE_Messages_Template_Pack) {
924
+			return $template_pack;
925
+		}
926
+
927
+		// nope...let's get it.
928
+		// not set yet so let's attempt to get it.
929
+		$pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
930
+			' ',
931
+			'_',
932
+			ucwords(
933
+				str_replace('_', ' ', $template_pack_name)
934
+			)
935
+		);
936
+		if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
937
+			return self::get_template_pack('default');
938
+		} else {
939
+			$template_pack = new $pack_class_name();
940
+			self::$_template_pack_collection->add($template_pack);
941
+			return $template_pack;
942
+		}
943
+	}
944
+
945
+
946
+
947
+
948
+	/**
949
+	 * Globs template packs installed in core and returns the template pack collection with all installed template packs
950
+	 * in it.
951
+	 *
952
+	 * @since 4.9.0
953
+	 *
954
+	 * @return EE_Messages_Template_Pack_Collection
955
+	 */
956
+	public static function get_template_pack_collection()
957
+	{
958
+		$new_collection = false;
959
+		if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
960
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
961
+			$new_collection = true;
962
+		}
963
+
964
+		// glob the defaults directory for messages
965
+		$templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
966
+		foreach ($templates as $template_path) {
967
+			// grab folder name
968
+			$template = basename($template_path);
969
+
970
+			if (! $new_collection) {
971
+				// already have it?
972
+				if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
973
+					continue;
974
+				}
975
+			}
976
+
977
+			// setup classname.
978
+			$template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
979
+				' ',
980
+				'_',
981
+				ucwords(
982
+					str_replace(
983
+						'_',
984
+						' ',
985
+						$template
986
+					)
987
+				)
988
+			);
989
+			if (! class_exists($template_pack_class_name)) {
990
+				continue;
991
+			}
992
+			self::$_template_pack_collection->add(new $template_pack_class_name());
993
+		}
994
+
995
+		/**
996
+		 * Filter for plugins to add in any additional template packs
997
+		 * Note the filter name here is for backward compat, this used to be found in EED_Messages.
998
+		 */
999
+		$additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1000
+		foreach ((array) $additional_template_packs as $template_pack) {
1001
+			if (
1002
+				self::$_template_pack_collection->get_by_name(
1003
+					$template_pack->dbref
1004
+				) instanceof EE_Messages_Template_Pack
1005
+			) {
1006
+				continue;
1007
+			}
1008
+			self::$_template_pack_collection->add($template_pack);
1009
+		}
1010
+		return self::$_template_pack_collection;
1011
+	}
1012
+
1013
+
1014
+	/**
1015
+	 * This is a wrapper for the protected _create_new_templates function
1016
+	 *
1017
+	 * @param string $messenger_name
1018
+	 * @param string $message_type_name message type that the templates are being created for
1019
+	 * @param int    $GRP_ID
1020
+	 * @param bool   $global
1021
+	 * @return array
1022
+	 * @throws EE_Error
1023
+	 * @throws ReflectionException
1024
+	 */
1025
+	public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1026
+	{
1027
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1028
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1029
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1030
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1031
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1032
+			return array();
1033
+		}
1034
+		// whew made it this far!  Okay, let's go ahead and create the templates then
1035
+		return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * @param EE_messenger     $messenger
1041
+	 * @param EE_message_type  $message_type
1042
+	 * @param                  $GRP_ID
1043
+	 * @param                  $global
1044
+	 * @return array|mixed
1045
+	 * @throws EE_Error
1046
+	 * @throws ReflectionException
1047
+	 */
1048
+	protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1049
+	{
1050
+		// if we're creating a custom template then we don't need to use the defaults class
1051
+		if (! $global) {
1052
+			return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1053
+		}
1054
+		/** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1055
+		$Message_Template_Defaults = EE_Registry::factory(
1056
+			'EE_Messages_Template_Defaults',
1057
+			array( $messenger, $message_type, $GRP_ID )
1058
+		);
1059
+		// generate templates
1060
+		$success = $Message_Template_Defaults->create_new_templates();
1061
+
1062
+		// if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1063
+		// its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1064
+		// attempts.
1065
+		if (! $success) {
1066
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
1067
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1068
+			$message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1069
+		}
1070
+
1071
+		/**
1072
+		 * $success is in an array in the following format
1073
+		 * array(
1074
+		 *    'GRP_ID' => $new_grp_id,
1075
+		 *    'MTP_context' => $first_context_in_new_templates,
1076
+		 * )
1077
+		 */
1078
+		return $success;
1079
+	}
1080
+
1081
+
1082
+	/**
1083
+	 * This creates a custom template using the incoming GRP_ID
1084
+	 *
1085
+	 * @param EE_messenger    $messenger
1086
+	 * @param EE_message_type $message_type
1087
+	 * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1088
+	 * @return  array $success              This will be an array in the format:
1089
+	 *                                          array(
1090
+	 *                                          'GRP_ID' => $new_grp_id,
1091
+	 *                                          'MTP_context' => $first_context_in_created_template
1092
+	 *                                          )
1093
+	 * @throws EE_Error
1094
+	 * @throws ReflectionException
1095
+	 * @access private
1096
+	 */
1097
+	private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1098
+	{
1099
+		// defaults
1100
+		$success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1101
+		// get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1102
+		$Message_Template_Group = empty($GRP_ID)
1103
+			? EEM_Message_Template_Group::instance()->get_one(
1104
+				array(
1105
+					array(
1106
+						'MTP_messenger'    => $messenger->name,
1107
+						'MTP_message_type' => $message_type->name,
1108
+						'MTP_is_global'    => true
1109
+					)
1110
+				)
1111
+			)
1112
+			: EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1113
+		// if we don't have a mtg at this point then we need to bail.
1114
+		if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1115
+			EE_Error::add_error(
1116
+				sprintf(
1117
+					esc_html__(
1118
+						'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1119
+						'event_espresso'
1120
+					),
1121
+					$GRP_ID
1122
+				),
1123
+				__FILE__,
1124
+				__FUNCTION__,
1125
+				__LINE__
1126
+			);
1127
+			return $success;
1128
+		}
1129
+		// let's get all the related message_template objects for this group.
1130
+		$message_templates = $Message_Template_Group->message_templates();
1131
+		// now we have what we need to setup the new template
1132
+		$new_mtg = clone $Message_Template_Group;
1133
+		$new_mtg->set('GRP_ID', 0);
1134
+		$new_mtg->set('MTP_is_global', false);
1135
+
1136
+		/** @var RequestInterface $request */
1137
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1138
+		$template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1139
+			? $request->getRequestParam('templateName')
1140
+			: esc_html__('New Custom Template', 'event_espresso');
1141
+		$template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1142
+			? $request->getRequestParam('templateDescription')
1143
+			: sprintf(
1144
+				esc_html__(
1145
+					'This is a custom template that was created for the %s messenger and %s message type.',
1146
+					'event_espresso'
1147
+				),
1148
+				$new_mtg->messenger_obj()->label['singular'],
1149
+				$new_mtg->message_type_obj()->label['singular']
1150
+			);
1151
+		$new_mtg->set('MTP_name', $template_name);
1152
+		$new_mtg->set('MTP_description', $template_description);
1153
+		// remove ALL relations on this template group so they don't get saved!
1154
+		$new_mtg->_remove_relations('Message_Template');
1155
+		$new_mtg->save();
1156
+		$success['GRP_ID'] = $new_mtg->ID();
1157
+		$success['template_name'] = $template_name;
1158
+		// add new message templates and add relation to.
1159
+		foreach ($message_templates as $message_template) {
1160
+			if (! $message_template instanceof EE_Message_Template) {
1161
+				continue;
1162
+			}
1163
+			$new_message_template = clone $message_template;
1164
+			$new_message_template->set('MTP_ID', 0);
1165
+			$new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1166
+			$new_message_template->save();
1167
+			if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') {
1168
+				$success['MTP_context'] = $new_message_template->get('MTP_context');
1169
+			}
1170
+		}
1171
+		return $success;
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * message_type_has_active_templates_for_messenger
1177
+	 *
1178
+	 * @param EE_messenger    $messenger
1179
+	 * @param EE_message_type $message_type
1180
+	 * @param bool            $global
1181
+	 * @return bool
1182
+	 * @throws EE_Error
1183
+	 */
1184
+	public static function message_type_has_active_templates_for_messenger(
1185
+		EE_messenger $messenger,
1186
+		EE_message_type $message_type,
1187
+		$global = false
1188
+	) {
1189
+		// is given message_type valid for given messenger (if this is not a global save)
1190
+		if ($global) {
1191
+			return true;
1192
+		}
1193
+		$active_templates = EEM_Message_Template_Group::instance()->count(
1194
+			array(
1195
+				array(
1196
+					'MTP_is_active'    => true,
1197
+					'MTP_messenger'    => $messenger->name,
1198
+					'MTP_message_type' => $message_type->name
1199
+				)
1200
+			)
1201
+		);
1202
+		if ($active_templates > 0) {
1203
+			return true;
1204
+		}
1205
+		EE_Error::add_error(
1206
+			sprintf(
1207
+				esc_html__(
1208
+					'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1209
+					'event_espresso'
1210
+				),
1211
+				$message_type->name,
1212
+				$messenger->name
1213
+			),
1214
+			__FILE__,
1215
+			__FUNCTION__,
1216
+			__LINE__
1217
+		);
1218
+		return false;
1219
+	}
1220
+
1221
+
1222
+	/**
1223
+	 * get_fields
1224
+	 * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1225
+	 *
1226
+	 * @param string $messenger_name    name of EE_messenger
1227
+	 * @param string $message_type_name name of EE_message_type
1228
+	 * @return array
1229
+	 * @throws EE_Error
1230
+	 * @throws ReflectionException
1231
+	 */
1232
+	public static function get_fields($messenger_name, $message_type_name)
1233
+	{
1234
+		$template_fields = array();
1235
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1236
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1237
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1238
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1239
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1240
+			return array();
1241
+		}
1242
+
1243
+		$excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1244
+
1245
+		// okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1246
+		foreach ($message_type->get_contexts() as $context => $details) {
1247
+			foreach ($messenger->get_template_fields() as $field => $value) {
1248
+				if (in_array($field, $excluded_fields_for_messenger, true)) {
1249
+					continue;
1250
+				}
1251
+				$template_fields[ $context ][ $field ] = $value;
1252
+			}
1253
+		}
1254
+		if (empty($template_fields)) {
1255
+			EE_Error::add_error(
1256
+				esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1257
+				__FILE__,
1258
+				__FUNCTION__,
1259
+				__LINE__
1260
+			);
1261
+			return array();
1262
+		}
1263
+		return $template_fields;
1264
+	}
1265 1265
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Autoloader.helper.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         if (self::$_autoloaders === null) {
54 54
             self::$_autoloaders = array();
55 55
             $this->_register_custom_autoloaders();
56
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
56
+            spl_autoload_register(array($this, 'espresso_autoloader'));
57 57
         }
58 58
     }
59 59
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     public static function instance()
67 67
     {
68 68
         // check if class object is instantiated
69
-        if (! self::$_instance instanceof EEH_Autoloader) {
69
+        if ( ! self::$_instance instanceof EEH_Autoloader) {
70 70
             self::$_instance = new self();
71 71
         }
72 72
         return self::$_instance;
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public static function espresso_autoloader($class_name)
87 87
     {
88
-        if (isset(self::$_autoloaders[ $class_name ])) {
89
-            require_once(self::$_autoloaders[ $class_name ]);
88
+        if (isset(self::$_autoloaders[$class_name])) {
89
+            require_once(self::$_autoloaders[$class_name]);
90 90
         }
91 91
     }
92 92
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public static function register_autoloader($class_paths, $read_check = true, $debug = false)
105 105
     {
106
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
106
+        $class_paths = is_array($class_paths) ? $class_paths : array($class_paths);
107 107
         foreach ($class_paths as $class => $path) {
108 108
             // skip all files that are not PHP
109 109
             if (substr($path, strlen($path) - 3) !== 'php') {
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
             if ($read_check && ! is_readable($path)) {
123 123
                 throw new EE_Error(sprintf(esc_html__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
124 124
             }
125
-            if (! isset(self::$_autoloaders[ $class ])) {
126
-                self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
127
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
128
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
125
+            if ( ! isset(self::$_autoloaders[$class])) {
126
+                self::$_autoloaders[$class] = str_replace(array('/', '\\'), '/', $path);
127
+                if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
128
+                    EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__);
129 129
                 }
130 130
             }
131 131
         }
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
     {
158 158
         EEH_Autoloader::$debug = '';
159 159
         \EEH_Autoloader::register_helpers_autoloaders();
160
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
160
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces');
161 161
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
162 162
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
163 163
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
164 164
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
165 165
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
166
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
166
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages');
167 167
         if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
168 168
             EEH_Debug_Tools::instance()->show_times();
169 169
         }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
     public static function register_line_item_display_autoloaders()
207 207
     {
208
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
208
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true);
209 209
     }
210 210
 
211 211
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      */
219 219
     public static function register_line_item_filter_autoloaders()
220 220
     {
221
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
221
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true);
222 222
     }
223 223
 
224 224
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      */
232 232
     public static function register_template_part_autoloaders()
233 233
     {
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
234
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true);
235 235
     }
236 236
 
237 237
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      */
242 242
     public static function register_business_classes()
243 243
     {
244
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
244
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business');
245 245
     }
246 246
 
247 247
 
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
             EEH_Debug_Tools::instance()->start_timer(basename($folder));
265 265
         }
266 266
         // make sure last char is a /
267
-        $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
267
+        $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : '';
268 268
         $class_to_filepath_map = array();
269
-        $exclude = array( 'index' );
269
+        $exclude = array('index');
270 270
         // get all the files in that folder that end in php
271
-        $filepaths = glob($folder . '*');
271
+        $filepaths = glob($folder.'*');
272 272
 
273 273
         if (empty($filepaths)) {
274 274
             return;
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
         foreach ($filepaths as $filepath) {
278 278
             if (substr($filepath, -4, 4) === '.php') {
279 279
                 $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
280
-                if (! in_array($class_name, $exclude)) {
281
-                    $class_to_filepath_map [ $class_name ] = $filepath;
280
+                if ( ! in_array($class_name, $exclude)) {
281
+                    $class_to_filepath_map [$class_name] = $filepath;
282 282
                 }
283 283
             } elseif ($recursive) {
284 284
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
      */
304 304
     public static function add_alias($class_name, $alias)
305 305
     {
306
-        if (isset(self::$_autoloaders[ $class_name ])) {
307
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
306
+        if (isset(self::$_autoloaders[$class_name])) {
307
+            self::$_autoloaders[$alias] = self::$_autoloaders[$class_name];
308 308
         }
309 309
     }
310 310
 }
Please login to merge, or discard this patch.
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -13,296 +13,296 @@
 block discarded – undo
13 13
  */
14 14
 class EEH_Autoloader extends EEH_Base
15 15
 {
16
-    /**
17
-     *    instance of the EE_System object
18
-     *
19
-     * @var    $_instance
20
-     * @access    private
21
-     */
22
-    private static $_instance = null;
23
-
24
-    /**
25
-    *   $_autoloaders
26
-    *   @var array $_autoloaders
27
-    *   @access     private
28
-    */
29
-    private static $_autoloaders;
30
-
31
-    /**
32
-     * set to "paths" to display autoloader class => path mappings
33
-     * set to "times" to display autoloader loading times
34
-     * set to "all" to display both
35
-     *
36
-     * @var string $debug
37
-     * @access    private
38
-     */
39
-    public static $debug = false;
40
-
41
-
42
-    /**
43
-     *    class constructor
44
-     *
45
-     * @access    private
46
-     * @return \EEH_Autoloader
47
-     * @throws Exception
48
-     */
49
-    private function __construct()
50
-    {
51
-        if (self::$_autoloaders === null) {
52
-            self::$_autoloaders = array();
53
-            $this->_register_custom_autoloaders();
54
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
55
-        }
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * @access public
62
-     * @return EEH_Autoloader
63
-     */
64
-    public static function instance()
65
-    {
66
-        // check if class object is instantiated
67
-        if (! self::$_instance instanceof EEH_Autoloader) {
68
-            self::$_instance = new self();
69
-        }
70
-        return self::$_instance;
71
-    }
72
-
73
-
74
-
75
-    /**
76
-     *    espresso_autoloader
77
-     *
78
-     * @access    public
79
-     * @param   $class_name
80
-     * @internal  param $className
81
-     * @internal  param string $class_name - simple class name ie: session
82
-     * @return  void
83
-     */
84
-    public static function espresso_autoloader($class_name)
85
-    {
86
-        if (isset(self::$_autoloaders[ $class_name ])) {
87
-            require_once(self::$_autoloaders[ $class_name ]);
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     *    register_autoloader
95
-     *
96
-     * @access    public
97
-     * @param array | string $class_paths - array of key => value pairings between class names and paths
98
-     * @param bool           $read_check  true if we need to check whether the file is readable or not.
99
-     * @param bool           $debug **deprecated**
100
-     * @throws \EE_Error
101
-     */
102
-    public static function register_autoloader($class_paths, $read_check = true, $debug = false)
103
-    {
104
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
105
-        foreach ($class_paths as $class => $path) {
106
-            // skip all files that are not PHP
107
-            if (substr($path, strlen($path) - 3) !== 'php') {
108
-                continue;
109
-            }
110
-            // don't give up! you gotta...
111
-            // get some class
112
-            if (empty($class)) {
113
-                throw new EE_Error(sprintf(esc_html__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
114
-            }
115
-            // one day you will find the path young grasshopper
116
-            if (empty($path)) {
117
-                throw new EE_Error(sprintf(esc_html__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
118
-            }
119
-            // is file readable ?
120
-            if ($read_check && ! is_readable($path)) {
121
-                throw new EE_Error(sprintf(esc_html__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
122
-            }
123
-            if (! isset(self::$_autoloaders[ $class ])) {
124
-                self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
125
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
126
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
127
-                }
128
-            }
129
-        }
130
-    }
131
-
132
-
133
-
134
-
135
-    /**
136
-     *  get_autoloaders
137
-     *
138
-     *  @access public
139
-     *  @return array
140
-     */
141
-    public static function get_autoloaders()
142
-    {
143
-        return self::$_autoloaders;
144
-    }
145
-
146
-
147
-    /**
148
-     *  register core, model and class 'autoloaders'
149
-     *
150
-     * @access private
151
-     * @return void
152
-     * @throws EE_Error
153
-     */
154
-    private function _register_custom_autoloaders()
155
-    {
156
-        EEH_Autoloader::$debug = '';
157
-        \EEH_Autoloader::register_helpers_autoloaders();
158
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
159
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
160
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
161
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
162
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
163
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
164
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
165
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
166
-            EEH_Debug_Tools::instance()->show_times();
167
-        }
168
-    }
169
-
170
-
171
-
172
-    /**
173
-     *    register core, model and class 'autoloaders'
174
-     *
175
-     * @access public
176
-     */
177
-    public static function register_helpers_autoloaders()
178
-    {
179
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
180
-    }
181
-
182
-
183
-
184
-
185
-    /**
186
-     *  register core, model and class 'autoloaders'
187
-     *
188
-     *  @access public
189
-     *  @return void
190
-     */
191
-    public static function register_form_sections_autoloaders()
192
-    {
193
-        // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
194
-    }
195
-
196
-
197
-    /**
198
-     *  register core, model and class 'autoloaders'
199
-     *
200
-     * @access public
201
-     * @return void
202
-     * @throws EE_Error
203
-     */
204
-    public static function register_line_item_display_autoloaders()
205
-    {
206
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
207
-    }
208
-
209
-
210
-    /**
211
-     *  register core, model and class 'autoloaders'
212
-     *
213
-     * @access public
214
-     * @return void
215
-     * @throws EE_Error
216
-     */
217
-    public static function register_line_item_filter_autoloaders()
218
-    {
219
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
220
-    }
221
-
222
-
223
-    /**
224
-     *  register template part 'autoloaders'
225
-     *
226
-     * @access public
227
-     * @return void
228
-     * @throws EE_Error
229
-     */
230
-    public static function register_template_part_autoloaders()
231
-    {
232
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
233
-    }
234
-
235
-
236
-    /**
237
-     * @return void
238
-     * @throws EE_Error
239
-     */
240
-    public static function register_business_classes()
241
-    {
242
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * Assumes all the files in this folder have the normal naming scheme (namely that their classname
249
-     * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
250
-     * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
251
-     * Yes this has to scan the directory for files, but it only does it once -- not on EACH
252
-     * time the autoloader is used
253
-     *
254
-     * @param string $folder name, with or without trailing /, doesn't matter
255
-     * @param bool   $recursive
256
-     * @param bool   $debug  **deprecated**
257
-     * @throws \EE_Error
258
-     */
259
-    public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
260
-    {
261
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
262
-            EEH_Debug_Tools::instance()->start_timer(basename($folder));
263
-        }
264
-        // make sure last char is a /
265
-        $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
266
-        $class_to_filepath_map = array();
267
-        $exclude = array( 'index' );
268
-        // get all the files in that folder that end in php
269
-        $filepaths = glob($folder . '*');
270
-
271
-        if (empty($filepaths)) {
272
-            return;
273
-        }
274
-
275
-        foreach ($filepaths as $filepath) {
276
-            if (substr($filepath, -4, 4) === '.php') {
277
-                $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
278
-                if (! in_array($class_name, $exclude)) {
279
-                    $class_to_filepath_map [ $class_name ] = $filepath;
280
-                }
281
-            } elseif ($recursive) {
282
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
283
-            }
284
-        }
285
-        // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
286
-        self::register_autoloader($class_to_filepath_map, false, $debug);
287
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
288
-            EEH_Debug_Tools::instance()->stop_timer(basename($folder));
289
-        }
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * add_alias
296
-     * register additional autoloader based on variation of the classname for an existing autoloader
297
-     *
298
-     * @access    public
299
-     * @param string $class_name - simple class name ie: EE_Session
300
-     * @param string $alias - variation on class name ie: EE_session, session, etc
301
-     */
302
-    public static function add_alias($class_name, $alias)
303
-    {
304
-        if (isset(self::$_autoloaders[ $class_name ])) {
305
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
306
-        }
307
-    }
16
+	/**
17
+	 *    instance of the EE_System object
18
+	 *
19
+	 * @var    $_instance
20
+	 * @access    private
21
+	 */
22
+	private static $_instance = null;
23
+
24
+	/**
25
+	 *   $_autoloaders
26
+	 *   @var array $_autoloaders
27
+	 *   @access     private
28
+	 */
29
+	private static $_autoloaders;
30
+
31
+	/**
32
+	 * set to "paths" to display autoloader class => path mappings
33
+	 * set to "times" to display autoloader loading times
34
+	 * set to "all" to display both
35
+	 *
36
+	 * @var string $debug
37
+	 * @access    private
38
+	 */
39
+	public static $debug = false;
40
+
41
+
42
+	/**
43
+	 *    class constructor
44
+	 *
45
+	 * @access    private
46
+	 * @return \EEH_Autoloader
47
+	 * @throws Exception
48
+	 */
49
+	private function __construct()
50
+	{
51
+		if (self::$_autoloaders === null) {
52
+			self::$_autoloaders = array();
53
+			$this->_register_custom_autoloaders();
54
+			spl_autoload_register(array( $this, 'espresso_autoloader' ));
55
+		}
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * @access public
62
+	 * @return EEH_Autoloader
63
+	 */
64
+	public static function instance()
65
+	{
66
+		// check if class object is instantiated
67
+		if (! self::$_instance instanceof EEH_Autoloader) {
68
+			self::$_instance = new self();
69
+		}
70
+		return self::$_instance;
71
+	}
72
+
73
+
74
+
75
+	/**
76
+	 *    espresso_autoloader
77
+	 *
78
+	 * @access    public
79
+	 * @param   $class_name
80
+	 * @internal  param $className
81
+	 * @internal  param string $class_name - simple class name ie: session
82
+	 * @return  void
83
+	 */
84
+	public static function espresso_autoloader($class_name)
85
+	{
86
+		if (isset(self::$_autoloaders[ $class_name ])) {
87
+			require_once(self::$_autoloaders[ $class_name ]);
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 *    register_autoloader
95
+	 *
96
+	 * @access    public
97
+	 * @param array | string $class_paths - array of key => value pairings between class names and paths
98
+	 * @param bool           $read_check  true if we need to check whether the file is readable or not.
99
+	 * @param bool           $debug **deprecated**
100
+	 * @throws \EE_Error
101
+	 */
102
+	public static function register_autoloader($class_paths, $read_check = true, $debug = false)
103
+	{
104
+		$class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
105
+		foreach ($class_paths as $class => $path) {
106
+			// skip all files that are not PHP
107
+			if (substr($path, strlen($path) - 3) !== 'php') {
108
+				continue;
109
+			}
110
+			// don't give up! you gotta...
111
+			// get some class
112
+			if (empty($class)) {
113
+				throw new EE_Error(sprintf(esc_html__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
114
+			}
115
+			// one day you will find the path young grasshopper
116
+			if (empty($path)) {
117
+				throw new EE_Error(sprintf(esc_html__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
118
+			}
119
+			// is file readable ?
120
+			if ($read_check && ! is_readable($path)) {
121
+				throw new EE_Error(sprintf(esc_html__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
122
+			}
123
+			if (! isset(self::$_autoloaders[ $class ])) {
124
+				self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
125
+				if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
126
+					EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
127
+				}
128
+			}
129
+		}
130
+	}
131
+
132
+
133
+
134
+
135
+	/**
136
+	 *  get_autoloaders
137
+	 *
138
+	 *  @access public
139
+	 *  @return array
140
+	 */
141
+	public static function get_autoloaders()
142
+	{
143
+		return self::$_autoloaders;
144
+	}
145
+
146
+
147
+	/**
148
+	 *  register core, model and class 'autoloaders'
149
+	 *
150
+	 * @access private
151
+	 * @return void
152
+	 * @throws EE_Error
153
+	 */
154
+	private function _register_custom_autoloaders()
155
+	{
156
+		EEH_Autoloader::$debug = '';
157
+		\EEH_Autoloader::register_helpers_autoloaders();
158
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
159
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
160
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
161
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
162
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
163
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
164
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
165
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
166
+			EEH_Debug_Tools::instance()->show_times();
167
+		}
168
+	}
169
+
170
+
171
+
172
+	/**
173
+	 *    register core, model and class 'autoloaders'
174
+	 *
175
+	 * @access public
176
+	 */
177
+	public static function register_helpers_autoloaders()
178
+	{
179
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
180
+	}
181
+
182
+
183
+
184
+
185
+	/**
186
+	 *  register core, model and class 'autoloaders'
187
+	 *
188
+	 *  @access public
189
+	 *  @return void
190
+	 */
191
+	public static function register_form_sections_autoloaders()
192
+	{
193
+		// EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
194
+	}
195
+
196
+
197
+	/**
198
+	 *  register core, model and class 'autoloaders'
199
+	 *
200
+	 * @access public
201
+	 * @return void
202
+	 * @throws EE_Error
203
+	 */
204
+	public static function register_line_item_display_autoloaders()
205
+	{
206
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
207
+	}
208
+
209
+
210
+	/**
211
+	 *  register core, model and class 'autoloaders'
212
+	 *
213
+	 * @access public
214
+	 * @return void
215
+	 * @throws EE_Error
216
+	 */
217
+	public static function register_line_item_filter_autoloaders()
218
+	{
219
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
220
+	}
221
+
222
+
223
+	/**
224
+	 *  register template part 'autoloaders'
225
+	 *
226
+	 * @access public
227
+	 * @return void
228
+	 * @throws EE_Error
229
+	 */
230
+	public static function register_template_part_autoloaders()
231
+	{
232
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
233
+	}
234
+
235
+
236
+	/**
237
+	 * @return void
238
+	 * @throws EE_Error
239
+	 */
240
+	public static function register_business_classes()
241
+	{
242
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * Assumes all the files in this folder have the normal naming scheme (namely that their classname
249
+	 * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
250
+	 * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
251
+	 * Yes this has to scan the directory for files, but it only does it once -- not on EACH
252
+	 * time the autoloader is used
253
+	 *
254
+	 * @param string $folder name, with or without trailing /, doesn't matter
255
+	 * @param bool   $recursive
256
+	 * @param bool   $debug  **deprecated**
257
+	 * @throws \EE_Error
258
+	 */
259
+	public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
260
+	{
261
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
262
+			EEH_Debug_Tools::instance()->start_timer(basename($folder));
263
+		}
264
+		// make sure last char is a /
265
+		$folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
266
+		$class_to_filepath_map = array();
267
+		$exclude = array( 'index' );
268
+		// get all the files in that folder that end in php
269
+		$filepaths = glob($folder . '*');
270
+
271
+		if (empty($filepaths)) {
272
+			return;
273
+		}
274
+
275
+		foreach ($filepaths as $filepath) {
276
+			if (substr($filepath, -4, 4) === '.php') {
277
+				$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
278
+				if (! in_array($class_name, $exclude)) {
279
+					$class_to_filepath_map [ $class_name ] = $filepath;
280
+				}
281
+			} elseif ($recursive) {
282
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
283
+			}
284
+		}
285
+		// we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
286
+		self::register_autoloader($class_to_filepath_map, false, $debug);
287
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
288
+			EEH_Debug_Tools::instance()->stop_timer(basename($folder));
289
+		}
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * add_alias
296
+	 * register additional autoloader based on variation of the classname for an existing autoloader
297
+	 *
298
+	 * @access    public
299
+	 * @param string $class_name - simple class name ie: EE_Session
300
+	 * @param string $alias - variation on class name ie: EE_session, session, etc
301
+	 */
302
+	public static function add_alias($class_name, $alias)
303
+	{
304
+		if (isset(self::$_autoloaders[ $class_name ])) {
305
+			self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
306
+		}
307
+	}
308 308
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 2 patches
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      */
59 59
     public static function getTableAnalysis()
60 60
     {
61
-        if (! self::$table_analysis instanceof TableAnalysis) {
61
+        if ( ! self::$table_analysis instanceof TableAnalysis) {
62 62
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true);
63 63
         }
64 64
         return self::$table_analysis;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public static function getTableManager()
74 74
     {
75
-        if (! self::$table_manager instanceof TableManager) {
75
+        if ( ! self::$table_manager instanceof TableManager) {
76 76
             self::$table_manager = EE_Registry::instance()->create('TableManager', [], true);
77 77
         }
78 78
         return self::$table_manager;
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
         if ($which_to_include === 'old') {
187 187
             $cron_tasks = array_filter(
188 188
                 $cron_tasks,
189
-                function ($value) {
189
+                function($value) {
190 190
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
191 191
                 }
192 192
             );
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     {
217 217
 
218 218
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
219
-            if (! wp_next_scheduled($hook_name)) {
219
+            if ( ! wp_next_scheduled($hook_name)) {
220 220
                 /**
221 221
                  * This allows client code to define the initial start timestamp for this schedule.
222 222
                  */
@@ -269,15 +269,15 @@  discard block
 block discarded – undo
269 269
             if (is_array($hooks_to_fire_at_time)) {
270 270
                 foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
271 271
                     if (
272
-                        isset($ee_cron_tasks_to_remove[ $hook_name ])
273
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
272
+                        isset($ee_cron_tasks_to_remove[$hook_name])
273
+                        && is_array($ee_cron_tasks_to_remove[$hook_name])
274 274
                     ) {
275
-                        unset($crons[ $timestamp ][ $hook_name ]);
275
+                        unset($crons[$timestamp][$hook_name]);
276 276
                     }
277 277
                 }
278 278
                 // also take care of any empty cron timestamps.
279 279
                 if (empty($hooks_to_fire_at_time)) {
280
-                    unset($crons[ $timestamp ]);
280
+                    unset($crons[$timestamp]);
281 281
                 }
282 282
             }
283 283
         }
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
             10,
317 317
             3
318 318
         );
319
-        if (! EE_Config::logging_enabled()) {
319
+        if ( ! EE_Config::logging_enabled()) {
320 320
             delete_option(EE_Config::LOG_NAME);
321 321
         }
322 322
     }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
     public static function load_calendar_config()
329 329
     {
330 330
         // grab array of all plugin folders and loop thru it
331
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
331
+        $plugins = glob(WP_PLUGIN_DIR.'/*', GLOB_ONLYDIR);
332 332
         if (empty($plugins)) {
333 333
             return;
334 334
         }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
                 || strpos($plugin, 'calendar') !== false
346 346
             ) {
347 347
                 // this is what we are looking for
348
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
348
+                $calendar_config = $plugin_path.'/EE_Calendar_Config.php';
349 349
                 // does it exist in this folder ?
350 350
                 if (is_readable($calendar_config)) {
351 351
                     // YEAH! let's load it
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
                 'code' => 'ESPRESSO_CANCELLED',
429 429
             ],
430 430
         ];
431
-        $EE_Core_Config        = EE_Registry::instance()->CFG->core;
431
+        $EE_Core_Config = EE_Registry::instance()->CFG->core;
432 432
         foreach ($critical_pages as $critical_page) {
433 433
             // is critical page ID set in config ?
434 434
             if ($EE_Core_Config->{$critical_page['id']} !== false) {
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
             ) {
461 461
                 // update Config with post ID
462 462
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
463
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
463
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
464 464
                     $msg = esc_html__(
465 465
                         'The Event Espresso critical page configuration settings could not be updated.',
466 466
                         'event_espresso'
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
                         'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
484 484
                         'event_espresso'
485 485
                     ),
486
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
486
+                    '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'
487 487
                     . esc_html__('Event Espresso Critical Pages Settings', 'event_espresso')
488 488
                     . '</a>'
489 489
                 )
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
     public static function get_page_by_ee_shortcode($ee_shortcode)
509 509
     {
510 510
         global $wpdb;
511
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
511
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
512 512
         $post_id                       =
513 513
             $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
514 514
         if ($post_id) {
@@ -533,11 +533,11 @@  discard block
 block discarded – undo
533 533
             'post_status'    => 'publish',
534 534
             'post_type'      => 'page',
535 535
             'comment_status' => 'closed',
536
-            'post_content'   => '[' . $critical_page['code'] . ']',
536
+            'post_content'   => '['.$critical_page['code'].']',
537 537
         ];
538 538
 
539 539
         $post_id = wp_insert_post($post_args);
540
-        if (! $post_id) {
540
+        if ( ! $post_id) {
541 541
             $msg = sprintf(
542 542
                 esc_html__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
543 543
                 $critical_page['name']
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
             return $critical_page;
547 547
         }
548 548
         // get newly created post's details
549
-        if (! $critical_page['post'] = get_post($post_id)) {
549
+        if ( ! $critical_page['post'] = get_post($post_id)) {
550 550
             $msg = sprintf(
551 551
                 esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
552 552
                 $critical_page['name']
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
     public static function get_default_creator_id()
572 572
     {
573 573
         global $wpdb;
574
-        if (! empty(self::$_default_creator_id)) {
574
+        if ( ! empty(self::$_default_creator_id)) {
575 575
             return self::$_default_creator_id;
576 576
         }/**/
577 577
         $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
         $capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
588 588
         $query            = $wpdb->prepare(
589 589
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
590
-            '%' . $role_to_check . '%'
590
+            '%'.$role_to_check.'%'
591 591
         );
592 592
         $user_id          = $wpdb->get_var($query);
593 593
         $user_id          = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
@@ -624,8 +624,8 @@  discard block
 block discarded – undo
624 624
             return;
625 625
         }
626 626
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
627
-        if (! function_exists('dbDelta')) {
628
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
627
+        if ( ! function_exists('dbDelta')) {
628
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
629 629
         }
630 630
         $tableAnalysis = EEH_Activation::getTableAnalysis();
631 631
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
             // ok, delete the table... but ONLY if it's empty
635 635
             $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
636 636
             // table is NOT empty, are you SURE you want to delete this table ???
637
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
637
+            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
638 638
                 EEH_Activation::getTableManager()->dropTable($wp_table_name);
639
-            } elseif (! $deleted_safely) {
639
+            } elseif ( ! $deleted_safely) {
640 640
                 // so we should be more cautious rather than just dropping tables so easily
641 641
                 error_log(
642 642
                     sprintf(
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
         EE_Registry::instance()->load_core('Data_Migration_Manager');
758 758
         // find the migration script that sets the database to be compatible with the code
759 759
         $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
760
-        if (! $dms_name) {
760
+        if ( ! $dms_name) {
761 761
             EE_Error::add_error(
762 762
                 esc_html__(
763 763
                     'Could not determine most up-to-date data migration script from which to pull database schema
@@ -817,13 +817,13 @@  discard block
 block discarded – undo
817 817
             // reset values array
818 818
             $QSG_values = [];
819 819
             // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
820
-            if (! in_array("$QSG_system", $question_groups)) {
820
+            if ( ! in_array("$QSG_system", $question_groups)) {
821 821
                 // add it
822 822
                 switch ($QSG_system) {
823 823
                     case 1:
824 824
                         $QSG_values = [
825 825
                             'QSG_name'            => esc_html__('Personal Information', 'event_espresso'),
826
-                            'QSG_identifier'      => 'personal-information-' . time(),
826
+                            'QSG_identifier'      => 'personal-information-'.time(),
827 827
                             'QSG_desc'            => '',
828 828
                             'QSG_order'           => 1,
829 829
                             'QSG_show_group_name' => 1,
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
                     case 2:
836 836
                         $QSG_values = [
837 837
                             'QSG_name'            => esc_html__('Address Information', 'event_espresso'),
838
-                            'QSG_identifier'      => 'address-information-' . time(),
838
+                            'QSG_identifier'      => 'address-information-'.time(),
839 839
                             'QSG_desc'            => '',
840 840
                             'QSG_order'           => 2,
841 841
                             'QSG_show_group_name' => 1,
@@ -846,14 +846,14 @@  discard block
 block discarded – undo
846 846
                         break;
847 847
                 }
848 848
                 // make sure we have some values before inserting them
849
-                if (! empty($QSG_values)) {
849
+                if ( ! empty($QSG_values)) {
850 850
                     // insert system question
851 851
                     $wpdb->insert(
852 852
                         $table_name,
853 853
                         $QSG_values,
854 854
                         ['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d']
855 855
                     );
856
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
856
+                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
857 857
                 }
858 858
             }
859 859
         }
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
         $address_system_group_questions  = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
869 869
         $system_questions_not_in_group   = ['email_confirm'];
870 870
         // merge all of the system questions we should have
871
-        $QST_systems       = array_merge(
871
+        $QST_systems = array_merge(
872 872
             $personal_system_group_questions,
873 873
             $address_system_group_questions,
874 874
             $system_questions_not_in_group
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
             // reset values array
881 881
             $QST_values = [];
882 882
             // if we don't have what we should have
883
-            if (! in_array($QST_system, $questions)) {
883
+            if ( ! in_array($QST_system, $questions)) {
884 884
                 // add it
885 885
                 switch ($QST_system) {
886 886
                     case 'fname':
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
                         ];
1057 1057
                         break;
1058 1058
                 }
1059
-                if (! empty($QST_values)) {
1059
+                if ( ! empty($QST_values)) {
1060 1060
                     // insert system question
1061 1061
                     $wpdb->insert(
1062 1062
                         $table_name,
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
                         // QST_system should not be assigned to any group
1075 1075
                         continue;
1076 1076
                     }
1077
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1078
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1077
+                    if (isset($QSG_IDs[$system_question_we_want])) {
1078
+                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1079 1079
                     } else {
1080 1080
                         $id_col = EEM_Question_Group::instance()
1081 1081
                                                     ->get_col([['QSG_system' => $system_question_we_want]]);
@@ -1124,7 +1124,7 @@  discard block
 block discarded – undo
1124 1124
      */
1125 1125
     public static function insert_default_payment_methods()
1126 1126
     {
1127
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1127
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1128 1128
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1129 1129
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1130 1130
         } else {
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
                         $active_messenger->name,
1261 1261
                         $default_message_type_name_for_messenger
1262 1262
                     )
1263
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1263
+                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1264 1264
                 ) {
1265 1265
                     continue;
1266 1266
                 }
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
                 false
1274 1274
             );
1275 1275
             // activate the templates for these message types
1276
-            if (! empty($default_message_type_names_to_activate)) {
1276
+            if ( ! empty($default_message_type_names_to_activate)) {
1277 1277
                 $templates_created = EEH_MSG_Template::generate_new_templates(
1278 1278
                     $active_messenger->name,
1279 1279
                     $default_message_type_names_for_messenger,
@@ -1307,13 +1307,13 @@  discard block
 block discarded – undo
1307 1307
             // verify the default message types match an installed message type.
1308 1308
             foreach ($default_message_type_names_for_messenger as $key => $name) {
1309 1309
                 if (
1310
-                    ! isset($installed_message_types[ $name ])
1310
+                    ! isset($installed_message_types[$name])
1311 1311
                     || $message_resource_manager->has_message_type_been_activated_for_messenger(
1312 1312
                         $name,
1313 1313
                         $messenger_to_generate->name
1314 1314
                     )
1315 1315
                 ) {
1316
-                    unset($default_message_type_names_for_messenger[ $key ]);
1316
+                    unset($default_message_type_names_for_messenger[$key]);
1317 1317
                 }
1318 1318
             }
1319 1319
             // in previous iterations, the active_messengers option in the db
@@ -1327,7 +1327,7 @@  discard block
 block discarded – undo
1327 1327
                 false
1328 1328
             );
1329 1329
             // create any templates needing created (or will reactivate templates already generated as necessary).
1330
-            if (! empty($default_message_type_names_for_messenger)) {
1330
+            if ( ! empty($default_message_type_names_for_messenger)) {
1331 1331
                 $templates_generated = EEH_MSG_Template::generate_new_templates(
1332 1332
                     $messenger_to_generate->name,
1333 1333
                     $default_message_type_names_for_messenger,
@@ -1363,12 +1363,12 @@  discard block
 block discarded – undo
1363 1363
             // and has never been activated
1364 1364
             if (
1365 1365
                 ! $installed_messenger->activate_on_install
1366
-                || isset($active_messengers[ $installed_messenger->name ])
1367
-                || isset($has_activated[ $installed_messenger->name ])
1366
+                || isset($active_messengers[$installed_messenger->name])
1367
+                || isset($has_activated[$installed_messenger->name])
1368 1368
             ) {
1369 1369
                 continue;
1370 1370
             }
1371
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1371
+            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1372 1372
         }
1373 1373
         return $messengers_to_generate;
1374 1374
     }
@@ -1404,7 +1404,7 @@  discard block
 block discarded – undo
1404 1404
         // this creates an array for tracking events that have no active ticket prices created
1405 1405
         // this allows us to warn admins of the situation so that it can be corrected
1406 1406
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1407
-        if (! $espresso_no_ticket_prices) {
1407
+        if ( ! $espresso_no_ticket_prices) {
1408 1408
             add_option('ee_no_ticket_prices', [], '', false);
1409 1409
         }
1410 1410
     }
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
             }
1440 1440
         }
1441 1441
         // get all our CPTs
1442
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1442
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1443 1443
         $cpt_ids = $wpdb->get_col($query);
1444 1444
         // delete each post meta and term relations too
1445 1445
         foreach ($cpt_ids as $post_id) {
@@ -1471,7 +1471,7 @@  discard block
 block discarded – undo
1471 1471
                                 || ! $table->is_global()// not main site,but not global either. nuke it
1472 1472
                             )
1473 1473
                         ) {
1474
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1474
+                            $tables[$table->get_table_name()] = $table->get_table_name();
1475 1475
                         }
1476 1476
                     }
1477 1477
                 }
@@ -1488,7 +1488,7 @@  discard block
 block discarded – undo
1488 1488
             'esp_rule',
1489 1489
         ];
1490 1490
         foreach ($tables_without_models as $table) {
1491
-            $tables[ $table ] = $table;
1491
+            $tables[$table] = $table;
1492 1492
         }
1493 1493
         return EEH_Activation::getTableManager()->dropTables($tables);
1494 1494
     }
@@ -1565,14 +1565,14 @@  discard block
 block discarded – undo
1565 1565
         $undeleted_options = [];
1566 1566
         foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1567 1567
             if ($no_wildcard) {
1568
-                if (! delete_option($option_name)) {
1568
+                if ( ! delete_option($option_name)) {
1569 1569
                     $undeleted_options[] = $option_name;
1570 1570
                 }
1571 1571
             } else {
1572 1572
                 $option_names_to_delete_from_wildcard =
1573 1573
                     $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1574 1574
                 foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1575
-                    if (! delete_option($option_name_from_wildcard)) {
1575
+                    if ( ! delete_option($option_name_from_wildcard)) {
1576 1576
                         $undeleted_options[] = $option_name_from_wildcard;
1577 1577
                     }
1578 1578
                 }
@@ -1584,20 +1584,20 @@  discard block
 block discarded – undo
1584 1584
             $db_update_sans_ee4 = [];
1585 1585
             foreach ($espresso_db_update as $version => $times_activated) {
1586 1586
                 if ((string) $version[0] === '3') {// if its NON EE4
1587
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1587
+                    $db_update_sans_ee4[$version] = $times_activated;
1588 1588
                 }
1589 1589
             }
1590 1590
             update_option('espresso_db_update', $db_update_sans_ee4);
1591 1591
         }
1592 1592
         $errors = '';
1593
-        if (! empty($undeleted_options)) {
1593
+        if ( ! empty($undeleted_options)) {
1594 1594
             $errors .= sprintf(
1595 1595
                 esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1596 1596
                 '<br/>',
1597 1597
                 implode(',<br/>', $undeleted_options)
1598 1598
             );
1599 1599
         }
1600
-        if (! empty($errors)) {
1600
+        if ( ! empty($errors)) {
1601 1601
             EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1602 1602
         }
1603 1603
     }
Please login to merge, or discard this patch.
Indentation   +1588 added lines, -1588 removed lines patch added patch discarded remove patch
@@ -16,237 +16,237 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class EEH_Activation implements ResettableInterface
18 18
 {
19
-    /**
20
-     * constant used to indicate a cron task is no longer in use
21
-     */
22
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
23
-
24
-    /**
25
-     * WP_User->ID
26
-     *
27
-     * @var int
28
-     */
29
-    private static $_default_creator_id;
30
-
31
-    /**
32
-     * indicates whether or not we've already verified core's default data during this request,
33
-     * because after migrations are done, any addons activated while in maintenance mode
34
-     * will want to setup their own default data, and they might hook into core's default data
35
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
36
-     * This prevents doing that for EVERY single addon.
37
-     *
38
-     * @var boolean
39
-     */
40
-    protected static $_initialized_db_content_already_in_this_request = false;
41
-
42
-    /**
43
-     * @var TableAnalysis $table_analysis
44
-     */
45
-    private static $table_analysis;
46
-
47
-    /**
48
-     * @var TableManager $table_manager
49
-     */
50
-    private static $table_manager;
51
-
52
-
53
-    /**
54
-     * @return TableAnalysis
55
-     * @throws EE_Error
56
-     * @throws ReflectionException
57
-     */
58
-    public static function getTableAnalysis()
59
-    {
60
-        if (! self::$table_analysis instanceof TableAnalysis) {
61
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true);
62
-        }
63
-        return self::$table_analysis;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return TableManager
69
-     * @throws EE_Error
70
-     * @throws ReflectionException
71
-     */
72
-    public static function getTableManager()
73
-    {
74
-        if (! self::$table_manager instanceof TableManager) {
75
-            self::$table_manager = EE_Registry::instance()->create('TableManager', [], true);
76
-        }
77
-        return self::$table_manager;
78
-    }
79
-
80
-
81
-    /**
82
-     * @param $table_name
83
-     * @return string
84
-     * @throws EE_Error
85
-     * @throws ReflectionException
86
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
-     */
88
-    public static function ensure_table_name_has_prefix($table_name)
89
-    {
90
-        return EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
91
-    }
92
-
93
-
94
-    /**
95
-     * ensures the EE configuration settings are loaded with at least default options set
96
-     * and that all critical EE pages have been generated with the appropriate shortcodes in place
97
-     *
98
-     * @return void
99
-     */
100
-    public static function system_initialization()
101
-    {
102
-        EEH_Activation::reset_and_update_config();
103
-        // which is fired BEFORE activation of plugin anyways
104
-        EEH_Activation::verify_default_pages_exist();
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets the database schema and creates folders. This should
110
-     * be called on plugin activation and reactivation
111
-     *
112
-     * @return boolean success, whether the database and folders are setup properly
113
-     * @throws EE_Error
114
-     * @throws ReflectionException
115
-     */
116
-    public static function initialize_db_and_folders()
117
-    {
118
-        return EEH_Activation::create_database_tables();
119
-    }
120
-
121
-
122
-    /**
123
-     * assuming we have an up-to-date database schema, this will populate it
124
-     * with default and initial data. This should be called
125
-     * upon activation of a new plugin, reactivation, and at the end
126
-     * of running migration scripts
127
-     *
128
-     * @throws EE_Error
129
-     * @throws ReflectionException
130
-     */
131
-    public static function initialize_db_content()
132
-    {
133
-        // let's avoid doing all this logic repeatedly, especially when addons are requesting it
134
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
135
-            return;
136
-        }
137
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
138
-
139
-        EEH_Activation::initialize_system_questions();
140
-        EEH_Activation::insert_default_status_codes();
141
-        EEH_Activation::generate_default_message_templates();
142
-        EEH_Activation::create_no_ticket_prices_array();
143
-        EEH_Activation::removeEmailConfirmFromAddressGroup();
144
-
145
-        EEH_Activation::validate_messages_system();
146
-        EEH_Activation::insert_default_payment_methods();
147
-        // in case we've
148
-        EEH_Activation::remove_cron_tasks();
149
-        EEH_Activation::create_cron_tasks();
150
-        // remove all TXN locks since that is being done via extra meta now
151
-        delete_option('ee_locked_transactions');
152
-        // also, check for CAF default db content
153
-        do_action('AHEE__EEH_Activation__initialize_db_content');
154
-        // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
155
-        // which users really won't care about on initial activation
156
-        EE_Error::overwrite_success();
157
-    }
158
-
159
-
160
-    /**
161
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
162
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
163
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
164
-     * (null)
165
-     *
166
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
167
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
168
-     * @return array
169
-     * @throws EE_Error
170
-     */
171
-    public static function get_cron_tasks($which_to_include)
172
-    {
173
-        $cron_tasks = apply_filters(
174
-            'FHEE__EEH_Activation__get_cron_tasks',
175
-            [
176
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
177
-                // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' =>
178
-                // EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
179
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
180
-                // there may have been a bug which prevented from these cron tasks from getting unscheduled,
181
-                // so we might want to remove these for a few updates
182
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
183
-            ]
184
-        );
185
-        if ($which_to_include === 'old') {
186
-            $cron_tasks = array_filter(
187
-                $cron_tasks,
188
-                function ($value) {
189
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
190
-                }
191
-            );
192
-        } elseif ($which_to_include === 'current') {
193
-            $cron_tasks = array_filter($cron_tasks);
194
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
195
-            throw new EE_Error(
196
-                sprintf(
197
-                    esc_html__(
198
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
199
-                        'event_espresso'
200
-                    ),
201
-                    $which_to_include
202
-                )
203
-            );
204
-        }
205
-        return $cron_tasks;
206
-    }
207
-
208
-
209
-    /**
210
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
211
-     *
212
-     * @throws EE_Error
213
-     */
214
-    public static function create_cron_tasks()
215
-    {
216
-
217
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
218
-            if (! wp_next_scheduled($hook_name)) {
219
-                /**
220
-                 * This allows client code to define the initial start timestamp for this schedule.
221
-                 */
222
-                if (
223
-                    is_array($frequency)
224
-                    && count($frequency) === 2
225
-                    && isset($frequency[0], $frequency[1])
226
-                ) {
227
-                    $start_timestamp = $frequency[0];
228
-                    $frequency       = $frequency[1];
229
-                } else {
230
-                    $start_timestamp = time();
231
-                }
232
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
233
-            }
234
-        }
235
-    }
236
-
237
-
238
-    /**
239
-     * Remove the currently-existing and now-removed cron tasks.
240
-     *
241
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
242
-     * @throws EE_Error
243
-     */
244
-    public static function remove_cron_tasks($remove_all = true)
245
-    {
246
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
247
-        $crons                = _get_cron_array();
248
-        $crons                = is_array($crons) ? $crons : [];
249
-        /* reminder of what $crons look like:
19
+	/**
20
+	 * constant used to indicate a cron task is no longer in use
21
+	 */
22
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
23
+
24
+	/**
25
+	 * WP_User->ID
26
+	 *
27
+	 * @var int
28
+	 */
29
+	private static $_default_creator_id;
30
+
31
+	/**
32
+	 * indicates whether or not we've already verified core's default data during this request,
33
+	 * because after migrations are done, any addons activated while in maintenance mode
34
+	 * will want to setup their own default data, and they might hook into core's default data
35
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
36
+	 * This prevents doing that for EVERY single addon.
37
+	 *
38
+	 * @var boolean
39
+	 */
40
+	protected static $_initialized_db_content_already_in_this_request = false;
41
+
42
+	/**
43
+	 * @var TableAnalysis $table_analysis
44
+	 */
45
+	private static $table_analysis;
46
+
47
+	/**
48
+	 * @var TableManager $table_manager
49
+	 */
50
+	private static $table_manager;
51
+
52
+
53
+	/**
54
+	 * @return TableAnalysis
55
+	 * @throws EE_Error
56
+	 * @throws ReflectionException
57
+	 */
58
+	public static function getTableAnalysis()
59
+	{
60
+		if (! self::$table_analysis instanceof TableAnalysis) {
61
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true);
62
+		}
63
+		return self::$table_analysis;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return TableManager
69
+	 * @throws EE_Error
70
+	 * @throws ReflectionException
71
+	 */
72
+	public static function getTableManager()
73
+	{
74
+		if (! self::$table_manager instanceof TableManager) {
75
+			self::$table_manager = EE_Registry::instance()->create('TableManager', [], true);
76
+		}
77
+		return self::$table_manager;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param $table_name
83
+	 * @return string
84
+	 * @throws EE_Error
85
+	 * @throws ReflectionException
86
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
+	 */
88
+	public static function ensure_table_name_has_prefix($table_name)
89
+	{
90
+		return EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
91
+	}
92
+
93
+
94
+	/**
95
+	 * ensures the EE configuration settings are loaded with at least default options set
96
+	 * and that all critical EE pages have been generated with the appropriate shortcodes in place
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public static function system_initialization()
101
+	{
102
+		EEH_Activation::reset_and_update_config();
103
+		// which is fired BEFORE activation of plugin anyways
104
+		EEH_Activation::verify_default_pages_exist();
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets the database schema and creates folders. This should
110
+	 * be called on plugin activation and reactivation
111
+	 *
112
+	 * @return boolean success, whether the database and folders are setup properly
113
+	 * @throws EE_Error
114
+	 * @throws ReflectionException
115
+	 */
116
+	public static function initialize_db_and_folders()
117
+	{
118
+		return EEH_Activation::create_database_tables();
119
+	}
120
+
121
+
122
+	/**
123
+	 * assuming we have an up-to-date database schema, this will populate it
124
+	 * with default and initial data. This should be called
125
+	 * upon activation of a new plugin, reactivation, and at the end
126
+	 * of running migration scripts
127
+	 *
128
+	 * @throws EE_Error
129
+	 * @throws ReflectionException
130
+	 */
131
+	public static function initialize_db_content()
132
+	{
133
+		// let's avoid doing all this logic repeatedly, especially when addons are requesting it
134
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
135
+			return;
136
+		}
137
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
138
+
139
+		EEH_Activation::initialize_system_questions();
140
+		EEH_Activation::insert_default_status_codes();
141
+		EEH_Activation::generate_default_message_templates();
142
+		EEH_Activation::create_no_ticket_prices_array();
143
+		EEH_Activation::removeEmailConfirmFromAddressGroup();
144
+
145
+		EEH_Activation::validate_messages_system();
146
+		EEH_Activation::insert_default_payment_methods();
147
+		// in case we've
148
+		EEH_Activation::remove_cron_tasks();
149
+		EEH_Activation::create_cron_tasks();
150
+		// remove all TXN locks since that is being done via extra meta now
151
+		delete_option('ee_locked_transactions');
152
+		// also, check for CAF default db content
153
+		do_action('AHEE__EEH_Activation__initialize_db_content');
154
+		// also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
155
+		// which users really won't care about on initial activation
156
+		EE_Error::overwrite_success();
157
+	}
158
+
159
+
160
+	/**
161
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
162
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
163
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
164
+	 * (null)
165
+	 *
166
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
167
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
168
+	 * @return array
169
+	 * @throws EE_Error
170
+	 */
171
+	public static function get_cron_tasks($which_to_include)
172
+	{
173
+		$cron_tasks = apply_filters(
174
+			'FHEE__EEH_Activation__get_cron_tasks',
175
+			[
176
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
177
+				// 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' =>
178
+				// EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
179
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
180
+				// there may have been a bug which prevented from these cron tasks from getting unscheduled,
181
+				// so we might want to remove these for a few updates
182
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
183
+			]
184
+		);
185
+		if ($which_to_include === 'old') {
186
+			$cron_tasks = array_filter(
187
+				$cron_tasks,
188
+				function ($value) {
189
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
190
+				}
191
+			);
192
+		} elseif ($which_to_include === 'current') {
193
+			$cron_tasks = array_filter($cron_tasks);
194
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
195
+			throw new EE_Error(
196
+				sprintf(
197
+					esc_html__(
198
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
199
+						'event_espresso'
200
+					),
201
+					$which_to_include
202
+				)
203
+			);
204
+		}
205
+		return $cron_tasks;
206
+	}
207
+
208
+
209
+	/**
210
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
211
+	 *
212
+	 * @throws EE_Error
213
+	 */
214
+	public static function create_cron_tasks()
215
+	{
216
+
217
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
218
+			if (! wp_next_scheduled($hook_name)) {
219
+				/**
220
+				 * This allows client code to define the initial start timestamp for this schedule.
221
+				 */
222
+				if (
223
+					is_array($frequency)
224
+					&& count($frequency) === 2
225
+					&& isset($frequency[0], $frequency[1])
226
+				) {
227
+					$start_timestamp = $frequency[0];
228
+					$frequency       = $frequency[1];
229
+				} else {
230
+					$start_timestamp = time();
231
+				}
232
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
233
+			}
234
+		}
235
+	}
236
+
237
+
238
+	/**
239
+	 * Remove the currently-existing and now-removed cron tasks.
240
+	 *
241
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
242
+	 * @throws EE_Error
243
+	 */
244
+	public static function remove_cron_tasks($remove_all = true)
245
+	{
246
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
247
+		$crons                = _get_cron_array();
248
+		$crons                = is_array($crons) ? $crons : [];
249
+		/* reminder of what $crons look like:
250 250
          * Top-level keys are timestamps, and their values are arrays.
251 251
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
252 252
          * and their values are arrays.
@@ -263,893 +263,893 @@  discard block
 block discarded – undo
263 263
          *                  ...
264 264
          *      ...
265 265
          */
266
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
267
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
268
-            if (is_array($hooks_to_fire_at_time)) {
269
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
270
-                    if (
271
-                        isset($ee_cron_tasks_to_remove[ $hook_name ])
272
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
273
-                    ) {
274
-                        unset($crons[ $timestamp ][ $hook_name ]);
275
-                    }
276
-                }
277
-                // also take care of any empty cron timestamps.
278
-                if (empty($hooks_to_fire_at_time)) {
279
-                    unset($crons[ $timestamp ]);
280
-                }
281
-            }
282
-        }
283
-        _set_cron_array($crons);
284
-    }
285
-
286
-
287
-    /**
288
-     * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
289
-     *
290
-     * @return void
291
-     * @throws EE_Error
292
-     * @throws ReflectionException
293
-     */
294
-    public static function CPT_initialization()
295
-    {
296
-        // register Custom Post Types
297
-        EE_Registry::instance()->load_core('Register_CPTs');
298
-        flush_rewrite_rules();
299
-    }
300
-
301
-
302
-    /**
303
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
304
-     * If there is old calendar config data saved, then it will get converted on activation.
305
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
306
-     *
307
-     * @return void
308
-     */
309
-    public static function reset_and_update_config()
310
-    {
311
-        do_action('AHEE__EE_Config___load_core_config__start', ['EEH_Activation', 'load_calendar_config']);
312
-        add_filter(
313
-            'FHEE__EE_Config___load_core_config__config_settings',
314
-            ['EEH_Activation', 'migrate_old_config_data'],
315
-            10,
316
-            3
317
-        );
318
-        if (! EE_Config::logging_enabled()) {
319
-            delete_option(EE_Config::LOG_NAME);
320
-        }
321
-    }
322
-
323
-
324
-    /**
325
-     * @return    void
326
-     */
327
-    public static function load_calendar_config()
328
-    {
329
-        // grab array of all plugin folders and loop thru it
330
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
331
-        if (empty($plugins)) {
332
-            return;
333
-        }
334
-        foreach ($plugins as $plugin_path) {
335
-            // grab plugin folder name from path
336
-            $plugin = basename($plugin_path);
337
-            // drill down to Espresso plugins
338
-            // then to calendar related plugins
339
-            if (
340
-                strpos($plugin, 'espresso') !== false
341
-                || strpos($plugin, 'Espresso') !== false
342
-                || strpos($plugin, 'ee4') !== false
343
-                || strpos($plugin, 'EE4') !== false
344
-                || strpos($plugin, 'calendar') !== false
345
-            ) {
346
-                // this is what we are looking for
347
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
348
-                // does it exist in this folder ?
349
-                if (is_readable($calendar_config)) {
350
-                    // YEAH! let's load it
351
-                    require_once($calendar_config);
352
-                }
353
-            }
354
-        }
355
-    }
356
-
357
-
358
-    /**
359
-     * @param array|stdClass $settings
360
-     * @param string         $config
361
-     * @param EE_Config      $EE_Config
362
-     * @return stdClass
363
-     */
364
-    public static function migrate_old_config_data($settings, $config, EE_Config $EE_Config)
365
-    {
366
-        $convert_from_array = ['addons'];
367
-        // in case old settings were saved as an array
368
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
369
-            // convert existing settings to an object
370
-            $config_array = $settings;
371
-            $settings     = new stdClass();
372
-            foreach ($config_array as $key => $value) {
373
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
374
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
375
-                } else {
376
-                    $settings->{$key} = $value;
377
-                }
378
-            }
379
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
380
-        }
381
-        return $settings;
382
-    }
383
-
384
-
385
-    /**
386
-     * @return void
387
-     */
388
-    public static function deactivate_event_espresso()
389
-    {
390
-        // check permissions
391
-        if (current_user_can('activate_plugins')) {
392
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
393
-        }
394
-    }
395
-
396
-
397
-    /**
398
-     * @return void
399
-     * @throws InvalidDataTypeException
400
-     */
401
-    public static function verify_default_pages_exist()
402
-    {
403
-        $critical_page_problem = false;
404
-        $critical_pages        = [
405
-            [
406
-                'id'   => 'reg_page_id',
407
-                'name' => esc_html__('Registration Checkout', 'event_espresso'),
408
-                'post' => null,
409
-                'code' => 'ESPRESSO_CHECKOUT',
410
-            ],
411
-            [
412
-                'id'   => 'txn_page_id',
413
-                'name' => esc_html__('Transactions', 'event_espresso'),
414
-                'post' => null,
415
-                'code' => 'ESPRESSO_TXN_PAGE',
416
-            ],
417
-            [
418
-                'id'   => 'thank_you_page_id',
419
-                'name' => esc_html__('Thank You', 'event_espresso'),
420
-                'post' => null,
421
-                'code' => 'ESPRESSO_THANK_YOU',
422
-            ],
423
-            [
424
-                'id'   => 'cancel_page_id',
425
-                'name' => esc_html__('Registration Cancelled', 'event_espresso'),
426
-                'post' => null,
427
-                'code' => 'ESPRESSO_CANCELLED',
428
-            ],
429
-        ];
430
-        $EE_Core_Config        = EE_Registry::instance()->CFG->core;
431
-        foreach ($critical_pages as $critical_page) {
432
-            // is critical page ID set in config ?
433
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
434
-                // attempt to find post by ID
435
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
436
-            }
437
-            // no dice?
438
-            if ($critical_page['post'] === null) {
439
-                // attempt to find post by title
440
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
441
-                // still nothing?
442
-                if ($critical_page['post'] === null) {
443
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
444
-                    // REALLY? Still nothing ??!?!?
445
-                    if ($critical_page['post'] === null) {
446
-                        $msg = esc_html__(
447
-                            'The Event Espresso critical page configuration settings could not be updated.',
448
-                            'event_espresso'
449
-                        );
450
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
451
-                        break;
452
-                    }
453
-                }
454
-            }
455
-            // check that Post ID matches critical page ID in config
456
-            if (
457
-                isset($critical_page['post']->ID)
458
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
459
-            ) {
460
-                // update Config with post ID
461
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
462
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
463
-                    $msg = esc_html__(
464
-                        'The Event Espresso critical page configuration settings could not be updated.',
465
-                        'event_espresso'
466
-                    );
467
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
468
-                }
469
-            }
470
-            $critical_page_problem =
471
-                ! isset($critical_page['post']->post_status)
472
-                || $critical_page['post']->post_status !== 'publish'
473
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
474
-                    ? true
475
-                    : $critical_page_problem;
476
-        }
477
-        if ($critical_page_problem) {
478
-            new PersistentAdminNotice(
479
-                'critical_page_problem',
480
-                sprintf(
481
-                    esc_html__(
482
-                        'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
483
-                        'event_espresso'
484
-                    ),
485
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
486
-                    . esc_html__('Event Espresso Critical Pages Settings', 'event_espresso')
487
-                    . '</a>'
488
-                )
489
-            );
490
-        }
491
-        if (EE_Error::has_notices()) {
492
-            EE_Error::get_notices(false, true);
493
-        }
494
-    }
495
-
496
-
497
-    /**
498
-     * Returns the first post which uses the specified shortcode
499
-     *
500
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
501
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
502
-     *                             "[ESPRESSO_THANK_YOU"
503
-     *                             (we don't search for the closing shortcode bracket because they might have added
504
-     *                             parameter to the shortcode
505
-     * @return WP_Post or NULl
506
-     */
507
-    public static function get_page_by_ee_shortcode($ee_shortcode)
508
-    {
509
-        global $wpdb;
510
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
511
-        $post_id                       =
512
-            $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
513
-        if ($post_id) {
514
-            return get_post($post_id);
515
-        } else {
516
-            return null;
517
-        }
518
-    }
519
-
520
-
521
-    /**
522
-     * This function generates a post for critical espresso pages
523
-     *
524
-     * @param array $critical_page
525
-     * @return array
526
-     */
527
-    public static function create_critical_page($critical_page)
528
-    {
529
-
530
-        $post_args = [
531
-            'post_title'     => $critical_page['name'],
532
-            'post_status'    => 'publish',
533
-            'post_type'      => 'page',
534
-            'comment_status' => 'closed',
535
-            'post_content'   => '[' . $critical_page['code'] . ']',
536
-        ];
537
-
538
-        $post_id = wp_insert_post($post_args);
539
-        if (! $post_id) {
540
-            $msg = sprintf(
541
-                esc_html__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
542
-                $critical_page['name']
543
-            );
544
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
545
-            return $critical_page;
546
-        }
547
-        // get newly created post's details
548
-        if (! $critical_page['post'] = get_post($post_id)) {
549
-            $msg = sprintf(
550
-                esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
551
-                $critical_page['name']
552
-            );
553
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
554
-        }
555
-
556
-        return $critical_page;
557
-    }
558
-
559
-
560
-    /**
561
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
562
-     * The role being used to check is filterable.
563
-     *
564
-     * @return int|null WP_user ID or NULL
565
-     * @throws EE_Error
566
-     * @throws ReflectionException
567
-     * @since  4.6.0
568
-     * @global WPDB $wpdb
569
-     */
570
-    public static function get_default_creator_id()
571
-    {
572
-        global $wpdb;
573
-        if (! empty(self::$_default_creator_id)) {
574
-            return self::$_default_creator_id;
575
-        }/**/
576
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
577
-        // let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
578
-        $pre_filtered_id = apply_filters(
579
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
580
-            false,
581
-            $role_to_check
582
-        );
583
-        if ($pre_filtered_id !== false) {
584
-            return (int) $pre_filtered_id;
585
-        }
586
-        $capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
587
-        $query            = $wpdb->prepare(
588
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
589
-            '%' . $role_to_check . '%'
590
-        );
591
-        $user_id          = $wpdb->get_var($query);
592
-        $user_id          = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
593
-        if ($user_id && (int) $user_id) {
594
-            self::$_default_creator_id = (int) $user_id;
595
-            return self::$_default_creator_id;
596
-        } else {
597
-            return null;
598
-        }
599
-    }
600
-
601
-
602
-    /**
603
-     * used by EE and EE addons during plugin activation to create tables.
604
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
605
-     * but includes extra logic regarding activations.
606
-     *
607
-     * @param string  $table_name              without the $wpdb->prefix
608
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
609
-     *                                         table query)
610
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
611
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
612
-     *                                         and new once this function is done (ie, you really do want to CREATE a
613
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
614
-     *                                         you just want to verify the table exists and matches this definition
615
-     *                                         (and if it HAS data in it you want to leave it be)
616
-     * @return void
617
-     * @throws EE_Error if there are database errors
618
-     * @throws ReflectionException
619
-     */
620
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
621
-    {
622
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
623
-            return;
624
-        }
625
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
626
-        if (! function_exists('dbDelta')) {
627
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
628
-        }
629
-        $tableAnalysis = EEH_Activation::getTableAnalysis();
630
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
631
-        // do we need to first delete an existing version of this table ?
632
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
633
-            // ok, delete the table... but ONLY if it's empty
634
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
635
-            // table is NOT empty, are you SURE you want to delete this table ???
636
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
637
-                EEH_Activation::getTableManager()->dropTable($wp_table_name);
638
-            } elseif (! $deleted_safely) {
639
-                // so we should be more cautious rather than just dropping tables so easily
640
-                error_log(
641
-                    sprintf(
642
-                        esc_html__(
643
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
644
-                            'event_espresso'
645
-                        ),
646
-                        $wp_table_name,
647
-                        '<br/>',
648
-                        'espresso_db_update'
649
-                    )
650
-                );
651
-            }
652
-        }
653
-        $engine = str_replace('ENGINE=', '', $engine);
654
-        EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
655
-    }
656
-
657
-
658
-    /**
659
-     * Checks if this column already exists on the specified table. Handy for addons which want to add a column
660
-     *
661
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
662
-     * @param string $column_name
663
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
664
-     *                            'VARCHAR(10)'
665
-     * @return bool|int
666
-     * @throws EE_Error
667
-     * @throws ReflectionException
668
-     * @deprecated instead use TableManager::addColumn()
669
-     */
670
-    public static function add_column_if_it_doesnt_exist(
671
-        $table_name,
672
-        $column_name,
673
-        $column_info = 'INT UNSIGNED NOT NULL'
674
-    ) {
675
-        return EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
676
-    }
677
-
678
-
679
-    /**
680
-     * Gets all the fields on the database table.
681
-     *
682
-     * @param string $table_name , without prefixed $wpdb->prefix
683
-     * @return array of database column names
684
-     * @throws EE_Error
685
-     * @throws ReflectionException
686
-     * @deprecated instead use TableManager::getTableColumns()
687
-     */
688
-    public static function get_fields_on_table($table_name = null)
689
-    {
690
-        return EEH_Activation::getTableManager()->getTableColumns($table_name);
691
-    }
692
-
693
-
694
-    /**
695
-     * @param string $table_name
696
-     * @return bool
697
-     * @throws EE_Error
698
-     * @throws ReflectionException
699
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
700
-     */
701
-    public static function db_table_is_empty($table_name)
702
-    {
703
-        return EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
704
-    }
705
-
706
-
707
-    /**
708
-     * @param string $table_name
709
-     * @return bool | int
710
-     * @throws EE_Error
711
-     * @throws ReflectionException
712
-     */
713
-    public static function delete_db_table_if_empty($table_name)
714
-    {
715
-        if (EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
716
-            return EEH_Activation::getTableManager()->dropTable($table_name);
717
-        }
718
-        return false;
719
-    }
720
-
721
-
722
-    /**
723
-     * @param string $table_name
724
-     * @return int
725
-     * @throws EE_Error
726
-     * @throws ReflectionException
727
-     * @deprecated instead use TableManager::dropTable()
728
-     */
729
-    public static function delete_unused_db_table($table_name)
730
-    {
731
-        return EEH_Activation::getTableManager()->dropTable($table_name);
732
-    }
733
-
734
-
735
-    /**
736
-     * @param string $table_name
737
-     * @param string $index_name
738
-     * @return int
739
-     * @throws EE_Error
740
-     * @throws ReflectionException
741
-     * @deprecated instead use TableManager::dropIndex()
742
-     */
743
-    public static function drop_index($table_name, $index_name)
744
-    {
745
-        return EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
746
-    }
747
-
748
-
749
-    /**
750
-     * @return boolean success (whether database is setup properly or not)
751
-     * @throws EE_Error
752
-     * @throws ReflectionException
753
-     */
754
-    public static function create_database_tables()
755
-    {
756
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
757
-        // find the migration script that sets the database to be compatible with the code
758
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
759
-        if (! $dms_name) {
760
-            EE_Error::add_error(
761
-                esc_html__(
762
-                    'Could not determine most up-to-date data migration script from which to pull database schema
266
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
267
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
268
+			if (is_array($hooks_to_fire_at_time)) {
269
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
270
+					if (
271
+						isset($ee_cron_tasks_to_remove[ $hook_name ])
272
+						&& is_array($ee_cron_tasks_to_remove[ $hook_name ])
273
+					) {
274
+						unset($crons[ $timestamp ][ $hook_name ]);
275
+					}
276
+				}
277
+				// also take care of any empty cron timestamps.
278
+				if (empty($hooks_to_fire_at_time)) {
279
+					unset($crons[ $timestamp ]);
280
+				}
281
+			}
282
+		}
283
+		_set_cron_array($crons);
284
+	}
285
+
286
+
287
+	/**
288
+	 * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
289
+	 *
290
+	 * @return void
291
+	 * @throws EE_Error
292
+	 * @throws ReflectionException
293
+	 */
294
+	public static function CPT_initialization()
295
+	{
296
+		// register Custom Post Types
297
+		EE_Registry::instance()->load_core('Register_CPTs');
298
+		flush_rewrite_rules();
299
+	}
300
+
301
+
302
+	/**
303
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
304
+	 * If there is old calendar config data saved, then it will get converted on activation.
305
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
306
+	 *
307
+	 * @return void
308
+	 */
309
+	public static function reset_and_update_config()
310
+	{
311
+		do_action('AHEE__EE_Config___load_core_config__start', ['EEH_Activation', 'load_calendar_config']);
312
+		add_filter(
313
+			'FHEE__EE_Config___load_core_config__config_settings',
314
+			['EEH_Activation', 'migrate_old_config_data'],
315
+			10,
316
+			3
317
+		);
318
+		if (! EE_Config::logging_enabled()) {
319
+			delete_option(EE_Config::LOG_NAME);
320
+		}
321
+	}
322
+
323
+
324
+	/**
325
+	 * @return    void
326
+	 */
327
+	public static function load_calendar_config()
328
+	{
329
+		// grab array of all plugin folders and loop thru it
330
+		$plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
331
+		if (empty($plugins)) {
332
+			return;
333
+		}
334
+		foreach ($plugins as $plugin_path) {
335
+			// grab plugin folder name from path
336
+			$plugin = basename($plugin_path);
337
+			// drill down to Espresso plugins
338
+			// then to calendar related plugins
339
+			if (
340
+				strpos($plugin, 'espresso') !== false
341
+				|| strpos($plugin, 'Espresso') !== false
342
+				|| strpos($plugin, 'ee4') !== false
343
+				|| strpos($plugin, 'EE4') !== false
344
+				|| strpos($plugin, 'calendar') !== false
345
+			) {
346
+				// this is what we are looking for
347
+				$calendar_config = $plugin_path . '/EE_Calendar_Config.php';
348
+				// does it exist in this folder ?
349
+				if (is_readable($calendar_config)) {
350
+					// YEAH! let's load it
351
+					require_once($calendar_config);
352
+				}
353
+			}
354
+		}
355
+	}
356
+
357
+
358
+	/**
359
+	 * @param array|stdClass $settings
360
+	 * @param string         $config
361
+	 * @param EE_Config      $EE_Config
362
+	 * @return stdClass
363
+	 */
364
+	public static function migrate_old_config_data($settings, $config, EE_Config $EE_Config)
365
+	{
366
+		$convert_from_array = ['addons'];
367
+		// in case old settings were saved as an array
368
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
369
+			// convert existing settings to an object
370
+			$config_array = $settings;
371
+			$settings     = new stdClass();
372
+			foreach ($config_array as $key => $value) {
373
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
374
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
375
+				} else {
376
+					$settings->{$key} = $value;
377
+				}
378
+			}
379
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
380
+		}
381
+		return $settings;
382
+	}
383
+
384
+
385
+	/**
386
+	 * @return void
387
+	 */
388
+	public static function deactivate_event_espresso()
389
+	{
390
+		// check permissions
391
+		if (current_user_can('activate_plugins')) {
392
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
393
+		}
394
+	}
395
+
396
+
397
+	/**
398
+	 * @return void
399
+	 * @throws InvalidDataTypeException
400
+	 */
401
+	public static function verify_default_pages_exist()
402
+	{
403
+		$critical_page_problem = false;
404
+		$critical_pages        = [
405
+			[
406
+				'id'   => 'reg_page_id',
407
+				'name' => esc_html__('Registration Checkout', 'event_espresso'),
408
+				'post' => null,
409
+				'code' => 'ESPRESSO_CHECKOUT',
410
+			],
411
+			[
412
+				'id'   => 'txn_page_id',
413
+				'name' => esc_html__('Transactions', 'event_espresso'),
414
+				'post' => null,
415
+				'code' => 'ESPRESSO_TXN_PAGE',
416
+			],
417
+			[
418
+				'id'   => 'thank_you_page_id',
419
+				'name' => esc_html__('Thank You', 'event_espresso'),
420
+				'post' => null,
421
+				'code' => 'ESPRESSO_THANK_YOU',
422
+			],
423
+			[
424
+				'id'   => 'cancel_page_id',
425
+				'name' => esc_html__('Registration Cancelled', 'event_espresso'),
426
+				'post' => null,
427
+				'code' => 'ESPRESSO_CANCELLED',
428
+			],
429
+		];
430
+		$EE_Core_Config        = EE_Registry::instance()->CFG->core;
431
+		foreach ($critical_pages as $critical_page) {
432
+			// is critical page ID set in config ?
433
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
434
+				// attempt to find post by ID
435
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
436
+			}
437
+			// no dice?
438
+			if ($critical_page['post'] === null) {
439
+				// attempt to find post by title
440
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
441
+				// still nothing?
442
+				if ($critical_page['post'] === null) {
443
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
444
+					// REALLY? Still nothing ??!?!?
445
+					if ($critical_page['post'] === null) {
446
+						$msg = esc_html__(
447
+							'The Event Espresso critical page configuration settings could not be updated.',
448
+							'event_espresso'
449
+						);
450
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
451
+						break;
452
+					}
453
+				}
454
+			}
455
+			// check that Post ID matches critical page ID in config
456
+			if (
457
+				isset($critical_page['post']->ID)
458
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
459
+			) {
460
+				// update Config with post ID
461
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
462
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
463
+					$msg = esc_html__(
464
+						'The Event Espresso critical page configuration settings could not be updated.',
465
+						'event_espresso'
466
+					);
467
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
468
+				}
469
+			}
470
+			$critical_page_problem =
471
+				! isset($critical_page['post']->post_status)
472
+				|| $critical_page['post']->post_status !== 'publish'
473
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
474
+					? true
475
+					: $critical_page_problem;
476
+		}
477
+		if ($critical_page_problem) {
478
+			new PersistentAdminNotice(
479
+				'critical_page_problem',
480
+				sprintf(
481
+					esc_html__(
482
+						'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
483
+						'event_espresso'
484
+					),
485
+					'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
486
+					. esc_html__('Event Espresso Critical Pages Settings', 'event_espresso')
487
+					. '</a>'
488
+				)
489
+			);
490
+		}
491
+		if (EE_Error::has_notices()) {
492
+			EE_Error::get_notices(false, true);
493
+		}
494
+	}
495
+
496
+
497
+	/**
498
+	 * Returns the first post which uses the specified shortcode
499
+	 *
500
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
501
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
502
+	 *                             "[ESPRESSO_THANK_YOU"
503
+	 *                             (we don't search for the closing shortcode bracket because they might have added
504
+	 *                             parameter to the shortcode
505
+	 * @return WP_Post or NULl
506
+	 */
507
+	public static function get_page_by_ee_shortcode($ee_shortcode)
508
+	{
509
+		global $wpdb;
510
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
511
+		$post_id                       =
512
+			$wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
513
+		if ($post_id) {
514
+			return get_post($post_id);
515
+		} else {
516
+			return null;
517
+		}
518
+	}
519
+
520
+
521
+	/**
522
+	 * This function generates a post for critical espresso pages
523
+	 *
524
+	 * @param array $critical_page
525
+	 * @return array
526
+	 */
527
+	public static function create_critical_page($critical_page)
528
+	{
529
+
530
+		$post_args = [
531
+			'post_title'     => $critical_page['name'],
532
+			'post_status'    => 'publish',
533
+			'post_type'      => 'page',
534
+			'comment_status' => 'closed',
535
+			'post_content'   => '[' . $critical_page['code'] . ']',
536
+		];
537
+
538
+		$post_id = wp_insert_post($post_args);
539
+		if (! $post_id) {
540
+			$msg = sprintf(
541
+				esc_html__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
542
+				$critical_page['name']
543
+			);
544
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
545
+			return $critical_page;
546
+		}
547
+		// get newly created post's details
548
+		if (! $critical_page['post'] = get_post($post_id)) {
549
+			$msg = sprintf(
550
+				esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
551
+				$critical_page['name']
552
+			);
553
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
554
+		}
555
+
556
+		return $critical_page;
557
+	}
558
+
559
+
560
+	/**
561
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
562
+	 * The role being used to check is filterable.
563
+	 *
564
+	 * @return int|null WP_user ID or NULL
565
+	 * @throws EE_Error
566
+	 * @throws ReflectionException
567
+	 * @since  4.6.0
568
+	 * @global WPDB $wpdb
569
+	 */
570
+	public static function get_default_creator_id()
571
+	{
572
+		global $wpdb;
573
+		if (! empty(self::$_default_creator_id)) {
574
+			return self::$_default_creator_id;
575
+		}/**/
576
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
577
+		// let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
578
+		$pre_filtered_id = apply_filters(
579
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
580
+			false,
581
+			$role_to_check
582
+		);
583
+		if ($pre_filtered_id !== false) {
584
+			return (int) $pre_filtered_id;
585
+		}
586
+		$capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
587
+		$query            = $wpdb->prepare(
588
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
589
+			'%' . $role_to_check . '%'
590
+		);
591
+		$user_id          = $wpdb->get_var($query);
592
+		$user_id          = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
593
+		if ($user_id && (int) $user_id) {
594
+			self::$_default_creator_id = (int) $user_id;
595
+			return self::$_default_creator_id;
596
+		} else {
597
+			return null;
598
+		}
599
+	}
600
+
601
+
602
+	/**
603
+	 * used by EE and EE addons during plugin activation to create tables.
604
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
605
+	 * but includes extra logic regarding activations.
606
+	 *
607
+	 * @param string  $table_name              without the $wpdb->prefix
608
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
609
+	 *                                         table query)
610
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
611
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
612
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
613
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
614
+	 *                                         you just want to verify the table exists and matches this definition
615
+	 *                                         (and if it HAS data in it you want to leave it be)
616
+	 * @return void
617
+	 * @throws EE_Error if there are database errors
618
+	 * @throws ReflectionException
619
+	 */
620
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
621
+	{
622
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
623
+			return;
624
+		}
625
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
626
+		if (! function_exists('dbDelta')) {
627
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
628
+		}
629
+		$tableAnalysis = EEH_Activation::getTableAnalysis();
630
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
631
+		// do we need to first delete an existing version of this table ?
632
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
633
+			// ok, delete the table... but ONLY if it's empty
634
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
635
+			// table is NOT empty, are you SURE you want to delete this table ???
636
+			if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
637
+				EEH_Activation::getTableManager()->dropTable($wp_table_name);
638
+			} elseif (! $deleted_safely) {
639
+				// so we should be more cautious rather than just dropping tables so easily
640
+				error_log(
641
+					sprintf(
642
+						esc_html__(
643
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
644
+							'event_espresso'
645
+						),
646
+						$wp_table_name,
647
+						'<br/>',
648
+						'espresso_db_update'
649
+					)
650
+				);
651
+			}
652
+		}
653
+		$engine = str_replace('ENGINE=', '', $engine);
654
+		EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
655
+	}
656
+
657
+
658
+	/**
659
+	 * Checks if this column already exists on the specified table. Handy for addons which want to add a column
660
+	 *
661
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
662
+	 * @param string $column_name
663
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
664
+	 *                            'VARCHAR(10)'
665
+	 * @return bool|int
666
+	 * @throws EE_Error
667
+	 * @throws ReflectionException
668
+	 * @deprecated instead use TableManager::addColumn()
669
+	 */
670
+	public static function add_column_if_it_doesnt_exist(
671
+		$table_name,
672
+		$column_name,
673
+		$column_info = 'INT UNSIGNED NOT NULL'
674
+	) {
675
+		return EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
676
+	}
677
+
678
+
679
+	/**
680
+	 * Gets all the fields on the database table.
681
+	 *
682
+	 * @param string $table_name , without prefixed $wpdb->prefix
683
+	 * @return array of database column names
684
+	 * @throws EE_Error
685
+	 * @throws ReflectionException
686
+	 * @deprecated instead use TableManager::getTableColumns()
687
+	 */
688
+	public static function get_fields_on_table($table_name = null)
689
+	{
690
+		return EEH_Activation::getTableManager()->getTableColumns($table_name);
691
+	}
692
+
693
+
694
+	/**
695
+	 * @param string $table_name
696
+	 * @return bool
697
+	 * @throws EE_Error
698
+	 * @throws ReflectionException
699
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
700
+	 */
701
+	public static function db_table_is_empty($table_name)
702
+	{
703
+		return EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
704
+	}
705
+
706
+
707
+	/**
708
+	 * @param string $table_name
709
+	 * @return bool | int
710
+	 * @throws EE_Error
711
+	 * @throws ReflectionException
712
+	 */
713
+	public static function delete_db_table_if_empty($table_name)
714
+	{
715
+		if (EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
716
+			return EEH_Activation::getTableManager()->dropTable($table_name);
717
+		}
718
+		return false;
719
+	}
720
+
721
+
722
+	/**
723
+	 * @param string $table_name
724
+	 * @return int
725
+	 * @throws EE_Error
726
+	 * @throws ReflectionException
727
+	 * @deprecated instead use TableManager::dropTable()
728
+	 */
729
+	public static function delete_unused_db_table($table_name)
730
+	{
731
+		return EEH_Activation::getTableManager()->dropTable($table_name);
732
+	}
733
+
734
+
735
+	/**
736
+	 * @param string $table_name
737
+	 * @param string $index_name
738
+	 * @return int
739
+	 * @throws EE_Error
740
+	 * @throws ReflectionException
741
+	 * @deprecated instead use TableManager::dropIndex()
742
+	 */
743
+	public static function drop_index($table_name, $index_name)
744
+	{
745
+		return EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
746
+	}
747
+
748
+
749
+	/**
750
+	 * @return boolean success (whether database is setup properly or not)
751
+	 * @throws EE_Error
752
+	 * @throws ReflectionException
753
+	 */
754
+	public static function create_database_tables()
755
+	{
756
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
757
+		// find the migration script that sets the database to be compatible with the code
758
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
759
+		if (! $dms_name) {
760
+			EE_Error::add_error(
761
+				esc_html__(
762
+					'Could not determine most up-to-date data migration script from which to pull database schema
763 763
                      structure. So database is probably not setup properly',
764
-                    'event_espresso'
765
-                ),
766
-                __FILE__,
767
-                __FUNCTION__,
768
-                __LINE__
769
-            );
770
-            return false;
771
-        }
772
-        $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
773
-        $current_data_migration_script->set_migrating(false);
774
-        $current_data_migration_script->schema_changes_before_migration();
775
-        $current_data_migration_script->schema_changes_after_migration();
776
-        if ($current_data_migration_script->get_errors()) {
777
-            if (WP_DEBUG) {
778
-                foreach ($current_data_migration_script->get_errors() as $error) {
779
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
780
-                }
781
-            } else {
782
-                EE_Error::add_error(
783
-                    esc_html__(
784
-                        'There were errors creating the Event Espresso database tables and Event Espresso has been 
764
+					'event_espresso'
765
+				),
766
+				__FILE__,
767
+				__FUNCTION__,
768
+				__LINE__
769
+			);
770
+			return false;
771
+		}
772
+		$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
773
+		$current_data_migration_script->set_migrating(false);
774
+		$current_data_migration_script->schema_changes_before_migration();
775
+		$current_data_migration_script->schema_changes_after_migration();
776
+		if ($current_data_migration_script->get_errors()) {
777
+			if (WP_DEBUG) {
778
+				foreach ($current_data_migration_script->get_errors() as $error) {
779
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
780
+				}
781
+			} else {
782
+				EE_Error::add_error(
783
+					esc_html__(
784
+						'There were errors creating the Event Espresso database tables and Event Espresso has been 
785 785
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
786
-                        'event_espresso'
787
-                    )
788
-                );
789
-            }
790
-            return false;
791
-        }
792
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to();
793
-        return true;
794
-    }
795
-
796
-
797
-    /**
798
-     * @return void
799
-     * @throws EE_Error
800
-     * @throws ReflectionException
801
-     */
802
-    public static function initialize_system_questions()
803
-    {
804
-        // QUESTION GROUPS
805
-        global $wpdb;
806
-        $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
807
-        $SQL        = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
808
-        // what we have
809
-        $question_groups = $wpdb->get_col($SQL);
810
-        // check the response
811
-        $question_groups = is_array($question_groups) ? $question_groups : [];
812
-        // what we should have
813
-        $QSG_systems = [1, 2];
814
-        // loop thru what we should have and compare to what we have
815
-        foreach ($QSG_systems as $QSG_system) {
816
-            // reset values array
817
-            $QSG_values = [];
818
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
819
-            if (! in_array("$QSG_system", $question_groups)) {
820
-                // add it
821
-                switch ($QSG_system) {
822
-                    case 1:
823
-                        $QSG_values = [
824
-                            'QSG_name'            => esc_html__('Personal Information', 'event_espresso'),
825
-                            'QSG_identifier'      => 'personal-information-' . time(),
826
-                            'QSG_desc'            => '',
827
-                            'QSG_order'           => 1,
828
-                            'QSG_show_group_name' => 1,
829
-                            'QSG_show_group_desc' => 1,
830
-                            'QSG_system'          => EEM_Question_Group::system_personal,
831
-                            'QSG_deleted'         => 0,
832
-                        ];
833
-                        break;
834
-                    case 2:
835
-                        $QSG_values = [
836
-                            'QSG_name'            => esc_html__('Address Information', 'event_espresso'),
837
-                            'QSG_identifier'      => 'address-information-' . time(),
838
-                            'QSG_desc'            => '',
839
-                            'QSG_order'           => 2,
840
-                            'QSG_show_group_name' => 1,
841
-                            'QSG_show_group_desc' => 1,
842
-                            'QSG_system'          => EEM_Question_Group::system_address,
843
-                            'QSG_deleted'         => 0,
844
-                        ];
845
-                        break;
846
-                }
847
-                // make sure we have some values before inserting them
848
-                if (! empty($QSG_values)) {
849
-                    // insert system question
850
-                    $wpdb->insert(
851
-                        $table_name,
852
-                        $QSG_values,
853
-                        ['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d']
854
-                    );
855
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
856
-                }
857
-            }
858
-        }
859
-        // QUESTIONS
860
-        global $wpdb;
861
-        $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
862
-        $SQL        = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
863
-        // what we have
864
-        $questions = $wpdb->get_col($SQL);
865
-        // all system questions
866
-        $personal_system_group_questions = ['fname', 'lname', 'email'];
867
-        $address_system_group_questions  = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
868
-        $system_questions_not_in_group   = ['email_confirm'];
869
-        // merge all of the system questions we should have
870
-        $QST_systems       = array_merge(
871
-            $personal_system_group_questions,
872
-            $address_system_group_questions,
873
-            $system_questions_not_in_group
874
-        );
875
-        $order_for_group_1 = 1;
876
-        $order_for_group_2 = 1;
877
-        // loop thru what we should have and compare to what we have
878
-        foreach ($QST_systems as $QST_system) {
879
-            // reset values array
880
-            $QST_values = [];
881
-            // if we don't have what we should have
882
-            if (! in_array($QST_system, $questions)) {
883
-                // add it
884
-                switch ($QST_system) {
885
-                    case 'fname':
886
-                        $QST_values = [
887
-                            'QST_display_text'  => esc_html__('First Name', 'event_espresso'),
888
-                            'QST_admin_label'   => esc_html__('First Name - System Question', 'event_espresso'),
889
-                            'QST_system'        => 'fname',
890
-                            'QST_type'          => 'TEXT',
891
-                            'QST_required'      => 1,
892
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
893
-                            'QST_order'         => 1,
894
-                            'QST_admin_only'    => 0,
895
-                            'QST_max'           => EEM_Question::instance()
896
-                                                               ->absolute_max_for_system_question($QST_system),
897
-                            'QST_wp_user'       => self::get_default_creator_id(),
898
-                            'QST_deleted'       => 0,
899
-                        ];
900
-                        break;
901
-                    case 'lname':
902
-                        $QST_values = [
903
-                            'QST_display_text'  => esc_html__('Last Name', 'event_espresso'),
904
-                            'QST_admin_label'   => esc_html__('Last Name - System Question', 'event_espresso'),
905
-                            'QST_system'        => 'lname',
906
-                            'QST_type'          => 'TEXT',
907
-                            'QST_required'      => 1,
908
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
909
-                            'QST_order'         => 2,
910
-                            'QST_admin_only'    => 0,
911
-                            'QST_max'           => EEM_Question::instance()
912
-                                                               ->absolute_max_for_system_question($QST_system),
913
-                            'QST_wp_user'       => self::get_default_creator_id(),
914
-                            'QST_deleted'       => 0,
915
-                        ];
916
-                        break;
917
-                    case 'email':
918
-                        $QST_values = [
919
-                            'QST_display_text'  => esc_html__('Email Address', 'event_espresso'),
920
-                            'QST_admin_label'   => esc_html__('Email Address - System Question', 'event_espresso'),
921
-                            'QST_system'        => 'email',
922
-                            'QST_type'          => 'EMAIL',
923
-                            'QST_required'      => 1,
924
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
925
-                            'QST_order'         => 3,
926
-                            'QST_admin_only'    => 0,
927
-                            'QST_max'           => EEM_Question::instance()
928
-                                                               ->absolute_max_for_system_question($QST_system),
929
-                            'QST_wp_user'       => self::get_default_creator_id(),
930
-                            'QST_deleted'       => 0,
931
-                        ];
932
-                        break;
933
-                    case 'email_confirm':
934
-                        $QST_values = [
935
-                            'QST_display_text'  => esc_html__('Confirm Email Address', 'event_espresso'),
936
-                            'QST_admin_label'   => esc_html__('Confirm Email Address - System Question', 'event_espresso'),
937
-                            'QST_system'        => 'email_confirm',
938
-                            'QST_type'          => 'EMAIL_CONFIRM',
939
-                            'QST_required'      => 1,
940
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
941
-                            'QST_order'         => 4,
942
-                            'QST_admin_only'    => 0,
943
-                            'QST_max'           => EEM_Question::instance()
944
-                                                               ->absolute_max_for_system_question($QST_system),
945
-                            'QST_wp_user'       => self::get_default_creator_id(),
946
-                            'QST_deleted'       => 0,
947
-                        ];
948
-                        break;
949
-                    case 'address':
950
-                        $QST_values = [
951
-                            'QST_display_text'  => esc_html__('Address', 'event_espresso'),
952
-                            'QST_admin_label'   => esc_html__('Address - System Question', 'event_espresso'),
953
-                            'QST_system'        => 'address',
954
-                            'QST_type'          => 'TEXT',
955
-                            'QST_required'      => 0,
956
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
957
-                            'QST_order'         => 5,
958
-                            'QST_admin_only'    => 0,
959
-                            'QST_max'           => EEM_Question::instance()
960
-                                                               ->absolute_max_for_system_question($QST_system),
961
-                            'QST_wp_user'       => self::get_default_creator_id(),
962
-                            'QST_deleted'       => 0,
963
-                        ];
964
-                        break;
965
-                    case 'address2':
966
-                        $QST_values = [
967
-                            'QST_display_text'  => esc_html__('Address2', 'event_espresso'),
968
-                            'QST_admin_label'   => esc_html__('Address2 - System Question', 'event_espresso'),
969
-                            'QST_system'        => 'address2',
970
-                            'QST_type'          => 'TEXT',
971
-                            'QST_required'      => 0,
972
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
973
-                            'QST_order'         => 6,
974
-                            'QST_admin_only'    => 0,
975
-                            'QST_max'           => EEM_Question::instance()
976
-                                                               ->absolute_max_for_system_question($QST_system),
977
-                            'QST_wp_user'       => self::get_default_creator_id(),
978
-                            'QST_deleted'       => 0,
979
-                        ];
980
-                        break;
981
-                    case 'city':
982
-                        $QST_values = [
983
-                            'QST_display_text'  => esc_html__('City', 'event_espresso'),
984
-                            'QST_admin_label'   => esc_html__('City - System Question', 'event_espresso'),
985
-                            'QST_system'        => 'city',
986
-                            'QST_type'          => 'TEXT',
987
-                            'QST_required'      => 0,
988
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
989
-                            'QST_order'         => 7,
990
-                            'QST_admin_only'    => 0,
991
-                            'QST_max'           => EEM_Question::instance()
992
-                                                               ->absolute_max_for_system_question($QST_system),
993
-                            'QST_wp_user'       => self::get_default_creator_id(),
994
-                            'QST_deleted'       => 0,
995
-                        ];
996
-                        break;
997
-                    case 'country':
998
-                        $QST_values = [
999
-                            'QST_display_text'  => esc_html__('Country', 'event_espresso'),
1000
-                            'QST_admin_label'   => esc_html__('Country - System Question', 'event_espresso'),
1001
-                            'QST_system'        => 'country',
1002
-                            'QST_type'          => 'COUNTRY',
1003
-                            'QST_required'      => 0,
1004
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1005
-                            'QST_order'         => 8,
1006
-                            'QST_admin_only'    => 0,
1007
-                            'QST_wp_user'       => self::get_default_creator_id(),
1008
-                            'QST_deleted'       => 0,
1009
-                        ];
1010
-                        break;
1011
-                    case 'state':
1012
-                        $QST_values = [
1013
-                            'QST_display_text'  => esc_html__('State/Province', 'event_espresso'),
1014
-                            'QST_admin_label'   => esc_html__('State/Province - System Question', 'event_espresso'),
1015
-                            'QST_system'        => 'state',
1016
-                            'QST_type'          => 'STATE',
1017
-                            'QST_required'      => 0,
1018
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1019
-                            'QST_order'         => 9,
1020
-                            'QST_admin_only'    => 0,
1021
-                            'QST_wp_user'       => self::get_default_creator_id(),
1022
-                            'QST_deleted'       => 0,
1023
-                        ];
1024
-                        break;
1025
-                    case 'zip':
1026
-                        $QST_values = [
1027
-                            'QST_display_text'  => esc_html__('Zip/Postal Code', 'event_espresso'),
1028
-                            'QST_admin_label'   => esc_html__('Zip/Postal Code - System Question', 'event_espresso'),
1029
-                            'QST_system'        => 'zip',
1030
-                            'QST_type'          => 'TEXT',
1031
-                            'QST_required'      => 0,
1032
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1033
-                            'QST_order'         => 10,
1034
-                            'QST_admin_only'    => 0,
1035
-                            'QST_max'           => EEM_Question::instance()
1036
-                                                               ->absolute_max_for_system_question($QST_system),
1037
-                            'QST_wp_user'       => self::get_default_creator_id(),
1038
-                            'QST_deleted'       => 0,
1039
-                        ];
1040
-                        break;
1041
-                    case 'phone':
1042
-                        $QST_values = [
1043
-                            'QST_display_text'  => esc_html__('Phone Number', 'event_espresso'),
1044
-                            'QST_admin_label'   => esc_html__('Phone Number - System Question', 'event_espresso'),
1045
-                            'QST_system'        => 'phone',
1046
-                            'QST_type'          => 'TEXT',
1047
-                            'QST_required'      => 0,
1048
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1049
-                            'QST_order'         => 11,
1050
-                            'QST_admin_only'    => 0,
1051
-                            'QST_max'           => EEM_Question::instance()
1052
-                                                               ->absolute_max_for_system_question($QST_system),
1053
-                            'QST_wp_user'       => self::get_default_creator_id(),
1054
-                            'QST_deleted'       => 0,
1055
-                        ];
1056
-                        break;
1057
-                }
1058
-                if (! empty($QST_values)) {
1059
-                    // insert system question
1060
-                    $wpdb->insert(
1061
-                        $table_name,
1062
-                        $QST_values,
1063
-                        ['%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d']
1064
-                    );
1065
-                    $QST_ID = $wpdb->insert_id;
1066
-
1067
-                    // QUESTION GROUP QUESTIONS
1068
-                    if (in_array($QST_system, $personal_system_group_questions)) {
1069
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1070
-                    } elseif (in_array($QST_system, $address_system_group_questions)) {
1071
-                        $system_question_we_want = EEM_Question_Group::system_address;
1072
-                    } else {
1073
-                        // QST_system should not be assigned to any group
1074
-                        continue;
1075
-                    }
1076
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1077
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1078
-                    } else {
1079
-                        $id_col = EEM_Question_Group::instance()
1080
-                                                    ->get_col([['QSG_system' => $system_question_we_want]]);
1081
-                        if (is_array($id_col)) {
1082
-                            $QSG_ID = reset($id_col);
1083
-                        } else {
1084
-                            // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1085
-                            EE_Log::instance()->log(
1086
-                                __FILE__,
1087
-                                __FUNCTION__,
1088
-                                sprintf(
1089
-                                    esc_html__(
1090
-                                        'Could not associate question %1$s to a question group because no system question
786
+						'event_espresso'
787
+					)
788
+				);
789
+			}
790
+			return false;
791
+		}
792
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to();
793
+		return true;
794
+	}
795
+
796
+
797
+	/**
798
+	 * @return void
799
+	 * @throws EE_Error
800
+	 * @throws ReflectionException
801
+	 */
802
+	public static function initialize_system_questions()
803
+	{
804
+		// QUESTION GROUPS
805
+		global $wpdb;
806
+		$table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
807
+		$SQL        = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
808
+		// what we have
809
+		$question_groups = $wpdb->get_col($SQL);
810
+		// check the response
811
+		$question_groups = is_array($question_groups) ? $question_groups : [];
812
+		// what we should have
813
+		$QSG_systems = [1, 2];
814
+		// loop thru what we should have and compare to what we have
815
+		foreach ($QSG_systems as $QSG_system) {
816
+			// reset values array
817
+			$QSG_values = [];
818
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
819
+			if (! in_array("$QSG_system", $question_groups)) {
820
+				// add it
821
+				switch ($QSG_system) {
822
+					case 1:
823
+						$QSG_values = [
824
+							'QSG_name'            => esc_html__('Personal Information', 'event_espresso'),
825
+							'QSG_identifier'      => 'personal-information-' . time(),
826
+							'QSG_desc'            => '',
827
+							'QSG_order'           => 1,
828
+							'QSG_show_group_name' => 1,
829
+							'QSG_show_group_desc' => 1,
830
+							'QSG_system'          => EEM_Question_Group::system_personal,
831
+							'QSG_deleted'         => 0,
832
+						];
833
+						break;
834
+					case 2:
835
+						$QSG_values = [
836
+							'QSG_name'            => esc_html__('Address Information', 'event_espresso'),
837
+							'QSG_identifier'      => 'address-information-' . time(),
838
+							'QSG_desc'            => '',
839
+							'QSG_order'           => 2,
840
+							'QSG_show_group_name' => 1,
841
+							'QSG_show_group_desc' => 1,
842
+							'QSG_system'          => EEM_Question_Group::system_address,
843
+							'QSG_deleted'         => 0,
844
+						];
845
+						break;
846
+				}
847
+				// make sure we have some values before inserting them
848
+				if (! empty($QSG_values)) {
849
+					// insert system question
850
+					$wpdb->insert(
851
+						$table_name,
852
+						$QSG_values,
853
+						['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d']
854
+					);
855
+					$QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
856
+				}
857
+			}
858
+		}
859
+		// QUESTIONS
860
+		global $wpdb;
861
+		$table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
862
+		$SQL        = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
863
+		// what we have
864
+		$questions = $wpdb->get_col($SQL);
865
+		// all system questions
866
+		$personal_system_group_questions = ['fname', 'lname', 'email'];
867
+		$address_system_group_questions  = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
868
+		$system_questions_not_in_group   = ['email_confirm'];
869
+		// merge all of the system questions we should have
870
+		$QST_systems       = array_merge(
871
+			$personal_system_group_questions,
872
+			$address_system_group_questions,
873
+			$system_questions_not_in_group
874
+		);
875
+		$order_for_group_1 = 1;
876
+		$order_for_group_2 = 1;
877
+		// loop thru what we should have and compare to what we have
878
+		foreach ($QST_systems as $QST_system) {
879
+			// reset values array
880
+			$QST_values = [];
881
+			// if we don't have what we should have
882
+			if (! in_array($QST_system, $questions)) {
883
+				// add it
884
+				switch ($QST_system) {
885
+					case 'fname':
886
+						$QST_values = [
887
+							'QST_display_text'  => esc_html__('First Name', 'event_espresso'),
888
+							'QST_admin_label'   => esc_html__('First Name - System Question', 'event_espresso'),
889
+							'QST_system'        => 'fname',
890
+							'QST_type'          => 'TEXT',
891
+							'QST_required'      => 1,
892
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
893
+							'QST_order'         => 1,
894
+							'QST_admin_only'    => 0,
895
+							'QST_max'           => EEM_Question::instance()
896
+															   ->absolute_max_for_system_question($QST_system),
897
+							'QST_wp_user'       => self::get_default_creator_id(),
898
+							'QST_deleted'       => 0,
899
+						];
900
+						break;
901
+					case 'lname':
902
+						$QST_values = [
903
+							'QST_display_text'  => esc_html__('Last Name', 'event_espresso'),
904
+							'QST_admin_label'   => esc_html__('Last Name - System Question', 'event_espresso'),
905
+							'QST_system'        => 'lname',
906
+							'QST_type'          => 'TEXT',
907
+							'QST_required'      => 1,
908
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
909
+							'QST_order'         => 2,
910
+							'QST_admin_only'    => 0,
911
+							'QST_max'           => EEM_Question::instance()
912
+															   ->absolute_max_for_system_question($QST_system),
913
+							'QST_wp_user'       => self::get_default_creator_id(),
914
+							'QST_deleted'       => 0,
915
+						];
916
+						break;
917
+					case 'email':
918
+						$QST_values = [
919
+							'QST_display_text'  => esc_html__('Email Address', 'event_espresso'),
920
+							'QST_admin_label'   => esc_html__('Email Address - System Question', 'event_espresso'),
921
+							'QST_system'        => 'email',
922
+							'QST_type'          => 'EMAIL',
923
+							'QST_required'      => 1,
924
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
925
+							'QST_order'         => 3,
926
+							'QST_admin_only'    => 0,
927
+							'QST_max'           => EEM_Question::instance()
928
+															   ->absolute_max_for_system_question($QST_system),
929
+							'QST_wp_user'       => self::get_default_creator_id(),
930
+							'QST_deleted'       => 0,
931
+						];
932
+						break;
933
+					case 'email_confirm':
934
+						$QST_values = [
935
+							'QST_display_text'  => esc_html__('Confirm Email Address', 'event_espresso'),
936
+							'QST_admin_label'   => esc_html__('Confirm Email Address - System Question', 'event_espresso'),
937
+							'QST_system'        => 'email_confirm',
938
+							'QST_type'          => 'EMAIL_CONFIRM',
939
+							'QST_required'      => 1,
940
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
941
+							'QST_order'         => 4,
942
+							'QST_admin_only'    => 0,
943
+							'QST_max'           => EEM_Question::instance()
944
+															   ->absolute_max_for_system_question($QST_system),
945
+							'QST_wp_user'       => self::get_default_creator_id(),
946
+							'QST_deleted'       => 0,
947
+						];
948
+						break;
949
+					case 'address':
950
+						$QST_values = [
951
+							'QST_display_text'  => esc_html__('Address', 'event_espresso'),
952
+							'QST_admin_label'   => esc_html__('Address - System Question', 'event_espresso'),
953
+							'QST_system'        => 'address',
954
+							'QST_type'          => 'TEXT',
955
+							'QST_required'      => 0,
956
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
957
+							'QST_order'         => 5,
958
+							'QST_admin_only'    => 0,
959
+							'QST_max'           => EEM_Question::instance()
960
+															   ->absolute_max_for_system_question($QST_system),
961
+							'QST_wp_user'       => self::get_default_creator_id(),
962
+							'QST_deleted'       => 0,
963
+						];
964
+						break;
965
+					case 'address2':
966
+						$QST_values = [
967
+							'QST_display_text'  => esc_html__('Address2', 'event_espresso'),
968
+							'QST_admin_label'   => esc_html__('Address2 - System Question', 'event_espresso'),
969
+							'QST_system'        => 'address2',
970
+							'QST_type'          => 'TEXT',
971
+							'QST_required'      => 0,
972
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
973
+							'QST_order'         => 6,
974
+							'QST_admin_only'    => 0,
975
+							'QST_max'           => EEM_Question::instance()
976
+															   ->absolute_max_for_system_question($QST_system),
977
+							'QST_wp_user'       => self::get_default_creator_id(),
978
+							'QST_deleted'       => 0,
979
+						];
980
+						break;
981
+					case 'city':
982
+						$QST_values = [
983
+							'QST_display_text'  => esc_html__('City', 'event_espresso'),
984
+							'QST_admin_label'   => esc_html__('City - System Question', 'event_espresso'),
985
+							'QST_system'        => 'city',
986
+							'QST_type'          => 'TEXT',
987
+							'QST_required'      => 0,
988
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
989
+							'QST_order'         => 7,
990
+							'QST_admin_only'    => 0,
991
+							'QST_max'           => EEM_Question::instance()
992
+															   ->absolute_max_for_system_question($QST_system),
993
+							'QST_wp_user'       => self::get_default_creator_id(),
994
+							'QST_deleted'       => 0,
995
+						];
996
+						break;
997
+					case 'country':
998
+						$QST_values = [
999
+							'QST_display_text'  => esc_html__('Country', 'event_espresso'),
1000
+							'QST_admin_label'   => esc_html__('Country - System Question', 'event_espresso'),
1001
+							'QST_system'        => 'country',
1002
+							'QST_type'          => 'COUNTRY',
1003
+							'QST_required'      => 0,
1004
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1005
+							'QST_order'         => 8,
1006
+							'QST_admin_only'    => 0,
1007
+							'QST_wp_user'       => self::get_default_creator_id(),
1008
+							'QST_deleted'       => 0,
1009
+						];
1010
+						break;
1011
+					case 'state':
1012
+						$QST_values = [
1013
+							'QST_display_text'  => esc_html__('State/Province', 'event_espresso'),
1014
+							'QST_admin_label'   => esc_html__('State/Province - System Question', 'event_espresso'),
1015
+							'QST_system'        => 'state',
1016
+							'QST_type'          => 'STATE',
1017
+							'QST_required'      => 0,
1018
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1019
+							'QST_order'         => 9,
1020
+							'QST_admin_only'    => 0,
1021
+							'QST_wp_user'       => self::get_default_creator_id(),
1022
+							'QST_deleted'       => 0,
1023
+						];
1024
+						break;
1025
+					case 'zip':
1026
+						$QST_values = [
1027
+							'QST_display_text'  => esc_html__('Zip/Postal Code', 'event_espresso'),
1028
+							'QST_admin_label'   => esc_html__('Zip/Postal Code - System Question', 'event_espresso'),
1029
+							'QST_system'        => 'zip',
1030
+							'QST_type'          => 'TEXT',
1031
+							'QST_required'      => 0,
1032
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1033
+							'QST_order'         => 10,
1034
+							'QST_admin_only'    => 0,
1035
+							'QST_max'           => EEM_Question::instance()
1036
+															   ->absolute_max_for_system_question($QST_system),
1037
+							'QST_wp_user'       => self::get_default_creator_id(),
1038
+							'QST_deleted'       => 0,
1039
+						];
1040
+						break;
1041
+					case 'phone':
1042
+						$QST_values = [
1043
+							'QST_display_text'  => esc_html__('Phone Number', 'event_espresso'),
1044
+							'QST_admin_label'   => esc_html__('Phone Number - System Question', 'event_espresso'),
1045
+							'QST_system'        => 'phone',
1046
+							'QST_type'          => 'TEXT',
1047
+							'QST_required'      => 0,
1048
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1049
+							'QST_order'         => 11,
1050
+							'QST_admin_only'    => 0,
1051
+							'QST_max'           => EEM_Question::instance()
1052
+															   ->absolute_max_for_system_question($QST_system),
1053
+							'QST_wp_user'       => self::get_default_creator_id(),
1054
+							'QST_deleted'       => 0,
1055
+						];
1056
+						break;
1057
+				}
1058
+				if (! empty($QST_values)) {
1059
+					// insert system question
1060
+					$wpdb->insert(
1061
+						$table_name,
1062
+						$QST_values,
1063
+						['%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d']
1064
+					);
1065
+					$QST_ID = $wpdb->insert_id;
1066
+
1067
+					// QUESTION GROUP QUESTIONS
1068
+					if (in_array($QST_system, $personal_system_group_questions)) {
1069
+						$system_question_we_want = EEM_Question_Group::system_personal;
1070
+					} elseif (in_array($QST_system, $address_system_group_questions)) {
1071
+						$system_question_we_want = EEM_Question_Group::system_address;
1072
+					} else {
1073
+						// QST_system should not be assigned to any group
1074
+						continue;
1075
+					}
1076
+					if (isset($QSG_IDs[ $system_question_we_want ])) {
1077
+						$QSG_ID = $QSG_IDs[ $system_question_we_want ];
1078
+					} else {
1079
+						$id_col = EEM_Question_Group::instance()
1080
+													->get_col([['QSG_system' => $system_question_we_want]]);
1081
+						if (is_array($id_col)) {
1082
+							$QSG_ID = reset($id_col);
1083
+						} else {
1084
+							// ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1085
+							EE_Log::instance()->log(
1086
+								__FILE__,
1087
+								__FUNCTION__,
1088
+								sprintf(
1089
+									esc_html__(
1090
+										'Could not associate question %1$s to a question group because no system question
1091 1091
                                          group existed',
1092
-                                        'event_espresso'
1093
-                                    ),
1094
-                                    $QST_ID
1095
-                                ),
1096
-                                'error'
1097
-                            );
1098
-                            continue;
1099
-                        }
1100
-                    }
1101
-                    // add system questions to groups
1102
-                    $wpdb->insert(
1103
-                        EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1104
-                        [
1105
-                            'QSG_ID'    => $QSG_ID,
1106
-                            'QST_ID'    => $QST_ID,
1107
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1108
-                        ],
1109
-                        ['%d', '%d', '%d']
1110
-                    );
1111
-                }
1112
-            }
1113
-        }
1114
-    }
1115
-
1116
-
1117
-    /**
1118
-     * Makes sure the default payment method (Invoice) is active.
1119
-     * This used to be done automatically as part of constructing the old gateways config
1120
-     *
1121
-     * @throws EE_Error
1122
-     * @throws ReflectionException
1123
-     */
1124
-    public static function insert_default_payment_methods()
1125
-    {
1126
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1127
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1128
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1129
-        } else {
1130
-            EEM_Payment_Method::instance()->verify_button_urls();
1131
-        }
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * @return void
1137
-     * @throws EE_Error
1138
-     * @throws ReflectionException
1139
-     */
1140
-    public static function insert_default_status_codes()
1141
-    {
1142
-
1143
-        global $wpdb;
1144
-
1145
-        if (EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1146
-            $table_name = EEM_Status::instance()->table();
1147
-
1148
-            $SQL =
1149
-                "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1150
-            $wpdb->query($SQL);
1151
-
1152
-            $SQL = "INSERT INTO $table_name
1092
+										'event_espresso'
1093
+									),
1094
+									$QST_ID
1095
+								),
1096
+								'error'
1097
+							);
1098
+							continue;
1099
+						}
1100
+					}
1101
+					// add system questions to groups
1102
+					$wpdb->insert(
1103
+						EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1104
+						[
1105
+							'QSG_ID'    => $QSG_ID,
1106
+							'QST_ID'    => $QST_ID,
1107
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1108
+						],
1109
+						['%d', '%d', '%d']
1110
+					);
1111
+				}
1112
+			}
1113
+		}
1114
+	}
1115
+
1116
+
1117
+	/**
1118
+	 * Makes sure the default payment method (Invoice) is active.
1119
+	 * This used to be done automatically as part of constructing the old gateways config
1120
+	 *
1121
+	 * @throws EE_Error
1122
+	 * @throws ReflectionException
1123
+	 */
1124
+	public static function insert_default_payment_methods()
1125
+	{
1126
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1127
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1128
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1129
+		} else {
1130
+			EEM_Payment_Method::instance()->verify_button_urls();
1131
+		}
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * @return void
1137
+	 * @throws EE_Error
1138
+	 * @throws ReflectionException
1139
+	 */
1140
+	public static function insert_default_status_codes()
1141
+	{
1142
+
1143
+		global $wpdb;
1144
+
1145
+		if (EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1146
+			$table_name = EEM_Status::instance()->table();
1147
+
1148
+			$SQL =
1149
+				"DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1150
+			$wpdb->query($SQL);
1151
+
1152
+			$SQL = "INSERT INTO $table_name
1153 1153
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1154 1154
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1155 1155
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1189,480 +1189,480 @@  discard block
 block discarded – undo
1189 1189
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1190 1190
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1191 1191
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1192
-            $wpdb->query($SQL);
1193
-        }
1194
-    }
1195
-
1196
-
1197
-    /**
1198
-     * @return bool     true means new templates were created.
1199
-     *                  false means no templates were created.
1200
-     *                  This is NOT an error flag. To check for errors you will want
1201
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1202
-     * @throws EE_Error
1203
-     * @throws ReflectionException
1204
-     */
1205
-    public static function generate_default_message_templates()
1206
-    {
1207
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1208
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1209
-        /*
1192
+			$wpdb->query($SQL);
1193
+		}
1194
+	}
1195
+
1196
+
1197
+	/**
1198
+	 * @return bool     true means new templates were created.
1199
+	 *                  false means no templates were created.
1200
+	 *                  This is NOT an error flag. To check for errors you will want
1201
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1202
+	 * @throws EE_Error
1203
+	 * @throws ReflectionException
1204
+	 */
1205
+	public static function generate_default_message_templates()
1206
+	{
1207
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1208
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1209
+		/*
1210 1210
          * This first method is taking care of ensuring any default messengers
1211 1211
          * that should be made active and have templates generated are done.
1212 1212
          */
1213
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1214
-            $message_resource_manager
1215
-        );
1216
-        /**
1217
-         * This method is verifying there are no NEW default message types
1218
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1219
-         */
1220
-        $new_templates_created_for_message_type =
1221
-            self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1222
-                $message_resource_manager
1223
-            );
1224
-        // after all is done, let's persist these changes to the db.
1225
-        $message_resource_manager->update_has_activated_messengers_option();
1226
-        $message_resource_manager->update_active_messengers_option();
1227
-        // will return true if either of these are true.  Otherwise will return false.
1228
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1229
-    }
1230
-
1231
-
1232
-    /**
1233
-     * @param EE_Message_Resource_Manager $message_resource_manager
1234
-     * @return array|bool
1235
-     * @throws EE_Error
1236
-     * @throws ReflectionException
1237
-     */
1238
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1239
-        EE_Message_Resource_Manager $message_resource_manager
1240
-    ) {
1241
-        $active_messengers       = $message_resource_manager->active_messengers();
1242
-        $installed_message_types = $message_resource_manager->installed_message_types();
1243
-        $templates_created       = false;
1244
-        foreach ($active_messengers as $active_messenger) {
1245
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1246
-            $default_message_type_names_to_activate   = [];
1247
-            // looping through each default message type reported by the messenger
1248
-            // and setup the actual message types to activate.
1249
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1250
-                // if already active or has already been activated before we skip
1251
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1252
-                // we also skip if the message type is not installed.
1253
-                if (
1254
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1255
-                        $default_message_type_name_for_messenger,
1256
-                        $active_messenger->name
1257
-                    )
1258
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1259
-                        $active_messenger->name,
1260
-                        $default_message_type_name_for_messenger
1261
-                    )
1262
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1263
-                ) {
1264
-                    continue;
1265
-                }
1266
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1267
-            }
1268
-            // let's activate!
1269
-            $message_resource_manager->ensure_message_types_are_active(
1270
-                $default_message_type_names_to_activate,
1271
-                $active_messenger->name,
1272
-                false
1273
-            );
1274
-            // activate the templates for these message types
1275
-            if (! empty($default_message_type_names_to_activate)) {
1276
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1277
-                    $active_messenger->name,
1278
-                    $default_message_type_names_for_messenger,
1279
-                    '',
1280
-                    true
1281
-                );
1282
-            }
1283
-        }
1284
-        return $templates_created;
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * This will activate and generate default messengers and default message types for those messengers.
1290
-     *
1291
-     * @param EE_message_Resource_Manager $message_resource_manager
1292
-     * @return array|bool  True means there were default messengers and message type templates generated.
1293
-     *                     False means that there were no templates generated
1294
-     *                     (which could simply mean there are no default message types for a messenger).
1295
-     * @throws EE_Error
1296
-     * @throws ReflectionException
1297
-     */
1298
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1299
-        EE_Message_Resource_Manager $message_resource_manager
1300
-    ) {
1301
-        $messengers_to_generate  = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1302
-        $installed_message_types = $message_resource_manager->installed_message_types();
1303
-        $templates_generated     = false;
1304
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1305
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1306
-            // verify the default message types match an installed message type.
1307
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1308
-                if (
1309
-                    ! isset($installed_message_types[ $name ])
1310
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1311
-                        $name,
1312
-                        $messenger_to_generate->name
1313
-                    )
1314
-                ) {
1315
-                    unset($default_message_type_names_for_messenger[ $key ]);
1316
-                }
1317
-            }
1318
-            // in previous iterations, the active_messengers option in the db
1319
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1320
-            // This comment is left here just in case we discover that we _do_ need to update before
1321
-            // passing off to create templates (after the refactor is done).
1322
-            // @todo remove this comment when determined not necessary.
1323
-            $message_resource_manager->activate_messenger(
1324
-                $messenger_to_generate,
1325
-                $default_message_type_names_for_messenger,
1326
-                false
1327
-            );
1328
-            // create any templates needing created (or will reactivate templates already generated as necessary).
1329
-            if (! empty($default_message_type_names_for_messenger)) {
1330
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1331
-                    $messenger_to_generate->name,
1332
-                    $default_message_type_names_for_messenger,
1333
-                    '',
1334
-                    true
1335
-                );
1336
-            }
1337
-        }
1338
-        return $templates_generated;
1339
-    }
1340
-
1341
-
1342
-    /**
1343
-     * This returns the default messengers to generate templates for on activation of EE.
1344
-     * It considers:
1345
-     * - whether a messenger is already active in the db.
1346
-     * - whether a messenger has been made active at any time in the past.
1347
-     *
1348
-     * @param EE_Message_Resource_Manager $message_resource_manager
1349
-     * @return EE_messenger[]
1350
-     */
1351
-    protected static function _get_default_messengers_to_generate_on_activation(
1352
-        EE_Message_Resource_Manager $message_resource_manager
1353
-    ) {
1354
-        $active_messengers    = $message_resource_manager->active_messengers();
1355
-        $installed_messengers = $message_resource_manager->installed_messengers();
1356
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1357
-
1358
-        $messengers_to_generate = [];
1359
-        foreach ($installed_messengers as $installed_messenger) {
1360
-            // if installed messenger is a messenger that should be activated on install
1361
-            // and is not already active
1362
-            // and has never been activated
1363
-            if (
1364
-                ! $installed_messenger->activate_on_install
1365
-                || isset($active_messengers[ $installed_messenger->name ])
1366
-                || isset($has_activated[ $installed_messenger->name ])
1367
-            ) {
1368
-                continue;
1369
-            }
1370
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1371
-        }
1372
-        return $messengers_to_generate;
1373
-    }
1374
-
1375
-
1376
-    /**
1377
-     * This simply validates active message types to ensure they actually match installed
1378
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1379
-     * rows are set inactive.
1380
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1381
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1382
-     * are still handled in here.
1383
-     *
1384
-     * @return void
1385
-     * @throws EE_Error
1386
-     * @throws ReflectionException
1387
-     * @since 4.3.1
1388
-     */
1389
-    public static function validate_messages_system()
1390
-    {
1391
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1392
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1393
-        $message_resource_manager->validate_active_message_types_are_installed();
1394
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1395
-    }
1396
-
1397
-
1398
-    /**
1399
-     * @return void
1400
-     */
1401
-    public static function create_no_ticket_prices_array()
1402
-    {
1403
-        // this creates an array for tracking events that have no active ticket prices created
1404
-        // this allows us to warn admins of the situation so that it can be corrected
1405
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1406
-        if (! $espresso_no_ticket_prices) {
1407
-            add_option('ee_no_ticket_prices', [], '', false);
1408
-        }
1409
-    }
1410
-
1411
-
1412
-    /**
1413
-     * @return void
1414
-     */
1415
-    public static function plugin_deactivation()
1416
-    {
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1422
-     * (like post meta or term relations)
1423
-     *
1424
-     * @throws EE_Error
1425
-     * @global wpdb $wpdb
1426
-     */
1427
-    public static function delete_all_espresso_cpt_data()
1428
-    {
1429
-        global $wpdb;
1430
-        // get all the CPT post_types
1431
-        $ee_post_types = [];
1432
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1433
-            if (method_exists($model_name, 'instance')) {
1434
-                $model_obj = call_user_func([$model_name, 'instance']);
1435
-                if ($model_obj instanceof EEM_CPT_Base) {
1436
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1437
-                }
1438
-            }
1439
-        }
1440
-        // get all our CPTs
1441
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1442
-        $cpt_ids = $wpdb->get_col($query);
1443
-        // delete each post meta and term relations too
1444
-        foreach ($cpt_ids as $post_id) {
1445
-            wp_delete_post($post_id, true);
1446
-        }
1447
-    }
1448
-
1449
-
1450
-    /**
1451
-     * Deletes all EE custom tables
1452
-     *
1453
-     * @return array
1454
-     * @throws EE_Error
1455
-     * @throws ReflectionException
1456
-     */
1457
-    public static function drop_espresso_tables()
1458
-    {
1459
-        $tables = [];
1460
-        // load registry
1461
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1462
-            if (method_exists($model_name, 'instance')) {
1463
-                $model_obj = call_user_func([$model_name, 'instance']);
1464
-                if ($model_obj instanceof EEM_Base) {
1465
-                    foreach ($model_obj->get_tables() as $table) {
1466
-                        if (
1467
-                            strpos($table->get_table_name(), 'esp_')
1468
-                            && (
1469
-                                is_main_site()// main site? nuke them all
1470
-                                || ! $table->is_global()// not main site,but not global either. nuke it
1471
-                            )
1472
-                        ) {
1473
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1474
-                        }
1475
-                    }
1476
-                }
1477
-            }
1478
-        }
1479
-
1480
-        // there are some tables whose models were removed.
1481
-        // they should be removed when removing all EE core's data
1482
-        $tables_without_models = [
1483
-            'esp_promotion',
1484
-            'esp_promotion_applied',
1485
-            'esp_promotion_object',
1486
-            'esp_promotion_rule',
1487
-            'esp_rule',
1488
-        ];
1489
-        foreach ($tables_without_models as $table) {
1490
-            $tables[ $table ] = $table;
1491
-        }
1492
-        return EEH_Activation::getTableManager()->dropTables($tables);
1493
-    }
1494
-
1495
-
1496
-    /**
1497
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1498
-     * each table name provided has a wpdb prefix attached, and that it exists.
1499
-     * Returns the list actually deleted
1500
-     *
1501
-     * @param array $table_names
1502
-     * @return array of table names which we deleted
1503
-     * @throws EE_Error
1504
-     * @throws ReflectionException
1505
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1506
-     * @global WPDB $wpdb
1507
-     */
1508
-    public static function drop_tables($table_names)
1509
-    {
1510
-        return EEH_Activation::getTableManager()->dropTables($table_names);
1511
-    }
1512
-
1513
-
1514
-    /**
1515
-     * plugin_uninstall
1516
-     *
1517
-     * @param bool $remove_all
1518
-     * @return void
1519
-     * @throws EE_Error
1520
-     * @throws ReflectionException
1521
-     */
1522
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1523
-    {
1524
-        global $wpdb;
1525
-        self::drop_espresso_tables();
1526
-        $wp_options_to_delete = [
1527
-            'ee_no_ticket_prices'                        => true,
1528
-            'ee_active_messengers'                       => true,
1529
-            'ee_has_activated_messenger'                 => true,
1530
-            RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1531
-            'ee_config'                                  => false,
1532
-            'ee_data_migration_current_db_state'         => true,
1533
-            'ee_data_migration_mapping_'                 => false,
1534
-            'ee_data_migration_script_'                  => false,
1535
-            'ee_data_migrations'                         => true,
1536
-            'ee_dms_map'                                 => false,
1537
-            'ee_notices'                                 => true,
1538
-            'lang_file_check_'                           => false,
1539
-            'ee_maintenance_mode'                        => true,
1540
-            'ee_ueip_optin'                              => true,
1541
-            'ee_ueip_has_notified'                       => true,
1542
-            'ee_plugin_activation_errors'                => true,
1543
-            'ee_id_mapping_from'                         => false,
1544
-            'espresso_persistent_admin_notices'          => true,
1545
-            'ee_encryption_key'                          => true,
1546
-            'pue_force_upgrade_'                         => false,
1547
-            'pue_json_error_'                            => false,
1548
-            'pue_install_key_'                           => false,
1549
-            'pue_verification_error_'                    => false,
1550
-            'pu_dismissed_upgrade_'                      => false,
1551
-            'external_updates-'                          => false,
1552
-            'ee_extra_data'                              => true,
1553
-            'ee_ssn_'                                    => false,
1554
-            'ee_rss_'                                    => false,
1555
-            'ee_rte_n_tx_'                               => false,
1556
-            'ee_pers_admin_notices'                      => true,
1557
-            'ee_job_parameters_'                         => false,
1558
-            'ee_upload_directories_incomplete'           => true,
1559
-            'ee_verified_db_collations'                  => true,
1560
-        ];
1561
-        if (is_main_site()) {
1562
-            $wp_options_to_delete['ee_network_config'] = true;
1563
-        }
1564
-        $undeleted_options = [];
1565
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1566
-            if ($no_wildcard) {
1567
-                if (! delete_option($option_name)) {
1568
-                    $undeleted_options[] = $option_name;
1569
-                }
1570
-            } else {
1571
-                $option_names_to_delete_from_wildcard =
1572
-                    $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1573
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1574
-                    if (! delete_option($option_name_from_wildcard)) {
1575
-                        $undeleted_options[] = $option_name_from_wildcard;
1576
-                    }
1577
-                }
1578
-            }
1579
-        }
1580
-        // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1581
-        remove_action('shutdown', [EE_Config::instance(), 'shutdown']);
1582
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1583
-            $db_update_sans_ee4 = [];
1584
-            foreach ($espresso_db_update as $version => $times_activated) {
1585
-                if ((string) $version[0] === '3') {// if its NON EE4
1586
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1587
-                }
1588
-            }
1589
-            update_option('espresso_db_update', $db_update_sans_ee4);
1590
-        }
1591
-        $errors = '';
1592
-        if (! empty($undeleted_options)) {
1593
-            $errors .= sprintf(
1594
-                esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1595
-                '<br/>',
1596
-                implode(',<br/>', $undeleted_options)
1597
-            );
1598
-        }
1599
-        if (! empty($errors)) {
1600
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1601
-        }
1602
-    }
1603
-
1604
-
1605
-    /**
1606
-     * Gets the mysql error code from the last used query by wpdb
1607
-     *
1608
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1609
-     */
1610
-    public static function last_wpdb_error_code()
1611
-    {
1612
-        // phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
1613
-        global $wpdb;
1614
-        return $wpdb->use_mysqli ? mysqli_errno($wpdb->dbh) : mysql_errno($wpdb->dbh);
1615
-        // phpcs:enable
1616
-    }
1617
-
1618
-
1619
-    /**
1620
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1621
-     *
1622
-     * @param string $table_name with or without $wpdb->prefix
1623
-     * @return boolean
1624
-     * @throws EE_Error
1625
-     * @throws ReflectionException
1626
-     * @global wpdb  $wpdb
1627
-     * @deprecated instead use TableAnalysis::tableExists()
1628
-     */
1629
-    public static function table_exists($table_name)
1630
-    {
1631
-        return EEH_Activation::getTableAnalysis()->tableExists($table_name);
1632
-    }
1633
-
1634
-
1635
-    /**
1636
-     * Resets the cache on EEH_Activation
1637
-     */
1638
-    public static function reset()
1639
-    {
1640
-        self::$_default_creator_id                             = null;
1641
-        self::$_initialized_db_content_already_in_this_request = false;
1642
-    }
1643
-
1644
-
1645
-    /**
1646
-     * Removes 'email_confirm' from the Address info question group on activation
1647
-     *
1648
-     * @return void
1649
-     * @throws EE_Error
1650
-     */
1651
-    public static function removeEmailConfirmFromAddressGroup()
1652
-    {
1653
-
1654
-        // Pull the email_confirm question ID.
1655
-        $email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
1656
-            EEM_Attendee::system_question_email_confirm
1657
-        );
1658
-        // Remove the email_confirm question group from the address group questions.
1659
-        EEM_Question_Group_Question::instance()->delete(
1660
-            [
1661
-                [
1662
-                    'QST_ID'                    => $email_confirm_question_id,
1663
-                    'Question_Group.QSG_system' => EEM_Question_Group::system_address,
1664
-                ],
1665
-            ]
1666
-        );
1667
-    }
1213
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1214
+			$message_resource_manager
1215
+		);
1216
+		/**
1217
+		 * This method is verifying there are no NEW default message types
1218
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1219
+		 */
1220
+		$new_templates_created_for_message_type =
1221
+			self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1222
+				$message_resource_manager
1223
+			);
1224
+		// after all is done, let's persist these changes to the db.
1225
+		$message_resource_manager->update_has_activated_messengers_option();
1226
+		$message_resource_manager->update_active_messengers_option();
1227
+		// will return true if either of these are true.  Otherwise will return false.
1228
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1229
+	}
1230
+
1231
+
1232
+	/**
1233
+	 * @param EE_Message_Resource_Manager $message_resource_manager
1234
+	 * @return array|bool
1235
+	 * @throws EE_Error
1236
+	 * @throws ReflectionException
1237
+	 */
1238
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1239
+		EE_Message_Resource_Manager $message_resource_manager
1240
+	) {
1241
+		$active_messengers       = $message_resource_manager->active_messengers();
1242
+		$installed_message_types = $message_resource_manager->installed_message_types();
1243
+		$templates_created       = false;
1244
+		foreach ($active_messengers as $active_messenger) {
1245
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1246
+			$default_message_type_names_to_activate   = [];
1247
+			// looping through each default message type reported by the messenger
1248
+			// and setup the actual message types to activate.
1249
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1250
+				// if already active or has already been activated before we skip
1251
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1252
+				// we also skip if the message type is not installed.
1253
+				if (
1254
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1255
+						$default_message_type_name_for_messenger,
1256
+						$active_messenger->name
1257
+					)
1258
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1259
+						$active_messenger->name,
1260
+						$default_message_type_name_for_messenger
1261
+					)
1262
+					|| ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1263
+				) {
1264
+					continue;
1265
+				}
1266
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1267
+			}
1268
+			// let's activate!
1269
+			$message_resource_manager->ensure_message_types_are_active(
1270
+				$default_message_type_names_to_activate,
1271
+				$active_messenger->name,
1272
+				false
1273
+			);
1274
+			// activate the templates for these message types
1275
+			if (! empty($default_message_type_names_to_activate)) {
1276
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1277
+					$active_messenger->name,
1278
+					$default_message_type_names_for_messenger,
1279
+					'',
1280
+					true
1281
+				);
1282
+			}
1283
+		}
1284
+		return $templates_created;
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * This will activate and generate default messengers and default message types for those messengers.
1290
+	 *
1291
+	 * @param EE_message_Resource_Manager $message_resource_manager
1292
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1293
+	 *                     False means that there were no templates generated
1294
+	 *                     (which could simply mean there are no default message types for a messenger).
1295
+	 * @throws EE_Error
1296
+	 * @throws ReflectionException
1297
+	 */
1298
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1299
+		EE_Message_Resource_Manager $message_resource_manager
1300
+	) {
1301
+		$messengers_to_generate  = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1302
+		$installed_message_types = $message_resource_manager->installed_message_types();
1303
+		$templates_generated     = false;
1304
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1305
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1306
+			// verify the default message types match an installed message type.
1307
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1308
+				if (
1309
+					! isset($installed_message_types[ $name ])
1310
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1311
+						$name,
1312
+						$messenger_to_generate->name
1313
+					)
1314
+				) {
1315
+					unset($default_message_type_names_for_messenger[ $key ]);
1316
+				}
1317
+			}
1318
+			// in previous iterations, the active_messengers option in the db
1319
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1320
+			// This comment is left here just in case we discover that we _do_ need to update before
1321
+			// passing off to create templates (after the refactor is done).
1322
+			// @todo remove this comment when determined not necessary.
1323
+			$message_resource_manager->activate_messenger(
1324
+				$messenger_to_generate,
1325
+				$default_message_type_names_for_messenger,
1326
+				false
1327
+			);
1328
+			// create any templates needing created (or will reactivate templates already generated as necessary).
1329
+			if (! empty($default_message_type_names_for_messenger)) {
1330
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1331
+					$messenger_to_generate->name,
1332
+					$default_message_type_names_for_messenger,
1333
+					'',
1334
+					true
1335
+				);
1336
+			}
1337
+		}
1338
+		return $templates_generated;
1339
+	}
1340
+
1341
+
1342
+	/**
1343
+	 * This returns the default messengers to generate templates for on activation of EE.
1344
+	 * It considers:
1345
+	 * - whether a messenger is already active in the db.
1346
+	 * - whether a messenger has been made active at any time in the past.
1347
+	 *
1348
+	 * @param EE_Message_Resource_Manager $message_resource_manager
1349
+	 * @return EE_messenger[]
1350
+	 */
1351
+	protected static function _get_default_messengers_to_generate_on_activation(
1352
+		EE_Message_Resource_Manager $message_resource_manager
1353
+	) {
1354
+		$active_messengers    = $message_resource_manager->active_messengers();
1355
+		$installed_messengers = $message_resource_manager->installed_messengers();
1356
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1357
+
1358
+		$messengers_to_generate = [];
1359
+		foreach ($installed_messengers as $installed_messenger) {
1360
+			// if installed messenger is a messenger that should be activated on install
1361
+			// and is not already active
1362
+			// and has never been activated
1363
+			if (
1364
+				! $installed_messenger->activate_on_install
1365
+				|| isset($active_messengers[ $installed_messenger->name ])
1366
+				|| isset($has_activated[ $installed_messenger->name ])
1367
+			) {
1368
+				continue;
1369
+			}
1370
+			$messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1371
+		}
1372
+		return $messengers_to_generate;
1373
+	}
1374
+
1375
+
1376
+	/**
1377
+	 * This simply validates active message types to ensure they actually match installed
1378
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1379
+	 * rows are set inactive.
1380
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1381
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1382
+	 * are still handled in here.
1383
+	 *
1384
+	 * @return void
1385
+	 * @throws EE_Error
1386
+	 * @throws ReflectionException
1387
+	 * @since 4.3.1
1388
+	 */
1389
+	public static function validate_messages_system()
1390
+	{
1391
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1392
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1393
+		$message_resource_manager->validate_active_message_types_are_installed();
1394
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1395
+	}
1396
+
1397
+
1398
+	/**
1399
+	 * @return void
1400
+	 */
1401
+	public static function create_no_ticket_prices_array()
1402
+	{
1403
+		// this creates an array for tracking events that have no active ticket prices created
1404
+		// this allows us to warn admins of the situation so that it can be corrected
1405
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1406
+		if (! $espresso_no_ticket_prices) {
1407
+			add_option('ee_no_ticket_prices', [], '', false);
1408
+		}
1409
+	}
1410
+
1411
+
1412
+	/**
1413
+	 * @return void
1414
+	 */
1415
+	public static function plugin_deactivation()
1416
+	{
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1422
+	 * (like post meta or term relations)
1423
+	 *
1424
+	 * @throws EE_Error
1425
+	 * @global wpdb $wpdb
1426
+	 */
1427
+	public static function delete_all_espresso_cpt_data()
1428
+	{
1429
+		global $wpdb;
1430
+		// get all the CPT post_types
1431
+		$ee_post_types = [];
1432
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1433
+			if (method_exists($model_name, 'instance')) {
1434
+				$model_obj = call_user_func([$model_name, 'instance']);
1435
+				if ($model_obj instanceof EEM_CPT_Base) {
1436
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1437
+				}
1438
+			}
1439
+		}
1440
+		// get all our CPTs
1441
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1442
+		$cpt_ids = $wpdb->get_col($query);
1443
+		// delete each post meta and term relations too
1444
+		foreach ($cpt_ids as $post_id) {
1445
+			wp_delete_post($post_id, true);
1446
+		}
1447
+	}
1448
+
1449
+
1450
+	/**
1451
+	 * Deletes all EE custom tables
1452
+	 *
1453
+	 * @return array
1454
+	 * @throws EE_Error
1455
+	 * @throws ReflectionException
1456
+	 */
1457
+	public static function drop_espresso_tables()
1458
+	{
1459
+		$tables = [];
1460
+		// load registry
1461
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1462
+			if (method_exists($model_name, 'instance')) {
1463
+				$model_obj = call_user_func([$model_name, 'instance']);
1464
+				if ($model_obj instanceof EEM_Base) {
1465
+					foreach ($model_obj->get_tables() as $table) {
1466
+						if (
1467
+							strpos($table->get_table_name(), 'esp_')
1468
+							&& (
1469
+								is_main_site()// main site? nuke them all
1470
+								|| ! $table->is_global()// not main site,but not global either. nuke it
1471
+							)
1472
+						) {
1473
+							$tables[ $table->get_table_name() ] = $table->get_table_name();
1474
+						}
1475
+					}
1476
+				}
1477
+			}
1478
+		}
1479
+
1480
+		// there are some tables whose models were removed.
1481
+		// they should be removed when removing all EE core's data
1482
+		$tables_without_models = [
1483
+			'esp_promotion',
1484
+			'esp_promotion_applied',
1485
+			'esp_promotion_object',
1486
+			'esp_promotion_rule',
1487
+			'esp_rule',
1488
+		];
1489
+		foreach ($tables_without_models as $table) {
1490
+			$tables[ $table ] = $table;
1491
+		}
1492
+		return EEH_Activation::getTableManager()->dropTables($tables);
1493
+	}
1494
+
1495
+
1496
+	/**
1497
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1498
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1499
+	 * Returns the list actually deleted
1500
+	 *
1501
+	 * @param array $table_names
1502
+	 * @return array of table names which we deleted
1503
+	 * @throws EE_Error
1504
+	 * @throws ReflectionException
1505
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1506
+	 * @global WPDB $wpdb
1507
+	 */
1508
+	public static function drop_tables($table_names)
1509
+	{
1510
+		return EEH_Activation::getTableManager()->dropTables($table_names);
1511
+	}
1512
+
1513
+
1514
+	/**
1515
+	 * plugin_uninstall
1516
+	 *
1517
+	 * @param bool $remove_all
1518
+	 * @return void
1519
+	 * @throws EE_Error
1520
+	 * @throws ReflectionException
1521
+	 */
1522
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1523
+	{
1524
+		global $wpdb;
1525
+		self::drop_espresso_tables();
1526
+		$wp_options_to_delete = [
1527
+			'ee_no_ticket_prices'                        => true,
1528
+			'ee_active_messengers'                       => true,
1529
+			'ee_has_activated_messenger'                 => true,
1530
+			RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1531
+			'ee_config'                                  => false,
1532
+			'ee_data_migration_current_db_state'         => true,
1533
+			'ee_data_migration_mapping_'                 => false,
1534
+			'ee_data_migration_script_'                  => false,
1535
+			'ee_data_migrations'                         => true,
1536
+			'ee_dms_map'                                 => false,
1537
+			'ee_notices'                                 => true,
1538
+			'lang_file_check_'                           => false,
1539
+			'ee_maintenance_mode'                        => true,
1540
+			'ee_ueip_optin'                              => true,
1541
+			'ee_ueip_has_notified'                       => true,
1542
+			'ee_plugin_activation_errors'                => true,
1543
+			'ee_id_mapping_from'                         => false,
1544
+			'espresso_persistent_admin_notices'          => true,
1545
+			'ee_encryption_key'                          => true,
1546
+			'pue_force_upgrade_'                         => false,
1547
+			'pue_json_error_'                            => false,
1548
+			'pue_install_key_'                           => false,
1549
+			'pue_verification_error_'                    => false,
1550
+			'pu_dismissed_upgrade_'                      => false,
1551
+			'external_updates-'                          => false,
1552
+			'ee_extra_data'                              => true,
1553
+			'ee_ssn_'                                    => false,
1554
+			'ee_rss_'                                    => false,
1555
+			'ee_rte_n_tx_'                               => false,
1556
+			'ee_pers_admin_notices'                      => true,
1557
+			'ee_job_parameters_'                         => false,
1558
+			'ee_upload_directories_incomplete'           => true,
1559
+			'ee_verified_db_collations'                  => true,
1560
+		];
1561
+		if (is_main_site()) {
1562
+			$wp_options_to_delete['ee_network_config'] = true;
1563
+		}
1564
+		$undeleted_options = [];
1565
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1566
+			if ($no_wildcard) {
1567
+				if (! delete_option($option_name)) {
1568
+					$undeleted_options[] = $option_name;
1569
+				}
1570
+			} else {
1571
+				$option_names_to_delete_from_wildcard =
1572
+					$wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1573
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1574
+					if (! delete_option($option_name_from_wildcard)) {
1575
+						$undeleted_options[] = $option_name_from_wildcard;
1576
+					}
1577
+				}
1578
+			}
1579
+		}
1580
+		// also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1581
+		remove_action('shutdown', [EE_Config::instance(), 'shutdown']);
1582
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1583
+			$db_update_sans_ee4 = [];
1584
+			foreach ($espresso_db_update as $version => $times_activated) {
1585
+				if ((string) $version[0] === '3') {// if its NON EE4
1586
+					$db_update_sans_ee4[ $version ] = $times_activated;
1587
+				}
1588
+			}
1589
+			update_option('espresso_db_update', $db_update_sans_ee4);
1590
+		}
1591
+		$errors = '';
1592
+		if (! empty($undeleted_options)) {
1593
+			$errors .= sprintf(
1594
+				esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1595
+				'<br/>',
1596
+				implode(',<br/>', $undeleted_options)
1597
+			);
1598
+		}
1599
+		if (! empty($errors)) {
1600
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1601
+		}
1602
+	}
1603
+
1604
+
1605
+	/**
1606
+	 * Gets the mysql error code from the last used query by wpdb
1607
+	 *
1608
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1609
+	 */
1610
+	public static function last_wpdb_error_code()
1611
+	{
1612
+		// phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
1613
+		global $wpdb;
1614
+		return $wpdb->use_mysqli ? mysqli_errno($wpdb->dbh) : mysql_errno($wpdb->dbh);
1615
+		// phpcs:enable
1616
+	}
1617
+
1618
+
1619
+	/**
1620
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1621
+	 *
1622
+	 * @param string $table_name with or without $wpdb->prefix
1623
+	 * @return boolean
1624
+	 * @throws EE_Error
1625
+	 * @throws ReflectionException
1626
+	 * @global wpdb  $wpdb
1627
+	 * @deprecated instead use TableAnalysis::tableExists()
1628
+	 */
1629
+	public static function table_exists($table_name)
1630
+	{
1631
+		return EEH_Activation::getTableAnalysis()->tableExists($table_name);
1632
+	}
1633
+
1634
+
1635
+	/**
1636
+	 * Resets the cache on EEH_Activation
1637
+	 */
1638
+	public static function reset()
1639
+	{
1640
+		self::$_default_creator_id                             = null;
1641
+		self::$_initialized_db_content_already_in_this_request = false;
1642
+	}
1643
+
1644
+
1645
+	/**
1646
+	 * Removes 'email_confirm' from the Address info question group on activation
1647
+	 *
1648
+	 * @return void
1649
+	 * @throws EE_Error
1650
+	 */
1651
+	public static function removeEmailConfirmFromAddressGroup()
1652
+	{
1653
+
1654
+		// Pull the email_confirm question ID.
1655
+		$email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
1656
+			EEM_Attendee::system_question_email_confirm
1657
+		);
1658
+		// Remove the email_confirm question group from the address group questions.
1659
+		EEM_Question_Group_Question::instance()->delete(
1660
+			[
1661
+				[
1662
+					'QST_ID'                    => $email_confirm_question_id,
1663
+					'Question_Group.QSG_system' => EEM_Question_Group::system_address,
1664
+				],
1665
+			]
1666
+		);
1667
+	}
1668 1668
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Template_Validator.helper.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
42 42
     {
43
-        if (!WP_DEBUG) {
43
+        if ( ! WP_DEBUG) {
44 44
             return;
45 45
         }
46
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
46
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
47 47
         if ('allow_null' == $allow_null && is_null($variable_to_test)) {
48 48
             return;
49 49
         }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public static function verify_isnt_null($variable_to_test, $name_of_variable)
68 68
     {
69
-        if (!WP_DEBUG) {
69
+        if ( ! WP_DEBUG) {
70 70
             return;
71 71
         }
72 72
         if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public static function verify_is_true($expression_to_test, $expression_string_representation)
88 88
     {
89
-        if (!WP_DEBUG) {
89
+        if ( ! WP_DEBUG) {
90 90
             return;
91 91
         }
92
-        if (!$expression_to_test) {
92
+        if ( ! $expression_to_test) {
93 93
             $error[] = esc_html__('Template error.', 'event_espresso');
94 94
             $error[] = esc_html__("%s evaluated to false, but it must be true!", 'event_espresso');
95 95
             throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
@@ -110,14 +110,14 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
112 112
     {
113
-        if (!WP_DEBUG) {
113
+        if ( ! WP_DEBUG) {
114 114
             return;
115 115
         }
116
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
116
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
117 117
         if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
118 118
             return;
119 119
         }
120
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
120
+        if ($variable_to_test == null || ! ($variable_to_test instanceof $class_name)) {
121 121
             $msg[] = esc_html__('Variable %s is not of the correct type.', 'event_espresso');
122 122
             $msg[] = esc_html__("It should be of type %s", 'event_espresso');
123 123
             throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
      */
139 139
     public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
140 140
     {
141
-        if (!WP_DEBUG) {
141
+        if ( ! WP_DEBUG) {
142 142
             return;
143 143
         }
144
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
144
+        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty', 'do_not_allow_empty'));
145 145
         if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
146 146
             return;
147 147
         }
148
-        if (!is_array($variable_to_test)) {
148
+        if ( ! is_array($variable_to_test)) {
149 149
             $error[] = esc_html__('Variable %s should be an array, but it is not.', 'event_espresso');
150 150
             $error[] = esc_html__("Its value is, instead '%s'", 'event_espresso');
151 151
             throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
170 170
     {
171
-        if (!WP_DEBUG) {
171
+        if ( ! WP_DEBUG) {
172 172
             return;
173 173
         }
174
-        if (!in_array($variable_to_test, $string_options)) {
174
+        if ( ! in_array($variable_to_test, $string_options)) {
175 175
             $msg[0] = esc_html__('Malconfigured template.', 'event_espresso');
176 176
             $msg[1] = esc_html__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
177 177
             throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
Please login to merge, or discard this patch.
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -24,152 +24,152 @@
 block discarded – undo
24 24
  */
25 25
 class EEH_Template_Validator
26 26
 {
27
-    /**
28
-     * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
29
-     * @param mixed $variable_to_test
30
-     * @param string $name_of_variable helpful in throwing intelligent errors
31
-     * @param string $class_name eg EE_Answer, EE_Transaction, etc.
32
-     * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
33
-     * @return void
34
-     * @throws EE_Error (indirectly)
35
-     */
36
-    public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
37
-    {
38
-        if (!WP_DEBUG) {
39
-            return;
40
-        }
41
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
42
-        if ('allow_null' == $allow_null && is_null($variable_to_test)) {
43
-            return;
44
-        }
45
-        self::verify_is_array($variable_to_test, $name_of_variable);
46
-        foreach ($variable_to_test as $key => $array_element) {
47
-            self::verify_instanceof($array_element, $key, $class_name);
48
-        }
49
-    }
50
-
51
-
52
-
53
-
54
-
55
-    /**
56
-     * throws an EE_Error if $variable_to_test is null
57
-     * @param mixed $variable_to_test
58
-     * @param string $name_of_variable helpful for throwing intelligent errors
59
-     * @return void
60
-     * @throws EE_Error
61
-     */
62
-    public static function verify_isnt_null($variable_to_test, $name_of_variable)
63
-    {
64
-        if (!WP_DEBUG) {
65
-            return;
66
-        }
67
-        if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
68
-            $error[] = esc_html__('Variable named %s is null.', 'event_espresso');
69
-            $error[] = esc_html__("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
70
-            throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
71
-        }
72
-    }
73
-
74
-    /**
75
-     * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
76
-     * @param boolean $expression_to_test
77
-     * @param string $expression_string_representation a string representation of your expression
78
-     * for example, if your expression were $var1==23, then this should be '$var1==23'
79
-     * @return void
80
-     * @throws EE_Error
81
-     */
82
-    public static function verify_is_true($expression_to_test, $expression_string_representation)
83
-    {
84
-        if (!WP_DEBUG) {
85
-            return;
86
-        }
87
-        if (!$expression_to_test) {
88
-            $error[] = esc_html__('Template error.', 'event_espresso');
89
-            $error[] = esc_html__("%s evaluated to false, but it must be true!", 'event_espresso');
90
-            throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
91
-        }
92
-    }
93
-
94
-
95
-
96
-
97
-
98
-    /**
99
-     * For verifying that a variable is indeed an object of class $class_name
100
-     * @param mixed $variable_to_test
101
-     * @param string $name_of_variable helpful when throwing errors
102
-     * @param string $class_name eg, EE_Answer,
103
-     * @return void
104
-     * @throws EE_Error
105
-     */
106
-    public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
107
-    {
108
-        if (!WP_DEBUG) {
109
-            return;
110
-        }
111
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
112
-        if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
113
-            return;
114
-        }
115
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
116
-            $msg[] = esc_html__('Variable %s is not of the correct type.', 'event_espresso');
117
-            $msg[] = esc_html__("It should be of type %s", 'event_espresso');
118
-            throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
119
-        }
120
-    }
121
-
122
-
123
-
124
-
125
-
126
-    /**
127
-     * For verifying that a variable is indeed an array, else throw an EE_Error
128
-     * @param type $variable_to_test
129
-     * @param type $variable_name
130
-     * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
131
-     * @return void
132
-     * @throws EE_Error
133
-     */
134
-    public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
135
-    {
136
-        if (!WP_DEBUG) {
137
-            return;
138
-        }
139
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
140
-        if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
141
-            return;
142
-        }
143
-        if (!is_array($variable_to_test)) {
144
-            $error[] = esc_html__('Variable %s should be an array, but it is not.', 'event_espresso');
145
-            $error[] = esc_html__("Its value is, instead '%s'", 'event_espresso');
146
-            throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
147
-        }
148
-    }
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-    /**
157
-     * for verifying that a variable is one of the string optiosn supplied
158
-     * @param mixed $variable_to_test
159
-     * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
160
-     * @param array $string_options an array of acceptable values
161
-     * @return void
162
-     * @throws EE_Error
163
-     */
164
-    public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
165
-    {
166
-        if (!WP_DEBUG) {
167
-            return;
168
-        }
169
-        if (!in_array($variable_to_test, $string_options)) {
170
-            $msg[0] = esc_html__('Malconfigured template.', 'event_espresso');
171
-            $msg[1] = esc_html__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
172
-            throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
173
-        }
174
-    }
27
+	/**
28
+	 * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
29
+	 * @param mixed $variable_to_test
30
+	 * @param string $name_of_variable helpful in throwing intelligent errors
31
+	 * @param string $class_name eg EE_Answer, EE_Transaction, etc.
32
+	 * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
33
+	 * @return void
34
+	 * @throws EE_Error (indirectly)
35
+	 */
36
+	public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
37
+	{
38
+		if (!WP_DEBUG) {
39
+			return;
40
+		}
41
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
42
+		if ('allow_null' == $allow_null && is_null($variable_to_test)) {
43
+			return;
44
+		}
45
+		self::verify_is_array($variable_to_test, $name_of_variable);
46
+		foreach ($variable_to_test as $key => $array_element) {
47
+			self::verify_instanceof($array_element, $key, $class_name);
48
+		}
49
+	}
50
+
51
+
52
+
53
+
54
+
55
+	/**
56
+	 * throws an EE_Error if $variable_to_test is null
57
+	 * @param mixed $variable_to_test
58
+	 * @param string $name_of_variable helpful for throwing intelligent errors
59
+	 * @return void
60
+	 * @throws EE_Error
61
+	 */
62
+	public static function verify_isnt_null($variable_to_test, $name_of_variable)
63
+	{
64
+		if (!WP_DEBUG) {
65
+			return;
66
+		}
67
+		if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
68
+			$error[] = esc_html__('Variable named %s is null.', 'event_espresso');
69
+			$error[] = esc_html__("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
70
+			throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
71
+		}
72
+	}
73
+
74
+	/**
75
+	 * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
76
+	 * @param boolean $expression_to_test
77
+	 * @param string $expression_string_representation a string representation of your expression
78
+	 * for example, if your expression were $var1==23, then this should be '$var1==23'
79
+	 * @return void
80
+	 * @throws EE_Error
81
+	 */
82
+	public static function verify_is_true($expression_to_test, $expression_string_representation)
83
+	{
84
+		if (!WP_DEBUG) {
85
+			return;
86
+		}
87
+		if (!$expression_to_test) {
88
+			$error[] = esc_html__('Template error.', 'event_espresso');
89
+			$error[] = esc_html__("%s evaluated to false, but it must be true!", 'event_espresso');
90
+			throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
91
+		}
92
+	}
93
+
94
+
95
+
96
+
97
+
98
+	/**
99
+	 * For verifying that a variable is indeed an object of class $class_name
100
+	 * @param mixed $variable_to_test
101
+	 * @param string $name_of_variable helpful when throwing errors
102
+	 * @param string $class_name eg, EE_Answer,
103
+	 * @return void
104
+	 * @throws EE_Error
105
+	 */
106
+	public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
107
+	{
108
+		if (!WP_DEBUG) {
109
+			return;
110
+		}
111
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
112
+		if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
113
+			return;
114
+		}
115
+		if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
116
+			$msg[] = esc_html__('Variable %s is not of the correct type.', 'event_espresso');
117
+			$msg[] = esc_html__("It should be of type %s", 'event_espresso');
118
+			throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
119
+		}
120
+	}
121
+
122
+
123
+
124
+
125
+
126
+	/**
127
+	 * For verifying that a variable is indeed an array, else throw an EE_Error
128
+	 * @param type $variable_to_test
129
+	 * @param type $variable_name
130
+	 * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
131
+	 * @return void
132
+	 * @throws EE_Error
133
+	 */
134
+	public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
135
+	{
136
+		if (!WP_DEBUG) {
137
+			return;
138
+		}
139
+		self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
140
+		if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
141
+			return;
142
+		}
143
+		if (!is_array($variable_to_test)) {
144
+			$error[] = esc_html__('Variable %s should be an array, but it is not.', 'event_espresso');
145
+			$error[] = esc_html__("Its value is, instead '%s'", 'event_espresso');
146
+			throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
147
+		}
148
+	}
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+	/**
157
+	 * for verifying that a variable is one of the string optiosn supplied
158
+	 * @param mixed $variable_to_test
159
+	 * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
160
+	 * @param array $string_options an array of acceptable values
161
+	 * @return void
162
+	 * @throws EE_Error
163
+	 */
164
+	public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
165
+	{
166
+		if (!WP_DEBUG) {
167
+			return;
168
+		}
169
+		if (!in_array($variable_to_test, $string_options)) {
170
+			$msg[0] = esc_html__('Malconfigured template.', 'event_espresso');
171
+			$msg[1] = esc_html__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
172
+			throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
173
+		}
174
+	}
175 175
 }
Please login to merge, or discard this patch.