Completed
Branch FET-9795-new-interfaces (793e2e)
by
unknown
121:05 queued 108:17
created
acceptance_tests/Helpers/EventsAdmin.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -14,61 +14,61 @@
 block discarded – undo
14 14
 trait EventsAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * @param string $additional_params
19
-     */
20
-    public function amOnDefaultEventsListTablePage($additional_params = '')
21
-    {
22
-        $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params));
23
-    }
17
+	/**
18
+	 * @param string $additional_params
19
+	 */
20
+	public function amOnDefaultEventsListTablePage($additional_params = '')
21
+	{
22
+		$this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params));
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * Triggers the publishing of the Event.
28
-     */
29
-    public function publishEvent()
30
-    {
31
-        $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR);
32
-    }
26
+	/**
27
+	 * Triggers the publishing of the Event.
28
+	 */
29
+	public function publishEvent()
30
+	{
31
+		$this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * Navigates the actor to the event list table page and will attempt to edit the event for the given title.
37
-     * First this will search using the given title and then attempt to edit from the results of the search.
38
-     *
39
-     * Assumes actor is already logged in.
40
-     * @param $event_title
41
-     */
42
-    public function amEditingTheEventWithTitle($event_title)
43
-    {
44
-        $this->amOnDefaultEventsListTablePage();
45
-        $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title);
46
-        $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR);
47
-        $this->actor()->waitForText('Displaying search results for');
48
-        $this->actor()->click(EventsPage::eventListTableEventTitleEditLink($event_title));
49
-    }
35
+	/**
36
+	 * Navigates the actor to the event list table page and will attempt to edit the event for the given title.
37
+	 * First this will search using the given title and then attempt to edit from the results of the search.
38
+	 *
39
+	 * Assumes actor is already logged in.
40
+	 * @param $event_title
41
+	 */
42
+	public function amEditingTheEventWithTitle($event_title)
43
+	{
44
+		$this->amOnDefaultEventsListTablePage();
45
+		$this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title);
46
+		$this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR);
47
+		$this->actor()->waitForText('Displaying search results for');
48
+		$this->actor()->click(EventsPage::eventListTableEventTitleEditLink($event_title));
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" link
54
-     * for the event in the event list table.
55
-     *
56
-     * Assumes the actor is already logged in and on the Event list table page.
57
-     * @param string $event_title
58
-     */
59
-    public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title)
60
-    {
61
-        $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
62
-        $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title));
63
-    }
52
+	/**
53
+	 * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" link
54
+	 * for the event in the event list table.
55
+	 *
56
+	 * Assumes the actor is already logged in and on the Event list table page.
57
+	 * @param string $event_title
58
+	 */
59
+	public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title)
60
+	{
61
+		$this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
62
+		$this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title));
63
+	}
64 64
 
65 65
 
66 66
 
67
-    public function changeDefaultRegistrationStatusTo($registration_status)
68
-    {
69
-        $this->actor()->selectOption(
70
-            EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR,
71
-            $registration_status
72
-        );
73
-    }
67
+	public function changeDefaultRegistrationStatusTo($registration_status)
68
+	{
69
+		$this->actor()->selectOption(
70
+			EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR,
71
+			$registration_status
72
+		);
73
+	}
74 74
 }
75 75
\ No newline at end of file
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.050');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.050');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.
caffeinated/brewing_regular.php 1 patch
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\database\TableAnalysis;
5 5
 
6 6
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 /**
10 10
  * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE
@@ -29,277 +29,277 @@  discard block
 block discarded – undo
29 29
 class EE_Brewing_Regular extends EE_BASE implements InterminableInterface
30 30
 {
31 31
 
32
-    /**
33
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
34
-     */
35
-    protected $_table_analysis;
36
-
37
-
38
-
39
-    /**
40
-     * EE_Brewing_Regular constructor.
41
-     */
42
-    public function __construct(TableAnalysis $table_analysis)
43
-    {
44
-        $this->_table_analysis = $table_analysis;
45
-        if (defined('EE_CAFF_PATH')) {
46
-            // activation
47
-            add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
48
-            // load caff init
49
-            add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
50
-            // remove the "powered by" credit link from receipts and invoices
51
-            add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
52
-            // add caffeinated modules
53
-            add_filter(
54
-                'FHEE__EE_Config__register_modules__modules_to_register',
55
-                array($this, 'caffeinated_modules_to_register')
56
-            );
57
-            // load caff scripts
58
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
59
-            add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
60
-            add_filter(
61
-                'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
62
-                array($this, 'caf_payment_methods')
63
-            );
64
-            // caffeinated constructed
65
-            do_action('AHEE__EE_Brewing_Regular__construct__finished');
66
-            //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
67
-            add_filter('FHEE__ee_show_affiliate_links', '__return_false');
68
-        }
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
75
-     *
76
-     * @param array $paths original helper paths array
77
-     * @return array             new array of paths
78
-     */
79
-    public function caf_helper_paths($paths)
80
-    {
81
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
82
-        return $paths;
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * Upon brand-new activation, if this is a new activation of CAF, we want to add
89
-     * some global prices that will show off EE4's capabilities. However, if they're upgrading
90
-     * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
91
-     * This action should only be called when EE 4.x.0.P is initially activated.
92
-     * Right now the only CAF content are these global prices. If there's more in the future, then
93
-     * we should probably create a caf file to contain it all instead just a function like this.
94
-     * Right now, we ASSUME the only price types in the system are default ones
95
-     *
96
-     * @global wpdb $wpdb
97
-     */
98
-    public function initialize_caf_db_content()
99
-    {
100
-        global $wpdb;
101
-        //use same method of getting creator id as the version introducing the change
102
-        $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
103
-        $price_type_table = $wpdb->prefix . "esp_price_type";
104
-        $price_table = $wpdb->prefix . "esp_price";
105
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
106
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
107
-            $tax_price_type_count = $wpdb->get_var($SQL);
108
-            if ($tax_price_type_count <= 1) {
109
-                $wpdb->insert(
110
-                    $price_type_table,
111
-                    array(
112
-                        'PRT_name'       => __("Regional Tax", "event_espresso"),
113
-                        'PBT_ID'         => 4,
114
-                        'PRT_is_percent' => true,
115
-                        'PRT_order'      => 60,
116
-                        'PRT_deleted'    => false,
117
-                        'PRT_wp_user'    => $default_creator_id,
118
-                    ),
119
-                    array(
120
-                        '%s',//PRT_name
121
-                        '%d',//PBT_id
122
-                        '%d',//PRT_is_percent
123
-                        '%d',//PRT_order
124
-                        '%d',//PRT_deleted
125
-                        '%d', //PRT_wp_user
126
-                    )
127
-                );
128
-                //federal tax
129
-                $result = $wpdb->insert(
130
-                    $price_type_table,
131
-                    array(
132
-                        'PRT_name'       => __("Federal Tax", "event_espresso"),
133
-                        'PBT_ID'         => 4,
134
-                        'PRT_is_percent' => true,
135
-                        'PRT_order'      => 70,
136
-                        'PRT_deleted'    => false,
137
-                        'PRT_wp_user'    => $default_creator_id,
138
-                    ),
139
-                    array(
140
-                        '%s',//PRT_name
141
-                        '%d',//PBT_id
142
-                        '%d',//PRT_is_percent
143
-                        '%d',//PRT_order
144
-                        '%d',//PRT_deleted
145
-                        '%d' //PRT_wp_user
146
-                    )
147
-                );
148
-                if ($result) {
149
-                    $wpdb->insert(
150
-                        $price_table,
151
-                        array(
152
-                            'PRT_ID'         => $wpdb->insert_id,
153
-                            'PRC_amount'     => 15.00,
154
-                            'PRC_name'       => __("Sales Tax", "event_espresso"),
155
-                            'PRC_desc'       => '',
156
-                            'PRC_is_default' => true,
157
-                            'PRC_overrides'  => null,
158
-                            'PRC_deleted'    => false,
159
-                            'PRC_order'      => 50,
160
-                            'PRC_parent'     => null,
161
-                            'PRC_wp_user'    => $default_creator_id,
162
-                        ),
163
-                        array(
164
-                            '%d',//PRT_id
165
-                            '%f',//PRC_amount
166
-                            '%s',//PRC_name
167
-                            '%s',//PRC_desc
168
-                            '%d',//PRC_is_default
169
-                            '%d',//PRC_overrides
170
-                            '%d',//PRC_deleted
171
-                            '%d',//PRC_order
172
-                            '%d',//PRC_parent
173
-                            '%d' //PRC_wp_user
174
-                        )
175
-                    );
176
-                }
177
-            }
178
-        }
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     *    caffeinated_modules_to_register
185
-     *
186
-     * @access public
187
-     * @param array $modules_to_register
188
-     * @return array
189
-     */
190
-    public function caffeinated_modules_to_register($modules_to_register = array())
191
-    {
192
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
193
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
194
-            if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
195
-                $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
196
-            }
197
-        }
198
-        return $modules_to_register;
199
-    }
200
-
201
-
202
-
203
-    public function caffeinated_init()
204
-    {
205
-        // EE_Register_CPTs hooks
206
-        add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
207
-        add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
208
-        add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
209
-        EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
210
-        // caffeinated_init__complete hook
211
-        do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
212
-    }
213
-
214
-
215
-
216
-    public function enqueue_caffeinated_scripts()
217
-    {
218
-        // sound of crickets...
219
-    }
220
-
221
-
222
-
223
-    /**
224
-     * callbacks below here
225
-     *
226
-     * @param array $taxonomy_array
227
-     * @return array
228
-     */
229
-    public function filter_taxonomies(array $taxonomy_array)
230
-    {
231
-        $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
232
-        return $taxonomy_array;
233
-    }
234
-
235
-
236
-
237
-    /**
238
-     * @param array $cpt_array
239
-     * @return mixed
240
-     */
241
-    public function filter_cpts(array $cpt_array)
242
-    {
243
-        $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
244
-        return $cpt_array;
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * @param array $menuitems
251
-     * @return array
252
-     */
253
-    public function nav_metabox_items(array $menuitems)
254
-    {
255
-        $menuitems[] = array(
256
-            'title'       => __('Venue List', 'event_espresso'),
257
-            'url'         => get_post_type_archive_link('espresso_venues'),
258
-            'description' => __('Archive page for all venues.', 'event_espresso'),
259
-        );
260
-        return $menuitems;
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
267
-     *
268
-     * @param array $payment_method_paths
269
-     * @return array values are folder paths to payment method folders
270
-     */
271
-    public function caf_payment_methods($payment_method_paths)
272
-    {
273
-        $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
274
-        $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
275
-        return $payment_method_paths;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * Gets the injected table analyzer, or throws an exception
282
-     *
283
-     * @return TableAnalysis
284
-     * @throws \EE_Error
285
-     */
286
-    protected function _get_table_analysis()
287
-    {
288
-        if ($this->_table_analysis instanceof TableAnalysis) {
289
-            return $this->_table_analysis;
290
-        } else {
291
-            throw new \EE_Error(
292
-                sprintf(
293
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
294
-                    get_class($this)
295
-                )
296
-            );
297
-        }
298
-    }
32
+	/**
33
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
34
+	 */
35
+	protected $_table_analysis;
36
+
37
+
38
+
39
+	/**
40
+	 * EE_Brewing_Regular constructor.
41
+	 */
42
+	public function __construct(TableAnalysis $table_analysis)
43
+	{
44
+		$this->_table_analysis = $table_analysis;
45
+		if (defined('EE_CAFF_PATH')) {
46
+			// activation
47
+			add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
48
+			// load caff init
49
+			add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
50
+			// remove the "powered by" credit link from receipts and invoices
51
+			add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
52
+			// add caffeinated modules
53
+			add_filter(
54
+				'FHEE__EE_Config__register_modules__modules_to_register',
55
+				array($this, 'caffeinated_modules_to_register')
56
+			);
57
+			// load caff scripts
58
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
59
+			add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
60
+			add_filter(
61
+				'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
62
+				array($this, 'caf_payment_methods')
63
+			);
64
+			// caffeinated constructed
65
+			do_action('AHEE__EE_Brewing_Regular__construct__finished');
66
+			//seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
67
+			add_filter('FHEE__ee_show_affiliate_links', '__return_false');
68
+		}
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
75
+	 *
76
+	 * @param array $paths original helper paths array
77
+	 * @return array             new array of paths
78
+	 */
79
+	public function caf_helper_paths($paths)
80
+	{
81
+		$paths[] = EE_CAF_CORE . 'helpers' . DS;
82
+		return $paths;
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * Upon brand-new activation, if this is a new activation of CAF, we want to add
89
+	 * some global prices that will show off EE4's capabilities. However, if they're upgrading
90
+	 * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
91
+	 * This action should only be called when EE 4.x.0.P is initially activated.
92
+	 * Right now the only CAF content are these global prices. If there's more in the future, then
93
+	 * we should probably create a caf file to contain it all instead just a function like this.
94
+	 * Right now, we ASSUME the only price types in the system are default ones
95
+	 *
96
+	 * @global wpdb $wpdb
97
+	 */
98
+	public function initialize_caf_db_content()
99
+	{
100
+		global $wpdb;
101
+		//use same method of getting creator id as the version introducing the change
102
+		$default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
103
+		$price_type_table = $wpdb->prefix . "esp_price_type";
104
+		$price_table = $wpdb->prefix . "esp_price";
105
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
106
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
107
+			$tax_price_type_count = $wpdb->get_var($SQL);
108
+			if ($tax_price_type_count <= 1) {
109
+				$wpdb->insert(
110
+					$price_type_table,
111
+					array(
112
+						'PRT_name'       => __("Regional Tax", "event_espresso"),
113
+						'PBT_ID'         => 4,
114
+						'PRT_is_percent' => true,
115
+						'PRT_order'      => 60,
116
+						'PRT_deleted'    => false,
117
+						'PRT_wp_user'    => $default_creator_id,
118
+					),
119
+					array(
120
+						'%s',//PRT_name
121
+						'%d',//PBT_id
122
+						'%d',//PRT_is_percent
123
+						'%d',//PRT_order
124
+						'%d',//PRT_deleted
125
+						'%d', //PRT_wp_user
126
+					)
127
+				);
128
+				//federal tax
129
+				$result = $wpdb->insert(
130
+					$price_type_table,
131
+					array(
132
+						'PRT_name'       => __("Federal Tax", "event_espresso"),
133
+						'PBT_ID'         => 4,
134
+						'PRT_is_percent' => true,
135
+						'PRT_order'      => 70,
136
+						'PRT_deleted'    => false,
137
+						'PRT_wp_user'    => $default_creator_id,
138
+					),
139
+					array(
140
+						'%s',//PRT_name
141
+						'%d',//PBT_id
142
+						'%d',//PRT_is_percent
143
+						'%d',//PRT_order
144
+						'%d',//PRT_deleted
145
+						'%d' //PRT_wp_user
146
+					)
147
+				);
148
+				if ($result) {
149
+					$wpdb->insert(
150
+						$price_table,
151
+						array(
152
+							'PRT_ID'         => $wpdb->insert_id,
153
+							'PRC_amount'     => 15.00,
154
+							'PRC_name'       => __("Sales Tax", "event_espresso"),
155
+							'PRC_desc'       => '',
156
+							'PRC_is_default' => true,
157
+							'PRC_overrides'  => null,
158
+							'PRC_deleted'    => false,
159
+							'PRC_order'      => 50,
160
+							'PRC_parent'     => null,
161
+							'PRC_wp_user'    => $default_creator_id,
162
+						),
163
+						array(
164
+							'%d',//PRT_id
165
+							'%f',//PRC_amount
166
+							'%s',//PRC_name
167
+							'%s',//PRC_desc
168
+							'%d',//PRC_is_default
169
+							'%d',//PRC_overrides
170
+							'%d',//PRC_deleted
171
+							'%d',//PRC_order
172
+							'%d',//PRC_parent
173
+							'%d' //PRC_wp_user
174
+						)
175
+					);
176
+				}
177
+			}
178
+		}
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 *    caffeinated_modules_to_register
185
+	 *
186
+	 * @access public
187
+	 * @param array $modules_to_register
188
+	 * @return array
189
+	 */
190
+	public function caffeinated_modules_to_register($modules_to_register = array())
191
+	{
192
+		if (is_readable(EE_CAFF_PATH . 'modules')) {
193
+			$caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
194
+			if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
195
+				$modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
196
+			}
197
+		}
198
+		return $modules_to_register;
199
+	}
200
+
201
+
202
+
203
+	public function caffeinated_init()
204
+	{
205
+		// EE_Register_CPTs hooks
206
+		add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
207
+		add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
208
+		add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
209
+		EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
210
+		// caffeinated_init__complete hook
211
+		do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
212
+	}
213
+
214
+
215
+
216
+	public function enqueue_caffeinated_scripts()
217
+	{
218
+		// sound of crickets...
219
+	}
220
+
221
+
222
+
223
+	/**
224
+	 * callbacks below here
225
+	 *
226
+	 * @param array $taxonomy_array
227
+	 * @return array
228
+	 */
229
+	public function filter_taxonomies(array $taxonomy_array)
230
+	{
231
+		$taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
232
+		return $taxonomy_array;
233
+	}
234
+
235
+
236
+
237
+	/**
238
+	 * @param array $cpt_array
239
+	 * @return mixed
240
+	 */
241
+	public function filter_cpts(array $cpt_array)
242
+	{
243
+		$cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
244
+		return $cpt_array;
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * @param array $menuitems
251
+	 * @return array
252
+	 */
253
+	public function nav_metabox_items(array $menuitems)
254
+	{
255
+		$menuitems[] = array(
256
+			'title'       => __('Venue List', 'event_espresso'),
257
+			'url'         => get_post_type_archive_link('espresso_venues'),
258
+			'description' => __('Archive page for all venues.', 'event_espresso'),
259
+		);
260
+		return $menuitems;
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
267
+	 *
268
+	 * @param array $payment_method_paths
269
+	 * @return array values are folder paths to payment method folders
270
+	 */
271
+	public function caf_payment_methods($payment_method_paths)
272
+	{
273
+		$caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
274
+		$payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
275
+		return $payment_method_paths;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * Gets the injected table analyzer, or throws an exception
282
+	 *
283
+	 * @return TableAnalysis
284
+	 * @throws \EE_Error
285
+	 */
286
+	protected function _get_table_analysis()
287
+	{
288
+		if ($this->_table_analysis instanceof TableAnalysis) {
289
+			return $this->_table_analysis;
290
+		} else {
291
+			throw new \EE_Error(
292
+				sprintf(
293
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
294
+					get_class($this)
295
+				)
296
+			);
297
+		}
298
+	}
299 299
 }
300 300
 
301 301
 
302 302
 
303 303
 $brewing = new EE_Brewing_Regular(
304
-    EE_Registry::instance()->create('TableAnalysis', array(), true)
304
+	EE_Registry::instance()->create('TableAnalysis', array(), true)
305 305
 );
306 306
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 1 patch
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\interfaces\ResettableInterface;
2 2
 
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -19,402 +19,402 @@  discard block
 block discarded – undo
19 19
 class EE_Payment_Method_Manager implements ResettableInterface
20 20
 {
21 21
 
22
-    /**
23
-     *    instance of the EE_Payment_Method_Manager object
24
-     *
25
-     * @var    $_instance
26
-     * @access    private
27
-     */
28
-    private static $_instance;
29
-
30
-    /**
31
-     * @var array keys are classnames without 'EE_PMT_', values are their filepaths
32
-     */
33
-    protected $_payment_method_types = array();
34
-
35
-
36
-
37
-    /**
38
-     * @singleton method used to instantiate class object
39
-     * @access    public
40
-     * @return EE_Payment_Method_Manager instance
41
-     */
42
-    public static function instance()
43
-    {
44
-        // check if class object is instantiated, and instantiated properly
45
-        if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
46
-            self::$_instance = new self();
47
-        }
48
-        EE_Registry::instance()->load_lib('PMT_Base');
49
-        return self::$_instance;
50
-    }
51
-
52
-
53
-
54
-    /**
55
-     * Resets the instance and returns a new one
56
-     *
57
-     * @return EE_Payment_Method_Manager
58
-     */
59
-    public static function reset()
60
-    {
61
-        self::$_instance = null;
62
-        return self::instance();
63
-    }
64
-
65
-
66
-
67
-    /**
68
-     * If necessary, re-register payment methods
69
-     *
70
-     * @param boolean $force_recheck whether to recheck for payment method types,
71
-     *                               or just re-use the PMTs we found last time we checked during this request (if
72
-     *                               we have not yet checked during this request, then we need to check anyways)
73
-     */
74
-    public function maybe_register_payment_methods($force_recheck = false)
75
-    {
76
-        if ( ! $this->_payment_method_types || $force_recheck) {
77
-            $this->_register_payment_methods();
78
-        }
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     *        register_payment_methods
85
-     *
86
-     * @return array
87
-     */
88
-    protected function _register_payment_methods()
89
-    {
90
-        // grab list of installed modules
91
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
92
-        // filter list of modules to register
93
-        $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
94
-            $pm_to_register);
95
-        // loop through folders
96
-        foreach ($pm_to_register as $pm_path) {
97
-            $this->register_payment_method($pm_path);
98
-        }
99
-        do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
100
-        // filter list of installed modules
101
-        //keep them organized alphabetically by the payment method type's name
102
-        ksort($this->_payment_method_types);
103
-        return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
104
-            $this->_payment_method_types);
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     *    register_payment_method- makes core aware of this payment method
111
-     *
112
-     * @access public
113
-     * @param string $payment_method_path - full path up to and including payment method folder
114
-     * @return boolean
115
-     */
116
-    public function register_payment_method($payment_method_path = '')
117
-    {
118
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
119
-        $module_ext = '.pm.php';
120
-        // make all separators match
121
-        $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
122
-        // grab and sanitize module name
123
-        $module_dir = basename($payment_method_path);
124
-        // create classname from module directory name
125
-        $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
126
-        // add class prefix
127
-        $module_class = 'EE_PMT_' . $module;
128
-        // does the module exist ?
129
-        if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
130
-            $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.',
131
-                'event_espresso'), $module);
132
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
133
-            return false;
134
-        }
135
-        if (WP_DEBUG === true) {
136
-            EEH_Debug_Tools::instance()->start_timer();
137
-        }
138
-        // load the module class file
139
-        require_once($payment_method_path . DS . $module_class . $module_ext);
140
-        if (WP_DEBUG === true) {
141
-            EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class");
142
-        }
143
-        // verify that class exists
144
-        if ( ! class_exists($module_class)) {
145
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
146
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
147
-            return false;
148
-        }
149
-        // add to array of registered modules
150
-        $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
151
-        return true;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * Checks if a payment method has been registered, and if so includes it
158
-     *
159
-     * @param string  $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_')
160
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
161
-     * @return boolean
162
-     */
163
-    public function payment_method_type_exists($payment_method_name, $force_recheck = false)
164
-    {
165
-        if (
166
-            $force_recheck
167
-            || ! is_array($this->_payment_method_types)
168
-            || ! isset($this->_payment_method_types[$payment_method_name])
169
-        ) {
170
-            $this->maybe_register_payment_methods($force_recheck);
171
-        }
172
-        if (isset($this->_payment_method_types[$payment_method_name])) {
173
-            require_once($this->_payment_method_types[$payment_method_name]);
174
-            return true;
175
-        } else {
176
-            return false;
177
-        }
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * Returns all the classnames of the various payment method types
184
-     *
185
-     * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names'
186
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
187
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
188
-     * @return array
189
-     */
190
-    public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
191
-    {
192
-        $this->maybe_register_payment_methods($force_recheck);
193
-        if ($with_prefixes) {
194
-            $classnames = array_keys($this->_payment_method_types);
195
-            $payment_methods = array();
196
-            foreach ($classnames as $classname) {
197
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
198
-            }
199
-            return $payment_methods;
200
-        } else {
201
-            return array_keys($this->_payment_method_types);
202
-        }
203
-    }
204
-
205
-
206
-
207
-    /**
208
-     * Gets an object of each payment method type, none of which are bound to a
209
-     * payment method instance
210
-     *
211
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
212
-     * @return EE_PMT_Base[]
213
-     */
214
-    public function payment_method_types($force_recheck = false)
215
-    {
216
-        $this->maybe_register_payment_methods($force_recheck);
217
-        $pmt_objs = array();
218
-        foreach ($this->payment_method_type_names(true) as $classname) {
219
-            $pmt_objs[] = new $classname;
220
-        }
221
-        return $pmt_objs;
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * Changes the payment method's classname into the payment method type's name
228
-     * (as used on the payment method's table's PMD_type field)
229
-     *
230
-     * @param string $classname
231
-     * @return string
232
-     */
233
-    public function payment_method_type_sans_class_prefix($classname)
234
-    {
235
-        return str_replace("EE_PMT_", "", $classname);
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * Does the opposite of payment-method_type_sans_prefix
242
-     *
243
-     * @param string $type
244
-     * @return string
245
-     */
246
-    public function payment_method_class_from_type($type)
247
-    {
248
-        $this->maybe_register_payment_methods();
249
-        return "EE_PMT_" . $type;
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * Activates a payment method of the given type.
256
-     *
257
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
258
-     * @return \EE_Payment_Method
259
-     * @throws \EE_Error
260
-     */
261
-    public function activate_a_payment_method_of_type($payment_method_type)
262
-    {
263
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
264
-        if ( ! $payment_method instanceof EE_Payment_Method) {
265
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
266
-            if (class_exists($pm_type_class)) {
267
-                /** @var $pm_type_obj EE_PMT_Base */
268
-                $pm_type_obj = new $pm_type_class;
269
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
270
-                if ( ! $payment_method) {
271
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
272
-                }
273
-                $payment_method->set_type($payment_method_type);
274
-                $this->initialize_payment_method($payment_method);
275
-            } else {
276
-                throw new EE_Error(
277
-                    sprintf(
278
-                        __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
279
-                        $pm_type_class)
280
-                );
281
-            }
282
-        }
283
-        $payment_method->set_active();
284
-        $payment_method->save();
285
-        $this->set_usable_currencies_on_payment_method($payment_method);
286
-        if ($payment_method->type() === 'Invoice') {
287
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
288
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
289
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
290
-            $message_resource_manager->ensure_messenger_is_active('pdf');
291
-            EE_Error::add_persistent_admin_notice(
292
-                'invoice_pm_requirements_notice',
293
-                sprintf(
294
-                    __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
295
-                        'event_espresso'),
296
-                    '<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
297
-                    '</a>'
298
-                ),
299
-                true
300
-            );
301
-        }
302
-        return $payment_method;
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * Creates a payment method of the specified type. Does not save it.
309
-     *
310
-     * @global WP_User    $current_user
311
-     * @param EE_PMT_Base $pm_type_obj
312
-     * @return EE_Payment_Method
313
-     * @throws \EE_Error
314
-     */
315
-    public function create_payment_method_of_type($pm_type_obj)
316
-    {
317
-        global $current_user;
318
-        $payment_method = EE_Payment_Method::new_instance(
319
-            array(
320
-                'PMD_type'       => $pm_type_obj->system_name(),
321
-                'PMD_name'       => $pm_type_obj->pretty_name(),
322
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
323
-                'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
324
-                'PMD_wp_user'    => $current_user->ID,
325
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
326
-                        array(array('PMD_type' => array('!=', 'Admin_Only')))
327
-                    ) * 10,
328
-            )
329
-        );
330
-        return $payment_method;
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * Sets the initial payment method properties (including extra meta)
337
-     *
338
-     * @param EE_Payment_Method $payment_method
339
-     * @return EE_Payment_Method
340
-     * @throws \EE_Error
341
-     */
342
-    public function initialize_payment_method($payment_method)
343
-    {
344
-        $pm_type_obj = $payment_method->type_obj();
345
-        $payment_method->set_description($pm_type_obj->default_description());
346
-        if ( ! $payment_method->button_url()) {
347
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
348
-        }
349
-        //now add setup its default extra meta properties
350
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
351
-        if ( ! empty($extra_metas)) {
352
-            //verify the payment method has an ID before adding extra meta
353
-            if ( ! $payment_method->ID()) {
354
-                $payment_method->save();
355
-            }
356
-            foreach ($extra_metas as $meta_name => $input) {
357
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
358
-            }
359
-        }
360
-        return $payment_method;
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * Makes sure the payment method is related to the specified payment method
367
-     *
368
-     * @param EE_Payment_Method $payment_method
369
-     * @return EE_Payment_Method
370
-     * @throws \EE_Error
371
-     */
372
-    public function set_usable_currencies_on_payment_method($payment_method)
373
-    {
374
-        foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
375
-            $payment_method->_add_relation_to($currency_obj, 'Currency');
376
-        }
377
-        return $payment_method;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * Deactivates a payment method of the given payment method slug.
384
-     *
385
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
386
-     * @return int count of rows updated.
387
-     */
388
-    public function deactivate_payment_method($payment_method_slug)
389
-    {
390
-        EE_Log::instance()->log(
391
-            __FILE__,
392
-            __FUNCTION__,
393
-            sprintf(
394
-                __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'),
395
-                $payment_method_slug
396
-            ),
397
-            'payment_method_change'
398
-        );
399
-        $count_updated = EEM_Payment_Method::instance()->update(
400
-            array('PMD_scope' => array()),
401
-            array(array('PMD_slug' => $payment_method_slug))
402
-        );
403
-        return $count_updated;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
410
-     * access caps.
411
-     *
412
-     * @param array $caps capabilities being filtered
413
-     * @return array
414
-     */
415
-    public function add_payment_method_caps($caps)
416
-    {
417
-        /* add dynamic caps from payment methods
22
+	/**
23
+	 *    instance of the EE_Payment_Method_Manager object
24
+	 *
25
+	 * @var    $_instance
26
+	 * @access    private
27
+	 */
28
+	private static $_instance;
29
+
30
+	/**
31
+	 * @var array keys are classnames without 'EE_PMT_', values are their filepaths
32
+	 */
33
+	protected $_payment_method_types = array();
34
+
35
+
36
+
37
+	/**
38
+	 * @singleton method used to instantiate class object
39
+	 * @access    public
40
+	 * @return EE_Payment_Method_Manager instance
41
+	 */
42
+	public static function instance()
43
+	{
44
+		// check if class object is instantiated, and instantiated properly
45
+		if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
46
+			self::$_instance = new self();
47
+		}
48
+		EE_Registry::instance()->load_lib('PMT_Base');
49
+		return self::$_instance;
50
+	}
51
+
52
+
53
+
54
+	/**
55
+	 * Resets the instance and returns a new one
56
+	 *
57
+	 * @return EE_Payment_Method_Manager
58
+	 */
59
+	public static function reset()
60
+	{
61
+		self::$_instance = null;
62
+		return self::instance();
63
+	}
64
+
65
+
66
+
67
+	/**
68
+	 * If necessary, re-register payment methods
69
+	 *
70
+	 * @param boolean $force_recheck whether to recheck for payment method types,
71
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
72
+	 *                               we have not yet checked during this request, then we need to check anyways)
73
+	 */
74
+	public function maybe_register_payment_methods($force_recheck = false)
75
+	{
76
+		if ( ! $this->_payment_method_types || $force_recheck) {
77
+			$this->_register_payment_methods();
78
+		}
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 *        register_payment_methods
85
+	 *
86
+	 * @return array
87
+	 */
88
+	protected function _register_payment_methods()
89
+	{
90
+		// grab list of installed modules
91
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
92
+		// filter list of modules to register
93
+		$pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
94
+			$pm_to_register);
95
+		// loop through folders
96
+		foreach ($pm_to_register as $pm_path) {
97
+			$this->register_payment_method($pm_path);
98
+		}
99
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
100
+		// filter list of installed modules
101
+		//keep them organized alphabetically by the payment method type's name
102
+		ksort($this->_payment_method_types);
103
+		return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
104
+			$this->_payment_method_types);
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 *    register_payment_method- makes core aware of this payment method
111
+	 *
112
+	 * @access public
113
+	 * @param string $payment_method_path - full path up to and including payment method folder
114
+	 * @return boolean
115
+	 */
116
+	public function register_payment_method($payment_method_path = '')
117
+	{
118
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
119
+		$module_ext = '.pm.php';
120
+		// make all separators match
121
+		$payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
122
+		// grab and sanitize module name
123
+		$module_dir = basename($payment_method_path);
124
+		// create classname from module directory name
125
+		$module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
126
+		// add class prefix
127
+		$module_class = 'EE_PMT_' . $module;
128
+		// does the module exist ?
129
+		if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
130
+			$msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.',
131
+				'event_espresso'), $module);
132
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
133
+			return false;
134
+		}
135
+		if (WP_DEBUG === true) {
136
+			EEH_Debug_Tools::instance()->start_timer();
137
+		}
138
+		// load the module class file
139
+		require_once($payment_method_path . DS . $module_class . $module_ext);
140
+		if (WP_DEBUG === true) {
141
+			EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class");
142
+		}
143
+		// verify that class exists
144
+		if ( ! class_exists($module_class)) {
145
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
146
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
147
+			return false;
148
+		}
149
+		// add to array of registered modules
150
+		$this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
151
+		return true;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * Checks if a payment method has been registered, and if so includes it
158
+	 *
159
+	 * @param string  $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_')
160
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
161
+	 * @return boolean
162
+	 */
163
+	public function payment_method_type_exists($payment_method_name, $force_recheck = false)
164
+	{
165
+		if (
166
+			$force_recheck
167
+			|| ! is_array($this->_payment_method_types)
168
+			|| ! isset($this->_payment_method_types[$payment_method_name])
169
+		) {
170
+			$this->maybe_register_payment_methods($force_recheck);
171
+		}
172
+		if (isset($this->_payment_method_types[$payment_method_name])) {
173
+			require_once($this->_payment_method_types[$payment_method_name]);
174
+			return true;
175
+		} else {
176
+			return false;
177
+		}
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * Returns all the classnames of the various payment method types
184
+	 *
185
+	 * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names'
186
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
187
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
188
+	 * @return array
189
+	 */
190
+	public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
191
+	{
192
+		$this->maybe_register_payment_methods($force_recheck);
193
+		if ($with_prefixes) {
194
+			$classnames = array_keys($this->_payment_method_types);
195
+			$payment_methods = array();
196
+			foreach ($classnames as $classname) {
197
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
198
+			}
199
+			return $payment_methods;
200
+		} else {
201
+			return array_keys($this->_payment_method_types);
202
+		}
203
+	}
204
+
205
+
206
+
207
+	/**
208
+	 * Gets an object of each payment method type, none of which are bound to a
209
+	 * payment method instance
210
+	 *
211
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
212
+	 * @return EE_PMT_Base[]
213
+	 */
214
+	public function payment_method_types($force_recheck = false)
215
+	{
216
+		$this->maybe_register_payment_methods($force_recheck);
217
+		$pmt_objs = array();
218
+		foreach ($this->payment_method_type_names(true) as $classname) {
219
+			$pmt_objs[] = new $classname;
220
+		}
221
+		return $pmt_objs;
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * Changes the payment method's classname into the payment method type's name
228
+	 * (as used on the payment method's table's PMD_type field)
229
+	 *
230
+	 * @param string $classname
231
+	 * @return string
232
+	 */
233
+	public function payment_method_type_sans_class_prefix($classname)
234
+	{
235
+		return str_replace("EE_PMT_", "", $classname);
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * Does the opposite of payment-method_type_sans_prefix
242
+	 *
243
+	 * @param string $type
244
+	 * @return string
245
+	 */
246
+	public function payment_method_class_from_type($type)
247
+	{
248
+		$this->maybe_register_payment_methods();
249
+		return "EE_PMT_" . $type;
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * Activates a payment method of the given type.
256
+	 *
257
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
258
+	 * @return \EE_Payment_Method
259
+	 * @throws \EE_Error
260
+	 */
261
+	public function activate_a_payment_method_of_type($payment_method_type)
262
+	{
263
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
264
+		if ( ! $payment_method instanceof EE_Payment_Method) {
265
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
266
+			if (class_exists($pm_type_class)) {
267
+				/** @var $pm_type_obj EE_PMT_Base */
268
+				$pm_type_obj = new $pm_type_class;
269
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
270
+				if ( ! $payment_method) {
271
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
272
+				}
273
+				$payment_method->set_type($payment_method_type);
274
+				$this->initialize_payment_method($payment_method);
275
+			} else {
276
+				throw new EE_Error(
277
+					sprintf(
278
+						__('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
279
+						$pm_type_class)
280
+				);
281
+			}
282
+		}
283
+		$payment_method->set_active();
284
+		$payment_method->save();
285
+		$this->set_usable_currencies_on_payment_method($payment_method);
286
+		if ($payment_method->type() === 'Invoice') {
287
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
288
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
289
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
290
+			$message_resource_manager->ensure_messenger_is_active('pdf');
291
+			EE_Error::add_persistent_admin_notice(
292
+				'invoice_pm_requirements_notice',
293
+				sprintf(
294
+					__('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
295
+						'event_espresso'),
296
+					'<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
297
+					'</a>'
298
+				),
299
+				true
300
+			);
301
+		}
302
+		return $payment_method;
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * Creates a payment method of the specified type. Does not save it.
309
+	 *
310
+	 * @global WP_User    $current_user
311
+	 * @param EE_PMT_Base $pm_type_obj
312
+	 * @return EE_Payment_Method
313
+	 * @throws \EE_Error
314
+	 */
315
+	public function create_payment_method_of_type($pm_type_obj)
316
+	{
317
+		global $current_user;
318
+		$payment_method = EE_Payment_Method::new_instance(
319
+			array(
320
+				'PMD_type'       => $pm_type_obj->system_name(),
321
+				'PMD_name'       => $pm_type_obj->pretty_name(),
322
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
323
+				'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
324
+				'PMD_wp_user'    => $current_user->ID,
325
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
326
+						array(array('PMD_type' => array('!=', 'Admin_Only')))
327
+					) * 10,
328
+			)
329
+		);
330
+		return $payment_method;
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * Sets the initial payment method properties (including extra meta)
337
+	 *
338
+	 * @param EE_Payment_Method $payment_method
339
+	 * @return EE_Payment_Method
340
+	 * @throws \EE_Error
341
+	 */
342
+	public function initialize_payment_method($payment_method)
343
+	{
344
+		$pm_type_obj = $payment_method->type_obj();
345
+		$payment_method->set_description($pm_type_obj->default_description());
346
+		if ( ! $payment_method->button_url()) {
347
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
348
+		}
349
+		//now add setup its default extra meta properties
350
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
351
+		if ( ! empty($extra_metas)) {
352
+			//verify the payment method has an ID before adding extra meta
353
+			if ( ! $payment_method->ID()) {
354
+				$payment_method->save();
355
+			}
356
+			foreach ($extra_metas as $meta_name => $input) {
357
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
358
+			}
359
+		}
360
+		return $payment_method;
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * Makes sure the payment method is related to the specified payment method
367
+	 *
368
+	 * @param EE_Payment_Method $payment_method
369
+	 * @return EE_Payment_Method
370
+	 * @throws \EE_Error
371
+	 */
372
+	public function set_usable_currencies_on_payment_method($payment_method)
373
+	{
374
+		foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
375
+			$payment_method->_add_relation_to($currency_obj, 'Currency');
376
+		}
377
+		return $payment_method;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * Deactivates a payment method of the given payment method slug.
384
+	 *
385
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
386
+	 * @return int count of rows updated.
387
+	 */
388
+	public function deactivate_payment_method($payment_method_slug)
389
+	{
390
+		EE_Log::instance()->log(
391
+			__FILE__,
392
+			__FUNCTION__,
393
+			sprintf(
394
+				__('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'),
395
+				$payment_method_slug
396
+			),
397
+			'payment_method_change'
398
+		);
399
+		$count_updated = EEM_Payment_Method::instance()->update(
400
+			array('PMD_scope' => array()),
401
+			array(array('PMD_slug' => $payment_method_slug))
402
+		);
403
+		return $count_updated;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
410
+	 * access caps.
411
+	 *
412
+	 * @param array $caps capabilities being filtered
413
+	 * @return array
414
+	 */
415
+	public function add_payment_method_caps($caps)
416
+	{
417
+		/* add dynamic caps from payment methods
418 418
          * at the time of writing, october 20 2014, these are the caps added:
419 419
          * ee_payment_method_admin_only
420 420
          * ee_payment_method_aim
@@ -428,10 +428,10 @@  discard block
 block discarded – undo
428 428
          * their related capability automatically added too, so long as they are
429 429
          * registered properly using EE_Register_Payment_Method::register()
430 430
          */
431
-        foreach ($this->payment_method_types() as $payment_method_type_obj) {
432
-            $caps['administrator'][] = $payment_method_type_obj->cap_name();
433
-        }
434
-        return $caps;
435
-    }
431
+		foreach ($this->payment_method_types() as $payment_method_type_obj) {
432
+			$caps['administrator'][] = $payment_method_type_obj->cap_name();
433
+		}
434
+		return $caps;
435
+	}
436 436
 
437 437
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 1 patch
Indentation   +1652 added lines, -1652 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\interfaces\ResettableInterface;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -17,243 +17,243 @@  discard block
 block discarded – undo
17 17
 class EEH_Activation implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * constant used to indicate a cron task is no longer in use
22
-     */
23
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
24
-
25
-    /**
26
-     * option name that will indicate whether or not we still
27
-     * need to create EE's folders in the uploads directory
28
-     * (because if EE was installed without file system access,
29
-     * we need to request credentials before we can create them)
30
-     */
31
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
32
-
33
-    /**
34
-     * WP_User->ID
35
-     *
36
-     * @var int
37
-     */
38
-    private static $_default_creator_id;
39
-
40
-    /**
41
-     * indicates whether or not we've already verified core's default data during this request,
42
-     * because after migrations are done, any addons activated while in maintenance mode
43
-     * will want to setup their own default data, and they might hook into core's default data
44
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
45
-     * This prevents doing that for EVERY single addon.
46
-     *
47
-     * @var boolean
48
-     */
49
-    protected static $_initialized_db_content_already_in_this_request = false;
50
-
51
-    /**
52
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
53
-     */
54
-    private static $table_analysis;
55
-
56
-    /**
57
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
58
-     */
59
-    private static $table_manager;
60
-
61
-
62
-    /**
63
-     * @return \EventEspresso\core\services\database\TableAnalysis
64
-     */
65
-    public static function getTableAnalysis()
66
-    {
67
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
68
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
69
-        }
70
-        return self::$table_analysis;
71
-    }
72
-
73
-
74
-    /**
75
-     * @return \EventEspresso\core\services\database\TableManager
76
-     */
77
-    public static function getTableManager()
78
-    {
79
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
80
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
81
-        }
82
-        return self::$table_manager;
83
-    }
84
-
85
-
86
-    /**
87
-     *    _ensure_table_name_has_prefix
88
-     *
89
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
90
-     * @access     public
91
-     * @static
92
-     * @param $table_name
93
-     * @return string
94
-     */
95
-    public static function ensure_table_name_has_prefix($table_name)
96
-    {
97
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
98
-    }
99
-
100
-
101
-    /**
102
-     *    system_initialization
103
-     *    ensures the EE configuration settings are loaded with at least default options set
104
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
105
-     *
106
-     * @access public
107
-     * @static
108
-     * @return void
109
-     */
110
-    public static function system_initialization()
111
-    {
112
-        EEH_Activation::reset_and_update_config();
113
-        //which is fired BEFORE activation of plugin anyways
114
-        EEH_Activation::verify_default_pages_exist();
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the database schema and creates folders. This should
120
-     * be called on plugin activation and reactivation
121
-     *
122
-     * @return boolean success, whether the database and folders are setup properly
123
-     * @throws \EE_Error
124
-     */
125
-    public static function initialize_db_and_folders()
126
-    {
127
-        $good_filesystem = EEH_Activation::create_upload_directories();
128
-        $good_db         = EEH_Activation::create_database_tables();
129
-        return $good_filesystem && $good_db;
130
-    }
131
-
132
-
133
-    /**
134
-     * assuming we have an up-to-date database schema, this will populate it
135
-     * with default and initial data. This should be called
136
-     * upon activation of a new plugin, reactivation, and at the end
137
-     * of running migration scripts
138
-     *
139
-     * @throws \EE_Error
140
-     */
141
-    public static function initialize_db_content()
142
-    {
143
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
144
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
145
-            return;
146
-        }
147
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
148
-
149
-        EEH_Activation::initialize_system_questions();
150
-        EEH_Activation::insert_default_status_codes();
151
-        EEH_Activation::generate_default_message_templates();
152
-        EEH_Activation::create_no_ticket_prices_array();
153
-        EEH_Activation::validate_messages_system();
154
-        EEH_Activation::insert_default_payment_methods();
155
-        //in case we've
156
-        EEH_Activation::remove_cron_tasks();
157
-        EEH_Activation::create_cron_tasks();
158
-        // remove all TXN locks since that is being done via extra meta now
159
-        delete_option('ee_locked_transactions');
160
-        //also, check for CAF default db content
161
-        do_action('AHEE__EEH_Activation__initialize_db_content');
162
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
163
-        //which users really won't care about on initial activation
164
-        EE_Error::overwrite_success();
165
-    }
166
-
167
-
168
-    /**
169
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
170
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
171
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
172
-     * (null)
173
-     *
174
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
175
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
176
-     * @return array
177
-     * @throws \EE_Error
178
-     */
179
-    public static function get_cron_tasks($which_to_include)
180
-    {
181
-        $cron_tasks = apply_filters(
182
-            'FHEE__EEH_Activation__get_cron_tasks',
183
-            array(
184
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
20
+	/**
21
+	 * constant used to indicate a cron task is no longer in use
22
+	 */
23
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
24
+
25
+	/**
26
+	 * option name that will indicate whether or not we still
27
+	 * need to create EE's folders in the uploads directory
28
+	 * (because if EE was installed without file system access,
29
+	 * we need to request credentials before we can create them)
30
+	 */
31
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
32
+
33
+	/**
34
+	 * WP_User->ID
35
+	 *
36
+	 * @var int
37
+	 */
38
+	private static $_default_creator_id;
39
+
40
+	/**
41
+	 * indicates whether or not we've already verified core's default data during this request,
42
+	 * because after migrations are done, any addons activated while in maintenance mode
43
+	 * will want to setup their own default data, and they might hook into core's default data
44
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
45
+	 * This prevents doing that for EVERY single addon.
46
+	 *
47
+	 * @var boolean
48
+	 */
49
+	protected static $_initialized_db_content_already_in_this_request = false;
50
+
51
+	/**
52
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
53
+	 */
54
+	private static $table_analysis;
55
+
56
+	/**
57
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
58
+	 */
59
+	private static $table_manager;
60
+
61
+
62
+	/**
63
+	 * @return \EventEspresso\core\services\database\TableAnalysis
64
+	 */
65
+	public static function getTableAnalysis()
66
+	{
67
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
68
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
69
+		}
70
+		return self::$table_analysis;
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return \EventEspresso\core\services\database\TableManager
76
+	 */
77
+	public static function getTableManager()
78
+	{
79
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
80
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
81
+		}
82
+		return self::$table_manager;
83
+	}
84
+
85
+
86
+	/**
87
+	 *    _ensure_table_name_has_prefix
88
+	 *
89
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
90
+	 * @access     public
91
+	 * @static
92
+	 * @param $table_name
93
+	 * @return string
94
+	 */
95
+	public static function ensure_table_name_has_prefix($table_name)
96
+	{
97
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
98
+	}
99
+
100
+
101
+	/**
102
+	 *    system_initialization
103
+	 *    ensures the EE configuration settings are loaded with at least default options set
104
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
105
+	 *
106
+	 * @access public
107
+	 * @static
108
+	 * @return void
109
+	 */
110
+	public static function system_initialization()
111
+	{
112
+		EEH_Activation::reset_and_update_config();
113
+		//which is fired BEFORE activation of plugin anyways
114
+		EEH_Activation::verify_default_pages_exist();
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the database schema and creates folders. This should
120
+	 * be called on plugin activation and reactivation
121
+	 *
122
+	 * @return boolean success, whether the database and folders are setup properly
123
+	 * @throws \EE_Error
124
+	 */
125
+	public static function initialize_db_and_folders()
126
+	{
127
+		$good_filesystem = EEH_Activation::create_upload_directories();
128
+		$good_db         = EEH_Activation::create_database_tables();
129
+		return $good_filesystem && $good_db;
130
+	}
131
+
132
+
133
+	/**
134
+	 * assuming we have an up-to-date database schema, this will populate it
135
+	 * with default and initial data. This should be called
136
+	 * upon activation of a new plugin, reactivation, and at the end
137
+	 * of running migration scripts
138
+	 *
139
+	 * @throws \EE_Error
140
+	 */
141
+	public static function initialize_db_content()
142
+	{
143
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
144
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
145
+			return;
146
+		}
147
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
148
+
149
+		EEH_Activation::initialize_system_questions();
150
+		EEH_Activation::insert_default_status_codes();
151
+		EEH_Activation::generate_default_message_templates();
152
+		EEH_Activation::create_no_ticket_prices_array();
153
+		EEH_Activation::validate_messages_system();
154
+		EEH_Activation::insert_default_payment_methods();
155
+		//in case we've
156
+		EEH_Activation::remove_cron_tasks();
157
+		EEH_Activation::create_cron_tasks();
158
+		// remove all TXN locks since that is being done via extra meta now
159
+		delete_option('ee_locked_transactions');
160
+		//also, check for CAF default db content
161
+		do_action('AHEE__EEH_Activation__initialize_db_content');
162
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
163
+		//which users really won't care about on initial activation
164
+		EE_Error::overwrite_success();
165
+	}
166
+
167
+
168
+	/**
169
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
170
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
171
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
172
+	 * (null)
173
+	 *
174
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
175
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
176
+	 * @return array
177
+	 * @throws \EE_Error
178
+	 */
179
+	public static function get_cron_tasks($which_to_include)
180
+	{
181
+		$cron_tasks = apply_filters(
182
+			'FHEE__EEH_Activation__get_cron_tasks',
183
+			array(
184
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
185 185
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
186
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
187
-                //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
188
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
189
-            )
190
-        );
191
-        if ($which_to_include === 'old') {
192
-            $cron_tasks = array_filter(
193
-                $cron_tasks,
194
-                function ($value) {
195
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
196
-                }
197
-            );
198
-        } elseif ($which_to_include === 'current') {
199
-            $cron_tasks = array_filter($cron_tasks);
200
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
201
-            throw new EE_Error(
202
-                sprintf(
203
-                    __(
204
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
205
-                        'event_espresso'
206
-                    ),
207
-                    $which_to_include
208
-                )
209
-            );
210
-        }
211
-        return $cron_tasks;
212
-    }
213
-
214
-
215
-    /**
216
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
217
-     *
218
-     * @throws \EE_Error
219
-     */
220
-    public static function create_cron_tasks()
221
-    {
222
-
223
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
224
-            if (! wp_next_scheduled($hook_name)) {
225
-                /**
226
-                 * This allows client code to define the initial start timestamp for this schedule.
227
-                 */
228
-                if (is_array($frequency)
229
-                    && count($frequency) === 2
230
-                    && isset($frequency[0], $frequency[1])
231
-                ) {
232
-                    $start_timestamp = $frequency[0];
233
-                    $frequency = $frequency[1];
234
-                } else {
235
-                    $start_timestamp = time();
236
-                }
237
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
238
-            }
239
-        }
240
-
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * Remove the currently-existing and now-removed cron tasks.
247
-     *
248
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
249
-     * @throws \EE_Error
250
-     */
251
-    public static function remove_cron_tasks($remove_all = true)
252
-    {
253
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
254
-        $crons                = _get_cron_array();
255
-        $crons                = is_array($crons) ? $crons : array();
256
-        /* reminder of what $crons look like:
186
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
187
+				//there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
188
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
189
+			)
190
+		);
191
+		if ($which_to_include === 'old') {
192
+			$cron_tasks = array_filter(
193
+				$cron_tasks,
194
+				function ($value) {
195
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
196
+				}
197
+			);
198
+		} elseif ($which_to_include === 'current') {
199
+			$cron_tasks = array_filter($cron_tasks);
200
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
201
+			throw new EE_Error(
202
+				sprintf(
203
+					__(
204
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
205
+						'event_espresso'
206
+					),
207
+					$which_to_include
208
+				)
209
+			);
210
+		}
211
+		return $cron_tasks;
212
+	}
213
+
214
+
215
+	/**
216
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
217
+	 *
218
+	 * @throws \EE_Error
219
+	 */
220
+	public static function create_cron_tasks()
221
+	{
222
+
223
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
224
+			if (! wp_next_scheduled($hook_name)) {
225
+				/**
226
+				 * This allows client code to define the initial start timestamp for this schedule.
227
+				 */
228
+				if (is_array($frequency)
229
+					&& count($frequency) === 2
230
+					&& isset($frequency[0], $frequency[1])
231
+				) {
232
+					$start_timestamp = $frequency[0];
233
+					$frequency = $frequency[1];
234
+				} else {
235
+					$start_timestamp = time();
236
+				}
237
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
238
+			}
239
+		}
240
+
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * Remove the currently-existing and now-removed cron tasks.
247
+	 *
248
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
249
+	 * @throws \EE_Error
250
+	 */
251
+	public static function remove_cron_tasks($remove_all = true)
252
+	{
253
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
254
+		$crons                = _get_cron_array();
255
+		$crons                = is_array($crons) ? $crons : array();
256
+		/* reminder of what $crons look like:
257 257
          * Top-level keys are timestamps, and their values are arrays.
258 258
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
259 259
          * and their values are arrays.
@@ -270,912 +270,912 @@  discard block
 block discarded – undo
270 270
          *					...
271 271
          *      ...
272 272
          */
273
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
274
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
275
-            if (is_array($hooks_to_fire_at_time)) {
276
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
277
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
278
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
279
-                    ) {
280
-                        unset($crons[$timestamp][$hook_name]);
281
-                    }
282
-                }
283
-                //also take care of any empty cron timestamps.
284
-                if (empty($hooks_to_fire_at_time)) {
285
-                    unset($crons[$timestamp]);
286
-                }
287
-            }
288
-        }
289
-        _set_cron_array($crons);
290
-    }
291
-
292
-
293
-    /**
294
-     *    CPT_initialization
295
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
296
-     *
297
-     * @access public
298
-     * @static
299
-     * @return void
300
-     */
301
-    public static function CPT_initialization()
302
-    {
303
-        // register Custom Post Types
304
-        EE_Registry::instance()->load_core('Register_CPTs');
305
-        flush_rewrite_rules();
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     *    reset_and_update_config
312
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
313
-     * If there is old calendar config data saved, then it will get converted on activation.
314
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
315
-     *
316
-     * @access public
317
-     * @static
318
-     * @return void
319
-     */
320
-    public static function reset_and_update_config()
321
-    {
322
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
323
-        add_filter(
324
-            'FHEE__EE_Config___load_core_config__config_settings',
325
-            array('EEH_Activation', 'migrate_old_config_data'),
326
-            10,
327
-            3
328
-        );
329
-        //EE_Config::reset();
330
-        if (! EE_Config::logging_enabled()) {
331
-            delete_option(EE_Config::LOG_NAME);
332
-        }
333
-    }
334
-
335
-
336
-    /**
337
-     *    load_calendar_config
338
-     *
339
-     * @access    public
340
-     * @return    void
341
-     */
342
-    public static function load_calendar_config()
343
-    {
344
-        // grab array of all plugin folders and loop thru it
345
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
346
-        if (empty($plugins)) {
347
-            return;
348
-        }
349
-        foreach ($plugins as $plugin_path) {
350
-            // grab plugin folder name from path
351
-            $plugin = basename($plugin_path);
352
-            // drill down to Espresso plugins
353
-            // then to calendar related plugins
354
-            if (
355
-                strpos($plugin, 'espresso') !== false
356
-                || strpos($plugin, 'Espresso') !== false
357
-                || strpos($plugin, 'ee4') !== false
358
-                || strpos($plugin, 'EE4') !== false
359
-                || strpos($plugin, 'calendar') !== false
360
-            ) {
361
-                // this is what we are looking for
362
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
363
-                // does it exist in this folder ?
364
-                if (is_readable($calendar_config)) {
365
-                    // YEAH! let's load it
366
-                    require_once($calendar_config);
367
-                }
368
-            }
369
-        }
370
-    }
371
-
372
-
373
-
374
-    /**
375
-     *    _migrate_old_config_data
376
-     *
377
-     * @access    public
378
-     * @param array|stdClass $settings
379
-     * @param string         $config
380
-     * @param \EE_Config     $EE_Config
381
-     * @return \stdClass
382
-     */
383
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
384
-    {
385
-        $convert_from_array = array('addons');
386
-        // in case old settings were saved as an array
387
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
388
-            // convert existing settings to an object
389
-            $config_array = $settings;
390
-            $settings = new stdClass();
391
-            foreach ($config_array as $key => $value) {
392
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
393
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
394
-                } else {
395
-                    $settings->{$key} = $value;
396
-                }
397
-            }
398
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
399
-        }
400
-        return $settings;
401
-    }
402
-
403
-
404
-    /**
405
-     * deactivate_event_espresso
406
-     *
407
-     * @access public
408
-     * @static
409
-     * @return void
410
-     */
411
-    public static function deactivate_event_espresso()
412
-    {
413
-        // check permissions
414
-        if (current_user_can('activate_plugins')) {
415
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
416
-        }
417
-    }
418
-
419
-
420
-
421
-
422
-    /**
423
-     * verify_default_pages_exist
424
-     *
425
-     * @access public
426
-     * @static
427
-     * @return void
428
-     */
429
-    public static function verify_default_pages_exist()
430
-    {
431
-        $critical_page_problem = false;
432
-        $critical_pages = array(
433
-            array(
434
-                'id'   => 'reg_page_id',
435
-                'name' => __('Registration Checkout', 'event_espresso'),
436
-                'post' => null,
437
-                'code' => 'ESPRESSO_CHECKOUT',
438
-            ),
439
-            array(
440
-                'id'   => 'txn_page_id',
441
-                'name' => __('Transactions', 'event_espresso'),
442
-                'post' => null,
443
-                'code' => 'ESPRESSO_TXN_PAGE',
444
-            ),
445
-            array(
446
-                'id'   => 'thank_you_page_id',
447
-                'name' => __('Thank You', 'event_espresso'),
448
-                'post' => null,
449
-                'code' => 'ESPRESSO_THANK_YOU',
450
-            ),
451
-            array(
452
-                'id'   => 'cancel_page_id',
453
-                'name' => __('Registration Cancelled', 'event_espresso'),
454
-                'post' => null,
455
-                'code' => 'ESPRESSO_CANCELLED',
456
-            ),
457
-        );
458
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
459
-        foreach ($critical_pages as $critical_page) {
460
-            // is critical page ID set in config ?
461
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
462
-                // attempt to find post by ID
463
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
464
-            }
465
-            // no dice?
466
-            if ($critical_page['post'] === null) {
467
-                // attempt to find post by title
468
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
469
-                // still nothing?
470
-                if ($critical_page['post'] === null) {
471
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
472
-                    // REALLY? Still nothing ??!?!?
473
-                    if ($critical_page['post'] === null) {
474
-                        $msg = __(
475
-                            'The Event Espresso critical page configuration settings could not be updated.',
476
-                            'event_espresso'
477
-                        );
478
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
479
-                        break;
480
-                    }
481
-                }
482
-            }
483
-            // check that Post ID matches critical page ID in config
484
-            if (
485
-                isset($critical_page['post']->ID)
486
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
487
-            ) {
488
-                //update Config with post ID
489
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
490
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
491
-                    $msg = __(
492
-                        'The Event Espresso critical page configuration settings could not be updated.',
493
-                        'event_espresso'
494
-                    );
495
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
496
-                }
497
-            }
498
-            $critical_page_problem =
499
-                ! isset($critical_page['post']->post_status)
500
-                || $critical_page['post']->post_status !== 'publish'
501
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
502
-                    ? true
503
-                    : $critical_page_problem;
504
-        }
505
-        if ($critical_page_problem) {
506
-            $msg = sprintf(
507
-                __(
508
-                    'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
509
-                    'event_espresso'
510
-                ),
511
-                '<a href="'
512
-                . admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
513
-                . '">'
514
-                . __('Event Espresso Critical Pages Settings', 'event_espresso')
515
-                . '</a>'
516
-            );
517
-            EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
518
-        }
519
-        if (EE_Error::has_notices()) {
520
-            EE_Error::get_notices(false, true, true);
521
-        }
522
-    }
523
-
524
-
525
-
526
-    /**
527
-     * Returns the first post which uses the specified shortcode
528
-     *
529
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
530
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
531
-     *                             "[ESPRESSO_THANK_YOU"
532
-     *                             (we don't search for the closing shortcode bracket because they might have added
533
-     *                             parameter to the shortcode
534
-     * @return WP_Post or NULl
535
-     */
536
-    public static function get_page_by_ee_shortcode($ee_shortcode)
537
-    {
538
-        global $wpdb;
539
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
540
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
541
-        if ($post_id) {
542
-            return get_post($post_id);
543
-        } else {
544
-            return null;
545
-        }
546
-    }
547
-
548
-
549
-
550
-    /**
551
-     *    This function generates a post for critical espresso pages
552
-     *
553
-     * @access public
554
-     * @static
555
-     * @param array $critical_page
556
-     * @return array
557
-     */
558
-    public static function create_critical_page($critical_page)
559
-    {
560
-
561
-        $post_args = array(
562
-            'post_title'     => $critical_page['name'],
563
-            'post_status'    => 'publish',
564
-            'post_type'      => 'page',
565
-            'comment_status' => 'closed',
566
-            'post_content'   => '[' . $critical_page['code'] . ']',
567
-        );
568
-
569
-        $post_id = wp_insert_post($post_args);
570
-        if (! $post_id) {
571
-            $msg = sprintf(
572
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
573
-                $critical_page['name']
574
-            );
575
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
576
-            return $critical_page;
577
-        }
578
-        // get newly created post's details
579
-        if (! $critical_page['post'] = get_post($post_id)) {
580
-            $msg = sprintf(
581
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
582
-                $critical_page['name']
583
-            );
584
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
585
-        }
586
-
587
-        return $critical_page;
588
-
589
-    }
590
-
591
-
592
-
593
-
594
-    /**
595
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
596
-     * The role being used to check is filterable.
597
-     *
598
-     * @since  4.6.0
599
-     * @global WPDB $wpdb
600
-     * @return mixed null|int WP_user ID or NULL
601
-     */
602
-    public static function get_default_creator_id()
603
-    {
604
-        global $wpdb;
605
-        if ( ! empty(self::$_default_creator_id)) {
606
-            return self::$_default_creator_id;
607
-        }/**/
608
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
609
-        //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.
610
-        $pre_filtered_id = apply_filters(
611
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
612
-            false,
613
-            $role_to_check
614
-        );
615
-        if ($pre_filtered_id !== false) {
616
-            return (int)$pre_filtered_id;
617
-        }
618
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
619
-        $query = $wpdb->prepare(
620
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
621
-            '%' . $role_to_check . '%'
622
-        );
623
-        $user_id = $wpdb->get_var($query);
624
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
625
-        if ($user_id && (int)$user_id) {
626
-            self::$_default_creator_id = (int)$user_id;
627
-            return self::$_default_creator_id;
628
-        } else {
629
-            return null;
630
-        }
631
-    }
632
-
633
-
634
-
635
-    /**
636
-     * used by EE and EE addons during plugin activation to create tables.
637
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
638
-     * but includes extra logic regarding activations.
639
-     *
640
-     * @access public
641
-     * @static
642
-     * @param string  $table_name              without the $wpdb->prefix
643
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
644
-     *                                         table query)
645
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
646
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
647
-     *                                         and new once this function is done (ie, you really do want to CREATE a
648
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
649
-     *                                         you just want to verify the table exists and matches this definition
650
-     *                                         (and if it HAS data in it you want to leave it be)
651
-     * @return void
652
-     * @throws EE_Error if there are database errors
653
-     */
654
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
655
-    {
656
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
657
-            return;
658
-        }
659
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
660
-        if ( ! function_exists('dbDelta')) {
661
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
662
-        }
663
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
664
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
665
-        // do we need to first delete an existing version of this table ?
666
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
667
-            // ok, delete the table... but ONLY if it's empty
668
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
669
-            // table is NOT empty, are you SURE you want to delete this table ???
670
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
671
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
672
-            } else if ( ! $deleted_safely) {
673
-                // so we should be more cautious rather than just dropping tables so easily
674
-                error_log(
675
-                    sprintf(
676
-                        __(
677
-                            '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.',
678
-                            'event_espresso'
679
-                        ),
680
-                        $wp_table_name,
681
-                        '<br/>',
682
-                        'espresso_db_update'
683
-                    )
684
-                );
685
-            }
686
-        }
687
-        $engine = str_replace('ENGINE=', '', $engine);
688
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
689
-    }
690
-
691
-
692
-
693
-    /**
694
-     *    add_column_if_it_doesn't_exist
695
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
696
-     *
697
-     * @access     public
698
-     * @static
699
-     * @deprecated instead use TableManager::addColumn()
700
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
701
-     * @param string $column_name
702
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
703
-     *                            'VARCHAR(10)'
704
-     * @return bool|int
705
-     */
706
-    public static function add_column_if_it_doesnt_exist(
707
-        $table_name,
708
-        $column_name,
709
-        $column_info = 'INT UNSIGNED NOT NULL'
710
-    ) {
711
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
712
-    }
713
-
714
-
715
-    /**
716
-     * get_fields_on_table
717
-     * Gets all the fields on the database table.
718
-     *
719
-     * @access     public
720
-     * @deprecated instead use TableManager::getTableColumns()
721
-     * @static
722
-     * @param string $table_name , without prefixed $wpdb->prefix
723
-     * @return array of database column names
724
-     */
725
-    public static function get_fields_on_table($table_name = null)
726
-    {
727
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
728
-    }
729
-
730
-
731
-    /**
732
-     * db_table_is_empty
733
-     *
734
-     * @access     public\
735
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
736
-     * @static
737
-     * @param string $table_name
738
-     * @return bool
739
-     */
740
-    public static function db_table_is_empty($table_name)
741
-    {
742
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
743
-    }
744
-
745
-
746
-    /**
747
-     * delete_db_table_if_empty
748
-     *
749
-     * @access public
750
-     * @static
751
-     * @param string $table_name
752
-     * @return bool | int
753
-     */
754
-    public static function delete_db_table_if_empty($table_name)
755
-    {
756
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
757
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
758
-        }
759
-        return false;
760
-    }
761
-
762
-
763
-    /**
764
-     * delete_unused_db_table
765
-     *
766
-     * @access     public
767
-     * @static
768
-     * @deprecated instead use TableManager::dropTable()
769
-     * @param string $table_name
770
-     * @return bool | int
771
-     */
772
-    public static function delete_unused_db_table($table_name)
773
-    {
774
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
775
-    }
776
-
777
-
778
-    /**
779
-     * drop_index
780
-     *
781
-     * @access     public
782
-     * @static
783
-     * @deprecated instead use TableManager::dropIndex()
784
-     * @param string $table_name
785
-     * @param string $index_name
786
-     * @return bool | int
787
-     */
788
-    public static function drop_index($table_name, $index_name)
789
-    {
790
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
791
-    }
792
-
793
-
794
-
795
-    /**
796
-     * create_database_tables
797
-     *
798
-     * @access public
799
-     * @static
800
-     * @throws EE_Error
801
-     * @return boolean success (whether database is setup properly or not)
802
-     */
803
-    public static function create_database_tables()
804
-    {
805
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
806
-        //find the migration script that sets the database to be compatible with the code
807
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
808
-        if ($dms_name) {
809
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
810
-            $current_data_migration_script->set_migrating(false);
811
-            $current_data_migration_script->schema_changes_before_migration();
812
-            $current_data_migration_script->schema_changes_after_migration();
813
-            if ($current_data_migration_script->get_errors()) {
814
-                if (WP_DEBUG) {
815
-                    foreach ($current_data_migration_script->get_errors() as $error) {
816
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
817
-                    }
818
-                } else {
819
-                    EE_Error::add_error(
820
-                        __(
821
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
273
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
274
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
275
+			if (is_array($hooks_to_fire_at_time)) {
276
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
277
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
278
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
279
+					) {
280
+						unset($crons[$timestamp][$hook_name]);
281
+					}
282
+				}
283
+				//also take care of any empty cron timestamps.
284
+				if (empty($hooks_to_fire_at_time)) {
285
+					unset($crons[$timestamp]);
286
+				}
287
+			}
288
+		}
289
+		_set_cron_array($crons);
290
+	}
291
+
292
+
293
+	/**
294
+	 *    CPT_initialization
295
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
296
+	 *
297
+	 * @access public
298
+	 * @static
299
+	 * @return void
300
+	 */
301
+	public static function CPT_initialization()
302
+	{
303
+		// register Custom Post Types
304
+		EE_Registry::instance()->load_core('Register_CPTs');
305
+		flush_rewrite_rules();
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 *    reset_and_update_config
312
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
313
+	 * If there is old calendar config data saved, then it will get converted on activation.
314
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
315
+	 *
316
+	 * @access public
317
+	 * @static
318
+	 * @return void
319
+	 */
320
+	public static function reset_and_update_config()
321
+	{
322
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
323
+		add_filter(
324
+			'FHEE__EE_Config___load_core_config__config_settings',
325
+			array('EEH_Activation', 'migrate_old_config_data'),
326
+			10,
327
+			3
328
+		);
329
+		//EE_Config::reset();
330
+		if (! EE_Config::logging_enabled()) {
331
+			delete_option(EE_Config::LOG_NAME);
332
+		}
333
+	}
334
+
335
+
336
+	/**
337
+	 *    load_calendar_config
338
+	 *
339
+	 * @access    public
340
+	 * @return    void
341
+	 */
342
+	public static function load_calendar_config()
343
+	{
344
+		// grab array of all plugin folders and loop thru it
345
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
346
+		if (empty($plugins)) {
347
+			return;
348
+		}
349
+		foreach ($plugins as $plugin_path) {
350
+			// grab plugin folder name from path
351
+			$plugin = basename($plugin_path);
352
+			// drill down to Espresso plugins
353
+			// then to calendar related plugins
354
+			if (
355
+				strpos($plugin, 'espresso') !== false
356
+				|| strpos($plugin, 'Espresso') !== false
357
+				|| strpos($plugin, 'ee4') !== false
358
+				|| strpos($plugin, 'EE4') !== false
359
+				|| strpos($plugin, 'calendar') !== false
360
+			) {
361
+				// this is what we are looking for
362
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
363
+				// does it exist in this folder ?
364
+				if (is_readable($calendar_config)) {
365
+					// YEAH! let's load it
366
+					require_once($calendar_config);
367
+				}
368
+			}
369
+		}
370
+	}
371
+
372
+
373
+
374
+	/**
375
+	 *    _migrate_old_config_data
376
+	 *
377
+	 * @access    public
378
+	 * @param array|stdClass $settings
379
+	 * @param string         $config
380
+	 * @param \EE_Config     $EE_Config
381
+	 * @return \stdClass
382
+	 */
383
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
384
+	{
385
+		$convert_from_array = array('addons');
386
+		// in case old settings were saved as an array
387
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
388
+			// convert existing settings to an object
389
+			$config_array = $settings;
390
+			$settings = new stdClass();
391
+			foreach ($config_array as $key => $value) {
392
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
393
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
394
+				} else {
395
+					$settings->{$key} = $value;
396
+				}
397
+			}
398
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
399
+		}
400
+		return $settings;
401
+	}
402
+
403
+
404
+	/**
405
+	 * deactivate_event_espresso
406
+	 *
407
+	 * @access public
408
+	 * @static
409
+	 * @return void
410
+	 */
411
+	public static function deactivate_event_espresso()
412
+	{
413
+		// check permissions
414
+		if (current_user_can('activate_plugins')) {
415
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
416
+		}
417
+	}
418
+
419
+
420
+
421
+
422
+	/**
423
+	 * verify_default_pages_exist
424
+	 *
425
+	 * @access public
426
+	 * @static
427
+	 * @return void
428
+	 */
429
+	public static function verify_default_pages_exist()
430
+	{
431
+		$critical_page_problem = false;
432
+		$critical_pages = array(
433
+			array(
434
+				'id'   => 'reg_page_id',
435
+				'name' => __('Registration Checkout', 'event_espresso'),
436
+				'post' => null,
437
+				'code' => 'ESPRESSO_CHECKOUT',
438
+			),
439
+			array(
440
+				'id'   => 'txn_page_id',
441
+				'name' => __('Transactions', 'event_espresso'),
442
+				'post' => null,
443
+				'code' => 'ESPRESSO_TXN_PAGE',
444
+			),
445
+			array(
446
+				'id'   => 'thank_you_page_id',
447
+				'name' => __('Thank You', 'event_espresso'),
448
+				'post' => null,
449
+				'code' => 'ESPRESSO_THANK_YOU',
450
+			),
451
+			array(
452
+				'id'   => 'cancel_page_id',
453
+				'name' => __('Registration Cancelled', 'event_espresso'),
454
+				'post' => null,
455
+				'code' => 'ESPRESSO_CANCELLED',
456
+			),
457
+		);
458
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
459
+		foreach ($critical_pages as $critical_page) {
460
+			// is critical page ID set in config ?
461
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
462
+				// attempt to find post by ID
463
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
464
+			}
465
+			// no dice?
466
+			if ($critical_page['post'] === null) {
467
+				// attempt to find post by title
468
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
469
+				// still nothing?
470
+				if ($critical_page['post'] === null) {
471
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
472
+					// REALLY? Still nothing ??!?!?
473
+					if ($critical_page['post'] === null) {
474
+						$msg = __(
475
+							'The Event Espresso critical page configuration settings could not be updated.',
476
+							'event_espresso'
477
+						);
478
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
479
+						break;
480
+					}
481
+				}
482
+			}
483
+			// check that Post ID matches critical page ID in config
484
+			if (
485
+				isset($critical_page['post']->ID)
486
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
487
+			) {
488
+				//update Config with post ID
489
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
490
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
491
+					$msg = __(
492
+						'The Event Espresso critical page configuration settings could not be updated.',
493
+						'event_espresso'
494
+					);
495
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
496
+				}
497
+			}
498
+			$critical_page_problem =
499
+				! isset($critical_page['post']->post_status)
500
+				|| $critical_page['post']->post_status !== 'publish'
501
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
502
+					? true
503
+					: $critical_page_problem;
504
+		}
505
+		if ($critical_page_problem) {
506
+			$msg = sprintf(
507
+				__(
508
+					'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
509
+					'event_espresso'
510
+				),
511
+				'<a href="'
512
+				. admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
513
+				. '">'
514
+				. __('Event Espresso Critical Pages Settings', 'event_espresso')
515
+				. '</a>'
516
+			);
517
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
518
+		}
519
+		if (EE_Error::has_notices()) {
520
+			EE_Error::get_notices(false, true, true);
521
+		}
522
+	}
523
+
524
+
525
+
526
+	/**
527
+	 * Returns the first post which uses the specified shortcode
528
+	 *
529
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
530
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
531
+	 *                             "[ESPRESSO_THANK_YOU"
532
+	 *                             (we don't search for the closing shortcode bracket because they might have added
533
+	 *                             parameter to the shortcode
534
+	 * @return WP_Post or NULl
535
+	 */
536
+	public static function get_page_by_ee_shortcode($ee_shortcode)
537
+	{
538
+		global $wpdb;
539
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
540
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
541
+		if ($post_id) {
542
+			return get_post($post_id);
543
+		} else {
544
+			return null;
545
+		}
546
+	}
547
+
548
+
549
+
550
+	/**
551
+	 *    This function generates a post for critical espresso pages
552
+	 *
553
+	 * @access public
554
+	 * @static
555
+	 * @param array $critical_page
556
+	 * @return array
557
+	 */
558
+	public static function create_critical_page($critical_page)
559
+	{
560
+
561
+		$post_args = array(
562
+			'post_title'     => $critical_page['name'],
563
+			'post_status'    => 'publish',
564
+			'post_type'      => 'page',
565
+			'comment_status' => 'closed',
566
+			'post_content'   => '[' . $critical_page['code'] . ']',
567
+		);
568
+
569
+		$post_id = wp_insert_post($post_args);
570
+		if (! $post_id) {
571
+			$msg = sprintf(
572
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
573
+				$critical_page['name']
574
+			);
575
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
576
+			return $critical_page;
577
+		}
578
+		// get newly created post's details
579
+		if (! $critical_page['post'] = get_post($post_id)) {
580
+			$msg = sprintf(
581
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
582
+				$critical_page['name']
583
+			);
584
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
585
+		}
586
+
587
+		return $critical_page;
588
+
589
+	}
590
+
591
+
592
+
593
+
594
+	/**
595
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
596
+	 * The role being used to check is filterable.
597
+	 *
598
+	 * @since  4.6.0
599
+	 * @global WPDB $wpdb
600
+	 * @return mixed null|int WP_user ID or NULL
601
+	 */
602
+	public static function get_default_creator_id()
603
+	{
604
+		global $wpdb;
605
+		if ( ! empty(self::$_default_creator_id)) {
606
+			return self::$_default_creator_id;
607
+		}/**/
608
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
609
+		//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.
610
+		$pre_filtered_id = apply_filters(
611
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
612
+			false,
613
+			$role_to_check
614
+		);
615
+		if ($pre_filtered_id !== false) {
616
+			return (int)$pre_filtered_id;
617
+		}
618
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
619
+		$query = $wpdb->prepare(
620
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
621
+			'%' . $role_to_check . '%'
622
+		);
623
+		$user_id = $wpdb->get_var($query);
624
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
625
+		if ($user_id && (int)$user_id) {
626
+			self::$_default_creator_id = (int)$user_id;
627
+			return self::$_default_creator_id;
628
+		} else {
629
+			return null;
630
+		}
631
+	}
632
+
633
+
634
+
635
+	/**
636
+	 * used by EE and EE addons during plugin activation to create tables.
637
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
638
+	 * but includes extra logic regarding activations.
639
+	 *
640
+	 * @access public
641
+	 * @static
642
+	 * @param string  $table_name              without the $wpdb->prefix
643
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
644
+	 *                                         table query)
645
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
646
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
647
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
648
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
649
+	 *                                         you just want to verify the table exists and matches this definition
650
+	 *                                         (and if it HAS data in it you want to leave it be)
651
+	 * @return void
652
+	 * @throws EE_Error if there are database errors
653
+	 */
654
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
655
+	{
656
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
657
+			return;
658
+		}
659
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
660
+		if ( ! function_exists('dbDelta')) {
661
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
662
+		}
663
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
664
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
665
+		// do we need to first delete an existing version of this table ?
666
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
667
+			// ok, delete the table... but ONLY if it's empty
668
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
669
+			// table is NOT empty, are you SURE you want to delete this table ???
670
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
671
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
672
+			} else if ( ! $deleted_safely) {
673
+				// so we should be more cautious rather than just dropping tables so easily
674
+				error_log(
675
+					sprintf(
676
+						__(
677
+							'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.',
678
+							'event_espresso'
679
+						),
680
+						$wp_table_name,
681
+						'<br/>',
682
+						'espresso_db_update'
683
+					)
684
+				);
685
+			}
686
+		}
687
+		$engine = str_replace('ENGINE=', '', $engine);
688
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
689
+	}
690
+
691
+
692
+
693
+	/**
694
+	 *    add_column_if_it_doesn't_exist
695
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
696
+	 *
697
+	 * @access     public
698
+	 * @static
699
+	 * @deprecated instead use TableManager::addColumn()
700
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
701
+	 * @param string $column_name
702
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
703
+	 *                            'VARCHAR(10)'
704
+	 * @return bool|int
705
+	 */
706
+	public static function add_column_if_it_doesnt_exist(
707
+		$table_name,
708
+		$column_name,
709
+		$column_info = 'INT UNSIGNED NOT NULL'
710
+	) {
711
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
712
+	}
713
+
714
+
715
+	/**
716
+	 * get_fields_on_table
717
+	 * Gets all the fields on the database table.
718
+	 *
719
+	 * @access     public
720
+	 * @deprecated instead use TableManager::getTableColumns()
721
+	 * @static
722
+	 * @param string $table_name , without prefixed $wpdb->prefix
723
+	 * @return array of database column names
724
+	 */
725
+	public static function get_fields_on_table($table_name = null)
726
+	{
727
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
728
+	}
729
+
730
+
731
+	/**
732
+	 * db_table_is_empty
733
+	 *
734
+	 * @access     public\
735
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
736
+	 * @static
737
+	 * @param string $table_name
738
+	 * @return bool
739
+	 */
740
+	public static function db_table_is_empty($table_name)
741
+	{
742
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
743
+	}
744
+
745
+
746
+	/**
747
+	 * delete_db_table_if_empty
748
+	 *
749
+	 * @access public
750
+	 * @static
751
+	 * @param string $table_name
752
+	 * @return bool | int
753
+	 */
754
+	public static function delete_db_table_if_empty($table_name)
755
+	{
756
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
757
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
758
+		}
759
+		return false;
760
+	}
761
+
762
+
763
+	/**
764
+	 * delete_unused_db_table
765
+	 *
766
+	 * @access     public
767
+	 * @static
768
+	 * @deprecated instead use TableManager::dropTable()
769
+	 * @param string $table_name
770
+	 * @return bool | int
771
+	 */
772
+	public static function delete_unused_db_table($table_name)
773
+	{
774
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
775
+	}
776
+
777
+
778
+	/**
779
+	 * drop_index
780
+	 *
781
+	 * @access     public
782
+	 * @static
783
+	 * @deprecated instead use TableManager::dropIndex()
784
+	 * @param string $table_name
785
+	 * @param string $index_name
786
+	 * @return bool | int
787
+	 */
788
+	public static function drop_index($table_name, $index_name)
789
+	{
790
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
791
+	}
792
+
793
+
794
+
795
+	/**
796
+	 * create_database_tables
797
+	 *
798
+	 * @access public
799
+	 * @static
800
+	 * @throws EE_Error
801
+	 * @return boolean success (whether database is setup properly or not)
802
+	 */
803
+	public static function create_database_tables()
804
+	{
805
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
806
+		//find the migration script that sets the database to be compatible with the code
807
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
808
+		if ($dms_name) {
809
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
810
+			$current_data_migration_script->set_migrating(false);
811
+			$current_data_migration_script->schema_changes_before_migration();
812
+			$current_data_migration_script->schema_changes_after_migration();
813
+			if ($current_data_migration_script->get_errors()) {
814
+				if (WP_DEBUG) {
815
+					foreach ($current_data_migration_script->get_errors() as $error) {
816
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
817
+					}
818
+				} else {
819
+					EE_Error::add_error(
820
+						__(
821
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
822 822
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
823
-                            'event_espresso'
824
-                        )
825
-                    );
826
-                }
827
-                return false;
828
-            }
829
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
830
-        } else {
831
-            EE_Error::add_error(
832
-                __(
833
-                    'Could not determine most up-to-date data migration script from which to pull database schema
823
+							'event_espresso'
824
+						)
825
+					);
826
+				}
827
+				return false;
828
+			}
829
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
830
+		} else {
831
+			EE_Error::add_error(
832
+				__(
833
+					'Could not determine most up-to-date data migration script from which to pull database schema
834 834
                      structure. So database is probably not setup properly',
835
-                    'event_espresso'
836
-                ),
837
-                __FILE__,
838
-                __FUNCTION__,
839
-                __LINE__
840
-            );
841
-            return false;
842
-        }
843
-        return true;
844
-    }
845
-
846
-
847
-
848
-    /**
849
-     * initialize_system_questions
850
-     *
851
-     * @access public
852
-     * @static
853
-     * @return void
854
-     */
855
-    public static function initialize_system_questions()
856
-    {
857
-        // QUESTION GROUPS
858
-        global $wpdb;
859
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
860
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
861
-        // what we have
862
-        $question_groups = $wpdb->get_col($SQL);
863
-        // check the response
864
-        $question_groups = is_array($question_groups) ? $question_groups : array();
865
-        // what we should have
866
-        $QSG_systems = array(1, 2);
867
-        // loop thru what we should have and compare to what we have
868
-        foreach ($QSG_systems as $QSG_system) {
869
-            // reset values array
870
-            $QSG_values = array();
871
-            // 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)
872
-            if (! in_array("$QSG_system", $question_groups)) {
873
-                // add it
874
-                switch ($QSG_system) {
875
-                    case 1:
876
-                        $QSG_values = array(
877
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
878
-                            'QSG_identifier'      => 'personal-information-' . time(),
879
-                            'QSG_desc'            => '',
880
-                            'QSG_order'           => 1,
881
-                            'QSG_show_group_name' => 1,
882
-                            'QSG_show_group_desc' => 1,
883
-                            'QSG_system'          => EEM_Question_Group::system_personal,
884
-                            'QSG_deleted'         => 0,
885
-                        );
886
-                        break;
887
-                    case 2:
888
-                        $QSG_values = array(
889
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
890
-                            'QSG_identifier'      => 'address-information-' . time(),
891
-                            'QSG_desc'            => '',
892
-                            'QSG_order'           => 2,
893
-                            'QSG_show_group_name' => 1,
894
-                            'QSG_show_group_desc' => 1,
895
-                            'QSG_system'          => EEM_Question_Group::system_address,
896
-                            'QSG_deleted'         => 0,
897
-                        );
898
-                        break;
899
-                }
900
-                // make sure we have some values before inserting them
901
-                if (! empty($QSG_values)) {
902
-                    // insert system question
903
-                    $wpdb->insert(
904
-                        $table_name,
905
-                        $QSG_values,
906
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
907
-                    );
908
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
909
-                }
910
-            }
911
-        }
912
-        // QUESTIONS
913
-        global $wpdb;
914
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
915
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
916
-        // what we have
917
-        $questions = $wpdb->get_col($SQL);
918
-        // what we should have
919
-        $QST_systems = array(
920
-            'fname',
921
-            'lname',
922
-            'email',
923
-            'address',
924
-            'address2',
925
-            'city',
926
-            'country',
927
-            'state',
928
-            'zip',
929
-            'phone',
930
-        );
931
-        $order_for_group_1 = 1;
932
-        $order_for_group_2 = 1;
933
-        // loop thru what we should have and compare to what we have
934
-        foreach ($QST_systems as $QST_system) {
935
-            // reset values array
936
-            $QST_values = array();
937
-            // if we don't have what we should have
938
-            if (! in_array($QST_system, $questions)) {
939
-                // add it
940
-                switch ($QST_system) {
941
-                    case 'fname':
942
-                        $QST_values = array(
943
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
944
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
945
-                            'QST_system'        => 'fname',
946
-                            'QST_type'          => 'TEXT',
947
-                            'QST_required'      => 1,
948
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
949
-                            'QST_order'         => 1,
950
-                            'QST_admin_only'    => 0,
951
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
952
-                            'QST_wp_user'       => self::get_default_creator_id(),
953
-                            'QST_deleted'       => 0,
954
-                        );
955
-                        break;
956
-                    case 'lname':
957
-                        $QST_values = array(
958
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
959
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
960
-                            'QST_system'        => 'lname',
961
-                            'QST_type'          => 'TEXT',
962
-                            'QST_required'      => 1,
963
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
964
-                            'QST_order'         => 2,
965
-                            'QST_admin_only'    => 0,
966
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
967
-                            'QST_wp_user'       => self::get_default_creator_id(),
968
-                            'QST_deleted'       => 0,
969
-                        );
970
-                        break;
971
-                    case 'email':
972
-                        $QST_values = array(
973
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
974
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
975
-                            'QST_system'        => 'email',
976
-                            'QST_type'          => 'EMAIL',
977
-                            'QST_required'      => 1,
978
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
979
-                            'QST_order'         => 3,
980
-                            'QST_admin_only'    => 0,
981
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
982
-                            'QST_wp_user'       => self::get_default_creator_id(),
983
-                            'QST_deleted'       => 0,
984
-                        );
985
-                        break;
986
-                    case 'address':
987
-                        $QST_values = array(
988
-                            'QST_display_text'  => __('Address', 'event_espresso'),
989
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
990
-                            'QST_system'        => 'address',
991
-                            'QST_type'          => 'TEXT',
992
-                            'QST_required'      => 0,
993
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
994
-                            'QST_order'         => 4,
995
-                            'QST_admin_only'    => 0,
996
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
997
-                            'QST_wp_user'       => self::get_default_creator_id(),
998
-                            'QST_deleted'       => 0,
999
-                        );
1000
-                        break;
1001
-                    case 'address2':
1002
-                        $QST_values = array(
1003
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1004
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1005
-                            'QST_system'        => 'address2',
1006
-                            'QST_type'          => 'TEXT',
1007
-                            'QST_required'      => 0,
1008
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1009
-                            'QST_order'         => 5,
1010
-                            'QST_admin_only'    => 0,
1011
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1012
-                            'QST_wp_user'       => self::get_default_creator_id(),
1013
-                            'QST_deleted'       => 0,
1014
-                        );
1015
-                        break;
1016
-                    case 'city':
1017
-                        $QST_values = array(
1018
-                            'QST_display_text'  => __('City', 'event_espresso'),
1019
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1020
-                            'QST_system'        => 'city',
1021
-                            'QST_type'          => 'TEXT',
1022
-                            'QST_required'      => 0,
1023
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1024
-                            'QST_order'         => 6,
1025
-                            'QST_admin_only'    => 0,
1026
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1027
-                            'QST_wp_user'       => self::get_default_creator_id(),
1028
-                            'QST_deleted'       => 0,
1029
-                        );
1030
-                        break;
1031
-                    case 'country':
1032
-                        $QST_values = array(
1033
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1034
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1035
-                            'QST_system'        => 'country',
1036
-                            'QST_type'          => 'COUNTRY',
1037
-                            'QST_required'      => 0,
1038
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1039
-                            'QST_order'         => 7,
1040
-                            'QST_admin_only'    => 0,
1041
-                            'QST_wp_user'       => self::get_default_creator_id(),
1042
-                            'QST_deleted'       => 0,
1043
-                        );
1044
-                        break;
1045
-                    case 'state':
1046
-                        $QST_values = array(
1047
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1048
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1049
-                            'QST_system'        => 'state',
1050
-                            'QST_type'          => 'STATE',
1051
-                            'QST_required'      => 0,
1052
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1053
-                            'QST_order'         => 8,
1054
-                            'QST_admin_only'    => 0,
1055
-                            'QST_wp_user'       => self::get_default_creator_id(),
1056
-                            'QST_deleted'       => 0,
1057
-                        );
1058
-                        break;
1059
-                    case 'zip':
1060
-                        $QST_values = array(
1061
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1062
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1063
-                            'QST_system'        => 'zip',
1064
-                            'QST_type'          => 'TEXT',
1065
-                            'QST_required'      => 0,
1066
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1067
-                            'QST_order'         => 9,
1068
-                            'QST_admin_only'    => 0,
1069
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1070
-                            'QST_wp_user'       => self::get_default_creator_id(),
1071
-                            'QST_deleted'       => 0,
1072
-                        );
1073
-                        break;
1074
-                    case 'phone':
1075
-                        $QST_values = array(
1076
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1077
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1078
-                            'QST_system'        => 'phone',
1079
-                            'QST_type'          => 'TEXT',
1080
-                            'QST_required'      => 0,
1081
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1082
-                            'QST_order'         => 10,
1083
-                            'QST_admin_only'    => 0,
1084
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1085
-                            'QST_wp_user'       => self::get_default_creator_id(),
1086
-                            'QST_deleted'       => 0,
1087
-                        );
1088
-                        break;
1089
-                }
1090
-                if (! empty($QST_values)) {
1091
-                    // insert system question
1092
-                    $wpdb->insert(
1093
-                        $table_name,
1094
-                        $QST_values,
1095
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1096
-                    );
1097
-                    $QST_ID = $wpdb->insert_id;
1098
-                    // QUESTION GROUP QUESTIONS
1099
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1100
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1101
-                    } else {
1102
-                        $system_question_we_want = EEM_Question_Group::system_address;
1103
-                    }
1104
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1105
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1106
-                    } else {
1107
-                        $id_col = EEM_Question_Group::instance()
1108
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1109
-                        if (is_array($id_col)) {
1110
-                            $QSG_ID = reset($id_col);
1111
-                        } else {
1112
-                            //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
1113
-                            EE_Log::instance()->log(
1114
-                                __FILE__,
1115
-                                __FUNCTION__,
1116
-                                sprintf(
1117
-                                    __(
1118
-                                        'Could not associate question %1$s to a question group because no system question
835
+					'event_espresso'
836
+				),
837
+				__FILE__,
838
+				__FUNCTION__,
839
+				__LINE__
840
+			);
841
+			return false;
842
+		}
843
+		return true;
844
+	}
845
+
846
+
847
+
848
+	/**
849
+	 * initialize_system_questions
850
+	 *
851
+	 * @access public
852
+	 * @static
853
+	 * @return void
854
+	 */
855
+	public static function initialize_system_questions()
856
+	{
857
+		// QUESTION GROUPS
858
+		global $wpdb;
859
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
860
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
861
+		// what we have
862
+		$question_groups = $wpdb->get_col($SQL);
863
+		// check the response
864
+		$question_groups = is_array($question_groups) ? $question_groups : array();
865
+		// what we should have
866
+		$QSG_systems = array(1, 2);
867
+		// loop thru what we should have and compare to what we have
868
+		foreach ($QSG_systems as $QSG_system) {
869
+			// reset values array
870
+			$QSG_values = array();
871
+			// 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)
872
+			if (! in_array("$QSG_system", $question_groups)) {
873
+				// add it
874
+				switch ($QSG_system) {
875
+					case 1:
876
+						$QSG_values = array(
877
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
878
+							'QSG_identifier'      => 'personal-information-' . time(),
879
+							'QSG_desc'            => '',
880
+							'QSG_order'           => 1,
881
+							'QSG_show_group_name' => 1,
882
+							'QSG_show_group_desc' => 1,
883
+							'QSG_system'          => EEM_Question_Group::system_personal,
884
+							'QSG_deleted'         => 0,
885
+						);
886
+						break;
887
+					case 2:
888
+						$QSG_values = array(
889
+							'QSG_name'            => __('Address Information', 'event_espresso'),
890
+							'QSG_identifier'      => 'address-information-' . time(),
891
+							'QSG_desc'            => '',
892
+							'QSG_order'           => 2,
893
+							'QSG_show_group_name' => 1,
894
+							'QSG_show_group_desc' => 1,
895
+							'QSG_system'          => EEM_Question_Group::system_address,
896
+							'QSG_deleted'         => 0,
897
+						);
898
+						break;
899
+				}
900
+				// make sure we have some values before inserting them
901
+				if (! empty($QSG_values)) {
902
+					// insert system question
903
+					$wpdb->insert(
904
+						$table_name,
905
+						$QSG_values,
906
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
907
+					);
908
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
909
+				}
910
+			}
911
+		}
912
+		// QUESTIONS
913
+		global $wpdb;
914
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
915
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
916
+		// what we have
917
+		$questions = $wpdb->get_col($SQL);
918
+		// what we should have
919
+		$QST_systems = array(
920
+			'fname',
921
+			'lname',
922
+			'email',
923
+			'address',
924
+			'address2',
925
+			'city',
926
+			'country',
927
+			'state',
928
+			'zip',
929
+			'phone',
930
+		);
931
+		$order_for_group_1 = 1;
932
+		$order_for_group_2 = 1;
933
+		// loop thru what we should have and compare to what we have
934
+		foreach ($QST_systems as $QST_system) {
935
+			// reset values array
936
+			$QST_values = array();
937
+			// if we don't have what we should have
938
+			if (! in_array($QST_system, $questions)) {
939
+				// add it
940
+				switch ($QST_system) {
941
+					case 'fname':
942
+						$QST_values = array(
943
+							'QST_display_text'  => __('First Name', 'event_espresso'),
944
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
945
+							'QST_system'        => 'fname',
946
+							'QST_type'          => 'TEXT',
947
+							'QST_required'      => 1,
948
+							'QST_required_text' => __('This field is required', 'event_espresso'),
949
+							'QST_order'         => 1,
950
+							'QST_admin_only'    => 0,
951
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
952
+							'QST_wp_user'       => self::get_default_creator_id(),
953
+							'QST_deleted'       => 0,
954
+						);
955
+						break;
956
+					case 'lname':
957
+						$QST_values = array(
958
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
959
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
960
+							'QST_system'        => 'lname',
961
+							'QST_type'          => 'TEXT',
962
+							'QST_required'      => 1,
963
+							'QST_required_text' => __('This field is required', 'event_espresso'),
964
+							'QST_order'         => 2,
965
+							'QST_admin_only'    => 0,
966
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
967
+							'QST_wp_user'       => self::get_default_creator_id(),
968
+							'QST_deleted'       => 0,
969
+						);
970
+						break;
971
+					case 'email':
972
+						$QST_values = array(
973
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
974
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
975
+							'QST_system'        => 'email',
976
+							'QST_type'          => 'EMAIL',
977
+							'QST_required'      => 1,
978
+							'QST_required_text' => __('This field is required', 'event_espresso'),
979
+							'QST_order'         => 3,
980
+							'QST_admin_only'    => 0,
981
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
982
+							'QST_wp_user'       => self::get_default_creator_id(),
983
+							'QST_deleted'       => 0,
984
+						);
985
+						break;
986
+					case 'address':
987
+						$QST_values = array(
988
+							'QST_display_text'  => __('Address', 'event_espresso'),
989
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
990
+							'QST_system'        => 'address',
991
+							'QST_type'          => 'TEXT',
992
+							'QST_required'      => 0,
993
+							'QST_required_text' => __('This field is required', 'event_espresso'),
994
+							'QST_order'         => 4,
995
+							'QST_admin_only'    => 0,
996
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
997
+							'QST_wp_user'       => self::get_default_creator_id(),
998
+							'QST_deleted'       => 0,
999
+						);
1000
+						break;
1001
+					case 'address2':
1002
+						$QST_values = array(
1003
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1004
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1005
+							'QST_system'        => 'address2',
1006
+							'QST_type'          => 'TEXT',
1007
+							'QST_required'      => 0,
1008
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1009
+							'QST_order'         => 5,
1010
+							'QST_admin_only'    => 0,
1011
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1012
+							'QST_wp_user'       => self::get_default_creator_id(),
1013
+							'QST_deleted'       => 0,
1014
+						);
1015
+						break;
1016
+					case 'city':
1017
+						$QST_values = array(
1018
+							'QST_display_text'  => __('City', 'event_espresso'),
1019
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1020
+							'QST_system'        => 'city',
1021
+							'QST_type'          => 'TEXT',
1022
+							'QST_required'      => 0,
1023
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1024
+							'QST_order'         => 6,
1025
+							'QST_admin_only'    => 0,
1026
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1027
+							'QST_wp_user'       => self::get_default_creator_id(),
1028
+							'QST_deleted'       => 0,
1029
+						);
1030
+						break;
1031
+					case 'country':
1032
+						$QST_values = array(
1033
+							'QST_display_text'  => __('Country', 'event_espresso'),
1034
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1035
+							'QST_system'        => 'country',
1036
+							'QST_type'          => 'COUNTRY',
1037
+							'QST_required'      => 0,
1038
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1039
+							'QST_order'         => 7,
1040
+							'QST_admin_only'    => 0,
1041
+							'QST_wp_user'       => self::get_default_creator_id(),
1042
+							'QST_deleted'       => 0,
1043
+						);
1044
+						break;
1045
+					case 'state':
1046
+						$QST_values = array(
1047
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1048
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1049
+							'QST_system'        => 'state',
1050
+							'QST_type'          => 'STATE',
1051
+							'QST_required'      => 0,
1052
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1053
+							'QST_order'         => 8,
1054
+							'QST_admin_only'    => 0,
1055
+							'QST_wp_user'       => self::get_default_creator_id(),
1056
+							'QST_deleted'       => 0,
1057
+						);
1058
+						break;
1059
+					case 'zip':
1060
+						$QST_values = array(
1061
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1062
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1063
+							'QST_system'        => 'zip',
1064
+							'QST_type'          => 'TEXT',
1065
+							'QST_required'      => 0,
1066
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1067
+							'QST_order'         => 9,
1068
+							'QST_admin_only'    => 0,
1069
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1070
+							'QST_wp_user'       => self::get_default_creator_id(),
1071
+							'QST_deleted'       => 0,
1072
+						);
1073
+						break;
1074
+					case 'phone':
1075
+						$QST_values = array(
1076
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1077
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1078
+							'QST_system'        => 'phone',
1079
+							'QST_type'          => 'TEXT',
1080
+							'QST_required'      => 0,
1081
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1082
+							'QST_order'         => 10,
1083
+							'QST_admin_only'    => 0,
1084
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1085
+							'QST_wp_user'       => self::get_default_creator_id(),
1086
+							'QST_deleted'       => 0,
1087
+						);
1088
+						break;
1089
+				}
1090
+				if (! empty($QST_values)) {
1091
+					// insert system question
1092
+					$wpdb->insert(
1093
+						$table_name,
1094
+						$QST_values,
1095
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1096
+					);
1097
+					$QST_ID = $wpdb->insert_id;
1098
+					// QUESTION GROUP QUESTIONS
1099
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1100
+						$system_question_we_want = EEM_Question_Group::system_personal;
1101
+					} else {
1102
+						$system_question_we_want = EEM_Question_Group::system_address;
1103
+					}
1104
+					if (isset($QSG_IDs[$system_question_we_want])) {
1105
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1106
+					} else {
1107
+						$id_col = EEM_Question_Group::instance()
1108
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1109
+						if (is_array($id_col)) {
1110
+							$QSG_ID = reset($id_col);
1111
+						} else {
1112
+							//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
1113
+							EE_Log::instance()->log(
1114
+								__FILE__,
1115
+								__FUNCTION__,
1116
+								sprintf(
1117
+									__(
1118
+										'Could not associate question %1$s to a question group because no system question
1119 1119
                                          group existed',
1120
-                                        'event_espresso'
1121
-                                    ),
1122
-                                    $QST_ID),
1123
-                                'error');
1124
-                            continue;
1125
-                        }
1126
-                    }
1127
-                    // add system questions to groups
1128
-                    $wpdb->insert(
1129
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1130
-                        array(
1131
-                            'QSG_ID'    => $QSG_ID,
1132
-                            'QST_ID'    => $QST_ID,
1133
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1134
-                        ),
1135
-                        array('%d', '%d', '%d')
1136
-                    );
1137
-                }
1138
-            }
1139
-        }
1140
-    }
1141
-
1142
-
1143
-    /**
1144
-     * Makes sure the default payment method (Invoice) is active.
1145
-     * This used to be done automatically as part of constructing the old gateways config
1146
-     *
1147
-     * @throws \EE_Error
1148
-     */
1149
-    public static function insert_default_payment_methods()
1150
-    {
1151
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1152
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1153
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1154
-        } else {
1155
-            EEM_Payment_Method::instance()->verify_button_urls();
1156
-        }
1157
-    }
1158
-
1159
-    /**
1160
-     * insert_default_status_codes
1161
-     *
1162
-     * @access public
1163
-     * @static
1164
-     * @return void
1165
-     */
1166
-    public static function insert_default_status_codes()
1167
-    {
1168
-
1169
-        global $wpdb;
1170
-
1171
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1172
-
1173
-            $table_name = EEM_Status::instance()->table();
1174
-
1175
-            $SQL = "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' );";
1176
-            $wpdb->query($SQL);
1177
-
1178
-            $SQL = "INSERT INTO $table_name
1120
+										'event_espresso'
1121
+									),
1122
+									$QST_ID),
1123
+								'error');
1124
+							continue;
1125
+						}
1126
+					}
1127
+					// add system questions to groups
1128
+					$wpdb->insert(
1129
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1130
+						array(
1131
+							'QSG_ID'    => $QSG_ID,
1132
+							'QST_ID'    => $QST_ID,
1133
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1134
+						),
1135
+						array('%d', '%d', '%d')
1136
+					);
1137
+				}
1138
+			}
1139
+		}
1140
+	}
1141
+
1142
+
1143
+	/**
1144
+	 * Makes sure the default payment method (Invoice) is active.
1145
+	 * This used to be done automatically as part of constructing the old gateways config
1146
+	 *
1147
+	 * @throws \EE_Error
1148
+	 */
1149
+	public static function insert_default_payment_methods()
1150
+	{
1151
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1152
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1153
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1154
+		} else {
1155
+			EEM_Payment_Method::instance()->verify_button_urls();
1156
+		}
1157
+	}
1158
+
1159
+	/**
1160
+	 * insert_default_status_codes
1161
+	 *
1162
+	 * @access public
1163
+	 * @static
1164
+	 * @return void
1165
+	 */
1166
+	public static function insert_default_status_codes()
1167
+	{
1168
+
1169
+		global $wpdb;
1170
+
1171
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1172
+
1173
+			$table_name = EEM_Status::instance()->table();
1174
+
1175
+			$SQL = "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' );";
1176
+			$wpdb->query($SQL);
1177
+
1178
+			$SQL = "INSERT INTO $table_name
1179 1179
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1180 1180
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1181 1181
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1215,521 +1215,521 @@  discard block
 block discarded – undo
1215 1215
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1216 1216
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1217 1217
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1218
-            $wpdb->query($SQL);
1219
-
1220
-        }
1221
-
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * create_upload_directories
1227
-     * Creates folders in the uploads directory to facilitate addons and templates
1228
-     *
1229
-     * @access public
1230
-     * @static
1231
-     * @return boolean success of verifying upload directories exist
1232
-     */
1233
-    public static function create_upload_directories()
1234
-    {
1235
-        // Create the required folders
1236
-        $folders = array(
1237
-            EVENT_ESPRESSO_TEMPLATE_DIR,
1238
-            EVENT_ESPRESSO_GATEWAY_DIR,
1239
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1240
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1241
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1242
-        );
1243
-        foreach ($folders as $folder) {
1244
-            try {
1245
-                EEH_File::ensure_folder_exists_and_is_writable($folder);
1246
-                @ chmod($folder, 0755);
1247
-            } catch (EE_Error $e) {
1248
-                EE_Error::add_error(
1249
-                    sprintf(
1250
-                        __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1251
-                        $folder,
1252
-                        '<br />' . $e->getMessage()
1253
-                    ),
1254
-                    __FILE__, __FUNCTION__, __LINE__
1255
-                );
1256
-                //indicate we'll need to fix this later
1257
-                update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1258
-                return false;
1259
-            }
1260
-        }
1261
-        //just add the .htaccess file to the logs directory to begin with. Even if logging
1262
-        //is disabled, there might be activation errors recorded in there
1263
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1264
-        //remember EE's folders are all good
1265
-        delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1266
-        return true;
1267
-    }
1268
-
1269
-    /**
1270
-     * Whether the upload directories need to be fixed or not.
1271
-     * If EE is installed but filesystem access isn't initially available,
1272
-     * we need to get the user's filesystem credentials and THEN create them,
1273
-     * so there might be period of time when EE is installed but its
1274
-     * upload directories aren't available. This indicates such a state
1275
-     *
1276
-     * @return boolean
1277
-     */
1278
-    public static function upload_directories_incomplete()
1279
-    {
1280
-        return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     * generate_default_message_templates
1286
-     *
1287
-     * @static
1288
-     * @throws EE_Error
1289
-     * @return bool     true means new templates were created.
1290
-     *                  false means no templates were created.
1291
-     *                  This is NOT an error flag. To check for errors you will want
1292
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1293
-     */
1294
-    public static function generate_default_message_templates()
1295
-    {
1296
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1297
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1298
-        /*
1218
+			$wpdb->query($SQL);
1219
+
1220
+		}
1221
+
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * create_upload_directories
1227
+	 * Creates folders in the uploads directory to facilitate addons and templates
1228
+	 *
1229
+	 * @access public
1230
+	 * @static
1231
+	 * @return boolean success of verifying upload directories exist
1232
+	 */
1233
+	public static function create_upload_directories()
1234
+	{
1235
+		// Create the required folders
1236
+		$folders = array(
1237
+			EVENT_ESPRESSO_TEMPLATE_DIR,
1238
+			EVENT_ESPRESSO_GATEWAY_DIR,
1239
+			EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1240
+			EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1241
+			EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1242
+		);
1243
+		foreach ($folders as $folder) {
1244
+			try {
1245
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1246
+				@ chmod($folder, 0755);
1247
+			} catch (EE_Error $e) {
1248
+				EE_Error::add_error(
1249
+					sprintf(
1250
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1251
+						$folder,
1252
+						'<br />' . $e->getMessage()
1253
+					),
1254
+					__FILE__, __FUNCTION__, __LINE__
1255
+				);
1256
+				//indicate we'll need to fix this later
1257
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1258
+				return false;
1259
+			}
1260
+		}
1261
+		//just add the .htaccess file to the logs directory to begin with. Even if logging
1262
+		//is disabled, there might be activation errors recorded in there
1263
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1264
+		//remember EE's folders are all good
1265
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1266
+		return true;
1267
+	}
1268
+
1269
+	/**
1270
+	 * Whether the upload directories need to be fixed or not.
1271
+	 * If EE is installed but filesystem access isn't initially available,
1272
+	 * we need to get the user's filesystem credentials and THEN create them,
1273
+	 * so there might be period of time when EE is installed but its
1274
+	 * upload directories aren't available. This indicates such a state
1275
+	 *
1276
+	 * @return boolean
1277
+	 */
1278
+	public static function upload_directories_incomplete()
1279
+	{
1280
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 * generate_default_message_templates
1286
+	 *
1287
+	 * @static
1288
+	 * @throws EE_Error
1289
+	 * @return bool     true means new templates were created.
1290
+	 *                  false means no templates were created.
1291
+	 *                  This is NOT an error flag. To check for errors you will want
1292
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1293
+	 */
1294
+	public static function generate_default_message_templates()
1295
+	{
1296
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1297
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1298
+		/*
1299 1299
          * This first method is taking care of ensuring any default messengers
1300 1300
          * that should be made active and have templates generated are done.
1301 1301
          */
1302
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1303
-            $message_resource_manager
1304
-        );
1305
-        /**
1306
-         * This method is verifying there are no NEW default message types
1307
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1308
-         */
1309
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1310
-            $message_resource_manager
1311
-        );
1312
-        //after all is done, let's persist these changes to the db.
1313
-        $message_resource_manager->update_has_activated_messengers_option();
1314
-        $message_resource_manager->update_active_messengers_option();
1315
-        // will return true if either of these are true.  Otherwise will return false.
1316
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1317
-    }
1318
-
1319
-
1320
-
1321
-    /**
1322
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1323
-     * @return array|bool
1324
-     * @throws \EE_Error
1325
-     */
1326
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1327
-        EE_Message_Resource_Manager $message_resource_manager
1328
-    ) {
1329
-        /** @type EE_messenger[] $active_messengers */
1330
-        $active_messengers = $message_resource_manager->active_messengers();
1331
-        $installed_message_types = $message_resource_manager->installed_message_types();
1332
-        $templates_created = false;
1333
-        foreach ($active_messengers as $active_messenger) {
1334
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1335
-            $default_message_type_names_to_activate = array();
1336
-            // looping through each default message type reported by the messenger
1337
-            // and setup the actual message types to activate.
1338
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1339
-                // if already active or has already been activated before we skip
1340
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1341
-                // we also skip if the message type is not installed.
1342
-                if (
1343
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1344
-                        $default_message_type_name_for_messenger,
1345
-                        $active_messenger->name
1346
-                    )
1347
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1348
-                        $active_messenger->name,
1349
-                        $default_message_type_name_for_messenger
1350
-                    )
1351
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1352
-                ) {
1353
-                    continue;
1354
-                }
1355
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1356
-            }
1357
-            //let's activate!
1358
-            $message_resource_manager->ensure_message_types_are_active(
1359
-                $default_message_type_names_to_activate,
1360
-                $active_messenger->name,
1361
-                false
1362
-            );
1363
-            //activate the templates for these message types
1364
-            if ( ! empty($default_message_type_names_to_activate)) {
1365
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1366
-                    $active_messenger->name,
1367
-                    $default_message_type_names_for_messenger,
1368
-                    '',
1369
-                    true
1370
-                );
1371
-            }
1372
-        }
1373
-        return $templates_created;
1374
-    }
1375
-
1376
-
1377
-
1378
-    /**
1379
-     * This will activate and generate default messengers and default message types for those messengers.
1380
-     *
1381
-     * @param EE_message_Resource_Manager $message_resource_manager
1382
-     * @return array|bool  True means there were default messengers and message type templates generated.
1383
-     *                     False means that there were no templates generated
1384
-     *                     (which could simply mean there are no default message types for a messenger).
1385
-     * @throws EE_Error
1386
-     */
1387
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1388
-        EE_Message_Resource_Manager $message_resource_manager
1389
-    ) {
1390
-        /** @type EE_messenger[] $messengers_to_generate */
1391
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1392
-        $installed_message_types = $message_resource_manager->installed_message_types();
1393
-        $templates_generated = false;
1394
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1395
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1396
-            //verify the default message types match an installed message type.
1397
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1398
-                if (
1399
-                    ! isset($installed_message_types[$name])
1400
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1401
-                        $name,
1402
-                        $messenger_to_generate->name
1403
-                    )
1404
-                ) {
1405
-                    unset($default_message_type_names_for_messenger[$key]);
1406
-                }
1407
-            }
1408
-            // in previous iterations, the active_messengers option in the db
1409
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1410
-            // This comment is left here just in case we discover that we _do_ need to update before
1411
-            // passing off to create templates (after the refactor is done).
1412
-            // @todo remove this comment when determined not necessary.
1413
-            $message_resource_manager->activate_messenger(
1414
-                $messenger_to_generate->name,
1415
-                $default_message_type_names_for_messenger,
1416
-                false
1417
-            );
1418
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1419
-            if ( ! empty($default_message_type_names_for_messenger)) {
1420
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1421
-                    $messenger_to_generate->name,
1422
-                    $default_message_type_names_for_messenger,
1423
-                    '',
1424
-                    true
1425
-                );
1426
-            }
1427
-        }
1428
-        return $templates_generated;
1429
-    }
1430
-
1431
-
1432
-    /**
1433
-     * This returns the default messengers to generate templates for on activation of EE.
1434
-     * It considers:
1435
-     * - whether a messenger is already active in the db.
1436
-     * - whether a messenger has been made active at any time in the past.
1437
-     *
1438
-     * @static
1439
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1440
-     * @return EE_messenger[]
1441
-     */
1442
-    protected static function _get_default_messengers_to_generate_on_activation(
1443
-        EE_Message_Resource_Manager $message_resource_manager
1444
-    ) {
1445
-        $active_messengers    = $message_resource_manager->active_messengers();
1446
-        $installed_messengers = $message_resource_manager->installed_messengers();
1447
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1448
-
1449
-        $messengers_to_generate = array();
1450
-        foreach ($installed_messengers as $installed_messenger) {
1451
-            //if installed messenger is a messenger that should be activated on install
1452
-            //and is not already active
1453
-            //and has never been activated
1454
-            if (
1455
-                ! $installed_messenger->activate_on_install
1456
-                || isset($active_messengers[$installed_messenger->name])
1457
-                || isset($has_activated[$installed_messenger->name])
1458
-            ) {
1459
-                continue;
1460
-            }
1461
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1462
-        }
1463
-        return $messengers_to_generate;
1464
-    }
1465
-
1466
-
1467
-    /**
1468
-     * This simply validates active message types to ensure they actually match installed
1469
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1470
-     * rows are set inactive.
1471
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1472
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1473
-     * are still handled in here.
1474
-     *
1475
-     * @since 4.3.1
1476
-     * @return void
1477
-     */
1478
-    public static function validate_messages_system()
1479
-    {
1480
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1481
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1482
-        $message_resource_manager->validate_active_message_types_are_installed();
1483
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1484
-    }
1485
-
1486
-
1487
-    /**
1488
-     * create_no_ticket_prices_array
1489
-     *
1490
-     * @access public
1491
-     * @static
1492
-     * @return void
1493
-     */
1494
-    public static function create_no_ticket_prices_array()
1495
-    {
1496
-        // this creates an array for tracking events that have no active ticket prices created
1497
-        // this allows us to warn admins of the situation so that it can be corrected
1498
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1499
-        if (! $espresso_no_ticket_prices) {
1500
-            add_option('ee_no_ticket_prices', array(), '', false);
1501
-        }
1502
-    }
1503
-
1504
-
1505
-    /**
1506
-     * plugin_deactivation
1507
-     *
1508
-     * @access public
1509
-     * @static
1510
-     * @return void
1511
-     */
1512
-    public static function plugin_deactivation()
1513
-    {
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1519
-     * (like post meta or term relations)
1520
-     *
1521
-     * @global wpdb $wpdb
1522
-     * @throws \EE_Error
1523
-     */
1524
-    public static function delete_all_espresso_cpt_data()
1525
-    {
1526
-        global $wpdb;
1527
-        //get all the CPT post_types
1528
-        $ee_post_types = array();
1529
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1530
-            if (method_exists($model_name, 'instance')) {
1531
-                $model_obj = call_user_func(array($model_name, 'instance'));
1532
-                if ($model_obj instanceof EEM_CPT_Base) {
1533
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1534
-                }
1535
-            }
1536
-        }
1537
-        //get all our CPTs
1538
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1539
-        $cpt_ids = $wpdb->get_col($query);
1540
-        //delete each post meta and term relations too
1541
-        foreach ($cpt_ids as $post_id) {
1542
-            wp_delete_post($post_id, true);
1543
-        }
1544
-    }
1545
-
1546
-    /**
1547
-     * Deletes all EE custom tables
1548
-     *
1549
-     * @return array
1550
-     */
1551
-    public static function drop_espresso_tables()
1552
-    {
1553
-        $tables = array();
1554
-        // load registry
1555
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1556
-            if (method_exists($model_name, 'instance')) {
1557
-                $model_obj = call_user_func(array($model_name, 'instance'));
1558
-                if ($model_obj instanceof EEM_Base) {
1559
-                    foreach ($model_obj->get_tables() as $table) {
1560
-                        if (strpos($table->get_table_name(), 'esp_')
1561
-                            &&
1562
-                            (
1563
-                                is_main_site()//main site? nuke them all
1564
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1565
-                            )
1566
-                        ) {
1567
-                            $tables[] = $table->get_table_name();
1568
-                        }
1569
-                    }
1570
-                }
1571
-            }
1572
-        }
1573
-
1574
-        //there are some tables whose models were removed.
1575
-        //they should be removed when removing all EE core's data
1576
-        $tables_without_models = array(
1577
-            'esp_promotion',
1578
-            'esp_promotion_applied',
1579
-            'esp_promotion_object',
1580
-            'esp_promotion_rule',
1581
-            'esp_rule',
1582
-        );
1583
-        foreach ($tables_without_models as $table) {
1584
-            $tables[] = $table;
1585
-        }
1586
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1587
-    }
1588
-
1589
-
1590
-
1591
-    /**
1592
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1593
-     * each table name provided has a wpdb prefix attached, and that it exists.
1594
-     * Returns the list actually deleted
1595
-     *
1596
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1597
-     * @global WPDB $wpdb
1598
-     * @param array $table_names
1599
-     * @return array of table names which we deleted
1600
-     */
1601
-    public static function drop_tables($table_names)
1602
-    {
1603
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1604
-    }
1605
-
1606
-
1607
-
1608
-    /**
1609
-     * plugin_uninstall
1610
-     *
1611
-     * @access public
1612
-     * @static
1613
-     * @param bool $remove_all
1614
-     * @return void
1615
-     */
1616
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1617
-    {
1618
-        global $wpdb;
1619
-        self::drop_espresso_tables();
1620
-        $wp_options_to_delete = array(
1621
-            'ee_no_ticket_prices'                => true,
1622
-            'ee_active_messengers'               => true,
1623
-            'ee_has_activated_messenger'         => true,
1624
-            'ee_flush_rewrite_rules'             => true,
1625
-            'ee_config'                          => false,
1626
-            'ee_data_migration_current_db_state' => true,
1627
-            'ee_data_migration_mapping_'         => false,
1628
-            'ee_data_migration_script_'          => false,
1629
-            'ee_data_migrations'                 => true,
1630
-            'ee_dms_map'                         => false,
1631
-            'ee_notices'                         => true,
1632
-            'lang_file_check_'                   => false,
1633
-            'ee_maintenance_mode'                => true,
1634
-            'ee_ueip_optin'                      => true,
1635
-            'ee_ueip_has_notified'               => true,
1636
-            'ee_plugin_activation_errors'        => true,
1637
-            'ee_id_mapping_from'                 => false,
1638
-            'espresso_persistent_admin_notices'  => true,
1639
-            'ee_encryption_key'                  => true,
1640
-            'pue_force_upgrade_'                 => false,
1641
-            'pue_json_error_'                    => false,
1642
-            'pue_install_key_'                   => false,
1643
-            'pue_verification_error_'            => false,
1644
-            'pu_dismissed_upgrade_'              => false,
1645
-            'external_updates-'                  => false,
1646
-            'ee_extra_data'                      => true,
1647
-            'ee_ssn_'                            => false,
1648
-            'ee_rss_'                            => false,
1649
-            'ee_rte_n_tx_'                       => false,
1650
-            'ee_pers_admin_notices'              => true,
1651
-            'ee_job_parameters_'                 => false,
1652
-            'ee_upload_directories_incomplete'   => true,
1653
-            'ee_verified_db_collations'          => true,
1654
-        );
1655
-        if (is_main_site()) {
1656
-            $wp_options_to_delete['ee_network_config'] = true;
1657
-        }
1658
-        $undeleted_options = array();
1659
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1660
-            if ($no_wildcard) {
1661
-                if ( ! delete_option($option_name)) {
1662
-                    $undeleted_options[] = $option_name;
1663
-                }
1664
-            } else {
1665
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1666
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1667
-                    if ( ! delete_option($option_name_from_wildcard)) {
1668
-                        $undeleted_options[] = $option_name_from_wildcard;
1669
-                    }
1670
-                }
1671
-            }
1672
-        }
1673
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1674
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1675
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1676
-            $db_update_sans_ee4 = array();
1677
-            foreach ($espresso_db_update as $version => $times_activated) {
1678
-                if ((string)$version[0] === '3') {//if its NON EE4
1679
-                    $db_update_sans_ee4[$version] = $times_activated;
1680
-                }
1681
-            }
1682
-            update_option('espresso_db_update', $db_update_sans_ee4);
1683
-        }
1684
-        $errors = '';
1685
-        if ( ! empty($undeleted_options)) {
1686
-            $errors .= sprintf(
1687
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1688
-                '<br/>',
1689
-                implode(',<br/>', $undeleted_options)
1690
-            );
1691
-        }
1692
-        if ( ! empty($errors)) {
1693
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1694
-        }
1695
-    }
1696
-
1697
-    /**
1698
-     * Gets the mysql error code from the last used query by wpdb
1699
-     *
1700
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1701
-     */
1702
-    public static function last_wpdb_error_code()
1703
-    {
1704
-        global $wpdb;
1705
-        if ($wpdb->use_mysqli) {
1706
-            return mysqli_errno($wpdb->dbh);
1707
-        } else {
1708
-            return mysql_errno($wpdb->dbh);
1709
-        }
1710
-    }
1711
-
1712
-    /**
1713
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1714
-     *
1715
-     * @global wpdb  $wpdb
1716
-     * @deprecated instead use TableAnalysis::tableExists()
1717
-     * @param string $table_name with or without $wpdb->prefix
1718
-     * @return boolean
1719
-     */
1720
-    public static function table_exists($table_name)
1721
-    {
1722
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1723
-    }
1724
-
1725
-    /**
1726
-     * Resets the cache on EEH_Activation
1727
-     */
1728
-    public static function reset()
1729
-    {
1730
-        self::$_default_creator_id                             = null;
1731
-        self::$_initialized_db_content_already_in_this_request = false;
1732
-    }
1302
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1303
+			$message_resource_manager
1304
+		);
1305
+		/**
1306
+		 * This method is verifying there are no NEW default message types
1307
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1308
+		 */
1309
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1310
+			$message_resource_manager
1311
+		);
1312
+		//after all is done, let's persist these changes to the db.
1313
+		$message_resource_manager->update_has_activated_messengers_option();
1314
+		$message_resource_manager->update_active_messengers_option();
1315
+		// will return true if either of these are true.  Otherwise will return false.
1316
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1317
+	}
1318
+
1319
+
1320
+
1321
+	/**
1322
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1323
+	 * @return array|bool
1324
+	 * @throws \EE_Error
1325
+	 */
1326
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1327
+		EE_Message_Resource_Manager $message_resource_manager
1328
+	) {
1329
+		/** @type EE_messenger[] $active_messengers */
1330
+		$active_messengers = $message_resource_manager->active_messengers();
1331
+		$installed_message_types = $message_resource_manager->installed_message_types();
1332
+		$templates_created = false;
1333
+		foreach ($active_messengers as $active_messenger) {
1334
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1335
+			$default_message_type_names_to_activate = array();
1336
+			// looping through each default message type reported by the messenger
1337
+			// and setup the actual message types to activate.
1338
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1339
+				// if already active or has already been activated before we skip
1340
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1341
+				// we also skip if the message type is not installed.
1342
+				if (
1343
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1344
+						$default_message_type_name_for_messenger,
1345
+						$active_messenger->name
1346
+					)
1347
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1348
+						$active_messenger->name,
1349
+						$default_message_type_name_for_messenger
1350
+					)
1351
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1352
+				) {
1353
+					continue;
1354
+				}
1355
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1356
+			}
1357
+			//let's activate!
1358
+			$message_resource_manager->ensure_message_types_are_active(
1359
+				$default_message_type_names_to_activate,
1360
+				$active_messenger->name,
1361
+				false
1362
+			);
1363
+			//activate the templates for these message types
1364
+			if ( ! empty($default_message_type_names_to_activate)) {
1365
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1366
+					$active_messenger->name,
1367
+					$default_message_type_names_for_messenger,
1368
+					'',
1369
+					true
1370
+				);
1371
+			}
1372
+		}
1373
+		return $templates_created;
1374
+	}
1375
+
1376
+
1377
+
1378
+	/**
1379
+	 * This will activate and generate default messengers and default message types for those messengers.
1380
+	 *
1381
+	 * @param EE_message_Resource_Manager $message_resource_manager
1382
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1383
+	 *                     False means that there were no templates generated
1384
+	 *                     (which could simply mean there are no default message types for a messenger).
1385
+	 * @throws EE_Error
1386
+	 */
1387
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1388
+		EE_Message_Resource_Manager $message_resource_manager
1389
+	) {
1390
+		/** @type EE_messenger[] $messengers_to_generate */
1391
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1392
+		$installed_message_types = $message_resource_manager->installed_message_types();
1393
+		$templates_generated = false;
1394
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1395
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1396
+			//verify the default message types match an installed message type.
1397
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1398
+				if (
1399
+					! isset($installed_message_types[$name])
1400
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1401
+						$name,
1402
+						$messenger_to_generate->name
1403
+					)
1404
+				) {
1405
+					unset($default_message_type_names_for_messenger[$key]);
1406
+				}
1407
+			}
1408
+			// in previous iterations, the active_messengers option in the db
1409
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1410
+			// This comment is left here just in case we discover that we _do_ need to update before
1411
+			// passing off to create templates (after the refactor is done).
1412
+			// @todo remove this comment when determined not necessary.
1413
+			$message_resource_manager->activate_messenger(
1414
+				$messenger_to_generate->name,
1415
+				$default_message_type_names_for_messenger,
1416
+				false
1417
+			);
1418
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1419
+			if ( ! empty($default_message_type_names_for_messenger)) {
1420
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1421
+					$messenger_to_generate->name,
1422
+					$default_message_type_names_for_messenger,
1423
+					'',
1424
+					true
1425
+				);
1426
+			}
1427
+		}
1428
+		return $templates_generated;
1429
+	}
1430
+
1431
+
1432
+	/**
1433
+	 * This returns the default messengers to generate templates for on activation of EE.
1434
+	 * It considers:
1435
+	 * - whether a messenger is already active in the db.
1436
+	 * - whether a messenger has been made active at any time in the past.
1437
+	 *
1438
+	 * @static
1439
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1440
+	 * @return EE_messenger[]
1441
+	 */
1442
+	protected static function _get_default_messengers_to_generate_on_activation(
1443
+		EE_Message_Resource_Manager $message_resource_manager
1444
+	) {
1445
+		$active_messengers    = $message_resource_manager->active_messengers();
1446
+		$installed_messengers = $message_resource_manager->installed_messengers();
1447
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1448
+
1449
+		$messengers_to_generate = array();
1450
+		foreach ($installed_messengers as $installed_messenger) {
1451
+			//if installed messenger is a messenger that should be activated on install
1452
+			//and is not already active
1453
+			//and has never been activated
1454
+			if (
1455
+				! $installed_messenger->activate_on_install
1456
+				|| isset($active_messengers[$installed_messenger->name])
1457
+				|| isset($has_activated[$installed_messenger->name])
1458
+			) {
1459
+				continue;
1460
+			}
1461
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1462
+		}
1463
+		return $messengers_to_generate;
1464
+	}
1465
+
1466
+
1467
+	/**
1468
+	 * This simply validates active message types to ensure they actually match installed
1469
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1470
+	 * rows are set inactive.
1471
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1472
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1473
+	 * are still handled in here.
1474
+	 *
1475
+	 * @since 4.3.1
1476
+	 * @return void
1477
+	 */
1478
+	public static function validate_messages_system()
1479
+	{
1480
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1481
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1482
+		$message_resource_manager->validate_active_message_types_are_installed();
1483
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1484
+	}
1485
+
1486
+
1487
+	/**
1488
+	 * create_no_ticket_prices_array
1489
+	 *
1490
+	 * @access public
1491
+	 * @static
1492
+	 * @return void
1493
+	 */
1494
+	public static function create_no_ticket_prices_array()
1495
+	{
1496
+		// this creates an array for tracking events that have no active ticket prices created
1497
+		// this allows us to warn admins of the situation so that it can be corrected
1498
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1499
+		if (! $espresso_no_ticket_prices) {
1500
+			add_option('ee_no_ticket_prices', array(), '', false);
1501
+		}
1502
+	}
1503
+
1504
+
1505
+	/**
1506
+	 * plugin_deactivation
1507
+	 *
1508
+	 * @access public
1509
+	 * @static
1510
+	 * @return void
1511
+	 */
1512
+	public static function plugin_deactivation()
1513
+	{
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1519
+	 * (like post meta or term relations)
1520
+	 *
1521
+	 * @global wpdb $wpdb
1522
+	 * @throws \EE_Error
1523
+	 */
1524
+	public static function delete_all_espresso_cpt_data()
1525
+	{
1526
+		global $wpdb;
1527
+		//get all the CPT post_types
1528
+		$ee_post_types = array();
1529
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1530
+			if (method_exists($model_name, 'instance')) {
1531
+				$model_obj = call_user_func(array($model_name, 'instance'));
1532
+				if ($model_obj instanceof EEM_CPT_Base) {
1533
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1534
+				}
1535
+			}
1536
+		}
1537
+		//get all our CPTs
1538
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1539
+		$cpt_ids = $wpdb->get_col($query);
1540
+		//delete each post meta and term relations too
1541
+		foreach ($cpt_ids as $post_id) {
1542
+			wp_delete_post($post_id, true);
1543
+		}
1544
+	}
1545
+
1546
+	/**
1547
+	 * Deletes all EE custom tables
1548
+	 *
1549
+	 * @return array
1550
+	 */
1551
+	public static function drop_espresso_tables()
1552
+	{
1553
+		$tables = array();
1554
+		// load registry
1555
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1556
+			if (method_exists($model_name, 'instance')) {
1557
+				$model_obj = call_user_func(array($model_name, 'instance'));
1558
+				if ($model_obj instanceof EEM_Base) {
1559
+					foreach ($model_obj->get_tables() as $table) {
1560
+						if (strpos($table->get_table_name(), 'esp_')
1561
+							&&
1562
+							(
1563
+								is_main_site()//main site? nuke them all
1564
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1565
+							)
1566
+						) {
1567
+							$tables[] = $table->get_table_name();
1568
+						}
1569
+					}
1570
+				}
1571
+			}
1572
+		}
1573
+
1574
+		//there are some tables whose models were removed.
1575
+		//they should be removed when removing all EE core's data
1576
+		$tables_without_models = array(
1577
+			'esp_promotion',
1578
+			'esp_promotion_applied',
1579
+			'esp_promotion_object',
1580
+			'esp_promotion_rule',
1581
+			'esp_rule',
1582
+		);
1583
+		foreach ($tables_without_models as $table) {
1584
+			$tables[] = $table;
1585
+		}
1586
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1587
+	}
1588
+
1589
+
1590
+
1591
+	/**
1592
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1593
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1594
+	 * Returns the list actually deleted
1595
+	 *
1596
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1597
+	 * @global WPDB $wpdb
1598
+	 * @param array $table_names
1599
+	 * @return array of table names which we deleted
1600
+	 */
1601
+	public static function drop_tables($table_names)
1602
+	{
1603
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1604
+	}
1605
+
1606
+
1607
+
1608
+	/**
1609
+	 * plugin_uninstall
1610
+	 *
1611
+	 * @access public
1612
+	 * @static
1613
+	 * @param bool $remove_all
1614
+	 * @return void
1615
+	 */
1616
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1617
+	{
1618
+		global $wpdb;
1619
+		self::drop_espresso_tables();
1620
+		$wp_options_to_delete = array(
1621
+			'ee_no_ticket_prices'                => true,
1622
+			'ee_active_messengers'               => true,
1623
+			'ee_has_activated_messenger'         => true,
1624
+			'ee_flush_rewrite_rules'             => true,
1625
+			'ee_config'                          => false,
1626
+			'ee_data_migration_current_db_state' => true,
1627
+			'ee_data_migration_mapping_'         => false,
1628
+			'ee_data_migration_script_'          => false,
1629
+			'ee_data_migrations'                 => true,
1630
+			'ee_dms_map'                         => false,
1631
+			'ee_notices'                         => true,
1632
+			'lang_file_check_'                   => false,
1633
+			'ee_maintenance_mode'                => true,
1634
+			'ee_ueip_optin'                      => true,
1635
+			'ee_ueip_has_notified'               => true,
1636
+			'ee_plugin_activation_errors'        => true,
1637
+			'ee_id_mapping_from'                 => false,
1638
+			'espresso_persistent_admin_notices'  => true,
1639
+			'ee_encryption_key'                  => true,
1640
+			'pue_force_upgrade_'                 => false,
1641
+			'pue_json_error_'                    => false,
1642
+			'pue_install_key_'                   => false,
1643
+			'pue_verification_error_'            => false,
1644
+			'pu_dismissed_upgrade_'              => false,
1645
+			'external_updates-'                  => false,
1646
+			'ee_extra_data'                      => true,
1647
+			'ee_ssn_'                            => false,
1648
+			'ee_rss_'                            => false,
1649
+			'ee_rte_n_tx_'                       => false,
1650
+			'ee_pers_admin_notices'              => true,
1651
+			'ee_job_parameters_'                 => false,
1652
+			'ee_upload_directories_incomplete'   => true,
1653
+			'ee_verified_db_collations'          => true,
1654
+		);
1655
+		if (is_main_site()) {
1656
+			$wp_options_to_delete['ee_network_config'] = true;
1657
+		}
1658
+		$undeleted_options = array();
1659
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1660
+			if ($no_wildcard) {
1661
+				if ( ! delete_option($option_name)) {
1662
+					$undeleted_options[] = $option_name;
1663
+				}
1664
+			} else {
1665
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1666
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1667
+					if ( ! delete_option($option_name_from_wildcard)) {
1668
+						$undeleted_options[] = $option_name_from_wildcard;
1669
+					}
1670
+				}
1671
+			}
1672
+		}
1673
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1674
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1675
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1676
+			$db_update_sans_ee4 = array();
1677
+			foreach ($espresso_db_update as $version => $times_activated) {
1678
+				if ((string)$version[0] === '3') {//if its NON EE4
1679
+					$db_update_sans_ee4[$version] = $times_activated;
1680
+				}
1681
+			}
1682
+			update_option('espresso_db_update', $db_update_sans_ee4);
1683
+		}
1684
+		$errors = '';
1685
+		if ( ! empty($undeleted_options)) {
1686
+			$errors .= sprintf(
1687
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1688
+				'<br/>',
1689
+				implode(',<br/>', $undeleted_options)
1690
+			);
1691
+		}
1692
+		if ( ! empty($errors)) {
1693
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1694
+		}
1695
+	}
1696
+
1697
+	/**
1698
+	 * Gets the mysql error code from the last used query by wpdb
1699
+	 *
1700
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1701
+	 */
1702
+	public static function last_wpdb_error_code()
1703
+	{
1704
+		global $wpdb;
1705
+		if ($wpdb->use_mysqli) {
1706
+			return mysqli_errno($wpdb->dbh);
1707
+		} else {
1708
+			return mysql_errno($wpdb->dbh);
1709
+		}
1710
+	}
1711
+
1712
+	/**
1713
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1714
+	 *
1715
+	 * @global wpdb  $wpdb
1716
+	 * @deprecated instead use TableAnalysis::tableExists()
1717
+	 * @param string $table_name with or without $wpdb->prefix
1718
+	 * @return boolean
1719
+	 */
1720
+	public static function table_exists($table_name)
1721
+	{
1722
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1723
+	}
1724
+
1725
+	/**
1726
+	 * Resets the cache on EEH_Activation
1727
+	 */
1728
+	public static function reset()
1729
+	{
1730
+		self::$_default_creator_id                             = null;
1731
+		self::$_initialized_db_content_already_in_this_request = false;
1732
+	}
1733 1733
 }
1734 1734
 // End of file EEH_Activation.helper.php
1735 1735
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.