Completed
Branch FET/editor-dates-tickets-refac... (89c3e0)
by
unknown
40:17 queued 32:20
created
display_strategies/number_bubbles/NumberBubblesProgressStepsDisplay.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -16,29 +16,29 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * used for setting up css and js required for the display strategy
21
-     *
22
-     * @return void
23
-     */
24
-    public function enqueueStylesAndScripts()
25
-    {
26
-        // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css
27
-        wp_enqueue_style(
28
-            'ee_progress_steps_display_number_bubbles',
29
-            plugin_dir_url(__FILE__) . 'number_bubbles.css'
30
-        );
31
-    }
19
+	/**
20
+	 * used for setting up css and js required for the display strategy
21
+	 *
22
+	 * @return void
23
+	 */
24
+	public function enqueueStylesAndScripts()
25
+	{
26
+		// core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css
27
+		wp_enqueue_style(
28
+			'ee_progress_steps_display_number_bubbles',
29
+			plugin_dir_url(__FILE__) . 'number_bubbles.css'
30
+		);
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * loads and returns a full server path to the template used for the display strategy
36
-     *
37
-     * @return string
38
-     */
39
-    public function getTemplate()
40
-    {
41
-        // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php';
42
-        return __DIR__ . '/number_bubbles.template.php';
43
-    }
34
+	/**
35
+	 * loads and returns a full server path to the template used for the display strategy
36
+	 *
37
+	 * @return string
38
+	 */
39
+	public function getTemplate()
40
+	{
41
+		// return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php';
42
+		return __DIR__ . '/number_bubbles.template.php';
43
+	}
44 44
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css
27 27
         wp_enqueue_style(
28 28
             'ee_progress_steps_display_number_bubbles',
29
-            plugin_dir_url(__FILE__) . 'number_bubbles.css'
29
+            plugin_dir_url(__FILE__).'number_bubbles.css'
30 30
         );
31 31
     }
32 32
 
@@ -39,6 +39,6 @@  discard block
 block discarded – undo
39 39
     public function getTemplate()
40 40
     {
41 41
         // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php';
42
-        return __DIR__ . '/number_bubbles.template.php';
42
+        return __DIR__.'/number_bubbles.template.php';
43 43
     }
44 44
 }
Please login to merge, or discard this patch.
core/services/shortcodes/LegacyShortcodesManager.php 2 patches
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -21,409 +21,409 @@
 block discarded – undo
21 21
 class LegacyShortcodesManager
22 22
 {
23 23
 
24
-    /**
25
-     * @var EE_Registry $registry
26
-     */
27
-    private $registry;
28
-
29
-
30
-    /**
31
-     * LegacyShortcodesManager constructor.
32
-     *
33
-     * @param \EE_Registry $registry
34
-     */
35
-    public function __construct(EE_Registry $registry)
36
-    {
37
-        $this->registry = $registry;
38
-    }
39
-
40
-
41
-    /**
42
-     * @return EE_Registry
43
-     */
44
-    public function registry()
45
-    {
46
-        return $this->registry;
47
-    }
48
-
49
-
50
-    /**
51
-     * registerShortcodes
52
-     *
53
-     * @return void
54
-     */
55
-    public function registerShortcodes()
56
-    {
57
-        $this->registry->shortcodes = $this->getShortcodes();
58
-    }
59
-
60
-
61
-    /**
62
-     * getShortcodes
63
-     *
64
-     * @return array
65
-     */
66
-    public function getShortcodes()
67
-    {
68
-        // previously this method would glob the shortcodes directory
69
-        // then filter that list of shortcodes to register,
70
-        // but now we are going to just supply an empty array.
71
-        // this allows any shortcodes that have not yet been converted to the new system
72
-        // to still get loaded and processed, albeit using the same legacy logic as before
73
-        $shortcodes_to_register = apply_filters(
74
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
75
-            array()
76
-        );
77
-        if (! empty($shortcodes_to_register)) {
78
-            // cycle thru shortcode folders
79
-            foreach ($shortcodes_to_register as $shortcode_path) {
80
-                // add to list of installed shortcode modules
81
-                $this->registerShortcode($shortcode_path);
82
-            }
83
-        }
84
-        // filter list of installed modules
85
-        return apply_filters(
86
-            'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
87
-            ! empty($this->registry->shortcodes)
88
-                ? $this->registry->shortcodes
89
-                : array()
90
-        );
91
-    }
92
-
93
-
94
-    /**
95
-     *    register_shortcode - makes core aware of this shortcode
96
-     *
97
-     * @access    public
98
-     * @param    string $shortcode_path - full path up to and including shortcode folder
99
-     * @return    bool
100
-     */
101
-    public function registerShortcode($shortcode_path = null)
102
-    {
103
-        do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
104
-        $shortcode_ext = '.shortcode.php';
105
-        // make all separators match
106
-        $shortcode_path = str_replace(array('\\', '/'), '/', $shortcode_path);
107
-        // does the file path INCLUDE the actual file name as part of the path ?
108
-        if (strpos($shortcode_path, $shortcode_ext) !== false) {
109
-            // grab shortcode file name from directory name and break apart at dots
110
-            $shortcode_file = explode('.', basename($shortcode_path));
111
-            // take first segment from file name pieces and remove class prefix if it exists
112
-            $shortcode = strpos($shortcode_file[0], 'EES_') === 0
113
-                ? substr($shortcode_file[0], 4)
114
-                : $shortcode_file[0];
115
-            // sanitize shortcode directory name
116
-            $shortcode = sanitize_key($shortcode);
117
-            // now we need to rebuild the shortcode path
118
-            $shortcode_path = explode('/', $shortcode_path);
119
-            // remove last segment
120
-            array_pop($shortcode_path);
121
-            // glue it back together
122
-            $shortcode_path = implode('/', $shortcode_path) . '/';
123
-        } else {
124
-            // we need to generate the filename based off of the folder name
125
-            // grab and sanitize shortcode directory name
126
-            $shortcode = sanitize_key(basename($shortcode_path));
127
-            $shortcode_path = rtrim($shortcode_path, '/') . '/';
128
-        }
129
-        // create classname from shortcode directory or file name
130
-        $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
131
-        // add class prefix
132
-        $shortcode_class = 'EES_' . $shortcode;
133
-        // does the shortcode exist ?
134
-        if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) {
135
-            $msg = sprintf(
136
-                esc_html__(
137
-                    'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s',
138
-                    'event_espresso'
139
-                ),
140
-                $shortcode_class,
141
-                $shortcode_path . '/' . $shortcode_class . $shortcode_ext
142
-            );
143
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
144
-            return false;
145
-        }
146
-        // load the shortcode class file
147
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
148
-        // verify that class exists
149
-        if (! class_exists($shortcode_class)) {
150
-            $msg = sprintf(
151
-                esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
152
-                $shortcode_class
153
-            );
154
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
155
-            return false;
156
-        }
157
-        $shortcode = strtoupper($shortcode);
158
-        // add to array of registered shortcodes
159
-        $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
160
-        return true;
161
-    }
162
-
163
-
164
-    /**
165
-     *    _initialize_shortcodes
166
-     *    allow shortcodes to set hooks for the rest of the system
167
-     *
168
-     * @access private
169
-     * @return void
170
-     */
171
-    public function addShortcodes()
172
-    {
173
-        // cycle thru shortcode folders
174
-        foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
175
-            // add class prefix
176
-            $shortcode_class = 'EES_' . $shortcode;
177
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
178
-            // which set hooks ?
179
-            if (is_admin()) {
180
-                // fire immediately
181
-                call_user_func(array($shortcode_class, 'set_hooks_admin'));
182
-            } else {
183
-                // delay until other systems are online
184
-                add_action(
185
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
186
-                    array($shortcode_class, 'set_hooks')
187
-                );
188
-                // convert classname to UPPERCASE and create WP shortcode.
189
-                $shortcode_tag = strtoupper($shortcode);
190
-                // but first check if the shortcode has already
191
-                // been added before assigning 'fallback_shortcode_processor'
192
-                if (! shortcode_exists($shortcode_tag)) {
193
-                    // NOTE: this shortcode declaration will get overridden if the shortcode
194
-                    // is successfully detected in the post content in initializeShortcode()
195
-                    add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
196
-                }
197
-            }
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * callback for the WP "get_header" hook point
204
-     * checks posts for EE shortcodes, and initializes them,
205
-     * then toggles filter switch that loads core default assets
206
-     *
207
-     * @param \WP_Query $wp_query
208
-     * @return void
209
-     */
210
-    public function initializeShortcodes(WP_Query $wp_query)
211
-    {
212
-        if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) {
213
-            return;
214
-        }
215
-        global $wp;
216
-        /** @var EE_Front_controller $Front_Controller */
217
-        $Front_Controller = $this->registry->load_core('Front_Controller', array(), false);
218
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller);
219
-        $Front_Controller->Request_Handler()->set_request_vars();
220
-        // grab post_name from request
221
-        $current_post = apply_filters(
222
-            'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
223
-            $Front_Controller->Request_Handler()->get('post_name')
224
-        );
225
-        $show_on_front = get_option('show_on_front');
226
-        // if it's not set, then check if frontpage is blog
227
-        if (empty($current_post)) {
228
-            // yup.. this is the posts page, prepare to load all shortcode modules
229
-            $current_post = 'posts';
230
-            // unless..
231
-            if ($show_on_front === 'page') {
232
-                // some other page is set as the homepage
233
-                $page_on_front = get_option('page_on_front');
234
-                if ($page_on_front) {
235
-                    // k now we need to find the post_name for this page
236
-                    global $wpdb;
237
-                    $page_on_front = $wpdb->get_var(
238
-                        $wpdb->prepare(
239
-                            "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d",
240
-                            $page_on_front
241
-                        )
242
-                    );
243
-                    // set the current post slug to what it actually is
244
-                    $current_post = $page_on_front ? $page_on_front : $current_post;
245
-                }
246
-            }
247
-        }
248
-        // in case $current_post is hierarchical like: /parent-page/current-page
249
-        $current_post = basename($current_post);
250
-        if (// is current page/post the "blog" page ?
251
-            $current_post === EE_Config::get_page_for_posts()
252
-            // or are we on a category page?
253
-            || (
254
-                is_array(term_exists($current_post, 'category'))
255
-                || array_key_exists('category_name', $wp->query_vars)
256
-            )
257
-        ) {
258
-            // initialize all legacy shortcodes
259
-            $load_assets = $this->parseContentForShortcodes('', true);
260
-        } else {
261
-            global $wpdb;
262
-            $post_content = $wpdb->get_var(
263
-                $wpdb->prepare(
264
-                    "SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s",
265
-                    $current_post
266
-                )
267
-            );
268
-            $load_assets = $this->parseContentForShortcodes($post_content);
269
-        }
270
-        if ($load_assets) {
271
-            $this->registry->REQ->set_espresso_page(true);
272
-            add_filter('FHEE_load_css', '__return_true');
273
-            add_filter('FHEE_load_js', '__return_true');
274
-        }
275
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller);
276
-    }
277
-
278
-
279
-    /**
280
-     * checks supplied content against list of legacy shortcodes,
281
-     * then initializes any found shortcodes, and returns true.
282
-     * returns false if no shortcodes found.
283
-     *
284
-     * @param string $content
285
-     * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
286
-     * @return bool
287
-     */
288
-    public function parseContentForShortcodes($content = '', $load_all = false)
289
-    {
290
-        $has_shortcode = false;
291
-        foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
292
-            if ($load_all || has_shortcode($content, $shortcode_class)) {
293
-                // load up the shortcode
294
-                $this->initializeShortcode($shortcode_class);
295
-                $has_shortcode = true;
296
-            }
297
-        }
298
-        return $has_shortcode;
299
-    }
300
-
301
-
302
-    /**
303
-     * given a shortcode name, will instantiate the shortcode and call it's run() method
304
-     *
305
-     * @param string $shortcode_class
306
-     * @param WP     $wp
307
-     */
308
-    public function initializeShortcode($shortcode_class = '', WP $wp = null)
309
-    {
310
-        // don't do anything if shortcode is already initialized
311
-        if (empty($this->registry->shortcodes->{$shortcode_class})
312
-            || ! is_string($this->registry->shortcodes->{$shortcode_class})
313
-        ) {
314
-            return;
315
-        }
316
-        // let's pause to reflect on this...
317
-        $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
318
-        // ensure that class is actually a shortcode
319
-        if (defined('WP_DEBUG')
320
-            && WP_DEBUG === true
321
-            && ! $sc_reflector->isSubclassOf('EES_Shortcode')
322
-        ) {
323
-            EE_Error::add_error(
324
-                sprintf(
325
-                    esc_html__(
326
-                        'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
327
-                        'event_espresso'
328
-                    ),
329
-                    $shortcode_class
330
-                ),
331
-                __FILE__,
332
-                __FUNCTION__,
333
-                __LINE__
334
-            );
335
-            add_filter('FHEE_run_EE_the_content', '__return_true');
336
-            return;
337
-        }
338
-        global $wp;
339
-        // and pass the request object to the run method
340
-        $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
341
-        // fire the shortcode class's run method, so that it can activate resources
342
-        $this->registry->shortcodes->{$shortcode_class}->run($wp);
343
-    }
344
-
345
-
346
-    /**
347
-     * get classname, remove EES_prefix, and convert to UPPERCASE
348
-     *
349
-     * @param string $class_name
350
-     * @return string
351
-     */
352
-    public static function generateShortcodeTagFromClassName($class_name)
353
-    {
354
-        return strtoupper(str_replace('EES_', '', $class_name));
355
-    }
356
-
357
-
358
-    /**
359
-     * add EES_prefix and Capitalize words
360
-     *
361
-     * @param string $tag
362
-     * @return string
363
-     */
364
-    public static function generateShortcodeClassNameFromTag($tag)
365
-    {
366
-        // order of operation runs from inside to out
367
-        // 5) maybe add prefix
368
-        return LegacyShortcodesManager::addShortcodeClassPrefix(
369
-            // 4) find spaces, replace with underscores
370
-            str_replace(
371
-                ' ',
372
-                '_',
373
-                // 3) capitalize first letter of each word
374
-                ucwords(
375
-                    // 2) also change to lowercase so ucwords() will work
376
-                    strtolower(
377
-                        // 1) find underscores, replace with spaces so ucwords() will work
378
-                        str_replace(
379
-                            '_',
380
-                            ' ',
381
-                            $tag
382
-                        )
383
-                    )
384
-                )
385
-            )
386
-        );
387
-    }
388
-
389
-
390
-    /**
391
-     * maybe add EES_prefix
392
-     *
393
-     * @param string $class_name
394
-     * @return string
395
-     */
396
-    public static function addShortcodeClassPrefix($class_name)
397
-    {
398
-        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
399
-    }
400
-
401
-
402
-    /**
403
-     * @return array
404
-     */
405
-    public function getEspressoShortcodeTags()
406
-    {
407
-        static $shortcode_tags = array();
408
-        if (empty($shortcode_tags)) {
409
-            $shortcode_tags = array_keys((array) $this->registry->shortcodes);
410
-        }
411
-        return $shortcode_tags;
412
-    }
413
-
414
-
415
-    /**
416
-     * @param string $content
417
-     * @return string
418
-     */
419
-    public function doShortcode($content)
420
-    {
421
-        foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
422
-            if (strpos($content, $shortcode_tag) !== false) {
423
-                $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
424
-                $this->initializeShortcode($shortcode_class);
425
-            }
426
-        }
427
-        return do_shortcode($content);
428
-    }
24
+	/**
25
+	 * @var EE_Registry $registry
26
+	 */
27
+	private $registry;
28
+
29
+
30
+	/**
31
+	 * LegacyShortcodesManager constructor.
32
+	 *
33
+	 * @param \EE_Registry $registry
34
+	 */
35
+	public function __construct(EE_Registry $registry)
36
+	{
37
+		$this->registry = $registry;
38
+	}
39
+
40
+
41
+	/**
42
+	 * @return EE_Registry
43
+	 */
44
+	public function registry()
45
+	{
46
+		return $this->registry;
47
+	}
48
+
49
+
50
+	/**
51
+	 * registerShortcodes
52
+	 *
53
+	 * @return void
54
+	 */
55
+	public function registerShortcodes()
56
+	{
57
+		$this->registry->shortcodes = $this->getShortcodes();
58
+	}
59
+
60
+
61
+	/**
62
+	 * getShortcodes
63
+	 *
64
+	 * @return array
65
+	 */
66
+	public function getShortcodes()
67
+	{
68
+		// previously this method would glob the shortcodes directory
69
+		// then filter that list of shortcodes to register,
70
+		// but now we are going to just supply an empty array.
71
+		// this allows any shortcodes that have not yet been converted to the new system
72
+		// to still get loaded and processed, albeit using the same legacy logic as before
73
+		$shortcodes_to_register = apply_filters(
74
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
75
+			array()
76
+		);
77
+		if (! empty($shortcodes_to_register)) {
78
+			// cycle thru shortcode folders
79
+			foreach ($shortcodes_to_register as $shortcode_path) {
80
+				// add to list of installed shortcode modules
81
+				$this->registerShortcode($shortcode_path);
82
+			}
83
+		}
84
+		// filter list of installed modules
85
+		return apply_filters(
86
+			'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
87
+			! empty($this->registry->shortcodes)
88
+				? $this->registry->shortcodes
89
+				: array()
90
+		);
91
+	}
92
+
93
+
94
+	/**
95
+	 *    register_shortcode - makes core aware of this shortcode
96
+	 *
97
+	 * @access    public
98
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
99
+	 * @return    bool
100
+	 */
101
+	public function registerShortcode($shortcode_path = null)
102
+	{
103
+		do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
104
+		$shortcode_ext = '.shortcode.php';
105
+		// make all separators match
106
+		$shortcode_path = str_replace(array('\\', '/'), '/', $shortcode_path);
107
+		// does the file path INCLUDE the actual file name as part of the path ?
108
+		if (strpos($shortcode_path, $shortcode_ext) !== false) {
109
+			// grab shortcode file name from directory name and break apart at dots
110
+			$shortcode_file = explode('.', basename($shortcode_path));
111
+			// take first segment from file name pieces and remove class prefix if it exists
112
+			$shortcode = strpos($shortcode_file[0], 'EES_') === 0
113
+				? substr($shortcode_file[0], 4)
114
+				: $shortcode_file[0];
115
+			// sanitize shortcode directory name
116
+			$shortcode = sanitize_key($shortcode);
117
+			// now we need to rebuild the shortcode path
118
+			$shortcode_path = explode('/', $shortcode_path);
119
+			// remove last segment
120
+			array_pop($shortcode_path);
121
+			// glue it back together
122
+			$shortcode_path = implode('/', $shortcode_path) . '/';
123
+		} else {
124
+			// we need to generate the filename based off of the folder name
125
+			// grab and sanitize shortcode directory name
126
+			$shortcode = sanitize_key(basename($shortcode_path));
127
+			$shortcode_path = rtrim($shortcode_path, '/') . '/';
128
+		}
129
+		// create classname from shortcode directory or file name
130
+		$shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
131
+		// add class prefix
132
+		$shortcode_class = 'EES_' . $shortcode;
133
+		// does the shortcode exist ?
134
+		if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) {
135
+			$msg = sprintf(
136
+				esc_html__(
137
+					'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s',
138
+					'event_espresso'
139
+				),
140
+				$shortcode_class,
141
+				$shortcode_path . '/' . $shortcode_class . $shortcode_ext
142
+			);
143
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
144
+			return false;
145
+		}
146
+		// load the shortcode class file
147
+		require_once($shortcode_path . $shortcode_class . $shortcode_ext);
148
+		// verify that class exists
149
+		if (! class_exists($shortcode_class)) {
150
+			$msg = sprintf(
151
+				esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
152
+				$shortcode_class
153
+			);
154
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
155
+			return false;
156
+		}
157
+		$shortcode = strtoupper($shortcode);
158
+		// add to array of registered shortcodes
159
+		$this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
160
+		return true;
161
+	}
162
+
163
+
164
+	/**
165
+	 *    _initialize_shortcodes
166
+	 *    allow shortcodes to set hooks for the rest of the system
167
+	 *
168
+	 * @access private
169
+	 * @return void
170
+	 */
171
+	public function addShortcodes()
172
+	{
173
+		// cycle thru shortcode folders
174
+		foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
175
+			// add class prefix
176
+			$shortcode_class = 'EES_' . $shortcode;
177
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
178
+			// which set hooks ?
179
+			if (is_admin()) {
180
+				// fire immediately
181
+				call_user_func(array($shortcode_class, 'set_hooks_admin'));
182
+			} else {
183
+				// delay until other systems are online
184
+				add_action(
185
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
186
+					array($shortcode_class, 'set_hooks')
187
+				);
188
+				// convert classname to UPPERCASE and create WP shortcode.
189
+				$shortcode_tag = strtoupper($shortcode);
190
+				// but first check if the shortcode has already
191
+				// been added before assigning 'fallback_shortcode_processor'
192
+				if (! shortcode_exists($shortcode_tag)) {
193
+					// NOTE: this shortcode declaration will get overridden if the shortcode
194
+					// is successfully detected in the post content in initializeShortcode()
195
+					add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
196
+				}
197
+			}
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * callback for the WP "get_header" hook point
204
+	 * checks posts for EE shortcodes, and initializes them,
205
+	 * then toggles filter switch that loads core default assets
206
+	 *
207
+	 * @param \WP_Query $wp_query
208
+	 * @return void
209
+	 */
210
+	public function initializeShortcodes(WP_Query $wp_query)
211
+	{
212
+		if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) {
213
+			return;
214
+		}
215
+		global $wp;
216
+		/** @var EE_Front_controller $Front_Controller */
217
+		$Front_Controller = $this->registry->load_core('Front_Controller', array(), false);
218
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller);
219
+		$Front_Controller->Request_Handler()->set_request_vars();
220
+		// grab post_name from request
221
+		$current_post = apply_filters(
222
+			'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
223
+			$Front_Controller->Request_Handler()->get('post_name')
224
+		);
225
+		$show_on_front = get_option('show_on_front');
226
+		// if it's not set, then check if frontpage is blog
227
+		if (empty($current_post)) {
228
+			// yup.. this is the posts page, prepare to load all shortcode modules
229
+			$current_post = 'posts';
230
+			// unless..
231
+			if ($show_on_front === 'page') {
232
+				// some other page is set as the homepage
233
+				$page_on_front = get_option('page_on_front');
234
+				if ($page_on_front) {
235
+					// k now we need to find the post_name for this page
236
+					global $wpdb;
237
+					$page_on_front = $wpdb->get_var(
238
+						$wpdb->prepare(
239
+							"SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d",
240
+							$page_on_front
241
+						)
242
+					);
243
+					// set the current post slug to what it actually is
244
+					$current_post = $page_on_front ? $page_on_front : $current_post;
245
+				}
246
+			}
247
+		}
248
+		// in case $current_post is hierarchical like: /parent-page/current-page
249
+		$current_post = basename($current_post);
250
+		if (// is current page/post the "blog" page ?
251
+			$current_post === EE_Config::get_page_for_posts()
252
+			// or are we on a category page?
253
+			|| (
254
+				is_array(term_exists($current_post, 'category'))
255
+				|| array_key_exists('category_name', $wp->query_vars)
256
+			)
257
+		) {
258
+			// initialize all legacy shortcodes
259
+			$load_assets = $this->parseContentForShortcodes('', true);
260
+		} else {
261
+			global $wpdb;
262
+			$post_content = $wpdb->get_var(
263
+				$wpdb->prepare(
264
+					"SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s",
265
+					$current_post
266
+				)
267
+			);
268
+			$load_assets = $this->parseContentForShortcodes($post_content);
269
+		}
270
+		if ($load_assets) {
271
+			$this->registry->REQ->set_espresso_page(true);
272
+			add_filter('FHEE_load_css', '__return_true');
273
+			add_filter('FHEE_load_js', '__return_true');
274
+		}
275
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller);
276
+	}
277
+
278
+
279
+	/**
280
+	 * checks supplied content against list of legacy shortcodes,
281
+	 * then initializes any found shortcodes, and returns true.
282
+	 * returns false if no shortcodes found.
283
+	 *
284
+	 * @param string $content
285
+	 * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
286
+	 * @return bool
287
+	 */
288
+	public function parseContentForShortcodes($content = '', $load_all = false)
289
+	{
290
+		$has_shortcode = false;
291
+		foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
292
+			if ($load_all || has_shortcode($content, $shortcode_class)) {
293
+				// load up the shortcode
294
+				$this->initializeShortcode($shortcode_class);
295
+				$has_shortcode = true;
296
+			}
297
+		}
298
+		return $has_shortcode;
299
+	}
300
+
301
+
302
+	/**
303
+	 * given a shortcode name, will instantiate the shortcode and call it's run() method
304
+	 *
305
+	 * @param string $shortcode_class
306
+	 * @param WP     $wp
307
+	 */
308
+	public function initializeShortcode($shortcode_class = '', WP $wp = null)
309
+	{
310
+		// don't do anything if shortcode is already initialized
311
+		if (empty($this->registry->shortcodes->{$shortcode_class})
312
+			|| ! is_string($this->registry->shortcodes->{$shortcode_class})
313
+		) {
314
+			return;
315
+		}
316
+		// let's pause to reflect on this...
317
+		$sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
318
+		// ensure that class is actually a shortcode
319
+		if (defined('WP_DEBUG')
320
+			&& WP_DEBUG === true
321
+			&& ! $sc_reflector->isSubclassOf('EES_Shortcode')
322
+		) {
323
+			EE_Error::add_error(
324
+				sprintf(
325
+					esc_html__(
326
+						'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
327
+						'event_espresso'
328
+					),
329
+					$shortcode_class
330
+				),
331
+				__FILE__,
332
+				__FUNCTION__,
333
+				__LINE__
334
+			);
335
+			add_filter('FHEE_run_EE_the_content', '__return_true');
336
+			return;
337
+		}
338
+		global $wp;
339
+		// and pass the request object to the run method
340
+		$this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
341
+		// fire the shortcode class's run method, so that it can activate resources
342
+		$this->registry->shortcodes->{$shortcode_class}->run($wp);
343
+	}
344
+
345
+
346
+	/**
347
+	 * get classname, remove EES_prefix, and convert to UPPERCASE
348
+	 *
349
+	 * @param string $class_name
350
+	 * @return string
351
+	 */
352
+	public static function generateShortcodeTagFromClassName($class_name)
353
+	{
354
+		return strtoupper(str_replace('EES_', '', $class_name));
355
+	}
356
+
357
+
358
+	/**
359
+	 * add EES_prefix and Capitalize words
360
+	 *
361
+	 * @param string $tag
362
+	 * @return string
363
+	 */
364
+	public static function generateShortcodeClassNameFromTag($tag)
365
+	{
366
+		// order of operation runs from inside to out
367
+		// 5) maybe add prefix
368
+		return LegacyShortcodesManager::addShortcodeClassPrefix(
369
+			// 4) find spaces, replace with underscores
370
+			str_replace(
371
+				' ',
372
+				'_',
373
+				// 3) capitalize first letter of each word
374
+				ucwords(
375
+					// 2) also change to lowercase so ucwords() will work
376
+					strtolower(
377
+						// 1) find underscores, replace with spaces so ucwords() will work
378
+						str_replace(
379
+							'_',
380
+							' ',
381
+							$tag
382
+						)
383
+					)
384
+				)
385
+			)
386
+		);
387
+	}
388
+
389
+
390
+	/**
391
+	 * maybe add EES_prefix
392
+	 *
393
+	 * @param string $class_name
394
+	 * @return string
395
+	 */
396
+	public static function addShortcodeClassPrefix($class_name)
397
+	{
398
+		return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
399
+	}
400
+
401
+
402
+	/**
403
+	 * @return array
404
+	 */
405
+	public function getEspressoShortcodeTags()
406
+	{
407
+		static $shortcode_tags = array();
408
+		if (empty($shortcode_tags)) {
409
+			$shortcode_tags = array_keys((array) $this->registry->shortcodes);
410
+		}
411
+		return $shortcode_tags;
412
+	}
413
+
414
+
415
+	/**
416
+	 * @param string $content
417
+	 * @return string
418
+	 */
419
+	public function doShortcode($content)
420
+	{
421
+		foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
422
+			if (strpos($content, $shortcode_tag) !== false) {
423
+				$shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
424
+				$this->initializeShortcode($shortcode_class);
425
+			}
426
+		}
427
+		return do_shortcode($content);
428
+	}
429 429
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
             'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
75 75
             array()
76 76
         );
77
-        if (! empty($shortcodes_to_register)) {
77
+        if ( ! empty($shortcodes_to_register)) {
78 78
             // cycle thru shortcode folders
79 79
             foreach ($shortcodes_to_register as $shortcode_path) {
80 80
                 // add to list of installed shortcode modules
@@ -119,44 +119,44 @@  discard block
 block discarded – undo
119 119
             // remove last segment
120 120
             array_pop($shortcode_path);
121 121
             // glue it back together
122
-            $shortcode_path = implode('/', $shortcode_path) . '/';
122
+            $shortcode_path = implode('/', $shortcode_path).'/';
123 123
         } else {
124 124
             // we need to generate the filename based off of the folder name
125 125
             // grab and sanitize shortcode directory name
126 126
             $shortcode = sanitize_key(basename($shortcode_path));
127
-            $shortcode_path = rtrim($shortcode_path, '/') . '/';
127
+            $shortcode_path = rtrim($shortcode_path, '/').'/';
128 128
         }
129 129
         // create classname from shortcode directory or file name
130 130
         $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
131 131
         // add class prefix
132
-        $shortcode_class = 'EES_' . $shortcode;
132
+        $shortcode_class = 'EES_'.$shortcode;
133 133
         // does the shortcode exist ?
134
-        if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) {
134
+        if ( ! is_readable($shortcode_path.'/'.$shortcode_class.$shortcode_ext)) {
135 135
             $msg = sprintf(
136 136
                 esc_html__(
137 137
                     'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s',
138 138
                     'event_espresso'
139 139
                 ),
140 140
                 $shortcode_class,
141
-                $shortcode_path . '/' . $shortcode_class . $shortcode_ext
141
+                $shortcode_path.'/'.$shortcode_class.$shortcode_ext
142 142
             );
143
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
143
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
144 144
             return false;
145 145
         }
146 146
         // load the shortcode class file
147
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
147
+        require_once($shortcode_path.$shortcode_class.$shortcode_ext);
148 148
         // verify that class exists
149
-        if (! class_exists($shortcode_class)) {
149
+        if ( ! class_exists($shortcode_class)) {
150 150
             $msg = sprintf(
151 151
                 esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
152 152
                 $shortcode_class
153 153
             );
154
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
155 155
             return false;
156 156
         }
157 157
         $shortcode = strtoupper($shortcode);
158 158
         // add to array of registered shortcodes
159
-        $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
159
+        $this->registry->shortcodes->{$shortcode} = $shortcode_path.$shortcode_class.$shortcode_ext;
160 160
         return true;
161 161
     }
162 162
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         // cycle thru shortcode folders
174 174
         foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
175 175
             // add class prefix
176
-            $shortcode_class = 'EES_' . $shortcode;
176
+            $shortcode_class = 'EES_'.$shortcode;
177 177
             // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
178 178
             // which set hooks ?
179 179
             if (is_admin()) {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
                 $shortcode_tag = strtoupper($shortcode);
190 190
                 // but first check if the shortcode has already
191 191
                 // been added before assigning 'fallback_shortcode_processor'
192
-                if (! shortcode_exists($shortcode_tag)) {
192
+                if ( ! shortcode_exists($shortcode_tag)) {
193 193
                     // NOTE: this shortcode declaration will get overridden if the shortcode
194 194
                     // is successfully detected in the post content in initializeShortcode()
195 195
                     add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
      */
396 396
     public static function addShortcodeClassPrefix($class_name)
397 397
     {
398
-        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
398
+        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_'.$class_name;
399 399
     }
400 400
 
401 401
 
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 2 patches
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     public static function instance()
35 35
     {
36 36
         // check if class object is instantiated, and instantiated properly
37
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
37
+        if ( ! self::$_instance instanceof EEH_Debug_Tools) {
38 38
             self::$_instance = new self();
39 39
         }
40 40
         return self::$_instance;
@@ -48,13 +48,13 @@  discard block
 block discarded – undo
48 48
     private function __construct()
49 49
     {
50 50
         // load Kint PHP debugging library
51
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) {
51
+        if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php')) {
52 52
             // despite EE4 having a check for an existing copy of the Kint debugging class,
53 53
             // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
54 54
             // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
55 55
             // so we've moved it to our test folder so that it is not included with production releases
56 56
             // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
57
-            require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
57
+            require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php');
58 58
         }
59 59
         // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
60 60
         // add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public static function show_db_name()
76 76
     {
77
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
77
+        if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
78 78
             echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
79 79
                  . DB_NAME
80 80
                  . '</p>';
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
         global $wp_filter;
124 124
         echo '<br/><br/><br/><h3>Hooked Functions</h3>';
125 125
         if ($tag) {
126
-            $hook[ $tag ] = $wp_filter[ $tag ];
127
-            if (! is_array($hook[ $tag ])) {
126
+            $hook[$tag] = $wp_filter[$tag];
127
+            if ( ! is_array($hook[$tag])) {
128 128
                 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
129 129
                 return;
130 130
             }
131
-            echo '<h5>For Tag: ' . $tag . '</h5>';
131
+            echo '<h5>For Tag: '.$tag.'</h5>';
132 132
         } else {
133 133
             $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
134 134
             ksort($hook);
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
     {
158 158
         $filters = array();
159 159
         global $wp_filter;
160
-        if (isset($wp_filter[ $hook_name ])) {
161
-            $filters[ $hook_name ] = array();
162
-            foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
163
-                $filters[ $hook_name ][ $priority ] = array();
160
+        if (isset($wp_filter[$hook_name])) {
161
+            $filters[$hook_name] = array();
162
+            foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
163
+                $filters[$hook_name][$priority] = array();
164 164
                 foreach ($callbacks as $callback) {
165
-                    $filters[ $hook_name ][ $priority ][] = $callback['function'];
165
+                    $filters[$hook_name][$priority][] = $callback['function'];
166 166
                 }
167 167
             }
168 168
         }
@@ -181,17 +181,17 @@  discard block
 block discarded – undo
181 181
     {
182 182
         if (WP_DEBUG) {
183 183
             $activation_errors = ob_get_contents();
184
-            if (! empty($activation_errors)) {
185
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
184
+            if ( ! empty($activation_errors)) {
185
+                $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
186 186
             }
187
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
187
+            espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
188 188
             if (class_exists('EEH_File')) {
189 189
                 try {
190 190
                     EEH_File::ensure_file_exists_and_is_writable(
191
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
191
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html'
192 192
                     );
193 193
                     EEH_File::write_to_file(
194
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
194
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html',
195 195
                         $activation_errors
196 196
                     );
197 197
                 } catch (EE_Error $e) {
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
             } else {
212 212
                 // old school attempt
213 213
                 file_put_contents(
214
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
214
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html',
215 215
                     $activation_errors
216 216
                 );
217 217
             }
218
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
218
+            $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
219 219
             update_option('ee_plugin_activation_errors', $activation_errors);
220 220
         }
221 221
     }
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         // don't trigger error if doing ajax,
276 276
         // instead we'll add a transient EE_Error notice that in theory should show on the next request.
277 277
         if (defined('DOING_AJAX') && DOING_AJAX) {
278
-            $error_message .= ' ' . esc_html__(
278
+            $error_message .= ' '.esc_html__(
279 279
                 'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
280 280
                 'event_espresso'
281 281
             );
@@ -319,19 +319,19 @@  discard block
 block discarded – undo
319 319
         $debug_key = 'EE_DEBUG_SPCO'
320 320
     ) {
321 321
         if (WP_DEBUG) {
322
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
322
+            $debug_key = $debug_key.'_'.EE_Session::instance()->id();
323 323
             $debug_data = get_option($debug_key, array());
324 324
             $default_data = array(
325
-                $class => $func . '() : ' . $line,
325
+                $class => $func.'() : '.$line,
326 326
                 'REQ'  => $display_request ? $_REQUEST : '',
327 327
             );
328 328
             // don't serialize objects
329 329
             $info = self::strip_objects($info);
330 330
             $index = ! empty($debug_index) ? $debug_index : 0;
331
-            if (! isset($debug_data[ $index ])) {
332
-                $debug_data[ $index ] = array();
331
+            if ( ! isset($debug_data[$index])) {
332
+                $debug_data[$index] = array();
333 333
             }
334
-            $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
334
+            $debug_data[$index][microtime()] = array_merge($default_data, $info);
335 335
             update_option($debug_key, $debug_data);
336 336
         }
337 337
     }
@@ -348,20 +348,20 @@  discard block
 block discarded – undo
348 348
     {
349 349
         foreach ($info as $key => $value) {
350 350
             if (is_array($value)) {
351
-                $info[ $key ] = self::strip_objects($value);
351
+                $info[$key] = self::strip_objects($value);
352 352
             } elseif (is_object($value)) {
353 353
                 $object_class = get_class($value);
354
-                $info[ $object_class ] = array();
355
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
354
+                $info[$object_class] = array();
355
+                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
356 356
                 if (method_exists($value, 'ID')) {
357
-                    $info[ $object_class ]['ID'] = $value->ID();
357
+                    $info[$object_class]['ID'] = $value->ID();
358 358
                 }
359 359
                 if (method_exists($value, 'status')) {
360
-                    $info[ $object_class ]['status'] = $value->status();
360
+                    $info[$object_class]['status'] = $value->status();
361 361
                 } elseif (method_exists($value, 'status_ID')) {
362
-                    $info[ $object_class ]['status'] = $value->status_ID();
362
+                    $info[$object_class]['status'] = $value->status_ID();
363 363
                 }
364
-                unset($info[ $key ]);
364
+                unset($info[$key]);
365 365
             }
366 366
         }
367 367
         return (array) $info;
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
         $result = EEH_Debug_Tools::headingSpacer($heading_tag);
396 396
         $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
397 397
         $result .= $is_method
398
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
399
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
398
+            ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()')
399
+            : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var);
400 400
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
401 401
         $result .= EEH_Debug_Tools::headingX($heading_tag);
402 402
         if ($die) {
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
             return $heading;
451 451
         }
452 452
         $margin = "25px 0 0 {$margin}";
453
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
453
+        return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>';
454 454
     }
455 455
 
456 456
 
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
         if (EEH_Debug_Tools::plainOutput()) {
465 465
             return '';
466 466
         }
467
-        return '</' . $heading_tag . '>';
467
+        return '</'.$heading_tag.'>';
468 468
     }
469 469
 
470 470
 
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
         if (EEH_Debug_Tools::plainOutput()) {
479 479
             return $content;
480 480
         }
481
-        return '<span style="color:#999">' . $content . '</span>';
481
+        return '<span style="color:#999">'.$content.'</span>';
482 482
     }
483 483
 
484 484
 
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
         if (EEH_Debug_Tools::plainOutput()) {
519 519
             return $content;
520 520
         }
521
-        return '<span style="color:#E76700">' . $content . '</span>';
521
+        return '<span style="color:#E76700">'.$content.'</span>';
522 522
     }
523 523
 
524 524
 
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
         if (EEH_Debug_Tools::plainOutput()) {
536 536
             return $var;
537 537
         }
538
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
538
+        return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>';
539 539
     }
540 540
 
541 541
 
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
         $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
580 580
         $result = EEH_Debug_Tools::headingSpacer($heading_tag);
581 581
         $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
582
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
582
+        $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span(
583 583
             EEH_Debug_Tools::pre_span($var)
584 584
         );
585 585
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
Please login to merge, or discard this patch.
Indentation   +685 added lines, -685 removed lines patch added patch discarded remove patch
@@ -11,676 +11,676 @@  discard block
 block discarded – undo
11 11
 class EEH_Debug_Tools
12 12
 {
13 13
 
14
-    /**
15
-     *    instance of the EEH_Autoloader object
16
-     *
17
-     * @var    $_instance
18
-     * @access    private
19
-     */
20
-    private static $_instance;
21
-
22
-    /**
23
-     * @var array
24
-     */
25
-    protected $_memory_usage_points = array();
26
-
27
-
28
-
29
-    /**
30
-     * @singleton method used to instantiate class object
31
-     * @access    public
32
-     * @return EEH_Debug_Tools
33
-     */
34
-    public static function instance()
35
-    {
36
-        // check if class object is instantiated, and instantiated properly
37
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
38
-            self::$_instance = new self();
39
-        }
40
-        return self::$_instance;
41
-    }
42
-
43
-
44
-
45
-    /**
46
-     * private class constructor
47
-     */
48
-    private function __construct()
49
-    {
50
-        // load Kint PHP debugging library
51
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) {
52
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
53
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
54
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
55
-            // so we've moved it to our test folder so that it is not included with production releases
56
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
57
-            require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
58
-        }
59
-        // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
60
-        // add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
61
-        // }
62
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
63
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
64
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
65
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     *    show_db_name
72
-     *
73
-     * @return void
74
-     */
75
-    public static function show_db_name()
76
-    {
77
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
78
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
79
-                 . DB_NAME
80
-                 . '</p>';
81
-        }
82
-        if (EE_DEBUG) {
83
-            Benchmark::displayResults();
84
-        }
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     *    dump EE_Session object at bottom of page after everything else has happened
91
-     *
92
-     * @return void
93
-     */
94
-    public function espresso_session_footer_dump()
95
-    {
96
-        if ((defined('WP_DEBUG') && WP_DEBUG)
97
-            && ! defined('DOING_AJAX')
98
-            && class_exists('Kint')
99
-            && function_exists('wp_get_current_user')
100
-            && current_user_can('update_core')
101
-            && class_exists('EE_Registry')
102
-        ) {
103
-            Kint::dump(EE_Registry::instance()->SSN->id());
104
-            Kint::dump(EE_Registry::instance()->SSN);
105
-            //          Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
106
-            $this->espresso_list_hooked_functions();
107
-            Benchmark::displayResults();
108
-        }
109
-    }
110
-
111
-
112
-
113
-    /**
114
-     *    List All Hooked Functions
115
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
116
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
117
-     *
118
-     * @param string $tag
119
-     * @return void
120
-     */
121
-    public function espresso_list_hooked_functions($tag = '')
122
-    {
123
-        global $wp_filter;
124
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
125
-        if ($tag) {
126
-            $hook[ $tag ] = $wp_filter[ $tag ];
127
-            if (! is_array($hook[ $tag ])) {
128
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
129
-                return;
130
-            }
131
-            echo '<h5>For Tag: ' . $tag . '</h5>';
132
-        } else {
133
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
134
-            ksort($hook);
135
-        }
136
-        foreach ($hook as $tag_name => $priorities) {
137
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
138
-            ksort($priorities);
139
-            foreach ($priorities as $priority => $function) {
140
-                echo $priority;
141
-                foreach ($function as $name => $properties) {
142
-                    echo "\t$name<br />";
143
-                }
144
-            }
145
-        }
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     *    registered_filter_callbacks
152
-     *
153
-     * @param string $hook_name
154
-     * @return array
155
-     */
156
-    public static function registered_filter_callbacks($hook_name = '')
157
-    {
158
-        $filters = array();
159
-        global $wp_filter;
160
-        if (isset($wp_filter[ $hook_name ])) {
161
-            $filters[ $hook_name ] = array();
162
-            foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
163
-                $filters[ $hook_name ][ $priority ] = array();
164
-                foreach ($callbacks as $callback) {
165
-                    $filters[ $hook_name ][ $priority ][] = $callback['function'];
166
-                }
167
-            }
168
-        }
169
-        return $filters;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     *    captures plugin activation errors for debugging
176
-     *
177
-     * @return void
178
-     * @throws EE_Error
179
-     */
180
-    public static function ee_plugin_activation_errors()
181
-    {
182
-        if (WP_DEBUG) {
183
-            $activation_errors = ob_get_contents();
184
-            if (! empty($activation_errors)) {
185
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
186
-            }
187
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
188
-            if (class_exists('EEH_File')) {
189
-                try {
190
-                    EEH_File::ensure_file_exists_and_is_writable(
191
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
192
-                    );
193
-                    EEH_File::write_to_file(
194
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
195
-                        $activation_errors
196
-                    );
197
-                } catch (EE_Error $e) {
198
-                    EE_Error::add_error(
199
-                        sprintf(
200
-                            __(
201
-                                'The Event Espresso activation errors file could not be setup because: %s',
202
-                                'event_espresso'
203
-                            ),
204
-                            $e->getMessage()
205
-                        ),
206
-                        __FILE__,
207
-                        __FUNCTION__,
208
-                        __LINE__
209
-                    );
210
-                }
211
-            } else {
212
-                // old school attempt
213
-                file_put_contents(
214
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
215
-                    $activation_errors
216
-                );
217
-            }
218
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
219
-            update_option('ee_plugin_activation_errors', $activation_errors);
220
-        }
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
227
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
228
-     * or we want to make sure they use something the right way.
229
-     *
230
-     * @access public
231
-     * @param string $function      The function that was called
232
-     * @param string $message       A message explaining what has been done incorrectly
233
-     * @param string $version       The version of Event Espresso where the error was added
234
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
235
-     *                              for a deprecated function. This allows deprecation to occur during one version,
236
-     *                              but not have any notices appear until a later version. This allows developers
237
-     *                              extra time to update their code before notices appear.
238
-     * @param int    $error_type
239
-     * @uses   trigger_error()
240
-     */
241
-    public function doing_it_wrong(
242
-        $function,
243
-        $message,
244
-        $version,
245
-        $applies_when = '',
246
-        $error_type = null
247
-    ) {
248
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
249
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
250
-        // because we swapped the parameter order around for the last two params,
251
-        // let's verify that some third party isn't still passing an error type value for the third param
252
-        if (is_int($applies_when)) {
253
-            $error_type = $applies_when;
254
-            $applies_when = espresso_version();
255
-        }
256
-        // if not displaying notices yet, then just leave
257
-        if (version_compare(espresso_version(), $applies_when, '<')) {
258
-            return;
259
-        }
260
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
261
-        $version = $version === null
262
-            ? ''
263
-            : sprintf(
264
-                __('(This message was added in version %s of Event Espresso)', 'event_espresso'),
265
-                $version
266
-            );
267
-        $error_message = sprintf(
268
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
269
-            $function,
270
-            '<strong>',
271
-            '</strong>',
272
-            $message,
273
-            $version
274
-        );
275
-        // don't trigger error if doing ajax,
276
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
277
-        if (defined('DOING_AJAX') && DOING_AJAX) {
278
-            $error_message .= ' ' . esc_html__(
279
-                'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
280
-                'event_espresso'
281
-            );
282
-            $error_message .= '<ul><li>';
283
-            $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
284
-            $error_message .= '</ul>';
285
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
286
-            // now we set this on the transient so it shows up on the next request.
287
-            EE_Error::get_notices(false, true);
288
-        } else {
289
-            trigger_error($error_message, $error_type);
290
-        }
291
-    }
292
-
293
-
294
-
295
-
296
-    /**
297
-     * Logger helpers
298
-     */
299
-    /**
300
-     * debug
301
-     *
302
-     * @param string $class
303
-     * @param string $func
304
-     * @param string $line
305
-     * @param array  $info
306
-     * @param bool   $display_request
307
-     * @param string $debug_index
308
-     * @param string $debug_key
309
-     * @throws EE_Error
310
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
311
-     */
312
-    public static function log(
313
-        $class = '',
314
-        $func = '',
315
-        $line = '',
316
-        $info = array(),
317
-        $display_request = false,
318
-        $debug_index = '',
319
-        $debug_key = 'EE_DEBUG_SPCO'
320
-    ) {
321
-        if (WP_DEBUG) {
322
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
323
-            $debug_data = get_option($debug_key, array());
324
-            $default_data = array(
325
-                $class => $func . '() : ' . $line,
326
-                'REQ'  => $display_request ? $_REQUEST : '',
327
-            );
328
-            // don't serialize objects
329
-            $info = self::strip_objects($info);
330
-            $index = ! empty($debug_index) ? $debug_index : 0;
331
-            if (! isset($debug_data[ $index ])) {
332
-                $debug_data[ $index ] = array();
333
-            }
334
-            $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
335
-            update_option($debug_key, $debug_data);
336
-        }
337
-    }
338
-
339
-
340
-
341
-    /**
342
-     * strip_objects
343
-     *
344
-     * @param array $info
345
-     * @return array
346
-     */
347
-    public static function strip_objects($info = array())
348
-    {
349
-        foreach ($info as $key => $value) {
350
-            if (is_array($value)) {
351
-                $info[ $key ] = self::strip_objects($value);
352
-            } elseif (is_object($value)) {
353
-                $object_class = get_class($value);
354
-                $info[ $object_class ] = array();
355
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
356
-                if (method_exists($value, 'ID')) {
357
-                    $info[ $object_class ]['ID'] = $value->ID();
358
-                }
359
-                if (method_exists($value, 'status')) {
360
-                    $info[ $object_class ]['status'] = $value->status();
361
-                } elseif (method_exists($value, 'status_ID')) {
362
-                    $info[ $object_class ]['status'] = $value->status_ID();
363
-                }
364
-                unset($info[ $key ]);
365
-            }
366
-        }
367
-        return (array) $info;
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     * @param mixed      $var
374
-     * @param string     $var_name
375
-     * @param string     $file
376
-     * @param int|string $line
377
-     * @param int|string $heading_tag
378
-     * @param bool       $die
379
-     * @param string     $margin
380
-     */
381
-    public static function printv(
382
-        $var,
383
-        $var_name = '',
384
-        $file = '',
385
-        $line = '',
386
-        $heading_tag = 5,
387
-        $die = false,
388
-        $margin = ''
389
-    ) {
390
-        $var_name = ! $var_name ? 'string' : $var_name;
391
-        $var_name = ucwords(str_replace('$', '', $var_name));
392
-        $is_method = method_exists($var_name, $var);
393
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
394
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
395
-        $result = EEH_Debug_Tools::headingSpacer($heading_tag);
396
-        $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
397
-        $result .= $is_method
398
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
399
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
400
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
401
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
402
-        if ($die) {
403
-            die($result);
404
-        }
405
-        echo $result;
406
-    }
407
-
408
-
409
-    protected static function headingTag($heading_tag)
410
-    {
411
-        $heading_tag = absint($heading_tag);
412
-        return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
413
-    }
414
-
415
-
416
-    protected static function headingSpacer($heading_tag)
417
-    {
418
-        return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
419
-            ? "\n"
420
-            : '';
421
-    }
422
-
423
-
424
-    protected static function plainOutput()
425
-    {
426
-        return defined('EE_TESTS_DIR')
427
-               || (defined('DOING_AJAX') && DOING_AJAX)
428
-               || (
429
-                   isset($_SERVER['REQUEST_URI'])
430
-                   && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false
431
-               );
432
-    }
433
-
434
-
435
-    /**
436
-     * @param string $var_name
437
-     * @param string $heading_tag
438
-     * @param string $margin
439
-     * @param int    $line
440
-     * @return string
441
-     */
442
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
443
-    {
444
-        if (EEH_Debug_Tools::plainOutput()) {
445
-            $heading = '';
446
-            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
447
-                $heading .= "\n";
448
-            }
449
-            $heading .= "\n{$line}) {$var_name}";
450
-            return $heading;
451
-        }
452
-        $margin = "25px 0 0 {$margin}";
453
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     * @param string $heading_tag
460
-     * @return string
461
-     */
462
-    protected static function headingX($heading_tag = 'h5')
463
-    {
464
-        if (EEH_Debug_Tools::plainOutput()) {
465
-            return '';
466
-        }
467
-        return '</' . $heading_tag . '>';
468
-    }
469
-
470
-
471
-
472
-    /**
473
-     * @param string $content
474
-     * @return string
475
-     */
476
-    protected static function grey_span($content = '')
477
-    {
478
-        if (EEH_Debug_Tools::plainOutput()) {
479
-            return $content;
480
-        }
481
-        return '<span style="color:#999">' . $content . '</span>';
482
-    }
483
-
484
-
485
-
486
-    /**
487
-     * @param string $file
488
-     * @param int    $line
489
-     * @return string
490
-     */
491
-    protected static function file_and_line($file, $line, $heading_tag)
492
-    {
493
-        if ($file === '' || $line === '') {
494
-            return '';
495
-        }
496
-        $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
497
-        if (EEH_Debug_Tools::plainOutput()) {
498
-            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
499
-                return " ({$file})";
500
-            }
501
-            return '';
502
-        }
503
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
504
-               . $file
505
-               . '<br />line no: '
506
-               . $line
507
-               . '</span>';
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * @param string $content
514
-     * @return string
515
-     */
516
-    protected static function orange_span($content = '')
517
-    {
518
-        if (EEH_Debug_Tools::plainOutput()) {
519
-            return $content;
520
-        }
521
-        return '<span style="color:#E76700">' . $content . '</span>';
522
-    }
523
-
524
-
525
-
526
-    /**
527
-     * @param mixed $var
528
-     * @return string
529
-     */
530
-    protected static function pre_span($var)
531
-    {
532
-        ob_start();
533
-        var_dump($var);
534
-        $var = ob_get_clean();
535
-        if (EEH_Debug_Tools::plainOutput()) {
536
-            return $var;
537
-        }
538
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     * @param mixed      $var
545
-     * @param string     $var_name
546
-     * @param string     $file
547
-     * @param int|string $line
548
-     * @param int|string $heading_tag
549
-     * @param bool       $die
550
-     */
551
-    public static function printr(
552
-        $var,
553
-        $var_name = '',
554
-        $file = '',
555
-        $line = '',
556
-        $heading_tag = 5,
557
-        $die = false
558
-    ) {
559
-        // return;
560
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
561
-        if (empty($var) && empty($var_name)) {
562
-            $var = $file;
563
-            $var_name = "line $line";
564
-            $file = '';
565
-            $line = '';
566
-        }
567
-        $margin = is_admin() ? ' 180px' : '0';
568
-        // $print_r = false;
569
-        if (is_string($var)) {
570
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
571
-            return;
572
-        }
573
-        if (is_object($var)) {
574
-            $var_name = ! $var_name ? 'object' : $var_name;
575
-            // $print_r = true;
576
-        } elseif (is_array($var)) {
577
-            $var_name = ! $var_name ? 'array' : $var_name;
578
-            // $print_r = true;
579
-        } elseif (is_numeric($var)) {
580
-            $var_name = ! $var_name ? 'numeric' : $var_name;
581
-        } elseif ($var === null) {
582
-            $var_name = ! $var_name ? 'null' : $var_name;
583
-        }
584
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
585
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
586
-        $result = EEH_Debug_Tools::headingSpacer($heading_tag);
587
-        $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
588
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
589
-            EEH_Debug_Tools::pre_span($var)
590
-        );
591
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
592
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
593
-        if ($die) {
594
-            die($result);
595
-        }
596
-        echo $result;
597
-    }
598
-
599
-
600
-
601
-    /******************** deprecated ********************/
602
-
603
-
604
-
605
-    /**
606
-     * @deprecated 4.9.39.rc.034
607
-     */
608
-    public function reset_times()
609
-    {
610
-        Benchmark::resetTimes();
611
-    }
612
-
613
-
614
-
615
-    /**
616
-     * @deprecated 4.9.39.rc.034
617
-     * @param null $timer_name
618
-     */
619
-    public function start_timer($timer_name = null)
620
-    {
621
-        Benchmark::startTimer($timer_name);
622
-    }
623
-
624
-
625
-
626
-    /**
627
-     * @deprecated 4.9.39.rc.034
628
-     * @param string $timer_name
629
-     */
630
-    public function stop_timer($timer_name = '')
631
-    {
632
-        Benchmark::stopTimer($timer_name);
633
-    }
634
-
635
-
636
-
637
-    /**
638
-     * @deprecated 4.9.39.rc.034
639
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
640
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
641
-     * @return void
642
-     */
643
-    public function measure_memory($label, $output_now = false)
644
-    {
645
-        Benchmark::measureMemory($label, $output_now);
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * @deprecated 4.9.39.rc.034
652
-     * @param int $size
653
-     * @return string
654
-     */
655
-    public function convert($size)
656
-    {
657
-        return Benchmark::convert($size);
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     * @deprecated 4.9.39.rc.034
664
-     * @param bool $output_now
665
-     * @return string
666
-     */
667
-    public function show_times($output_now = true)
668
-    {
669
-        return Benchmark::displayResults($output_now);
670
-    }
671
-
672
-
673
-
674
-    /**
675
-     * @deprecated 4.9.39.rc.034
676
-     * @param string $timer_name
677
-     * @param float  $total_time
678
-     * @return string
679
-     */
680
-    public function format_time($timer_name, $total_time)
681
-    {
682
-        return Benchmark::formatTime($timer_name, $total_time);
683
-    }
14
+	/**
15
+	 *    instance of the EEH_Autoloader object
16
+	 *
17
+	 * @var    $_instance
18
+	 * @access    private
19
+	 */
20
+	private static $_instance;
21
+
22
+	/**
23
+	 * @var array
24
+	 */
25
+	protected $_memory_usage_points = array();
26
+
27
+
28
+
29
+	/**
30
+	 * @singleton method used to instantiate class object
31
+	 * @access    public
32
+	 * @return EEH_Debug_Tools
33
+	 */
34
+	public static function instance()
35
+	{
36
+		// check if class object is instantiated, and instantiated properly
37
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
38
+			self::$_instance = new self();
39
+		}
40
+		return self::$_instance;
41
+	}
42
+
43
+
44
+
45
+	/**
46
+	 * private class constructor
47
+	 */
48
+	private function __construct()
49
+	{
50
+		// load Kint PHP debugging library
51
+		if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) {
52
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
53
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
54
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
55
+			// so we've moved it to our test folder so that it is not included with production releases
56
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
57
+			require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
58
+		}
59
+		// if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
60
+		// add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
61
+		// }
62
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
63
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
64
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
65
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 *    show_db_name
72
+	 *
73
+	 * @return void
74
+	 */
75
+	public static function show_db_name()
76
+	{
77
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
78
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
79
+				 . DB_NAME
80
+				 . '</p>';
81
+		}
82
+		if (EE_DEBUG) {
83
+			Benchmark::displayResults();
84
+		}
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 *    dump EE_Session object at bottom of page after everything else has happened
91
+	 *
92
+	 * @return void
93
+	 */
94
+	public function espresso_session_footer_dump()
95
+	{
96
+		if ((defined('WP_DEBUG') && WP_DEBUG)
97
+			&& ! defined('DOING_AJAX')
98
+			&& class_exists('Kint')
99
+			&& function_exists('wp_get_current_user')
100
+			&& current_user_can('update_core')
101
+			&& class_exists('EE_Registry')
102
+		) {
103
+			Kint::dump(EE_Registry::instance()->SSN->id());
104
+			Kint::dump(EE_Registry::instance()->SSN);
105
+			//          Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
106
+			$this->espresso_list_hooked_functions();
107
+			Benchmark::displayResults();
108
+		}
109
+	}
110
+
111
+
112
+
113
+	/**
114
+	 *    List All Hooked Functions
115
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
116
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
117
+	 *
118
+	 * @param string $tag
119
+	 * @return void
120
+	 */
121
+	public function espresso_list_hooked_functions($tag = '')
122
+	{
123
+		global $wp_filter;
124
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
125
+		if ($tag) {
126
+			$hook[ $tag ] = $wp_filter[ $tag ];
127
+			if (! is_array($hook[ $tag ])) {
128
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
129
+				return;
130
+			}
131
+			echo '<h5>For Tag: ' . $tag . '</h5>';
132
+		} else {
133
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
134
+			ksort($hook);
135
+		}
136
+		foreach ($hook as $tag_name => $priorities) {
137
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
138
+			ksort($priorities);
139
+			foreach ($priorities as $priority => $function) {
140
+				echo $priority;
141
+				foreach ($function as $name => $properties) {
142
+					echo "\t$name<br />";
143
+				}
144
+			}
145
+		}
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 *    registered_filter_callbacks
152
+	 *
153
+	 * @param string $hook_name
154
+	 * @return array
155
+	 */
156
+	public static function registered_filter_callbacks($hook_name = '')
157
+	{
158
+		$filters = array();
159
+		global $wp_filter;
160
+		if (isset($wp_filter[ $hook_name ])) {
161
+			$filters[ $hook_name ] = array();
162
+			foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
163
+				$filters[ $hook_name ][ $priority ] = array();
164
+				foreach ($callbacks as $callback) {
165
+					$filters[ $hook_name ][ $priority ][] = $callback['function'];
166
+				}
167
+			}
168
+		}
169
+		return $filters;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 *    captures plugin activation errors for debugging
176
+	 *
177
+	 * @return void
178
+	 * @throws EE_Error
179
+	 */
180
+	public static function ee_plugin_activation_errors()
181
+	{
182
+		if (WP_DEBUG) {
183
+			$activation_errors = ob_get_contents();
184
+			if (! empty($activation_errors)) {
185
+				$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
186
+			}
187
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
188
+			if (class_exists('EEH_File')) {
189
+				try {
190
+					EEH_File::ensure_file_exists_and_is_writable(
191
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
192
+					);
193
+					EEH_File::write_to_file(
194
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
195
+						$activation_errors
196
+					);
197
+				} catch (EE_Error $e) {
198
+					EE_Error::add_error(
199
+						sprintf(
200
+							__(
201
+								'The Event Espresso activation errors file could not be setup because: %s',
202
+								'event_espresso'
203
+							),
204
+							$e->getMessage()
205
+						),
206
+						__FILE__,
207
+						__FUNCTION__,
208
+						__LINE__
209
+					);
210
+				}
211
+			} else {
212
+				// old school attempt
213
+				file_put_contents(
214
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
215
+					$activation_errors
216
+				);
217
+			}
218
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
219
+			update_option('ee_plugin_activation_errors', $activation_errors);
220
+		}
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
227
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
228
+	 * or we want to make sure they use something the right way.
229
+	 *
230
+	 * @access public
231
+	 * @param string $function      The function that was called
232
+	 * @param string $message       A message explaining what has been done incorrectly
233
+	 * @param string $version       The version of Event Espresso where the error was added
234
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
235
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
236
+	 *                              but not have any notices appear until a later version. This allows developers
237
+	 *                              extra time to update their code before notices appear.
238
+	 * @param int    $error_type
239
+	 * @uses   trigger_error()
240
+	 */
241
+	public function doing_it_wrong(
242
+		$function,
243
+		$message,
244
+		$version,
245
+		$applies_when = '',
246
+		$error_type = null
247
+	) {
248
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
249
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
250
+		// because we swapped the parameter order around for the last two params,
251
+		// let's verify that some third party isn't still passing an error type value for the third param
252
+		if (is_int($applies_when)) {
253
+			$error_type = $applies_when;
254
+			$applies_when = espresso_version();
255
+		}
256
+		// if not displaying notices yet, then just leave
257
+		if (version_compare(espresso_version(), $applies_when, '<')) {
258
+			return;
259
+		}
260
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
261
+		$version = $version === null
262
+			? ''
263
+			: sprintf(
264
+				__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
265
+				$version
266
+			);
267
+		$error_message = sprintf(
268
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
269
+			$function,
270
+			'<strong>',
271
+			'</strong>',
272
+			$message,
273
+			$version
274
+		);
275
+		// don't trigger error if doing ajax,
276
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
277
+		if (defined('DOING_AJAX') && DOING_AJAX) {
278
+			$error_message .= ' ' . esc_html__(
279
+				'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
280
+				'event_espresso'
281
+			);
282
+			$error_message .= '<ul><li>';
283
+			$error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
284
+			$error_message .= '</ul>';
285
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
286
+			// now we set this on the transient so it shows up on the next request.
287
+			EE_Error::get_notices(false, true);
288
+		} else {
289
+			trigger_error($error_message, $error_type);
290
+		}
291
+	}
292
+
293
+
294
+
295
+
296
+	/**
297
+	 * Logger helpers
298
+	 */
299
+	/**
300
+	 * debug
301
+	 *
302
+	 * @param string $class
303
+	 * @param string $func
304
+	 * @param string $line
305
+	 * @param array  $info
306
+	 * @param bool   $display_request
307
+	 * @param string $debug_index
308
+	 * @param string $debug_key
309
+	 * @throws EE_Error
310
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
311
+	 */
312
+	public static function log(
313
+		$class = '',
314
+		$func = '',
315
+		$line = '',
316
+		$info = array(),
317
+		$display_request = false,
318
+		$debug_index = '',
319
+		$debug_key = 'EE_DEBUG_SPCO'
320
+	) {
321
+		if (WP_DEBUG) {
322
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
323
+			$debug_data = get_option($debug_key, array());
324
+			$default_data = array(
325
+				$class => $func . '() : ' . $line,
326
+				'REQ'  => $display_request ? $_REQUEST : '',
327
+			);
328
+			// don't serialize objects
329
+			$info = self::strip_objects($info);
330
+			$index = ! empty($debug_index) ? $debug_index : 0;
331
+			if (! isset($debug_data[ $index ])) {
332
+				$debug_data[ $index ] = array();
333
+			}
334
+			$debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
335
+			update_option($debug_key, $debug_data);
336
+		}
337
+	}
338
+
339
+
340
+
341
+	/**
342
+	 * strip_objects
343
+	 *
344
+	 * @param array $info
345
+	 * @return array
346
+	 */
347
+	public static function strip_objects($info = array())
348
+	{
349
+		foreach ($info as $key => $value) {
350
+			if (is_array($value)) {
351
+				$info[ $key ] = self::strip_objects($value);
352
+			} elseif (is_object($value)) {
353
+				$object_class = get_class($value);
354
+				$info[ $object_class ] = array();
355
+				$info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
356
+				if (method_exists($value, 'ID')) {
357
+					$info[ $object_class ]['ID'] = $value->ID();
358
+				}
359
+				if (method_exists($value, 'status')) {
360
+					$info[ $object_class ]['status'] = $value->status();
361
+				} elseif (method_exists($value, 'status_ID')) {
362
+					$info[ $object_class ]['status'] = $value->status_ID();
363
+				}
364
+				unset($info[ $key ]);
365
+			}
366
+		}
367
+		return (array) $info;
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 * @param mixed      $var
374
+	 * @param string     $var_name
375
+	 * @param string     $file
376
+	 * @param int|string $line
377
+	 * @param int|string $heading_tag
378
+	 * @param bool       $die
379
+	 * @param string     $margin
380
+	 */
381
+	public static function printv(
382
+		$var,
383
+		$var_name = '',
384
+		$file = '',
385
+		$line = '',
386
+		$heading_tag = 5,
387
+		$die = false,
388
+		$margin = ''
389
+	) {
390
+		$var_name = ! $var_name ? 'string' : $var_name;
391
+		$var_name = ucwords(str_replace('$', '', $var_name));
392
+		$is_method = method_exists($var_name, $var);
393
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
394
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
395
+		$result = EEH_Debug_Tools::headingSpacer($heading_tag);
396
+		$result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
397
+		$result .= $is_method
398
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
399
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
400
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
401
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
402
+		if ($die) {
403
+			die($result);
404
+		}
405
+		echo $result;
406
+	}
407
+
408
+
409
+	protected static function headingTag($heading_tag)
410
+	{
411
+		$heading_tag = absint($heading_tag);
412
+		return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
413
+	}
414
+
415
+
416
+	protected static function headingSpacer($heading_tag)
417
+	{
418
+		return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
419
+			? "\n"
420
+			: '';
421
+	}
422
+
423
+
424
+	protected static function plainOutput()
425
+	{
426
+		return defined('EE_TESTS_DIR')
427
+			   || (defined('DOING_AJAX') && DOING_AJAX)
428
+			   || (
429
+				   isset($_SERVER['REQUEST_URI'])
430
+				   && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false
431
+			   );
432
+	}
433
+
434
+
435
+	/**
436
+	 * @param string $var_name
437
+	 * @param string $heading_tag
438
+	 * @param string $margin
439
+	 * @param int    $line
440
+	 * @return string
441
+	 */
442
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
443
+	{
444
+		if (EEH_Debug_Tools::plainOutput()) {
445
+			$heading = '';
446
+			if ($heading_tag === 'h1' || $heading_tag === 'h2') {
447
+				$heading .= "\n";
448
+			}
449
+			$heading .= "\n{$line}) {$var_name}";
450
+			return $heading;
451
+		}
452
+		$margin = "25px 0 0 {$margin}";
453
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 * @param string $heading_tag
460
+	 * @return string
461
+	 */
462
+	protected static function headingX($heading_tag = 'h5')
463
+	{
464
+		if (EEH_Debug_Tools::plainOutput()) {
465
+			return '';
466
+		}
467
+		return '</' . $heading_tag . '>';
468
+	}
469
+
470
+
471
+
472
+	/**
473
+	 * @param string $content
474
+	 * @return string
475
+	 */
476
+	protected static function grey_span($content = '')
477
+	{
478
+		if (EEH_Debug_Tools::plainOutput()) {
479
+			return $content;
480
+		}
481
+		return '<span style="color:#999">' . $content . '</span>';
482
+	}
483
+
484
+
485
+
486
+	/**
487
+	 * @param string $file
488
+	 * @param int    $line
489
+	 * @return string
490
+	 */
491
+	protected static function file_and_line($file, $line, $heading_tag)
492
+	{
493
+		if ($file === '' || $line === '') {
494
+			return '';
495
+		}
496
+		$file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
497
+		if (EEH_Debug_Tools::plainOutput()) {
498
+			if ($heading_tag === 'h1' || $heading_tag === 'h2') {
499
+				return " ({$file})";
500
+			}
501
+			return '';
502
+		}
503
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
504
+			   . $file
505
+			   . '<br />line no: '
506
+			   . $line
507
+			   . '</span>';
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * @param string $content
514
+	 * @return string
515
+	 */
516
+	protected static function orange_span($content = '')
517
+	{
518
+		if (EEH_Debug_Tools::plainOutput()) {
519
+			return $content;
520
+		}
521
+		return '<span style="color:#E76700">' . $content . '</span>';
522
+	}
523
+
524
+
525
+
526
+	/**
527
+	 * @param mixed $var
528
+	 * @return string
529
+	 */
530
+	protected static function pre_span($var)
531
+	{
532
+		ob_start();
533
+		var_dump($var);
534
+		$var = ob_get_clean();
535
+		if (EEH_Debug_Tools::plainOutput()) {
536
+			return $var;
537
+		}
538
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 * @param mixed      $var
545
+	 * @param string     $var_name
546
+	 * @param string     $file
547
+	 * @param int|string $line
548
+	 * @param int|string $heading_tag
549
+	 * @param bool       $die
550
+	 */
551
+	public static function printr(
552
+		$var,
553
+		$var_name = '',
554
+		$file = '',
555
+		$line = '',
556
+		$heading_tag = 5,
557
+		$die = false
558
+	) {
559
+		// return;
560
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
561
+		if (empty($var) && empty($var_name)) {
562
+			$var = $file;
563
+			$var_name = "line $line";
564
+			$file = '';
565
+			$line = '';
566
+		}
567
+		$margin = is_admin() ? ' 180px' : '0';
568
+		// $print_r = false;
569
+		if (is_string($var)) {
570
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
571
+			return;
572
+		}
573
+		if (is_object($var)) {
574
+			$var_name = ! $var_name ? 'object' : $var_name;
575
+			// $print_r = true;
576
+		} elseif (is_array($var)) {
577
+			$var_name = ! $var_name ? 'array' : $var_name;
578
+			// $print_r = true;
579
+		} elseif (is_numeric($var)) {
580
+			$var_name = ! $var_name ? 'numeric' : $var_name;
581
+		} elseif ($var === null) {
582
+			$var_name = ! $var_name ? 'null' : $var_name;
583
+		}
584
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
585
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
586
+		$result = EEH_Debug_Tools::headingSpacer($heading_tag);
587
+		$result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
588
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
589
+			EEH_Debug_Tools::pre_span($var)
590
+		);
591
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
592
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
593
+		if ($die) {
594
+			die($result);
595
+		}
596
+		echo $result;
597
+	}
598
+
599
+
600
+
601
+	/******************** deprecated ********************/
602
+
603
+
604
+
605
+	/**
606
+	 * @deprecated 4.9.39.rc.034
607
+	 */
608
+	public function reset_times()
609
+	{
610
+		Benchmark::resetTimes();
611
+	}
612
+
613
+
614
+
615
+	/**
616
+	 * @deprecated 4.9.39.rc.034
617
+	 * @param null $timer_name
618
+	 */
619
+	public function start_timer($timer_name = null)
620
+	{
621
+		Benchmark::startTimer($timer_name);
622
+	}
623
+
624
+
625
+
626
+	/**
627
+	 * @deprecated 4.9.39.rc.034
628
+	 * @param string $timer_name
629
+	 */
630
+	public function stop_timer($timer_name = '')
631
+	{
632
+		Benchmark::stopTimer($timer_name);
633
+	}
634
+
635
+
636
+
637
+	/**
638
+	 * @deprecated 4.9.39.rc.034
639
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
640
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
641
+	 * @return void
642
+	 */
643
+	public function measure_memory($label, $output_now = false)
644
+	{
645
+		Benchmark::measureMemory($label, $output_now);
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * @deprecated 4.9.39.rc.034
652
+	 * @param int $size
653
+	 * @return string
654
+	 */
655
+	public function convert($size)
656
+	{
657
+		return Benchmark::convert($size);
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 * @deprecated 4.9.39.rc.034
664
+	 * @param bool $output_now
665
+	 * @return string
666
+	 */
667
+	public function show_times($output_now = true)
668
+	{
669
+		return Benchmark::displayResults($output_now);
670
+	}
671
+
672
+
673
+
674
+	/**
675
+	 * @deprecated 4.9.39.rc.034
676
+	 * @param string $timer_name
677
+	 * @param float  $total_time
678
+	 * @return string
679
+	 */
680
+	public function format_time($timer_name, $total_time)
681
+	{
682
+		return Benchmark::formatTime($timer_name, $total_time);
683
+	}
684 684
 }
685 685
 
686 686
 
@@ -690,31 +690,31 @@  discard block
 block discarded – undo
690 690
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
691 691
  */
692 692
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
693
-    function dump_wp_query()
694
-    {
695
-        global $wp_query;
696
-        d($wp_query);
697
-    }
693
+	function dump_wp_query()
694
+	{
695
+		global $wp_query;
696
+		d($wp_query);
697
+	}
698 698
 }
699 699
 /**
700 700
  * borrowed from Kint Debugger
701 701
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
702 702
  */
703 703
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
704
-    function dump_wp()
705
-    {
706
-        global $wp;
707
-        d($wp);
708
-    }
704
+	function dump_wp()
705
+	{
706
+		global $wp;
707
+		d($wp);
708
+	}
709 709
 }
710 710
 /**
711 711
  * borrowed from Kint Debugger
712 712
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
713 713
  */
714 714
 if (class_exists('Kint') && ! function_exists('dump_post')) {
715
-    function dump_post()
716
-    {
717
-        global $post;
718
-        d($post);
719
-    }
715
+	function dump_post()
716
+	{
717
+		global $post;
718
+		d($post);
719
+	}
720 720
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Template.helper.php 2 patches
Indentation   +962 added lines, -962 removed lines patch added patch discarded remove patch
@@ -5,35 +5,35 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 
7 7
 if (! function_exists('espresso_get_template_part')) {
8
-    /**
9
-     * espresso_get_template_part
10
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
11
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
12
-     *
13
-     * @param string $slug The slug name for the generic template.
14
-     * @param string $name The name of the specialised template.
15
-     * @return string        the html output for the formatted money value
16
-     */
17
-    function espresso_get_template_part($slug = null, $name = null)
18
-    {
19
-        EEH_Template::get_template_part($slug, $name);
20
-    }
8
+	/**
9
+	 * espresso_get_template_part
10
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
11
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
12
+	 *
13
+	 * @param string $slug The slug name for the generic template.
14
+	 * @param string $name The name of the specialised template.
15
+	 * @return string        the html output for the formatted money value
16
+	 */
17
+	function espresso_get_template_part($slug = null, $name = null)
18
+	{
19
+		EEH_Template::get_template_part($slug, $name);
20
+	}
21 21
 }
22 22
 
23 23
 
24 24
 if (! function_exists('espresso_get_object_css_class')) {
25
-    /**
26
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
-     *
28
-     * @param EE_Base_Class $object the EE object the css class is being generated for
29
-     * @param  string       $prefix added to the beginning of the generated class
30
-     * @param  string       $suffix added to the end of the generated class
31
-     * @return string
32
-     */
33
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
34
-    {
35
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
36
-    }
25
+	/**
26
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
+	 *
28
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
29
+	 * @param  string       $prefix added to the beginning of the generated class
30
+	 * @param  string       $suffix added to the end of the generated class
31
+	 * @return string
32
+	 */
33
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
34
+	{
35
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
36
+	}
37 37
 }
38 38
 
39 39
 
@@ -48,672 +48,672 @@  discard block
 block discarded – undo
48 48
 class EEH_Template
49 49
 {
50 50
 
51
-    private static $_espresso_themes = array();
52
-
53
-
54
-    /**
55
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
56
-     *
57
-     * @return boolean
58
-     */
59
-    public static function is_espresso_theme()
60
-    {
61
-        return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
62
-    }
63
-
64
-    /**
65
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
66
-     *    load it's functions.php file ( if not already loaded )
67
-     *
68
-     * @return void
69
-     */
70
-    public static function load_espresso_theme_functions()
71
-    {
72
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
74
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
75
-            }
76
-        }
77
-    }
78
-
79
-
80
-    /**
81
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
82
-     *
83
-     * @return array
84
-     */
85
-    public static function get_espresso_themes()
86
-    {
87
-        if (empty(EEH_Template::$_espresso_themes)) {
88
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
89
-            if (empty($espresso_themes)) {
90
-                return array();
91
-            }
92
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
-                unset($espresso_themes[ $key ]);
94
-            }
95
-            EEH_Template::$_espresso_themes = array();
96
-            foreach ($espresso_themes as $espresso_theme) {
97
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
98
-            }
99
-        }
100
-        return EEH_Template::$_espresso_themes;
101
-    }
102
-
103
-
104
-    /**
105
-     * EEH_Template::get_template_part
106
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
107
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
108
-     * filtering based off of the entire template part name
109
-     *
110
-     * @param string $slug The slug name for the generic template.
111
-     * @param string $name The name of the specialised template.
112
-     * @param array  $template_args
113
-     * @param bool   $return_string
114
-     * @return string        the html output for the formatted money value
115
-     */
116
-    public static function get_template_part(
117
-        $slug = null,
118
-        $name = null,
119
-        $template_args = array(),
120
-        $return_string = false
121
-    ) {
122
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
123
-        $templates = array();
124
-        $name      = (string) $name;
125
-        if ($name != '') {
126
-            $templates[] = "{$slug}-{$name}.php";
127
-        }
128
-        // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
129
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
130
-            EEH_Template::locate_template($templates, $template_args, true, $return_string);
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     *    locate_template
137
-     *    locate a template file by looking in the following places, in the following order:
138
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
139
-     *        <assumed full absolute server path>
140
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
141
-     *        <server path up to>/wp-content/uploads/espresso/templates/
142
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
143
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
144
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
145
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
146
-     *        Example:
147
-     *          You are using the WordPress Twenty Sixteen theme,
148
-     *        and you want to customize the "some-event.template.php" template,
149
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
150
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
151
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
152
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
153
-     *        /relative/path/to/some-event.template.php
154
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
155
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
156
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
157
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
158
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
159
-     *          Had you passed an absolute path to your template that was in some other location,
160
-     *        ie: "/absolute/path/to/some-event.template.php"
161
-     *          then the search would have been :
162
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
163
-     *        /absolute/path/to/some-event.template.php
164
-     *          and stopped there upon finding it in the second location
165
-     *
166
-     * @param array|string $templates       array of template file names including extension (or just a single string)
167
-     * @param  array       $template_args   an array of arguments to be extracted for use in the template
168
-     * @param  boolean     $load            whether to pass the located template path on to the
169
-     *                                      EEH_Template::display_template() method or simply return it
170
-     * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
171
-     *                                      string
172
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
173
-     *                                      generate a custom template or not. Used in places where you don't actually
174
-     *                                      load the template, you just want to know if there's a custom version of it.
175
-     * @return mixed
176
-     * @throws DomainException
177
-     * @throws InvalidArgumentException
178
-     * @throws InvalidDataTypeException
179
-     * @throws InvalidInterfaceException
180
-     */
181
-    public static function locate_template(
182
-        $templates = array(),
183
-        $template_args = array(),
184
-        $load = true,
185
-        $return_string = true,
186
-        $check_if_custom = false
187
-    ) {
188
-        // first use WP locate_template to check for template in the current theme folder
189
-        $template_path = locate_template($templates);
190
-
191
-        if ($check_if_custom && ! empty($template_path)) {
192
-            return true;
193
-        }
194
-
195
-        // not in the theme
196
-        if (empty($template_path)) {
197
-            // not even a template to look for ?
198
-            if (empty($templates)) {
199
-                // get post_type
200
-                $post_type = EE_Registry::instance()->REQ->get('post_type');
201
-                /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
202
-                $custom_post_types = LoaderFactory::getLoader()->getShared(
203
-                    'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
204
-                );
205
-                // get array of EE Custom Post Types
206
-                $EE_CPTs = $custom_post_types->getDefinitions();
207
-                // build template name based on request
208
-                if (isset($EE_CPTs[ $post_type ])) {
209
-                    $archive_or_single = is_archive() ? 'archive' : '';
210
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
211
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
212
-                }
213
-            }
214
-            // currently active EE template theme
215
-            $current_theme = EE_Config::get_current_theme();
216
-
217
-            // array of paths to folders that may contain templates
218
-            $template_folder_paths = array(
219
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
221
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
222
-                EVENT_ESPRESSO_TEMPLATE_DIR,
223
-            );
224
-
225
-            // add core plugin folders for checking only if we're not $check_if_custom
226
-            if (! $check_if_custom) {
227
-                $core_paths            = array(
228
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
-                    EE_PUBLIC . $current_theme,
230
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
-                    EE_TEMPLATES . $current_theme,
232
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233
-                    EE_PLUGIN_DIR_PATH,
234
-                );
235
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
236
-            }
237
-
238
-            // now filter that array
239
-            $template_folder_paths = apply_filters(
240
-                'FHEE__EEH_Template__locate_template__template_folder_paths',
241
-                $template_folder_paths
242
-            );
243
-            $templates             = is_array($templates) ? $templates : array($templates);
244
-            $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
245
-            // array to hold all possible template paths
246
-            $full_template_paths = array();
247
-
248
-            // loop through $templates
249
-            foreach ($templates as $template) {
250
-                // normalize directory separators
251
-                $template                      = EEH_File::standardise_directory_separators($template);
252
-                $file_name                     = basename($template);
253
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
254
-                // while looping through all template folder paths
255
-                foreach ($template_folder_paths as $template_folder_path) {
256
-                    // normalize directory separators
257
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
258
-                    // determine if any common base path exists between the two paths
259
-                    $common_base_path = EEH_Template::_find_common_base_path(
260
-                        array($template_folder_path, $template_path_minus_file_name)
261
-                    );
262
-                    if ($common_base_path !== '') {
263
-                        // both paths have a common base, so just tack the filename onto our search path
264
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
-                    } else {
266
-                        // no common base path, so let's just concatenate
267
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
-                    }
269
-                    // build up our template locations array by adding our resolved paths
270
-                    $full_template_paths[] = $resolved_path;
271
-                }
272
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273
-                array_unshift($full_template_paths, $template);
274
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
276
-            }
277
-            // filter final array of full template paths
278
-            $full_template_paths = apply_filters(
279
-                'FHEE__EEH_Template__locate_template__full_template_paths',
280
-                $full_template_paths,
281
-                $file_name
282
-            );
283
-            // now loop through our final array of template location paths and check each location
284
-            foreach ((array) $full_template_paths as $full_template_path) {
285
-                if (is_readable($full_template_path)) {
286
-                    $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
287
-                    break;
288
-                }
289
-            }
290
-        }
291
-
292
-        // hook that can be used to display the full template path that will be used
293
-        do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
294
-
295
-        // if we got it and you want to see it...
296
-        if ($template_path && $load && ! $check_if_custom) {
297
-            if ($return_string) {
298
-                return EEH_Template::display_template($template_path, $template_args, true);
299
-            } else {
300
-                EEH_Template::display_template($template_path, $template_args, false);
301
-            }
302
-        }
303
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
304
-    }
305
-
306
-
307
-    /**
308
-     * _find_common_base_path
309
-     * given two paths, this determines if there is a common base path between the two
310
-     *
311
-     * @param array $paths
312
-     * @return string
313
-     */
314
-    protected static function _find_common_base_path($paths)
315
-    {
316
-        $last_offset      = 0;
317
-        $common_base_path = '';
318
-        while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
319
-            $dir_length = $index - $last_offset + 1;
320
-            $directory  = substr($paths[0], $last_offset, $dir_length);
321
-            foreach ($paths as $path) {
322
-                if (substr($path, $last_offset, $dir_length) != $directory) {
323
-                    return $common_base_path;
324
-                }
325
-            }
326
-            $common_base_path .= $directory;
327
-            $last_offset = $index + 1;
328
-        }
329
-        return substr($common_base_path, 0, -1);
330
-    }
331
-
332
-
333
-    /**
334
-     * load and display a template
335
-     *
336
-     * @param bool|string $template_path server path to the file to be loaded, including file name and extension
337
-     * @param  array      $template_args an array of arguments to be extracted for use in the template
338
-     * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339
-     * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340
-     *                                      not found or is not readable
341
-     * @return mixed string
342
-     * @throws \DomainException
343
-     */
344
-    public static function display_template(
345
-        $template_path = false,
346
-        $template_args = array(),
347
-        $return_string = false,
348
-        $throw_exceptions = false
349
-    ) {
350
-
351
-        /**
352
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
353
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
354
-         * the display_template method are templates we DON'T want modified (usually because of js
355
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
356
-         * using this.
357
-         *
358
-         * @since 4.6.0
359
-         */
360
-        $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
361
-        $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362
-
363
-        // you gimme nuttin - YOU GET NUTTIN !!
364
-        if (! $template_path || ! is_readable($template_path)) {
365
-            return '';
366
-        }
367
-        // if $template_args are not in an array, then make it so
368
-        if (! is_array($template_args) && ! is_object($template_args)) {
369
-            $template_args = array($template_args);
370
-        }
371
-        extract($template_args, EXTR_SKIP);
372
-        // ignore whether template is accessible ?
373
-        if ($throw_exceptions && ! is_readable($template_path)) {
374
-            throw new \DomainException(
375
-                esc_html__(
376
-                    'Invalid, unreadable, or missing file.',
377
-                    'event_espresso'
378
-                )
379
-            );
380
-        }
381
-
382
-
383
-        if ($return_string) {
384
-            // because we want to return a string, we are going to capture the output
385
-            ob_start();
386
-            include($template_path);
387
-            return ob_get_clean();
388
-        } else {
389
-            include($template_path);
390
-        }
391
-        return '';
392
-    }
393
-
394
-
395
-    /**
396
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
397
-     *
398
-     * @param EE_Base_Class $object the EE object the css class is being generated for
399
-     * @param  string       $prefix added to the beginning of the generated class
400
-     * @param  string       $suffix added to the end of the generated class
401
-     * @return string
402
-     */
403
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404
-    {
405
-        // in the beginning...
406
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
407
-        // da muddle
408
-        $class = '';
409
-        // the end
410
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
411
-        // is the passed object an EE object ?
412
-        if ($object instanceof EE_Base_Class) {
413
-            // grab the exact type of object
414
-            $obj_class = get_class($object);
415
-            // depending on the type of object...
416
-            switch ($obj_class) {
417
-                // no specifics just yet...
418
-                default:
419
-                    $class = strtolower(str_replace('_', '-', $obj_class));
420
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
421
-            }
422
-        }
423
-        return $prefix . $class . $suffix;
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * EEH_Template::format_currency
430
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
431
-     * the country currency settings from the supplied country ISO code
432
-     *
433
-     * @param  float   $amount       raw money value
434
-     * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
435
-     * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
436
-     * @param string   $CNT_ISO      2 letter ISO code for a country
437
-     * @param string   $cur_code_span_class
438
-     * @return string        the html output for the formatted money value
439
-     * @throws \EE_Error
440
-     */
441
-    public static function format_currency(
442
-        $amount = null,
443
-        $return_raw = false,
444
-        $display_code = true,
445
-        $CNT_ISO = '',
446
-        $cur_code_span_class = 'currency-code'
447
-    ) {
448
-        // ensure amount was received
449
-        if ($amount === null) {
450
-            $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
451
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
452
-            return '';
453
-        }
454
-        // ensure amount is float
455
-        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
456
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
457
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
458
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
459
-        // still a number or was amount converted to a string like "free" ?
460
-        if (is_float($amount_formatted)) {
461
-            // was a country ISO code passed ? if so generate currency config object for that country
462
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
463
-            // verify results
464
-            if (! $mny instanceof EE_Currency_Config) {
465
-                // set default config country currency settings
466
-                $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
467
-                    ? EE_Registry::instance()->CFG->currency
468
-                    : new EE_Currency_Config();
469
-            }
470
-            // format float
471
-            $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
472
-            // add formatting ?
473
-            if (! $return_raw) {
474
-                // add currency sign
475
-                if ($mny->sign_b4) {
476
-                    if ($amount >= 0) {
477
-                        $amount_formatted = $mny->sign . $amount_formatted;
478
-                    } else {
479
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
480
-                    }
481
-                } else {
482
-                    $amount_formatted = $amount_formatted . $mny->sign;
483
-                }
484
-
485
-                // filter to allow global setting of display_code
486
-                $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487
-
488
-                // add currency code ?
489
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
490
-            }
491
-            // filter results
492
-            $amount_formatted = apply_filters(
493
-                'FHEE__EEH_Template__format_currency__amount_formatted',
494
-                $amount_formatted,
495
-                $mny,
496
-                $return_raw
497
-            );
498
-        }
499
-        // clean up vars
500
-        unset($mny);
501
-        // return formatted currency amount
502
-        return $amount_formatted;
503
-    }
504
-
505
-
506
-    /**
507
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
508
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
509
-     * related status model or model object (i.e. in documentation etc.)
510
-     *
511
-     * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
512
-     *                            match, then 'Unknown' will be returned.
513
-     * @param  boolean $plural    Whether to return plural or not
514
-     * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
515
-     * @return string             The localized label for the status id.
516
-     */
517
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
518
-    {
519
-        /** @type EEM_Status $EEM_Status */
520
-        $EEM_Status = EE_Registry::instance()->load_model('Status');
521
-        $status     = $EEM_Status->localized_status(
522
-            array($status_id => __('unknown', 'event_espresso')),
523
-            $plural,
524
-            $schema
525
-        );
526
-        return $status[ $status_id ];
527
-    }
528
-
529
-
530
-    /**
531
-     * This helper just returns a button or link for the given parameters
532
-     *
533
-     * @param  string $url   the url for the link, note that `esc_url` will be called on it
534
-     * @param  string $label What is the label you want displayed for the button
535
-     * @param  string $class what class is used for the button (defaults to 'button-primary')
536
-     * @param string  $icon
537
-     * @param string  $title
538
-     * @return string the html output for the button
539
-     */
540
-    public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
541
-    {
542
-        $icon_html = '';
543
-        if (! empty($icon)) {
544
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
545
-            $dashicons = array_filter($dashicons);
546
-            $count     = count($dashicons);
547
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
548
-            foreach ($dashicons as $dashicon) {
549
-                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
550
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
551
-            }
552
-            $icon_html .= $count > 1 ? '</span>' : '';
553
-        }
554
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
555
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
556
-        return $button;
557
-    }
558
-
559
-
560
-    /**
561
-     * This returns a generated link that will load the related help tab on admin pages.
562
-     *
563
-     * @param  string     $help_tab_id the id for the connected help tab
564
-     * @param bool|string $page        The page identifier for the page the help tab is on
565
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
566
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
567
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
568
-     * @return string              generated link
569
-     */
570
-    public static function get_help_tab_link(
571
-        $help_tab_id,
572
-        $page = false,
573
-        $action = false,
574
-        $icon_style = false,
575
-        $help_text = false
576
-    ) {
577
-
578
-        if (! $page) {
579
-            $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
580
-        }
581
-
582
-        if (! $action) {
583
-            $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
584
-        }
585
-
586
-        $action = empty($action) ? 'default' : $action;
587
-
588
-
589
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
590
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
591
-        $help_text    = ! $help_text ? '' : $help_text;
592
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
593
-            'Click to open the \'Help\' tab for more information about this feature.',
594
-            'event_espresso'
595
-        ) . '" > ' . $help_text . ' </a>';
596
-    }
597
-
598
-
599
-    /**
600
-     * This helper generates the html structure for the jquery joyride plugin with the given params.
601
-     *
602
-     * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
603
-     * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
604
-     * @param EE_Help_Tour
605
-     * @return string         html
606
-     */
607
-    public static function help_tour_stops_generator(EE_Help_Tour $tour)
608
-    {
609
-        $id    = $tour->get_slug();
610
-        $stops = $tour->get_stops();
611
-
612
-        $content = '<ol style="display:none" id="' . $id . '">';
613
-
614
-        foreach ($stops as $stop) {
615
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
616
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
617
-
618
-            // if container is set to modal then let's make sure we set the options accordingly
619
-            if (empty($data_id) && empty($data_class)) {
620
-                $stop['options']['modal']  = true;
621
-                $stop['options']['expose'] = true;
622
-            }
623
-
624
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
625
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
626
-            $inner_content = isset($stop['content']) ? $stop['content'] : '';
627
-
628
-            // options
629
-            if (isset($stop['options']) && is_array($stop['options'])) {
630
-                $options = ' data-options="';
631
-                foreach ($stop['options'] as $option => $value) {
632
-                    $options .= $option . ':' . $value . ';';
633
-                }
634
-                $options .= '"';
635
-            } else {
636
-                $options = '';
637
-            }
638
-
639
-            // let's put all together
640
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
641
-        }
642
-
643
-        $content .= '</ol>';
644
-        return $content;
645
-    }
646
-
647
-
648
-    /**
649
-     * This is a helper method to generate a status legend for a given status array.
650
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
651
-     * status_array.
652
-     *
653
-     * @param  array  $status_array  array of statuses that will make up the legend. In format:
654
-     *                               array(
655
-     *                               'status_item' => 'status_name'
656
-     *                               )
657
-     * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
658
-     *                               the legend.
659
-     * @throws EE_Error
660
-     * @return string               html structure for status.
661
-     */
662
-    public static function status_legend($status_array, $active_status = '')
663
-    {
664
-        if (! is_array($status_array)) {
665
-            throw new EE_Error(esc_html__(
666
-                'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
667
-                'event_espresso'
668
-            ));
669
-        }
670
-
671
-        $setup_array = array();
672
-        foreach ($status_array as $item => $status) {
673
-            $setup_array[ $item ] = array(
674
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
675
-                'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
676
-                'status' => $status,
677
-            );
678
-        }
679
-
680
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
681
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
682
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
683
-        foreach ($setup_array as $item => $details) {
684
-            $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
685
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
686
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
687
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
688
-            $content .= '</dt>' . "\n";
689
-        }
690
-        $content .= '</dl>' . "\n";
691
-        $content .= '</div>' . "\n";
692
-        return $content;
693
-    }
694
-
695
-
696
-    /**
697
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
698
-     * that's nice for presenting in the wp admin
699
-     *
700
-     * @param mixed $data
701
-     * @return string
702
-     */
703
-    public static function layout_array_as_table($data)
704
-    {
705
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
706
-            $data = (array) $data;
707
-        }
708
-        ob_start();
709
-        if (is_array($data)) {
710
-            if (EEH_Array::is_associative_array($data)) {
711
-                ?>
51
+	private static $_espresso_themes = array();
52
+
53
+
54
+	/**
55
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
56
+	 *
57
+	 * @return boolean
58
+	 */
59
+	public static function is_espresso_theme()
60
+	{
61
+		return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
62
+	}
63
+
64
+	/**
65
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
66
+	 *    load it's functions.php file ( if not already loaded )
67
+	 *
68
+	 * @return void
69
+	 */
70
+	public static function load_espresso_theme_functions()
71
+	{
72
+		if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
74
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
75
+			}
76
+		}
77
+	}
78
+
79
+
80
+	/**
81
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
82
+	 *
83
+	 * @return array
84
+	 */
85
+	public static function get_espresso_themes()
86
+	{
87
+		if (empty(EEH_Template::$_espresso_themes)) {
88
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
89
+			if (empty($espresso_themes)) {
90
+				return array();
91
+			}
92
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
+				unset($espresso_themes[ $key ]);
94
+			}
95
+			EEH_Template::$_espresso_themes = array();
96
+			foreach ($espresso_themes as $espresso_theme) {
97
+				EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
98
+			}
99
+		}
100
+		return EEH_Template::$_espresso_themes;
101
+	}
102
+
103
+
104
+	/**
105
+	 * EEH_Template::get_template_part
106
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
107
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
108
+	 * filtering based off of the entire template part name
109
+	 *
110
+	 * @param string $slug The slug name for the generic template.
111
+	 * @param string $name The name of the specialised template.
112
+	 * @param array  $template_args
113
+	 * @param bool   $return_string
114
+	 * @return string        the html output for the formatted money value
115
+	 */
116
+	public static function get_template_part(
117
+		$slug = null,
118
+		$name = null,
119
+		$template_args = array(),
120
+		$return_string = false
121
+	) {
122
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
123
+		$templates = array();
124
+		$name      = (string) $name;
125
+		if ($name != '') {
126
+			$templates[] = "{$slug}-{$name}.php";
127
+		}
128
+		// allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
129
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
130
+			EEH_Template::locate_template($templates, $template_args, true, $return_string);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 *    locate_template
137
+	 *    locate a template file by looking in the following places, in the following order:
138
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
139
+	 *        <assumed full absolute server path>
140
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
141
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
142
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
143
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
144
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
145
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
146
+	 *        Example:
147
+	 *          You are using the WordPress Twenty Sixteen theme,
148
+	 *        and you want to customize the "some-event.template.php" template,
149
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
150
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
151
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
152
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
153
+	 *        /relative/path/to/some-event.template.php
154
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
155
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
156
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
157
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
158
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
159
+	 *          Had you passed an absolute path to your template that was in some other location,
160
+	 *        ie: "/absolute/path/to/some-event.template.php"
161
+	 *          then the search would have been :
162
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
163
+	 *        /absolute/path/to/some-event.template.php
164
+	 *          and stopped there upon finding it in the second location
165
+	 *
166
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
167
+	 * @param  array       $template_args   an array of arguments to be extracted for use in the template
168
+	 * @param  boolean     $load            whether to pass the located template path on to the
169
+	 *                                      EEH_Template::display_template() method or simply return it
170
+	 * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
171
+	 *                                      string
172
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
173
+	 *                                      generate a custom template or not. Used in places where you don't actually
174
+	 *                                      load the template, you just want to know if there's a custom version of it.
175
+	 * @return mixed
176
+	 * @throws DomainException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws InvalidDataTypeException
179
+	 * @throws InvalidInterfaceException
180
+	 */
181
+	public static function locate_template(
182
+		$templates = array(),
183
+		$template_args = array(),
184
+		$load = true,
185
+		$return_string = true,
186
+		$check_if_custom = false
187
+	) {
188
+		// first use WP locate_template to check for template in the current theme folder
189
+		$template_path = locate_template($templates);
190
+
191
+		if ($check_if_custom && ! empty($template_path)) {
192
+			return true;
193
+		}
194
+
195
+		// not in the theme
196
+		if (empty($template_path)) {
197
+			// not even a template to look for ?
198
+			if (empty($templates)) {
199
+				// get post_type
200
+				$post_type = EE_Registry::instance()->REQ->get('post_type');
201
+				/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
202
+				$custom_post_types = LoaderFactory::getLoader()->getShared(
203
+					'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
204
+				);
205
+				// get array of EE Custom Post Types
206
+				$EE_CPTs = $custom_post_types->getDefinitions();
207
+				// build template name based on request
208
+				if (isset($EE_CPTs[ $post_type ])) {
209
+					$archive_or_single = is_archive() ? 'archive' : '';
210
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
211
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
212
+				}
213
+			}
214
+			// currently active EE template theme
215
+			$current_theme = EE_Config::get_current_theme();
216
+
217
+			// array of paths to folders that may contain templates
218
+			$template_folder_paths = array(
219
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
221
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
222
+				EVENT_ESPRESSO_TEMPLATE_DIR,
223
+			);
224
+
225
+			// add core plugin folders for checking only if we're not $check_if_custom
226
+			if (! $check_if_custom) {
227
+				$core_paths            = array(
228
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
+					EE_PUBLIC . $current_theme,
230
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
+					EE_TEMPLATES . $current_theme,
232
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233
+					EE_PLUGIN_DIR_PATH,
234
+				);
235
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
236
+			}
237
+
238
+			// now filter that array
239
+			$template_folder_paths = apply_filters(
240
+				'FHEE__EEH_Template__locate_template__template_folder_paths',
241
+				$template_folder_paths
242
+			);
243
+			$templates             = is_array($templates) ? $templates : array($templates);
244
+			$template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
245
+			// array to hold all possible template paths
246
+			$full_template_paths = array();
247
+
248
+			// loop through $templates
249
+			foreach ($templates as $template) {
250
+				// normalize directory separators
251
+				$template                      = EEH_File::standardise_directory_separators($template);
252
+				$file_name                     = basename($template);
253
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
254
+				// while looping through all template folder paths
255
+				foreach ($template_folder_paths as $template_folder_path) {
256
+					// normalize directory separators
257
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
258
+					// determine if any common base path exists between the two paths
259
+					$common_base_path = EEH_Template::_find_common_base_path(
260
+						array($template_folder_path, $template_path_minus_file_name)
261
+					);
262
+					if ($common_base_path !== '') {
263
+						// both paths have a common base, so just tack the filename onto our search path
264
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
+					} else {
266
+						// no common base path, so let's just concatenate
267
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
+					}
269
+					// build up our template locations array by adding our resolved paths
270
+					$full_template_paths[] = $resolved_path;
271
+				}
272
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273
+				array_unshift($full_template_paths, $template);
274
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
+				array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
276
+			}
277
+			// filter final array of full template paths
278
+			$full_template_paths = apply_filters(
279
+				'FHEE__EEH_Template__locate_template__full_template_paths',
280
+				$full_template_paths,
281
+				$file_name
282
+			);
283
+			// now loop through our final array of template location paths and check each location
284
+			foreach ((array) $full_template_paths as $full_template_path) {
285
+				if (is_readable($full_template_path)) {
286
+					$template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
287
+					break;
288
+				}
289
+			}
290
+		}
291
+
292
+		// hook that can be used to display the full template path that will be used
293
+		do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
294
+
295
+		// if we got it and you want to see it...
296
+		if ($template_path && $load && ! $check_if_custom) {
297
+			if ($return_string) {
298
+				return EEH_Template::display_template($template_path, $template_args, true);
299
+			} else {
300
+				EEH_Template::display_template($template_path, $template_args, false);
301
+			}
302
+		}
303
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
304
+	}
305
+
306
+
307
+	/**
308
+	 * _find_common_base_path
309
+	 * given two paths, this determines if there is a common base path between the two
310
+	 *
311
+	 * @param array $paths
312
+	 * @return string
313
+	 */
314
+	protected static function _find_common_base_path($paths)
315
+	{
316
+		$last_offset      = 0;
317
+		$common_base_path = '';
318
+		while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
319
+			$dir_length = $index - $last_offset + 1;
320
+			$directory  = substr($paths[0], $last_offset, $dir_length);
321
+			foreach ($paths as $path) {
322
+				if (substr($path, $last_offset, $dir_length) != $directory) {
323
+					return $common_base_path;
324
+				}
325
+			}
326
+			$common_base_path .= $directory;
327
+			$last_offset = $index + 1;
328
+		}
329
+		return substr($common_base_path, 0, -1);
330
+	}
331
+
332
+
333
+	/**
334
+	 * load and display a template
335
+	 *
336
+	 * @param bool|string $template_path server path to the file to be loaded, including file name and extension
337
+	 * @param  array      $template_args an array of arguments to be extracted for use in the template
338
+	 * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339
+	 * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340
+	 *                                      not found or is not readable
341
+	 * @return mixed string
342
+	 * @throws \DomainException
343
+	 */
344
+	public static function display_template(
345
+		$template_path = false,
346
+		$template_args = array(),
347
+		$return_string = false,
348
+		$throw_exceptions = false
349
+	) {
350
+
351
+		/**
352
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
353
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
354
+		 * the display_template method are templates we DON'T want modified (usually because of js
355
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
356
+		 * using this.
357
+		 *
358
+		 * @since 4.6.0
359
+		 */
360
+		$template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
361
+		$template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362
+
363
+		// you gimme nuttin - YOU GET NUTTIN !!
364
+		if (! $template_path || ! is_readable($template_path)) {
365
+			return '';
366
+		}
367
+		// if $template_args are not in an array, then make it so
368
+		if (! is_array($template_args) && ! is_object($template_args)) {
369
+			$template_args = array($template_args);
370
+		}
371
+		extract($template_args, EXTR_SKIP);
372
+		// ignore whether template is accessible ?
373
+		if ($throw_exceptions && ! is_readable($template_path)) {
374
+			throw new \DomainException(
375
+				esc_html__(
376
+					'Invalid, unreadable, or missing file.',
377
+					'event_espresso'
378
+				)
379
+			);
380
+		}
381
+
382
+
383
+		if ($return_string) {
384
+			// because we want to return a string, we are going to capture the output
385
+			ob_start();
386
+			include($template_path);
387
+			return ob_get_clean();
388
+		} else {
389
+			include($template_path);
390
+		}
391
+		return '';
392
+	}
393
+
394
+
395
+	/**
396
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
397
+	 *
398
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
399
+	 * @param  string       $prefix added to the beginning of the generated class
400
+	 * @param  string       $suffix added to the end of the generated class
401
+	 * @return string
402
+	 */
403
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404
+	{
405
+		// in the beginning...
406
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
407
+		// da muddle
408
+		$class = '';
409
+		// the end
410
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
411
+		// is the passed object an EE object ?
412
+		if ($object instanceof EE_Base_Class) {
413
+			// grab the exact type of object
414
+			$obj_class = get_class($object);
415
+			// depending on the type of object...
416
+			switch ($obj_class) {
417
+				// no specifics just yet...
418
+				default:
419
+					$class = strtolower(str_replace('_', '-', $obj_class));
420
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
421
+			}
422
+		}
423
+		return $prefix . $class . $suffix;
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * EEH_Template::format_currency
430
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
431
+	 * the country currency settings from the supplied country ISO code
432
+	 *
433
+	 * @param  float   $amount       raw money value
434
+	 * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
435
+	 * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
436
+	 * @param string   $CNT_ISO      2 letter ISO code for a country
437
+	 * @param string   $cur_code_span_class
438
+	 * @return string        the html output for the formatted money value
439
+	 * @throws \EE_Error
440
+	 */
441
+	public static function format_currency(
442
+		$amount = null,
443
+		$return_raw = false,
444
+		$display_code = true,
445
+		$CNT_ISO = '',
446
+		$cur_code_span_class = 'currency-code'
447
+	) {
448
+		// ensure amount was received
449
+		if ($amount === null) {
450
+			$msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
451
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
452
+			return '';
453
+		}
454
+		// ensure amount is float
455
+		$amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
456
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
457
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
458
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
459
+		// still a number or was amount converted to a string like "free" ?
460
+		if (is_float($amount_formatted)) {
461
+			// was a country ISO code passed ? if so generate currency config object for that country
462
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
463
+			// verify results
464
+			if (! $mny instanceof EE_Currency_Config) {
465
+				// set default config country currency settings
466
+				$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
467
+					? EE_Registry::instance()->CFG->currency
468
+					: new EE_Currency_Config();
469
+			}
470
+			// format float
471
+			$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
472
+			// add formatting ?
473
+			if (! $return_raw) {
474
+				// add currency sign
475
+				if ($mny->sign_b4) {
476
+					if ($amount >= 0) {
477
+						$amount_formatted = $mny->sign . $amount_formatted;
478
+					} else {
479
+						$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
480
+					}
481
+				} else {
482
+					$amount_formatted = $amount_formatted . $mny->sign;
483
+				}
484
+
485
+				// filter to allow global setting of display_code
486
+				$display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487
+
488
+				// add currency code ?
489
+				$amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
490
+			}
491
+			// filter results
492
+			$amount_formatted = apply_filters(
493
+				'FHEE__EEH_Template__format_currency__amount_formatted',
494
+				$amount_formatted,
495
+				$mny,
496
+				$return_raw
497
+			);
498
+		}
499
+		// clean up vars
500
+		unset($mny);
501
+		// return formatted currency amount
502
+		return $amount_formatted;
503
+	}
504
+
505
+
506
+	/**
507
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
508
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
509
+	 * related status model or model object (i.e. in documentation etc.)
510
+	 *
511
+	 * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
512
+	 *                            match, then 'Unknown' will be returned.
513
+	 * @param  boolean $plural    Whether to return plural or not
514
+	 * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
515
+	 * @return string             The localized label for the status id.
516
+	 */
517
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
518
+	{
519
+		/** @type EEM_Status $EEM_Status */
520
+		$EEM_Status = EE_Registry::instance()->load_model('Status');
521
+		$status     = $EEM_Status->localized_status(
522
+			array($status_id => __('unknown', 'event_espresso')),
523
+			$plural,
524
+			$schema
525
+		);
526
+		return $status[ $status_id ];
527
+	}
528
+
529
+
530
+	/**
531
+	 * This helper just returns a button or link for the given parameters
532
+	 *
533
+	 * @param  string $url   the url for the link, note that `esc_url` will be called on it
534
+	 * @param  string $label What is the label you want displayed for the button
535
+	 * @param  string $class what class is used for the button (defaults to 'button-primary')
536
+	 * @param string  $icon
537
+	 * @param string  $title
538
+	 * @return string the html output for the button
539
+	 */
540
+	public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
541
+	{
542
+		$icon_html = '';
543
+		if (! empty($icon)) {
544
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
545
+			$dashicons = array_filter($dashicons);
546
+			$count     = count($dashicons);
547
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
548
+			foreach ($dashicons as $dashicon) {
549
+				$type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
550
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
551
+			}
552
+			$icon_html .= $count > 1 ? '</span>' : '';
553
+		}
554
+		$label  = ! empty($icon) ? $icon_html . $label : $label;
555
+		$button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
556
+		return $button;
557
+	}
558
+
559
+
560
+	/**
561
+	 * This returns a generated link that will load the related help tab on admin pages.
562
+	 *
563
+	 * @param  string     $help_tab_id the id for the connected help tab
564
+	 * @param bool|string $page        The page identifier for the page the help tab is on
565
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
566
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
567
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
568
+	 * @return string              generated link
569
+	 */
570
+	public static function get_help_tab_link(
571
+		$help_tab_id,
572
+		$page = false,
573
+		$action = false,
574
+		$icon_style = false,
575
+		$help_text = false
576
+	) {
577
+
578
+		if (! $page) {
579
+			$page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
580
+		}
581
+
582
+		if (! $action) {
583
+			$action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
584
+		}
585
+
586
+		$action = empty($action) ? 'default' : $action;
587
+
588
+
589
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
590
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
591
+		$help_text    = ! $help_text ? '' : $help_text;
592
+		return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
593
+			'Click to open the \'Help\' tab for more information about this feature.',
594
+			'event_espresso'
595
+		) . '" > ' . $help_text . ' </a>';
596
+	}
597
+
598
+
599
+	/**
600
+	 * This helper generates the html structure for the jquery joyride plugin with the given params.
601
+	 *
602
+	 * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
603
+	 * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
604
+	 * @param EE_Help_Tour
605
+	 * @return string         html
606
+	 */
607
+	public static function help_tour_stops_generator(EE_Help_Tour $tour)
608
+	{
609
+		$id    = $tour->get_slug();
610
+		$stops = $tour->get_stops();
611
+
612
+		$content = '<ol style="display:none" id="' . $id . '">';
613
+
614
+		foreach ($stops as $stop) {
615
+			$data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
616
+			$data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
617
+
618
+			// if container is set to modal then let's make sure we set the options accordingly
619
+			if (empty($data_id) && empty($data_class)) {
620
+				$stop['options']['modal']  = true;
621
+				$stop['options']['expose'] = true;
622
+			}
623
+
624
+			$custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
625
+			$button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
626
+			$inner_content = isset($stop['content']) ? $stop['content'] : '';
627
+
628
+			// options
629
+			if (isset($stop['options']) && is_array($stop['options'])) {
630
+				$options = ' data-options="';
631
+				foreach ($stop['options'] as $option => $value) {
632
+					$options .= $option . ':' . $value . ';';
633
+				}
634
+				$options .= '"';
635
+			} else {
636
+				$options = '';
637
+			}
638
+
639
+			// let's put all together
640
+			$content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
641
+		}
642
+
643
+		$content .= '</ol>';
644
+		return $content;
645
+	}
646
+
647
+
648
+	/**
649
+	 * This is a helper method to generate a status legend for a given status array.
650
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
651
+	 * status_array.
652
+	 *
653
+	 * @param  array  $status_array  array of statuses that will make up the legend. In format:
654
+	 *                               array(
655
+	 *                               'status_item' => 'status_name'
656
+	 *                               )
657
+	 * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
658
+	 *                               the legend.
659
+	 * @throws EE_Error
660
+	 * @return string               html structure for status.
661
+	 */
662
+	public static function status_legend($status_array, $active_status = '')
663
+	{
664
+		if (! is_array($status_array)) {
665
+			throw new EE_Error(esc_html__(
666
+				'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
667
+				'event_espresso'
668
+			));
669
+		}
670
+
671
+		$setup_array = array();
672
+		foreach ($status_array as $item => $status) {
673
+			$setup_array[ $item ] = array(
674
+				'class'  => 'ee-status-legend ee-status-legend-' . $status,
675
+				'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
676
+				'status' => $status,
677
+			);
678
+		}
679
+
680
+		$content = '<div class="ee-list-table-legend-container">' . "\n";
681
+		$content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
682
+		$content .= '<dl class="ee-list-table-legend">' . "\n\t";
683
+		foreach ($setup_array as $item => $details) {
684
+			$active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
685
+			$content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
686
+			$content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
687
+			$content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
688
+			$content .= '</dt>' . "\n";
689
+		}
690
+		$content .= '</dl>' . "\n";
691
+		$content .= '</div>' . "\n";
692
+		return $content;
693
+	}
694
+
695
+
696
+	/**
697
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
698
+	 * that's nice for presenting in the wp admin
699
+	 *
700
+	 * @param mixed $data
701
+	 * @return string
702
+	 */
703
+	public static function layout_array_as_table($data)
704
+	{
705
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
706
+			$data = (array) $data;
707
+		}
708
+		ob_start();
709
+		if (is_array($data)) {
710
+			if (EEH_Array::is_associative_array($data)) {
711
+				?>
712 712
                 <table class="widefat">
713 713
                     <tbody>
714 714
                     <?php
715
-                    foreach ($data as $data_key => $data_values) {
716
-                        ?>
715
+					foreach ($data as $data_key => $data_values) {
716
+						?>
717 717
                         <tr>
718 718
                             <td>
719 719
                                 <?php echo $data_key; ?>
@@ -723,291 +723,291 @@  discard block
 block discarded – undo
723 723
                             </td>
724 724
                         </tr>
725 725
                         <?php
726
-                    } ?>
726
+					} ?>
727 727
                     </tbody>
728 728
                 </table>
729 729
                 <?php
730
-            } else {
731
-                ?>
730
+			} else {
731
+				?>
732 732
                 <ul>
733 733
                     <?php
734
-                    foreach ($data as $datum) {
735
-                        echo "<li>";
736
-                        echo self::layout_array_as_table($datum);
737
-                        echo "</li>";
738
-                    } ?>
734
+					foreach ($data as $datum) {
735
+						echo "<li>";
736
+						echo self::layout_array_as_table($datum);
737
+						echo "</li>";
738
+					} ?>
739 739
                 </ul>
740 740
                 <?php
741
-            }
742
-        } else {
743
-            // simple value
744
-            echo esc_html($data);
745
-        }
746
-        return ob_get_clean();
747
-    }
748
-
749
-
750
-    /**
751
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
752
-     *
753
-     * @since 4.4.0
754
-     * @see   self:get_paging_html() for argument docs.
755
-     * @param        $total_items
756
-     * @param        $current
757
-     * @param        $per_page
758
-     * @param        $url
759
-     * @param bool   $show_num_field
760
-     * @param string $paged_arg_name
761
-     * @param array  $items_label
762
-     * @return string
763
-     */
764
-    public static function paging_html(
765
-        $total_items,
766
-        $current,
767
-        $per_page,
768
-        $url,
769
-        $show_num_field = true,
770
-        $paged_arg_name = 'paged',
771
-        $items_label = array()
772
-    ) {
773
-        echo self::get_paging_html(
774
-            $total_items,
775
-            $current,
776
-            $per_page,
777
-            $url,
778
-            $show_num_field,
779
-            $paged_arg_name,
780
-            $items_label
781
-        );
782
-    }
783
-
784
-
785
-    /**
786
-     * A method for generating paging similar to WP_List_Table
787
-     *
788
-     * @since    4.4.0
789
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
790
-     * @param  integer $total_items     How many total items there are to page.
791
-     * @param  integer $current         What the current page is.
792
-     * @param  integer $per_page        How many items per page.
793
-     * @param  string  $url             What the base url for page links is.
794
-     * @param  boolean $show_num_field  Whether to show the input for changing page number.
795
-     * @param  string  $paged_arg_name  The name of the key for the paged query argument.
796
-     * @param  array   $items_label     An array of singular/plural values for the items label:
797
-     *                                  array(
798
-     *                                  'single' => 'item',
799
-     *                                  'plural' => 'items'
800
-     *                                  )
801
-     * @return  string
802
-     */
803
-    public static function get_paging_html(
804
-        $total_items,
805
-        $current,
806
-        $per_page,
807
-        $url,
808
-        $show_num_field = true,
809
-        $paged_arg_name = 'paged',
810
-        $items_label = array()
811
-    ) {
812
-        $page_links     = array();
813
-        $disable_first  = $disable_last = '';
814
-        $total_items    = (int) $total_items;
815
-        $per_page       = (int) $per_page;
816
-        $current        = (int) $current;
817
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
818
-
819
-        // filter items_label
820
-        $items_label = apply_filters(
821
-            'FHEE__EEH_Template__get_paging_html__items_label',
822
-            $items_label
823
-        );
824
-
825
-        if (empty($items_label)
826
-            || ! is_array($items_label)
827
-            || ! isset($items_label['single'])
828
-            || ! isset($items_label['plural'])
829
-        ) {
830
-            $items_label = array(
831
-                'single' => __('1 item', 'event_espresso'),
832
-                'plural' => __('%s items', 'event_espresso'),
833
-            );
834
-        } else {
835
-            $items_label = array(
836
-                'single' => '1 ' . esc_html($items_label['single']),
837
-                'plural' => '%s ' . esc_html($items_label['plural']),
838
-            );
839
-        }
840
-
841
-        $total_pages = ceil($total_items / $per_page);
842
-
843
-        if ($total_pages <= 1) {
844
-            return '';
845
-        }
846
-
847
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
848
-
849
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
850
-
851
-        if ($current === 1) {
852
-            $disable_first = ' disabled';
853
-        }
854
-        if ($current == $total_pages) {
855
-            $disable_last = ' disabled';
856
-        }
857
-
858
-        $page_links[] = sprintf(
859
-            "<a class='%s' title='%s' href='%s'>%s</a>",
860
-            'first-page' . $disable_first,
861
-            esc_attr__('Go to the first page', 'event_espresso'),
862
-            esc_url(remove_query_arg($paged_arg_name, $url)),
863
-            '&laquo;'
864
-        );
865
-
866
-        $page_links[] = sprintf(
867
-            '<a class="%s" title="%s" href="%s">%s</a>',
868
-            'prev-page' . $disable_first,
869
-            esc_attr__('Go to the previous page', 'event_espresso'),
870
-            esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
871
-            '&lsaquo;'
872
-        );
873
-
874
-        if (! $show_num_field) {
875
-            $html_current_page = $current;
876
-        } else {
877
-            $html_current_page = sprintf(
878
-                "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
879
-                esc_attr__('Current page', 'event_espresso'),
880
-                $current,
881
-                strlen($total_pages)
882
-            );
883
-        }
884
-
885
-        $html_total_pages = sprintf(
886
-            '<span class="total-pages">%s</span>',
887
-            number_format_i18n($total_pages)
888
-        );
889
-        $page_links[]     = sprintf(
890
-            _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
891
-            $html_current_page,
892
-            $html_total_pages,
893
-            '<span class="paging-input">',
894
-            '</span>'
895
-        );
896
-
897
-        $page_links[] = sprintf(
898
-            '<a class="%s" title="%s" href="%s">%s</a>',
899
-            'next-page' . $disable_last,
900
-            esc_attr__('Go to the next page', 'event_espresso'),
901
-            esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
902
-            '&rsaquo;'
903
-        );
904
-
905
-        $page_links[] = sprintf(
906
-            '<a class="%s" title="%s" href="%s">%s</a>',
907
-            'last-page' . $disable_last,
908
-            esc_attr__('Go to the last page', 'event_espresso'),
909
-            esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
910
-            '&raquo;'
911
-        );
912
-
913
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
914
-        // set page class
915
-        if ($total_pages) {
916
-            $page_class = $total_pages < 2 ? ' one-page' : '';
917
-        } else {
918
-            $page_class = ' no-pages';
919
-        }
920
-
921
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
922
-    }
923
-
924
-
925
-    /**
926
-     * @param string $wrap_class
927
-     * @param string $wrap_id
928
-     * @return string
929
-     */
930
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
931
-    {
932
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
933
-        if (! $admin &&
934
-            ! apply_filters(
935
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
936
-                EE_Registry::instance()->CFG->admin->show_reg_footer
937
-            )
938
-        ) {
939
-            return '';
940
-        }
941
-        $tag        = $admin ? 'span' : 'div';
942
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
943
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
944
-        $attributes .= ! empty($wrap_class)
945
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
946
-            : ' class="powered-by-event-espresso-credit"';
947
-        $query_args = array_merge(
948
-            array(
949
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
950
-                'utm_source'   => 'powered_by_event_espresso',
951
-                'utm_medium'   => 'link',
952
-                'utm_campaign' => 'powered_by',
953
-            ),
954
-            $query_args
955
-        );
956
-        $powered_by = apply_filters(
957
-            'FHEE__EEH_Template__powered_by_event_espresso_text',
958
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
959
-        );
960
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
961
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
962
-        return (string) apply_filters(
963
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
964
-            sprintf(
965
-                esc_html_x(
966
-                    '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
967
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
968
-                    'event_espresso'
969
-                ),
970
-                "<{$tag}{$attributes}>",
971
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
972
-                $admin ? '' : '<br />'
973
-            ),
974
-            $wrap_class,
975
-            $wrap_id
976
-        );
977
-    }
741
+			}
742
+		} else {
743
+			// simple value
744
+			echo esc_html($data);
745
+		}
746
+		return ob_get_clean();
747
+	}
748
+
749
+
750
+	/**
751
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
752
+	 *
753
+	 * @since 4.4.0
754
+	 * @see   self:get_paging_html() for argument docs.
755
+	 * @param        $total_items
756
+	 * @param        $current
757
+	 * @param        $per_page
758
+	 * @param        $url
759
+	 * @param bool   $show_num_field
760
+	 * @param string $paged_arg_name
761
+	 * @param array  $items_label
762
+	 * @return string
763
+	 */
764
+	public static function paging_html(
765
+		$total_items,
766
+		$current,
767
+		$per_page,
768
+		$url,
769
+		$show_num_field = true,
770
+		$paged_arg_name = 'paged',
771
+		$items_label = array()
772
+	) {
773
+		echo self::get_paging_html(
774
+			$total_items,
775
+			$current,
776
+			$per_page,
777
+			$url,
778
+			$show_num_field,
779
+			$paged_arg_name,
780
+			$items_label
781
+		);
782
+	}
783
+
784
+
785
+	/**
786
+	 * A method for generating paging similar to WP_List_Table
787
+	 *
788
+	 * @since    4.4.0
789
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
790
+	 * @param  integer $total_items     How many total items there are to page.
791
+	 * @param  integer $current         What the current page is.
792
+	 * @param  integer $per_page        How many items per page.
793
+	 * @param  string  $url             What the base url for page links is.
794
+	 * @param  boolean $show_num_field  Whether to show the input for changing page number.
795
+	 * @param  string  $paged_arg_name  The name of the key for the paged query argument.
796
+	 * @param  array   $items_label     An array of singular/plural values for the items label:
797
+	 *                                  array(
798
+	 *                                  'single' => 'item',
799
+	 *                                  'plural' => 'items'
800
+	 *                                  )
801
+	 * @return  string
802
+	 */
803
+	public static function get_paging_html(
804
+		$total_items,
805
+		$current,
806
+		$per_page,
807
+		$url,
808
+		$show_num_field = true,
809
+		$paged_arg_name = 'paged',
810
+		$items_label = array()
811
+	) {
812
+		$page_links     = array();
813
+		$disable_first  = $disable_last = '';
814
+		$total_items    = (int) $total_items;
815
+		$per_page       = (int) $per_page;
816
+		$current        = (int) $current;
817
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
818
+
819
+		// filter items_label
820
+		$items_label = apply_filters(
821
+			'FHEE__EEH_Template__get_paging_html__items_label',
822
+			$items_label
823
+		);
824
+
825
+		if (empty($items_label)
826
+			|| ! is_array($items_label)
827
+			|| ! isset($items_label['single'])
828
+			|| ! isset($items_label['plural'])
829
+		) {
830
+			$items_label = array(
831
+				'single' => __('1 item', 'event_espresso'),
832
+				'plural' => __('%s items', 'event_espresso'),
833
+			);
834
+		} else {
835
+			$items_label = array(
836
+				'single' => '1 ' . esc_html($items_label['single']),
837
+				'plural' => '%s ' . esc_html($items_label['plural']),
838
+			);
839
+		}
840
+
841
+		$total_pages = ceil($total_items / $per_page);
842
+
843
+		if ($total_pages <= 1) {
844
+			return '';
845
+		}
846
+
847
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
848
+
849
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
850
+
851
+		if ($current === 1) {
852
+			$disable_first = ' disabled';
853
+		}
854
+		if ($current == $total_pages) {
855
+			$disable_last = ' disabled';
856
+		}
857
+
858
+		$page_links[] = sprintf(
859
+			"<a class='%s' title='%s' href='%s'>%s</a>",
860
+			'first-page' . $disable_first,
861
+			esc_attr__('Go to the first page', 'event_espresso'),
862
+			esc_url(remove_query_arg($paged_arg_name, $url)),
863
+			'&laquo;'
864
+		);
865
+
866
+		$page_links[] = sprintf(
867
+			'<a class="%s" title="%s" href="%s">%s</a>',
868
+			'prev-page' . $disable_first,
869
+			esc_attr__('Go to the previous page', 'event_espresso'),
870
+			esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
871
+			'&lsaquo;'
872
+		);
873
+
874
+		if (! $show_num_field) {
875
+			$html_current_page = $current;
876
+		} else {
877
+			$html_current_page = sprintf(
878
+				"<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
879
+				esc_attr__('Current page', 'event_espresso'),
880
+				$current,
881
+				strlen($total_pages)
882
+			);
883
+		}
884
+
885
+		$html_total_pages = sprintf(
886
+			'<span class="total-pages">%s</span>',
887
+			number_format_i18n($total_pages)
888
+		);
889
+		$page_links[]     = sprintf(
890
+			_x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
891
+			$html_current_page,
892
+			$html_total_pages,
893
+			'<span class="paging-input">',
894
+			'</span>'
895
+		);
896
+
897
+		$page_links[] = sprintf(
898
+			'<a class="%s" title="%s" href="%s">%s</a>',
899
+			'next-page' . $disable_last,
900
+			esc_attr__('Go to the next page', 'event_espresso'),
901
+			esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
902
+			'&rsaquo;'
903
+		);
904
+
905
+		$page_links[] = sprintf(
906
+			'<a class="%s" title="%s" href="%s">%s</a>',
907
+			'last-page' . $disable_last,
908
+			esc_attr__('Go to the last page', 'event_espresso'),
909
+			esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
910
+			'&raquo;'
911
+		);
912
+
913
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
914
+		// set page class
915
+		if ($total_pages) {
916
+			$page_class = $total_pages < 2 ? ' one-page' : '';
917
+		} else {
918
+			$page_class = ' no-pages';
919
+		}
920
+
921
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
922
+	}
923
+
924
+
925
+	/**
926
+	 * @param string $wrap_class
927
+	 * @param string $wrap_id
928
+	 * @return string
929
+	 */
930
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
931
+	{
932
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
933
+		if (! $admin &&
934
+			! apply_filters(
935
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
936
+				EE_Registry::instance()->CFG->admin->show_reg_footer
937
+			)
938
+		) {
939
+			return '';
940
+		}
941
+		$tag        = $admin ? 'span' : 'div';
942
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
943
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
944
+		$attributes .= ! empty($wrap_class)
945
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
946
+			: ' class="powered-by-event-espresso-credit"';
947
+		$query_args = array_merge(
948
+			array(
949
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
950
+				'utm_source'   => 'powered_by_event_espresso',
951
+				'utm_medium'   => 'link',
952
+				'utm_campaign' => 'powered_by',
953
+			),
954
+			$query_args
955
+		);
956
+		$powered_by = apply_filters(
957
+			'FHEE__EEH_Template__powered_by_event_espresso_text',
958
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
959
+		);
960
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
961
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
962
+		return (string) apply_filters(
963
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
964
+			sprintf(
965
+				esc_html_x(
966
+					'%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
967
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
968
+					'event_espresso'
969
+				),
970
+				"<{$tag}{$attributes}>",
971
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
972
+				$admin ? '' : '<br />'
973
+			),
974
+			$wrap_class,
975
+			$wrap_id
976
+		);
977
+	}
978 978
 }
979 979
 
980 980
 
981 981
 
982 982
 
983 983
 if (! function_exists('espresso_pagination')) {
984
-    /**
985
-     *    espresso_pagination
986
-     *
987
-     * @access    public
988
-     * @return    void
989
-     */
990
-    function espresso_pagination()
991
-    {
992
-        global $wp_query;
993
-        $big        = 999999999; // need an unlikely integer
994
-        $pagination = paginate_links(
995
-            array(
996
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
997
-                'format'       => '?paged=%#%',
998
-                'current'      => max(1, get_query_var('paged')),
999
-                'total'        => $wp_query->max_num_pages,
1000
-                'show_all'     => true,
1001
-                'end_size'     => 10,
1002
-                'mid_size'     => 6,
1003
-                'prev_next'    => true,
1004
-                'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
1005
-                'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
1006
-                'type'         => 'plain',
1007
-                'add_args'     => false,
1008
-                'add_fragment' => '',
1009
-            )
1010
-        );
1011
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1012
-    }
984
+	/**
985
+	 *    espresso_pagination
986
+	 *
987
+	 * @access    public
988
+	 * @return    void
989
+	 */
990
+	function espresso_pagination()
991
+	{
992
+		global $wp_query;
993
+		$big        = 999999999; // need an unlikely integer
994
+		$pagination = paginate_links(
995
+			array(
996
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
997
+				'format'       => '?paged=%#%',
998
+				'current'      => max(1, get_query_var('paged')),
999
+				'total'        => $wp_query->max_num_pages,
1000
+				'show_all'     => true,
1001
+				'end_size'     => 10,
1002
+				'mid_size'     => 6,
1003
+				'prev_next'    => true,
1004
+				'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
1005
+				'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
1006
+				'type'         => 'plain',
1007
+				'add_args'     => false,
1008
+				'add_fragment' => '',
1009
+			)
1010
+		);
1011
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1012
+	}
1013 1013
 }
1014 1014
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 
7
-if (! function_exists('espresso_get_template_part')) {
7
+if ( ! function_exists('espresso_get_template_part')) {
8 8
     /**
9 9
      * espresso_get_template_part
10 10
      * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 }
22 22
 
23 23
 
24
-if (! function_exists('espresso_get_object_css_class')) {
24
+if ( ! function_exists('espresso_get_object_css_class')) {
25 25
     /**
26 26
      * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27 27
      *
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public static function load_espresso_theme_functions()
71 71
     {
72
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
74
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
72
+        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
+            if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) {
74
+                require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php');
75 75
             }
76 76
         }
77 77
     }
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
     public static function get_espresso_themes()
86 86
     {
87 87
         if (empty(EEH_Template::$_espresso_themes)) {
88
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
88
+            $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
89 89
             if (empty($espresso_themes)) {
90 90
                 return array();
91 91
             }
92 92
             if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
-                unset($espresso_themes[ $key ]);
93
+                unset($espresso_themes[$key]);
94 94
             }
95 95
             EEH_Template::$_espresso_themes = array();
96 96
             foreach ($espresso_themes as $espresso_theme) {
97
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
97
+                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
98 98
             }
99 99
         }
100 100
         return EEH_Template::$_espresso_themes;
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
                 // get array of EE Custom Post Types
206 206
                 $EE_CPTs = $custom_post_types->getDefinitions();
207 207
                 // build template name based on request
208
-                if (isset($EE_CPTs[ $post_type ])) {
208
+                if (isset($EE_CPTs[$post_type])) {
209 209
                     $archive_or_single = is_archive() ? 'archive' : '';
210 210
                     $archive_or_single = is_single() ? 'single' : $archive_or_single;
211
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
211
+                    $templates         = $archive_or_single.'-'.$post_type.'.php';
212 212
                 }
213 213
             }
214 214
             // currently active EE template theme
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
             // array of paths to folders that may contain templates
218 218
             $template_folder_paths = array(
219 219
                 // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
220
+                EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
221 221
                 // then in the root of the /wp-content/uploads/espresso/templates/ folder
222 222
                 EVENT_ESPRESSO_TEMPLATE_DIR,
223 223
             );
224 224
 
225 225
             // add core plugin folders for checking only if we're not $check_if_custom
226
-            if (! $check_if_custom) {
227
-                $core_paths            = array(
226
+            if ( ! $check_if_custom) {
227
+                $core_paths = array(
228 228
                     // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
-                    EE_PUBLIC . $current_theme,
229
+                    EE_PUBLIC.$current_theme,
230 230
                     // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
-                    EE_TEMPLATES . $current_theme,
231
+                    EE_TEMPLATES.$current_theme,
232 232
                     // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233 233
                     EE_PLUGIN_DIR_PATH,
234 234
                 );
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
                     );
262 262
                     if ($common_base_path !== '') {
263 263
                         // both paths have a common base, so just tack the filename onto our search path
264
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
264
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
265 265
                     } else {
266 266
                         // no common base path, so let's just concatenate
267
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
267
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
268 268
                     }
269 269
                     // build up our template locations array by adding our resolved paths
270 270
                     $full_template_paths[] = $resolved_path;
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                 // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273 273
                 array_unshift($full_template_paths, $template);
274 274
                 // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
275
+                array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name);
276 276
             }
277 277
             // filter final array of full template paths
278 278
             $full_template_paths = apply_filters(
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
         $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362 362
 
363 363
         // you gimme nuttin - YOU GET NUTTIN !!
364
-        if (! $template_path || ! is_readable($template_path)) {
364
+        if ( ! $template_path || ! is_readable($template_path)) {
365 365
             return '';
366 366
         }
367 367
         // if $template_args are not in an array, then make it so
368
-        if (! is_array($template_args) && ! is_object($template_args)) {
368
+        if ( ! is_array($template_args) && ! is_object($template_args)) {
369 369
             $template_args = array($template_args);
370 370
         }
371 371
         extract($template_args, EXTR_SKIP);
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
     public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404 404
     {
405 405
         // in the beginning...
406
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
406
+        $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
407 407
         // da muddle
408 408
         $class = '';
409 409
         // the end
410
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
410
+        $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
411 411
         // is the passed object an EE object ?
412 412
         if ($object instanceof EE_Base_Class) {
413 413
             // grab the exact type of object
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
                 // no specifics just yet...
418 418
                 default:
419 419
                     $class = strtolower(str_replace('_', '-', $obj_class));
420
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
420
+                    $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
421 421
             }
422 422
         }
423
-        return $prefix . $class . $suffix;
423
+        return $prefix.$class.$suffix;
424 424
     }
425 425
 
426 426
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
             // was a country ISO code passed ? if so generate currency config object for that country
462 462
             $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
463 463
             // verify results
464
-            if (! $mny instanceof EE_Currency_Config) {
464
+            if ( ! $mny instanceof EE_Currency_Config) {
465 465
                 // set default config country currency settings
466 466
                 $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
467 467
                     ? EE_Registry::instance()->CFG->currency
@@ -470,23 +470,23 @@  discard block
 block discarded – undo
470 470
             // format float
471 471
             $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
472 472
             // add formatting ?
473
-            if (! $return_raw) {
473
+            if ( ! $return_raw) {
474 474
                 // add currency sign
475 475
                 if ($mny->sign_b4) {
476 476
                     if ($amount >= 0) {
477
-                        $amount_formatted = $mny->sign . $amount_formatted;
477
+                        $amount_formatted = $mny->sign.$amount_formatted;
478 478
                     } else {
479
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
479
+                        $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
480 480
                     }
481 481
                 } else {
482
-                    $amount_formatted = $amount_formatted . $mny->sign;
482
+                    $amount_formatted = $amount_formatted.$mny->sign;
483 483
                 }
484 484
 
485 485
                 // filter to allow global setting of display_code
486 486
                 $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487 487
 
488 488
                 // add currency code ?
489
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
489
+                $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted;
490 490
             }
491 491
             // filter results
492 492
             $amount_formatted = apply_filters(
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
             $plural,
524 524
             $schema
525 525
         );
526
-        return $status[ $status_id ];
526
+        return $status[$status_id];
527 527
     }
528 528
 
529 529
 
@@ -540,19 +540,19 @@  discard block
 block discarded – undo
540 540
     public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
541 541
     {
542 542
         $icon_html = '';
543
-        if (! empty($icon)) {
543
+        if ( ! empty($icon)) {
544 544
             $dashicons = preg_split("(ee-icon |dashicons )", $icon);
545 545
             $dashicons = array_filter($dashicons);
546 546
             $count     = count($dashicons);
547 547
             $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
548 548
             foreach ($dashicons as $dashicon) {
549 549
                 $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
550
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
550
+                $icon_html .= '<span class="'.$type.$dashicon.'"></span>';
551 551
             }
552 552
             $icon_html .= $count > 1 ? '</span>' : '';
553 553
         }
554
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
555
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
554
+        $label  = ! empty($icon) ? $icon_html.$label : $label;
555
+        $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.esc_url($url).'" class="'.$class.'" title="'.$title.'">'.$label.'</a>';
556 556
         return $button;
557 557
     }
558 558
 
@@ -575,24 +575,24 @@  discard block
 block discarded – undo
575 575
         $help_text = false
576 576
     ) {
577 577
 
578
-        if (! $page) {
578
+        if ( ! $page) {
579 579
             $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
580 580
         }
581 581
 
582
-        if (! $action) {
582
+        if ( ! $action) {
583 583
             $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
584 584
         }
585 585
 
586 586
         $action = empty($action) ? 'default' : $action;
587 587
 
588 588
 
589
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
589
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
590 590
         $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
591 591
         $help_text    = ! $help_text ? '' : $help_text;
592
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
592
+        return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__(
593 593
             'Click to open the \'Help\' tab for more information about this feature.',
594 594
             'event_espresso'
595
-        ) . '" > ' . $help_text . ' </a>';
595
+        ).'" > '.$help_text.' </a>';
596 596
     }
597 597
 
598 598
 
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
         $id    = $tour->get_slug();
610 610
         $stops = $tour->get_stops();
611 611
 
612
-        $content = '<ol style="display:none" id="' . $id . '">';
612
+        $content = '<ol style="display:none" id="'.$id.'">';
613 613
 
614 614
         foreach ($stops as $stop) {
615
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
616
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
615
+            $data_id    = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : '';
616
+            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : '';
617 617
 
618 618
             // if container is set to modal then let's make sure we set the options accordingly
619 619
             if (empty($data_id) && empty($data_class)) {
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
                 $stop['options']['expose'] = true;
622 622
             }
623 623
 
624
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
625
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
624
+            $custom_class  = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : '';
625
+            $button_text   = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : '';
626 626
             $inner_content = isset($stop['content']) ? $stop['content'] : '';
627 627
 
628 628
             // options
629 629
             if (isset($stop['options']) && is_array($stop['options'])) {
630 630
                 $options = ' data-options="';
631 631
                 foreach ($stop['options'] as $option => $value) {
632
-                    $options .= $option . ':' . $value . ';';
632
+                    $options .= $option.':'.$value.';';
633 633
                 }
634 634
                 $options .= '"';
635 635
             } else {
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
             }
638 638
 
639 639
             // let's put all together
640
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
640
+            $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>';
641 641
         }
642 642
 
643 643
         $content .= '</ol>';
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
      */
662 662
     public static function status_legend($status_array, $active_status = '')
663 663
     {
664
-        if (! is_array($status_array)) {
664
+        if ( ! is_array($status_array)) {
665 665
             throw new EE_Error(esc_html__(
666 666
                 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
667 667
                 'event_espresso'
@@ -670,25 +670,25 @@  discard block
 block discarded – undo
670 670
 
671 671
         $setup_array = array();
672 672
         foreach ($status_array as $item => $status) {
673
-            $setup_array[ $item ] = array(
674
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
673
+            $setup_array[$item] = array(
674
+                'class'  => 'ee-status-legend ee-status-legend-'.$status,
675 675
                 'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
676 676
                 'status' => $status,
677 677
             );
678 678
         }
679 679
 
680
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
681
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
682
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
680
+        $content = '<div class="ee-list-table-legend-container">'."\n";
681
+        $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n";
682
+        $content .= '<dl class="ee-list-table-legend">'."\n\t";
683 683
         foreach ($setup_array as $item => $details) {
684 684
             $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
685
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
686
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
687
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
688
-            $content .= '</dt>' . "\n";
685
+            $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t";
686
+            $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t";
687
+            $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t";
688
+            $content .= '</dt>'."\n";
689 689
         }
690
-        $content .= '</dl>' . "\n";
691
-        $content .= '</div>' . "\n";
690
+        $content .= '</dl>'."\n";
691
+        $content .= '</div>'."\n";
692 692
         return $content;
693 693
     }
694 694
 
@@ -833,8 +833,8 @@  discard block
 block discarded – undo
833 833
             );
834 834
         } else {
835 835
             $items_label = array(
836
-                'single' => '1 ' . esc_html($items_label['single']),
837
-                'plural' => '%s ' . esc_html($items_label['plural']),
836
+                'single' => '1 '.esc_html($items_label['single']),
837
+                'plural' => '%s '.esc_html($items_label['plural']),
838 838
             );
839 839
         }
840 840
 
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 
847 847
         $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
848 848
 
849
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
849
+        $output = '<span class="displaying-num">'.$item_label.'</span>';
850 850
 
851 851
         if ($current === 1) {
852 852
             $disable_first = ' disabled';
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 
858 858
         $page_links[] = sprintf(
859 859
             "<a class='%s' title='%s' href='%s'>%s</a>",
860
-            'first-page' . $disable_first,
860
+            'first-page'.$disable_first,
861 861
             esc_attr__('Go to the first page', 'event_espresso'),
862 862
             esc_url(remove_query_arg($paged_arg_name, $url)),
863 863
             '&laquo;'
@@ -865,13 +865,13 @@  discard block
 block discarded – undo
865 865
 
866 866
         $page_links[] = sprintf(
867 867
             '<a class="%s" title="%s" href="%s">%s</a>',
868
-            'prev-page' . $disable_first,
868
+            'prev-page'.$disable_first,
869 869
             esc_attr__('Go to the previous page', 'event_espresso'),
870 870
             esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
871 871
             '&lsaquo;'
872 872
         );
873 873
 
874
-        if (! $show_num_field) {
874
+        if ( ! $show_num_field) {
875 875
             $html_current_page = $current;
876 876
         } else {
877 877
             $html_current_page = sprintf(
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
             '<span class="total-pages">%s</span>',
887 887
             number_format_i18n($total_pages)
888 888
         );
889
-        $page_links[]     = sprintf(
889
+        $page_links[] = sprintf(
890 890
             _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
891 891
             $html_current_page,
892 892
             $html_total_pages,
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
 
897 897
         $page_links[] = sprintf(
898 898
             '<a class="%s" title="%s" href="%s">%s</a>',
899
-            'next-page' . $disable_last,
899
+            'next-page'.$disable_last,
900 900
             esc_attr__('Go to the next page', 'event_espresso'),
901 901
             esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
902 902
             '&rsaquo;'
@@ -904,13 +904,13 @@  discard block
 block discarded – undo
904 904
 
905 905
         $page_links[] = sprintf(
906 906
             '<a class="%s" title="%s" href="%s">%s</a>',
907
-            'last-page' . $disable_last,
907
+            'last-page'.$disable_last,
908 908
             esc_attr__('Go to the last page', 'event_espresso'),
909 909
             esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
910 910
             '&raquo;'
911 911
         );
912 912
 
913
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
913
+        $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
914 914
         // set page class
915 915
         if ($total_pages) {
916 916
             $page_class = $total_pages < 2 ? ' one-page' : '';
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
             $page_class = ' no-pages';
919 919
         }
920 920
 
921
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
921
+        return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
922 922
     }
923 923
 
924 924
 
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
     public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
931 931
     {
932 932
         $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
933
-        if (! $admin &&
933
+        if ( ! $admin &&
934 934
             ! apply_filters(
935 935
                 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
936 936
                 EE_Registry::instance()->CFG->admin->show_reg_footer
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
         );
956 956
         $powered_by = apply_filters(
957 957
             'FHEE__EEH_Template__powered_by_event_espresso_text',
958
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
958
+            $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'
959 959
         );
960 960
         $url        = add_query_arg($query_args, 'https://eventespresso.com/');
961 961
         $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
 
981 981
 
982 982
 
983
-if (! function_exists('espresso_pagination')) {
983
+if ( ! function_exists('espresso_pagination')) {
984 984
     /**
985 985
      *    espresso_pagination
986 986
      *
@@ -1008,6 +1008,6 @@  discard block
 block discarded – undo
1008 1008
                 'add_fragment' => '',
1009 1009
             )
1010 1010
         );
1011
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1011
+        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
1012 1012
     }
1013 1013
 }
1014 1014
\ No newline at end of file
Please login to merge, or discard this patch.
core/helpers/EEH_File.helper.php 2 patches
Indentation   +662 added lines, -662 removed lines patch added patch discarded remove patch
@@ -24,666 +24,666 @@
 block discarded – undo
24 24
 class EEH_File extends EEH_Base implements EEHI_File
25 25
 {
26 26
 
27
-    /**
28
-     * @var string $_credentials_form
29
-     */
30
-    private static $_credentials_form;
31
-
32
-    protected static $_wp_filesystem_direct;
33
-
34
-    /**
35
-     * @param string|null $filepath the filepath we want to work in. If its in the
36
-     * wp uploads directory, we'll want to just use the filesystem directly.
37
-     * If not provided, we have to assume its not in the uploads directory
38
-     * @throws EE_Error if filesystem credentials are required
39
-     * @return WP_Filesystem_Base
40
-     */
41
-    private static function _get_wp_filesystem($filepath = null)
42
-    {
43
-        if (apply_filters(
44
-            'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
45
-            $filepath && EEH_File::is_in_uploads_folder($filepath),
46
-            $filepath
47
-        ) ) {
48
-            if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
49
-                require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
50
-                $method = 'direct';
51
-                $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
52
-                // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
53
-                if (! defined('FS_CHMOD_DIR')) {
54
-                    define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 ));
55
-                }
56
-                if (! defined('FS_CHMOD_FILE')) {
57
-                    define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 ));
58
-                }
59
-                require_once($wp_filesystem_direct_file);
60
-                EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
61
-            }
62
-            return EEH_File::$_wp_filesystem_direct;
63
-        }
64
-        global $wp_filesystem;
65
-        // no filesystem setup ???
66
-        if (! $wp_filesystem instanceof WP_Filesystem_Base) {
67
-            // if some eager beaver's just trying to get in there too early...
68
-            // let them do it, because we are one of those eager beavers! :P
69
-            /**
70
-             * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base
71
-             * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process
72
-             * is setup to mostly happen on 'init', and refactoring to have it happen on
73
-             * 'wp_loaded' is too much work on a BETA milestone.
74
-             * So this fix is expected to work if the WP files are owned by the server user,
75
-             * but probably not if the user needs to enter their FTP credentials to modify files
76
-             * and there may be troubles if the WP files are owned by a different user
77
-             * than the server user. But both of these issues should exist in 4.4 and earlier too
78
-             */
79
-            if (false && ! did_action('wp_loaded')) {
80
-                $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
81
-                if (WP_DEBUG) {
82
-                    $msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
83
-                }
84
-                throw new EE_Error($msg);
85
-            } else {
86
-                // should be loaded if we are past the wp_loaded hook...
87
-                if (! function_exists('WP_Filesystem')) {
88
-                    require_once(ABSPATH . 'wp-admin/includes/file.php');
89
-                    require_once(ABSPATH . 'wp-admin/includes/template.php');
90
-                }
91
-                // turn on output buffering so that we can capture the credentials form
92
-                ob_start();
93
-                $credentials = request_filesystem_credentials('');
94
-                // store credentials form for the time being
95
-                EEH_File::$_credentials_form = ob_get_clean();
96
-                // basically check for direct or previously configured access
97
-                if (! WP_Filesystem($credentials)) {
98
-                    // if credentials do NOT exist
99
-                    if ($credentials === false) {
100
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
101
-                        throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
102
-                    } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
103
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
104
-                        throw new EE_Error(
105
-                            sprintf(
106
-                                __('WP Filesystem Error: $1%s', 'event_espresso'),
107
-                                $wp_filesystem->errors->get_error_message()
108
-                            )
109
-                        );
110
-                    }
111
-                }
112
-            }
113
-        }
114
-        return $wp_filesystem;
115
-    }
116
-
117
-    /**
118
-     * display_request_filesystem_credentials_form
119
-     */
120
-    public static function display_request_filesystem_credentials_form()
121
-    {
122
-        if (! empty(EEH_File::$_credentials_form)) {
123
-            echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
124
-        }
125
-    }
126
-
127
-
128
-
129
-    /**
130
-     *    verify_filepath_and_permissions
131
-     *    checks that a file is readable and has sufficient file permissions set to access
132
-     *
133
-     * @access public
134
-     * @param string $full_file_path - full server path to the folder or file
135
-     * @param string $file_name      - name of file if checking a file
136
-     * @param string $file_ext       - file extension (ie: "php") if checking a file
137
-     * @param string $type_of_file   - general type of file (ie: "module"), this is only used to improve error messages
138
-     * @throws EE_Error if filesystem credentials are required
139
-     * @return bool
140
-     */
141
-    public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '')
142
-    {
143
-        // load WP_Filesystem and set file permissions
144
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
145
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
146
-        if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
147
-            $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name;
148
-            $file_name .= ! empty($file_ext) ? ' file' : ' folder';
149
-            $msg = sprintf(
150
-                __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
151
-                $file_name,
152
-                '<br />'
153
-            );
154
-            if (EEH_File::exists($full_file_path)) {
155
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
156
-            } else {
157
-                // no file permissions means the file was not found
158
-                $msg .= sprintf(
159
-                    __('Please ensure the following path is correct: "%s".', 'event_espresso'),
160
-                    $full_file_path
161
-                );
162
-            }
163
-            if (defined('WP_DEBUG') && WP_DEBUG) {
164
-                throw new EE_Error($msg . '||' . $msg);
165
-            }
166
-            return false;
167
-        }
168
-        return true;
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder
175
-     *
176
-     * @access private
177
-     * @param string $full_file_path - full server path to the folder or file
178
-     * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages
179
-     * @throws EE_Error if filesystem credentials are required
180
-     * @return string
181
-     */
182
-    private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '')
183
-    {
184
-        // load WP_Filesystem and set file permissions
185
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
186
-        // check file permissions
187
-        $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
188
-        if ($perms) {
189
-            // file permissions exist, but way be set incorrectly
190
-            $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : '';
191
-            $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
192
-            return sprintf(
193
-                __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
194
-                $type_of_file,
195
-                $perms
196
-            );
197
-        } else {
198
-            // file exists but file permissions could not be read ?!?!
199
-            return sprintf(
200
-                __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
201
-                $full_file_path
202
-            );
203
-        }
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * ensure_folder_exists_and_is_writable
210
-     * ensures that a folder exists and is writable, will attempt to create folder if it does not exist
211
-     * Also ensures all the parent folders exist, and if not tries to create them.
212
-     * Also, if this function creates the folder, adds a .htaccess file and index.html file
213
-     * @param string $folder
214
-     * @throws EE_Error if the folder exists and is writeable, but for some reason we
215
-     * can't write to it
216
-     * @return bool false if folder isn't writable; true if it exists and is writeable,
217
-     */
218
-    public static function ensure_folder_exists_and_is_writable($folder = '')
219
-    {
220
-        if (empty($folder)) {
221
-            return false;
222
-        }
223
-        // remove ending /
224
-        $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
225
-        $parent_folder = EEH_File::get_parent_folder($folder);
226
-        // add / to folder
227
-        $folder = EEH_File::end_with_directory_separator($folder);
228
-        $wp_filesystem = EEH_File::_get_wp_filesystem($folder);
229
-        if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
230
-            // ok so it doesn't exist. Does its parent? Can we write to it?
231
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
232
-                return false;
233
-            }
234
-            if (! EEH_File::verify_is_writable($parent_folder, 'folder')) {
235
-                return false;
236
-            } else {
237
-                if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
238
-                    if (defined('WP_DEBUG') && WP_DEBUG) {
239
-                        $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
240
-                        $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
241
-                        throw new EE_Error($msg);
242
-                    }
243
-                    return false;
244
-                }
245
-                EEH_File::add_index_file($folder);
246
-            }
247
-        } elseif (! EEH_File::verify_is_writable($folder, 'folder')) {
248
-            return false;
249
-        }
250
-        return true;
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * verify_is_writable - checks if a file or folder is writable
257
-     * @param string $full_path      - full server path to file or folder
258
-     * @param string $file_or_folder - whether checking a file or folder
259
-     * @throws EE_Error if filesystem credentials are required
260
-     * @return bool
261
-     */
262
-    public static function verify_is_writable($full_path = '', $file_or_folder = 'folder')
263
-    {
264
-        // load WP_Filesystem and set file permissions
265
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
266
-        $full_path = EEH_File::standardise_directory_separators($full_path);
267
-        if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
268
-            if (defined('WP_DEBUG') && WP_DEBUG) {
269
-                $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
270
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
271
-                throw new EE_Error($msg);
272
-            }
273
-            return false;
274
-        }
275
-        return true;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * ensure_file_exists_and_is_writable
282
-     * ensures that a file exists and is writable, will attempt to create file if it does not exist.
283
-     * Also ensures all the parent folders exist, and if not tries to create them.
284
-     * @param string $full_file_path
285
-     * @throws EE_Error if filesystem credentials are required
286
-     * @return bool
287
-     */
288
-    public static function ensure_file_exists_and_is_writable($full_file_path = '')
289
-    {
290
-        // load WP_Filesystem and set file permissions
291
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
292
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
293
-        $parent_folder = EEH_File::get_parent_folder($full_file_path);
294
-        if (! EEH_File::exists($full_file_path)) {
295
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
296
-                return false;
297
-            }
298
-            if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
299
-                if (defined('WP_DEBUG') && WP_DEBUG) {
300
-                    $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
301
-                    $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
302
-                    throw new EE_Error($msg);
303
-                }
304
-                return false;
305
-            }
306
-        }
307
-        if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
308
-            return false;
309
-        }
310
-        return true;
311
-    }
312
-
313
-    /**
314
-     * Gets the parent folder. If provided with file, gets the folder that contains it.
315
-     * If provided a folder, gets its parent folder.
316
-     * @param string $file_or_folder_path
317
-     * @return string parent folder, ENDING with a directory separator
318
-     */
319
-    public static function get_parent_folder($file_or_folder_path)
320
-    {
321
-        // find the last /, ignoring a / on the very end
322
-        // eg if given "/var/something/somewhere/", we want to get "somewhere"'s
323
-        // parent folder, "/var/something/"
324
-        $ds = strlen($file_or_folder_path) > 1
325
-            ? strrpos($file_or_folder_path, '/', -2)
326
-            : strlen($file_or_folder_path);
327
-        return substr($file_or_folder_path, 0, $ds + 1);
328
-    }
329
-
330
-    // public static function ensure_folder_exists_recursively( $folder ) {
331
-    //
332
-    // }
333
-
334
-
335
-
336
-    /**
337
-     * get_file_contents
338
-     * @param string $full_file_path
339
-     * @throws EE_Error if filesystem credentials are required
340
-     * @return string
341
-     */
342
-    public static function get_file_contents($full_file_path = '')
343
-    {
344
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
345
-        if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
346
-            // load WP_Filesystem and set file permissions
347
-            $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
348
-            return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
349
-        }
350
-        return '';
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * write_file
357
-     * @param string $full_file_path
358
-     * @param string $file_contents - the content to be written to the file
359
-     * @param string $file_type
360
-     * @throws EE_Error if filesystem credentials are required
361
-     * @return bool
362
-     */
363
-    public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
364
-    {
365
-        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
366
-        $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
367
-        $folder = EEH_File::remove_filename_from_filepath($full_file_path);
368
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
369
-            if (defined('WP_DEBUG') && WP_DEBUG) {
370
-                $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
371
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
372
-                throw new EE_Error($msg);
373
-            }
374
-            return false;
375
-        }
376
-        // load WP_Filesystem and set file permissions
377
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
378
-        // write the file
379
-        if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
380
-            if (defined('WP_DEBUG') && WP_DEBUG) {
381
-                $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
382
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
383
-                throw new EE_Error($msg);
384
-            }
385
-            return false;
386
-        }
387
-        return true;
388
-    }
389
-
390
-    /**
391
-     * Wrapper for WP_Filesystem_Base::delete
392
-     *
393
-     * @param string $filepath
394
-     * @param boolean $recursive
395
-     * @param boolean|string $type 'd' for directory, 'f' for file
396
-     * @throws EE_Error if filesystem credentials are required
397
-     * @return boolean
398
-     */
399
-    public static function delete($filepath, $recursive = false, $type = false)
400
-    {
401
-        $wp_filesystem = EEH_File::_get_wp_filesystem();
402
-        return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false;
403
-    }
404
-
405
-
406
-
407
-    /**
408
-     * exists
409
-     * checks if a file exists using the WP filesystem
410
-     * @param string $full_file_path
411
-     * @throws EE_Error if filesystem credentials are required
412
-     * @return bool
413
-     */
414
-    public static function exists($full_file_path = '')
415
-    {
416
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
417
-        return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false;
418
-    }
419
-
420
-
421
-
422
-    /**
423
-     * is_readable
424
-     * checks if a file is_readable using the WP filesystem
425
-     *
426
-     * @param string $full_file_path
427
-     * @throws EE_Error if filesystem credentials are required
428
-     * @return bool
429
-     */
430
-    public static function is_readable($full_file_path = '')
431
-    {
432
-        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
433
-        if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
434
-            return true;
435
-        } else {
436
-            return false;
437
-        }
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * remove_filename_from_filepath
444
-     * given a full path to a file including the filename itself, this removes  the filename and returns the path, up to, but NOT including the filename OR slash
445
-     *
446
-     * @param string $full_file_path
447
-     * @return string
448
-     */
449
-    public static function remove_filename_from_filepath($full_file_path = '')
450
-    {
451
-        return pathinfo($full_file_path, PATHINFO_DIRNAME);
452
-    }
453
-
454
-
455
-    /**
456
-     * get_filename_from_filepath. Arguably the same as basename()
457
-     *
458
-     * @param string $full_file_path
459
-     * @return string
460
-     */
461
-    public static function get_filename_from_filepath($full_file_path = '')
462
-    {
463
-        return pathinfo($full_file_path, PATHINFO_BASENAME);
464
-    }
465
-
466
-
467
-    /**
468
-     * get_file_extension
469
-     *
470
-     * @param string $full_file_path
471
-     * @return string
472
-     */
473
-    public static function get_file_extension($full_file_path = '')
474
-    {
475
-        return pathinfo($full_file_path, PATHINFO_EXTENSION);
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * add_htaccess_deny_from_all so the webserver cannot access this folder
482
-     * @param string $folder
483
-     * @throws EE_Error if filesystem credentials are required
484
-     * @return bool
485
-     */
486
-    public static function add_htaccess_deny_from_all($folder = '')
487
-    {
488
-        $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
489
-        if (! EEH_File::exists($folder . '.htaccess')) {
490
-            if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) {
491
-                return false;
492
-            }
493
-        }
494
-
495
-        return true;
496
-    }
497
-
498
-    /**
499
-     * Adds an index file to this folder, so folks can't list all the file's contents
500
-     * @param string $folder
501
-     * @throws EE_Error if filesystem credentials are required
502
-     * @return boolean
503
-     */
504
-    public static function add_index_file($folder)
505
-    {
506
-        $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
507
-        if (! EEH_File::exists($folder . 'index.php')) {
508
-            if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) {
509
-                return false;
510
-            }
511
-        }
512
-        return true;
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php),
519
-     * extract that classname.
520
-     * @param string $file_path
521
-     * @return string
522
-     */
523
-    public static function get_classname_from_filepath_with_standard_filename($file_path)
524
-    {
525
-        // extract file from path
526
-        $filename = basename($file_path);
527
-        // now remove the first period and everything after
528
-        $pos_of_first_period = strpos($filename, '.');
529
-        return substr($filename, 0, $pos_of_first_period);
530
-    }
531
-
532
-
533
-
534
-    /**
535
-     * standardise_directory_separators
536
-     *  convert all directory separators in a file path.
537
-     * @param string $file_path
538
-     * @return string
539
-     */
540
-    public static function standardise_directory_separators($file_path)
541
-    {
542
-        return str_replace(array( '\\', '/' ), '/', $file_path);
543
-    }
544
-
545
-
546
-
547
-    /**
548
-     * end_with_directory_separator
549
-     *  ensures that file path ends with '/'
550
-     * @param string $file_path
551
-     * @return string
552
-     */
553
-    public static function end_with_directory_separator($file_path)
554
-    {
555
-        return rtrim($file_path, '/\\') . '/';
556
-    }
557
-
558
-
559
-
560
-    /**
561
-     * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators
562
-     * @param $file_path
563
-     * @return string
564
-     */
565
-    public static function standardise_and_end_with_directory_separator($file_path)
566
-    {
567
-        return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
568
-    }
569
-
570
-
571
-
572
-    /**
573
-     * takes the folder name (with or without trailing slash) and finds the files it in,
574
-     * and what the class's name inside of each should be.
575
-     * @param array $folder_paths
576
-     * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically;
577
-     *      if FALSE (Default), returned array will be indexed by the filenames minus extensions.
578
-     *      Set it TRUE if you know there are files in the directory with the same name but different extensions
579
-     * @throws EE_Error if filesystem credentials are required
580
-     * @return array if $index_numerically == TRUE keys are numeric ,
581
-     *      if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
582
-     *       and values are their filepaths
583
-     */
584
-    public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false)
585
-    {
586
-        $class_to_folder_path = array();
587
-        foreach ($folder_paths as $folder_path) {
588
-            $folder_path = self::standardise_and_end_with_directory_separator($folder_path);
589
-            // load WP_Filesystem and set file permissions
590
-            $files_in_folder = glob($folder_path . '*');
591
-            $class_to_folder_path = array();
592
-            if ($files_in_folder) {
593
-                foreach ($files_in_folder as $file_path) {
594
-                    // only add files, not folders
595
-                    if (! is_dir($file_path)) {
596
-                        if ($index_numerically) {
597
-                            $class_to_folder_path[] = $file_path;
598
-                        } else {
599
-                            $classname = self::get_classname_from_filepath_with_standard_filename($file_path);
600
-                            $class_to_folder_path[ $classname ] = $file_path;
601
-                        }
602
-                    }
603
-                }
604
-            }
605
-        }
606
-        return $class_to_folder_path;
607
-    }
608
-
609
-
610
-
611
-    /**
612
-     * Copies a file. Mostly a wrapper of WP_Filesystem::copy
613
-     * @param string $source_file
614
-     * @param string $destination_file
615
-     * @param boolean $overwrite
616
-     * @throws EE_Error if filesystem credentials are required
617
-     * @return boolean success
618
-     */
619
-    public static function copy($source_file, $destination_file, $overwrite = false)
620
-    {
621
-        $full_source_path = EEH_File::standardise_directory_separators($source_file);
622
-        if (! EEH_File::exists($full_source_path)) {
623
-            if (defined('WP_DEBUG') && WP_DEBUG) {
624
-                $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
625
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
626
-                throw new EE_Error($msg);
627
-            }
628
-            return false;
629
-        }
630
-
631
-        $full_dest_path = EEH_File::standardise_directory_separators($destination_file);
632
-        $folder = EEH_File::remove_filename_from_filepath($full_dest_path);
633
-        EEH_File::ensure_folder_exists_and_is_writable($folder);
634
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
635
-            if (defined('WP_DEBUG') && WP_DEBUG) {
636
-                $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
637
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
638
-                throw new EE_Error($msg);
639
-            }
640
-            return false;
641
-        }
642
-
643
-        // load WP_Filesystem and set file permissions
644
-        $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
645
-        // write the file
646
-        if (! $wp_filesystem->copy(
647
-            EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
648
-            EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
649
-            $overwrite
650
-        )) {
651
-            if (defined('WP_DEBUG') && WP_DEBUG) {
652
-                $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
653
-                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
654
-                throw new EE_Error($msg);
655
-            }
656
-            return false;
657
-        }
658
-        return true;
659
-    }
660
-
661
-    /**
662
-     * Reports whether or not the filepath is in the EE uploads folder or not
663
-     * @param string $filepath
664
-     * @return boolean
665
-     */
666
-    public static function is_in_uploads_folder($filepath)
667
-    {
668
-        $uploads = wp_upload_dir();
669
-        return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
670
-    }
671
-
672
-    /**
673
-     * Given a "local" filepath (what you probably thought was the only filepath),
674
-     * converts it into a "remote" filepath (the filepath the currently-in-use
675
-     * $wp_filesystem needs to use access the folder or file).
676
-     * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins
677
-     * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one
678
-     * is in use, so you need to provide it
679
-     * @param string $local_filepath the filepath to the folder/file locally
680
-     * @throws EE_Error if filesystem credentials are required
681
-     * @return string the remote filepath (eg the filepath the filesystem method, eg
682
-     * ftp or ssh, will use to access the folder
683
-     */
684
-    public static function convert_local_filepath_to_remote_filepath($local_filepath)
685
-    {
686
-        $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
687
-        return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath);
688
-    }
27
+	/**
28
+	 * @var string $_credentials_form
29
+	 */
30
+	private static $_credentials_form;
31
+
32
+	protected static $_wp_filesystem_direct;
33
+
34
+	/**
35
+	 * @param string|null $filepath the filepath we want to work in. If its in the
36
+	 * wp uploads directory, we'll want to just use the filesystem directly.
37
+	 * If not provided, we have to assume its not in the uploads directory
38
+	 * @throws EE_Error if filesystem credentials are required
39
+	 * @return WP_Filesystem_Base
40
+	 */
41
+	private static function _get_wp_filesystem($filepath = null)
42
+	{
43
+		if (apply_filters(
44
+			'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
45
+			$filepath && EEH_File::is_in_uploads_folder($filepath),
46
+			$filepath
47
+		) ) {
48
+			if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
49
+				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
50
+				$method = 'direct';
51
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
52
+				// check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
53
+				if (! defined('FS_CHMOD_DIR')) {
54
+					define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 ));
55
+				}
56
+				if (! defined('FS_CHMOD_FILE')) {
57
+					define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 ));
58
+				}
59
+				require_once($wp_filesystem_direct_file);
60
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
61
+			}
62
+			return EEH_File::$_wp_filesystem_direct;
63
+		}
64
+		global $wp_filesystem;
65
+		// no filesystem setup ???
66
+		if (! $wp_filesystem instanceof WP_Filesystem_Base) {
67
+			// if some eager beaver's just trying to get in there too early...
68
+			// let them do it, because we are one of those eager beavers! :P
69
+			/**
70
+			 * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base
71
+			 * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process
72
+			 * is setup to mostly happen on 'init', and refactoring to have it happen on
73
+			 * 'wp_loaded' is too much work on a BETA milestone.
74
+			 * So this fix is expected to work if the WP files are owned by the server user,
75
+			 * but probably not if the user needs to enter their FTP credentials to modify files
76
+			 * and there may be troubles if the WP files are owned by a different user
77
+			 * than the server user. But both of these issues should exist in 4.4 and earlier too
78
+			 */
79
+			if (false && ! did_action('wp_loaded')) {
80
+				$msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
81
+				if (WP_DEBUG) {
82
+					$msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
83
+				}
84
+				throw new EE_Error($msg);
85
+			} else {
86
+				// should be loaded if we are past the wp_loaded hook...
87
+				if (! function_exists('WP_Filesystem')) {
88
+					require_once(ABSPATH . 'wp-admin/includes/file.php');
89
+					require_once(ABSPATH . 'wp-admin/includes/template.php');
90
+				}
91
+				// turn on output buffering so that we can capture the credentials form
92
+				ob_start();
93
+				$credentials = request_filesystem_credentials('');
94
+				// store credentials form for the time being
95
+				EEH_File::$_credentials_form = ob_get_clean();
96
+				// basically check for direct or previously configured access
97
+				if (! WP_Filesystem($credentials)) {
98
+					// if credentials do NOT exist
99
+					if ($credentials === false) {
100
+						add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
101
+						throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
102
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
103
+						add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
104
+						throw new EE_Error(
105
+							sprintf(
106
+								__('WP Filesystem Error: $1%s', 'event_espresso'),
107
+								$wp_filesystem->errors->get_error_message()
108
+							)
109
+						);
110
+					}
111
+				}
112
+			}
113
+		}
114
+		return $wp_filesystem;
115
+	}
116
+
117
+	/**
118
+	 * display_request_filesystem_credentials_form
119
+	 */
120
+	public static function display_request_filesystem_credentials_form()
121
+	{
122
+		if (! empty(EEH_File::$_credentials_form)) {
123
+			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
124
+		}
125
+	}
126
+
127
+
128
+
129
+	/**
130
+	 *    verify_filepath_and_permissions
131
+	 *    checks that a file is readable and has sufficient file permissions set to access
132
+	 *
133
+	 * @access public
134
+	 * @param string $full_file_path - full server path to the folder or file
135
+	 * @param string $file_name      - name of file if checking a file
136
+	 * @param string $file_ext       - file extension (ie: "php") if checking a file
137
+	 * @param string $type_of_file   - general type of file (ie: "module"), this is only used to improve error messages
138
+	 * @throws EE_Error if filesystem credentials are required
139
+	 * @return bool
140
+	 */
141
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '')
142
+	{
143
+		// load WP_Filesystem and set file permissions
144
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
145
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
146
+		if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
147
+			$file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name;
148
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
149
+			$msg = sprintf(
150
+				__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
151
+				$file_name,
152
+				'<br />'
153
+			);
154
+			if (EEH_File::exists($full_file_path)) {
155
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
156
+			} else {
157
+				// no file permissions means the file was not found
158
+				$msg .= sprintf(
159
+					__('Please ensure the following path is correct: "%s".', 'event_espresso'),
160
+					$full_file_path
161
+				);
162
+			}
163
+			if (defined('WP_DEBUG') && WP_DEBUG) {
164
+				throw new EE_Error($msg . '||' . $msg);
165
+			}
166
+			return false;
167
+		}
168
+		return true;
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder
175
+	 *
176
+	 * @access private
177
+	 * @param string $full_file_path - full server path to the folder or file
178
+	 * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages
179
+	 * @throws EE_Error if filesystem credentials are required
180
+	 * @return string
181
+	 */
182
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '')
183
+	{
184
+		// load WP_Filesystem and set file permissions
185
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
186
+		// check file permissions
187
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
188
+		if ($perms) {
189
+			// file permissions exist, but way be set incorrectly
190
+			$type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : '';
191
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
192
+			return sprintf(
193
+				__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
194
+				$type_of_file,
195
+				$perms
196
+			);
197
+		} else {
198
+			// file exists but file permissions could not be read ?!?!
199
+			return sprintf(
200
+				__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
201
+				$full_file_path
202
+			);
203
+		}
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * ensure_folder_exists_and_is_writable
210
+	 * ensures that a folder exists and is writable, will attempt to create folder if it does not exist
211
+	 * Also ensures all the parent folders exist, and if not tries to create them.
212
+	 * Also, if this function creates the folder, adds a .htaccess file and index.html file
213
+	 * @param string $folder
214
+	 * @throws EE_Error if the folder exists and is writeable, but for some reason we
215
+	 * can't write to it
216
+	 * @return bool false if folder isn't writable; true if it exists and is writeable,
217
+	 */
218
+	public static function ensure_folder_exists_and_is_writable($folder = '')
219
+	{
220
+		if (empty($folder)) {
221
+			return false;
222
+		}
223
+		// remove ending /
224
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
225
+		$parent_folder = EEH_File::get_parent_folder($folder);
226
+		// add / to folder
227
+		$folder = EEH_File::end_with_directory_separator($folder);
228
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
229
+		if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
230
+			// ok so it doesn't exist. Does its parent? Can we write to it?
231
+			if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
232
+				return false;
233
+			}
234
+			if (! EEH_File::verify_is_writable($parent_folder, 'folder')) {
235
+				return false;
236
+			} else {
237
+				if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
238
+					if (defined('WP_DEBUG') && WP_DEBUG) {
239
+						$msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
240
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
241
+						throw new EE_Error($msg);
242
+					}
243
+					return false;
244
+				}
245
+				EEH_File::add_index_file($folder);
246
+			}
247
+		} elseif (! EEH_File::verify_is_writable($folder, 'folder')) {
248
+			return false;
249
+		}
250
+		return true;
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * verify_is_writable - checks if a file or folder is writable
257
+	 * @param string $full_path      - full server path to file or folder
258
+	 * @param string $file_or_folder - whether checking a file or folder
259
+	 * @throws EE_Error if filesystem credentials are required
260
+	 * @return bool
261
+	 */
262
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder')
263
+	{
264
+		// load WP_Filesystem and set file permissions
265
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
266
+		$full_path = EEH_File::standardise_directory_separators($full_path);
267
+		if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
268
+			if (defined('WP_DEBUG') && WP_DEBUG) {
269
+				$msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
270
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
271
+				throw new EE_Error($msg);
272
+			}
273
+			return false;
274
+		}
275
+		return true;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * ensure_file_exists_and_is_writable
282
+	 * ensures that a file exists and is writable, will attempt to create file if it does not exist.
283
+	 * Also ensures all the parent folders exist, and if not tries to create them.
284
+	 * @param string $full_file_path
285
+	 * @throws EE_Error if filesystem credentials are required
286
+	 * @return bool
287
+	 */
288
+	public static function ensure_file_exists_and_is_writable($full_file_path = '')
289
+	{
290
+		// load WP_Filesystem and set file permissions
291
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
292
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
293
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
294
+		if (! EEH_File::exists($full_file_path)) {
295
+			if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
296
+				return false;
297
+			}
298
+			if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
299
+				if (defined('WP_DEBUG') && WP_DEBUG) {
300
+					$msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
301
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
302
+					throw new EE_Error($msg);
303
+				}
304
+				return false;
305
+			}
306
+		}
307
+		if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
308
+			return false;
309
+		}
310
+		return true;
311
+	}
312
+
313
+	/**
314
+	 * Gets the parent folder. If provided with file, gets the folder that contains it.
315
+	 * If provided a folder, gets its parent folder.
316
+	 * @param string $file_or_folder_path
317
+	 * @return string parent folder, ENDING with a directory separator
318
+	 */
319
+	public static function get_parent_folder($file_or_folder_path)
320
+	{
321
+		// find the last /, ignoring a / on the very end
322
+		// eg if given "/var/something/somewhere/", we want to get "somewhere"'s
323
+		// parent folder, "/var/something/"
324
+		$ds = strlen($file_or_folder_path) > 1
325
+			? strrpos($file_or_folder_path, '/', -2)
326
+			: strlen($file_or_folder_path);
327
+		return substr($file_or_folder_path, 0, $ds + 1);
328
+	}
329
+
330
+	// public static function ensure_folder_exists_recursively( $folder ) {
331
+	//
332
+	// }
333
+
334
+
335
+
336
+	/**
337
+	 * get_file_contents
338
+	 * @param string $full_file_path
339
+	 * @throws EE_Error if filesystem credentials are required
340
+	 * @return string
341
+	 */
342
+	public static function get_file_contents($full_file_path = '')
343
+	{
344
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
345
+		if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
346
+			// load WP_Filesystem and set file permissions
347
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
348
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
349
+		}
350
+		return '';
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * write_file
357
+	 * @param string $full_file_path
358
+	 * @param string $file_contents - the content to be written to the file
359
+	 * @param string $file_type
360
+	 * @throws EE_Error if filesystem credentials are required
361
+	 * @return bool
362
+	 */
363
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
364
+	{
365
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
366
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
367
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
368
+		if (! EEH_File::verify_is_writable($folder, 'folder')) {
369
+			if (defined('WP_DEBUG') && WP_DEBUG) {
370
+				$msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
371
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
372
+				throw new EE_Error($msg);
373
+			}
374
+			return false;
375
+		}
376
+		// load WP_Filesystem and set file permissions
377
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
378
+		// write the file
379
+		if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
380
+			if (defined('WP_DEBUG') && WP_DEBUG) {
381
+				$msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
382
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
383
+				throw new EE_Error($msg);
384
+			}
385
+			return false;
386
+		}
387
+		return true;
388
+	}
389
+
390
+	/**
391
+	 * Wrapper for WP_Filesystem_Base::delete
392
+	 *
393
+	 * @param string $filepath
394
+	 * @param boolean $recursive
395
+	 * @param boolean|string $type 'd' for directory, 'f' for file
396
+	 * @throws EE_Error if filesystem credentials are required
397
+	 * @return boolean
398
+	 */
399
+	public static function delete($filepath, $recursive = false, $type = false)
400
+	{
401
+		$wp_filesystem = EEH_File::_get_wp_filesystem();
402
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false;
403
+	}
404
+
405
+
406
+
407
+	/**
408
+	 * exists
409
+	 * checks if a file exists using the WP filesystem
410
+	 * @param string $full_file_path
411
+	 * @throws EE_Error if filesystem credentials are required
412
+	 * @return bool
413
+	 */
414
+	public static function exists($full_file_path = '')
415
+	{
416
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
417
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false;
418
+	}
419
+
420
+
421
+
422
+	/**
423
+	 * is_readable
424
+	 * checks if a file is_readable using the WP filesystem
425
+	 *
426
+	 * @param string $full_file_path
427
+	 * @throws EE_Error if filesystem credentials are required
428
+	 * @return bool
429
+	 */
430
+	public static function is_readable($full_file_path = '')
431
+	{
432
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
433
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
434
+			return true;
435
+		} else {
436
+			return false;
437
+		}
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * remove_filename_from_filepath
444
+	 * given a full path to a file including the filename itself, this removes  the filename and returns the path, up to, but NOT including the filename OR slash
445
+	 *
446
+	 * @param string $full_file_path
447
+	 * @return string
448
+	 */
449
+	public static function remove_filename_from_filepath($full_file_path = '')
450
+	{
451
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
452
+	}
453
+
454
+
455
+	/**
456
+	 * get_filename_from_filepath. Arguably the same as basename()
457
+	 *
458
+	 * @param string $full_file_path
459
+	 * @return string
460
+	 */
461
+	public static function get_filename_from_filepath($full_file_path = '')
462
+	{
463
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
464
+	}
465
+
466
+
467
+	/**
468
+	 * get_file_extension
469
+	 *
470
+	 * @param string $full_file_path
471
+	 * @return string
472
+	 */
473
+	public static function get_file_extension($full_file_path = '')
474
+	{
475
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * add_htaccess_deny_from_all so the webserver cannot access this folder
482
+	 * @param string $folder
483
+	 * @throws EE_Error if filesystem credentials are required
484
+	 * @return bool
485
+	 */
486
+	public static function add_htaccess_deny_from_all($folder = '')
487
+	{
488
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
489
+		if (! EEH_File::exists($folder . '.htaccess')) {
490
+			if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) {
491
+				return false;
492
+			}
493
+		}
494
+
495
+		return true;
496
+	}
497
+
498
+	/**
499
+	 * Adds an index file to this folder, so folks can't list all the file's contents
500
+	 * @param string $folder
501
+	 * @throws EE_Error if filesystem credentials are required
502
+	 * @return boolean
503
+	 */
504
+	public static function add_index_file($folder)
505
+	{
506
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
507
+		if (! EEH_File::exists($folder . 'index.php')) {
508
+			if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) {
509
+				return false;
510
+			}
511
+		}
512
+		return true;
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php),
519
+	 * extract that classname.
520
+	 * @param string $file_path
521
+	 * @return string
522
+	 */
523
+	public static function get_classname_from_filepath_with_standard_filename($file_path)
524
+	{
525
+		// extract file from path
526
+		$filename = basename($file_path);
527
+		// now remove the first period and everything after
528
+		$pos_of_first_period = strpos($filename, '.');
529
+		return substr($filename, 0, $pos_of_first_period);
530
+	}
531
+
532
+
533
+
534
+	/**
535
+	 * standardise_directory_separators
536
+	 *  convert all directory separators in a file path.
537
+	 * @param string $file_path
538
+	 * @return string
539
+	 */
540
+	public static function standardise_directory_separators($file_path)
541
+	{
542
+		return str_replace(array( '\\', '/' ), '/', $file_path);
543
+	}
544
+
545
+
546
+
547
+	/**
548
+	 * end_with_directory_separator
549
+	 *  ensures that file path ends with '/'
550
+	 * @param string $file_path
551
+	 * @return string
552
+	 */
553
+	public static function end_with_directory_separator($file_path)
554
+	{
555
+		return rtrim($file_path, '/\\') . '/';
556
+	}
557
+
558
+
559
+
560
+	/**
561
+	 * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators
562
+	 * @param $file_path
563
+	 * @return string
564
+	 */
565
+	public static function standardise_and_end_with_directory_separator($file_path)
566
+	{
567
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
568
+	}
569
+
570
+
571
+
572
+	/**
573
+	 * takes the folder name (with or without trailing slash) and finds the files it in,
574
+	 * and what the class's name inside of each should be.
575
+	 * @param array $folder_paths
576
+	 * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically;
577
+	 *      if FALSE (Default), returned array will be indexed by the filenames minus extensions.
578
+	 *      Set it TRUE if you know there are files in the directory with the same name but different extensions
579
+	 * @throws EE_Error if filesystem credentials are required
580
+	 * @return array if $index_numerically == TRUE keys are numeric ,
581
+	 *      if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
582
+	 *       and values are their filepaths
583
+	 */
584
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false)
585
+	{
586
+		$class_to_folder_path = array();
587
+		foreach ($folder_paths as $folder_path) {
588
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
589
+			// load WP_Filesystem and set file permissions
590
+			$files_in_folder = glob($folder_path . '*');
591
+			$class_to_folder_path = array();
592
+			if ($files_in_folder) {
593
+				foreach ($files_in_folder as $file_path) {
594
+					// only add files, not folders
595
+					if (! is_dir($file_path)) {
596
+						if ($index_numerically) {
597
+							$class_to_folder_path[] = $file_path;
598
+						} else {
599
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
600
+							$class_to_folder_path[ $classname ] = $file_path;
601
+						}
602
+					}
603
+				}
604
+			}
605
+		}
606
+		return $class_to_folder_path;
607
+	}
608
+
609
+
610
+
611
+	/**
612
+	 * Copies a file. Mostly a wrapper of WP_Filesystem::copy
613
+	 * @param string $source_file
614
+	 * @param string $destination_file
615
+	 * @param boolean $overwrite
616
+	 * @throws EE_Error if filesystem credentials are required
617
+	 * @return boolean success
618
+	 */
619
+	public static function copy($source_file, $destination_file, $overwrite = false)
620
+	{
621
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
622
+		if (! EEH_File::exists($full_source_path)) {
623
+			if (defined('WP_DEBUG') && WP_DEBUG) {
624
+				$msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
625
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
626
+				throw new EE_Error($msg);
627
+			}
628
+			return false;
629
+		}
630
+
631
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
632
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
633
+		EEH_File::ensure_folder_exists_and_is_writable($folder);
634
+		if (! EEH_File::verify_is_writable($folder, 'folder')) {
635
+			if (defined('WP_DEBUG') && WP_DEBUG) {
636
+				$msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
637
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
638
+				throw new EE_Error($msg);
639
+			}
640
+			return false;
641
+		}
642
+
643
+		// load WP_Filesystem and set file permissions
644
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
645
+		// write the file
646
+		if (! $wp_filesystem->copy(
647
+			EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
648
+			EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
649
+			$overwrite
650
+		)) {
651
+			if (defined('WP_DEBUG') && WP_DEBUG) {
652
+				$msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
653
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
654
+				throw new EE_Error($msg);
655
+			}
656
+			return false;
657
+		}
658
+		return true;
659
+	}
660
+
661
+	/**
662
+	 * Reports whether or not the filepath is in the EE uploads folder or not
663
+	 * @param string $filepath
664
+	 * @return boolean
665
+	 */
666
+	public static function is_in_uploads_folder($filepath)
667
+	{
668
+		$uploads = wp_upload_dir();
669
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
670
+	}
671
+
672
+	/**
673
+	 * Given a "local" filepath (what you probably thought was the only filepath),
674
+	 * converts it into a "remote" filepath (the filepath the currently-in-use
675
+	 * $wp_filesystem needs to use access the folder or file).
676
+	 * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins
677
+	 * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one
678
+	 * is in use, so you need to provide it
679
+	 * @param string $local_filepath the filepath to the folder/file locally
680
+	 * @throws EE_Error if filesystem credentials are required
681
+	 * @return string the remote filepath (eg the filepath the filesystem method, eg
682
+	 * ftp or ssh, will use to access the folder
683
+	 */
684
+	public static function convert_local_filepath_to_remote_filepath($local_filepath)
685
+	{
686
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
687
+		return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath);
688
+	}
689 689
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -44,17 +44,17 @@  discard block
 block discarded – undo
44 44
             'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
45 45
             $filepath && EEH_File::is_in_uploads_folder($filepath),
46 46
             $filepath
47
-        ) ) {
48
-            if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
49
-                require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
47
+        )) {
48
+            if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
49
+                require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
50 50
                 $method = 'direct';
51
-                $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
51
+                $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
52 52
                 // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
53
-                if (! defined('FS_CHMOD_DIR')) {
54
-                    define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 ));
53
+                if ( ! defined('FS_CHMOD_DIR')) {
54
+                    define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
55 55
                 }
56
-                if (! defined('FS_CHMOD_FILE')) {
57
-                    define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 ));
56
+                if ( ! defined('FS_CHMOD_FILE')) {
57
+                    define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
58 58
                 }
59 59
                 require_once($wp_filesystem_direct_file);
60 60
                 EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         }
64 64
         global $wp_filesystem;
65 65
         // no filesystem setup ???
66
-        if (! $wp_filesystem instanceof WP_Filesystem_Base) {
66
+        if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
67 67
             // if some eager beaver's just trying to get in there too early...
68 68
             // let them do it, because we are one of those eager beavers! :P
69 69
             /**
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
             if (false && ! did_action('wp_loaded')) {
80 80
                 $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
81 81
                 if (WP_DEBUG) {
82
-                    $msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
82
+                    $msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
83 83
                 }
84 84
                 throw new EE_Error($msg);
85 85
             } else {
86 86
                 // should be loaded if we are past the wp_loaded hook...
87
-                if (! function_exists('WP_Filesystem')) {
88
-                    require_once(ABSPATH . 'wp-admin/includes/file.php');
89
-                    require_once(ABSPATH . 'wp-admin/includes/template.php');
87
+                if ( ! function_exists('WP_Filesystem')) {
88
+                    require_once(ABSPATH.'wp-admin/includes/file.php');
89
+                    require_once(ABSPATH.'wp-admin/includes/template.php');
90 90
                 }
91 91
                 // turn on output buffering so that we can capture the credentials form
92 92
                 ob_start();
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
                 // store credentials form for the time being
95 95
                 EEH_File::$_credentials_form = ob_get_clean();
96 96
                 // basically check for direct or previously configured access
97
-                if (! WP_Filesystem($credentials)) {
97
+                if ( ! WP_Filesystem($credentials)) {
98 98
                     // if credentials do NOT exist
99 99
                     if ($credentials === false) {
100
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
100
+                        add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
101 101
                         throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
102 102
                     } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
103
-                        add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999);
103
+                        add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
104 104
                         throw new EE_Error(
105 105
                             sprintf(
106 106
                                 __('WP Filesystem Error: $1%s', 'event_espresso'),
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
      */
120 120
     public static function display_request_filesystem_credentials_form()
121 121
     {
122
-        if (! empty(EEH_File::$_credentials_form)) {
123
-            echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
122
+        if ( ! empty(EEH_File::$_credentials_form)) {
123
+            echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
124 124
         }
125 125
     }
126 126
 
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
         // load WP_Filesystem and set file permissions
144 144
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
145 145
         $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
146
-        if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
147
-            $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name;
146
+        if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
147
+            $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
148 148
             $file_name .= ! empty($file_ext) ? ' file' : ' folder';
149 149
             $msg = sprintf(
150 150
                 __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
                 );
162 162
             }
163 163
             if (defined('WP_DEBUG') && WP_DEBUG) {
164
-                throw new EE_Error($msg . '||' . $msg);
164
+                throw new EE_Error($msg.'||'.$msg);
165 165
             }
166 166
             return false;
167 167
         }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
188 188
         if ($perms) {
189 189
             // file permissions exist, but way be set incorrectly
190
-            $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : '';
190
+            $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
191 191
             $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
192 192
             return sprintf(
193 193
                 __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
@@ -226,15 +226,15 @@  discard block
 block discarded – undo
226 226
         // add / to folder
227 227
         $folder = EEH_File::end_with_directory_separator($folder);
228 228
         $wp_filesystem = EEH_File::_get_wp_filesystem($folder);
229
-        if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
229
+        if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
230 230
             // ok so it doesn't exist. Does its parent? Can we write to it?
231
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
231
+            if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
232 232
                 return false;
233 233
             }
234
-            if (! EEH_File::verify_is_writable($parent_folder, 'folder')) {
234
+            if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
235 235
                 return false;
236 236
             } else {
237
-                if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
237
+                if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
238 238
                     if (defined('WP_DEBUG') && WP_DEBUG) {
239 239
                         $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
240 240
                         $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
                 }
245 245
                 EEH_File::add_index_file($folder);
246 246
             }
247
-        } elseif (! EEH_File::verify_is_writable($folder, 'folder')) {
247
+        } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
248 248
             return false;
249 249
         }
250 250
         return true;
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         // load WP_Filesystem and set file permissions
265 265
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
266 266
         $full_path = EEH_File::standardise_directory_separators($full_path);
267
-        if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
267
+        if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
268 268
             if (defined('WP_DEBUG') && WP_DEBUG) {
269 269
                 $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
270 270
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
@@ -291,11 +291,11 @@  discard block
 block discarded – undo
291 291
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
292 292
         $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
293 293
         $parent_folder = EEH_File::get_parent_folder($full_file_path);
294
-        if (! EEH_File::exists($full_file_path)) {
295
-            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
294
+        if ( ! EEH_File::exists($full_file_path)) {
295
+            if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
296 296
                 return false;
297 297
             }
298
-            if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
298
+            if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
299 299
                 if (defined('WP_DEBUG') && WP_DEBUG) {
300 300
                     $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
301 301
                     $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
                 return false;
305 305
             }
306 306
         }
307
-        if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
307
+        if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
308 308
             return false;
309 309
         }
310 310
         return true;
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
     public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
364 364
     {
365 365
         $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
366
-        $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
366
+        $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
367 367
         $folder = EEH_File::remove_filename_from_filepath($full_file_path);
368
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
368
+        if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
369 369
             if (defined('WP_DEBUG') && WP_DEBUG) {
370 370
                 $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
371 371
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         // load WP_Filesystem and set file permissions
377 377
         $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
378 378
         // write the file
379
-        if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
379
+        if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
380 380
             if (defined('WP_DEBUG') && WP_DEBUG) {
381 381
                 $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
382 382
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
@@ -486,8 +486,8 @@  discard block
 block discarded – undo
486 486
     public static function add_htaccess_deny_from_all($folder = '')
487 487
     {
488 488
         $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
489
-        if (! EEH_File::exists($folder . '.htaccess')) {
490
-            if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) {
489
+        if ( ! EEH_File::exists($folder.'.htaccess')) {
490
+            if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
491 491
                 return false;
492 492
             }
493 493
         }
@@ -504,8 +504,8 @@  discard block
 block discarded – undo
504 504
     public static function add_index_file($folder)
505 505
     {
506 506
         $folder = EEH_File::standardise_and_end_with_directory_separator($folder);
507
-        if (! EEH_File::exists($folder . 'index.php')) {
508
-            if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) {
507
+        if ( ! EEH_File::exists($folder.'index.php')) {
508
+            if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
509 509
                 return false;
510 510
             }
511 511
         }
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
      */
540 540
     public static function standardise_directory_separators($file_path)
541 541
     {
542
-        return str_replace(array( '\\', '/' ), '/', $file_path);
542
+        return str_replace(array('\\', '/'), '/', $file_path);
543 543
     }
544 544
 
545 545
 
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
      */
553 553
     public static function end_with_directory_separator($file_path)
554 554
     {
555
-        return rtrim($file_path, '/\\') . '/';
555
+        return rtrim($file_path, '/\\').'/';
556 556
     }
557 557
 
558 558
 
@@ -587,17 +587,17 @@  discard block
 block discarded – undo
587 587
         foreach ($folder_paths as $folder_path) {
588 588
             $folder_path = self::standardise_and_end_with_directory_separator($folder_path);
589 589
             // load WP_Filesystem and set file permissions
590
-            $files_in_folder = glob($folder_path . '*');
590
+            $files_in_folder = glob($folder_path.'*');
591 591
             $class_to_folder_path = array();
592 592
             if ($files_in_folder) {
593 593
                 foreach ($files_in_folder as $file_path) {
594 594
                     // only add files, not folders
595
-                    if (! is_dir($file_path)) {
595
+                    if ( ! is_dir($file_path)) {
596 596
                         if ($index_numerically) {
597 597
                             $class_to_folder_path[] = $file_path;
598 598
                         } else {
599 599
                             $classname = self::get_classname_from_filepath_with_standard_filename($file_path);
600
-                            $class_to_folder_path[ $classname ] = $file_path;
600
+                            $class_to_folder_path[$classname] = $file_path;
601 601
                         }
602 602
                     }
603 603
                 }
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
     public static function copy($source_file, $destination_file, $overwrite = false)
620 620
     {
621 621
         $full_source_path = EEH_File::standardise_directory_separators($source_file);
622
-        if (! EEH_File::exists($full_source_path)) {
622
+        if ( ! EEH_File::exists($full_source_path)) {
623 623
             if (defined('WP_DEBUG') && WP_DEBUG) {
624 624
                 $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
625 625
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
         $full_dest_path = EEH_File::standardise_directory_separators($destination_file);
632 632
         $folder = EEH_File::remove_filename_from_filepath($full_dest_path);
633 633
         EEH_File::ensure_folder_exists_and_is_writable($folder);
634
-        if (! EEH_File::verify_is_writable($folder, 'folder')) {
634
+        if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
635 635
             if (defined('WP_DEBUG') && WP_DEBUG) {
636 636
                 $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
637 637
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
         // load WP_Filesystem and set file permissions
644 644
         $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
645 645
         // write the file
646
-        if (! $wp_filesystem->copy(
646
+        if ( ! $wp_filesystem->copy(
647 647
             EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
648 648
             EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
649 649
             $overwrite
@@ -684,6 +684,6 @@  discard block
 block discarded – undo
684 684
     public static function convert_local_filepath_to_remote_filepath($local_filepath)
685 685
     {
686 686
         $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
687
-        return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath);
687
+        return str_replace(WP_CONTENT_DIR.'/', $wp_filesystem->wp_content_dir(), $local_filepath);
688 688
     }
689 689
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Autoloader.helper.php 2 patches
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -15,296 +15,296 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     *    instance of the EE_System object
20
-     *
21
-     * @var    $_instance
22
-     * @access    private
23
-     */
24
-    private static $_instance = null;
25
-
26
-    /**
27
-    *   $_autoloaders
28
-    *   @var array $_autoloaders
29
-    *   @access     private
30
-    */
31
-    private static $_autoloaders;
32
-
33
-    /**
34
-     * set to "paths" to display autoloader class => path mappings
35
-     * set to "times" to display autoloader loading times
36
-     * set to "all" to display both
37
-     *
38
-     * @var string $debug
39
-     * @access    private
40
-     */
41
-    public static $debug = false;
42
-
43
-
44
-    /**
45
-     *    class constructor
46
-     *
47
-     * @access    private
48
-     * @return \EEH_Autoloader
49
-     * @throws Exception
50
-     */
51
-    private function __construct()
52
-    {
53
-        if (self::$_autoloaders === null) {
54
-            self::$_autoloaders = array();
55
-            $this->_register_custom_autoloaders();
56
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
57
-        }
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @access public
64
-     * @return EEH_Autoloader
65
-     */
66
-    public static function instance()
67
-    {
68
-        // check if class object is instantiated
69
-        if (! self::$_instance instanceof EEH_Autoloader) {
70
-            self::$_instance = new self();
71
-        }
72
-        return self::$_instance;
73
-    }
74
-
75
-
76
-
77
-    /**
78
-     *    espresso_autoloader
79
-     *
80
-     * @access    public
81
-     * @param   $class_name
82
-     * @internal  param $className
83
-     * @internal  param string $class_name - simple class name ie: session
84
-     * @return  void
85
-     */
86
-    public static function espresso_autoloader($class_name)
87
-    {
88
-        if (isset(self::$_autoloaders[ $class_name ])) {
89
-            require_once(self::$_autoloaders[ $class_name ]);
90
-        }
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    register_autoloader
97
-     *
98
-     * @access    public
99
-     * @param array | string $class_paths - array of key => value pairings between class names and paths
100
-     * @param bool           $read_check  true if we need to check whether the file is readable or not.
101
-     * @param bool           $debug **deprecated**
102
-     * @throws \EE_Error
103
-     */
104
-    public static function register_autoloader($class_paths, $read_check = true, $debug = false)
105
-    {
106
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
107
-        foreach ($class_paths as $class => $path) {
108
-            // skip all files that are not PHP
109
-            if (substr($path, strlen($path) - 3) !== 'php') {
110
-                continue;
111
-            }
112
-            // don't give up! you gotta...
113
-            // get some class
114
-            if (empty($class)) {
115
-                throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
116
-            }
117
-            // one day you will find the path young grasshopper
118
-            if (empty($path)) {
119
-                throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
120
-            }
121
-            // is file readable ?
122
-            if ($read_check && ! is_readable($path)) {
123
-                throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
124
-            }
125
-            if (! isset(self::$_autoloaders[ $class ])) {
126
-                self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
127
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
128
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
129
-                }
130
-            }
131
-        }
132
-    }
133
-
134
-
135
-
136
-
137
-    /**
138
-     *  get_autoloaders
139
-     *
140
-     *  @access public
141
-     *  @return array
142
-     */
143
-    public static function get_autoloaders()
144
-    {
145
-        return self::$_autoloaders;
146
-    }
147
-
148
-
149
-    /**
150
-     *  register core, model and class 'autoloaders'
151
-     *
152
-     * @access private
153
-     * @return void
154
-     * @throws EE_Error
155
-     */
156
-    private function _register_custom_autoloaders()
157
-    {
158
-        EEH_Autoloader::$debug = '';
159
-        \EEH_Autoloader::register_helpers_autoloaders();
160
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
161
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
162
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
163
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
164
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
165
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
166
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
167
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
168
-            EEH_Debug_Tools::instance()->show_times();
169
-        }
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     *    register core, model and class 'autoloaders'
176
-     *
177
-     * @access public
178
-     */
179
-    public static function register_helpers_autoloaders()
180
-    {
181
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
182
-    }
183
-
184
-
185
-
186
-
187
-    /**
188
-     *  register core, model and class 'autoloaders'
189
-     *
190
-     *  @access public
191
-     *  @return void
192
-     */
193
-    public static function register_form_sections_autoloaders()
194
-    {
195
-        // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
196
-    }
197
-
198
-
199
-    /**
200
-     *  register core, model and class 'autoloaders'
201
-     *
202
-     * @access public
203
-     * @return void
204
-     * @throws EE_Error
205
-     */
206
-    public static function register_line_item_display_autoloaders()
207
-    {
208
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
209
-    }
210
-
211
-
212
-    /**
213
-     *  register core, model and class 'autoloaders'
214
-     *
215
-     * @access public
216
-     * @return void
217
-     * @throws EE_Error
218
-     */
219
-    public static function register_line_item_filter_autoloaders()
220
-    {
221
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
222
-    }
223
-
224
-
225
-    /**
226
-     *  register template part 'autoloaders'
227
-     *
228
-     * @access public
229
-     * @return void
230
-     * @throws EE_Error
231
-     */
232
-    public static function register_template_part_autoloaders()
233
-    {
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
235
-    }
236
-
237
-
238
-    /**
239
-     * @return void
240
-     * @throws EE_Error
241
-     */
242
-    public static function register_business_classes()
243
-    {
244
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * Assumes all the files in this folder have the normal naming scheme (namely that their classname
251
-     * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
252
-     * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
253
-     * Yes this has to scan the directory for files, but it only does it once -- not on EACH
254
-     * time the autoloader is used
255
-     *
256
-     * @param string $folder name, with or without trailing /, doesn't matter
257
-     * @param bool   $recursive
258
-     * @param bool   $debug  **deprecated**
259
-     * @throws \EE_Error
260
-     */
261
-    public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
262
-    {
263
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
264
-            EEH_Debug_Tools::instance()->start_timer(basename($folder));
265
-        }
266
-        // make sure last char is a /
267
-        $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : '';
268
-        $class_to_filepath_map = array();
269
-        $exclude = array( 'index' );
270
-        // get all the files in that folder that end in php
271
-        $filepaths = glob($folder.'*');
272
-
273
-        if (empty($filepaths)) {
274
-            return;
275
-        }
276
-
277
-        foreach ($filepaths as $filepath) {
278
-            if (substr($filepath, -4, 4) === '.php') {
279
-                $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
280
-                if (! in_array($class_name, $exclude)) {
281
-                    $class_to_filepath_map [ $class_name ] = $filepath;
282
-                }
283
-            } elseif ($recursive) {
284
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
285
-            }
286
-        }
287
-        // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
288
-        self::register_autoloader($class_to_filepath_map, false, $debug);
289
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
290
-            EEH_Debug_Tools::instance()->stop_timer(basename($folder));
291
-        }
292
-    }
293
-
294
-
295
-
296
-    /**
297
-     * add_alias
298
-     * register additional autoloader based on variation of the classname for an existing autoloader
299
-     *
300
-     * @access    public
301
-     * @param string $class_name - simple class name ie: EE_Session
302
-     * @param string $alias - variation on class name ie: EE_session, session, etc
303
-     */
304
-    public static function add_alias($class_name, $alias)
305
-    {
306
-        if (isset(self::$_autoloaders[ $class_name ])) {
307
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
308
-        }
309
-    }
18
+	/**
19
+	 *    instance of the EE_System object
20
+	 *
21
+	 * @var    $_instance
22
+	 * @access    private
23
+	 */
24
+	private static $_instance = null;
25
+
26
+	/**
27
+	 *   $_autoloaders
28
+	 *   @var array $_autoloaders
29
+	 *   @access     private
30
+	 */
31
+	private static $_autoloaders;
32
+
33
+	/**
34
+	 * set to "paths" to display autoloader class => path mappings
35
+	 * set to "times" to display autoloader loading times
36
+	 * set to "all" to display both
37
+	 *
38
+	 * @var string $debug
39
+	 * @access    private
40
+	 */
41
+	public static $debug = false;
42
+
43
+
44
+	/**
45
+	 *    class constructor
46
+	 *
47
+	 * @access    private
48
+	 * @return \EEH_Autoloader
49
+	 * @throws Exception
50
+	 */
51
+	private function __construct()
52
+	{
53
+		if (self::$_autoloaders === null) {
54
+			self::$_autoloaders = array();
55
+			$this->_register_custom_autoloaders();
56
+			spl_autoload_register(array( $this, 'espresso_autoloader' ));
57
+		}
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @access public
64
+	 * @return EEH_Autoloader
65
+	 */
66
+	public static function instance()
67
+	{
68
+		// check if class object is instantiated
69
+		if (! self::$_instance instanceof EEH_Autoloader) {
70
+			self::$_instance = new self();
71
+		}
72
+		return self::$_instance;
73
+	}
74
+
75
+
76
+
77
+	/**
78
+	 *    espresso_autoloader
79
+	 *
80
+	 * @access    public
81
+	 * @param   $class_name
82
+	 * @internal  param $className
83
+	 * @internal  param string $class_name - simple class name ie: session
84
+	 * @return  void
85
+	 */
86
+	public static function espresso_autoloader($class_name)
87
+	{
88
+		if (isset(self::$_autoloaders[ $class_name ])) {
89
+			require_once(self::$_autoloaders[ $class_name ]);
90
+		}
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    register_autoloader
97
+	 *
98
+	 * @access    public
99
+	 * @param array | string $class_paths - array of key => value pairings between class names and paths
100
+	 * @param bool           $read_check  true if we need to check whether the file is readable or not.
101
+	 * @param bool           $debug **deprecated**
102
+	 * @throws \EE_Error
103
+	 */
104
+	public static function register_autoloader($class_paths, $read_check = true, $debug = false)
105
+	{
106
+		$class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
107
+		foreach ($class_paths as $class => $path) {
108
+			// skip all files that are not PHP
109
+			if (substr($path, strlen($path) - 3) !== 'php') {
110
+				continue;
111
+			}
112
+			// don't give up! you gotta...
113
+			// get some class
114
+			if (empty($class)) {
115
+				throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
116
+			}
117
+			// one day you will find the path young grasshopper
118
+			if (empty($path)) {
119
+				throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
120
+			}
121
+			// is file readable ?
122
+			if ($read_check && ! is_readable($path)) {
123
+				throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
124
+			}
125
+			if (! isset(self::$_autoloaders[ $class ])) {
126
+				self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
127
+				if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
128
+					EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
129
+				}
130
+			}
131
+		}
132
+	}
133
+
134
+
135
+
136
+
137
+	/**
138
+	 *  get_autoloaders
139
+	 *
140
+	 *  @access public
141
+	 *  @return array
142
+	 */
143
+	public static function get_autoloaders()
144
+	{
145
+		return self::$_autoloaders;
146
+	}
147
+
148
+
149
+	/**
150
+	 *  register core, model and class 'autoloaders'
151
+	 *
152
+	 * @access private
153
+	 * @return void
154
+	 * @throws EE_Error
155
+	 */
156
+	private function _register_custom_autoloaders()
157
+	{
158
+		EEH_Autoloader::$debug = '';
159
+		\EEH_Autoloader::register_helpers_autoloaders();
160
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
161
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
162
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
163
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
164
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
165
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
166
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
167
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
168
+			EEH_Debug_Tools::instance()->show_times();
169
+		}
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 *    register core, model and class 'autoloaders'
176
+	 *
177
+	 * @access public
178
+	 */
179
+	public static function register_helpers_autoloaders()
180
+	{
181
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
182
+	}
183
+
184
+
185
+
186
+
187
+	/**
188
+	 *  register core, model and class 'autoloaders'
189
+	 *
190
+	 *  @access public
191
+	 *  @return void
192
+	 */
193
+	public static function register_form_sections_autoloaders()
194
+	{
195
+		// EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
196
+	}
197
+
198
+
199
+	/**
200
+	 *  register core, model and class 'autoloaders'
201
+	 *
202
+	 * @access public
203
+	 * @return void
204
+	 * @throws EE_Error
205
+	 */
206
+	public static function register_line_item_display_autoloaders()
207
+	{
208
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
209
+	}
210
+
211
+
212
+	/**
213
+	 *  register core, model and class 'autoloaders'
214
+	 *
215
+	 * @access public
216
+	 * @return void
217
+	 * @throws EE_Error
218
+	 */
219
+	public static function register_line_item_filter_autoloaders()
220
+	{
221
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
222
+	}
223
+
224
+
225
+	/**
226
+	 *  register template part 'autoloaders'
227
+	 *
228
+	 * @access public
229
+	 * @return void
230
+	 * @throws EE_Error
231
+	 */
232
+	public static function register_template_part_autoloaders()
233
+	{
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
235
+	}
236
+
237
+
238
+	/**
239
+	 * @return void
240
+	 * @throws EE_Error
241
+	 */
242
+	public static function register_business_classes()
243
+	{
244
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * Assumes all the files in this folder have the normal naming scheme (namely that their classname
251
+	 * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
252
+	 * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
253
+	 * Yes this has to scan the directory for files, but it only does it once -- not on EACH
254
+	 * time the autoloader is used
255
+	 *
256
+	 * @param string $folder name, with or without trailing /, doesn't matter
257
+	 * @param bool   $recursive
258
+	 * @param bool   $debug  **deprecated**
259
+	 * @throws \EE_Error
260
+	 */
261
+	public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
262
+	{
263
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
264
+			EEH_Debug_Tools::instance()->start_timer(basename($folder));
265
+		}
266
+		// make sure last char is a /
267
+		$folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : '';
268
+		$class_to_filepath_map = array();
269
+		$exclude = array( 'index' );
270
+		// get all the files in that folder that end in php
271
+		$filepaths = glob($folder.'*');
272
+
273
+		if (empty($filepaths)) {
274
+			return;
275
+		}
276
+
277
+		foreach ($filepaths as $filepath) {
278
+			if (substr($filepath, -4, 4) === '.php') {
279
+				$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
280
+				if (! in_array($class_name, $exclude)) {
281
+					$class_to_filepath_map [ $class_name ] = $filepath;
282
+				}
283
+			} elseif ($recursive) {
284
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
285
+			}
286
+		}
287
+		// we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
288
+		self::register_autoloader($class_to_filepath_map, false, $debug);
289
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
290
+			EEH_Debug_Tools::instance()->stop_timer(basename($folder));
291
+		}
292
+	}
293
+
294
+
295
+
296
+	/**
297
+	 * add_alias
298
+	 * register additional autoloader based on variation of the classname for an existing autoloader
299
+	 *
300
+	 * @access    public
301
+	 * @param string $class_name - simple class name ie: EE_Session
302
+	 * @param string $alias - variation on class name ie: EE_session, session, etc
303
+	 */
304
+	public static function add_alias($class_name, $alias)
305
+	{
306
+		if (isset(self::$_autoloaders[ $class_name ])) {
307
+			self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
308
+		}
309
+	}
310 310
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         if (self::$_autoloaders === null) {
54 54
             self::$_autoloaders = array();
55 55
             $this->_register_custom_autoloaders();
56
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
56
+            spl_autoload_register(array($this, 'espresso_autoloader'));
57 57
         }
58 58
     }
59 59
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     public static function instance()
67 67
     {
68 68
         // check if class object is instantiated
69
-        if (! self::$_instance instanceof EEH_Autoloader) {
69
+        if ( ! self::$_instance instanceof EEH_Autoloader) {
70 70
             self::$_instance = new self();
71 71
         }
72 72
         return self::$_instance;
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public static function espresso_autoloader($class_name)
87 87
     {
88
-        if (isset(self::$_autoloaders[ $class_name ])) {
89
-            require_once(self::$_autoloaders[ $class_name ]);
88
+        if (isset(self::$_autoloaders[$class_name])) {
89
+            require_once(self::$_autoloaders[$class_name]);
90 90
         }
91 91
     }
92 92
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public static function register_autoloader($class_paths, $read_check = true, $debug = false)
105 105
     {
106
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
106
+        $class_paths = is_array($class_paths) ? $class_paths : array($class_paths);
107 107
         foreach ($class_paths as $class => $path) {
108 108
             // skip all files that are not PHP
109 109
             if (substr($path, strlen($path) - 3) !== 'php') {
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
             if ($read_check && ! is_readable($path)) {
123 123
                 throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
124 124
             }
125
-            if (! isset(self::$_autoloaders[ $class ])) {
126
-                self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
127
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
128
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
125
+            if ( ! isset(self::$_autoloaders[$class])) {
126
+                self::$_autoloaders[$class] = str_replace(array('/', '\\'), '/', $path);
127
+                if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
128
+                    EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__);
129 129
                 }
130 130
             }
131 131
         }
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
     {
158 158
         EEH_Autoloader::$debug = '';
159 159
         \EEH_Autoloader::register_helpers_autoloaders();
160
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
160
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces');
161 161
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
162 162
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
163 163
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
164 164
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
165 165
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
166
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
166
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages');
167 167
         if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
168 168
             EEH_Debug_Tools::instance()->show_times();
169 169
         }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
     public static function register_line_item_display_autoloaders()
207 207
     {
208
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
208
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true);
209 209
     }
210 210
 
211 211
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      */
219 219
     public static function register_line_item_filter_autoloaders()
220 220
     {
221
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
221
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true);
222 222
     }
223 223
 
224 224
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      */
232 232
     public static function register_template_part_autoloaders()
233 233
     {
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
234
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true);
235 235
     }
236 236
 
237 237
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      */
242 242
     public static function register_business_classes()
243 243
     {
244
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
244
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business');
245 245
     }
246 246
 
247 247
 
@@ -264,9 +264,9 @@  discard block
 block discarded – undo
264 264
             EEH_Debug_Tools::instance()->start_timer(basename($folder));
265 265
         }
266 266
         // make sure last char is a /
267
-        $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : '';
267
+        $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : '';
268 268
         $class_to_filepath_map = array();
269
-        $exclude = array( 'index' );
269
+        $exclude = array('index');
270 270
         // get all the files in that folder that end in php
271 271
         $filepaths = glob($folder.'*');
272 272
 
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
         foreach ($filepaths as $filepath) {
278 278
             if (substr($filepath, -4, 4) === '.php') {
279 279
                 $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
280
-                if (! in_array($class_name, $exclude)) {
281
-                    $class_to_filepath_map [ $class_name ] = $filepath;
280
+                if ( ! in_array($class_name, $exclude)) {
281
+                    $class_to_filepath_map [$class_name] = $filepath;
282 282
                 }
283 283
             } elseif ($recursive) {
284 284
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
      */
304 304
     public static function add_alias($class_name, $alias)
305 305
     {
306
-        if (isset(self::$_autoloaders[ $class_name ])) {
307
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
306
+        if (isset(self::$_autoloaders[$class_name])) {
307
+            self::$_autoloaders[$alias] = self::$_autoloaders[$class_name];
308 308
         }
309 309
     }
310 310
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 2 patches
Indentation   +1576 added lines, -1576 removed lines patch added patch discarded remove patch
@@ -15,232 +15,232 @@  discard block
 block discarded – undo
15 15
 class EEH_Activation implements ResettableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * constant used to indicate a cron task is no longer in use
20
-     */
21
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
22
-
23
-    /**
24
-     * WP_User->ID
25
-     *
26
-     * @var int
27
-     */
28
-    private static $_default_creator_id;
29
-
30
-    /**
31
-     * indicates whether or not we've already verified core's default data during this request,
32
-     * because after migrations are done, any addons activated while in maintenance mode
33
-     * will want to setup their own default data, and they might hook into core's default data
34
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
35
-     * This prevents doing that for EVERY single addon.
36
-     *
37
-     * @var boolean
38
-     */
39
-    protected static $_initialized_db_content_already_in_this_request = false;
40
-
41
-    /**
42
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
43
-     */
44
-    private static $table_analysis;
45
-
46
-    /**
47
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
48
-     */
49
-    private static $table_manager;
50
-
51
-
52
-    /**
53
-     * @return \EventEspresso\core\services\database\TableAnalysis
54
-     */
55
-    public static function getTableAnalysis()
56
-    {
57
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
58
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
59
-        }
60
-        return self::$table_analysis;
61
-    }
62
-
63
-
64
-    /**
65
-     * @return \EventEspresso\core\services\database\TableManager
66
-     */
67
-    public static function getTableManager()
68
-    {
69
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
70
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
71
-        }
72
-        return self::$table_manager;
73
-    }
74
-
75
-
76
-    /**
77
-     *    _ensure_table_name_has_prefix
78
-     *
79
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
80
-     * @access     public
81
-     * @static
82
-     * @param $table_name
83
-     * @return string
84
-     */
85
-    public static function ensure_table_name_has_prefix($table_name)
86
-    {
87
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
88
-    }
89
-
90
-
91
-    /**
92
-     *    system_initialization
93
-     *    ensures the EE configuration settings are loaded with at least default options set
94
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
95
-     *
96
-     * @access public
97
-     * @static
98
-     * @return void
99
-     */
100
-    public static function system_initialization()
101
-    {
102
-        EEH_Activation::reset_and_update_config();
103
-        // which is fired BEFORE activation of plugin anyways
104
-        EEH_Activation::verify_default_pages_exist();
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets the database schema and creates folders. This should
110
-     * be called on plugin activation and reactivation
111
-     *
112
-     * @return boolean success, whether the database and folders are setup properly
113
-     * @throws \EE_Error
114
-     */
115
-    public static function initialize_db_and_folders()
116
-    {
117
-        return EEH_Activation::create_database_tables();
118
-    }
119
-
120
-
121
-    /**
122
-     * assuming we have an up-to-date database schema, this will populate it
123
-     * with default and initial data. This should be called
124
-     * upon activation of a new plugin, reactivation, and at the end
125
-     * of running migration scripts
126
-     *
127
-     * @throws \EE_Error
128
-     */
129
-    public static function initialize_db_content()
130
-    {
131
-        // let's avoid doing all this logic repeatedly, especially when addons are requesting it
132
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
133
-            return;
134
-        }
135
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
136
-
137
-        EEH_Activation::initialize_system_questions();
138
-        EEH_Activation::insert_default_status_codes();
139
-        EEH_Activation::generate_default_message_templates();
140
-        EEH_Activation::create_no_ticket_prices_array();
141
-
142
-        EEH_Activation::validate_messages_system();
143
-        EEH_Activation::insert_default_payment_methods();
144
-        // in case we've
145
-        EEH_Activation::remove_cron_tasks();
146
-        EEH_Activation::create_cron_tasks();
147
-        // remove all TXN locks since that is being done via extra meta now
148
-        delete_option('ee_locked_transactions');
149
-        // also, check for CAF default db content
150
-        do_action('AHEE__EEH_Activation__initialize_db_content');
151
-        // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
152
-        // which users really won't care about on initial activation
153
-        EE_Error::overwrite_success();
154
-    }
155
-
156
-
157
-    /**
158
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
159
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
160
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
161
-     * (null)
162
-     *
163
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
164
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
165
-     * @return array
166
-     * @throws \EE_Error
167
-     */
168
-    public static function get_cron_tasks($which_to_include)
169
-    {
170
-        $cron_tasks = apply_filters(
171
-            'FHEE__EEH_Activation__get_cron_tasks',
172
-            array(
173
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
174
-            //              'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
175
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
176
-                // 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
177
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
178
-            )
179
-        );
180
-        if ($which_to_include === 'old') {
181
-            $cron_tasks = array_filter(
182
-                $cron_tasks,
183
-                function ($value) {
184
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
185
-                }
186
-            );
187
-        } elseif ($which_to_include === 'current') {
188
-            $cron_tasks = array_filter($cron_tasks);
189
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
190
-            throw new EE_Error(
191
-                sprintf(
192
-                    __(
193
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
194
-                        'event_espresso'
195
-                    ),
196
-                    $which_to_include
197
-                )
198
-            );
199
-        }
200
-        return $cron_tasks;
201
-    }
202
-
203
-
204
-    /**
205
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
206
-     *
207
-     * @throws \EE_Error
208
-     */
209
-    public static function create_cron_tasks()
210
-    {
211
-
212
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
213
-            if (! wp_next_scheduled($hook_name)) {
214
-                /**
215
-                 * This allows client code to define the initial start timestamp for this schedule.
216
-                 */
217
-                if (is_array($frequency)
218
-                    && count($frequency) === 2
219
-                    && isset($frequency[0], $frequency[1])
220
-                ) {
221
-                    $start_timestamp = $frequency[0];
222
-                    $frequency = $frequency[1];
223
-                } else {
224
-                    $start_timestamp = time();
225
-                }
226
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
227
-            }
228
-        }
229
-    }
230
-
231
-
232
-    /**
233
-     * Remove the currently-existing and now-removed cron tasks.
234
-     *
235
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
236
-     * @throws \EE_Error
237
-     */
238
-    public static function remove_cron_tasks($remove_all = true)
239
-    {
240
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
241
-        $crons                = _get_cron_array();
242
-        $crons                = is_array($crons) ? $crons : array();
243
-        /* reminder of what $crons look like:
18
+	/**
19
+	 * constant used to indicate a cron task is no longer in use
20
+	 */
21
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
22
+
23
+	/**
24
+	 * WP_User->ID
25
+	 *
26
+	 * @var int
27
+	 */
28
+	private static $_default_creator_id;
29
+
30
+	/**
31
+	 * indicates whether or not we've already verified core's default data during this request,
32
+	 * because after migrations are done, any addons activated while in maintenance mode
33
+	 * will want to setup their own default data, and they might hook into core's default data
34
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
35
+	 * This prevents doing that for EVERY single addon.
36
+	 *
37
+	 * @var boolean
38
+	 */
39
+	protected static $_initialized_db_content_already_in_this_request = false;
40
+
41
+	/**
42
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
43
+	 */
44
+	private static $table_analysis;
45
+
46
+	/**
47
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
48
+	 */
49
+	private static $table_manager;
50
+
51
+
52
+	/**
53
+	 * @return \EventEspresso\core\services\database\TableAnalysis
54
+	 */
55
+	public static function getTableAnalysis()
56
+	{
57
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
58
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
59
+		}
60
+		return self::$table_analysis;
61
+	}
62
+
63
+
64
+	/**
65
+	 * @return \EventEspresso\core\services\database\TableManager
66
+	 */
67
+	public static function getTableManager()
68
+	{
69
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
70
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
71
+		}
72
+		return self::$table_manager;
73
+	}
74
+
75
+
76
+	/**
77
+	 *    _ensure_table_name_has_prefix
78
+	 *
79
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
80
+	 * @access     public
81
+	 * @static
82
+	 * @param $table_name
83
+	 * @return string
84
+	 */
85
+	public static function ensure_table_name_has_prefix($table_name)
86
+	{
87
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
88
+	}
89
+
90
+
91
+	/**
92
+	 *    system_initialization
93
+	 *    ensures the EE configuration settings are loaded with at least default options set
94
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
95
+	 *
96
+	 * @access public
97
+	 * @static
98
+	 * @return void
99
+	 */
100
+	public static function system_initialization()
101
+	{
102
+		EEH_Activation::reset_and_update_config();
103
+		// which is fired BEFORE activation of plugin anyways
104
+		EEH_Activation::verify_default_pages_exist();
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets the database schema and creates folders. This should
110
+	 * be called on plugin activation and reactivation
111
+	 *
112
+	 * @return boolean success, whether the database and folders are setup properly
113
+	 * @throws \EE_Error
114
+	 */
115
+	public static function initialize_db_and_folders()
116
+	{
117
+		return EEH_Activation::create_database_tables();
118
+	}
119
+
120
+
121
+	/**
122
+	 * assuming we have an up-to-date database schema, this will populate it
123
+	 * with default and initial data. This should be called
124
+	 * upon activation of a new plugin, reactivation, and at the end
125
+	 * of running migration scripts
126
+	 *
127
+	 * @throws \EE_Error
128
+	 */
129
+	public static function initialize_db_content()
130
+	{
131
+		// let's avoid doing all this logic repeatedly, especially when addons are requesting it
132
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
133
+			return;
134
+		}
135
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
136
+
137
+		EEH_Activation::initialize_system_questions();
138
+		EEH_Activation::insert_default_status_codes();
139
+		EEH_Activation::generate_default_message_templates();
140
+		EEH_Activation::create_no_ticket_prices_array();
141
+
142
+		EEH_Activation::validate_messages_system();
143
+		EEH_Activation::insert_default_payment_methods();
144
+		// in case we've
145
+		EEH_Activation::remove_cron_tasks();
146
+		EEH_Activation::create_cron_tasks();
147
+		// remove all TXN locks since that is being done via extra meta now
148
+		delete_option('ee_locked_transactions');
149
+		// also, check for CAF default db content
150
+		do_action('AHEE__EEH_Activation__initialize_db_content');
151
+		// also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
152
+		// which users really won't care about on initial activation
153
+		EE_Error::overwrite_success();
154
+	}
155
+
156
+
157
+	/**
158
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
159
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
160
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
161
+	 * (null)
162
+	 *
163
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
164
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
165
+	 * @return array
166
+	 * @throws \EE_Error
167
+	 */
168
+	public static function get_cron_tasks($which_to_include)
169
+	{
170
+		$cron_tasks = apply_filters(
171
+			'FHEE__EEH_Activation__get_cron_tasks',
172
+			array(
173
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
174
+			//              'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
175
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
176
+				// 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
177
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
178
+			)
179
+		);
180
+		if ($which_to_include === 'old') {
181
+			$cron_tasks = array_filter(
182
+				$cron_tasks,
183
+				function ($value) {
184
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
185
+				}
186
+			);
187
+		} elseif ($which_to_include === 'current') {
188
+			$cron_tasks = array_filter($cron_tasks);
189
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
190
+			throw new EE_Error(
191
+				sprintf(
192
+					__(
193
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
194
+						'event_espresso'
195
+					),
196
+					$which_to_include
197
+				)
198
+			);
199
+		}
200
+		return $cron_tasks;
201
+	}
202
+
203
+
204
+	/**
205
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
206
+	 *
207
+	 * @throws \EE_Error
208
+	 */
209
+	public static function create_cron_tasks()
210
+	{
211
+
212
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
213
+			if (! wp_next_scheduled($hook_name)) {
214
+				/**
215
+				 * This allows client code to define the initial start timestamp for this schedule.
216
+				 */
217
+				if (is_array($frequency)
218
+					&& count($frequency) === 2
219
+					&& isset($frequency[0], $frequency[1])
220
+				) {
221
+					$start_timestamp = $frequency[0];
222
+					$frequency = $frequency[1];
223
+				} else {
224
+					$start_timestamp = time();
225
+				}
226
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
227
+			}
228
+		}
229
+	}
230
+
231
+
232
+	/**
233
+	 * Remove the currently-existing and now-removed cron tasks.
234
+	 *
235
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
236
+	 * @throws \EE_Error
237
+	 */
238
+	public static function remove_cron_tasks($remove_all = true)
239
+	{
240
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
241
+		$crons                = _get_cron_array();
242
+		$crons                = is_array($crons) ? $crons : array();
243
+		/* reminder of what $crons look like:
244 244
          * Top-level keys are timestamps, and their values are arrays.
245 245
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
246 246
          * and their values are arrays.
@@ -257,909 +257,909 @@  discard block
 block discarded – undo
257 257
          *                  ...
258 258
          *      ...
259 259
          */
260
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
261
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
262
-            if (is_array($hooks_to_fire_at_time)) {
263
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
264
-                    if (isset($ee_cron_tasks_to_remove[ $hook_name ])
265
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
266
-                    ) {
267
-                        unset($crons[ $timestamp ][ $hook_name ]);
268
-                    }
269
-                }
270
-                // also take care of any empty cron timestamps.
271
-                if (empty($hooks_to_fire_at_time)) {
272
-                    unset($crons[ $timestamp ]);
273
-                }
274
-            }
275
-        }
276
-        _set_cron_array($crons);
277
-    }
278
-
279
-
280
-    /**
281
-     *    CPT_initialization
282
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
283
-     *
284
-     * @access public
285
-     * @static
286
-     * @return void
287
-     */
288
-    public static function CPT_initialization()
289
-    {
290
-        // register Custom Post Types
291
-        EE_Registry::instance()->load_core('Register_CPTs');
292
-        flush_rewrite_rules();
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     *    reset_and_update_config
299
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
300
-     * If there is old calendar config data saved, then it will get converted on activation.
301
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
302
-     *
303
-     * @access public
304
-     * @static
305
-     * @return void
306
-     */
307
-    public static function reset_and_update_config()
308
-    {
309
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
310
-        add_filter(
311
-            'FHEE__EE_Config___load_core_config__config_settings',
312
-            array('EEH_Activation', 'migrate_old_config_data'),
313
-            10,
314
-            3
315
-        );
316
-        // EE_Config::reset();
317
-        if (! EE_Config::logging_enabled()) {
318
-            delete_option(EE_Config::LOG_NAME);
319
-        }
320
-    }
321
-
322
-
323
-    /**
324
-     *    load_calendar_config
325
-     *
326
-     * @access    public
327
-     * @return    void
328
-     */
329
-    public static function load_calendar_config()
330
-    {
331
-        // grab array of all plugin folders and loop thru it
332
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
333
-        if (empty($plugins)) {
334
-            return;
335
-        }
336
-        foreach ($plugins as $plugin_path) {
337
-            // grab plugin folder name from path
338
-            $plugin = basename($plugin_path);
339
-            // drill down to Espresso plugins
340
-            // then to calendar related plugins
341
-            if (strpos($plugin, 'espresso') !== false
342
-                || strpos($plugin, 'Espresso') !== false
343
-                || strpos($plugin, 'ee4') !== false
344
-                || strpos($plugin, 'EE4') !== false
345
-                || strpos($plugin, 'calendar') !== false
346
-            ) {
347
-                // this is what we are looking for
348
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
349
-                // does it exist in this folder ?
350
-                if (is_readable($calendar_config)) {
351
-                    // YEAH! let's load it
352
-                    require_once($calendar_config);
353
-                }
354
-            }
355
-        }
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     *    _migrate_old_config_data
362
-     *
363
-     * @access    public
364
-     * @param array|stdClass $settings
365
-     * @param string         $config
366
-     * @param \EE_Config     $EE_Config
367
-     * @return \stdClass
368
-     */
369
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
370
-    {
371
-        $convert_from_array = array('addons');
372
-        // in case old settings were saved as an array
373
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
374
-            // convert existing settings to an object
375
-            $config_array = $settings;
376
-            $settings = new stdClass();
377
-            foreach ($config_array as $key => $value) {
378
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
379
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
380
-                } else {
381
-                    $settings->{$key} = $value;
382
-                }
383
-            }
384
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
385
-        }
386
-        return $settings;
387
-    }
388
-
389
-
390
-    /**
391
-     * deactivate_event_espresso
392
-     *
393
-     * @access public
394
-     * @static
395
-     * @return void
396
-     */
397
-    public static function deactivate_event_espresso()
398
-    {
399
-        // check permissions
400
-        if (current_user_can('activate_plugins')) {
401
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
402
-        }
403
-    }
404
-
405
-
406
-
407
-    /**
408
-     * verify_default_pages_exist
409
-     *
410
-     * @access public
411
-     * @static
412
-     * @return void
413
-     * @throws InvalidDataTypeException
414
-     */
415
-    public static function verify_default_pages_exist()
416
-    {
417
-        $critical_page_problem = false;
418
-        $critical_pages = array(
419
-            array(
420
-                'id'   => 'reg_page_id',
421
-                'name' => __('Registration Checkout', 'event_espresso'),
422
-                'post' => null,
423
-                'code' => 'ESPRESSO_CHECKOUT',
424
-            ),
425
-            array(
426
-                'id'   => 'txn_page_id',
427
-                'name' => __('Transactions', 'event_espresso'),
428
-                'post' => null,
429
-                'code' => 'ESPRESSO_TXN_PAGE',
430
-            ),
431
-            array(
432
-                'id'   => 'thank_you_page_id',
433
-                'name' => __('Thank You', 'event_espresso'),
434
-                'post' => null,
435
-                'code' => 'ESPRESSO_THANK_YOU',
436
-            ),
437
-            array(
438
-                'id'   => 'cancel_page_id',
439
-                'name' => __('Registration Cancelled', 'event_espresso'),
440
-                'post' => null,
441
-                'code' => 'ESPRESSO_CANCELLED',
442
-            ),
443
-        );
444
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
445
-        foreach ($critical_pages as $critical_page) {
446
-            // is critical page ID set in config ?
447
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
448
-                // attempt to find post by ID
449
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
450
-            }
451
-            // no dice?
452
-            if ($critical_page['post'] === null) {
453
-                // attempt to find post by title
454
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
455
-                // still nothing?
456
-                if ($critical_page['post'] === null) {
457
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
458
-                    // REALLY? Still nothing ??!?!?
459
-                    if ($critical_page['post'] === null) {
460
-                        $msg = __(
461
-                            'The Event Espresso critical page configuration settings could not be updated.',
462
-                            'event_espresso'
463
-                        );
464
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
465
-                        break;
466
-                    }
467
-                }
468
-            }
469
-            // check that Post ID matches critical page ID in config
470
-            if (isset($critical_page['post']->ID)
471
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
472
-            ) {
473
-                // update Config with post ID
474
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
475
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
476
-                    $msg = __(
477
-                        'The Event Espresso critical page configuration settings could not be updated.',
478
-                        'event_espresso'
479
-                    );
480
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
481
-                }
482
-            }
483
-            $critical_page_problem =
484
-                ! isset($critical_page['post']->post_status)
485
-                || $critical_page['post']->post_status !== 'publish'
486
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
487
-                    ? true
488
-                    : $critical_page_problem;
489
-        }
490
-        if ($critical_page_problem) {
491
-            new PersistentAdminNotice(
492
-                'critical_page_problem',
493
-                sprintf(
494
-                    esc_html__(
495
-                        'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
496
-                        'event_espresso'
497
-                    ),
498
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
499
-                    . __('Event Espresso Critical Pages Settings', 'event_espresso')
500
-                    . '</a>'
501
-                )
502
-            );
503
-        }
504
-        if (EE_Error::has_notices()) {
505
-            EE_Error::get_notices(false, true, true);
506
-        }
507
-    }
508
-
509
-
510
-
511
-    /**
512
-     * Returns the first post which uses the specified shortcode
513
-     *
514
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
515
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
516
-     *                             "[ESPRESSO_THANK_YOU"
517
-     *                             (we don't search for the closing shortcode bracket because they might have added
518
-     *                             parameter to the shortcode
519
-     * @return WP_Post or NULl
520
-     */
521
-    public static function get_page_by_ee_shortcode($ee_shortcode)
522
-    {
523
-        global $wpdb;
524
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
525
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
526
-        if ($post_id) {
527
-            return get_post($post_id);
528
-        } else {
529
-            return null;
530
-        }
531
-    }
532
-
533
-
534
-    /**
535
-     *    This function generates a post for critical espresso pages
536
-     *
537
-     * @access public
538
-     * @static
539
-     * @param array $critical_page
540
-     * @return array
541
-     */
542
-    public static function create_critical_page($critical_page)
543
-    {
544
-
545
-        $post_args = array(
546
-            'post_title'     => $critical_page['name'],
547
-            'post_status'    => 'publish',
548
-            'post_type'      => 'page',
549
-            'comment_status' => 'closed',
550
-            'post_content'   => '[' . $critical_page['code'] . ']',
551
-        );
552
-
553
-        $post_id = wp_insert_post($post_args);
554
-        if (! $post_id) {
555
-            $msg = sprintf(
556
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
557
-                $critical_page['name']
558
-            );
559
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
560
-            return $critical_page;
561
-        }
562
-        // get newly created post's details
563
-        if (! $critical_page['post'] = get_post($post_id)) {
564
-            $msg = sprintf(
565
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
566
-                $critical_page['name']
567
-            );
568
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
569
-        }
570
-
571
-        return $critical_page;
572
-    }
573
-
574
-
575
-
576
-
577
-    /**
578
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
579
-     * The role being used to check is filterable.
580
-     *
581
-     * @since  4.6.0
582
-     * @global WPDB $wpdb
583
-     * @return mixed null|int WP_user ID or NULL
584
-     */
585
-    public static function get_default_creator_id()
586
-    {
587
-        global $wpdb;
588
-        if (! empty(self::$_default_creator_id)) {
589
-            return self::$_default_creator_id;
590
-        }/**/
591
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
592
-        // 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.
593
-        $pre_filtered_id = apply_filters(
594
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
595
-            false,
596
-            $role_to_check
597
-        );
598
-        if ($pre_filtered_id !== false) {
599
-            return (int) $pre_filtered_id;
600
-        }
601
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
602
-        $query = $wpdb->prepare(
603
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
604
-            '%' . $role_to_check . '%'
605
-        );
606
-        $user_id = $wpdb->get_var($query);
607
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
608
-        if ($user_id && (int) $user_id) {
609
-            self::$_default_creator_id = (int) $user_id;
610
-            return self::$_default_creator_id;
611
-        } else {
612
-            return null;
613
-        }
614
-    }
615
-
616
-
617
-
618
-    /**
619
-     * used by EE and EE addons during plugin activation to create tables.
620
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
621
-     * but includes extra logic regarding activations.
622
-     *
623
-     * @access public
624
-     * @static
625
-     * @param string  $table_name              without the $wpdb->prefix
626
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
627
-     *                                         table query)
628
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
629
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
630
-     *                                         and new once this function is done (ie, you really do want to CREATE a
631
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
632
-     *                                         you just want to verify the table exists and matches this definition
633
-     *                                         (and if it HAS data in it you want to leave it be)
634
-     * @return void
635
-     * @throws EE_Error if there are database errors
636
-     */
637
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
638
-    {
639
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
640
-            return;
641
-        }
642
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
643
-        if (! function_exists('dbDelta')) {
644
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
645
-        }
646
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
647
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
648
-        // do we need to first delete an existing version of this table ?
649
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
650
-            // ok, delete the table... but ONLY if it's empty
651
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
652
-            // table is NOT empty, are you SURE you want to delete this table ???
653
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
654
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
655
-            } elseif (! $deleted_safely) {
656
-                // so we should be more cautious rather than just dropping tables so easily
657
-                error_log(
658
-                    sprintf(
659
-                        __(
660
-                            '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.',
661
-                            'event_espresso'
662
-                        ),
663
-                        $wp_table_name,
664
-                        '<br/>',
665
-                        'espresso_db_update'
666
-                    )
667
-                );
668
-            }
669
-        }
670
-        $engine = str_replace('ENGINE=', '', $engine);
671
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
672
-    }
673
-
674
-
675
-
676
-    /**
677
-     *    add_column_if_it_doesn't_exist
678
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
679
-     *
680
-     * @access     public
681
-     * @static
682
-     * @deprecated instead use TableManager::addColumn()
683
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
684
-     * @param string $column_name
685
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
686
-     *                            'VARCHAR(10)'
687
-     * @return bool|int
688
-     */
689
-    public static function add_column_if_it_doesnt_exist(
690
-        $table_name,
691
-        $column_name,
692
-        $column_info = 'INT UNSIGNED NOT NULL'
693
-    ) {
694
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
695
-    }
696
-
697
-
698
-    /**
699
-     * get_fields_on_table
700
-     * Gets all the fields on the database table.
701
-     *
702
-     * @access     public
703
-     * @deprecated instead use TableManager::getTableColumns()
704
-     * @static
705
-     * @param string $table_name , without prefixed $wpdb->prefix
706
-     * @return array of database column names
707
-     */
708
-    public static function get_fields_on_table($table_name = null)
709
-    {
710
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
711
-    }
712
-
713
-
714
-    /**
715
-     * db_table_is_empty
716
-     *
717
-     * @access     public\
718
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
719
-     * @static
720
-     * @param string $table_name
721
-     * @return bool
722
-     */
723
-    public static function db_table_is_empty($table_name)
724
-    {
725
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
726
-    }
727
-
728
-
729
-    /**
730
-     * delete_db_table_if_empty
731
-     *
732
-     * @access public
733
-     * @static
734
-     * @param string $table_name
735
-     * @return bool | int
736
-     */
737
-    public static function delete_db_table_if_empty($table_name)
738
-    {
739
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
740
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
741
-        }
742
-        return false;
743
-    }
744
-
745
-
746
-    /**
747
-     * delete_unused_db_table
748
-     *
749
-     * @access     public
750
-     * @static
751
-     * @deprecated instead use TableManager::dropTable()
752
-     * @param string $table_name
753
-     * @return bool | int
754
-     */
755
-    public static function delete_unused_db_table($table_name)
756
-    {
757
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
758
-    }
759
-
760
-
761
-    /**
762
-     * drop_index
763
-     *
764
-     * @access     public
765
-     * @static
766
-     * @deprecated instead use TableManager::dropIndex()
767
-     * @param string $table_name
768
-     * @param string $index_name
769
-     * @return bool | int
770
-     */
771
-    public static function drop_index($table_name, $index_name)
772
-    {
773
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
774
-    }
775
-
776
-
777
-
778
-    /**
779
-     * create_database_tables
780
-     *
781
-     * @access public
782
-     * @static
783
-     * @throws EE_Error
784
-     * @return boolean success (whether database is setup properly or not)
785
-     */
786
-    public static function create_database_tables()
787
-    {
788
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
789
-        // find the migration script that sets the database to be compatible with the code
790
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
791
-        if ($dms_name) {
792
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
793
-            $current_data_migration_script->set_migrating(false);
794
-            $current_data_migration_script->schema_changes_before_migration();
795
-            $current_data_migration_script->schema_changes_after_migration();
796
-            if ($current_data_migration_script->get_errors()) {
797
-                if (WP_DEBUG) {
798
-                    foreach ($current_data_migration_script->get_errors() as $error) {
799
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
800
-                    }
801
-                } else {
802
-                    EE_Error::add_error(
803
-                        __(
804
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
260
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
261
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
262
+			if (is_array($hooks_to_fire_at_time)) {
263
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
264
+					if (isset($ee_cron_tasks_to_remove[ $hook_name ])
265
+						&& is_array($ee_cron_tasks_to_remove[ $hook_name ])
266
+					) {
267
+						unset($crons[ $timestamp ][ $hook_name ]);
268
+					}
269
+				}
270
+				// also take care of any empty cron timestamps.
271
+				if (empty($hooks_to_fire_at_time)) {
272
+					unset($crons[ $timestamp ]);
273
+				}
274
+			}
275
+		}
276
+		_set_cron_array($crons);
277
+	}
278
+
279
+
280
+	/**
281
+	 *    CPT_initialization
282
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
283
+	 *
284
+	 * @access public
285
+	 * @static
286
+	 * @return void
287
+	 */
288
+	public static function CPT_initialization()
289
+	{
290
+		// register Custom Post Types
291
+		EE_Registry::instance()->load_core('Register_CPTs');
292
+		flush_rewrite_rules();
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 *    reset_and_update_config
299
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
300
+	 * If there is old calendar config data saved, then it will get converted on activation.
301
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
302
+	 *
303
+	 * @access public
304
+	 * @static
305
+	 * @return void
306
+	 */
307
+	public static function reset_and_update_config()
308
+	{
309
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
310
+		add_filter(
311
+			'FHEE__EE_Config___load_core_config__config_settings',
312
+			array('EEH_Activation', 'migrate_old_config_data'),
313
+			10,
314
+			3
315
+		);
316
+		// EE_Config::reset();
317
+		if (! EE_Config::logging_enabled()) {
318
+			delete_option(EE_Config::LOG_NAME);
319
+		}
320
+	}
321
+
322
+
323
+	/**
324
+	 *    load_calendar_config
325
+	 *
326
+	 * @access    public
327
+	 * @return    void
328
+	 */
329
+	public static function load_calendar_config()
330
+	{
331
+		// grab array of all plugin folders and loop thru it
332
+		$plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
333
+		if (empty($plugins)) {
334
+			return;
335
+		}
336
+		foreach ($plugins as $plugin_path) {
337
+			// grab plugin folder name from path
338
+			$plugin = basename($plugin_path);
339
+			// drill down to Espresso plugins
340
+			// then to calendar related plugins
341
+			if (strpos($plugin, 'espresso') !== false
342
+				|| strpos($plugin, 'Espresso') !== false
343
+				|| strpos($plugin, 'ee4') !== false
344
+				|| strpos($plugin, 'EE4') !== false
345
+				|| strpos($plugin, 'calendar') !== false
346
+			) {
347
+				// this is what we are looking for
348
+				$calendar_config = $plugin_path . '/EE_Calendar_Config.php';
349
+				// does it exist in this folder ?
350
+				if (is_readable($calendar_config)) {
351
+					// YEAH! let's load it
352
+					require_once($calendar_config);
353
+				}
354
+			}
355
+		}
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 *    _migrate_old_config_data
362
+	 *
363
+	 * @access    public
364
+	 * @param array|stdClass $settings
365
+	 * @param string         $config
366
+	 * @param \EE_Config     $EE_Config
367
+	 * @return \stdClass
368
+	 */
369
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
370
+	{
371
+		$convert_from_array = array('addons');
372
+		// in case old settings were saved as an array
373
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
374
+			// convert existing settings to an object
375
+			$config_array = $settings;
376
+			$settings = new stdClass();
377
+			foreach ($config_array as $key => $value) {
378
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
379
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
380
+				} else {
381
+					$settings->{$key} = $value;
382
+				}
383
+			}
384
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
385
+		}
386
+		return $settings;
387
+	}
388
+
389
+
390
+	/**
391
+	 * deactivate_event_espresso
392
+	 *
393
+	 * @access public
394
+	 * @static
395
+	 * @return void
396
+	 */
397
+	public static function deactivate_event_espresso()
398
+	{
399
+		// check permissions
400
+		if (current_user_can('activate_plugins')) {
401
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
402
+		}
403
+	}
404
+
405
+
406
+
407
+	/**
408
+	 * verify_default_pages_exist
409
+	 *
410
+	 * @access public
411
+	 * @static
412
+	 * @return void
413
+	 * @throws InvalidDataTypeException
414
+	 */
415
+	public static function verify_default_pages_exist()
416
+	{
417
+		$critical_page_problem = false;
418
+		$critical_pages = array(
419
+			array(
420
+				'id'   => 'reg_page_id',
421
+				'name' => __('Registration Checkout', 'event_espresso'),
422
+				'post' => null,
423
+				'code' => 'ESPRESSO_CHECKOUT',
424
+			),
425
+			array(
426
+				'id'   => 'txn_page_id',
427
+				'name' => __('Transactions', 'event_espresso'),
428
+				'post' => null,
429
+				'code' => 'ESPRESSO_TXN_PAGE',
430
+			),
431
+			array(
432
+				'id'   => 'thank_you_page_id',
433
+				'name' => __('Thank You', 'event_espresso'),
434
+				'post' => null,
435
+				'code' => 'ESPRESSO_THANK_YOU',
436
+			),
437
+			array(
438
+				'id'   => 'cancel_page_id',
439
+				'name' => __('Registration Cancelled', 'event_espresso'),
440
+				'post' => null,
441
+				'code' => 'ESPRESSO_CANCELLED',
442
+			),
443
+		);
444
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
445
+		foreach ($critical_pages as $critical_page) {
446
+			// is critical page ID set in config ?
447
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
448
+				// attempt to find post by ID
449
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
450
+			}
451
+			// no dice?
452
+			if ($critical_page['post'] === null) {
453
+				// attempt to find post by title
454
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
455
+				// still nothing?
456
+				if ($critical_page['post'] === null) {
457
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
458
+					// REALLY? Still nothing ??!?!?
459
+					if ($critical_page['post'] === null) {
460
+						$msg = __(
461
+							'The Event Espresso critical page configuration settings could not be updated.',
462
+							'event_espresso'
463
+						);
464
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
465
+						break;
466
+					}
467
+				}
468
+			}
469
+			// check that Post ID matches critical page ID in config
470
+			if (isset($critical_page['post']->ID)
471
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
472
+			) {
473
+				// update Config with post ID
474
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
475
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
476
+					$msg = __(
477
+						'The Event Espresso critical page configuration settings could not be updated.',
478
+						'event_espresso'
479
+					);
480
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
481
+				}
482
+			}
483
+			$critical_page_problem =
484
+				! isset($critical_page['post']->post_status)
485
+				|| $critical_page['post']->post_status !== 'publish'
486
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
487
+					? true
488
+					: $critical_page_problem;
489
+		}
490
+		if ($critical_page_problem) {
491
+			new PersistentAdminNotice(
492
+				'critical_page_problem',
493
+				sprintf(
494
+					esc_html__(
495
+						'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
496
+						'event_espresso'
497
+					),
498
+					'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
499
+					. __('Event Espresso Critical Pages Settings', 'event_espresso')
500
+					. '</a>'
501
+				)
502
+			);
503
+		}
504
+		if (EE_Error::has_notices()) {
505
+			EE_Error::get_notices(false, true, true);
506
+		}
507
+	}
508
+
509
+
510
+
511
+	/**
512
+	 * Returns the first post which uses the specified shortcode
513
+	 *
514
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
515
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
516
+	 *                             "[ESPRESSO_THANK_YOU"
517
+	 *                             (we don't search for the closing shortcode bracket because they might have added
518
+	 *                             parameter to the shortcode
519
+	 * @return WP_Post or NULl
520
+	 */
521
+	public static function get_page_by_ee_shortcode($ee_shortcode)
522
+	{
523
+		global $wpdb;
524
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
525
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
526
+		if ($post_id) {
527
+			return get_post($post_id);
528
+		} else {
529
+			return null;
530
+		}
531
+	}
532
+
533
+
534
+	/**
535
+	 *    This function generates a post for critical espresso pages
536
+	 *
537
+	 * @access public
538
+	 * @static
539
+	 * @param array $critical_page
540
+	 * @return array
541
+	 */
542
+	public static function create_critical_page($critical_page)
543
+	{
544
+
545
+		$post_args = array(
546
+			'post_title'     => $critical_page['name'],
547
+			'post_status'    => 'publish',
548
+			'post_type'      => 'page',
549
+			'comment_status' => 'closed',
550
+			'post_content'   => '[' . $critical_page['code'] . ']',
551
+		);
552
+
553
+		$post_id = wp_insert_post($post_args);
554
+		if (! $post_id) {
555
+			$msg = sprintf(
556
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
557
+				$critical_page['name']
558
+			);
559
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
560
+			return $critical_page;
561
+		}
562
+		// get newly created post's details
563
+		if (! $critical_page['post'] = get_post($post_id)) {
564
+			$msg = sprintf(
565
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
566
+				$critical_page['name']
567
+			);
568
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
569
+		}
570
+
571
+		return $critical_page;
572
+	}
573
+
574
+
575
+
576
+
577
+	/**
578
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
579
+	 * The role being used to check is filterable.
580
+	 *
581
+	 * @since  4.6.0
582
+	 * @global WPDB $wpdb
583
+	 * @return mixed null|int WP_user ID or NULL
584
+	 */
585
+	public static function get_default_creator_id()
586
+	{
587
+		global $wpdb;
588
+		if (! empty(self::$_default_creator_id)) {
589
+			return self::$_default_creator_id;
590
+		}/**/
591
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
592
+		// 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.
593
+		$pre_filtered_id = apply_filters(
594
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
595
+			false,
596
+			$role_to_check
597
+		);
598
+		if ($pre_filtered_id !== false) {
599
+			return (int) $pre_filtered_id;
600
+		}
601
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
602
+		$query = $wpdb->prepare(
603
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
604
+			'%' . $role_to_check . '%'
605
+		);
606
+		$user_id = $wpdb->get_var($query);
607
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
608
+		if ($user_id && (int) $user_id) {
609
+			self::$_default_creator_id = (int) $user_id;
610
+			return self::$_default_creator_id;
611
+		} else {
612
+			return null;
613
+		}
614
+	}
615
+
616
+
617
+
618
+	/**
619
+	 * used by EE and EE addons during plugin activation to create tables.
620
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
621
+	 * but includes extra logic regarding activations.
622
+	 *
623
+	 * @access public
624
+	 * @static
625
+	 * @param string  $table_name              without the $wpdb->prefix
626
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
627
+	 *                                         table query)
628
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
629
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
630
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
631
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
632
+	 *                                         you just want to verify the table exists and matches this definition
633
+	 *                                         (and if it HAS data in it you want to leave it be)
634
+	 * @return void
635
+	 * @throws EE_Error if there are database errors
636
+	 */
637
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
638
+	{
639
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
640
+			return;
641
+		}
642
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
643
+		if (! function_exists('dbDelta')) {
644
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
645
+		}
646
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
647
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
648
+		// do we need to first delete an existing version of this table ?
649
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
650
+			// ok, delete the table... but ONLY if it's empty
651
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
652
+			// table is NOT empty, are you SURE you want to delete this table ???
653
+			if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
654
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
655
+			} elseif (! $deleted_safely) {
656
+				// so we should be more cautious rather than just dropping tables so easily
657
+				error_log(
658
+					sprintf(
659
+						__(
660
+							'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.',
661
+							'event_espresso'
662
+						),
663
+						$wp_table_name,
664
+						'<br/>',
665
+						'espresso_db_update'
666
+					)
667
+				);
668
+			}
669
+		}
670
+		$engine = str_replace('ENGINE=', '', $engine);
671
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
672
+	}
673
+
674
+
675
+
676
+	/**
677
+	 *    add_column_if_it_doesn't_exist
678
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
679
+	 *
680
+	 * @access     public
681
+	 * @static
682
+	 * @deprecated instead use TableManager::addColumn()
683
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
684
+	 * @param string $column_name
685
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
686
+	 *                            'VARCHAR(10)'
687
+	 * @return bool|int
688
+	 */
689
+	public static function add_column_if_it_doesnt_exist(
690
+		$table_name,
691
+		$column_name,
692
+		$column_info = 'INT UNSIGNED NOT NULL'
693
+	) {
694
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
695
+	}
696
+
697
+
698
+	/**
699
+	 * get_fields_on_table
700
+	 * Gets all the fields on the database table.
701
+	 *
702
+	 * @access     public
703
+	 * @deprecated instead use TableManager::getTableColumns()
704
+	 * @static
705
+	 * @param string $table_name , without prefixed $wpdb->prefix
706
+	 * @return array of database column names
707
+	 */
708
+	public static function get_fields_on_table($table_name = null)
709
+	{
710
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
711
+	}
712
+
713
+
714
+	/**
715
+	 * db_table_is_empty
716
+	 *
717
+	 * @access     public\
718
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
719
+	 * @static
720
+	 * @param string $table_name
721
+	 * @return bool
722
+	 */
723
+	public static function db_table_is_empty($table_name)
724
+	{
725
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
726
+	}
727
+
728
+
729
+	/**
730
+	 * delete_db_table_if_empty
731
+	 *
732
+	 * @access public
733
+	 * @static
734
+	 * @param string $table_name
735
+	 * @return bool | int
736
+	 */
737
+	public static function delete_db_table_if_empty($table_name)
738
+	{
739
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
740
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
741
+		}
742
+		return false;
743
+	}
744
+
745
+
746
+	/**
747
+	 * delete_unused_db_table
748
+	 *
749
+	 * @access     public
750
+	 * @static
751
+	 * @deprecated instead use TableManager::dropTable()
752
+	 * @param string $table_name
753
+	 * @return bool | int
754
+	 */
755
+	public static function delete_unused_db_table($table_name)
756
+	{
757
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
758
+	}
759
+
760
+
761
+	/**
762
+	 * drop_index
763
+	 *
764
+	 * @access     public
765
+	 * @static
766
+	 * @deprecated instead use TableManager::dropIndex()
767
+	 * @param string $table_name
768
+	 * @param string $index_name
769
+	 * @return bool | int
770
+	 */
771
+	public static function drop_index($table_name, $index_name)
772
+	{
773
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
774
+	}
775
+
776
+
777
+
778
+	/**
779
+	 * create_database_tables
780
+	 *
781
+	 * @access public
782
+	 * @static
783
+	 * @throws EE_Error
784
+	 * @return boolean success (whether database is setup properly or not)
785
+	 */
786
+	public static function create_database_tables()
787
+	{
788
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
789
+		// find the migration script that sets the database to be compatible with the code
790
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
791
+		if ($dms_name) {
792
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
793
+			$current_data_migration_script->set_migrating(false);
794
+			$current_data_migration_script->schema_changes_before_migration();
795
+			$current_data_migration_script->schema_changes_after_migration();
796
+			if ($current_data_migration_script->get_errors()) {
797
+				if (WP_DEBUG) {
798
+					foreach ($current_data_migration_script->get_errors() as $error) {
799
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
800
+					}
801
+				} else {
802
+					EE_Error::add_error(
803
+						__(
804
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
805 805
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
806
-                            'event_espresso'
807
-                        )
808
-                    );
809
-                }
810
-                return false;
811
-            }
812
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
813
-        } else {
814
-            EE_Error::add_error(
815
-                __(
816
-                    'Could not determine most up-to-date data migration script from which to pull database schema
806
+							'event_espresso'
807
+						)
808
+					);
809
+				}
810
+				return false;
811
+			}
812
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
813
+		} else {
814
+			EE_Error::add_error(
815
+				__(
816
+					'Could not determine most up-to-date data migration script from which to pull database schema
817 817
                      structure. So database is probably not setup properly',
818
-                    'event_espresso'
819
-                ),
820
-                __FILE__,
821
-                __FUNCTION__,
822
-                __LINE__
823
-            );
824
-            return false;
825
-        }
826
-        return true;
827
-    }
828
-
829
-
830
-
831
-    /**
832
-     * initialize_system_questions
833
-     *
834
-     * @access public
835
-     * @static
836
-     * @return void
837
-     */
838
-    public static function initialize_system_questions()
839
-    {
840
-        // QUESTION GROUPS
841
-        global $wpdb;
842
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
843
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
844
-        // what we have
845
-        $question_groups = $wpdb->get_col($SQL);
846
-        // check the response
847
-        $question_groups = is_array($question_groups) ? $question_groups : array();
848
-        // what we should have
849
-        $QSG_systems = array(1, 2);
850
-        // loop thru what we should have and compare to what we have
851
-        foreach ($QSG_systems as $QSG_system) {
852
-            // reset values array
853
-            $QSG_values = array();
854
-            // 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)
855
-            if (! in_array("$QSG_system", $question_groups)) {
856
-                // add it
857
-                switch ($QSG_system) {
858
-                    case 1:
859
-                        $QSG_values = array(
860
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
861
-                            'QSG_identifier'      => 'personal-information-' . time(),
862
-                            'QSG_desc'            => '',
863
-                            'QSG_order'           => 1,
864
-                            'QSG_show_group_name' => 1,
865
-                            'QSG_show_group_desc' => 1,
866
-                            'QSG_system'          => EEM_Question_Group::system_personal,
867
-                            'QSG_deleted'         => 0,
868
-                        );
869
-                        break;
870
-                    case 2:
871
-                        $QSG_values = array(
872
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
873
-                            'QSG_identifier'      => 'address-information-' . time(),
874
-                            'QSG_desc'            => '',
875
-                            'QSG_order'           => 2,
876
-                            'QSG_show_group_name' => 1,
877
-                            'QSG_show_group_desc' => 1,
878
-                            'QSG_system'          => EEM_Question_Group::system_address,
879
-                            'QSG_deleted'         => 0,
880
-                        );
881
-                        break;
882
-                }
883
-                // make sure we have some values before inserting them
884
-                if (! empty($QSG_values)) {
885
-                    // insert system question
886
-                    $wpdb->insert(
887
-                        $table_name,
888
-                        $QSG_values,
889
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
890
-                    );
891
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
892
-                }
893
-            }
894
-        }
895
-        // QUESTIONS
896
-        global $wpdb;
897
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
898
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
899
-        // what we have
900
-        $questions = $wpdb->get_col($SQL);
901
-        // what we should have
902
-        $QST_systems = array(
903
-            'fname',
904
-            'lname',
905
-            'email',
906
-            'address',
907
-            'address2',
908
-            'city',
909
-            'country',
910
-            'state',
911
-            'zip',
912
-            'phone',
913
-        );
914
-        $order_for_group_1 = 1;
915
-        $order_for_group_2 = 1;
916
-        // loop thru what we should have and compare to what we have
917
-        foreach ($QST_systems as $QST_system) {
918
-            // reset values array
919
-            $QST_values = array();
920
-            // if we don't have what we should have
921
-            if (! in_array($QST_system, $questions)) {
922
-                // add it
923
-                switch ($QST_system) {
924
-                    case 'fname':
925
-                        $QST_values = array(
926
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
927
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
928
-                            'QST_system'        => 'fname',
929
-                            'QST_type'          => 'TEXT',
930
-                            'QST_required'      => 1,
931
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
932
-                            'QST_order'         => 1,
933
-                            'QST_admin_only'    => 0,
934
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
935
-                            'QST_wp_user'       => self::get_default_creator_id(),
936
-                            'QST_deleted'       => 0,
937
-                        );
938
-                        break;
939
-                    case 'lname':
940
-                        $QST_values = array(
941
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
942
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
943
-                            'QST_system'        => 'lname',
944
-                            'QST_type'          => 'TEXT',
945
-                            'QST_required'      => 1,
946
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
947
-                            'QST_order'         => 2,
948
-                            'QST_admin_only'    => 0,
949
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
950
-                            'QST_wp_user'       => self::get_default_creator_id(),
951
-                            'QST_deleted'       => 0,
952
-                        );
953
-                        break;
954
-                    case 'email':
955
-                        $QST_values = array(
956
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
957
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
958
-                            'QST_system'        => 'email',
959
-                            'QST_type'          => 'EMAIL',
960
-                            'QST_required'      => 1,
961
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
962
-                            'QST_order'         => 3,
963
-                            'QST_admin_only'    => 0,
964
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
965
-                            'QST_wp_user'       => self::get_default_creator_id(),
966
-                            'QST_deleted'       => 0,
967
-                        );
968
-                        break;
969
-                    case 'address':
970
-                        $QST_values = array(
971
-                            'QST_display_text'  => __('Address', 'event_espresso'),
972
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
973
-                            'QST_system'        => 'address',
974
-                            'QST_type'          => 'TEXT',
975
-                            'QST_required'      => 0,
976
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
977
-                            'QST_order'         => 4,
978
-                            'QST_admin_only'    => 0,
979
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
980
-                            'QST_wp_user'       => self::get_default_creator_id(),
981
-                            'QST_deleted'       => 0,
982
-                        );
983
-                        break;
984
-                    case 'address2':
985
-                        $QST_values = array(
986
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
987
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
988
-                            'QST_system'        => 'address2',
989
-                            'QST_type'          => 'TEXT',
990
-                            'QST_required'      => 0,
991
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
992
-                            'QST_order'         => 5,
993
-                            'QST_admin_only'    => 0,
994
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
995
-                            'QST_wp_user'       => self::get_default_creator_id(),
996
-                            'QST_deleted'       => 0,
997
-                        );
998
-                        break;
999
-                    case 'city':
1000
-                        $QST_values = array(
1001
-                            'QST_display_text'  => __('City', 'event_espresso'),
1002
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1003
-                            'QST_system'        => 'city',
1004
-                            'QST_type'          => 'TEXT',
1005
-                            'QST_required'      => 0,
1006
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1007
-                            'QST_order'         => 6,
1008
-                            'QST_admin_only'    => 0,
1009
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1010
-                            'QST_wp_user'       => self::get_default_creator_id(),
1011
-                            'QST_deleted'       => 0,
1012
-                        );
1013
-                        break;
1014
-                    case 'country':
1015
-                        $QST_values = array(
1016
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1017
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1018
-                            'QST_system'        => 'country',
1019
-                            'QST_type'          => 'COUNTRY',
1020
-                            'QST_required'      => 0,
1021
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1022
-                            'QST_order'         => 7,
1023
-                            'QST_admin_only'    => 0,
1024
-                            'QST_wp_user'       => self::get_default_creator_id(),
1025
-                            'QST_deleted'       => 0,
1026
-                        );
1027
-                        break;
1028
-                    case 'state':
1029
-                        $QST_values = array(
1030
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1031
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1032
-                            'QST_system'        => 'state',
1033
-                            'QST_type'          => 'STATE',
1034
-                            'QST_required'      => 0,
1035
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1036
-                            'QST_order'         => 8,
1037
-                            'QST_admin_only'    => 0,
1038
-                            'QST_wp_user'       => self::get_default_creator_id(),
1039
-                            'QST_deleted'       => 0,
1040
-                        );
1041
-                        break;
1042
-                    case 'zip':
1043
-                        $QST_values = array(
1044
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1045
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1046
-                            'QST_system'        => 'zip',
1047
-                            'QST_type'          => 'TEXT',
1048
-                            'QST_required'      => 0,
1049
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1050
-                            'QST_order'         => 9,
1051
-                            'QST_admin_only'    => 0,
1052
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1053
-                            'QST_wp_user'       => self::get_default_creator_id(),
1054
-                            'QST_deleted'       => 0,
1055
-                        );
1056
-                        break;
1057
-                    case 'phone':
1058
-                        $QST_values = array(
1059
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1060
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1061
-                            'QST_system'        => 'phone',
1062
-                            'QST_type'          => 'TEXT',
1063
-                            'QST_required'      => 0,
1064
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1065
-                            'QST_order'         => 10,
1066
-                            'QST_admin_only'    => 0,
1067
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1068
-                            'QST_wp_user'       => self::get_default_creator_id(),
1069
-                            'QST_deleted'       => 0,
1070
-                        );
1071
-                        break;
1072
-                }
1073
-                if (! empty($QST_values)) {
1074
-                    // insert system question
1075
-                    $wpdb->insert(
1076
-                        $table_name,
1077
-                        $QST_values,
1078
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1079
-                    );
1080
-                    $QST_ID = $wpdb->insert_id;
1081
-                    // QUESTION GROUP QUESTIONS
1082
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1083
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1084
-                    } else {
1085
-                        $system_question_we_want = EEM_Question_Group::system_address;
1086
-                    }
1087
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1088
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1089
-                    } else {
1090
-                        $id_col = EEM_Question_Group::instance()
1091
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1092
-                        if (is_array($id_col)) {
1093
-                            $QSG_ID = reset($id_col);
1094
-                        } else {
1095
-                            // 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
1096
-                            EE_Log::instance()->log(
1097
-                                __FILE__,
1098
-                                __FUNCTION__,
1099
-                                sprintf(
1100
-                                    __(
1101
-                                        'Could not associate question %1$s to a question group because no system question
818
+					'event_espresso'
819
+				),
820
+				__FILE__,
821
+				__FUNCTION__,
822
+				__LINE__
823
+			);
824
+			return false;
825
+		}
826
+		return true;
827
+	}
828
+
829
+
830
+
831
+	/**
832
+	 * initialize_system_questions
833
+	 *
834
+	 * @access public
835
+	 * @static
836
+	 * @return void
837
+	 */
838
+	public static function initialize_system_questions()
839
+	{
840
+		// QUESTION GROUPS
841
+		global $wpdb;
842
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
843
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
844
+		// what we have
845
+		$question_groups = $wpdb->get_col($SQL);
846
+		// check the response
847
+		$question_groups = is_array($question_groups) ? $question_groups : array();
848
+		// what we should have
849
+		$QSG_systems = array(1, 2);
850
+		// loop thru what we should have and compare to what we have
851
+		foreach ($QSG_systems as $QSG_system) {
852
+			// reset values array
853
+			$QSG_values = array();
854
+			// 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)
855
+			if (! in_array("$QSG_system", $question_groups)) {
856
+				// add it
857
+				switch ($QSG_system) {
858
+					case 1:
859
+						$QSG_values = array(
860
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
861
+							'QSG_identifier'      => 'personal-information-' . time(),
862
+							'QSG_desc'            => '',
863
+							'QSG_order'           => 1,
864
+							'QSG_show_group_name' => 1,
865
+							'QSG_show_group_desc' => 1,
866
+							'QSG_system'          => EEM_Question_Group::system_personal,
867
+							'QSG_deleted'         => 0,
868
+						);
869
+						break;
870
+					case 2:
871
+						$QSG_values = array(
872
+							'QSG_name'            => __('Address Information', 'event_espresso'),
873
+							'QSG_identifier'      => 'address-information-' . time(),
874
+							'QSG_desc'            => '',
875
+							'QSG_order'           => 2,
876
+							'QSG_show_group_name' => 1,
877
+							'QSG_show_group_desc' => 1,
878
+							'QSG_system'          => EEM_Question_Group::system_address,
879
+							'QSG_deleted'         => 0,
880
+						);
881
+						break;
882
+				}
883
+				// make sure we have some values before inserting them
884
+				if (! empty($QSG_values)) {
885
+					// insert system question
886
+					$wpdb->insert(
887
+						$table_name,
888
+						$QSG_values,
889
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
890
+					);
891
+					$QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
892
+				}
893
+			}
894
+		}
895
+		// QUESTIONS
896
+		global $wpdb;
897
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
898
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
899
+		// what we have
900
+		$questions = $wpdb->get_col($SQL);
901
+		// what we should have
902
+		$QST_systems = array(
903
+			'fname',
904
+			'lname',
905
+			'email',
906
+			'address',
907
+			'address2',
908
+			'city',
909
+			'country',
910
+			'state',
911
+			'zip',
912
+			'phone',
913
+		);
914
+		$order_for_group_1 = 1;
915
+		$order_for_group_2 = 1;
916
+		// loop thru what we should have and compare to what we have
917
+		foreach ($QST_systems as $QST_system) {
918
+			// reset values array
919
+			$QST_values = array();
920
+			// if we don't have what we should have
921
+			if (! in_array($QST_system, $questions)) {
922
+				// add it
923
+				switch ($QST_system) {
924
+					case 'fname':
925
+						$QST_values = array(
926
+							'QST_display_text'  => __('First Name', 'event_espresso'),
927
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
928
+							'QST_system'        => 'fname',
929
+							'QST_type'          => 'TEXT',
930
+							'QST_required'      => 1,
931
+							'QST_required_text' => __('This field is required', 'event_espresso'),
932
+							'QST_order'         => 1,
933
+							'QST_admin_only'    => 0,
934
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
935
+							'QST_wp_user'       => self::get_default_creator_id(),
936
+							'QST_deleted'       => 0,
937
+						);
938
+						break;
939
+					case 'lname':
940
+						$QST_values = array(
941
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
942
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
943
+							'QST_system'        => 'lname',
944
+							'QST_type'          => 'TEXT',
945
+							'QST_required'      => 1,
946
+							'QST_required_text' => __('This field is required', 'event_espresso'),
947
+							'QST_order'         => 2,
948
+							'QST_admin_only'    => 0,
949
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
950
+							'QST_wp_user'       => self::get_default_creator_id(),
951
+							'QST_deleted'       => 0,
952
+						);
953
+						break;
954
+					case 'email':
955
+						$QST_values = array(
956
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
957
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
958
+							'QST_system'        => 'email',
959
+							'QST_type'          => 'EMAIL',
960
+							'QST_required'      => 1,
961
+							'QST_required_text' => __('This field is required', 'event_espresso'),
962
+							'QST_order'         => 3,
963
+							'QST_admin_only'    => 0,
964
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
965
+							'QST_wp_user'       => self::get_default_creator_id(),
966
+							'QST_deleted'       => 0,
967
+						);
968
+						break;
969
+					case 'address':
970
+						$QST_values = array(
971
+							'QST_display_text'  => __('Address', 'event_espresso'),
972
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
973
+							'QST_system'        => 'address',
974
+							'QST_type'          => 'TEXT',
975
+							'QST_required'      => 0,
976
+							'QST_required_text' => __('This field is required', 'event_espresso'),
977
+							'QST_order'         => 4,
978
+							'QST_admin_only'    => 0,
979
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
980
+							'QST_wp_user'       => self::get_default_creator_id(),
981
+							'QST_deleted'       => 0,
982
+						);
983
+						break;
984
+					case 'address2':
985
+						$QST_values = array(
986
+							'QST_display_text'  => __('Address2', 'event_espresso'),
987
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
988
+							'QST_system'        => 'address2',
989
+							'QST_type'          => 'TEXT',
990
+							'QST_required'      => 0,
991
+							'QST_required_text' => __('This field is required', 'event_espresso'),
992
+							'QST_order'         => 5,
993
+							'QST_admin_only'    => 0,
994
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
995
+							'QST_wp_user'       => self::get_default_creator_id(),
996
+							'QST_deleted'       => 0,
997
+						);
998
+						break;
999
+					case 'city':
1000
+						$QST_values = array(
1001
+							'QST_display_text'  => __('City', 'event_espresso'),
1002
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1003
+							'QST_system'        => 'city',
1004
+							'QST_type'          => 'TEXT',
1005
+							'QST_required'      => 0,
1006
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1007
+							'QST_order'         => 6,
1008
+							'QST_admin_only'    => 0,
1009
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1010
+							'QST_wp_user'       => self::get_default_creator_id(),
1011
+							'QST_deleted'       => 0,
1012
+						);
1013
+						break;
1014
+					case 'country':
1015
+						$QST_values = array(
1016
+							'QST_display_text'  => __('Country', 'event_espresso'),
1017
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1018
+							'QST_system'        => 'country',
1019
+							'QST_type'          => 'COUNTRY',
1020
+							'QST_required'      => 0,
1021
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1022
+							'QST_order'         => 7,
1023
+							'QST_admin_only'    => 0,
1024
+							'QST_wp_user'       => self::get_default_creator_id(),
1025
+							'QST_deleted'       => 0,
1026
+						);
1027
+						break;
1028
+					case 'state':
1029
+						$QST_values = array(
1030
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1031
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1032
+							'QST_system'        => 'state',
1033
+							'QST_type'          => 'STATE',
1034
+							'QST_required'      => 0,
1035
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1036
+							'QST_order'         => 8,
1037
+							'QST_admin_only'    => 0,
1038
+							'QST_wp_user'       => self::get_default_creator_id(),
1039
+							'QST_deleted'       => 0,
1040
+						);
1041
+						break;
1042
+					case 'zip':
1043
+						$QST_values = array(
1044
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1045
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1046
+							'QST_system'        => 'zip',
1047
+							'QST_type'          => 'TEXT',
1048
+							'QST_required'      => 0,
1049
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1050
+							'QST_order'         => 9,
1051
+							'QST_admin_only'    => 0,
1052
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1053
+							'QST_wp_user'       => self::get_default_creator_id(),
1054
+							'QST_deleted'       => 0,
1055
+						);
1056
+						break;
1057
+					case 'phone':
1058
+						$QST_values = array(
1059
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1060
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1061
+							'QST_system'        => 'phone',
1062
+							'QST_type'          => 'TEXT',
1063
+							'QST_required'      => 0,
1064
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1065
+							'QST_order'         => 10,
1066
+							'QST_admin_only'    => 0,
1067
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1068
+							'QST_wp_user'       => self::get_default_creator_id(),
1069
+							'QST_deleted'       => 0,
1070
+						);
1071
+						break;
1072
+				}
1073
+				if (! empty($QST_values)) {
1074
+					// insert system question
1075
+					$wpdb->insert(
1076
+						$table_name,
1077
+						$QST_values,
1078
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1079
+					);
1080
+					$QST_ID = $wpdb->insert_id;
1081
+					// QUESTION GROUP QUESTIONS
1082
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1083
+						$system_question_we_want = EEM_Question_Group::system_personal;
1084
+					} else {
1085
+						$system_question_we_want = EEM_Question_Group::system_address;
1086
+					}
1087
+					if (isset($QSG_IDs[ $system_question_we_want ])) {
1088
+						$QSG_ID = $QSG_IDs[ $system_question_we_want ];
1089
+					} else {
1090
+						$id_col = EEM_Question_Group::instance()
1091
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1092
+						if (is_array($id_col)) {
1093
+							$QSG_ID = reset($id_col);
1094
+						} else {
1095
+							// 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
1096
+							EE_Log::instance()->log(
1097
+								__FILE__,
1098
+								__FUNCTION__,
1099
+								sprintf(
1100
+									__(
1101
+										'Could not associate question %1$s to a question group because no system question
1102 1102
                                          group existed',
1103
-                                        'event_espresso'
1104
-                                    ),
1105
-                                    $QST_ID
1106
-                                ),
1107
-                                'error'
1108
-                            );
1109
-                            continue;
1110
-                        }
1111
-                    }
1112
-                    // add system questions to groups
1113
-                    $wpdb->insert(
1114
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1115
-                        array(
1116
-                            'QSG_ID'    => $QSG_ID,
1117
-                            'QST_ID'    => $QST_ID,
1118
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1119
-                        ),
1120
-                        array('%d', '%d', '%d')
1121
-                    );
1122
-                }
1123
-            }
1124
-        }
1125
-    }
1126
-
1127
-
1128
-    /**
1129
-     * Makes sure the default payment method (Invoice) is active.
1130
-     * This used to be done automatically as part of constructing the old gateways config
1131
-     *
1132
-     * @throws \EE_Error
1133
-     */
1134
-    public static function insert_default_payment_methods()
1135
-    {
1136
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1137
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1138
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1139
-        } else {
1140
-            EEM_Payment_Method::instance()->verify_button_urls();
1141
-        }
1142
-    }
1143
-
1144
-    /**
1145
-     * insert_default_status_codes
1146
-     *
1147
-     * @access public
1148
-     * @static
1149
-     * @return void
1150
-     */
1151
-    public static function insert_default_status_codes()
1152
-    {
1153
-
1154
-        global $wpdb;
1155
-
1156
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1157
-            $table_name = EEM_Status::instance()->table();
1158
-
1159
-            $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' );";
1160
-            $wpdb->query($SQL);
1161
-
1162
-            $SQL = "INSERT INTO $table_name
1103
+										'event_espresso'
1104
+									),
1105
+									$QST_ID
1106
+								),
1107
+								'error'
1108
+							);
1109
+							continue;
1110
+						}
1111
+					}
1112
+					// add system questions to groups
1113
+					$wpdb->insert(
1114
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1115
+						array(
1116
+							'QSG_ID'    => $QSG_ID,
1117
+							'QST_ID'    => $QST_ID,
1118
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1119
+						),
1120
+						array('%d', '%d', '%d')
1121
+					);
1122
+				}
1123
+			}
1124
+		}
1125
+	}
1126
+
1127
+
1128
+	/**
1129
+	 * Makes sure the default payment method (Invoice) is active.
1130
+	 * This used to be done automatically as part of constructing the old gateways config
1131
+	 *
1132
+	 * @throws \EE_Error
1133
+	 */
1134
+	public static function insert_default_payment_methods()
1135
+	{
1136
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1137
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1138
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1139
+		} else {
1140
+			EEM_Payment_Method::instance()->verify_button_urls();
1141
+		}
1142
+	}
1143
+
1144
+	/**
1145
+	 * insert_default_status_codes
1146
+	 *
1147
+	 * @access public
1148
+	 * @static
1149
+	 * @return void
1150
+	 */
1151
+	public static function insert_default_status_codes()
1152
+	{
1153
+
1154
+		global $wpdb;
1155
+
1156
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1157
+			$table_name = EEM_Status::instance()->table();
1158
+
1159
+			$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' );";
1160
+			$wpdb->query($SQL);
1161
+
1162
+			$SQL = "INSERT INTO $table_name
1163 1163
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1164 1164
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1165 1165
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1199,457 +1199,457 @@  discard block
 block discarded – undo
1199 1199
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1200 1200
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1201 1201
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1202
-            $wpdb->query($SQL);
1203
-        }
1204
-    }
1205
-
1206
-
1207
-    /**
1208
-     * generate_default_message_templates
1209
-     *
1210
-     * @static
1211
-     * @throws EE_Error
1212
-     * @return bool     true means new templates were created.
1213
-     *                  false means no templates were created.
1214
-     *                  This is NOT an error flag. To check for errors you will want
1215
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1216
-     */
1217
-    public static function generate_default_message_templates()
1218
-    {
1219
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1220
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1221
-        /*
1202
+			$wpdb->query($SQL);
1203
+		}
1204
+	}
1205
+
1206
+
1207
+	/**
1208
+	 * generate_default_message_templates
1209
+	 *
1210
+	 * @static
1211
+	 * @throws EE_Error
1212
+	 * @return bool     true means new templates were created.
1213
+	 *                  false means no templates were created.
1214
+	 *                  This is NOT an error flag. To check for errors you will want
1215
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1216
+	 */
1217
+	public static function generate_default_message_templates()
1218
+	{
1219
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1220
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1221
+		/*
1222 1222
          * This first method is taking care of ensuring any default messengers
1223 1223
          * that should be made active and have templates generated are done.
1224 1224
          */
1225
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1226
-            $message_resource_manager
1227
-        );
1228
-        /**
1229
-         * This method is verifying there are no NEW default message types
1230
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1231
-         */
1232
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1233
-            $message_resource_manager
1234
-        );
1235
-        // after all is done, let's persist these changes to the db.
1236
-        $message_resource_manager->update_has_activated_messengers_option();
1237
-        $message_resource_manager->update_active_messengers_option();
1238
-        // will return true if either of these are true.  Otherwise will return false.
1239
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1240
-    }
1241
-
1242
-
1243
-
1244
-    /**
1245
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1246
-     * @return array|bool
1247
-     * @throws \EE_Error
1248
-     */
1249
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1250
-        EE_Message_Resource_Manager $message_resource_manager
1251
-    ) {
1252
-        /** @type EE_messenger[] $active_messengers */
1253
-        $active_messengers = $message_resource_manager->active_messengers();
1254
-        $installed_message_types = $message_resource_manager->installed_message_types();
1255
-        $templates_created = false;
1256
-        foreach ($active_messengers as $active_messenger) {
1257
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1258
-            $default_message_type_names_to_activate = array();
1259
-            // looping through each default message type reported by the messenger
1260
-            // and setup the actual message types to activate.
1261
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1262
-                // if already active or has already been activated before we skip
1263
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1264
-                // we also skip if the message type is not installed.
1265
-                if ($message_resource_manager->has_message_type_been_activated_for_messenger(
1266
-                    $default_message_type_name_for_messenger,
1267
-                    $active_messenger->name
1268
-                )
1269
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1270
-                        $active_messenger->name,
1271
-                        $default_message_type_name_for_messenger
1272
-                    )
1273
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1274
-                ) {
1275
-                    continue;
1276
-                }
1277
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1278
-            }
1279
-            // let's activate!
1280
-            $message_resource_manager->ensure_message_types_are_active(
1281
-                $default_message_type_names_to_activate,
1282
-                $active_messenger->name,
1283
-                false
1284
-            );
1285
-            // activate the templates for these message types
1286
-            if (! empty($default_message_type_names_to_activate)) {
1287
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1288
-                    $active_messenger->name,
1289
-                    $default_message_type_names_for_messenger,
1290
-                    '',
1291
-                    true
1292
-                );
1293
-            }
1294
-        }
1295
-        return $templates_created;
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * This will activate and generate default messengers and default message types for those messengers.
1302
-     *
1303
-     * @param EE_message_Resource_Manager $message_resource_manager
1304
-     * @return array|bool  True means there were default messengers and message type templates generated.
1305
-     *                     False means that there were no templates generated
1306
-     *                     (which could simply mean there are no default message types for a messenger).
1307
-     * @throws EE_Error
1308
-     */
1309
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1310
-        EE_Message_Resource_Manager $message_resource_manager
1311
-    ) {
1312
-        /** @type EE_messenger[] $messengers_to_generate */
1313
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1314
-        $installed_message_types = $message_resource_manager->installed_message_types();
1315
-        $templates_generated = false;
1316
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1317
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1318
-            // verify the default message types match an installed message type.
1319
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1320
-                if (! isset($installed_message_types[ $name ])
1321
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1322
-                        $name,
1323
-                        $messenger_to_generate->name
1324
-                    )
1325
-                ) {
1326
-                    unset($default_message_type_names_for_messenger[ $key ]);
1327
-                }
1328
-            }
1329
-            // in previous iterations, the active_messengers option in the db
1330
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1331
-            // This comment is left here just in case we discover that we _do_ need to update before
1332
-            // passing off to create templates (after the refactor is done).
1333
-            // @todo remove this comment when determined not necessary.
1334
-            $message_resource_manager->activate_messenger(
1335
-                $messenger_to_generate->name,
1336
-                $default_message_type_names_for_messenger,
1337
-                false
1338
-            );
1339
-            // create any templates needing created (or will reactivate templates already generated as necessary).
1340
-            if (! empty($default_message_type_names_for_messenger)) {
1341
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1342
-                    $messenger_to_generate->name,
1343
-                    $default_message_type_names_for_messenger,
1344
-                    '',
1345
-                    true
1346
-                );
1347
-            }
1348
-        }
1349
-        return $templates_generated;
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * This returns the default messengers to generate templates for on activation of EE.
1355
-     * It considers:
1356
-     * - whether a messenger is already active in the db.
1357
-     * - whether a messenger has been made active at any time in the past.
1358
-     *
1359
-     * @static
1360
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1361
-     * @return EE_messenger[]
1362
-     */
1363
-    protected static function _get_default_messengers_to_generate_on_activation(
1364
-        EE_Message_Resource_Manager $message_resource_manager
1365
-    ) {
1366
-        $active_messengers    = $message_resource_manager->active_messengers();
1367
-        $installed_messengers = $message_resource_manager->installed_messengers();
1368
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1369
-
1370
-        $messengers_to_generate = array();
1371
-        foreach ($installed_messengers as $installed_messenger) {
1372
-            // if installed messenger is a messenger that should be activated on install
1373
-            // and is not already active
1374
-            // and has never been activated
1375
-            if (! $installed_messenger->activate_on_install
1376
-                || isset($active_messengers[ $installed_messenger->name ])
1377
-                || isset($has_activated[ $installed_messenger->name ])
1378
-            ) {
1379
-                continue;
1380
-            }
1381
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1382
-        }
1383
-        return $messengers_to_generate;
1384
-    }
1385
-
1386
-
1387
-    /**
1388
-     * This simply validates active message types to ensure they actually match installed
1389
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1390
-     * rows are set inactive.
1391
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1392
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1393
-     * are still handled in here.
1394
-     *
1395
-     * @since 4.3.1
1396
-     * @return void
1397
-     */
1398
-    public static function validate_messages_system()
1399
-    {
1400
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1401
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1402
-        $message_resource_manager->validate_active_message_types_are_installed();
1403
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * create_no_ticket_prices_array
1409
-     *
1410
-     * @access public
1411
-     * @static
1412
-     * @return void
1413
-     */
1414
-    public static function create_no_ticket_prices_array()
1415
-    {
1416
-        // this creates an array for tracking events that have no active ticket prices created
1417
-        // this allows us to warn admins of the situation so that it can be corrected
1418
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1419
-        if (! $espresso_no_ticket_prices) {
1420
-            add_option('ee_no_ticket_prices', array(), '', false);
1421
-        }
1422
-    }
1423
-
1424
-
1425
-    /**
1426
-     * plugin_deactivation
1427
-     *
1428
-     * @access public
1429
-     * @static
1430
-     * @return void
1431
-     */
1432
-    public static function plugin_deactivation()
1433
-    {
1434
-    }
1435
-
1436
-
1437
-    /**
1438
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1439
-     * (like post meta or term relations)
1440
-     *
1441
-     * @global wpdb $wpdb
1442
-     * @throws \EE_Error
1443
-     */
1444
-    public static function delete_all_espresso_cpt_data()
1445
-    {
1446
-        global $wpdb;
1447
-        // get all the CPT post_types
1448
-        $ee_post_types = array();
1449
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1450
-            if (method_exists($model_name, 'instance')) {
1451
-                $model_obj = call_user_func(array($model_name, 'instance'));
1452
-                if ($model_obj instanceof EEM_CPT_Base) {
1453
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1454
-                }
1455
-            }
1456
-        }
1457
-        // get all our CPTs
1458
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1459
-        $cpt_ids = $wpdb->get_col($query);
1460
-        // delete each post meta and term relations too
1461
-        foreach ($cpt_ids as $post_id) {
1462
-            wp_delete_post($post_id, true);
1463
-        }
1464
-    }
1465
-
1466
-    /**
1467
-     * Deletes all EE custom tables
1468
-     *
1469
-     * @return array
1470
-     */
1471
-    public static function drop_espresso_tables()
1472
-    {
1473
-        $tables = array();
1474
-        // load registry
1475
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1476
-            if (method_exists($model_name, 'instance')) {
1477
-                $model_obj = call_user_func(array($model_name, 'instance'));
1478
-                if ($model_obj instanceof EEM_Base) {
1479
-                    foreach ($model_obj->get_tables() as $table) {
1480
-                        if (strpos($table->get_table_name(), 'esp_')
1481
-                            &&
1482
-                            (
1483
-                                is_main_site()// main site? nuke them all
1484
-                                || ! $table->is_global()// not main site,but not global either. nuke it
1485
-                            )
1486
-                        ) {
1487
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1488
-                        }
1489
-                    }
1490
-                }
1491
-            }
1492
-        }
1493
-
1494
-        // there are some tables whose models were removed.
1495
-        // they should be removed when removing all EE core's data
1496
-        $tables_without_models = array(
1497
-            'esp_promotion',
1498
-            'esp_promotion_applied',
1499
-            'esp_promotion_object',
1500
-            'esp_promotion_rule',
1501
-            'esp_rule',
1502
-        );
1503
-        foreach ($tables_without_models as $table) {
1504
-            $tables[ $table ] = $table;
1505
-        }
1506
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1507
-    }
1508
-
1509
-
1510
-
1511
-    /**
1512
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1513
-     * each table name provided has a wpdb prefix attached, and that it exists.
1514
-     * Returns the list actually deleted
1515
-     *
1516
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1517
-     * @global WPDB $wpdb
1518
-     * @param array $table_names
1519
-     * @return array of table names which we deleted
1520
-     */
1521
-    public static function drop_tables($table_names)
1522
-    {
1523
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1524
-    }
1525
-
1526
-
1527
-
1528
-    /**
1529
-     * plugin_uninstall
1530
-     *
1531
-     * @access public
1532
-     * @static
1533
-     * @param bool $remove_all
1534
-     * @return void
1535
-     */
1536
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1537
-    {
1538
-        global $wpdb;
1539
-        self::drop_espresso_tables();
1540
-        $wp_options_to_delete = array(
1541
-            'ee_no_ticket_prices'                => true,
1542
-            'ee_active_messengers'               => true,
1543
-            'ee_has_activated_messenger'         => true,
1544
-            RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1545
-            'ee_config'                          => false,
1546
-            'ee_data_migration_current_db_state' => true,
1547
-            'ee_data_migration_mapping_'         => false,
1548
-            'ee_data_migration_script_'          => false,
1549
-            'ee_data_migrations'                 => true,
1550
-            'ee_dms_map'                         => false,
1551
-            'ee_notices'                         => true,
1552
-            'lang_file_check_'                   => false,
1553
-            'ee_maintenance_mode'                => true,
1554
-            'ee_ueip_optin'                      => true,
1555
-            'ee_ueip_has_notified'               => true,
1556
-            'ee_plugin_activation_errors'        => true,
1557
-            'ee_id_mapping_from'                 => false,
1558
-            'espresso_persistent_admin_notices'  => true,
1559
-            'ee_encryption_key'                  => true,
1560
-            'pue_force_upgrade_'                 => false,
1561
-            'pue_json_error_'                    => false,
1562
-            'pue_install_key_'                   => false,
1563
-            'pue_verification_error_'            => false,
1564
-            'pu_dismissed_upgrade_'              => false,
1565
-            'external_updates-'                  => false,
1566
-            'ee_extra_data'                      => true,
1567
-            'ee_ssn_'                            => false,
1568
-            'ee_rss_'                            => false,
1569
-            'ee_rte_n_tx_'                       => false,
1570
-            'ee_pers_admin_notices'              => true,
1571
-            'ee_job_parameters_'                 => false,
1572
-            'ee_upload_directories_incomplete'   => true,
1573
-            'ee_verified_db_collations'          => true,
1574
-        );
1575
-        if (is_main_site()) {
1576
-            $wp_options_to_delete['ee_network_config'] = true;
1577
-        }
1578
-        $undeleted_options = array();
1579
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1580
-            if ($no_wildcard) {
1581
-                if (! delete_option($option_name)) {
1582
-                    $undeleted_options[] = $option_name;
1583
-                }
1584
-            } else {
1585
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1586
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1587
-                    if (! delete_option($option_name_from_wildcard)) {
1588
-                        $undeleted_options[] = $option_name_from_wildcard;
1589
-                    }
1590
-                }
1591
-            }
1592
-        }
1593
-        // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1594
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1595
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1596
-            $db_update_sans_ee4 = array();
1597
-            foreach ($espresso_db_update as $version => $times_activated) {
1598
-                if ((string) $version[0] === '3') {// if its NON EE4
1599
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1600
-                }
1601
-            }
1602
-            update_option('espresso_db_update', $db_update_sans_ee4);
1603
-        }
1604
-        $errors = '';
1605
-        if (! empty($undeleted_options)) {
1606
-            $errors .= sprintf(
1607
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1608
-                '<br/>',
1609
-                implode(',<br/>', $undeleted_options)
1610
-            );
1611
-        }
1612
-        if (! empty($errors)) {
1613
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1614
-        }
1615
-    }
1616
-
1617
-    /**
1618
-     * Gets the mysql error code from the last used query by wpdb
1619
-     *
1620
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1621
-     */
1622
-    public static function last_wpdb_error_code()
1623
-    {
1624
-        // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved
1625
-        global $wpdb;
1626
-        if ($wpdb->use_mysqli) {
1627
-            return mysqli_errno($wpdb->dbh);
1628
-        } else {
1629
-            return mysql_errno($wpdb->dbh);
1630
-        }
1631
-        // phpcs:enable
1632
-    }
1633
-
1634
-    /**
1635
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1636
-     *
1637
-     * @global wpdb  $wpdb
1638
-     * @deprecated instead use TableAnalysis::tableExists()
1639
-     * @param string $table_name with or without $wpdb->prefix
1640
-     * @return boolean
1641
-     */
1642
-    public static function table_exists($table_name)
1643
-    {
1644
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1645
-    }
1646
-
1647
-    /**
1648
-     * Resets the cache on EEH_Activation
1649
-     */
1650
-    public static function reset()
1651
-    {
1652
-        self::$_default_creator_id                             = null;
1653
-        self::$_initialized_db_content_already_in_this_request = false;
1654
-    }
1225
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1226
+			$message_resource_manager
1227
+		);
1228
+		/**
1229
+		 * This method is verifying there are no NEW default message types
1230
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1231
+		 */
1232
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1233
+			$message_resource_manager
1234
+		);
1235
+		// after all is done, let's persist these changes to the db.
1236
+		$message_resource_manager->update_has_activated_messengers_option();
1237
+		$message_resource_manager->update_active_messengers_option();
1238
+		// will return true if either of these are true.  Otherwise will return false.
1239
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1240
+	}
1241
+
1242
+
1243
+
1244
+	/**
1245
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1246
+	 * @return array|bool
1247
+	 * @throws \EE_Error
1248
+	 */
1249
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1250
+		EE_Message_Resource_Manager $message_resource_manager
1251
+	) {
1252
+		/** @type EE_messenger[] $active_messengers */
1253
+		$active_messengers = $message_resource_manager->active_messengers();
1254
+		$installed_message_types = $message_resource_manager->installed_message_types();
1255
+		$templates_created = false;
1256
+		foreach ($active_messengers as $active_messenger) {
1257
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1258
+			$default_message_type_names_to_activate = array();
1259
+			// looping through each default message type reported by the messenger
1260
+			// and setup the actual message types to activate.
1261
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1262
+				// if already active or has already been activated before we skip
1263
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1264
+				// we also skip if the message type is not installed.
1265
+				if ($message_resource_manager->has_message_type_been_activated_for_messenger(
1266
+					$default_message_type_name_for_messenger,
1267
+					$active_messenger->name
1268
+				)
1269
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1270
+						$active_messenger->name,
1271
+						$default_message_type_name_for_messenger
1272
+					)
1273
+					|| ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1274
+				) {
1275
+					continue;
1276
+				}
1277
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1278
+			}
1279
+			// let's activate!
1280
+			$message_resource_manager->ensure_message_types_are_active(
1281
+				$default_message_type_names_to_activate,
1282
+				$active_messenger->name,
1283
+				false
1284
+			);
1285
+			// activate the templates for these message types
1286
+			if (! empty($default_message_type_names_to_activate)) {
1287
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1288
+					$active_messenger->name,
1289
+					$default_message_type_names_for_messenger,
1290
+					'',
1291
+					true
1292
+				);
1293
+			}
1294
+		}
1295
+		return $templates_created;
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * This will activate and generate default messengers and default message types for those messengers.
1302
+	 *
1303
+	 * @param EE_message_Resource_Manager $message_resource_manager
1304
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1305
+	 *                     False means that there were no templates generated
1306
+	 *                     (which could simply mean there are no default message types for a messenger).
1307
+	 * @throws EE_Error
1308
+	 */
1309
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1310
+		EE_Message_Resource_Manager $message_resource_manager
1311
+	) {
1312
+		/** @type EE_messenger[] $messengers_to_generate */
1313
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1314
+		$installed_message_types = $message_resource_manager->installed_message_types();
1315
+		$templates_generated = false;
1316
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1317
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1318
+			// verify the default message types match an installed message type.
1319
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1320
+				if (! isset($installed_message_types[ $name ])
1321
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1322
+						$name,
1323
+						$messenger_to_generate->name
1324
+					)
1325
+				) {
1326
+					unset($default_message_type_names_for_messenger[ $key ]);
1327
+				}
1328
+			}
1329
+			// in previous iterations, the active_messengers option in the db
1330
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1331
+			// This comment is left here just in case we discover that we _do_ need to update before
1332
+			// passing off to create templates (after the refactor is done).
1333
+			// @todo remove this comment when determined not necessary.
1334
+			$message_resource_manager->activate_messenger(
1335
+				$messenger_to_generate->name,
1336
+				$default_message_type_names_for_messenger,
1337
+				false
1338
+			);
1339
+			// create any templates needing created (or will reactivate templates already generated as necessary).
1340
+			if (! empty($default_message_type_names_for_messenger)) {
1341
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1342
+					$messenger_to_generate->name,
1343
+					$default_message_type_names_for_messenger,
1344
+					'',
1345
+					true
1346
+				);
1347
+			}
1348
+		}
1349
+		return $templates_generated;
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * This returns the default messengers to generate templates for on activation of EE.
1355
+	 * It considers:
1356
+	 * - whether a messenger is already active in the db.
1357
+	 * - whether a messenger has been made active at any time in the past.
1358
+	 *
1359
+	 * @static
1360
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1361
+	 * @return EE_messenger[]
1362
+	 */
1363
+	protected static function _get_default_messengers_to_generate_on_activation(
1364
+		EE_Message_Resource_Manager $message_resource_manager
1365
+	) {
1366
+		$active_messengers    = $message_resource_manager->active_messengers();
1367
+		$installed_messengers = $message_resource_manager->installed_messengers();
1368
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1369
+
1370
+		$messengers_to_generate = array();
1371
+		foreach ($installed_messengers as $installed_messenger) {
1372
+			// if installed messenger is a messenger that should be activated on install
1373
+			// and is not already active
1374
+			// and has never been activated
1375
+			if (! $installed_messenger->activate_on_install
1376
+				|| isset($active_messengers[ $installed_messenger->name ])
1377
+				|| isset($has_activated[ $installed_messenger->name ])
1378
+			) {
1379
+				continue;
1380
+			}
1381
+			$messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1382
+		}
1383
+		return $messengers_to_generate;
1384
+	}
1385
+
1386
+
1387
+	/**
1388
+	 * This simply validates active message types to ensure they actually match installed
1389
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1390
+	 * rows are set inactive.
1391
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1392
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1393
+	 * are still handled in here.
1394
+	 *
1395
+	 * @since 4.3.1
1396
+	 * @return void
1397
+	 */
1398
+	public static function validate_messages_system()
1399
+	{
1400
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1401
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1402
+		$message_resource_manager->validate_active_message_types_are_installed();
1403
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * create_no_ticket_prices_array
1409
+	 *
1410
+	 * @access public
1411
+	 * @static
1412
+	 * @return void
1413
+	 */
1414
+	public static function create_no_ticket_prices_array()
1415
+	{
1416
+		// this creates an array for tracking events that have no active ticket prices created
1417
+		// this allows us to warn admins of the situation so that it can be corrected
1418
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1419
+		if (! $espresso_no_ticket_prices) {
1420
+			add_option('ee_no_ticket_prices', array(), '', false);
1421
+		}
1422
+	}
1423
+
1424
+
1425
+	/**
1426
+	 * plugin_deactivation
1427
+	 *
1428
+	 * @access public
1429
+	 * @static
1430
+	 * @return void
1431
+	 */
1432
+	public static function plugin_deactivation()
1433
+	{
1434
+	}
1435
+
1436
+
1437
+	/**
1438
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1439
+	 * (like post meta or term relations)
1440
+	 *
1441
+	 * @global wpdb $wpdb
1442
+	 * @throws \EE_Error
1443
+	 */
1444
+	public static function delete_all_espresso_cpt_data()
1445
+	{
1446
+		global $wpdb;
1447
+		// get all the CPT post_types
1448
+		$ee_post_types = array();
1449
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1450
+			if (method_exists($model_name, 'instance')) {
1451
+				$model_obj = call_user_func(array($model_name, 'instance'));
1452
+				if ($model_obj instanceof EEM_CPT_Base) {
1453
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1454
+				}
1455
+			}
1456
+		}
1457
+		// get all our CPTs
1458
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1459
+		$cpt_ids = $wpdb->get_col($query);
1460
+		// delete each post meta and term relations too
1461
+		foreach ($cpt_ids as $post_id) {
1462
+			wp_delete_post($post_id, true);
1463
+		}
1464
+	}
1465
+
1466
+	/**
1467
+	 * Deletes all EE custom tables
1468
+	 *
1469
+	 * @return array
1470
+	 */
1471
+	public static function drop_espresso_tables()
1472
+	{
1473
+		$tables = array();
1474
+		// load registry
1475
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1476
+			if (method_exists($model_name, 'instance')) {
1477
+				$model_obj = call_user_func(array($model_name, 'instance'));
1478
+				if ($model_obj instanceof EEM_Base) {
1479
+					foreach ($model_obj->get_tables() as $table) {
1480
+						if (strpos($table->get_table_name(), 'esp_')
1481
+							&&
1482
+							(
1483
+								is_main_site()// main site? nuke them all
1484
+								|| ! $table->is_global()// not main site,but not global either. nuke it
1485
+							)
1486
+						) {
1487
+							$tables[ $table->get_table_name() ] = $table->get_table_name();
1488
+						}
1489
+					}
1490
+				}
1491
+			}
1492
+		}
1493
+
1494
+		// there are some tables whose models were removed.
1495
+		// they should be removed when removing all EE core's data
1496
+		$tables_without_models = array(
1497
+			'esp_promotion',
1498
+			'esp_promotion_applied',
1499
+			'esp_promotion_object',
1500
+			'esp_promotion_rule',
1501
+			'esp_rule',
1502
+		);
1503
+		foreach ($tables_without_models as $table) {
1504
+			$tables[ $table ] = $table;
1505
+		}
1506
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1507
+	}
1508
+
1509
+
1510
+
1511
+	/**
1512
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1513
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1514
+	 * Returns the list actually deleted
1515
+	 *
1516
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1517
+	 * @global WPDB $wpdb
1518
+	 * @param array $table_names
1519
+	 * @return array of table names which we deleted
1520
+	 */
1521
+	public static function drop_tables($table_names)
1522
+	{
1523
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1524
+	}
1525
+
1526
+
1527
+
1528
+	/**
1529
+	 * plugin_uninstall
1530
+	 *
1531
+	 * @access public
1532
+	 * @static
1533
+	 * @param bool $remove_all
1534
+	 * @return void
1535
+	 */
1536
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1537
+	{
1538
+		global $wpdb;
1539
+		self::drop_espresso_tables();
1540
+		$wp_options_to_delete = array(
1541
+			'ee_no_ticket_prices'                => true,
1542
+			'ee_active_messengers'               => true,
1543
+			'ee_has_activated_messenger'         => true,
1544
+			RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1545
+			'ee_config'                          => false,
1546
+			'ee_data_migration_current_db_state' => true,
1547
+			'ee_data_migration_mapping_'         => false,
1548
+			'ee_data_migration_script_'          => false,
1549
+			'ee_data_migrations'                 => true,
1550
+			'ee_dms_map'                         => false,
1551
+			'ee_notices'                         => true,
1552
+			'lang_file_check_'                   => false,
1553
+			'ee_maintenance_mode'                => true,
1554
+			'ee_ueip_optin'                      => true,
1555
+			'ee_ueip_has_notified'               => true,
1556
+			'ee_plugin_activation_errors'        => true,
1557
+			'ee_id_mapping_from'                 => false,
1558
+			'espresso_persistent_admin_notices'  => true,
1559
+			'ee_encryption_key'                  => true,
1560
+			'pue_force_upgrade_'                 => false,
1561
+			'pue_json_error_'                    => false,
1562
+			'pue_install_key_'                   => false,
1563
+			'pue_verification_error_'            => false,
1564
+			'pu_dismissed_upgrade_'              => false,
1565
+			'external_updates-'                  => false,
1566
+			'ee_extra_data'                      => true,
1567
+			'ee_ssn_'                            => false,
1568
+			'ee_rss_'                            => false,
1569
+			'ee_rte_n_tx_'                       => false,
1570
+			'ee_pers_admin_notices'              => true,
1571
+			'ee_job_parameters_'                 => false,
1572
+			'ee_upload_directories_incomplete'   => true,
1573
+			'ee_verified_db_collations'          => true,
1574
+		);
1575
+		if (is_main_site()) {
1576
+			$wp_options_to_delete['ee_network_config'] = true;
1577
+		}
1578
+		$undeleted_options = array();
1579
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1580
+			if ($no_wildcard) {
1581
+				if (! delete_option($option_name)) {
1582
+					$undeleted_options[] = $option_name;
1583
+				}
1584
+			} else {
1585
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1586
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1587
+					if (! delete_option($option_name_from_wildcard)) {
1588
+						$undeleted_options[] = $option_name_from_wildcard;
1589
+					}
1590
+				}
1591
+			}
1592
+		}
1593
+		// also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1594
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1595
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1596
+			$db_update_sans_ee4 = array();
1597
+			foreach ($espresso_db_update as $version => $times_activated) {
1598
+				if ((string) $version[0] === '3') {// if its NON EE4
1599
+					$db_update_sans_ee4[ $version ] = $times_activated;
1600
+				}
1601
+			}
1602
+			update_option('espresso_db_update', $db_update_sans_ee4);
1603
+		}
1604
+		$errors = '';
1605
+		if (! empty($undeleted_options)) {
1606
+			$errors .= sprintf(
1607
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1608
+				'<br/>',
1609
+				implode(',<br/>', $undeleted_options)
1610
+			);
1611
+		}
1612
+		if (! empty($errors)) {
1613
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1614
+		}
1615
+	}
1616
+
1617
+	/**
1618
+	 * Gets the mysql error code from the last used query by wpdb
1619
+	 *
1620
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1621
+	 */
1622
+	public static function last_wpdb_error_code()
1623
+	{
1624
+		// phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved
1625
+		global $wpdb;
1626
+		if ($wpdb->use_mysqli) {
1627
+			return mysqli_errno($wpdb->dbh);
1628
+		} else {
1629
+			return mysql_errno($wpdb->dbh);
1630
+		}
1631
+		// phpcs:enable
1632
+	}
1633
+
1634
+	/**
1635
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1636
+	 *
1637
+	 * @global wpdb  $wpdb
1638
+	 * @deprecated instead use TableAnalysis::tableExists()
1639
+	 * @param string $table_name with or without $wpdb->prefix
1640
+	 * @return boolean
1641
+	 */
1642
+	public static function table_exists($table_name)
1643
+	{
1644
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1645
+	}
1646
+
1647
+	/**
1648
+	 * Resets the cache on EEH_Activation
1649
+	 */
1650
+	public static function reset()
1651
+	{
1652
+		self::$_default_creator_id                             = null;
1653
+		self::$_initialized_db_content_already_in_this_request = false;
1654
+	}
1655 1655
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public static function getTableAnalysis()
56 56
     {
57
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
57
+        if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
58 58
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
59 59
         }
60 60
         return self::$table_analysis;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public static function getTableManager()
68 68
     {
69
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
69
+        if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
70 70
             self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
71 71
         }
72 72
         return self::$table_manager;
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         if ($which_to_include === 'old') {
181 181
             $cron_tasks = array_filter(
182 182
                 $cron_tasks,
183
-                function ($value) {
183
+                function($value) {
184 184
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
185 185
                 }
186 186
             );
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
     {
211 211
 
212 212
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
213
-            if (! wp_next_scheduled($hook_name)) {
213
+            if ( ! wp_next_scheduled($hook_name)) {
214 214
                 /**
215 215
                  * This allows client code to define the initial start timestamp for this schedule.
216 216
                  */
@@ -261,15 +261,15 @@  discard block
 block discarded – undo
261 261
         foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
262 262
             if (is_array($hooks_to_fire_at_time)) {
263 263
                 foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
264
-                    if (isset($ee_cron_tasks_to_remove[ $hook_name ])
265
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
264
+                    if (isset($ee_cron_tasks_to_remove[$hook_name])
265
+                        && is_array($ee_cron_tasks_to_remove[$hook_name])
266 266
                     ) {
267
-                        unset($crons[ $timestamp ][ $hook_name ]);
267
+                        unset($crons[$timestamp][$hook_name]);
268 268
                     }
269 269
                 }
270 270
                 // also take care of any empty cron timestamps.
271 271
                 if (empty($hooks_to_fire_at_time)) {
272
-                    unset($crons[ $timestamp ]);
272
+                    unset($crons[$timestamp]);
273 273
                 }
274 274
             }
275 275
         }
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             3
315 315
         );
316 316
         // EE_Config::reset();
317
-        if (! EE_Config::logging_enabled()) {
317
+        if ( ! EE_Config::logging_enabled()) {
318 318
             delete_option(EE_Config::LOG_NAME);
319 319
         }
320 320
     }
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
     public static function load_calendar_config()
330 330
     {
331 331
         // grab array of all plugin folders and loop thru it
332
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
332
+        $plugins = glob(WP_PLUGIN_DIR.'/*', GLOB_ONLYDIR);
333 333
         if (empty($plugins)) {
334 334
             return;
335 335
         }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
                 || strpos($plugin, 'calendar') !== false
346 346
             ) {
347 347
                 // this is what we are looking for
348
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
348
+                $calendar_config = $plugin_path.'/EE_Calendar_Config.php';
349 349
                 // does it exist in this folder ?
350 350
                 if (is_readable($calendar_config)) {
351 351
                     // YEAH! let's load it
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
             ) {
473 473
                 // update Config with post ID
474 474
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
475
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
475
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
476 476
                     $msg = __(
477 477
                         'The Event Espresso critical page configuration settings could not be updated.',
478 478
                         'event_espresso'
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
                         'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
496 496
                         'event_espresso'
497 497
                     ),
498
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
498
+                    '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'
499 499
                     . __('Event Espresso Critical Pages Settings', 'event_espresso')
500 500
                     . '</a>'
501 501
                 )
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
     public static function get_page_by_ee_shortcode($ee_shortcode)
522 522
     {
523 523
         global $wpdb;
524
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
524
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
525 525
         $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
526 526
         if ($post_id) {
527 527
             return get_post($post_id);
@@ -547,11 +547,11 @@  discard block
 block discarded – undo
547 547
             'post_status'    => 'publish',
548 548
             'post_type'      => 'page',
549 549
             'comment_status' => 'closed',
550
-            'post_content'   => '[' . $critical_page['code'] . ']',
550
+            'post_content'   => '['.$critical_page['code'].']',
551 551
         );
552 552
 
553 553
         $post_id = wp_insert_post($post_args);
554
-        if (! $post_id) {
554
+        if ( ! $post_id) {
555 555
             $msg = sprintf(
556 556
                 __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
557 557
                 $critical_page['name']
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
             return $critical_page;
561 561
         }
562 562
         // get newly created post's details
563
-        if (! $critical_page['post'] = get_post($post_id)) {
563
+        if ( ! $critical_page['post'] = get_post($post_id)) {
564 564
             $msg = sprintf(
565 565
                 __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
566 566
                 $critical_page['name']
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
     public static function get_default_creator_id()
586 586
     {
587 587
         global $wpdb;
588
-        if (! empty(self::$_default_creator_id)) {
588
+        if ( ! empty(self::$_default_creator_id)) {
589 589
             return self::$_default_creator_id;
590 590
         }/**/
591 591
         $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
         $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
602 602
         $query = $wpdb->prepare(
603 603
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
604
-            '%' . $role_to_check . '%'
604
+            '%'.$role_to_check.'%'
605 605
         );
606 606
         $user_id = $wpdb->get_var($query);
607 607
         $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
             return;
641 641
         }
642 642
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
643
-        if (! function_exists('dbDelta')) {
644
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
643
+        if ( ! function_exists('dbDelta')) {
644
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
645 645
         }
646 646
         $tableAnalysis = \EEH_Activation::getTableAnalysis();
647 647
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
             // ok, delete the table... but ONLY if it's empty
651 651
             $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
652 652
             // table is NOT empty, are you SURE you want to delete this table ???
653
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
653
+            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
654 654
                 \EEH_Activation::getTableManager()->dropTable($wp_table_name);
655
-            } elseif (! $deleted_safely) {
655
+            } elseif ( ! $deleted_safely) {
656 656
                 // so we should be more cautious rather than just dropping tables so easily
657 657
                 error_log(
658 658
                     sprintf(
@@ -852,13 +852,13 @@  discard block
 block discarded – undo
852 852
             // reset values array
853 853
             $QSG_values = array();
854 854
             // 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)
855
-            if (! in_array("$QSG_system", $question_groups)) {
855
+            if ( ! in_array("$QSG_system", $question_groups)) {
856 856
                 // add it
857 857
                 switch ($QSG_system) {
858 858
                     case 1:
859 859
                         $QSG_values = array(
860 860
                             'QSG_name'            => __('Personal Information', 'event_espresso'),
861
-                            'QSG_identifier'      => 'personal-information-' . time(),
861
+                            'QSG_identifier'      => 'personal-information-'.time(),
862 862
                             'QSG_desc'            => '',
863 863
                             'QSG_order'           => 1,
864 864
                             'QSG_show_group_name' => 1,
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
                     case 2:
871 871
                         $QSG_values = array(
872 872
                             'QSG_name'            => __('Address Information', 'event_espresso'),
873
-                            'QSG_identifier'      => 'address-information-' . time(),
873
+                            'QSG_identifier'      => 'address-information-'.time(),
874 874
                             'QSG_desc'            => '',
875 875
                             'QSG_order'           => 2,
876 876
                             'QSG_show_group_name' => 1,
@@ -881,14 +881,14 @@  discard block
 block discarded – undo
881 881
                         break;
882 882
                 }
883 883
                 // make sure we have some values before inserting them
884
-                if (! empty($QSG_values)) {
884
+                if ( ! empty($QSG_values)) {
885 885
                     // insert system question
886 886
                     $wpdb->insert(
887 887
                         $table_name,
888 888
                         $QSG_values,
889 889
                         array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
890 890
                     );
891
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
891
+                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
892 892
                 }
893 893
             }
894 894
         }
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
             // reset values array
919 919
             $QST_values = array();
920 920
             // if we don't have what we should have
921
-            if (! in_array($QST_system, $questions)) {
921
+            if ( ! in_array($QST_system, $questions)) {
922 922
                 // add it
923 923
                 switch ($QST_system) {
924 924
                     case 'fname':
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
                         );
1071 1071
                         break;
1072 1072
                 }
1073
-                if (! empty($QST_values)) {
1073
+                if ( ! empty($QST_values)) {
1074 1074
                     // insert system question
1075 1075
                     $wpdb->insert(
1076 1076
                         $table_name,
@@ -1084,8 +1084,8 @@  discard block
 block discarded – undo
1084 1084
                     } else {
1085 1085
                         $system_question_we_want = EEM_Question_Group::system_address;
1086 1086
                     }
1087
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1088
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1087
+                    if (isset($QSG_IDs[$system_question_we_want])) {
1088
+                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1089 1089
                     } else {
1090 1090
                         $id_col = EEM_Question_Group::instance()
1091 1091
                                                     ->get_col(array(array('QSG_system' => $system_question_we_want)));
@@ -1133,7 +1133,7 @@  discard block
 block discarded – undo
1133 1133
      */
1134 1134
     public static function insert_default_payment_methods()
1135 1135
     {
1136
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1136
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1137 1137
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1138 1138
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1139 1139
         } else {
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
                         $active_messenger->name,
1271 1271
                         $default_message_type_name_for_messenger
1272 1272
                     )
1273
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1273
+                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1274 1274
                 ) {
1275 1275
                     continue;
1276 1276
                 }
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
                 false
1284 1284
             );
1285 1285
             // activate the templates for these message types
1286
-            if (! empty($default_message_type_names_to_activate)) {
1286
+            if ( ! empty($default_message_type_names_to_activate)) {
1287 1287
                 $templates_created = EEH_MSG_Template::generate_new_templates(
1288 1288
                     $active_messenger->name,
1289 1289
                     $default_message_type_names_for_messenger,
@@ -1317,13 +1317,13 @@  discard block
 block discarded – undo
1317 1317
             $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1318 1318
             // verify the default message types match an installed message type.
1319 1319
             foreach ($default_message_type_names_for_messenger as $key => $name) {
1320
-                if (! isset($installed_message_types[ $name ])
1320
+                if ( ! isset($installed_message_types[$name])
1321 1321
                     || $message_resource_manager->has_message_type_been_activated_for_messenger(
1322 1322
                         $name,
1323 1323
                         $messenger_to_generate->name
1324 1324
                     )
1325 1325
                 ) {
1326
-                    unset($default_message_type_names_for_messenger[ $key ]);
1326
+                    unset($default_message_type_names_for_messenger[$key]);
1327 1327
                 }
1328 1328
             }
1329 1329
             // in previous iterations, the active_messengers option in the db
@@ -1337,7 +1337,7 @@  discard block
 block discarded – undo
1337 1337
                 false
1338 1338
             );
1339 1339
             // create any templates needing created (or will reactivate templates already generated as necessary).
1340
-            if (! empty($default_message_type_names_for_messenger)) {
1340
+            if ( ! empty($default_message_type_names_for_messenger)) {
1341 1341
                 $templates_generated = EEH_MSG_Template::generate_new_templates(
1342 1342
                     $messenger_to_generate->name,
1343 1343
                     $default_message_type_names_for_messenger,
@@ -1372,13 +1372,13 @@  discard block
 block discarded – undo
1372 1372
             // if installed messenger is a messenger that should be activated on install
1373 1373
             // and is not already active
1374 1374
             // and has never been activated
1375
-            if (! $installed_messenger->activate_on_install
1376
-                || isset($active_messengers[ $installed_messenger->name ])
1377
-                || isset($has_activated[ $installed_messenger->name ])
1375
+            if ( ! $installed_messenger->activate_on_install
1376
+                || isset($active_messengers[$installed_messenger->name])
1377
+                || isset($has_activated[$installed_messenger->name])
1378 1378
             ) {
1379 1379
                 continue;
1380 1380
             }
1381
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1381
+            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1382 1382
         }
1383 1383
         return $messengers_to_generate;
1384 1384
     }
@@ -1416,7 +1416,7 @@  discard block
 block discarded – undo
1416 1416
         // this creates an array for tracking events that have no active ticket prices created
1417 1417
         // this allows us to warn admins of the situation so that it can be corrected
1418 1418
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1419
-        if (! $espresso_no_ticket_prices) {
1419
+        if ( ! $espresso_no_ticket_prices) {
1420 1420
             add_option('ee_no_ticket_prices', array(), '', false);
1421 1421
         }
1422 1422
     }
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
             }
1456 1456
         }
1457 1457
         // get all our CPTs
1458
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1458
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1459 1459
         $cpt_ids = $wpdb->get_col($query);
1460 1460
         // delete each post meta and term relations too
1461 1461
         foreach ($cpt_ids as $post_id) {
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
                                 || ! $table->is_global()// not main site,but not global either. nuke it
1485 1485
                             )
1486 1486
                         ) {
1487
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1487
+                            $tables[$table->get_table_name()] = $table->get_table_name();
1488 1488
                         }
1489 1489
                     }
1490 1490
                 }
@@ -1501,7 +1501,7 @@  discard block
 block discarded – undo
1501 1501
             'esp_rule',
1502 1502
         );
1503 1503
         foreach ($tables_without_models as $table) {
1504
-            $tables[ $table ] = $table;
1504
+            $tables[$table] = $table;
1505 1505
         }
1506 1506
         return \EEH_Activation::getTableManager()->dropTables($tables);
1507 1507
     }
@@ -1578,13 +1578,13 @@  discard block
 block discarded – undo
1578 1578
         $undeleted_options = array();
1579 1579
         foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1580 1580
             if ($no_wildcard) {
1581
-                if (! delete_option($option_name)) {
1581
+                if ( ! delete_option($option_name)) {
1582 1582
                     $undeleted_options[] = $option_name;
1583 1583
                 }
1584 1584
             } else {
1585 1585
                 $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1586 1586
                 foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1587
-                    if (! delete_option($option_name_from_wildcard)) {
1587
+                    if ( ! delete_option($option_name_from_wildcard)) {
1588 1588
                         $undeleted_options[] = $option_name_from_wildcard;
1589 1589
                     }
1590 1590
                 }
@@ -1596,20 +1596,20 @@  discard block
 block discarded – undo
1596 1596
             $db_update_sans_ee4 = array();
1597 1597
             foreach ($espresso_db_update as $version => $times_activated) {
1598 1598
                 if ((string) $version[0] === '3') {// if its NON EE4
1599
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1599
+                    $db_update_sans_ee4[$version] = $times_activated;
1600 1600
                 }
1601 1601
             }
1602 1602
             update_option('espresso_db_update', $db_update_sans_ee4);
1603 1603
         }
1604 1604
         $errors = '';
1605
-        if (! empty($undeleted_options)) {
1605
+        if ( ! empty($undeleted_options)) {
1606 1606
             $errors .= sprintf(
1607 1607
                 __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1608 1608
                 '<br/>',
1609 1609
                 implode(',<br/>', $undeleted_options)
1610 1610
             );
1611 1611
         }
1612
-        if (! empty($errors)) {
1612
+        if ( ! empty($errors)) {
1613 1613
             EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1614 1614
         }
1615 1615
     }
Please login to merge, or discard this patch.
core/EE_Config.core.php 2 patches
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     public static function instance()
146 146
     {
147 147
         // check if class object is instantiated, and instantiated properly
148
-        if (! self::$_instance instanceof EE_Config) {
148
+        if ( ! self::$_instance instanceof EE_Config) {
149 149
             self::$_instance = new self();
150 150
         }
151 151
         return self::$_instance;
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 $this
284 284
             );
285 285
             if (is_object($settings) && property_exists($this, $config)) {
286
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
286
+                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings);
287 287
                 // call configs populate method to ensure any defaults are set for empty values.
288 288
                 if (method_exists($settings, 'populate')) {
289 289
                     $this->{$config}->populate();
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
                         break;
557 557
                     // TEST #2 : check that settings section exists
558 558
                     case 2:
559
-                        if (! isset($this->{$section})) {
559
+                        if ( ! isset($this->{$section})) {
560 560
                             if ($display_errors) {
561 561
                                 throw new EE_Error(
562 562
                                     sprintf(
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
                         break;
571 571
                     // TEST #3 : check that section is the proper format
572 572
                     case 3:
573
-                        if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
573
+                        if ( ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574 574
                         ) {
575 575
                             if ($display_errors) {
576 576
                                 throw new EE_Error(
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
                         break;
617 617
                     // TEST #6 : verify config class is accessible
618 618
                     case 6:
619
-                        if (! class_exists($config_class)) {
619
+                        if ( ! class_exists($config_class)) {
620 620
                             if ($display_errors) {
621 621
                                 throw new EE_Error(
622 622
                                     sprintf(
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
                         break;
634 634
                     // TEST #7 : check that config has even been set
635 635
                     case 7:
636
-                        if (! isset($this->{$section}->{$name})) {
636
+                        if ( ! isset($this->{$section}->{$name})) {
637 637
                             if ($display_errors) {
638 638
                                 throw new EE_Error(
639 639
                                     sprintf(
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
                         break;
652 652
                     // TEST #8 : check that config is the requested type
653 653
                     case 8:
654
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
654
+                        if ( ! $this->{$section}->{$name} instanceof $config_class) {
655 655
                             if ($display_errors) {
656 656
                                 throw new EE_Error(
657 657
                                     sprintf(
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
                         break;
671 671
                     // TEST #9 : verify config object
672 672
                     case 9:
673
-                        if (! $config_obj instanceof EE_Config_Base) {
673
+                        if ( ! $config_obj instanceof EE_Config_Base) {
674 674
                             if ($display_errors) {
675 675
                                 throw new EE_Error(
676 676
                                     sprintf(
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
      */
703 703
     private function _generate_config_option_name($section = '', $name = '')
704 704
     {
705
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
705
+        return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name));
706 706
     }
707 707
 
708 708
 
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
     {
720 720
         return ! empty($config_class)
721 721
             ? $config_class
722
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
722
+            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config';
723 723
     }
724 724
 
725 725
 
@@ -738,17 +738,17 @@  discard block
 block discarded – undo
738 738
         // ensure config class is set to something
739 739
         $config_class = $this->_set_config_class($config_class, $name);
740 740
         // run tests 1-4, 6, and 7 to verify all config params are set and valid
741
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
741
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742 742
             return null;
743 743
         }
744 744
         $config_option_name = $this->_generate_config_option_name($section, $name);
745 745
         // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
746
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
747
+            $this->_addon_option_names[$config_option_name] = $config_class;
748 748
             $this->update_addon_option_names();
749 749
         }
750 750
         // verify the incoming config object but suppress errors
751
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
751
+        if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752 752
             $config_obj = new $config_class();
753 753
         }
754 754
         if (get_option($config_option_name)) {
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
         // get class name of the incoming object
796 796
         $config_class = get_class($config_obj);
797 797
         // run tests 1-5 and 9 to verify config
798
-        if (! $this->_verify_config_params(
798
+        if ( ! $this->_verify_config_params(
799 799
             $section,
800 800
             $name,
801 801
             $config_class,
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
         }
808 808
         $config_option_name = $this->_generate_config_option_name($section, $name);
809 809
         // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
810
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
811 811
             // save new config to db
812 812
             if ($this->set_config($section, $name, $config_class, $config_obj)) {
813 813
                 return true;
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
                             'event_espresso'
834 834
                         ),
835 835
                         $config_class,
836
-                        'EE_Config->' . $section . '->' . $name
836
+                        'EE_Config->'.$section.'->'.$name
837 837
                     ),
838 838
                     __FILE__,
839 839
                     __FUNCTION__,
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
         // ensure config class is set to something
860 860
         $config_class = $this->_set_config_class($config_class, $name);
861 861
         // run tests 1-4, 6 and 7 to verify that all params have been set
862
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
862
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863 863
             return null;
864 864
         }
865 865
         // now test if the requested config object exists, but suppress errors
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
         // retrieve the wp-option for this config class.
905 905
         $config_option = maybe_unserialize(get_option($config_option_name, array()));
906 906
         if (empty($config_option)) {
907
-            EE_Config::log($config_option_name . '-NOT-FOUND');
907
+            EE_Config::log($config_option_name.'-NOT-FOUND');
908 908
         }
909 909
         return $config_option;
910 910
     }
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
             // copy incoming $_REQUEST and sanitize it so we can save it
923 923
             $_request = $_REQUEST;
924 924
             array_walk_recursive($_request, 'sanitize_text_field');
925
-            $config_log[ (string) microtime(true) ] = array(
925
+            $config_log[(string) microtime(true)] = array(
926 926
                 'config_name' => $config_option_name,
927 927
                 'request'     => $_request,
928 928
             );
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
      */
938 938
     public static function trim_log()
939 939
     {
940
-        if (! EE_Config::logging_enabled()) {
940
+        if ( ! EE_Config::logging_enabled()) {
941 941
             return;
942 942
         }
943 943
         $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
     public static function get_page_for_posts()
962 962
     {
963 963
         $page_for_posts = get_option('page_for_posts');
964
-        if (! $page_for_posts) {
964
+        if ( ! $page_for_posts) {
965 965
             return 'posts';
966 966
         }
967 967
         /** @type WPDB $wpdb */
@@ -1011,20 +1011,20 @@  discard block
 block discarded – undo
1011 1011
     {
1012 1012
         // only init widgets on admin pages when not in complete maintenance, and
1013 1013
         // on frontend when not in any maintenance mode
1014
-        if (! EE_Maintenance_Mode::instance()->level()
1014
+        if ( ! EE_Maintenance_Mode::instance()->level()
1015 1015
             || (
1016 1016
                 is_admin()
1017 1017
                 && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018 1018
             )
1019 1019
         ) {
1020 1020
             // grab list of installed widgets
1021
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1021
+            $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR);
1022 1022
             // filter list of modules to register
1023 1023
             $widgets_to_register = apply_filters(
1024 1024
                 'FHEE__EE_Config__register_widgets__widgets_to_register',
1025 1025
                 $widgets_to_register
1026 1026
             );
1027
-            if (! empty($widgets_to_register)) {
1027
+            if ( ! empty($widgets_to_register)) {
1028 1028
                 // cycle thru widget folders
1029 1029
                 foreach ($widgets_to_register as $widget_path) {
1030 1030
                     // add to list of installed widget modules
@@ -1074,31 +1074,31 @@  discard block
 block discarded – undo
1074 1074
         // create classname from widget directory name
1075 1075
         $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076 1076
         // add class prefix
1077
-        $widget_class = 'EEW_' . $widget;
1077
+        $widget_class = 'EEW_'.$widget;
1078 1078
         // does the widget exist ?
1079
-        if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1079
+        if ( ! is_readable($widget_path.'/'.$widget_class.$widget_ext)) {
1080 1080
             $msg = sprintf(
1081 1081
                 __(
1082 1082
                     'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083 1083
                     'event_espresso'
1084 1084
                 ),
1085 1085
                 $widget_class,
1086
-                $widget_path . '/' . $widget_class . $widget_ext
1086
+                $widget_path.'/'.$widget_class.$widget_ext
1087 1087
             );
1088
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1088
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1089 1089
             return;
1090 1090
         }
1091 1091
         // load the widget class file
1092
-        require_once($widget_path . '/' . $widget_class . $widget_ext);
1092
+        require_once($widget_path.'/'.$widget_class.$widget_ext);
1093 1093
         // verify that class exists
1094
-        if (! class_exists($widget_class)) {
1094
+        if ( ! class_exists($widget_class)) {
1095 1095
             $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1096
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1097 1097
             return;
1098 1098
         }
1099 1099
         register_widget($widget_class);
1100 1100
         // add to array of registered widgets
1101
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1101
+        EE_Registry::instance()->widgets->{$widget_class} = $widget_path.'/'.$widget_class.$widget_ext;
1102 1102
     }
1103 1103
 
1104 1104
 
@@ -1111,18 +1111,18 @@  discard block
 block discarded – undo
1111 1111
     private function _register_modules()
1112 1112
     {
1113 1113
         // grab list of installed modules
1114
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1114
+        $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR);
1115 1115
         // filter list of modules to register
1116 1116
         $modules_to_register = apply_filters(
1117 1117
             'FHEE__EE_Config__register_modules__modules_to_register',
1118 1118
             $modules_to_register
1119 1119
         );
1120
-        if (! empty($modules_to_register)) {
1120
+        if ( ! empty($modules_to_register)) {
1121 1121
             // loop through folders
1122 1122
             foreach ($modules_to_register as $module_path) {
1123 1123
                 /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
-                if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
-                    && $module_path !== EE_MODULES . 'gateways'
1124
+                if ($module_path !== EE_MODULES.'zzz-copy-this-module-template'
1125
+                    && $module_path !== EE_MODULES.'gateways'
1126 1126
                 ) {
1127 1127
                     // add to list of installed modules
1128 1128
                     EE_Config::register_module($module_path);
@@ -1159,25 +1159,25 @@  discard block
 block discarded – undo
1159 1159
             // remove last segment
1160 1160
             array_pop($module_path);
1161 1161
             // glue it back together
1162
-            $module_path = implode('/', $module_path) . '/';
1162
+            $module_path = implode('/', $module_path).'/';
1163 1163
             // take first segment from file name pieces and sanitize it
1164 1164
             $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165 1165
             // ensure class prefix is added
1166
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1166
+            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module;
1167 1167
         } else {
1168 1168
             // we need to generate the filename based off of the folder name
1169 1169
             // grab and sanitize module name
1170 1170
             $module = strtolower(basename($module_path));
1171 1171
             $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172 1172
             // like trailingslashit()
1173
-            $module_path = rtrim($module_path, '/') . '/';
1173
+            $module_path = rtrim($module_path, '/').'/';
1174 1174
             // create classname from module directory name
1175 1175
             $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176 1176
             // add class prefix
1177
-            $module_class = 'EED_' . $module;
1177
+            $module_class = 'EED_'.$module;
1178 1178
         }
1179 1179
         // does the module exist ?
1180
-        if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1180
+        if ( ! is_readable($module_path.'/'.$module_class.$module_ext)) {
1181 1181
             $msg = sprintf(
1182 1182
                 __(
1183 1183
                     'The requested %s module file could not be found or is not readable due to file permissions.',
@@ -1185,19 +1185,19 @@  discard block
 block discarded – undo
1185 1185
                 ),
1186 1186
                 $module
1187 1187
             );
1188
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1188
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1189 1189
             return false;
1190 1190
         }
1191 1191
         // load the module class file
1192
-        require_once($module_path . $module_class . $module_ext);
1192
+        require_once($module_path.$module_class.$module_ext);
1193 1193
         // verify that class exists
1194
-        if (! class_exists($module_class)) {
1194
+        if ( ! class_exists($module_class)) {
1195 1195
             $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1196
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1197 1197
             return false;
1198 1198
         }
1199 1199
         // add to array of registered modules
1200
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1200
+        EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext;
1201 1201
         do_action(
1202 1202
             'AHEE__EE_Config__register_module__complete',
1203 1203
             $module_class,
@@ -1248,26 +1248,26 @@  discard block
 block discarded – undo
1248 1248
     {
1249 1249
         do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250 1250
         $module = str_replace('EED_', '', $module);
1251
-        $module_class = 'EED_' . $module;
1252
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1251
+        $module_class = 'EED_'.$module;
1252
+        if ( ! isset(EE_Registry::instance()->modules->{$module_class})) {
1253 1253
             $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1254
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1255 1255
             return false;
1256 1256
         }
1257 1257
         if (empty($route)) {
1258 1258
             $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1259
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1260 1260
             return false;
1261 1261
         }
1262
-        if (! method_exists('EED_' . $module, $method_name)) {
1262
+        if ( ! method_exists('EED_'.$module, $method_name)) {
1263 1263
             $msg = sprintf(
1264 1264
                 __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265 1265
                 $route
1266 1266
             );
1267
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1267
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1268 1268
             return false;
1269 1269
         }
1270
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1270
+        EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name);
1271 1271
         return true;
1272 1272
     }
1273 1273
 
@@ -1284,8 +1284,8 @@  discard block
 block discarded – undo
1284 1284
     {
1285 1285
         do_action('AHEE__EE_Config__get_route__begin', $route);
1286 1286
         $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1287
+        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1288
+            return EE_Config::$_module_route_map[$key][$route];
1289 1289
         }
1290 1290
         return null;
1291 1291
     }
@@ -1317,47 +1317,47 @@  discard block
 block discarded – undo
1317 1317
     public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318 1318
     {
1319 1319
         do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1320
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1321 1321
             $msg = sprintf(
1322 1322
                 __('The module route %s for this forward has not been registered.', 'event_espresso'),
1323 1323
                 $route
1324 1324
             );
1325
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1325
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1326 1326
             return false;
1327 1327
         }
1328 1328
         if (empty($forward)) {
1329 1329
             $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1330
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1331 1331
             return false;
1332 1332
         }
1333 1333
         if (is_array($forward)) {
1334
-            if (! isset($forward[1])) {
1334
+            if ( ! isset($forward[1])) {
1335 1335
                 $msg = sprintf(
1336 1336
                     __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337 1337
                     $route
1338 1338
                 );
1339
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1339
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1340 1340
                 return false;
1341 1341
             }
1342
-            if (! method_exists($forward[0], $forward[1])) {
1342
+            if ( ! method_exists($forward[0], $forward[1])) {
1343 1343
                 $msg = sprintf(
1344 1344
                     __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345 1345
                     $forward[1],
1346 1346
                     $route
1347 1347
                 );
1348
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1348
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1349 1349
                 return false;
1350 1350
             }
1351
-        } elseif (! function_exists($forward)) {
1351
+        } elseif ( ! function_exists($forward)) {
1352 1352
             $msg = sprintf(
1353 1353
                 __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354 1354
                 $forward,
1355 1355
                 $route
1356 1356
             );
1357
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1357
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1358 1358
             return false;
1359 1359
         }
1360
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1360
+        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1361 1361
         return true;
1362 1362
     }
1363 1363
 
@@ -1375,10 +1375,10 @@  discard block
 block discarded – undo
1375 1375
     public static function get_forward($route = null, $status = 0, $key = 'ee')
1376 1376
     {
1377 1377
         do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1378
+        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1379 1379
             return apply_filters(
1380 1380
                 'FHEE__EE_Config__get_forward',
1381
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1381
+                EE_Config::$_module_forward_map[$key][$route][$status],
1382 1382
                 $route,
1383 1383
                 $status
1384 1384
             );
@@ -1402,15 +1402,15 @@  discard block
 block discarded – undo
1402 1402
     public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403 1403
     {
1404 1404
         do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1405
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1406 1406
             $msg = sprintf(
1407 1407
                 __('The module route %s for this view has not been registered.', 'event_espresso'),
1408 1408
                 $route
1409 1409
             );
1410
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1410
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1411 1411
             return false;
1412 1412
         }
1413
-        if (! is_readable($view)) {
1413
+        if ( ! is_readable($view)) {
1414 1414
             $msg = sprintf(
1415 1415
                 __(
1416 1416
                     'The %s view file could not be found or is not readable due to file permissions.',
@@ -1418,10 +1418,10 @@  discard block
 block discarded – undo
1418 1418
                 ),
1419 1419
                 $view
1420 1420
             );
1421
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1421
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1422 1422
             return false;
1423 1423
         }
1424
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1424
+        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1425 1425
         return true;
1426 1426
     }
1427 1427
 
@@ -1439,10 +1439,10 @@  discard block
 block discarded – undo
1439 1439
     public static function get_view($route = null, $status = 0, $key = 'ee')
1440 1440
     {
1441 1441
         do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1442
+        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1443 1443
             return apply_filters(
1444 1444
                 'FHEE__EE_Config__get_view',
1445
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1445
+                EE_Config::$_module_view_map[$key][$route][$status],
1446 1446
                 $route,
1447 1447
                 $status
1448 1448
             );
@@ -1469,7 +1469,7 @@  discard block
 block discarded – undo
1469 1469
     public static function getLegacyShortcodesManager()
1470 1470
     {
1471 1471
 
1472
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1472
+        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473 1473
             EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474 1474
                 EE_Registry::instance()
1475 1475
             );
@@ -1516,7 +1516,7 @@  discard block
 block discarded – undo
1516 1516
      */
1517 1517
     public function get_pretty($property)
1518 1518
     {
1519
-        if (! property_exists($this, $property)) {
1519
+        if ( ! property_exists($this, $property)) {
1520 1520
             throw new EE_Error(
1521 1521
                 sprintf(
1522 1522
                     __(
@@ -1745,11 +1745,11 @@  discard block
 block discarded – undo
1745 1745
      */
1746 1746
     public function reg_page_url()
1747 1747
     {
1748
-        if (! $this->reg_page_url) {
1748
+        if ( ! $this->reg_page_url) {
1749 1749
             $this->reg_page_url = add_query_arg(
1750 1750
                 array('uts' => time()),
1751 1751
                 get_permalink($this->reg_page_id)
1752
-            ) . '#checkout';
1752
+            ).'#checkout';
1753 1753
         }
1754 1754
         return $this->reg_page_url;
1755 1755
     }
@@ -1765,7 +1765,7 @@  discard block
 block discarded – undo
1765 1765
      */
1766 1766
     public function txn_page_url($query_args = array())
1767 1767
     {
1768
-        if (! $this->txn_page_url) {
1768
+        if ( ! $this->txn_page_url) {
1769 1769
             $this->txn_page_url = get_permalink($this->txn_page_id);
1770 1770
         }
1771 1771
         if ($query_args) {
@@ -1786,7 +1786,7 @@  discard block
 block discarded – undo
1786 1786
      */
1787 1787
     public function thank_you_page_url($query_args = array())
1788 1788
     {
1789
-        if (! $this->thank_you_page_url) {
1789
+        if ( ! $this->thank_you_page_url) {
1790 1790
             $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791 1791
         }
1792 1792
         if ($query_args) {
@@ -1805,7 +1805,7 @@  discard block
 block discarded – undo
1805 1805
      */
1806 1806
     public function cancel_page_url()
1807 1807
     {
1808
-        if (! $this->cancel_page_url) {
1808
+        if ( ! $this->cancel_page_url) {
1809 1809
             $this->cancel_page_url = get_permalink($this->cancel_page_id);
1810 1810
         }
1811 1811
         return $this->cancel_page_url;
@@ -1848,13 +1848,13 @@  discard block
 block discarded – undo
1848 1848
         $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849 1849
         $option = self::OPTION_NAME_UXIP;
1850 1850
         // set correct table for query
1851
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1851
+        $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options';
1852 1852
         // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853 1853
         // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854 1854
         // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855 1855
         // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856 1856
         // for the purpose of caching.
1857
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1857
+        $pre = apply_filters('pre_option_'.$option, false, $option);
1858 1858
         if (false !== $pre) {
1859 1859
             EE_Core_Config::$ee_ueip_option = $pre;
1860 1860
             return EE_Core_Config::$ee_ueip_option;
@@ -1868,10 +1868,10 @@  discard block
 block discarded – undo
1868 1868
         if (is_object($row)) {
1869 1869
             $value = $row->option_value;
1870 1870
         } else { // option does not exist so use default.
1871
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1871
+            EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option);
1872 1872
             return EE_Core_Config::$ee_ueip_option;
1873 1873
         }
1874
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1874
+        EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option);
1875 1875
         return EE_Core_Config::$ee_ueip_option;
1876 1876
     }
1877 1877
 
@@ -2125,37 +2125,37 @@  discard block
 block discarded – undo
2125 2125
         // but override if requested
2126 2126
         $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127 2127
         // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
-        if (! empty($CNT_ISO)
2128
+        if ( ! empty($CNT_ISO)
2129 2129
             && EE_Maintenance_Mode::instance()->models_can_query()
2130 2130
             && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131 2131
         ) {
2132 2132
             // retrieve the country settings from the db, just in case they have been customized
2133 2133
             $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134 2134
             if ($country instanceof EE_Country) {
2135
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
-                $this->name = $country->currency_name_single();    // Dollar
2137
-                $this->plural = $country->currency_name_plural();    // Dollars
2138
-                $this->sign = $country->currency_sign();            // currency sign: $
2135
+                $this->code = $country->currency_code(); // currency code: USD, CAD, EUR
2136
+                $this->name = $country->currency_name_single(); // Dollar
2137
+                $this->plural = $country->currency_name_plural(); // Dollars
2138
+                $this->sign = $country->currency_sign(); // currency sign: $
2139 2139
                 $this->sign_b4 = $country->currency_sign_before(
2140
-                );        // currency sign before or after: $TRUE  or  FALSE$
2141
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2140
+                ); // currency sign before or after: $TRUE  or  FALSE$
2141
+                $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00  3 = 0.000
2142 2142
                 $this->dec_mrk = $country->currency_decimal_mark(
2143
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2143
+                ); // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144 2144
                 $this->thsnds = $country->currency_thousands_separator(
2145
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2145
+                ); // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146 2146
             }
2147 2147
         }
2148 2148
         // fallback to hardcoded defaults, in case the above failed
2149 2149
         if (empty($this->code)) {
2150 2150
             // set default currency settings
2151
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2152
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2153
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
-            $this->sign = '$';    // currency sign: $
2155
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2151
+            $this->code = 'USD'; // currency code: USD, CAD, EUR
2152
+            $this->name = __('Dollar', 'event_espresso'); // Dollar
2153
+            $this->plural = __('Dollars', 'event_espresso'); // Dollars
2154
+            $this->sign = '$'; // currency sign: $
2155
+            $this->sign_b4 = true; // currency sign before or after: $TRUE  or  FALSE$
2156
+            $this->dec_plc = 2; // decimal places: 2 = 0.00  3 = 0.000
2157
+            $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
+            $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159 2159
         }
2160 2160
     }
2161 2161
 }
@@ -2414,8 +2414,8 @@  discard block
 block discarded – undo
2414 2414
             $closing_a_tag = '';
2415 2415
             if (function_exists('get_privacy_policy_url')) {
2416 2416
                 $privacy_page_url = get_privacy_policy_url();
2417
-                if (! empty($privacy_page_url)) {
2418
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2417
+                if ( ! empty($privacy_page_url)) {
2418
+                    $opening_a_tag = '<a href="'.$privacy_page_url.'" target="_blank">';
2419 2419
                     $closing_a_tag = '</a>';
2420 2420
                 }
2421 2421
             }
@@ -2630,7 +2630,7 @@  discard block
 block discarded – undo
2630 2630
     public function log_file_name($reset = false)
2631 2631
     {
2632 2632
         if (empty($this->log_file_name) || $reset) {
2633
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2633
+            $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt';
2634 2634
             EE_Config::instance()->update_espresso_config(false, false);
2635 2635
         }
2636 2636
         return $this->log_file_name;
@@ -2644,7 +2644,7 @@  discard block
 block discarded – undo
2644 2644
     public function debug_file_name($reset = false)
2645 2645
     {
2646 2646
         if (empty($this->debug_file_name) || $reset) {
2647
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2647
+            $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt';
2648 2648
             EE_Config::instance()->update_espresso_config(false, false);
2649 2649
         }
2650 2650
         return $this->debug_file_name;
@@ -2848,21 +2848,21 @@  discard block
 block discarded – undo
2848 2848
         $this->use_google_maps = true;
2849 2849
         $this->google_map_api_key = '';
2850 2850
         // for event details pages (reg page)
2851
-        $this->event_details_map_width = 585;            // ee_map_width_single
2852
-        $this->event_details_map_height = 362;            // ee_map_height_single
2853
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2854
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2855
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2856
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2857
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2851
+        $this->event_details_map_width = 585; // ee_map_width_single
2852
+        $this->event_details_map_height = 362; // ee_map_height_single
2853
+        $this->event_details_map_zoom = 14; // ee_map_zoom_single
2854
+        $this->event_details_display_nav = true; // ee_map_nav_display_single
2855
+        $this->event_details_nav_size = false; // ee_map_nav_size_single
2856
+        $this->event_details_control_type = 'default'; // ee_map_type_control_single
2857
+        $this->event_details_map_align = 'center'; // ee_map_align_single
2858 2858
         // for event list pages
2859
-        $this->event_list_map_width = 300;            // ee_map_width
2860
-        $this->event_list_map_height = 185;        // ee_map_height
2861
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2862
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2863
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2864
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2865
-        $this->event_list_map_align = 'center';            // ee_map_align
2859
+        $this->event_list_map_width = 300; // ee_map_width
2860
+        $this->event_list_map_height = 185; // ee_map_height
2861
+        $this->event_list_map_zoom = 12; // ee_map_zoom
2862
+        $this->event_list_display_nav = false; // ee_map_nav_display
2863
+        $this->event_list_nav_size = true; // ee_map_nav_size
2864
+        $this->event_list_control_type = 'dropdown'; // ee_map_type_control
2865
+        $this->event_list_map_align = 'center'; // ee_map_align
2866 2866
     }
2867 2867
 }
2868 2868
 
@@ -3180,7 +3180,7 @@  discard block
 block discarded – undo
3180 3180
      */
3181 3181
     public function max_input_vars_limit_check($input_count = 0)
3182 3182
     {
3183
-        if (! empty($this->php->max_input_vars)
3183
+        if ( ! empty($this->php->max_input_vars)
3184 3184
             && ($input_count >= $this->php->max_input_vars)
3185 3185
         ) {
3186 3186
             // check the server setting because the config value could be stale
Please login to merge, or discard this patch.
Indentation   +3176 added lines, -3176 removed lines patch added patch discarded remove patch
@@ -14,2509 +14,2509 @@  discard block
 block discarded – undo
14 14
 final class EE_Config implements ResettableInterface
15 15
 {
16 16
 
17
-    const OPTION_NAME = 'ee_config';
18
-
19
-    const LOG_NAME = 'ee_config_log';
20
-
21
-    const LOG_LENGTH = 100;
22
-
23
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
-
25
-    /**
26
-     *    instance of the EE_Config object
27
-     *
28
-     * @var    EE_Config $_instance
29
-     * @access    private
30
-     */
31
-    private static $_instance;
32
-
33
-    /**
34
-     * @var boolean $_logging_enabled
35
-     */
36
-    private static $_logging_enabled = false;
37
-
38
-    /**
39
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
-     */
41
-    private $legacy_shortcodes_manager;
42
-
43
-    /**
44
-     * An StdClass whose property names are addon slugs,
45
-     * and values are their config classes
46
-     *
47
-     * @var StdClass
48
-     */
49
-    public $addons;
50
-
51
-    /**
52
-     * @var EE_Admin_Config
53
-     */
54
-    public $admin;
55
-
56
-    /**
57
-     * @var EE_Core_Config
58
-     */
59
-    public $core;
60
-
61
-    /**
62
-     * @var EE_Currency_Config
63
-     */
64
-    public $currency;
65
-
66
-    /**
67
-     * @var EE_Organization_Config
68
-     */
69
-    public $organization;
70
-
71
-    /**
72
-     * @var EE_Registration_Config
73
-     */
74
-    public $registration;
75
-
76
-    /**
77
-     * @var EE_Template_Config
78
-     */
79
-    public $template_settings;
80
-
81
-    /**
82
-     * Holds EE environment values.
83
-     *
84
-     * @var EE_Environment_Config
85
-     */
86
-    public $environment;
87
-
88
-    /**
89
-     * settings pertaining to Google maps
90
-     *
91
-     * @var EE_Map_Config
92
-     */
93
-    public $map_settings;
94
-
95
-    /**
96
-     * settings pertaining to Taxes
97
-     *
98
-     * @var EE_Tax_Config
99
-     */
100
-    public $tax_settings;
101
-
102
-    /**
103
-     * Settings pertaining to global messages settings.
104
-     *
105
-     * @var EE_Messages_Config
106
-     */
107
-    public $messages;
108
-
109
-    /**
110
-     * @deprecated
111
-     * @var EE_Gateway_Config
112
-     */
113
-    public $gateway;
114
-
115
-    /**
116
-     * @var    array $_addon_option_names
117
-     * @access    private
118
-     */
119
-    private $_addon_option_names = array();
120
-
121
-    /**
122
-     * @var    array $_module_route_map
123
-     * @access    private
124
-     */
125
-    private static $_module_route_map = array();
126
-
127
-    /**
128
-     * @var    array $_module_forward_map
129
-     * @access    private
130
-     */
131
-    private static $_module_forward_map = array();
132
-
133
-    /**
134
-     * @var    array $_module_view_map
135
-     * @access    private
136
-     */
137
-    private static $_module_view_map = array();
138
-
139
-
140
-    /**
141
-     * @singleton method used to instantiate class object
142
-     * @access    public
143
-     * @return EE_Config instance
144
-     */
145
-    public static function instance()
146
-    {
147
-        // check if class object is instantiated, and instantiated properly
148
-        if (! self::$_instance instanceof EE_Config) {
149
-            self::$_instance = new self();
150
-        }
151
-        return self::$_instance;
152
-    }
153
-
154
-
155
-    /**
156
-     * Resets the config
157
-     *
158
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
159
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
160
-     *                               reflect its state in the database
161
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
162
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
163
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
164
-     *                               site was put into maintenance mode)
165
-     * @return EE_Config
166
-     */
167
-    public static function reset($hard_reset = false, $reinstantiate = true)
168
-    {
169
-        if (self::$_instance instanceof EE_Config) {
170
-            if ($hard_reset) {
171
-                self::$_instance->legacy_shortcodes_manager = null;
172
-                self::$_instance->_addon_option_names = array();
173
-                self::$_instance->_initialize_config();
174
-                self::$_instance->update_espresso_config();
175
-            }
176
-            self::$_instance->update_addon_option_names();
177
-        }
178
-        self::$_instance = null;
179
-        // we don't need to reset the static properties imo because those should
180
-        // only change when a module is added or removed. Currently we don't
181
-        // support removing a module during a request when it previously existed
182
-        if ($reinstantiate) {
183
-            return self::instance();
184
-        } else {
185
-            return null;
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     *    class constructor
192
-     *
193
-     * @access    private
194
-     */
195
-    private function __construct()
196
-    {
197
-        do_action('AHEE__EE_Config__construct__begin', $this);
198
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
199
-        // setup empty config classes
200
-        $this->_initialize_config();
201
-        // load existing EE site settings
202
-        $this->_load_core_config();
203
-        // confirm everything loaded correctly and set filtered defaults if not
204
-        $this->_verify_config();
205
-        //  register shortcodes and modules
206
-        add_action(
207
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
208
-            array($this, 'register_shortcodes_and_modules'),
209
-            999
210
-        );
211
-        //  initialize shortcodes and modules
212
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
213
-        // register widgets
214
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
215
-        // shutdown
216
-        add_action('shutdown', array($this, 'shutdown'), 10);
217
-        // construct__end hook
218
-        do_action('AHEE__EE_Config__construct__end', $this);
219
-        // hardcoded hack
220
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
221
-    }
222
-
223
-
224
-    /**
225
-     * @return boolean
226
-     */
227
-    public static function logging_enabled()
228
-    {
229
-        return self::$_logging_enabled;
230
-    }
231
-
232
-
233
-    /**
234
-     * use to get the current theme if needed from static context
235
-     *
236
-     * @return string current theme set.
237
-     */
238
-    public static function get_current_theme()
239
-    {
240
-        return isset(self::$_instance->template_settings->current_espresso_theme)
241
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
242
-    }
243
-
244
-
245
-    /**
246
-     *        _initialize_config
247
-     *
248
-     * @access private
249
-     * @return void
250
-     */
251
-    private function _initialize_config()
252
-    {
253
-        EE_Config::trim_log();
254
-        // set defaults
255
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
256
-        $this->addons = new stdClass();
257
-        // set _module_route_map
258
-        EE_Config::$_module_route_map = array();
259
-        // set _module_forward_map
260
-        EE_Config::$_module_forward_map = array();
261
-        // set _module_view_map
262
-        EE_Config::$_module_view_map = array();
263
-    }
264
-
265
-
266
-    /**
267
-     *        load core plugin configuration
268
-     *
269
-     * @access private
270
-     * @return void
271
-     */
272
-    private function _load_core_config()
273
-    {
274
-        // load_core_config__start hook
275
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
276
-        $espresso_config = $this->get_espresso_config();
277
-        foreach ($espresso_config as $config => $settings) {
278
-            // load_core_config__start hook
279
-            $settings = apply_filters(
280
-                'FHEE__EE_Config___load_core_config__config_settings',
281
-                $settings,
282
-                $config,
283
-                $this
284
-            );
285
-            if (is_object($settings) && property_exists($this, $config)) {
286
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
287
-                // call configs populate method to ensure any defaults are set for empty values.
288
-                if (method_exists($settings, 'populate')) {
289
-                    $this->{$config}->populate();
290
-                }
291
-                if (method_exists($settings, 'do_hooks')) {
292
-                    $this->{$config}->do_hooks();
293
-                }
294
-            }
295
-        }
296
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
297
-            $this->update_espresso_config();
298
-        }
299
-        // load_core_config__end hook
300
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
301
-    }
302
-
303
-
304
-    /**
305
-     *    _verify_config
306
-     *
307
-     * @access    protected
308
-     * @return    void
309
-     */
310
-    protected function _verify_config()
311
-    {
312
-        $this->core = $this->core instanceof EE_Core_Config
313
-            ? $this->core
314
-            : new EE_Core_Config();
315
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
316
-        $this->organization = $this->organization instanceof EE_Organization_Config
317
-            ? $this->organization
318
-            : new EE_Organization_Config();
319
-        $this->organization = apply_filters(
320
-            'FHEE__EE_Config___initialize_config__organization',
321
-            $this->organization
322
-        );
323
-        $this->currency = $this->currency instanceof EE_Currency_Config
324
-            ? $this->currency
325
-            : new EE_Currency_Config();
326
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
327
-        $this->registration = $this->registration instanceof EE_Registration_Config
328
-            ? $this->registration
329
-            : new EE_Registration_Config();
330
-        $this->registration = apply_filters(
331
-            'FHEE__EE_Config___initialize_config__registration',
332
-            $this->registration
333
-        );
334
-        $this->admin = $this->admin instanceof EE_Admin_Config
335
-            ? $this->admin
336
-            : new EE_Admin_Config();
337
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
339
-            ? $this->template_settings
340
-            : new EE_Template_Config();
341
-        $this->template_settings = apply_filters(
342
-            'FHEE__EE_Config___initialize_config__template_settings',
343
-            $this->template_settings
344
-        );
345
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
346
-            ? $this->map_settings
347
-            : new EE_Map_Config();
348
-        $this->map_settings = apply_filters(
349
-            'FHEE__EE_Config___initialize_config__map_settings',
350
-            $this->map_settings
351
-        );
352
-        $this->environment = $this->environment instanceof EE_Environment_Config
353
-            ? $this->environment
354
-            : new EE_Environment_Config();
355
-        $this->environment = apply_filters(
356
-            'FHEE__EE_Config___initialize_config__environment',
357
-            $this->environment
358
-        );
359
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
360
-            ? $this->tax_settings
361
-            : new EE_Tax_Config();
362
-        $this->tax_settings = apply_filters(
363
-            'FHEE__EE_Config___initialize_config__tax_settings',
364
-            $this->tax_settings
365
-        );
366
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
367
-        $this->messages = $this->messages instanceof EE_Messages_Config
368
-            ? $this->messages
369
-            : new EE_Messages_Config();
370
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
371
-            ? $this->gateway
372
-            : new EE_Gateway_Config();
373
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
374
-        $this->legacy_shortcodes_manager = null;
375
-    }
376
-
377
-
378
-    /**
379
-     *    get_espresso_config
380
-     *
381
-     * @access    public
382
-     * @return    array of espresso config stuff
383
-     */
384
-    public function get_espresso_config()
385
-    {
386
-        // grab espresso configuration
387
-        return apply_filters(
388
-            'FHEE__EE_Config__get_espresso_config__CFG',
389
-            get_option(EE_Config::OPTION_NAME, array())
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     *    double_check_config_comparison
396
-     *
397
-     * @access    public
398
-     * @param string $option
399
-     * @param        $old_value
400
-     * @param        $value
401
-     */
402
-    public function double_check_config_comparison($option = '', $old_value, $value)
403
-    {
404
-        // make sure we're checking the ee config
405
-        if ($option === EE_Config::OPTION_NAME) {
406
-            // run a loose comparison of the old value against the new value for type and properties,
407
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
408
-            if ($value != $old_value) {
409
-                // if they are NOT the same, then remove the hook,
410
-                // which means the subsequent update results will be based solely on the update query results
411
-                // the reason we do this is because, as stated above,
412
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
413
-                // this happens PRIOR to serialization and any subsequent update.
414
-                // If values are found to match their previous old value,
415
-                // then WP bails before performing any update.
416
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
417
-                // it just pulled from the db, with the one being passed to it (which will not match).
418
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
419
-                // MySQL MAY ALSO NOT perform the update because
420
-                // the string it sees in the db looks the same as the new one it has been passed!!!
421
-                // This results in the query returning an "affected rows" value of ZERO,
422
-                // which gets returned immediately by WP update_option and looks like an error.
423
-                remove_action('update_option', array($this, 'check_config_updated'));
424
-            }
425
-        }
426
-    }
427
-
428
-
429
-    /**
430
-     *    update_espresso_config
431
-     *
432
-     * @access   public
433
-     */
434
-    protected function _reset_espresso_addon_config()
435
-    {
436
-        $this->_addon_option_names = array();
437
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
438
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
439
-            if ($addon_config_obj instanceof EE_Config_Base) {
440
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
441
-            }
442
-            $this->addons->{$addon_name} = null;
443
-        }
444
-    }
445
-
446
-
447
-    /**
448
-     *    update_espresso_config
449
-     *
450
-     * @access   public
451
-     * @param   bool $add_success
452
-     * @param   bool $add_error
453
-     * @return   bool
454
-     */
455
-    public function update_espresso_config($add_success = false, $add_error = true)
456
-    {
457
-        // don't allow config updates during WP heartbeats
458
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
459
-            return false;
460
-        }
461
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
462
-        // $clone = clone( self::$_instance );
463
-        // self::$_instance = NULL;
464
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
465
-        $this->_reset_espresso_addon_config();
466
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
467
-        // but BEFORE the actual update occurs
468
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
469
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
470
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
471
-        $this->legacy_shortcodes_manager = null;
472
-        // now update "ee_config"
473
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
474
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
475
-        EE_Config::log(EE_Config::OPTION_NAME);
476
-        // if not saved... check if the hook we just added still exists;
477
-        // if it does, it means one of two things:
478
-        // that update_option bailed at the($value === $old_value) conditional,
479
-        // or...
480
-        // the db update query returned 0 rows affected
481
-        // (probably because the data  value was the same from it's perspective)
482
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
483
-        // but just means no update occurred, so don't display an error to the user.
484
-        // BUT... if update_option returns FALSE, AND the hook is missing,
485
-        // then it means that something truly went wrong
486
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
487
-        // remove our action since we don't want it in the system anymore
488
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
489
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
490
-        // self::$_instance = $clone;
491
-        // unset( $clone );
492
-        // if config remains the same or was updated successfully
493
-        if ($saved) {
494
-            if ($add_success) {
495
-                EE_Error::add_success(
496
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
497
-                    __FILE__,
498
-                    __FUNCTION__,
499
-                    __LINE__
500
-                );
501
-            }
502
-            return true;
503
-        } else {
504
-            if ($add_error) {
505
-                EE_Error::add_error(
506
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
507
-                    __FILE__,
508
-                    __FUNCTION__,
509
-                    __LINE__
510
-                );
511
-            }
512
-            return false;
513
-        }
514
-    }
515
-
516
-
517
-    /**
518
-     *    _verify_config_params
519
-     *
520
-     * @access    private
521
-     * @param    string         $section
522
-     * @param    string         $name
523
-     * @param    string         $config_class
524
-     * @param    EE_Config_Base $config_obj
525
-     * @param    array          $tests_to_run
526
-     * @param    bool           $display_errors
527
-     * @return    bool    TRUE on success, FALSE on fail
528
-     */
529
-    private function _verify_config_params(
530
-        $section = '',
531
-        $name = '',
532
-        $config_class = '',
533
-        $config_obj = null,
534
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
535
-        $display_errors = true
536
-    ) {
537
-        try {
538
-            foreach ($tests_to_run as $test) {
539
-                switch ($test) {
540
-                    // TEST #1 : check that section was set
541
-                    case 1:
542
-                        if (empty($section)) {
543
-                            if ($display_errors) {
544
-                                throw new EE_Error(
545
-                                    sprintf(
546
-                                        __(
547
-                                            'No configuration section has been provided while attempting to save "%s".',
548
-                                            'event_espresso'
549
-                                        ),
550
-                                        $config_class
551
-                                    )
552
-                                );
553
-                            }
554
-                            return false;
555
-                        }
556
-                        break;
557
-                    // TEST #2 : check that settings section exists
558
-                    case 2:
559
-                        if (! isset($this->{$section})) {
560
-                            if ($display_errors) {
561
-                                throw new EE_Error(
562
-                                    sprintf(
563
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
564
-                                        $section
565
-                                    )
566
-                                );
567
-                            }
568
-                            return false;
569
-                        }
570
-                        break;
571
-                    // TEST #3 : check that section is the proper format
572
-                    case 3:
573
-                        if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574
-                        ) {
575
-                            if ($display_errors) {
576
-                                throw new EE_Error(
577
-                                    sprintf(
578
-                                        __(
579
-                                            'The "%s" configuration settings have not been formatted correctly.',
580
-                                            'event_espresso'
581
-                                        ),
582
-                                        $section
583
-                                    )
584
-                                );
585
-                            }
586
-                            return false;
587
-                        }
588
-                        break;
589
-                    // TEST #4 : check that config section name has been set
590
-                    case 4:
591
-                        if (empty($name)) {
592
-                            if ($display_errors) {
593
-                                throw new EE_Error(
594
-                                    __(
595
-                                        'No name has been provided for the specific configuration section.',
596
-                                        'event_espresso'
597
-                                    )
598
-                                );
599
-                            }
600
-                            return false;
601
-                        }
602
-                        break;
603
-                    // TEST #5 : check that a config class name has been set
604
-                    case 5:
605
-                        if (empty($config_class)) {
606
-                            if ($display_errors) {
607
-                                throw new EE_Error(
608
-                                    __(
609
-                                        'No class name has been provided for the specific configuration section.',
610
-                                        'event_espresso'
611
-                                    )
612
-                                );
613
-                            }
614
-                            return false;
615
-                        }
616
-                        break;
617
-                    // TEST #6 : verify config class is accessible
618
-                    case 6:
619
-                        if (! class_exists($config_class)) {
620
-                            if ($display_errors) {
621
-                                throw new EE_Error(
622
-                                    sprintf(
623
-                                        __(
624
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
625
-                                            'event_espresso'
626
-                                        ),
627
-                                        $config_class
628
-                                    )
629
-                                );
630
-                            }
631
-                            return false;
632
-                        }
633
-                        break;
634
-                    // TEST #7 : check that config has even been set
635
-                    case 7:
636
-                        if (! isset($this->{$section}->{$name})) {
637
-                            if ($display_errors) {
638
-                                throw new EE_Error(
639
-                                    sprintf(
640
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
641
-                                        $section,
642
-                                        $name
643
-                                    )
644
-                                );
645
-                            }
646
-                            return false;
647
-                        } else {
648
-                            // and make sure it's not serialized
649
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
650
-                        }
651
-                        break;
652
-                    // TEST #8 : check that config is the requested type
653
-                    case 8:
654
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
655
-                            if ($display_errors) {
656
-                                throw new EE_Error(
657
-                                    sprintf(
658
-                                        __(
659
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
660
-                                            'event_espresso'
661
-                                        ),
662
-                                        $section,
663
-                                        $name,
664
-                                        $config_class
665
-                                    )
666
-                                );
667
-                            }
668
-                            return false;
669
-                        }
670
-                        break;
671
-                    // TEST #9 : verify config object
672
-                    case 9:
673
-                        if (! $config_obj instanceof EE_Config_Base) {
674
-                            if ($display_errors) {
675
-                                throw new EE_Error(
676
-                                    sprintf(
677
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
678
-                                        print_r($config_obj, true)
679
-                                    )
680
-                                );
681
-                            }
682
-                            return false;
683
-                        }
684
-                        break;
685
-                }
686
-            }
687
-        } catch (EE_Error $e) {
688
-            $e->get_error();
689
-        }
690
-        // you have successfully run the gauntlet
691
-        return true;
692
-    }
693
-
694
-
695
-    /**
696
-     *    _generate_config_option_name
697
-     *
698
-     * @access        protected
699
-     * @param        string $section
700
-     * @param        string $name
701
-     * @return        string
702
-     */
703
-    private function _generate_config_option_name($section = '', $name = '')
704
-    {
705
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
706
-    }
707
-
708
-
709
-    /**
710
-     *    _set_config_class
711
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
712
-     *
713
-     * @access    private
714
-     * @param    string $config_class
715
-     * @param    string $name
716
-     * @return    string
717
-     */
718
-    private function _set_config_class($config_class = '', $name = '')
719
-    {
720
-        return ! empty($config_class)
721
-            ? $config_class
722
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
723
-    }
724
-
725
-
726
-    /**
727
-     *    set_config
728
-     *
729
-     * @access    protected
730
-     * @param    string         $section
731
-     * @param    string         $name
732
-     * @param    string         $config_class
733
-     * @param    EE_Config_Base $config_obj
734
-     * @return    EE_Config_Base
735
-     */
736
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
737
-    {
738
-        // ensure config class is set to something
739
-        $config_class = $this->_set_config_class($config_class, $name);
740
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
741
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742
-            return null;
743
-        }
744
-        $config_option_name = $this->_generate_config_option_name($section, $name);
745
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
748
-            $this->update_addon_option_names();
749
-        }
750
-        // verify the incoming config object but suppress errors
751
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752
-            $config_obj = new $config_class();
753
-        }
754
-        if (get_option($config_option_name)) {
755
-            EE_Config::log($config_option_name);
756
-            update_option($config_option_name, $config_obj);
757
-            $this->{$section}->{$name} = $config_obj;
758
-            return $this->{$section}->{$name};
759
-        } else {
760
-            // create a wp-option for this config
761
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
762
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
763
-                return $this->{$section}->{$name};
764
-            } else {
765
-                EE_Error::add_error(
766
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
767
-                    __FILE__,
768
-                    __FUNCTION__,
769
-                    __LINE__
770
-                );
771
-                return null;
772
-            }
773
-        }
774
-    }
775
-
776
-
777
-    /**
778
-     *    update_config
779
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
780
-     *
781
-     * @access    public
782
-     * @param    string                $section
783
-     * @param    string                $name
784
-     * @param    EE_Config_Base|string $config_obj
785
-     * @param    bool                  $throw_errors
786
-     * @return    bool
787
-     */
788
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
789
-    {
790
-        // don't allow config updates during WP heartbeats
791
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
792
-            return false;
793
-        }
794
-        $config_obj = maybe_unserialize($config_obj);
795
-        // get class name of the incoming object
796
-        $config_class = get_class($config_obj);
797
-        // run tests 1-5 and 9 to verify config
798
-        if (! $this->_verify_config_params(
799
-            $section,
800
-            $name,
801
-            $config_class,
802
-            $config_obj,
803
-            array(1, 2, 3, 4, 7, 9)
804
-        )
805
-        ) {
806
-            return false;
807
-        }
808
-        $config_option_name = $this->_generate_config_option_name($section, $name);
809
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
811
-            // save new config to db
812
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
813
-                return true;
814
-            }
815
-        } else {
816
-            // first check if the record already exists
817
-            $existing_config = get_option($config_option_name);
818
-            $config_obj = serialize($config_obj);
819
-            // just return if db record is already up to date (NOT type safe comparison)
820
-            if ($existing_config == $config_obj) {
821
-                $this->{$section}->{$name} = $config_obj;
822
-                return true;
823
-            } elseif (update_option($config_option_name, $config_obj)) {
824
-                EE_Config::log($config_option_name);
825
-                // update wp-option for this config class
826
-                $this->{$section}->{$name} = $config_obj;
827
-                return true;
828
-            } elseif ($throw_errors) {
829
-                EE_Error::add_error(
830
-                    sprintf(
831
-                        __(
832
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
833
-                            'event_espresso'
834
-                        ),
835
-                        $config_class,
836
-                        'EE_Config->' . $section . '->' . $name
837
-                    ),
838
-                    __FILE__,
839
-                    __FUNCTION__,
840
-                    __LINE__
841
-                );
842
-            }
843
-        }
844
-        return false;
845
-    }
846
-
847
-
848
-    /**
849
-     *    get_config
850
-     *
851
-     * @access    public
852
-     * @param    string $section
853
-     * @param    string $name
854
-     * @param    string $config_class
855
-     * @return    mixed EE_Config_Base | NULL
856
-     */
857
-    public function get_config($section = '', $name = '', $config_class = '')
858
-    {
859
-        // ensure config class is set to something
860
-        $config_class = $this->_set_config_class($config_class, $name);
861
-        // run tests 1-4, 6 and 7 to verify that all params have been set
862
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
-            return null;
864
-        }
865
-        // now test if the requested config object exists, but suppress errors
866
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
-            // config already exists, so pass it back
868
-            return $this->{$section}->{$name};
869
-        }
870
-        // load config option from db if it exists
871
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
-        // verify the newly retrieved config object, but suppress errors
873
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
-            // config is good, so set it and pass it back
875
-            $this->{$section}->{$name} = $config_obj;
876
-            return $this->{$section}->{$name};
877
-        }
878
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
879
-        $config_obj = $this->set_config($section, $name, $config_class);
880
-        // verify the newly created config object
881
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
-            return $this->{$section}->{$name};
883
-        } else {
884
-            EE_Error::add_error(
885
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
-                __FILE__,
887
-                __FUNCTION__,
888
-                __LINE__
889
-            );
890
-        }
891
-        return null;
892
-    }
893
-
894
-
895
-    /**
896
-     *    get_config_option
897
-     *
898
-     * @access    public
899
-     * @param    string $config_option_name
900
-     * @return    mixed EE_Config_Base | FALSE
901
-     */
902
-    public function get_config_option($config_option_name = '')
903
-    {
904
-        // retrieve the wp-option for this config class.
905
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
906
-        if (empty($config_option)) {
907
-            EE_Config::log($config_option_name . '-NOT-FOUND');
908
-        }
909
-        return $config_option;
910
-    }
911
-
912
-
913
-    /**
914
-     * log
915
-     *
916
-     * @param string $config_option_name
917
-     */
918
-    public static function log($config_option_name = '')
919
-    {
920
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
921
-            $config_log = get_option(EE_Config::LOG_NAME, array());
922
-            // copy incoming $_REQUEST and sanitize it so we can save it
923
-            $_request = $_REQUEST;
924
-            array_walk_recursive($_request, 'sanitize_text_field');
925
-            $config_log[ (string) microtime(true) ] = array(
926
-                'config_name' => $config_option_name,
927
-                'request'     => $_request,
928
-            );
929
-            update_option(EE_Config::LOG_NAME, $config_log);
930
-        }
931
-    }
932
-
933
-
934
-    /**
935
-     * trim_log
936
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
937
-     */
938
-    public static function trim_log()
939
-    {
940
-        if (! EE_Config::logging_enabled()) {
941
-            return;
942
-        }
943
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
944
-        $log_length = count($config_log);
945
-        if ($log_length > EE_Config::LOG_LENGTH) {
946
-            ksort($config_log);
947
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
948
-            update_option(EE_Config::LOG_NAME, $config_log);
949
-        }
950
-    }
951
-
952
-
953
-    /**
954
-     *    get_page_for_posts
955
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
956
-     *    wp-option "page_for_posts", or "posts" if no page is selected
957
-     *
958
-     * @access    public
959
-     * @return    string
960
-     */
961
-    public static function get_page_for_posts()
962
-    {
963
-        $page_for_posts = get_option('page_for_posts');
964
-        if (! $page_for_posts) {
965
-            return 'posts';
966
-        }
967
-        /** @type WPDB $wpdb */
968
-        global $wpdb;
969
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
970
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
971
-    }
972
-
973
-
974
-    /**
975
-     *    register_shortcodes_and_modules.
976
-     *    At this point, it's too early to tell if we're maintenance mode or not.
977
-     *    In fact, this is where we give modules a chance to let core know they exist
978
-     *    so they can help trigger maintenance mode if it's needed
979
-     *
980
-     * @access    public
981
-     * @return    void
982
-     */
983
-    public function register_shortcodes_and_modules()
984
-    {
985
-        // allow modules to set hooks for the rest of the system
986
-        EE_Registry::instance()->modules = $this->_register_modules();
987
-    }
988
-
989
-
990
-    /**
991
-     *    initialize_shortcodes_and_modules
992
-     *    meaning they can start adding their hooks to get stuff done
993
-     *
994
-     * @access    public
995
-     * @return    void
996
-     */
997
-    public function initialize_shortcodes_and_modules()
998
-    {
999
-        // allow modules to set hooks for the rest of the system
1000
-        $this->_initialize_modules();
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     *    widgets_init
1006
-     *
1007
-     * @access private
1008
-     * @return void
1009
-     */
1010
-    public function widgets_init()
1011
-    {
1012
-        // only init widgets on admin pages when not in complete maintenance, and
1013
-        // on frontend when not in any maintenance mode
1014
-        if (! EE_Maintenance_Mode::instance()->level()
1015
-            || (
1016
-                is_admin()
1017
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018
-            )
1019
-        ) {
1020
-            // grab list of installed widgets
1021
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1022
-            // filter list of modules to register
1023
-            $widgets_to_register = apply_filters(
1024
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1025
-                $widgets_to_register
1026
-            );
1027
-            if (! empty($widgets_to_register)) {
1028
-                // cycle thru widget folders
1029
-                foreach ($widgets_to_register as $widget_path) {
1030
-                    // add to list of installed widget modules
1031
-                    EE_Config::register_ee_widget($widget_path);
1032
-                }
1033
-            }
1034
-            // filter list of installed modules
1035
-            EE_Registry::instance()->widgets = apply_filters(
1036
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1037
-                EE_Registry::instance()->widgets
1038
-            );
1039
-        }
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     *    register_ee_widget - makes core aware of this widget
1045
-     *
1046
-     * @access    public
1047
-     * @param    string $widget_path - full path up to and including widget folder
1048
-     * @return    void
1049
-     */
1050
-    public static function register_ee_widget($widget_path = null)
1051
-    {
1052
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1053
-        $widget_ext = '.widget.php';
1054
-        // make all separators match
1055
-        $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1056
-        // does the file path INCLUDE the actual file name as part of the path ?
1057
-        if (strpos($widget_path, $widget_ext) !== false) {
1058
-            // grab and shortcode file name from directory name and break apart at dots
1059
-            $file_name = explode('.', basename($widget_path));
1060
-            // take first segment from file name pieces and remove class prefix if it exists
1061
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1062
-            // sanitize shortcode directory name
1063
-            $widget = sanitize_key($widget);
1064
-            // now we need to rebuild the shortcode path
1065
-            $widget_path = explode('/', $widget_path);
1066
-            // remove last segment
1067
-            array_pop($widget_path);
1068
-            // glue it back together
1069
-            $widget_path = implode(DS, $widget_path);
1070
-        } else {
1071
-            // grab and sanitize widget directory name
1072
-            $widget = sanitize_key(basename($widget_path));
1073
-        }
1074
-        // create classname from widget directory name
1075
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076
-        // add class prefix
1077
-        $widget_class = 'EEW_' . $widget;
1078
-        // does the widget exist ?
1079
-        if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1080
-            $msg = sprintf(
1081
-                __(
1082
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083
-                    'event_espresso'
1084
-                ),
1085
-                $widget_class,
1086
-                $widget_path . '/' . $widget_class . $widget_ext
1087
-            );
1088
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1089
-            return;
1090
-        }
1091
-        // load the widget class file
1092
-        require_once($widget_path . '/' . $widget_class . $widget_ext);
1093
-        // verify that class exists
1094
-        if (! class_exists($widget_class)) {
1095
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1097
-            return;
1098
-        }
1099
-        register_widget($widget_class);
1100
-        // add to array of registered widgets
1101
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1102
-    }
1103
-
1104
-
1105
-    /**
1106
-     *        _register_modules
1107
-     *
1108
-     * @access private
1109
-     * @return array
1110
-     */
1111
-    private function _register_modules()
1112
-    {
1113
-        // grab list of installed modules
1114
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1115
-        // filter list of modules to register
1116
-        $modules_to_register = apply_filters(
1117
-            'FHEE__EE_Config__register_modules__modules_to_register',
1118
-            $modules_to_register
1119
-        );
1120
-        if (! empty($modules_to_register)) {
1121
-            // loop through folders
1122
-            foreach ($modules_to_register as $module_path) {
1123
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
-                if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
-                    && $module_path !== EE_MODULES . 'gateways'
1126
-                ) {
1127
-                    // add to list of installed modules
1128
-                    EE_Config::register_module($module_path);
1129
-                }
1130
-            }
1131
-        }
1132
-        // filter list of installed modules
1133
-        return apply_filters(
1134
-            'FHEE__EE_Config___register_modules__installed_modules',
1135
-            EE_Registry::instance()->modules
1136
-        );
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     *    register_module - makes core aware of this module
1142
-     *
1143
-     * @access    public
1144
-     * @param    string $module_path - full path up to and including module folder
1145
-     * @return    bool
1146
-     */
1147
-    public static function register_module($module_path = null)
1148
-    {
1149
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1150
-        $module_ext = '.module.php';
1151
-        // make all separators match
1152
-        $module_path = str_replace(array('\\', '/'), '/', $module_path);
1153
-        // does the file path INCLUDE the actual file name as part of the path ?
1154
-        if (strpos($module_path, $module_ext) !== false) {
1155
-            // grab and shortcode file name from directory name and break apart at dots
1156
-            $module_file = explode('.', basename($module_path));
1157
-            // now we need to rebuild the shortcode path
1158
-            $module_path = explode('/', $module_path);
1159
-            // remove last segment
1160
-            array_pop($module_path);
1161
-            // glue it back together
1162
-            $module_path = implode('/', $module_path) . '/';
1163
-            // take first segment from file name pieces and sanitize it
1164
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165
-            // ensure class prefix is added
1166
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1167
-        } else {
1168
-            // we need to generate the filename based off of the folder name
1169
-            // grab and sanitize module name
1170
-            $module = strtolower(basename($module_path));
1171
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172
-            // like trailingslashit()
1173
-            $module_path = rtrim($module_path, '/') . '/';
1174
-            // create classname from module directory name
1175
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176
-            // add class prefix
1177
-            $module_class = 'EED_' . $module;
1178
-        }
1179
-        // does the module exist ?
1180
-        if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1181
-            $msg = sprintf(
1182
-                __(
1183
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1184
-                    'event_espresso'
1185
-                ),
1186
-                $module
1187
-            );
1188
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1189
-            return false;
1190
-        }
1191
-        // load the module class file
1192
-        require_once($module_path . $module_class . $module_ext);
1193
-        // verify that class exists
1194
-        if (! class_exists($module_class)) {
1195
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1197
-            return false;
1198
-        }
1199
-        // add to array of registered modules
1200
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1201
-        do_action(
1202
-            'AHEE__EE_Config__register_module__complete',
1203
-            $module_class,
1204
-            EE_Registry::instance()->modules->{$module_class}
1205
-        );
1206
-        return true;
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     *    _initialize_modules
1212
-     *    allow modules to set hooks for the rest of the system
1213
-     *
1214
-     * @access private
1215
-     * @return void
1216
-     */
1217
-    private function _initialize_modules()
1218
-    {
1219
-        // cycle thru shortcode folders
1220
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1221
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1222
-            // which set hooks ?
1223
-            if (is_admin()) {
1224
-                // fire immediately
1225
-                call_user_func(array($module_class, 'set_hooks_admin'));
1226
-            } else {
1227
-                // delay until other systems are online
1228
-                add_action(
1229
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1230
-                    array($module_class, 'set_hooks')
1231
-                );
1232
-            }
1233
-        }
1234
-    }
1235
-
1236
-
1237
-    /**
1238
-     *    register_route - adds module method routes to route_map
1239
-     *
1240
-     * @access    public
1241
-     * @param    string $route       - "pretty" public alias for module method
1242
-     * @param    string $module      - module name (classname without EED_ prefix)
1243
-     * @param    string $method_name - the actual module method to be routed to
1244
-     * @param    string $key         - url param key indicating a route is being called
1245
-     * @return    bool
1246
-     */
1247
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1248
-    {
1249
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250
-        $module = str_replace('EED_', '', $module);
1251
-        $module_class = 'EED_' . $module;
1252
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1253
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1255
-            return false;
1256
-        }
1257
-        if (empty($route)) {
1258
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1260
-            return false;
1261
-        }
1262
-        if (! method_exists('EED_' . $module, $method_name)) {
1263
-            $msg = sprintf(
1264
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265
-                $route
1266
-            );
1267
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1268
-            return false;
1269
-        }
1270
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1271
-        return true;
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     *    get_route - get module method route
1277
-     *
1278
-     * @access    public
1279
-     * @param    string $route - "pretty" public alias for module method
1280
-     * @param    string $key   - url param key indicating a route is being called
1281
-     * @return    string
1282
-     */
1283
-    public static function get_route($route = null, $key = 'ee')
1284
-    {
1285
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1286
-        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1289
-        }
1290
-        return null;
1291
-    }
1292
-
1293
-
1294
-    /**
1295
-     *    get_routes - get ALL module method routes
1296
-     *
1297
-     * @access    public
1298
-     * @return    array
1299
-     */
1300
-    public static function get_routes()
1301
-    {
1302
-        return EE_Config::$_module_route_map;
1303
-    }
1304
-
1305
-
1306
-    /**
1307
-     *    register_forward - allows modules to forward request to another module for further processing
1308
-     *
1309
-     * @access    public
1310
-     * @param    string       $route   - "pretty" public alias for module method
1311
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1312
-     *                                 class, allows different forwards to be served based on status
1313
-     * @param    array|string $forward - function name or array( class, method )
1314
-     * @param    string       $key     - url param key indicating a route is being called
1315
-     * @return    bool
1316
-     */
1317
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318
-    {
1319
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1321
-            $msg = sprintf(
1322
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1323
-                $route
1324
-            );
1325
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1326
-            return false;
1327
-        }
1328
-        if (empty($forward)) {
1329
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1331
-            return false;
1332
-        }
1333
-        if (is_array($forward)) {
1334
-            if (! isset($forward[1])) {
1335
-                $msg = sprintf(
1336
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337
-                    $route
1338
-                );
1339
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1340
-                return false;
1341
-            }
1342
-            if (! method_exists($forward[0], $forward[1])) {
1343
-                $msg = sprintf(
1344
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345
-                    $forward[1],
1346
-                    $route
1347
-                );
1348
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1349
-                return false;
1350
-            }
1351
-        } elseif (! function_exists($forward)) {
1352
-            $msg = sprintf(
1353
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354
-                $forward,
1355
-                $route
1356
-            );
1357
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1358
-            return false;
1359
-        }
1360
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1361
-        return true;
1362
-    }
1363
-
1364
-
1365
-    /**
1366
-     *    get_forward - get forwarding route
1367
-     *
1368
-     * @access    public
1369
-     * @param    string  $route  - "pretty" public alias for module method
1370
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1371
-     *                           allows different forwards to be served based on status
1372
-     * @param    string  $key    - url param key indicating a route is being called
1373
-     * @return    string
1374
-     */
1375
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1376
-    {
1377
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1379
-            return apply_filters(
1380
-                'FHEE__EE_Config__get_forward',
1381
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1382
-                $route,
1383
-                $status
1384
-            );
1385
-        }
1386
-        return null;
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1392
-     *    results
1393
-     *
1394
-     * @access    public
1395
-     * @param    string  $route  - "pretty" public alias for module method
1396
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1397
-     *                           allows different views to be served based on status
1398
-     * @param    string  $view
1399
-     * @param    string  $key    - url param key indicating a route is being called
1400
-     * @return    bool
1401
-     */
1402
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403
-    {
1404
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1406
-            $msg = sprintf(
1407
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1408
-                $route
1409
-            );
1410
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1411
-            return false;
1412
-        }
1413
-        if (! is_readable($view)) {
1414
-            $msg = sprintf(
1415
-                __(
1416
-                    'The %s view file could not be found or is not readable due to file permissions.',
1417
-                    'event_espresso'
1418
-                ),
1419
-                $view
1420
-            );
1421
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
-            return false;
1423
-        }
1424
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1425
-        return true;
1426
-    }
1427
-
1428
-
1429
-    /**
1430
-     *    get_view - get view for route and status
1431
-     *
1432
-     * @access    public
1433
-     * @param    string  $route  - "pretty" public alias for module method
1434
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1435
-     *                           allows different views to be served based on status
1436
-     * @param    string  $key    - url param key indicating a route is being called
1437
-     * @return    string
1438
-     */
1439
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1440
-    {
1441
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1443
-            return apply_filters(
1444
-                'FHEE__EE_Config__get_view',
1445
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1446
-                $route,
1447
-                $status
1448
-            );
1449
-        }
1450
-        return null;
1451
-    }
1452
-
1453
-
1454
-    public function update_addon_option_names()
1455
-    {
1456
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1457
-    }
1458
-
1459
-
1460
-    public function shutdown()
1461
-    {
1462
-        $this->update_addon_option_names();
1463
-    }
1464
-
1465
-
1466
-    /**
1467
-     * @return LegacyShortcodesManager
1468
-     */
1469
-    public static function getLegacyShortcodesManager()
1470
-    {
1471
-
1472
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474
-                EE_Registry::instance()
1475
-            );
1476
-        }
1477
-        return EE_Config::instance()->legacy_shortcodes_manager;
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * register_shortcode - makes core aware of this shortcode
1483
-     *
1484
-     * @deprecated 4.9.26
1485
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1486
-     * @return    bool
1487
-     */
1488
-    public static function register_shortcode($shortcode_path = null)
1489
-    {
1490
-        EE_Error::doing_it_wrong(
1491
-            __METHOD__,
1492
-            __(
1493
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1494
-                'event_espresso'
1495
-            ),
1496
-            '4.9.26'
1497
-        );
1498
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1499
-    }
1500
-}
1501
-
1502
-/**
1503
- * Base class used for config classes. These classes should generally not have
1504
- * magic functions in use, except we'll allow them to magically set and get stuff...
1505
- * basically, they should just be well-defined stdClasses
1506
- */
1507
-class EE_Config_Base
1508
-{
1509
-
1510
-    /**
1511
-     * Utility function for escaping the value of a property and returning.
1512
-     *
1513
-     * @param string $property property name (checks to see if exists).
1514
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1515
-     * @throws \EE_Error
1516
-     */
1517
-    public function get_pretty($property)
1518
-    {
1519
-        if (! property_exists($this, $property)) {
1520
-            throw new EE_Error(
1521
-                sprintf(
1522
-                    __(
1523
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1524
-                        'event_espresso'
1525
-                    ),
1526
-                    get_class($this),
1527
-                    $property
1528
-                )
1529
-            );
1530
-        }
1531
-        // just handling escaping of strings for now.
1532
-        if (is_string($this->{$property})) {
1533
-            return stripslashes($this->{$property});
1534
-        }
1535
-        return $this->{$property};
1536
-    }
1537
-
1538
-
1539
-    public function populate()
1540
-    {
1541
-        // grab defaults via a new instance of this class.
1542
-        $class_name = get_class($this);
1543
-        $defaults = new $class_name;
1544
-        // loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1545
-        // default from our $defaults object.
1546
-        foreach (get_object_vars($defaults) as $property => $value) {
1547
-            if ($this->{$property} === null) {
1548
-                $this->{$property} = $value;
1549
-            }
1550
-        }
1551
-        // cleanup
1552
-        unset($defaults);
1553
-    }
1554
-
1555
-
1556
-    /**
1557
-     *        __isset
1558
-     *
1559
-     * @param $a
1560
-     * @return bool
1561
-     */
1562
-    public function __isset($a)
1563
-    {
1564
-        return false;
1565
-    }
1566
-
1567
-
1568
-    /**
1569
-     *        __unset
1570
-     *
1571
-     * @param $a
1572
-     * @return bool
1573
-     */
1574
-    public function __unset($a)
1575
-    {
1576
-        return false;
1577
-    }
1578
-
1579
-
1580
-    /**
1581
-     *        __clone
1582
-     */
1583
-    public function __clone()
1584
-    {
1585
-    }
1586
-
1587
-
1588
-    /**
1589
-     *        __wakeup
1590
-     */
1591
-    public function __wakeup()
1592
-    {
1593
-    }
1594
-
1595
-
1596
-    /**
1597
-     *        __destruct
1598
-     */
1599
-    public function __destruct()
1600
-    {
1601
-    }
1602
-}
1603
-
1604
-/**
1605
- * Class for defining what's in the EE_Config relating to registration settings
1606
- */
1607
-class EE_Core_Config extends EE_Config_Base
1608
-{
1609
-
1610
-    const OPTION_NAME_UXIP = 'ee_ueip_optin';
1611
-
1612
-
1613
-    public $current_blog_id;
1614
-
1615
-    public $ee_ueip_optin;
1616
-
1617
-    public $ee_ueip_has_notified;
1618
-
1619
-    /**
1620
-     * Not to be confused with the 4 critical page variables (See
1621
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1622
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1623
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1624
-     *
1625
-     * @var array
1626
-     */
1627
-    public $post_shortcodes;
1628
-
1629
-    public $module_route_map;
1630
-
1631
-    public $module_forward_map;
1632
-
1633
-    public $module_view_map;
1634
-
1635
-    /**
1636
-     * The next 4 vars are the IDs of critical EE pages.
1637
-     *
1638
-     * @var int
1639
-     */
1640
-    public $reg_page_id;
1641
-
1642
-    public $txn_page_id;
1643
-
1644
-    public $thank_you_page_id;
1645
-
1646
-    public $cancel_page_id;
1647
-
1648
-    /**
1649
-     * The next 4 vars are the URLs of critical EE pages.
1650
-     *
1651
-     * @var int
1652
-     */
1653
-    public $reg_page_url;
1654
-
1655
-    public $txn_page_url;
1656
-
1657
-    public $thank_you_page_url;
1658
-
1659
-    public $cancel_page_url;
1660
-
1661
-    /**
1662
-     * The next vars relate to the custom slugs for EE CPT routes
1663
-     */
1664
-    public $event_cpt_slug;
1665
-
1666
-    /**
1667
-     * This caches the _ee_ueip_option in case this config is reset in the same
1668
-     * request across blog switches in a multisite context.
1669
-     * Avoids extra queries to the db for this option.
1670
-     *
1671
-     * @var bool
1672
-     */
1673
-    public static $ee_ueip_option;
1674
-
1675
-
1676
-    /**
1677
-     *    class constructor
1678
-     *
1679
-     * @access    public
1680
-     */
1681
-    public function __construct()
1682
-    {
1683
-        // set default organization settings
1684
-        $this->current_blog_id = get_current_blog_id();
1685
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
-        $this->post_shortcodes = array();
1689
-        $this->module_route_map = array();
1690
-        $this->module_forward_map = array();
1691
-        $this->module_view_map = array();
1692
-        // critical EE page IDs
1693
-        $this->reg_page_id = 0;
1694
-        $this->txn_page_id = 0;
1695
-        $this->thank_you_page_id = 0;
1696
-        $this->cancel_page_id = 0;
1697
-        // critical EE page URLs
1698
-        $this->reg_page_url = '';
1699
-        $this->txn_page_url = '';
1700
-        $this->thank_you_page_url = '';
1701
-        $this->cancel_page_url = '';
1702
-        // cpt slugs
1703
-        $this->event_cpt_slug = __('events', 'event_espresso');
1704
-        // ueip constant check
1705
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
-            $this->ee_ueip_optin = false;
1707
-            $this->ee_ueip_has_notified = true;
1708
-        }
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * @return array
1714
-     */
1715
-    public function get_critical_pages_array()
1716
-    {
1717
-        return array(
1718
-            $this->reg_page_id,
1719
-            $this->txn_page_id,
1720
-            $this->thank_you_page_id,
1721
-            $this->cancel_page_id,
1722
-        );
1723
-    }
1724
-
1725
-
1726
-    /**
1727
-     * @return array
1728
-     */
1729
-    public function get_critical_pages_shortcodes_array()
1730
-    {
1731
-        return array(
1732
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
-        );
1737
-    }
1738
-
1739
-
1740
-    /**
1741
-     *  gets/returns URL for EE reg_page
1742
-     *
1743
-     * @access    public
1744
-     * @return    string
1745
-     */
1746
-    public function reg_page_url()
1747
-    {
1748
-        if (! $this->reg_page_url) {
1749
-            $this->reg_page_url = add_query_arg(
1750
-                array('uts' => time()),
1751
-                get_permalink($this->reg_page_id)
1752
-            ) . '#checkout';
1753
-        }
1754
-        return $this->reg_page_url;
1755
-    }
1756
-
1757
-
1758
-    /**
1759
-     *  gets/returns URL for EE txn_page
1760
-     *
1761
-     * @param array $query_args like what gets passed to
1762
-     *                          add_query_arg() as the first argument
1763
-     * @access    public
1764
-     * @return    string
1765
-     */
1766
-    public function txn_page_url($query_args = array())
1767
-    {
1768
-        if (! $this->txn_page_url) {
1769
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1770
-        }
1771
-        if ($query_args) {
1772
-            return add_query_arg($query_args, $this->txn_page_url);
1773
-        } else {
1774
-            return $this->txn_page_url;
1775
-        }
1776
-    }
1777
-
1778
-
1779
-    /**
1780
-     *  gets/returns URL for EE thank_you_page
1781
-     *
1782
-     * @param array $query_args like what gets passed to
1783
-     *                          add_query_arg() as the first argument
1784
-     * @access    public
1785
-     * @return    string
1786
-     */
1787
-    public function thank_you_page_url($query_args = array())
1788
-    {
1789
-        if (! $this->thank_you_page_url) {
1790
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
-        }
1792
-        if ($query_args) {
1793
-            return add_query_arg($query_args, $this->thank_you_page_url);
1794
-        } else {
1795
-            return $this->thank_you_page_url;
1796
-        }
1797
-    }
1798
-
1799
-
1800
-    /**
1801
-     *  gets/returns URL for EE cancel_page
1802
-     *
1803
-     * @access    public
1804
-     * @return    string
1805
-     */
1806
-    public function cancel_page_url()
1807
-    {
1808
-        if (! $this->cancel_page_url) {
1809
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
-        }
1811
-        return $this->cancel_page_url;
1812
-    }
1813
-
1814
-
1815
-    /**
1816
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
-     *
1818
-     * @since 4.7.5
1819
-     */
1820
-    protected function _reset_urls()
1821
-    {
1822
-        $this->reg_page_url = '';
1823
-        $this->txn_page_url = '';
1824
-        $this->cancel_page_url = '';
1825
-        $this->thank_you_page_url = '';
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * Used to return what the optin value is set for the EE User Experience Program.
1831
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
-     * on the main site only.
1833
-     *
1834
-     * @return bool
1835
-     */
1836
-    protected function _get_main_ee_ueip_optin()
1837
-    {
1838
-        // if this is the main site then we can just bypass our direct query.
1839
-        if (is_main_site()) {
1840
-            return get_option(self::OPTION_NAME_UXIP, false);
1841
-        }
1842
-        // is this already cached for this request?  If so use it.
1843
-        if (EE_Core_Config::$ee_ueip_option !== null) {
1844
-            return EE_Core_Config::$ee_ueip_option;
1845
-        }
1846
-        global $wpdb;
1847
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1848
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
-        $option = self::OPTION_NAME_UXIP;
1850
-        // set correct table for query
1851
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
-        // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
-        // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
-        // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
-        // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
-        // for the purpose of caching.
1857
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1858
-        if (false !== $pre) {
1859
-            EE_Core_Config::$ee_ueip_option = $pre;
1860
-            return EE_Core_Config::$ee_ueip_option;
1861
-        }
1862
-        $row = $wpdb->get_row(
1863
-            $wpdb->prepare(
1864
-                "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
-                $option
1866
-            )
1867
-        );
1868
-        if (is_object($row)) {
1869
-            $value = $row->option_value;
1870
-        } else { // option does not exist so use default.
1871
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1872
-            return EE_Core_Config::$ee_ueip_option;
1873
-        }
1874
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1875
-        return EE_Core_Config::$ee_ueip_option;
1876
-    }
1877
-
1878
-
1879
-    /**
1880
-     * Utility function for escaping the value of a property and returning.
1881
-     *
1882
-     * @param string $property property name (checks to see if exists).
1883
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1884
-     * @throws \EE_Error
1885
-     */
1886
-    public function get_pretty($property)
1887
-    {
1888
-        if ($property === self::OPTION_NAME_UXIP) {
1889
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1890
-        }
1891
-        return parent::get_pretty($property);
1892
-    }
1893
-
1894
-
1895
-    /**
1896
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1897
-     * on the object.
1898
-     *
1899
-     * @return array
1900
-     */
1901
-    public function __sleep()
1902
-    {
1903
-        // reset all url properties
1904
-        $this->_reset_urls();
1905
-        // return what to save to db
1906
-        return array_keys(get_object_vars($this));
1907
-    }
1908
-}
1909
-
1910
-/**
1911
- * Config class for storing info on the Organization
1912
- */
1913
-class EE_Organization_Config extends EE_Config_Base
1914
-{
1915
-
1916
-    /**
1917
-     * @var string $name
1918
-     * eg EE4.1
1919
-     */
1920
-    public $name;
1921
-
1922
-    /**
1923
-     * @var string $address_1
1924
-     * eg 123 Onna Road
1925
-     */
1926
-    public $address_1 = '';
1927
-
1928
-    /**
1929
-     * @var string $address_2
1930
-     * eg PO Box 123
1931
-     */
1932
-    public $address_2 = '';
1933
-
1934
-    /**
1935
-     * @var string $city
1936
-     * eg Inna City
1937
-     */
1938
-    public $city = '';
1939
-
1940
-    /**
1941
-     * @var int $STA_ID
1942
-     * eg 4
1943
-     */
1944
-    public $STA_ID = 0;
1945
-
1946
-    /**
1947
-     * @var string $CNT_ISO
1948
-     * eg US
1949
-     */
1950
-    public $CNT_ISO = '';
1951
-
1952
-    /**
1953
-     * @var string $zip
1954
-     * eg 12345  or V1A 2B3
1955
-     */
1956
-    public $zip = '';
1957
-
1958
-    /**
1959
-     * @var string $email
1960
-     * eg [email protected]
1961
-     */
1962
-    public $email;
1963
-
1964
-    /**
1965
-     * @var string $phone
1966
-     * eg. 111-111-1111
1967
-     */
1968
-    public $phone = '';
1969
-
1970
-    /**
1971
-     * @var string $vat
1972
-     * VAT/Tax Number
1973
-     */
1974
-    public $vat = '';
1975
-
1976
-    /**
1977
-     * @var string $logo_url
1978
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1979
-     */
1980
-    public $logo_url = '';
1981
-
1982
-    /**
1983
-     * The below are all various properties for holding links to organization social network profiles
1984
-     *
1985
-     * @var string
1986
-     */
1987
-    /**
1988
-     * facebook (facebook.com/profile.name)
1989
-     *
1990
-     * @var string
1991
-     */
1992
-    public $facebook = '';
1993
-
1994
-    /**
1995
-     * twitter (twitter.com/twitter_handle)
1996
-     *
1997
-     * @var string
1998
-     */
1999
-    public $twitter = '';
2000
-
2001
-    /**
2002
-     * linkedin (linkedin.com/in/profile_name)
2003
-     *
2004
-     * @var string
2005
-     */
2006
-    public $linkedin = '';
2007
-
2008
-    /**
2009
-     * pinterest (www.pinterest.com/profile_name)
2010
-     *
2011
-     * @var string
2012
-     */
2013
-    public $pinterest = '';
2014
-
2015
-    /**
2016
-     * google+ (google.com/+profileName)
2017
-     *
2018
-     * @var string
2019
-     */
2020
-    public $google = '';
2021
-
2022
-    /**
2023
-     * instagram (instagram.com/handle)
2024
-     *
2025
-     * @var string
2026
-     */
2027
-    public $instagram = '';
2028
-
2029
-
2030
-    /**
2031
-     *    class constructor
2032
-     *
2033
-     * @access    public
2034
-     */
2035
-    public function __construct()
2036
-    {
2037
-        // set default organization settings
2038
-        // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2039
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2040
-        $this->email = get_bloginfo('admin_email');
2041
-    }
2042
-}
2043
-
2044
-/**
2045
- * Class for defining what's in the EE_Config relating to currency
2046
- */
2047
-class EE_Currency_Config extends EE_Config_Base
2048
-{
2049
-
2050
-    /**
2051
-     * @var string $code
2052
-     * eg 'US'
2053
-     */
2054
-    public $code;
2055
-
2056
-    /**
2057
-     * @var string $name
2058
-     * eg 'Dollar'
2059
-     */
2060
-    public $name;
2061
-
2062
-    /**
2063
-     * plural name
2064
-     *
2065
-     * @var string $plural
2066
-     * eg 'Dollars'
2067
-     */
2068
-    public $plural;
2069
-
2070
-    /**
2071
-     * currency sign
2072
-     *
2073
-     * @var string $sign
2074
-     * eg '$'
2075
-     */
2076
-    public $sign;
2077
-
2078
-    /**
2079
-     * Whether the currency sign should come before the number or not
2080
-     *
2081
-     * @var boolean $sign_b4
2082
-     */
2083
-    public $sign_b4;
2084
-
2085
-    /**
2086
-     * How many digits should come after the decimal place
2087
-     *
2088
-     * @var int $dec_plc
2089
-     */
2090
-    public $dec_plc;
2091
-
2092
-    /**
2093
-     * Symbol to use for decimal mark
2094
-     *
2095
-     * @var string $dec_mrk
2096
-     * eg '.'
2097
-     */
2098
-    public $dec_mrk;
2099
-
2100
-    /**
2101
-     * Symbol to use for thousands
2102
-     *
2103
-     * @var string $thsnds
2104
-     * eg ','
2105
-     */
2106
-    public $thsnds;
2107
-
2108
-
2109
-    /**
2110
-     *    class constructor
2111
-     *
2112
-     * @access    public
2113
-     * @param string $CNT_ISO
2114
-     * @throws \EE_Error
2115
-     */
2116
-    public function __construct($CNT_ISO = '')
2117
-    {
2118
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2119
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2120
-        // get country code from organization settings or use default
2121
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2122
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2123
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2124
-            : '';
2125
-        // but override if requested
2126
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
-        if (! empty($CNT_ISO)
2129
-            && EE_Maintenance_Mode::instance()->models_can_query()
2130
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131
-        ) {
2132
-            // retrieve the country settings from the db, just in case they have been customized
2133
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134
-            if ($country instanceof EE_Country) {
2135
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
-                $this->name = $country->currency_name_single();    // Dollar
2137
-                $this->plural = $country->currency_name_plural();    // Dollars
2138
-                $this->sign = $country->currency_sign();            // currency sign: $
2139
-                $this->sign_b4 = $country->currency_sign_before(
2140
-                );        // currency sign before or after: $TRUE  or  FALSE$
2141
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2142
-                $this->dec_mrk = $country->currency_decimal_mark(
2143
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144
-                $this->thsnds = $country->currency_thousands_separator(
2145
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146
-            }
2147
-        }
2148
-        // fallback to hardcoded defaults, in case the above failed
2149
-        if (empty($this->code)) {
2150
-            // set default currency settings
2151
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2152
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2153
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
-            $this->sign = '$';    // currency sign: $
2155
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
-        }
2160
-    }
2161
-}
2162
-
2163
-/**
2164
- * Class for defining what's in the EE_Config relating to registration settings
2165
- */
2166
-class EE_Registration_Config extends EE_Config_Base
2167
-{
2168
-
2169
-    /**
2170
-     * Default registration status
2171
-     *
2172
-     * @var string $default_STS_ID
2173
-     * eg 'RPP'
2174
-     */
2175
-    public $default_STS_ID;
2176
-
2177
-    /**
2178
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2179
-     * registrations)
2180
-     *
2181
-     * @var int
2182
-     */
2183
-    public $default_maximum_number_of_tickets;
2184
-
2185
-    /**
2186
-     * level of validation to apply to email addresses
2187
-     *
2188
-     * @var string $email_validation_level
2189
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2190
-     */
2191
-    public $email_validation_level;
2192
-
2193
-    /**
2194
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2195
-     *
2196
-     * @var boolean $show_pending_payment_options
2197
-     */
2198
-    public $show_pending_payment_options;
2199
-
2200
-    /**
2201
-     * Whether to skip the registration confirmation page
2202
-     *
2203
-     * @var boolean $skip_reg_confirmation
2204
-     */
2205
-    public $skip_reg_confirmation;
2206
-
2207
-    /**
2208
-     * an array of SPCO reg steps where:
2209
-     *        the keys denotes the reg step order
2210
-     *        each element consists of an array with the following elements:
2211
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2212
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2213
-     *            "slug" => the URL param used to trigger the reg step
2214
-     *
2215
-     * @var array $reg_steps
2216
-     */
2217
-    public $reg_steps;
2218
-
2219
-    /**
2220
-     * Whether registration confirmation should be the last page of SPCO
2221
-     *
2222
-     * @var boolean $reg_confirmation_last
2223
-     */
2224
-    public $reg_confirmation_last;
2225
-
2226
-    /**
2227
-     * Whether or not to enable the EE Bot Trap
2228
-     *
2229
-     * @var boolean $use_bot_trap
2230
-     */
2231
-    public $use_bot_trap;
2232
-
2233
-    /**
2234
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2235
-     *
2236
-     * @var boolean $use_encryption
2237
-     */
2238
-    public $use_encryption;
2239
-
2240
-    /**
2241
-     * Whether or not to use ReCaptcha
2242
-     *
2243
-     * @var boolean $use_captcha
2244
-     */
2245
-    public $use_captcha;
2246
-
2247
-    /**
2248
-     * ReCaptcha Theme
2249
-     *
2250
-     * @var string $recaptcha_theme
2251
-     *    options: 'dark', 'light', 'invisible'
2252
-     */
2253
-    public $recaptcha_theme;
2254
-
2255
-    /**
2256
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2257
-     *
2258
-     * @var string $recaptcha_badge
2259
-     *    options: 'bottomright', 'bottomleft', 'inline'
2260
-     */
2261
-    public $recaptcha_badge;
17
+	const OPTION_NAME = 'ee_config';
18
+
19
+	const LOG_NAME = 'ee_config_log';
20
+
21
+	const LOG_LENGTH = 100;
22
+
23
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
+
25
+	/**
26
+	 *    instance of the EE_Config object
27
+	 *
28
+	 * @var    EE_Config $_instance
29
+	 * @access    private
30
+	 */
31
+	private static $_instance;
32
+
33
+	/**
34
+	 * @var boolean $_logging_enabled
35
+	 */
36
+	private static $_logging_enabled = false;
37
+
38
+	/**
39
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
+	 */
41
+	private $legacy_shortcodes_manager;
42
+
43
+	/**
44
+	 * An StdClass whose property names are addon slugs,
45
+	 * and values are their config classes
46
+	 *
47
+	 * @var StdClass
48
+	 */
49
+	public $addons;
50
+
51
+	/**
52
+	 * @var EE_Admin_Config
53
+	 */
54
+	public $admin;
55
+
56
+	/**
57
+	 * @var EE_Core_Config
58
+	 */
59
+	public $core;
60
+
61
+	/**
62
+	 * @var EE_Currency_Config
63
+	 */
64
+	public $currency;
65
+
66
+	/**
67
+	 * @var EE_Organization_Config
68
+	 */
69
+	public $organization;
70
+
71
+	/**
72
+	 * @var EE_Registration_Config
73
+	 */
74
+	public $registration;
75
+
76
+	/**
77
+	 * @var EE_Template_Config
78
+	 */
79
+	public $template_settings;
80
+
81
+	/**
82
+	 * Holds EE environment values.
83
+	 *
84
+	 * @var EE_Environment_Config
85
+	 */
86
+	public $environment;
87
+
88
+	/**
89
+	 * settings pertaining to Google maps
90
+	 *
91
+	 * @var EE_Map_Config
92
+	 */
93
+	public $map_settings;
94
+
95
+	/**
96
+	 * settings pertaining to Taxes
97
+	 *
98
+	 * @var EE_Tax_Config
99
+	 */
100
+	public $tax_settings;
101
+
102
+	/**
103
+	 * Settings pertaining to global messages settings.
104
+	 *
105
+	 * @var EE_Messages_Config
106
+	 */
107
+	public $messages;
108
+
109
+	/**
110
+	 * @deprecated
111
+	 * @var EE_Gateway_Config
112
+	 */
113
+	public $gateway;
114
+
115
+	/**
116
+	 * @var    array $_addon_option_names
117
+	 * @access    private
118
+	 */
119
+	private $_addon_option_names = array();
120
+
121
+	/**
122
+	 * @var    array $_module_route_map
123
+	 * @access    private
124
+	 */
125
+	private static $_module_route_map = array();
126
+
127
+	/**
128
+	 * @var    array $_module_forward_map
129
+	 * @access    private
130
+	 */
131
+	private static $_module_forward_map = array();
132
+
133
+	/**
134
+	 * @var    array $_module_view_map
135
+	 * @access    private
136
+	 */
137
+	private static $_module_view_map = array();
138
+
139
+
140
+	/**
141
+	 * @singleton method used to instantiate class object
142
+	 * @access    public
143
+	 * @return EE_Config instance
144
+	 */
145
+	public static function instance()
146
+	{
147
+		// check if class object is instantiated, and instantiated properly
148
+		if (! self::$_instance instanceof EE_Config) {
149
+			self::$_instance = new self();
150
+		}
151
+		return self::$_instance;
152
+	}
153
+
154
+
155
+	/**
156
+	 * Resets the config
157
+	 *
158
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
159
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
160
+	 *                               reflect its state in the database
161
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
162
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
163
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
164
+	 *                               site was put into maintenance mode)
165
+	 * @return EE_Config
166
+	 */
167
+	public static function reset($hard_reset = false, $reinstantiate = true)
168
+	{
169
+		if (self::$_instance instanceof EE_Config) {
170
+			if ($hard_reset) {
171
+				self::$_instance->legacy_shortcodes_manager = null;
172
+				self::$_instance->_addon_option_names = array();
173
+				self::$_instance->_initialize_config();
174
+				self::$_instance->update_espresso_config();
175
+			}
176
+			self::$_instance->update_addon_option_names();
177
+		}
178
+		self::$_instance = null;
179
+		// we don't need to reset the static properties imo because those should
180
+		// only change when a module is added or removed. Currently we don't
181
+		// support removing a module during a request when it previously existed
182
+		if ($reinstantiate) {
183
+			return self::instance();
184
+		} else {
185
+			return null;
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 *    class constructor
192
+	 *
193
+	 * @access    private
194
+	 */
195
+	private function __construct()
196
+	{
197
+		do_action('AHEE__EE_Config__construct__begin', $this);
198
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
199
+		// setup empty config classes
200
+		$this->_initialize_config();
201
+		// load existing EE site settings
202
+		$this->_load_core_config();
203
+		// confirm everything loaded correctly and set filtered defaults if not
204
+		$this->_verify_config();
205
+		//  register shortcodes and modules
206
+		add_action(
207
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
208
+			array($this, 'register_shortcodes_and_modules'),
209
+			999
210
+		);
211
+		//  initialize shortcodes and modules
212
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
213
+		// register widgets
214
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
215
+		// shutdown
216
+		add_action('shutdown', array($this, 'shutdown'), 10);
217
+		// construct__end hook
218
+		do_action('AHEE__EE_Config__construct__end', $this);
219
+		// hardcoded hack
220
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return boolean
226
+	 */
227
+	public static function logging_enabled()
228
+	{
229
+		return self::$_logging_enabled;
230
+	}
231
+
232
+
233
+	/**
234
+	 * use to get the current theme if needed from static context
235
+	 *
236
+	 * @return string current theme set.
237
+	 */
238
+	public static function get_current_theme()
239
+	{
240
+		return isset(self::$_instance->template_settings->current_espresso_theme)
241
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
242
+	}
243
+
244
+
245
+	/**
246
+	 *        _initialize_config
247
+	 *
248
+	 * @access private
249
+	 * @return void
250
+	 */
251
+	private function _initialize_config()
252
+	{
253
+		EE_Config::trim_log();
254
+		// set defaults
255
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
256
+		$this->addons = new stdClass();
257
+		// set _module_route_map
258
+		EE_Config::$_module_route_map = array();
259
+		// set _module_forward_map
260
+		EE_Config::$_module_forward_map = array();
261
+		// set _module_view_map
262
+		EE_Config::$_module_view_map = array();
263
+	}
264
+
265
+
266
+	/**
267
+	 *        load core plugin configuration
268
+	 *
269
+	 * @access private
270
+	 * @return void
271
+	 */
272
+	private function _load_core_config()
273
+	{
274
+		// load_core_config__start hook
275
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
276
+		$espresso_config = $this->get_espresso_config();
277
+		foreach ($espresso_config as $config => $settings) {
278
+			// load_core_config__start hook
279
+			$settings = apply_filters(
280
+				'FHEE__EE_Config___load_core_config__config_settings',
281
+				$settings,
282
+				$config,
283
+				$this
284
+			);
285
+			if (is_object($settings) && property_exists($this, $config)) {
286
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
287
+				// call configs populate method to ensure any defaults are set for empty values.
288
+				if (method_exists($settings, 'populate')) {
289
+					$this->{$config}->populate();
290
+				}
291
+				if (method_exists($settings, 'do_hooks')) {
292
+					$this->{$config}->do_hooks();
293
+				}
294
+			}
295
+		}
296
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
297
+			$this->update_espresso_config();
298
+		}
299
+		// load_core_config__end hook
300
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
301
+	}
302
+
303
+
304
+	/**
305
+	 *    _verify_config
306
+	 *
307
+	 * @access    protected
308
+	 * @return    void
309
+	 */
310
+	protected function _verify_config()
311
+	{
312
+		$this->core = $this->core instanceof EE_Core_Config
313
+			? $this->core
314
+			: new EE_Core_Config();
315
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
316
+		$this->organization = $this->organization instanceof EE_Organization_Config
317
+			? $this->organization
318
+			: new EE_Organization_Config();
319
+		$this->organization = apply_filters(
320
+			'FHEE__EE_Config___initialize_config__organization',
321
+			$this->organization
322
+		);
323
+		$this->currency = $this->currency instanceof EE_Currency_Config
324
+			? $this->currency
325
+			: new EE_Currency_Config();
326
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
327
+		$this->registration = $this->registration instanceof EE_Registration_Config
328
+			? $this->registration
329
+			: new EE_Registration_Config();
330
+		$this->registration = apply_filters(
331
+			'FHEE__EE_Config___initialize_config__registration',
332
+			$this->registration
333
+		);
334
+		$this->admin = $this->admin instanceof EE_Admin_Config
335
+			? $this->admin
336
+			: new EE_Admin_Config();
337
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
339
+			? $this->template_settings
340
+			: new EE_Template_Config();
341
+		$this->template_settings = apply_filters(
342
+			'FHEE__EE_Config___initialize_config__template_settings',
343
+			$this->template_settings
344
+		);
345
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
346
+			? $this->map_settings
347
+			: new EE_Map_Config();
348
+		$this->map_settings = apply_filters(
349
+			'FHEE__EE_Config___initialize_config__map_settings',
350
+			$this->map_settings
351
+		);
352
+		$this->environment = $this->environment instanceof EE_Environment_Config
353
+			? $this->environment
354
+			: new EE_Environment_Config();
355
+		$this->environment = apply_filters(
356
+			'FHEE__EE_Config___initialize_config__environment',
357
+			$this->environment
358
+		);
359
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
360
+			? $this->tax_settings
361
+			: new EE_Tax_Config();
362
+		$this->tax_settings = apply_filters(
363
+			'FHEE__EE_Config___initialize_config__tax_settings',
364
+			$this->tax_settings
365
+		);
366
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
367
+		$this->messages = $this->messages instanceof EE_Messages_Config
368
+			? $this->messages
369
+			: new EE_Messages_Config();
370
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
371
+			? $this->gateway
372
+			: new EE_Gateway_Config();
373
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
374
+		$this->legacy_shortcodes_manager = null;
375
+	}
376
+
377
+
378
+	/**
379
+	 *    get_espresso_config
380
+	 *
381
+	 * @access    public
382
+	 * @return    array of espresso config stuff
383
+	 */
384
+	public function get_espresso_config()
385
+	{
386
+		// grab espresso configuration
387
+		return apply_filters(
388
+			'FHEE__EE_Config__get_espresso_config__CFG',
389
+			get_option(EE_Config::OPTION_NAME, array())
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 *    double_check_config_comparison
396
+	 *
397
+	 * @access    public
398
+	 * @param string $option
399
+	 * @param        $old_value
400
+	 * @param        $value
401
+	 */
402
+	public function double_check_config_comparison($option = '', $old_value, $value)
403
+	{
404
+		// make sure we're checking the ee config
405
+		if ($option === EE_Config::OPTION_NAME) {
406
+			// run a loose comparison of the old value against the new value for type and properties,
407
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
408
+			if ($value != $old_value) {
409
+				// if they are NOT the same, then remove the hook,
410
+				// which means the subsequent update results will be based solely on the update query results
411
+				// the reason we do this is because, as stated above,
412
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
413
+				// this happens PRIOR to serialization and any subsequent update.
414
+				// If values are found to match their previous old value,
415
+				// then WP bails before performing any update.
416
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
417
+				// it just pulled from the db, with the one being passed to it (which will not match).
418
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
419
+				// MySQL MAY ALSO NOT perform the update because
420
+				// the string it sees in the db looks the same as the new one it has been passed!!!
421
+				// This results in the query returning an "affected rows" value of ZERO,
422
+				// which gets returned immediately by WP update_option and looks like an error.
423
+				remove_action('update_option', array($this, 'check_config_updated'));
424
+			}
425
+		}
426
+	}
427
+
428
+
429
+	/**
430
+	 *    update_espresso_config
431
+	 *
432
+	 * @access   public
433
+	 */
434
+	protected function _reset_espresso_addon_config()
435
+	{
436
+		$this->_addon_option_names = array();
437
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
438
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
439
+			if ($addon_config_obj instanceof EE_Config_Base) {
440
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
441
+			}
442
+			$this->addons->{$addon_name} = null;
443
+		}
444
+	}
445
+
446
+
447
+	/**
448
+	 *    update_espresso_config
449
+	 *
450
+	 * @access   public
451
+	 * @param   bool $add_success
452
+	 * @param   bool $add_error
453
+	 * @return   bool
454
+	 */
455
+	public function update_espresso_config($add_success = false, $add_error = true)
456
+	{
457
+		// don't allow config updates during WP heartbeats
458
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
459
+			return false;
460
+		}
461
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
462
+		// $clone = clone( self::$_instance );
463
+		// self::$_instance = NULL;
464
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
465
+		$this->_reset_espresso_addon_config();
466
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
467
+		// but BEFORE the actual update occurs
468
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
469
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
470
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
471
+		$this->legacy_shortcodes_manager = null;
472
+		// now update "ee_config"
473
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
474
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
475
+		EE_Config::log(EE_Config::OPTION_NAME);
476
+		// if not saved... check if the hook we just added still exists;
477
+		// if it does, it means one of two things:
478
+		// that update_option bailed at the($value === $old_value) conditional,
479
+		// or...
480
+		// the db update query returned 0 rows affected
481
+		// (probably because the data  value was the same from it's perspective)
482
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
483
+		// but just means no update occurred, so don't display an error to the user.
484
+		// BUT... if update_option returns FALSE, AND the hook is missing,
485
+		// then it means that something truly went wrong
486
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
487
+		// remove our action since we don't want it in the system anymore
488
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
489
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
490
+		// self::$_instance = $clone;
491
+		// unset( $clone );
492
+		// if config remains the same or was updated successfully
493
+		if ($saved) {
494
+			if ($add_success) {
495
+				EE_Error::add_success(
496
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
497
+					__FILE__,
498
+					__FUNCTION__,
499
+					__LINE__
500
+				);
501
+			}
502
+			return true;
503
+		} else {
504
+			if ($add_error) {
505
+				EE_Error::add_error(
506
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
507
+					__FILE__,
508
+					__FUNCTION__,
509
+					__LINE__
510
+				);
511
+			}
512
+			return false;
513
+		}
514
+	}
515
+
516
+
517
+	/**
518
+	 *    _verify_config_params
519
+	 *
520
+	 * @access    private
521
+	 * @param    string         $section
522
+	 * @param    string         $name
523
+	 * @param    string         $config_class
524
+	 * @param    EE_Config_Base $config_obj
525
+	 * @param    array          $tests_to_run
526
+	 * @param    bool           $display_errors
527
+	 * @return    bool    TRUE on success, FALSE on fail
528
+	 */
529
+	private function _verify_config_params(
530
+		$section = '',
531
+		$name = '',
532
+		$config_class = '',
533
+		$config_obj = null,
534
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
535
+		$display_errors = true
536
+	) {
537
+		try {
538
+			foreach ($tests_to_run as $test) {
539
+				switch ($test) {
540
+					// TEST #1 : check that section was set
541
+					case 1:
542
+						if (empty($section)) {
543
+							if ($display_errors) {
544
+								throw new EE_Error(
545
+									sprintf(
546
+										__(
547
+											'No configuration section has been provided while attempting to save "%s".',
548
+											'event_espresso'
549
+										),
550
+										$config_class
551
+									)
552
+								);
553
+							}
554
+							return false;
555
+						}
556
+						break;
557
+					// TEST #2 : check that settings section exists
558
+					case 2:
559
+						if (! isset($this->{$section})) {
560
+							if ($display_errors) {
561
+								throw new EE_Error(
562
+									sprintf(
563
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
564
+										$section
565
+									)
566
+								);
567
+							}
568
+							return false;
569
+						}
570
+						break;
571
+					// TEST #3 : check that section is the proper format
572
+					case 3:
573
+						if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574
+						) {
575
+							if ($display_errors) {
576
+								throw new EE_Error(
577
+									sprintf(
578
+										__(
579
+											'The "%s" configuration settings have not been formatted correctly.',
580
+											'event_espresso'
581
+										),
582
+										$section
583
+									)
584
+								);
585
+							}
586
+							return false;
587
+						}
588
+						break;
589
+					// TEST #4 : check that config section name has been set
590
+					case 4:
591
+						if (empty($name)) {
592
+							if ($display_errors) {
593
+								throw new EE_Error(
594
+									__(
595
+										'No name has been provided for the specific configuration section.',
596
+										'event_espresso'
597
+									)
598
+								);
599
+							}
600
+							return false;
601
+						}
602
+						break;
603
+					// TEST #5 : check that a config class name has been set
604
+					case 5:
605
+						if (empty($config_class)) {
606
+							if ($display_errors) {
607
+								throw new EE_Error(
608
+									__(
609
+										'No class name has been provided for the specific configuration section.',
610
+										'event_espresso'
611
+									)
612
+								);
613
+							}
614
+							return false;
615
+						}
616
+						break;
617
+					// TEST #6 : verify config class is accessible
618
+					case 6:
619
+						if (! class_exists($config_class)) {
620
+							if ($display_errors) {
621
+								throw new EE_Error(
622
+									sprintf(
623
+										__(
624
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
625
+											'event_espresso'
626
+										),
627
+										$config_class
628
+									)
629
+								);
630
+							}
631
+							return false;
632
+						}
633
+						break;
634
+					// TEST #7 : check that config has even been set
635
+					case 7:
636
+						if (! isset($this->{$section}->{$name})) {
637
+							if ($display_errors) {
638
+								throw new EE_Error(
639
+									sprintf(
640
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
641
+										$section,
642
+										$name
643
+									)
644
+								);
645
+							}
646
+							return false;
647
+						} else {
648
+							// and make sure it's not serialized
649
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
650
+						}
651
+						break;
652
+					// TEST #8 : check that config is the requested type
653
+					case 8:
654
+						if (! $this->{$section}->{$name} instanceof $config_class) {
655
+							if ($display_errors) {
656
+								throw new EE_Error(
657
+									sprintf(
658
+										__(
659
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
660
+											'event_espresso'
661
+										),
662
+										$section,
663
+										$name,
664
+										$config_class
665
+									)
666
+								);
667
+							}
668
+							return false;
669
+						}
670
+						break;
671
+					// TEST #9 : verify config object
672
+					case 9:
673
+						if (! $config_obj instanceof EE_Config_Base) {
674
+							if ($display_errors) {
675
+								throw new EE_Error(
676
+									sprintf(
677
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
678
+										print_r($config_obj, true)
679
+									)
680
+								);
681
+							}
682
+							return false;
683
+						}
684
+						break;
685
+				}
686
+			}
687
+		} catch (EE_Error $e) {
688
+			$e->get_error();
689
+		}
690
+		// you have successfully run the gauntlet
691
+		return true;
692
+	}
693
+
694
+
695
+	/**
696
+	 *    _generate_config_option_name
697
+	 *
698
+	 * @access        protected
699
+	 * @param        string $section
700
+	 * @param        string $name
701
+	 * @return        string
702
+	 */
703
+	private function _generate_config_option_name($section = '', $name = '')
704
+	{
705
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
706
+	}
707
+
708
+
709
+	/**
710
+	 *    _set_config_class
711
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
712
+	 *
713
+	 * @access    private
714
+	 * @param    string $config_class
715
+	 * @param    string $name
716
+	 * @return    string
717
+	 */
718
+	private function _set_config_class($config_class = '', $name = '')
719
+	{
720
+		return ! empty($config_class)
721
+			? $config_class
722
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
723
+	}
724
+
725
+
726
+	/**
727
+	 *    set_config
728
+	 *
729
+	 * @access    protected
730
+	 * @param    string         $section
731
+	 * @param    string         $name
732
+	 * @param    string         $config_class
733
+	 * @param    EE_Config_Base $config_obj
734
+	 * @return    EE_Config_Base
735
+	 */
736
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
737
+	{
738
+		// ensure config class is set to something
739
+		$config_class = $this->_set_config_class($config_class, $name);
740
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
741
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742
+			return null;
743
+		}
744
+		$config_option_name = $this->_generate_config_option_name($section, $name);
745
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
+			$this->_addon_option_names[ $config_option_name ] = $config_class;
748
+			$this->update_addon_option_names();
749
+		}
750
+		// verify the incoming config object but suppress errors
751
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752
+			$config_obj = new $config_class();
753
+		}
754
+		if (get_option($config_option_name)) {
755
+			EE_Config::log($config_option_name);
756
+			update_option($config_option_name, $config_obj);
757
+			$this->{$section}->{$name} = $config_obj;
758
+			return $this->{$section}->{$name};
759
+		} else {
760
+			// create a wp-option for this config
761
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
762
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
763
+				return $this->{$section}->{$name};
764
+			} else {
765
+				EE_Error::add_error(
766
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
767
+					__FILE__,
768
+					__FUNCTION__,
769
+					__LINE__
770
+				);
771
+				return null;
772
+			}
773
+		}
774
+	}
775
+
776
+
777
+	/**
778
+	 *    update_config
779
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
780
+	 *
781
+	 * @access    public
782
+	 * @param    string                $section
783
+	 * @param    string                $name
784
+	 * @param    EE_Config_Base|string $config_obj
785
+	 * @param    bool                  $throw_errors
786
+	 * @return    bool
787
+	 */
788
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
789
+	{
790
+		// don't allow config updates during WP heartbeats
791
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
792
+			return false;
793
+		}
794
+		$config_obj = maybe_unserialize($config_obj);
795
+		// get class name of the incoming object
796
+		$config_class = get_class($config_obj);
797
+		// run tests 1-5 and 9 to verify config
798
+		if (! $this->_verify_config_params(
799
+			$section,
800
+			$name,
801
+			$config_class,
802
+			$config_obj,
803
+			array(1, 2, 3, 4, 7, 9)
804
+		)
805
+		) {
806
+			return false;
807
+		}
808
+		$config_option_name = $this->_generate_config_option_name($section, $name);
809
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
811
+			// save new config to db
812
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
813
+				return true;
814
+			}
815
+		} else {
816
+			// first check if the record already exists
817
+			$existing_config = get_option($config_option_name);
818
+			$config_obj = serialize($config_obj);
819
+			// just return if db record is already up to date (NOT type safe comparison)
820
+			if ($existing_config == $config_obj) {
821
+				$this->{$section}->{$name} = $config_obj;
822
+				return true;
823
+			} elseif (update_option($config_option_name, $config_obj)) {
824
+				EE_Config::log($config_option_name);
825
+				// update wp-option for this config class
826
+				$this->{$section}->{$name} = $config_obj;
827
+				return true;
828
+			} elseif ($throw_errors) {
829
+				EE_Error::add_error(
830
+					sprintf(
831
+						__(
832
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
833
+							'event_espresso'
834
+						),
835
+						$config_class,
836
+						'EE_Config->' . $section . '->' . $name
837
+					),
838
+					__FILE__,
839
+					__FUNCTION__,
840
+					__LINE__
841
+				);
842
+			}
843
+		}
844
+		return false;
845
+	}
846
+
847
+
848
+	/**
849
+	 *    get_config
850
+	 *
851
+	 * @access    public
852
+	 * @param    string $section
853
+	 * @param    string $name
854
+	 * @param    string $config_class
855
+	 * @return    mixed EE_Config_Base | NULL
856
+	 */
857
+	public function get_config($section = '', $name = '', $config_class = '')
858
+	{
859
+		// ensure config class is set to something
860
+		$config_class = $this->_set_config_class($config_class, $name);
861
+		// run tests 1-4, 6 and 7 to verify that all params have been set
862
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
+			return null;
864
+		}
865
+		// now test if the requested config object exists, but suppress errors
866
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
+			// config already exists, so pass it back
868
+			return $this->{$section}->{$name};
869
+		}
870
+		// load config option from db if it exists
871
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
+		// verify the newly retrieved config object, but suppress errors
873
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
+			// config is good, so set it and pass it back
875
+			$this->{$section}->{$name} = $config_obj;
876
+			return $this->{$section}->{$name};
877
+		}
878
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
879
+		$config_obj = $this->set_config($section, $name, $config_class);
880
+		// verify the newly created config object
881
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
+			return $this->{$section}->{$name};
883
+		} else {
884
+			EE_Error::add_error(
885
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
+				__FILE__,
887
+				__FUNCTION__,
888
+				__LINE__
889
+			);
890
+		}
891
+		return null;
892
+	}
893
+
894
+
895
+	/**
896
+	 *    get_config_option
897
+	 *
898
+	 * @access    public
899
+	 * @param    string $config_option_name
900
+	 * @return    mixed EE_Config_Base | FALSE
901
+	 */
902
+	public function get_config_option($config_option_name = '')
903
+	{
904
+		// retrieve the wp-option for this config class.
905
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
906
+		if (empty($config_option)) {
907
+			EE_Config::log($config_option_name . '-NOT-FOUND');
908
+		}
909
+		return $config_option;
910
+	}
911
+
912
+
913
+	/**
914
+	 * log
915
+	 *
916
+	 * @param string $config_option_name
917
+	 */
918
+	public static function log($config_option_name = '')
919
+	{
920
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
921
+			$config_log = get_option(EE_Config::LOG_NAME, array());
922
+			// copy incoming $_REQUEST and sanitize it so we can save it
923
+			$_request = $_REQUEST;
924
+			array_walk_recursive($_request, 'sanitize_text_field');
925
+			$config_log[ (string) microtime(true) ] = array(
926
+				'config_name' => $config_option_name,
927
+				'request'     => $_request,
928
+			);
929
+			update_option(EE_Config::LOG_NAME, $config_log);
930
+		}
931
+	}
932
+
933
+
934
+	/**
935
+	 * trim_log
936
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
937
+	 */
938
+	public static function trim_log()
939
+	{
940
+		if (! EE_Config::logging_enabled()) {
941
+			return;
942
+		}
943
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
944
+		$log_length = count($config_log);
945
+		if ($log_length > EE_Config::LOG_LENGTH) {
946
+			ksort($config_log);
947
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
948
+			update_option(EE_Config::LOG_NAME, $config_log);
949
+		}
950
+	}
951
+
952
+
953
+	/**
954
+	 *    get_page_for_posts
955
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
956
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
957
+	 *
958
+	 * @access    public
959
+	 * @return    string
960
+	 */
961
+	public static function get_page_for_posts()
962
+	{
963
+		$page_for_posts = get_option('page_for_posts');
964
+		if (! $page_for_posts) {
965
+			return 'posts';
966
+		}
967
+		/** @type WPDB $wpdb */
968
+		global $wpdb;
969
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
970
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
971
+	}
972
+
973
+
974
+	/**
975
+	 *    register_shortcodes_and_modules.
976
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
977
+	 *    In fact, this is where we give modules a chance to let core know they exist
978
+	 *    so they can help trigger maintenance mode if it's needed
979
+	 *
980
+	 * @access    public
981
+	 * @return    void
982
+	 */
983
+	public function register_shortcodes_and_modules()
984
+	{
985
+		// allow modules to set hooks for the rest of the system
986
+		EE_Registry::instance()->modules = $this->_register_modules();
987
+	}
988
+
989
+
990
+	/**
991
+	 *    initialize_shortcodes_and_modules
992
+	 *    meaning they can start adding their hooks to get stuff done
993
+	 *
994
+	 * @access    public
995
+	 * @return    void
996
+	 */
997
+	public function initialize_shortcodes_and_modules()
998
+	{
999
+		// allow modules to set hooks for the rest of the system
1000
+		$this->_initialize_modules();
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 *    widgets_init
1006
+	 *
1007
+	 * @access private
1008
+	 * @return void
1009
+	 */
1010
+	public function widgets_init()
1011
+	{
1012
+		// only init widgets on admin pages when not in complete maintenance, and
1013
+		// on frontend when not in any maintenance mode
1014
+		if (! EE_Maintenance_Mode::instance()->level()
1015
+			|| (
1016
+				is_admin()
1017
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018
+			)
1019
+		) {
1020
+			// grab list of installed widgets
1021
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1022
+			// filter list of modules to register
1023
+			$widgets_to_register = apply_filters(
1024
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1025
+				$widgets_to_register
1026
+			);
1027
+			if (! empty($widgets_to_register)) {
1028
+				// cycle thru widget folders
1029
+				foreach ($widgets_to_register as $widget_path) {
1030
+					// add to list of installed widget modules
1031
+					EE_Config::register_ee_widget($widget_path);
1032
+				}
1033
+			}
1034
+			// filter list of installed modules
1035
+			EE_Registry::instance()->widgets = apply_filters(
1036
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1037
+				EE_Registry::instance()->widgets
1038
+			);
1039
+		}
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 *    register_ee_widget - makes core aware of this widget
1045
+	 *
1046
+	 * @access    public
1047
+	 * @param    string $widget_path - full path up to and including widget folder
1048
+	 * @return    void
1049
+	 */
1050
+	public static function register_ee_widget($widget_path = null)
1051
+	{
1052
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1053
+		$widget_ext = '.widget.php';
1054
+		// make all separators match
1055
+		$widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1056
+		// does the file path INCLUDE the actual file name as part of the path ?
1057
+		if (strpos($widget_path, $widget_ext) !== false) {
1058
+			// grab and shortcode file name from directory name and break apart at dots
1059
+			$file_name = explode('.', basename($widget_path));
1060
+			// take first segment from file name pieces and remove class prefix if it exists
1061
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1062
+			// sanitize shortcode directory name
1063
+			$widget = sanitize_key($widget);
1064
+			// now we need to rebuild the shortcode path
1065
+			$widget_path = explode('/', $widget_path);
1066
+			// remove last segment
1067
+			array_pop($widget_path);
1068
+			// glue it back together
1069
+			$widget_path = implode(DS, $widget_path);
1070
+		} else {
1071
+			// grab and sanitize widget directory name
1072
+			$widget = sanitize_key(basename($widget_path));
1073
+		}
1074
+		// create classname from widget directory name
1075
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076
+		// add class prefix
1077
+		$widget_class = 'EEW_' . $widget;
1078
+		// does the widget exist ?
1079
+		if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1080
+			$msg = sprintf(
1081
+				__(
1082
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083
+					'event_espresso'
1084
+				),
1085
+				$widget_class,
1086
+				$widget_path . '/' . $widget_class . $widget_ext
1087
+			);
1088
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1089
+			return;
1090
+		}
1091
+		// load the widget class file
1092
+		require_once($widget_path . '/' . $widget_class . $widget_ext);
1093
+		// verify that class exists
1094
+		if (! class_exists($widget_class)) {
1095
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1097
+			return;
1098
+		}
1099
+		register_widget($widget_class);
1100
+		// add to array of registered widgets
1101
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1102
+	}
1103
+
1104
+
1105
+	/**
1106
+	 *        _register_modules
1107
+	 *
1108
+	 * @access private
1109
+	 * @return array
1110
+	 */
1111
+	private function _register_modules()
1112
+	{
1113
+		// grab list of installed modules
1114
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1115
+		// filter list of modules to register
1116
+		$modules_to_register = apply_filters(
1117
+			'FHEE__EE_Config__register_modules__modules_to_register',
1118
+			$modules_to_register
1119
+		);
1120
+		if (! empty($modules_to_register)) {
1121
+			// loop through folders
1122
+			foreach ($modules_to_register as $module_path) {
1123
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
+				if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
+					&& $module_path !== EE_MODULES . 'gateways'
1126
+				) {
1127
+					// add to list of installed modules
1128
+					EE_Config::register_module($module_path);
1129
+				}
1130
+			}
1131
+		}
1132
+		// filter list of installed modules
1133
+		return apply_filters(
1134
+			'FHEE__EE_Config___register_modules__installed_modules',
1135
+			EE_Registry::instance()->modules
1136
+		);
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 *    register_module - makes core aware of this module
1142
+	 *
1143
+	 * @access    public
1144
+	 * @param    string $module_path - full path up to and including module folder
1145
+	 * @return    bool
1146
+	 */
1147
+	public static function register_module($module_path = null)
1148
+	{
1149
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1150
+		$module_ext = '.module.php';
1151
+		// make all separators match
1152
+		$module_path = str_replace(array('\\', '/'), '/', $module_path);
1153
+		// does the file path INCLUDE the actual file name as part of the path ?
1154
+		if (strpos($module_path, $module_ext) !== false) {
1155
+			// grab and shortcode file name from directory name and break apart at dots
1156
+			$module_file = explode('.', basename($module_path));
1157
+			// now we need to rebuild the shortcode path
1158
+			$module_path = explode('/', $module_path);
1159
+			// remove last segment
1160
+			array_pop($module_path);
1161
+			// glue it back together
1162
+			$module_path = implode('/', $module_path) . '/';
1163
+			// take first segment from file name pieces and sanitize it
1164
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165
+			// ensure class prefix is added
1166
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1167
+		} else {
1168
+			// we need to generate the filename based off of the folder name
1169
+			// grab and sanitize module name
1170
+			$module = strtolower(basename($module_path));
1171
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172
+			// like trailingslashit()
1173
+			$module_path = rtrim($module_path, '/') . '/';
1174
+			// create classname from module directory name
1175
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176
+			// add class prefix
1177
+			$module_class = 'EED_' . $module;
1178
+		}
1179
+		// does the module exist ?
1180
+		if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1181
+			$msg = sprintf(
1182
+				__(
1183
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1184
+					'event_espresso'
1185
+				),
1186
+				$module
1187
+			);
1188
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1189
+			return false;
1190
+		}
1191
+		// load the module class file
1192
+		require_once($module_path . $module_class . $module_ext);
1193
+		// verify that class exists
1194
+		if (! class_exists($module_class)) {
1195
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1197
+			return false;
1198
+		}
1199
+		// add to array of registered modules
1200
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1201
+		do_action(
1202
+			'AHEE__EE_Config__register_module__complete',
1203
+			$module_class,
1204
+			EE_Registry::instance()->modules->{$module_class}
1205
+		);
1206
+		return true;
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 *    _initialize_modules
1212
+	 *    allow modules to set hooks for the rest of the system
1213
+	 *
1214
+	 * @access private
1215
+	 * @return void
1216
+	 */
1217
+	private function _initialize_modules()
1218
+	{
1219
+		// cycle thru shortcode folders
1220
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1221
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1222
+			// which set hooks ?
1223
+			if (is_admin()) {
1224
+				// fire immediately
1225
+				call_user_func(array($module_class, 'set_hooks_admin'));
1226
+			} else {
1227
+				// delay until other systems are online
1228
+				add_action(
1229
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1230
+					array($module_class, 'set_hooks')
1231
+				);
1232
+			}
1233
+		}
1234
+	}
1235
+
1236
+
1237
+	/**
1238
+	 *    register_route - adds module method routes to route_map
1239
+	 *
1240
+	 * @access    public
1241
+	 * @param    string $route       - "pretty" public alias for module method
1242
+	 * @param    string $module      - module name (classname without EED_ prefix)
1243
+	 * @param    string $method_name - the actual module method to be routed to
1244
+	 * @param    string $key         - url param key indicating a route is being called
1245
+	 * @return    bool
1246
+	 */
1247
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1248
+	{
1249
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250
+		$module = str_replace('EED_', '', $module);
1251
+		$module_class = 'EED_' . $module;
1252
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1253
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1255
+			return false;
1256
+		}
1257
+		if (empty($route)) {
1258
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1260
+			return false;
1261
+		}
1262
+		if (! method_exists('EED_' . $module, $method_name)) {
1263
+			$msg = sprintf(
1264
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265
+				$route
1266
+			);
1267
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1268
+			return false;
1269
+		}
1270
+		EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1271
+		return true;
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 *    get_route - get module method route
1277
+	 *
1278
+	 * @access    public
1279
+	 * @param    string $route - "pretty" public alias for module method
1280
+	 * @param    string $key   - url param key indicating a route is being called
1281
+	 * @return    string
1282
+	 */
1283
+	public static function get_route($route = null, $key = 'ee')
1284
+	{
1285
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1286
+		$route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
+		if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
+			return EE_Config::$_module_route_map[ $key ][ $route ];
1289
+		}
1290
+		return null;
1291
+	}
1292
+
1293
+
1294
+	/**
1295
+	 *    get_routes - get ALL module method routes
1296
+	 *
1297
+	 * @access    public
1298
+	 * @return    array
1299
+	 */
1300
+	public static function get_routes()
1301
+	{
1302
+		return EE_Config::$_module_route_map;
1303
+	}
1304
+
1305
+
1306
+	/**
1307
+	 *    register_forward - allows modules to forward request to another module for further processing
1308
+	 *
1309
+	 * @access    public
1310
+	 * @param    string       $route   - "pretty" public alias for module method
1311
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1312
+	 *                                 class, allows different forwards to be served based on status
1313
+	 * @param    array|string $forward - function name or array( class, method )
1314
+	 * @param    string       $key     - url param key indicating a route is being called
1315
+	 * @return    bool
1316
+	 */
1317
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318
+	{
1319
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1321
+			$msg = sprintf(
1322
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1323
+				$route
1324
+			);
1325
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1326
+			return false;
1327
+		}
1328
+		if (empty($forward)) {
1329
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1331
+			return false;
1332
+		}
1333
+		if (is_array($forward)) {
1334
+			if (! isset($forward[1])) {
1335
+				$msg = sprintf(
1336
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337
+					$route
1338
+				);
1339
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1340
+				return false;
1341
+			}
1342
+			if (! method_exists($forward[0], $forward[1])) {
1343
+				$msg = sprintf(
1344
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345
+					$forward[1],
1346
+					$route
1347
+				);
1348
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1349
+				return false;
1350
+			}
1351
+		} elseif (! function_exists($forward)) {
1352
+			$msg = sprintf(
1353
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354
+				$forward,
1355
+				$route
1356
+			);
1357
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1358
+			return false;
1359
+		}
1360
+		EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1361
+		return true;
1362
+	}
1363
+
1364
+
1365
+	/**
1366
+	 *    get_forward - get forwarding route
1367
+	 *
1368
+	 * @access    public
1369
+	 * @param    string  $route  - "pretty" public alias for module method
1370
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1371
+	 *                           allows different forwards to be served based on status
1372
+	 * @param    string  $key    - url param key indicating a route is being called
1373
+	 * @return    string
1374
+	 */
1375
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1376
+	{
1377
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
+		if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1379
+			return apply_filters(
1380
+				'FHEE__EE_Config__get_forward',
1381
+				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1382
+				$route,
1383
+				$status
1384
+			);
1385
+		}
1386
+		return null;
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1392
+	 *    results
1393
+	 *
1394
+	 * @access    public
1395
+	 * @param    string  $route  - "pretty" public alias for module method
1396
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1397
+	 *                           allows different views to be served based on status
1398
+	 * @param    string  $view
1399
+	 * @param    string  $key    - url param key indicating a route is being called
1400
+	 * @return    bool
1401
+	 */
1402
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403
+	{
1404
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1406
+			$msg = sprintf(
1407
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1408
+				$route
1409
+			);
1410
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1411
+			return false;
1412
+		}
1413
+		if (! is_readable($view)) {
1414
+			$msg = sprintf(
1415
+				__(
1416
+					'The %s view file could not be found or is not readable due to file permissions.',
1417
+					'event_espresso'
1418
+				),
1419
+				$view
1420
+			);
1421
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
+			return false;
1423
+		}
1424
+		EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1425
+		return true;
1426
+	}
1427
+
1428
+
1429
+	/**
1430
+	 *    get_view - get view for route and status
1431
+	 *
1432
+	 * @access    public
1433
+	 * @param    string  $route  - "pretty" public alias for module method
1434
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1435
+	 *                           allows different views to be served based on status
1436
+	 * @param    string  $key    - url param key indicating a route is being called
1437
+	 * @return    string
1438
+	 */
1439
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1440
+	{
1441
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
+		if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1443
+			return apply_filters(
1444
+				'FHEE__EE_Config__get_view',
1445
+				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1446
+				$route,
1447
+				$status
1448
+			);
1449
+		}
1450
+		return null;
1451
+	}
1452
+
1453
+
1454
+	public function update_addon_option_names()
1455
+	{
1456
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1457
+	}
1458
+
1459
+
1460
+	public function shutdown()
1461
+	{
1462
+		$this->update_addon_option_names();
1463
+	}
1464
+
1465
+
1466
+	/**
1467
+	 * @return LegacyShortcodesManager
1468
+	 */
1469
+	public static function getLegacyShortcodesManager()
1470
+	{
1471
+
1472
+		if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474
+				EE_Registry::instance()
1475
+			);
1476
+		}
1477
+		return EE_Config::instance()->legacy_shortcodes_manager;
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * register_shortcode - makes core aware of this shortcode
1483
+	 *
1484
+	 * @deprecated 4.9.26
1485
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1486
+	 * @return    bool
1487
+	 */
1488
+	public static function register_shortcode($shortcode_path = null)
1489
+	{
1490
+		EE_Error::doing_it_wrong(
1491
+			__METHOD__,
1492
+			__(
1493
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1494
+				'event_espresso'
1495
+			),
1496
+			'4.9.26'
1497
+		);
1498
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1499
+	}
1500
+}
2262 1501
 
2263
-    /**
2264
-     * ReCaptcha Type
2265
-     *
2266
-     * @var string $recaptcha_type
2267
-     *    options: 'audio', 'image'
2268
-     */
2269
-    public $recaptcha_type;
1502
+/**
1503
+ * Base class used for config classes. These classes should generally not have
1504
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1505
+ * basically, they should just be well-defined stdClasses
1506
+ */
1507
+class EE_Config_Base
1508
+{
2270 1509
 
2271
-    /**
2272
-     * ReCaptcha language
2273
-     *
2274
-     * @var string $recaptcha_language
2275
-     * eg 'en'
2276
-     */
2277
-    public $recaptcha_language;
1510
+	/**
1511
+	 * Utility function for escaping the value of a property and returning.
1512
+	 *
1513
+	 * @param string $property property name (checks to see if exists).
1514
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1515
+	 * @throws \EE_Error
1516
+	 */
1517
+	public function get_pretty($property)
1518
+	{
1519
+		if (! property_exists($this, $property)) {
1520
+			throw new EE_Error(
1521
+				sprintf(
1522
+					__(
1523
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1524
+						'event_espresso'
1525
+					),
1526
+					get_class($this),
1527
+					$property
1528
+				)
1529
+			);
1530
+		}
1531
+		// just handling escaping of strings for now.
1532
+		if (is_string($this->{$property})) {
1533
+			return stripslashes($this->{$property});
1534
+		}
1535
+		return $this->{$property};
1536
+	}
1537
+
1538
+
1539
+	public function populate()
1540
+	{
1541
+		// grab defaults via a new instance of this class.
1542
+		$class_name = get_class($this);
1543
+		$defaults = new $class_name;
1544
+		// loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1545
+		// default from our $defaults object.
1546
+		foreach (get_object_vars($defaults) as $property => $value) {
1547
+			if ($this->{$property} === null) {
1548
+				$this->{$property} = $value;
1549
+			}
1550
+		}
1551
+		// cleanup
1552
+		unset($defaults);
1553
+	}
1554
+
1555
+
1556
+	/**
1557
+	 *        __isset
1558
+	 *
1559
+	 * @param $a
1560
+	 * @return bool
1561
+	 */
1562
+	public function __isset($a)
1563
+	{
1564
+		return false;
1565
+	}
1566
+
1567
+
1568
+	/**
1569
+	 *        __unset
1570
+	 *
1571
+	 * @param $a
1572
+	 * @return bool
1573
+	 */
1574
+	public function __unset($a)
1575
+	{
1576
+		return false;
1577
+	}
1578
+
1579
+
1580
+	/**
1581
+	 *        __clone
1582
+	 */
1583
+	public function __clone()
1584
+	{
1585
+	}
1586
+
1587
+
1588
+	/**
1589
+	 *        __wakeup
1590
+	 */
1591
+	public function __wakeup()
1592
+	{
1593
+	}
1594
+
1595
+
1596
+	/**
1597
+	 *        __destruct
1598
+	 */
1599
+	public function __destruct()
1600
+	{
1601
+	}
1602
+}
2278 1603
 
2279
-    /**
2280
-     * ReCaptcha public key
2281
-     *
2282
-     * @var string $recaptcha_publickey
2283
-     */
2284
-    public $recaptcha_publickey;
1604
+/**
1605
+ * Class for defining what's in the EE_Config relating to registration settings
1606
+ */
1607
+class EE_Core_Config extends EE_Config_Base
1608
+{
2285 1609
 
2286
-    /**
2287
-     * ReCaptcha private key
2288
-     *
2289
-     * @var string $recaptcha_privatekey
2290
-     */
2291
-    public $recaptcha_privatekey;
1610
+	const OPTION_NAME_UXIP = 'ee_ueip_optin';
1611
+
1612
+
1613
+	public $current_blog_id;
1614
+
1615
+	public $ee_ueip_optin;
1616
+
1617
+	public $ee_ueip_has_notified;
1618
+
1619
+	/**
1620
+	 * Not to be confused with the 4 critical page variables (See
1621
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1622
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1623
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1624
+	 *
1625
+	 * @var array
1626
+	 */
1627
+	public $post_shortcodes;
1628
+
1629
+	public $module_route_map;
1630
+
1631
+	public $module_forward_map;
1632
+
1633
+	public $module_view_map;
1634
+
1635
+	/**
1636
+	 * The next 4 vars are the IDs of critical EE pages.
1637
+	 *
1638
+	 * @var int
1639
+	 */
1640
+	public $reg_page_id;
1641
+
1642
+	public $txn_page_id;
1643
+
1644
+	public $thank_you_page_id;
1645
+
1646
+	public $cancel_page_id;
1647
+
1648
+	/**
1649
+	 * The next 4 vars are the URLs of critical EE pages.
1650
+	 *
1651
+	 * @var int
1652
+	 */
1653
+	public $reg_page_url;
1654
+
1655
+	public $txn_page_url;
1656
+
1657
+	public $thank_you_page_url;
1658
+
1659
+	public $cancel_page_url;
1660
+
1661
+	/**
1662
+	 * The next vars relate to the custom slugs for EE CPT routes
1663
+	 */
1664
+	public $event_cpt_slug;
1665
+
1666
+	/**
1667
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1668
+	 * request across blog switches in a multisite context.
1669
+	 * Avoids extra queries to the db for this option.
1670
+	 *
1671
+	 * @var bool
1672
+	 */
1673
+	public static $ee_ueip_option;
1674
+
1675
+
1676
+	/**
1677
+	 *    class constructor
1678
+	 *
1679
+	 * @access    public
1680
+	 */
1681
+	public function __construct()
1682
+	{
1683
+		// set default organization settings
1684
+		$this->current_blog_id = get_current_blog_id();
1685
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
+		$this->post_shortcodes = array();
1689
+		$this->module_route_map = array();
1690
+		$this->module_forward_map = array();
1691
+		$this->module_view_map = array();
1692
+		// critical EE page IDs
1693
+		$this->reg_page_id = 0;
1694
+		$this->txn_page_id = 0;
1695
+		$this->thank_you_page_id = 0;
1696
+		$this->cancel_page_id = 0;
1697
+		// critical EE page URLs
1698
+		$this->reg_page_url = '';
1699
+		$this->txn_page_url = '';
1700
+		$this->thank_you_page_url = '';
1701
+		$this->cancel_page_url = '';
1702
+		// cpt slugs
1703
+		$this->event_cpt_slug = __('events', 'event_espresso');
1704
+		// ueip constant check
1705
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
+			$this->ee_ueip_optin = false;
1707
+			$this->ee_ueip_has_notified = true;
1708
+		}
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * @return array
1714
+	 */
1715
+	public function get_critical_pages_array()
1716
+	{
1717
+		return array(
1718
+			$this->reg_page_id,
1719
+			$this->txn_page_id,
1720
+			$this->thank_you_page_id,
1721
+			$this->cancel_page_id,
1722
+		);
1723
+	}
1724
+
1725
+
1726
+	/**
1727
+	 * @return array
1728
+	 */
1729
+	public function get_critical_pages_shortcodes_array()
1730
+	{
1731
+		return array(
1732
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
+		);
1737
+	}
1738
+
1739
+
1740
+	/**
1741
+	 *  gets/returns URL for EE reg_page
1742
+	 *
1743
+	 * @access    public
1744
+	 * @return    string
1745
+	 */
1746
+	public function reg_page_url()
1747
+	{
1748
+		if (! $this->reg_page_url) {
1749
+			$this->reg_page_url = add_query_arg(
1750
+				array('uts' => time()),
1751
+				get_permalink($this->reg_page_id)
1752
+			) . '#checkout';
1753
+		}
1754
+		return $this->reg_page_url;
1755
+	}
1756
+
1757
+
1758
+	/**
1759
+	 *  gets/returns URL for EE txn_page
1760
+	 *
1761
+	 * @param array $query_args like what gets passed to
1762
+	 *                          add_query_arg() as the first argument
1763
+	 * @access    public
1764
+	 * @return    string
1765
+	 */
1766
+	public function txn_page_url($query_args = array())
1767
+	{
1768
+		if (! $this->txn_page_url) {
1769
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1770
+		}
1771
+		if ($query_args) {
1772
+			return add_query_arg($query_args, $this->txn_page_url);
1773
+		} else {
1774
+			return $this->txn_page_url;
1775
+		}
1776
+	}
1777
+
1778
+
1779
+	/**
1780
+	 *  gets/returns URL for EE thank_you_page
1781
+	 *
1782
+	 * @param array $query_args like what gets passed to
1783
+	 *                          add_query_arg() as the first argument
1784
+	 * @access    public
1785
+	 * @return    string
1786
+	 */
1787
+	public function thank_you_page_url($query_args = array())
1788
+	{
1789
+		if (! $this->thank_you_page_url) {
1790
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
+		}
1792
+		if ($query_args) {
1793
+			return add_query_arg($query_args, $this->thank_you_page_url);
1794
+		} else {
1795
+			return $this->thank_you_page_url;
1796
+		}
1797
+	}
1798
+
1799
+
1800
+	/**
1801
+	 *  gets/returns URL for EE cancel_page
1802
+	 *
1803
+	 * @access    public
1804
+	 * @return    string
1805
+	 */
1806
+	public function cancel_page_url()
1807
+	{
1808
+		if (! $this->cancel_page_url) {
1809
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
+		}
1811
+		return $this->cancel_page_url;
1812
+	}
1813
+
1814
+
1815
+	/**
1816
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
+	 *
1818
+	 * @since 4.7.5
1819
+	 */
1820
+	protected function _reset_urls()
1821
+	{
1822
+		$this->reg_page_url = '';
1823
+		$this->txn_page_url = '';
1824
+		$this->cancel_page_url = '';
1825
+		$this->thank_you_page_url = '';
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * Used to return what the optin value is set for the EE User Experience Program.
1831
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
+	 * on the main site only.
1833
+	 *
1834
+	 * @return bool
1835
+	 */
1836
+	protected function _get_main_ee_ueip_optin()
1837
+	{
1838
+		// if this is the main site then we can just bypass our direct query.
1839
+		if (is_main_site()) {
1840
+			return get_option(self::OPTION_NAME_UXIP, false);
1841
+		}
1842
+		// is this already cached for this request?  If so use it.
1843
+		if (EE_Core_Config::$ee_ueip_option !== null) {
1844
+			return EE_Core_Config::$ee_ueip_option;
1845
+		}
1846
+		global $wpdb;
1847
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1848
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
+		$option = self::OPTION_NAME_UXIP;
1850
+		// set correct table for query
1851
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
+		// rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
+		// get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
+		// re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
+		// this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
+		// for the purpose of caching.
1857
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1858
+		if (false !== $pre) {
1859
+			EE_Core_Config::$ee_ueip_option = $pre;
1860
+			return EE_Core_Config::$ee_ueip_option;
1861
+		}
1862
+		$row = $wpdb->get_row(
1863
+			$wpdb->prepare(
1864
+				"SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
+				$option
1866
+			)
1867
+		);
1868
+		if (is_object($row)) {
1869
+			$value = $row->option_value;
1870
+		} else { // option does not exist so use default.
1871
+			EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1872
+			return EE_Core_Config::$ee_ueip_option;
1873
+		}
1874
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1875
+		return EE_Core_Config::$ee_ueip_option;
1876
+	}
1877
+
1878
+
1879
+	/**
1880
+	 * Utility function for escaping the value of a property and returning.
1881
+	 *
1882
+	 * @param string $property property name (checks to see if exists).
1883
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1884
+	 * @throws \EE_Error
1885
+	 */
1886
+	public function get_pretty($property)
1887
+	{
1888
+		if ($property === self::OPTION_NAME_UXIP) {
1889
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1890
+		}
1891
+		return parent::get_pretty($property);
1892
+	}
1893
+
1894
+
1895
+	/**
1896
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1897
+	 * on the object.
1898
+	 *
1899
+	 * @return array
1900
+	 */
1901
+	public function __sleep()
1902
+	{
1903
+		// reset all url properties
1904
+		$this->_reset_urls();
1905
+		// return what to save to db
1906
+		return array_keys(get_object_vars($this));
1907
+	}
1908
+}
2292 1909
 
2293
-    /**
2294
-     * array of form names protected by ReCaptcha
2295
-     *
2296
-     * @var array $recaptcha_protected_forms
2297
-     */
2298
-    public $recaptcha_protected_forms;
1910
+/**
1911
+ * Config class for storing info on the Organization
1912
+ */
1913
+class EE_Organization_Config extends EE_Config_Base
1914
+{
2299 1915
 
2300
-    /**
2301
-     * ReCaptcha width
2302
-     *
2303
-     * @var int $recaptcha_width
2304
-     * @deprecated
2305
-     */
2306
-    public $recaptcha_width;
1916
+	/**
1917
+	 * @var string $name
1918
+	 * eg EE4.1
1919
+	 */
1920
+	public $name;
1921
+
1922
+	/**
1923
+	 * @var string $address_1
1924
+	 * eg 123 Onna Road
1925
+	 */
1926
+	public $address_1 = '';
1927
+
1928
+	/**
1929
+	 * @var string $address_2
1930
+	 * eg PO Box 123
1931
+	 */
1932
+	public $address_2 = '';
1933
+
1934
+	/**
1935
+	 * @var string $city
1936
+	 * eg Inna City
1937
+	 */
1938
+	public $city = '';
1939
+
1940
+	/**
1941
+	 * @var int $STA_ID
1942
+	 * eg 4
1943
+	 */
1944
+	public $STA_ID = 0;
1945
+
1946
+	/**
1947
+	 * @var string $CNT_ISO
1948
+	 * eg US
1949
+	 */
1950
+	public $CNT_ISO = '';
1951
+
1952
+	/**
1953
+	 * @var string $zip
1954
+	 * eg 12345  or V1A 2B3
1955
+	 */
1956
+	public $zip = '';
1957
+
1958
+	/**
1959
+	 * @var string $email
1960
+	 * eg [email protected]
1961
+	 */
1962
+	public $email;
1963
+
1964
+	/**
1965
+	 * @var string $phone
1966
+	 * eg. 111-111-1111
1967
+	 */
1968
+	public $phone = '';
1969
+
1970
+	/**
1971
+	 * @var string $vat
1972
+	 * VAT/Tax Number
1973
+	 */
1974
+	public $vat = '';
1975
+
1976
+	/**
1977
+	 * @var string $logo_url
1978
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1979
+	 */
1980
+	public $logo_url = '';
1981
+
1982
+	/**
1983
+	 * The below are all various properties for holding links to organization social network profiles
1984
+	 *
1985
+	 * @var string
1986
+	 */
1987
+	/**
1988
+	 * facebook (facebook.com/profile.name)
1989
+	 *
1990
+	 * @var string
1991
+	 */
1992
+	public $facebook = '';
1993
+
1994
+	/**
1995
+	 * twitter (twitter.com/twitter_handle)
1996
+	 *
1997
+	 * @var string
1998
+	 */
1999
+	public $twitter = '';
2000
+
2001
+	/**
2002
+	 * linkedin (linkedin.com/in/profile_name)
2003
+	 *
2004
+	 * @var string
2005
+	 */
2006
+	public $linkedin = '';
2007
+
2008
+	/**
2009
+	 * pinterest (www.pinterest.com/profile_name)
2010
+	 *
2011
+	 * @var string
2012
+	 */
2013
+	public $pinterest = '';
2014
+
2015
+	/**
2016
+	 * google+ (google.com/+profileName)
2017
+	 *
2018
+	 * @var string
2019
+	 */
2020
+	public $google = '';
2021
+
2022
+	/**
2023
+	 * instagram (instagram.com/handle)
2024
+	 *
2025
+	 * @var string
2026
+	 */
2027
+	public $instagram = '';
2028
+
2029
+
2030
+	/**
2031
+	 *    class constructor
2032
+	 *
2033
+	 * @access    public
2034
+	 */
2035
+	public function __construct()
2036
+	{
2037
+		// set default organization settings
2038
+		// decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2039
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2040
+		$this->email = get_bloginfo('admin_email');
2041
+	}
2042
+}
2307 2043
 
2308
-    /**
2309
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2310
-     *
2311
-     * @var boolean $track_invalid_checkout_access
2312
-     */
2313
-    protected $track_invalid_checkout_access = true;
2044
+/**
2045
+ * Class for defining what's in the EE_Config relating to currency
2046
+ */
2047
+class EE_Currency_Config extends EE_Config_Base
2048
+{
2314 2049
 
2315
-    /**
2316
-     * Whether or not to show the privacy policy consent checkbox
2317
-     *
2318
-     * @var bool
2319
-     */
2320
-    public $consent_checkbox_enabled;
2050
+	/**
2051
+	 * @var string $code
2052
+	 * eg 'US'
2053
+	 */
2054
+	public $code;
2055
+
2056
+	/**
2057
+	 * @var string $name
2058
+	 * eg 'Dollar'
2059
+	 */
2060
+	public $name;
2061
+
2062
+	/**
2063
+	 * plural name
2064
+	 *
2065
+	 * @var string $plural
2066
+	 * eg 'Dollars'
2067
+	 */
2068
+	public $plural;
2069
+
2070
+	/**
2071
+	 * currency sign
2072
+	 *
2073
+	 * @var string $sign
2074
+	 * eg '$'
2075
+	 */
2076
+	public $sign;
2077
+
2078
+	/**
2079
+	 * Whether the currency sign should come before the number or not
2080
+	 *
2081
+	 * @var boolean $sign_b4
2082
+	 */
2083
+	public $sign_b4;
2084
+
2085
+	/**
2086
+	 * How many digits should come after the decimal place
2087
+	 *
2088
+	 * @var int $dec_plc
2089
+	 */
2090
+	public $dec_plc;
2091
+
2092
+	/**
2093
+	 * Symbol to use for decimal mark
2094
+	 *
2095
+	 * @var string $dec_mrk
2096
+	 * eg '.'
2097
+	 */
2098
+	public $dec_mrk;
2099
+
2100
+	/**
2101
+	 * Symbol to use for thousands
2102
+	 *
2103
+	 * @var string $thsnds
2104
+	 * eg ','
2105
+	 */
2106
+	public $thsnds;
2107
+
2108
+
2109
+	/**
2110
+	 *    class constructor
2111
+	 *
2112
+	 * @access    public
2113
+	 * @param string $CNT_ISO
2114
+	 * @throws \EE_Error
2115
+	 */
2116
+	public function __construct($CNT_ISO = '')
2117
+	{
2118
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2119
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2120
+		// get country code from organization settings or use default
2121
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2122
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2123
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2124
+			: '';
2125
+		// but override if requested
2126
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
+		if (! empty($CNT_ISO)
2129
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2130
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131
+		) {
2132
+			// retrieve the country settings from the db, just in case they have been customized
2133
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134
+			if ($country instanceof EE_Country) {
2135
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
+				$this->name = $country->currency_name_single();    // Dollar
2137
+				$this->plural = $country->currency_name_plural();    // Dollars
2138
+				$this->sign = $country->currency_sign();            // currency sign: $
2139
+				$this->sign_b4 = $country->currency_sign_before(
2140
+				);        // currency sign before or after: $TRUE  or  FALSE$
2141
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2142
+				$this->dec_mrk = $country->currency_decimal_mark(
2143
+				);    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144
+				$this->thsnds = $country->currency_thousands_separator(
2145
+				);    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146
+			}
2147
+		}
2148
+		// fallback to hardcoded defaults, in case the above failed
2149
+		if (empty($this->code)) {
2150
+			// set default currency settings
2151
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2152
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2153
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
+			$this->sign = '$';    // currency sign: $
2155
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
+		}
2160
+	}
2161
+}
2321 2162
 
2322
-    /**
2323
-     * Label text to show on the checkbox
2324
-     *
2325
-     * @var string
2326
-     */
2327
-    public $consent_checkbox_label_text;
2163
+/**
2164
+ * Class for defining what's in the EE_Config relating to registration settings
2165
+ */
2166
+class EE_Registration_Config extends EE_Config_Base
2167
+{
2328 2168
 
2329
-    /*
2169
+	/**
2170
+	 * Default registration status
2171
+	 *
2172
+	 * @var string $default_STS_ID
2173
+	 * eg 'RPP'
2174
+	 */
2175
+	public $default_STS_ID;
2176
+
2177
+	/**
2178
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2179
+	 * registrations)
2180
+	 *
2181
+	 * @var int
2182
+	 */
2183
+	public $default_maximum_number_of_tickets;
2184
+
2185
+	/**
2186
+	 * level of validation to apply to email addresses
2187
+	 *
2188
+	 * @var string $email_validation_level
2189
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2190
+	 */
2191
+	public $email_validation_level;
2192
+
2193
+	/**
2194
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2195
+	 *
2196
+	 * @var boolean $show_pending_payment_options
2197
+	 */
2198
+	public $show_pending_payment_options;
2199
+
2200
+	/**
2201
+	 * Whether to skip the registration confirmation page
2202
+	 *
2203
+	 * @var boolean $skip_reg_confirmation
2204
+	 */
2205
+	public $skip_reg_confirmation;
2206
+
2207
+	/**
2208
+	 * an array of SPCO reg steps where:
2209
+	 *        the keys denotes the reg step order
2210
+	 *        each element consists of an array with the following elements:
2211
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2212
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2213
+	 *            "slug" => the URL param used to trigger the reg step
2214
+	 *
2215
+	 * @var array $reg_steps
2216
+	 */
2217
+	public $reg_steps;
2218
+
2219
+	/**
2220
+	 * Whether registration confirmation should be the last page of SPCO
2221
+	 *
2222
+	 * @var boolean $reg_confirmation_last
2223
+	 */
2224
+	public $reg_confirmation_last;
2225
+
2226
+	/**
2227
+	 * Whether or not to enable the EE Bot Trap
2228
+	 *
2229
+	 * @var boolean $use_bot_trap
2230
+	 */
2231
+	public $use_bot_trap;
2232
+
2233
+	/**
2234
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2235
+	 *
2236
+	 * @var boolean $use_encryption
2237
+	 */
2238
+	public $use_encryption;
2239
+
2240
+	/**
2241
+	 * Whether or not to use ReCaptcha
2242
+	 *
2243
+	 * @var boolean $use_captcha
2244
+	 */
2245
+	public $use_captcha;
2246
+
2247
+	/**
2248
+	 * ReCaptcha Theme
2249
+	 *
2250
+	 * @var string $recaptcha_theme
2251
+	 *    options: 'dark', 'light', 'invisible'
2252
+	 */
2253
+	public $recaptcha_theme;
2254
+
2255
+	/**
2256
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2257
+	 *
2258
+	 * @var string $recaptcha_badge
2259
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2260
+	 */
2261
+	public $recaptcha_badge;
2262
+
2263
+	/**
2264
+	 * ReCaptcha Type
2265
+	 *
2266
+	 * @var string $recaptcha_type
2267
+	 *    options: 'audio', 'image'
2268
+	 */
2269
+	public $recaptcha_type;
2270
+
2271
+	/**
2272
+	 * ReCaptcha language
2273
+	 *
2274
+	 * @var string $recaptcha_language
2275
+	 * eg 'en'
2276
+	 */
2277
+	public $recaptcha_language;
2278
+
2279
+	/**
2280
+	 * ReCaptcha public key
2281
+	 *
2282
+	 * @var string $recaptcha_publickey
2283
+	 */
2284
+	public $recaptcha_publickey;
2285
+
2286
+	/**
2287
+	 * ReCaptcha private key
2288
+	 *
2289
+	 * @var string $recaptcha_privatekey
2290
+	 */
2291
+	public $recaptcha_privatekey;
2292
+
2293
+	/**
2294
+	 * array of form names protected by ReCaptcha
2295
+	 *
2296
+	 * @var array $recaptcha_protected_forms
2297
+	 */
2298
+	public $recaptcha_protected_forms;
2299
+
2300
+	/**
2301
+	 * ReCaptcha width
2302
+	 *
2303
+	 * @var int $recaptcha_width
2304
+	 * @deprecated
2305
+	 */
2306
+	public $recaptcha_width;
2307
+
2308
+	/**
2309
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2310
+	 *
2311
+	 * @var boolean $track_invalid_checkout_access
2312
+	 */
2313
+	protected $track_invalid_checkout_access = true;
2314
+
2315
+	/**
2316
+	 * Whether or not to show the privacy policy consent checkbox
2317
+	 *
2318
+	 * @var bool
2319
+	 */
2320
+	public $consent_checkbox_enabled;
2321
+
2322
+	/**
2323
+	 * Label text to show on the checkbox
2324
+	 *
2325
+	 * @var string
2326
+	 */
2327
+	public $consent_checkbox_label_text;
2328
+
2329
+	/*
2330 2330
      * String describing how long to keep payment logs. Passed into DateTime constructor
2331 2331
      * @var string
2332 2332
      */
2333
-    public $gateway_log_lifespan = '1 week';
2334
-
2335
-
2336
-    /**
2337
-     *    class constructor
2338
-     *
2339
-     * @access    public
2340
-     */
2341
-    public function __construct()
2342
-    {
2343
-        // set default registration settings
2344
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2345
-        $this->email_validation_level = 'wp_default';
2346
-        $this->show_pending_payment_options = true;
2347
-        $this->skip_reg_confirmation = true;
2348
-        $this->reg_steps = array();
2349
-        $this->reg_confirmation_last = false;
2350
-        $this->use_bot_trap = true;
2351
-        $this->use_encryption = true;
2352
-        $this->use_captcha = false;
2353
-        $this->recaptcha_theme = 'light';
2354
-        $this->recaptcha_badge = 'bottomleft';
2355
-        $this->recaptcha_type = 'image';
2356
-        $this->recaptcha_language = 'en';
2357
-        $this->recaptcha_publickey = null;
2358
-        $this->recaptcha_privatekey = null;
2359
-        $this->recaptcha_protected_forms = array();
2360
-        $this->recaptcha_width = 500;
2361
-        $this->default_maximum_number_of_tickets = 10;
2362
-        $this->consent_checkbox_enabled = false;
2363
-        $this->consent_checkbox_label_text = '';
2364
-        $this->gateway_log_lifespan = '7 days';
2365
-    }
2366
-
2367
-
2368
-    /**
2369
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2370
-     *
2371
-     * @since 4.8.8.rc.019
2372
-     */
2373
-    public function do_hooks()
2374
-    {
2375
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2376
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2377
-        add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2378
-    }
2379
-
2380
-
2381
-    /**
2382
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2383
-     * EVT_default_registration_status field matches the config setting for default_STS_ID.
2384
-     */
2385
-    public function set_default_reg_status_on_EEM_Event()
2386
-    {
2387
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2388
-    }
2389
-
2390
-
2391
-    /**
2392
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2393
-     * for Events matches the config setting for default_maximum_number_of_tickets
2394
-     */
2395
-    public function set_default_max_ticket_on_EEM_Event()
2396
-    {
2397
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2398
-    }
2399
-
2400
-
2401
-    /**
2402
-     * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2403
-     * constructed because that happens before we can get the privacy policy page's permalink.
2404
-     *
2405
-     * @throws InvalidArgumentException
2406
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2407
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2408
-     */
2409
-    public function setDefaultCheckboxLabelText()
2410
-    {
2411
-        if ($this->getConsentCheckboxLabelText() === null
2412
-            || $this->getConsentCheckboxLabelText() === '') {
2413
-            $opening_a_tag = '';
2414
-            $closing_a_tag = '';
2415
-            if (function_exists('get_privacy_policy_url')) {
2416
-                $privacy_page_url = get_privacy_policy_url();
2417
-                if (! empty($privacy_page_url)) {
2418
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2419
-                    $closing_a_tag = '</a>';
2420
-                }
2421
-            }
2422
-            $loader = LoaderFactory::getLoader();
2423
-            $org_config = $loader->getShared('EE_Organization_Config');
2424
-            /**
2425
-             * @var $org_config EE_Organization_Config
2426
-             */
2427
-
2428
-            $this->setConsentCheckboxLabelText(
2429
-                sprintf(
2430
-                    esc_html__(
2431
-                        'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2432
-                        'event_espresso'
2433
-                    ),
2434
-                    $org_config->name,
2435
-                    $opening_a_tag,
2436
-                    $closing_a_tag
2437
-                )
2438
-            );
2439
-        }
2440
-    }
2441
-
2442
-
2443
-    /**
2444
-     * @return boolean
2445
-     */
2446
-    public function track_invalid_checkout_access()
2447
-    {
2448
-        return $this->track_invalid_checkout_access;
2449
-    }
2450
-
2451
-
2452
-    /**
2453
-     * @param boolean $track_invalid_checkout_access
2454
-     */
2455
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2456
-    {
2457
-        $this->track_invalid_checkout_access = filter_var(
2458
-            $track_invalid_checkout_access,
2459
-            FILTER_VALIDATE_BOOLEAN
2460
-        );
2461
-    }
2462
-
2463
-
2464
-    /**
2465
-     * Gets the options to make availalbe for the gateway log lifespan
2466
-     * @return array
2467
-     */
2468
-    public function gatewayLogLifespanOptions()
2469
-    {
2470
-        return (array) apply_filters(
2471
-            'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2472
-            array(
2473
-                '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2474
-                '1 day' => esc_html__('1 Day', 'event_espresso'),
2475
-                '7 days' => esc_html__('7 Days', 'event_espresso'),
2476
-                '14 days' => esc_html__('14 Days', 'event_espresso'),
2477
-                '30 days' => esc_html__('30 Days', 'event_espresso')
2478
-            )
2479
-        );
2480
-    }
2481
-
2482
-
2483
-    /**
2484
-     * @return bool
2485
-     */
2486
-    public function isConsentCheckboxEnabled()
2487
-    {
2488
-        return $this->consent_checkbox_enabled;
2489
-    }
2490
-
2491
-
2492
-    /**
2493
-     * @param bool $consent_checkbox_enabled
2494
-     */
2495
-    public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2496
-    {
2497
-        $this->consent_checkbox_enabled = filter_var(
2498
-            $consent_checkbox_enabled,
2499
-            FILTER_VALIDATE_BOOLEAN
2500
-        );
2501
-    }
2502
-
2503
-
2504
-    /**
2505
-     * @return string
2506
-     */
2507
-    public function getConsentCheckboxLabelText()
2508
-    {
2509
-        return $this->consent_checkbox_label_text;
2510
-    }
2511
-
2512
-
2513
-    /**
2514
-     * @param string $consent_checkbox_label_text
2515
-     */
2516
-    public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2517
-    {
2518
-        $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2519
-    }
2333
+	public $gateway_log_lifespan = '1 week';
2334
+
2335
+
2336
+	/**
2337
+	 *    class constructor
2338
+	 *
2339
+	 * @access    public
2340
+	 */
2341
+	public function __construct()
2342
+	{
2343
+		// set default registration settings
2344
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2345
+		$this->email_validation_level = 'wp_default';
2346
+		$this->show_pending_payment_options = true;
2347
+		$this->skip_reg_confirmation = true;
2348
+		$this->reg_steps = array();
2349
+		$this->reg_confirmation_last = false;
2350
+		$this->use_bot_trap = true;
2351
+		$this->use_encryption = true;
2352
+		$this->use_captcha = false;
2353
+		$this->recaptcha_theme = 'light';
2354
+		$this->recaptcha_badge = 'bottomleft';
2355
+		$this->recaptcha_type = 'image';
2356
+		$this->recaptcha_language = 'en';
2357
+		$this->recaptcha_publickey = null;
2358
+		$this->recaptcha_privatekey = null;
2359
+		$this->recaptcha_protected_forms = array();
2360
+		$this->recaptcha_width = 500;
2361
+		$this->default_maximum_number_of_tickets = 10;
2362
+		$this->consent_checkbox_enabled = false;
2363
+		$this->consent_checkbox_label_text = '';
2364
+		$this->gateway_log_lifespan = '7 days';
2365
+	}
2366
+
2367
+
2368
+	/**
2369
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2370
+	 *
2371
+	 * @since 4.8.8.rc.019
2372
+	 */
2373
+	public function do_hooks()
2374
+	{
2375
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2376
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2377
+		add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2378
+	}
2379
+
2380
+
2381
+	/**
2382
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2383
+	 * EVT_default_registration_status field matches the config setting for default_STS_ID.
2384
+	 */
2385
+	public function set_default_reg_status_on_EEM_Event()
2386
+	{
2387
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2388
+	}
2389
+
2390
+
2391
+	/**
2392
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2393
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2394
+	 */
2395
+	public function set_default_max_ticket_on_EEM_Event()
2396
+	{
2397
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2398
+	}
2399
+
2400
+
2401
+	/**
2402
+	 * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2403
+	 * constructed because that happens before we can get the privacy policy page's permalink.
2404
+	 *
2405
+	 * @throws InvalidArgumentException
2406
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2407
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2408
+	 */
2409
+	public function setDefaultCheckboxLabelText()
2410
+	{
2411
+		if ($this->getConsentCheckboxLabelText() === null
2412
+			|| $this->getConsentCheckboxLabelText() === '') {
2413
+			$opening_a_tag = '';
2414
+			$closing_a_tag = '';
2415
+			if (function_exists('get_privacy_policy_url')) {
2416
+				$privacy_page_url = get_privacy_policy_url();
2417
+				if (! empty($privacy_page_url)) {
2418
+					$opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2419
+					$closing_a_tag = '</a>';
2420
+				}
2421
+			}
2422
+			$loader = LoaderFactory::getLoader();
2423
+			$org_config = $loader->getShared('EE_Organization_Config');
2424
+			/**
2425
+			 * @var $org_config EE_Organization_Config
2426
+			 */
2427
+
2428
+			$this->setConsentCheckboxLabelText(
2429
+				sprintf(
2430
+					esc_html__(
2431
+						'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2432
+						'event_espresso'
2433
+					),
2434
+					$org_config->name,
2435
+					$opening_a_tag,
2436
+					$closing_a_tag
2437
+				)
2438
+			);
2439
+		}
2440
+	}
2441
+
2442
+
2443
+	/**
2444
+	 * @return boolean
2445
+	 */
2446
+	public function track_invalid_checkout_access()
2447
+	{
2448
+		return $this->track_invalid_checkout_access;
2449
+	}
2450
+
2451
+
2452
+	/**
2453
+	 * @param boolean $track_invalid_checkout_access
2454
+	 */
2455
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2456
+	{
2457
+		$this->track_invalid_checkout_access = filter_var(
2458
+			$track_invalid_checkout_access,
2459
+			FILTER_VALIDATE_BOOLEAN
2460
+		);
2461
+	}
2462
+
2463
+
2464
+	/**
2465
+	 * Gets the options to make availalbe for the gateway log lifespan
2466
+	 * @return array
2467
+	 */
2468
+	public function gatewayLogLifespanOptions()
2469
+	{
2470
+		return (array) apply_filters(
2471
+			'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2472
+			array(
2473
+				'1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2474
+				'1 day' => esc_html__('1 Day', 'event_espresso'),
2475
+				'7 days' => esc_html__('7 Days', 'event_espresso'),
2476
+				'14 days' => esc_html__('14 Days', 'event_espresso'),
2477
+				'30 days' => esc_html__('30 Days', 'event_espresso')
2478
+			)
2479
+		);
2480
+	}
2481
+
2482
+
2483
+	/**
2484
+	 * @return bool
2485
+	 */
2486
+	public function isConsentCheckboxEnabled()
2487
+	{
2488
+		return $this->consent_checkbox_enabled;
2489
+	}
2490
+
2491
+
2492
+	/**
2493
+	 * @param bool $consent_checkbox_enabled
2494
+	 */
2495
+	public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2496
+	{
2497
+		$this->consent_checkbox_enabled = filter_var(
2498
+			$consent_checkbox_enabled,
2499
+			FILTER_VALIDATE_BOOLEAN
2500
+		);
2501
+	}
2502
+
2503
+
2504
+	/**
2505
+	 * @return string
2506
+	 */
2507
+	public function getConsentCheckboxLabelText()
2508
+	{
2509
+		return $this->consent_checkbox_label_text;
2510
+	}
2511
+
2512
+
2513
+	/**
2514
+	 * @param string $consent_checkbox_label_text
2515
+	 */
2516
+	public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2517
+	{
2518
+		$this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2519
+	}
2520 2520
 }
2521 2521
 
2522 2522
 /**
@@ -2525,179 +2525,179 @@  discard block
 block discarded – undo
2525 2525
 class EE_Admin_Config extends EE_Config_Base
2526 2526
 {
2527 2527
 
2528
-    /**
2529
-     * @var boolean $useAdvancedEditor
2530
-     */
2531
-    private $useAdvancedEditor;
2532
-
2533
-    /**
2534
-     * @var boolean $use_personnel_manager
2535
-     */
2536
-    public $use_personnel_manager;
2537
-
2538
-    /**
2539
-     * @var boolean $use_dashboard_widget
2540
-     */
2541
-    public $use_dashboard_widget;
2542
-
2543
-    /**
2544
-     * @var int $events_in_dashboard
2545
-     */
2546
-    public $events_in_dashboard;
2547
-
2548
-    /**
2549
-     * @var boolean $use_event_timezones
2550
-     */
2551
-    public $use_event_timezones;
2552
-
2553
-    /**
2554
-     * @var string $log_file_name
2555
-     */
2556
-    public $log_file_name;
2557
-
2558
-    /**
2559
-     * @var string $debug_file_name
2560
-     */
2561
-    public $debug_file_name;
2562
-
2563
-    /**
2564
-     * @var boolean $use_remote_logging
2565
-     */
2566
-    public $use_remote_logging;
2567
-
2568
-    /**
2569
-     * @var string $remote_logging_url
2570
-     */
2571
-    public $remote_logging_url;
2572
-
2573
-    /**
2574
-     * @var boolean $show_reg_footer
2575
-     */
2576
-    public $show_reg_footer;
2577
-
2578
-    /**
2579
-     * @var string $affiliate_id
2580
-     */
2581
-    public $affiliate_id;
2582
-
2583
-    /**
2584
-     * help tours on or off (global setting)
2585
-     *
2586
-     * @var boolean
2587
-     */
2588
-    public $help_tour_activation;
2589
-
2590
-    /**
2591
-     * adds extra layer of encoding to session data to prevent serialization errors
2592
-     * but is incompatible with some server configuration errors
2593
-     * if you get "500 internal server errors" during registration, try turning this on
2594
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2595
-     *
2596
-     * @var boolean $encode_session_data
2597
-     */
2598
-    private $encode_session_data = false;
2599
-
2600
-
2601
-    /**
2602
-     *    class constructor
2603
-     *
2604
-     * @access    public
2605
-     */
2606
-    public function __construct()
2607
-    {
2608
-        // set default general admin settings
2609
-        $this->useAdvancedEditor = false;
2610
-        $this->use_personnel_manager = true;
2611
-        $this->use_dashboard_widget = true;
2612
-        $this->events_in_dashboard = 30;
2613
-        $this->use_event_timezones = false;
2614
-        $this->use_remote_logging = false;
2615
-        $this->remote_logging_url = null;
2616
-        $this->show_reg_footer = apply_filters(
2617
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
2618
-            false
2619
-        );
2620
-        $this->affiliate_id = 'default';
2621
-        $this->help_tour_activation = true;
2622
-        $this->encode_session_data = false;
2623
-    }
2624
-
2625
-
2626
-    /**
2627
-     * @param bool $reset
2628
-     * @return string
2629
-     */
2630
-    public function log_file_name($reset = false)
2631
-    {
2632
-        if (empty($this->log_file_name) || $reset) {
2633
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2634
-            EE_Config::instance()->update_espresso_config(false, false);
2635
-        }
2636
-        return $this->log_file_name;
2637
-    }
2638
-
2639
-
2640
-    /**
2641
-     * @param bool $reset
2642
-     * @return string
2643
-     */
2644
-    public function debug_file_name($reset = false)
2645
-    {
2646
-        if (empty($this->debug_file_name) || $reset) {
2647
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2648
-            EE_Config::instance()->update_espresso_config(false, false);
2649
-        }
2650
-        return $this->debug_file_name;
2651
-    }
2652
-
2653
-
2654
-    /**
2655
-     * @return string
2656
-     */
2657
-    public function affiliate_id()
2658
-    {
2659
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2660
-    }
2661
-
2662
-
2663
-    /**
2664
-     * @return boolean
2665
-     */
2666
-    public function encode_session_data()
2667
-    {
2668
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2669
-    }
2670
-
2671
-
2672
-    /**
2673
-     * @param boolean $encode_session_data
2674
-     */
2675
-    public function set_encode_session_data($encode_session_data)
2676
-    {
2677
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2678
-    }
2679
-
2680
-    /**
2681
-     * @return boolean
2682
-     */
2683
-    public function useAdvancedEditor()
2684
-    {
2685
-        return $this->useAdvancedEditor;
2686
-    }
2687
-
2688
-    /**
2689
-     * @param boolean $use_advanced_editor
2690
-     */
2691
-    public function setUseAdvancedEditor($use_advanced_editor = true)
2692
-    {
2693
-        $this->useAdvancedEditor = filter_var(
2694
-            apply_filters(
2695
-                'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2696
-                $use_advanced_editor
2697
-            ),
2698
-            FILTER_VALIDATE_BOOLEAN
2699
-        );
2700
-    }
2528
+	/**
2529
+	 * @var boolean $useAdvancedEditor
2530
+	 */
2531
+	private $useAdvancedEditor;
2532
+
2533
+	/**
2534
+	 * @var boolean $use_personnel_manager
2535
+	 */
2536
+	public $use_personnel_manager;
2537
+
2538
+	/**
2539
+	 * @var boolean $use_dashboard_widget
2540
+	 */
2541
+	public $use_dashboard_widget;
2542
+
2543
+	/**
2544
+	 * @var int $events_in_dashboard
2545
+	 */
2546
+	public $events_in_dashboard;
2547
+
2548
+	/**
2549
+	 * @var boolean $use_event_timezones
2550
+	 */
2551
+	public $use_event_timezones;
2552
+
2553
+	/**
2554
+	 * @var string $log_file_name
2555
+	 */
2556
+	public $log_file_name;
2557
+
2558
+	/**
2559
+	 * @var string $debug_file_name
2560
+	 */
2561
+	public $debug_file_name;
2562
+
2563
+	/**
2564
+	 * @var boolean $use_remote_logging
2565
+	 */
2566
+	public $use_remote_logging;
2567
+
2568
+	/**
2569
+	 * @var string $remote_logging_url
2570
+	 */
2571
+	public $remote_logging_url;
2572
+
2573
+	/**
2574
+	 * @var boolean $show_reg_footer
2575
+	 */
2576
+	public $show_reg_footer;
2577
+
2578
+	/**
2579
+	 * @var string $affiliate_id
2580
+	 */
2581
+	public $affiliate_id;
2582
+
2583
+	/**
2584
+	 * help tours on or off (global setting)
2585
+	 *
2586
+	 * @var boolean
2587
+	 */
2588
+	public $help_tour_activation;
2589
+
2590
+	/**
2591
+	 * adds extra layer of encoding to session data to prevent serialization errors
2592
+	 * but is incompatible with some server configuration errors
2593
+	 * if you get "500 internal server errors" during registration, try turning this on
2594
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2595
+	 *
2596
+	 * @var boolean $encode_session_data
2597
+	 */
2598
+	private $encode_session_data = false;
2599
+
2600
+
2601
+	/**
2602
+	 *    class constructor
2603
+	 *
2604
+	 * @access    public
2605
+	 */
2606
+	public function __construct()
2607
+	{
2608
+		// set default general admin settings
2609
+		$this->useAdvancedEditor = false;
2610
+		$this->use_personnel_manager = true;
2611
+		$this->use_dashboard_widget = true;
2612
+		$this->events_in_dashboard = 30;
2613
+		$this->use_event_timezones = false;
2614
+		$this->use_remote_logging = false;
2615
+		$this->remote_logging_url = null;
2616
+		$this->show_reg_footer = apply_filters(
2617
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
2618
+			false
2619
+		);
2620
+		$this->affiliate_id = 'default';
2621
+		$this->help_tour_activation = true;
2622
+		$this->encode_session_data = false;
2623
+	}
2624
+
2625
+
2626
+	/**
2627
+	 * @param bool $reset
2628
+	 * @return string
2629
+	 */
2630
+	public function log_file_name($reset = false)
2631
+	{
2632
+		if (empty($this->log_file_name) || $reset) {
2633
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2634
+			EE_Config::instance()->update_espresso_config(false, false);
2635
+		}
2636
+		return $this->log_file_name;
2637
+	}
2638
+
2639
+
2640
+	/**
2641
+	 * @param bool $reset
2642
+	 * @return string
2643
+	 */
2644
+	public function debug_file_name($reset = false)
2645
+	{
2646
+		if (empty($this->debug_file_name) || $reset) {
2647
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2648
+			EE_Config::instance()->update_espresso_config(false, false);
2649
+		}
2650
+		return $this->debug_file_name;
2651
+	}
2652
+
2653
+
2654
+	/**
2655
+	 * @return string
2656
+	 */
2657
+	public function affiliate_id()
2658
+	{
2659
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2660
+	}
2661
+
2662
+
2663
+	/**
2664
+	 * @return boolean
2665
+	 */
2666
+	public function encode_session_data()
2667
+	{
2668
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2669
+	}
2670
+
2671
+
2672
+	/**
2673
+	 * @param boolean $encode_session_data
2674
+	 */
2675
+	public function set_encode_session_data($encode_session_data)
2676
+	{
2677
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2678
+	}
2679
+
2680
+	/**
2681
+	 * @return boolean
2682
+	 */
2683
+	public function useAdvancedEditor()
2684
+	{
2685
+		return $this->useAdvancedEditor;
2686
+	}
2687
+
2688
+	/**
2689
+	 * @param boolean $use_advanced_editor
2690
+	 */
2691
+	public function setUseAdvancedEditor($use_advanced_editor = true)
2692
+	{
2693
+		$this->useAdvancedEditor = filter_var(
2694
+			apply_filters(
2695
+				'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2696
+				$use_advanced_editor
2697
+			),
2698
+			FILTER_VALIDATE_BOOLEAN
2699
+		);
2700
+	}
2701 2701
 }
2702 2702
 
2703 2703
 /**
@@ -2706,70 +2706,70 @@  discard block
 block discarded – undo
2706 2706
 class EE_Template_Config extends EE_Config_Base
2707 2707
 {
2708 2708
 
2709
-    /**
2710
-     * @var boolean $enable_default_style
2711
-     */
2712
-    public $enable_default_style;
2713
-
2714
-    /**
2715
-     * @var string $custom_style_sheet
2716
-     */
2717
-    public $custom_style_sheet;
2718
-
2719
-    /**
2720
-     * @var boolean $display_address_in_regform
2721
-     */
2722
-    public $display_address_in_regform;
2723
-
2724
-    /**
2725
-     * @var int $display_description_on_multi_reg_page
2726
-     */
2727
-    public $display_description_on_multi_reg_page;
2728
-
2729
-    /**
2730
-     * @var boolean $use_custom_templates
2731
-     */
2732
-    public $use_custom_templates;
2733
-
2734
-    /**
2735
-     * @var string $current_espresso_theme
2736
-     */
2737
-    public $current_espresso_theme;
2738
-
2739
-    /**
2740
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2741
-     */
2742
-    public $EED_Ticket_Selector;
2743
-
2744
-    /**
2745
-     * @var EE_Event_Single_Config $EED_Event_Single
2746
-     */
2747
-    public $EED_Event_Single;
2748
-
2749
-    /**
2750
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2751
-     */
2752
-    public $EED_Events_Archive;
2753
-
2754
-
2755
-    /**
2756
-     *    class constructor
2757
-     *
2758
-     * @access    public
2759
-     */
2760
-    public function __construct()
2761
-    {
2762
-        // set default template settings
2763
-        $this->enable_default_style = true;
2764
-        $this->custom_style_sheet = null;
2765
-        $this->display_address_in_regform = true;
2766
-        $this->display_description_on_multi_reg_page = false;
2767
-        $this->use_custom_templates = false;
2768
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2769
-        $this->EED_Event_Single = null;
2770
-        $this->EED_Events_Archive = null;
2771
-        $this->EED_Ticket_Selector = null;
2772
-    }
2709
+	/**
2710
+	 * @var boolean $enable_default_style
2711
+	 */
2712
+	public $enable_default_style;
2713
+
2714
+	/**
2715
+	 * @var string $custom_style_sheet
2716
+	 */
2717
+	public $custom_style_sheet;
2718
+
2719
+	/**
2720
+	 * @var boolean $display_address_in_regform
2721
+	 */
2722
+	public $display_address_in_regform;
2723
+
2724
+	/**
2725
+	 * @var int $display_description_on_multi_reg_page
2726
+	 */
2727
+	public $display_description_on_multi_reg_page;
2728
+
2729
+	/**
2730
+	 * @var boolean $use_custom_templates
2731
+	 */
2732
+	public $use_custom_templates;
2733
+
2734
+	/**
2735
+	 * @var string $current_espresso_theme
2736
+	 */
2737
+	public $current_espresso_theme;
2738
+
2739
+	/**
2740
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2741
+	 */
2742
+	public $EED_Ticket_Selector;
2743
+
2744
+	/**
2745
+	 * @var EE_Event_Single_Config $EED_Event_Single
2746
+	 */
2747
+	public $EED_Event_Single;
2748
+
2749
+	/**
2750
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2751
+	 */
2752
+	public $EED_Events_Archive;
2753
+
2754
+
2755
+	/**
2756
+	 *    class constructor
2757
+	 *
2758
+	 * @access    public
2759
+	 */
2760
+	public function __construct()
2761
+	{
2762
+		// set default template settings
2763
+		$this->enable_default_style = true;
2764
+		$this->custom_style_sheet = null;
2765
+		$this->display_address_in_regform = true;
2766
+		$this->display_description_on_multi_reg_page = false;
2767
+		$this->use_custom_templates = false;
2768
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2769
+		$this->EED_Event_Single = null;
2770
+		$this->EED_Events_Archive = null;
2771
+		$this->EED_Ticket_Selector = null;
2772
+	}
2773 2773
 }
2774 2774
 
2775 2775
 /**
@@ -2778,114 +2778,114 @@  discard block
 block discarded – undo
2778 2778
 class EE_Map_Config extends EE_Config_Base
2779 2779
 {
2780 2780
 
2781
-    /**
2782
-     * @var boolean $use_google_maps
2783
-     */
2784
-    public $use_google_maps;
2785
-
2786
-    /**
2787
-     * @var string $api_key
2788
-     */
2789
-    public $google_map_api_key;
2790
-
2791
-    /**
2792
-     * @var int $event_details_map_width
2793
-     */
2794
-    public $event_details_map_width;
2795
-
2796
-    /**
2797
-     * @var int $event_details_map_height
2798
-     */
2799
-    public $event_details_map_height;
2800
-
2801
-    /**
2802
-     * @var int $event_details_map_zoom
2803
-     */
2804
-    public $event_details_map_zoom;
2805
-
2806
-    /**
2807
-     * @var boolean $event_details_display_nav
2808
-     */
2809
-    public $event_details_display_nav;
2810
-
2811
-    /**
2812
-     * @var boolean $event_details_nav_size
2813
-     */
2814
-    public $event_details_nav_size;
2815
-
2816
-    /**
2817
-     * @var string $event_details_control_type
2818
-     */
2819
-    public $event_details_control_type;
2820
-
2821
-    /**
2822
-     * @var string $event_details_map_align
2823
-     */
2824
-    public $event_details_map_align;
2825
-
2826
-    /**
2827
-     * @var int $event_list_map_width
2828
-     */
2829
-    public $event_list_map_width;
2830
-
2831
-    /**
2832
-     * @var int $event_list_map_height
2833
-     */
2834
-    public $event_list_map_height;
2835
-
2836
-    /**
2837
-     * @var int $event_list_map_zoom
2838
-     */
2839
-    public $event_list_map_zoom;
2840
-
2841
-    /**
2842
-     * @var boolean $event_list_display_nav
2843
-     */
2844
-    public $event_list_display_nav;
2845
-
2846
-    /**
2847
-     * @var boolean $event_list_nav_size
2848
-     */
2849
-    public $event_list_nav_size;
2850
-
2851
-    /**
2852
-     * @var string $event_list_control_type
2853
-     */
2854
-    public $event_list_control_type;
2855
-
2856
-    /**
2857
-     * @var string $event_list_map_align
2858
-     */
2859
-    public $event_list_map_align;
2860
-
2861
-
2862
-    /**
2863
-     *    class constructor
2864
-     *
2865
-     * @access    public
2866
-     */
2867
-    public function __construct()
2868
-    {
2869
-        // set default map settings
2870
-        $this->use_google_maps = true;
2871
-        $this->google_map_api_key = '';
2872
-        // for event details pages (reg page)
2873
-        $this->event_details_map_width = 585;            // ee_map_width_single
2874
-        $this->event_details_map_height = 362;            // ee_map_height_single
2875
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2876
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2877
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2878
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2879
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2880
-        // for event list pages
2881
-        $this->event_list_map_width = 300;            // ee_map_width
2882
-        $this->event_list_map_height = 185;        // ee_map_height
2883
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2884
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2885
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2886
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2887
-        $this->event_list_map_align = 'center';            // ee_map_align
2888
-    }
2781
+	/**
2782
+	 * @var boolean $use_google_maps
2783
+	 */
2784
+	public $use_google_maps;
2785
+
2786
+	/**
2787
+	 * @var string $api_key
2788
+	 */
2789
+	public $google_map_api_key;
2790
+
2791
+	/**
2792
+	 * @var int $event_details_map_width
2793
+	 */
2794
+	public $event_details_map_width;
2795
+
2796
+	/**
2797
+	 * @var int $event_details_map_height
2798
+	 */
2799
+	public $event_details_map_height;
2800
+
2801
+	/**
2802
+	 * @var int $event_details_map_zoom
2803
+	 */
2804
+	public $event_details_map_zoom;
2805
+
2806
+	/**
2807
+	 * @var boolean $event_details_display_nav
2808
+	 */
2809
+	public $event_details_display_nav;
2810
+
2811
+	/**
2812
+	 * @var boolean $event_details_nav_size
2813
+	 */
2814
+	public $event_details_nav_size;
2815
+
2816
+	/**
2817
+	 * @var string $event_details_control_type
2818
+	 */
2819
+	public $event_details_control_type;
2820
+
2821
+	/**
2822
+	 * @var string $event_details_map_align
2823
+	 */
2824
+	public $event_details_map_align;
2825
+
2826
+	/**
2827
+	 * @var int $event_list_map_width
2828
+	 */
2829
+	public $event_list_map_width;
2830
+
2831
+	/**
2832
+	 * @var int $event_list_map_height
2833
+	 */
2834
+	public $event_list_map_height;
2835
+
2836
+	/**
2837
+	 * @var int $event_list_map_zoom
2838
+	 */
2839
+	public $event_list_map_zoom;
2840
+
2841
+	/**
2842
+	 * @var boolean $event_list_display_nav
2843
+	 */
2844
+	public $event_list_display_nav;
2845
+
2846
+	/**
2847
+	 * @var boolean $event_list_nav_size
2848
+	 */
2849
+	public $event_list_nav_size;
2850
+
2851
+	/**
2852
+	 * @var string $event_list_control_type
2853
+	 */
2854
+	public $event_list_control_type;
2855
+
2856
+	/**
2857
+	 * @var string $event_list_map_align
2858
+	 */
2859
+	public $event_list_map_align;
2860
+
2861
+
2862
+	/**
2863
+	 *    class constructor
2864
+	 *
2865
+	 * @access    public
2866
+	 */
2867
+	public function __construct()
2868
+	{
2869
+		// set default map settings
2870
+		$this->use_google_maps = true;
2871
+		$this->google_map_api_key = '';
2872
+		// for event details pages (reg page)
2873
+		$this->event_details_map_width = 585;            // ee_map_width_single
2874
+		$this->event_details_map_height = 362;            // ee_map_height_single
2875
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2876
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2877
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2878
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2879
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2880
+		// for event list pages
2881
+		$this->event_list_map_width = 300;            // ee_map_width
2882
+		$this->event_list_map_height = 185;        // ee_map_height
2883
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2884
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2885
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2886
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2887
+		$this->event_list_map_align = 'center';            // ee_map_align
2888
+	}
2889 2889
 }
2890 2890
 
2891 2891
 /**
@@ -2894,46 +2894,46 @@  discard block
 block discarded – undo
2894 2894
 class EE_Events_Archive_Config extends EE_Config_Base
2895 2895
 {
2896 2896
 
2897
-    public $display_status_banner;
2897
+	public $display_status_banner;
2898 2898
 
2899
-    public $display_description;
2899
+	public $display_description;
2900 2900
 
2901
-    public $display_ticket_selector;
2901
+	public $display_ticket_selector;
2902 2902
 
2903
-    public $display_datetimes;
2903
+	public $display_datetimes;
2904 2904
 
2905
-    public $display_venue;
2905
+	public $display_venue;
2906 2906
 
2907
-    public $display_expired_events;
2907
+	public $display_expired_events;
2908 2908
 
2909
-    public $use_sortable_display_order;
2909
+	public $use_sortable_display_order;
2910 2910
 
2911
-    public $display_order_tickets;
2911
+	public $display_order_tickets;
2912 2912
 
2913
-    public $display_order_datetimes;
2913
+	public $display_order_datetimes;
2914 2914
 
2915
-    public $display_order_event;
2915
+	public $display_order_event;
2916 2916
 
2917
-    public $display_order_venue;
2917
+	public $display_order_venue;
2918 2918
 
2919 2919
 
2920
-    /**
2921
-     *    class constructor
2922
-     */
2923
-    public function __construct()
2924
-    {
2925
-        $this->display_status_banner = 0;
2926
-        $this->display_description = 1;
2927
-        $this->display_ticket_selector = 0;
2928
-        $this->display_datetimes = 1;
2929
-        $this->display_venue = 0;
2930
-        $this->display_expired_events = 0;
2931
-        $this->use_sortable_display_order = false;
2932
-        $this->display_order_tickets = 100;
2933
-        $this->display_order_datetimes = 110;
2934
-        $this->display_order_event = 120;
2935
-        $this->display_order_venue = 130;
2936
-    }
2920
+	/**
2921
+	 *    class constructor
2922
+	 */
2923
+	public function __construct()
2924
+	{
2925
+		$this->display_status_banner = 0;
2926
+		$this->display_description = 1;
2927
+		$this->display_ticket_selector = 0;
2928
+		$this->display_datetimes = 1;
2929
+		$this->display_venue = 0;
2930
+		$this->display_expired_events = 0;
2931
+		$this->use_sortable_display_order = false;
2932
+		$this->display_order_tickets = 100;
2933
+		$this->display_order_datetimes = 110;
2934
+		$this->display_order_event = 120;
2935
+		$this->display_order_venue = 130;
2936
+	}
2937 2937
 }
2938 2938
 
2939 2939
 /**
@@ -2942,34 +2942,34 @@  discard block
 block discarded – undo
2942 2942
 class EE_Event_Single_Config extends EE_Config_Base
2943 2943
 {
2944 2944
 
2945
-    public $display_status_banner_single;
2945
+	public $display_status_banner_single;
2946 2946
 
2947
-    public $display_venue;
2947
+	public $display_venue;
2948 2948
 
2949
-    public $use_sortable_display_order;
2949
+	public $use_sortable_display_order;
2950 2950
 
2951
-    public $display_order_tickets;
2951
+	public $display_order_tickets;
2952 2952
 
2953
-    public $display_order_datetimes;
2953
+	public $display_order_datetimes;
2954 2954
 
2955
-    public $display_order_event;
2955
+	public $display_order_event;
2956 2956
 
2957
-    public $display_order_venue;
2957
+	public $display_order_venue;
2958 2958
 
2959 2959
 
2960
-    /**
2961
-     *    class constructor
2962
-     */
2963
-    public function __construct()
2964
-    {
2965
-        $this->display_status_banner_single = 0;
2966
-        $this->display_venue = 1;
2967
-        $this->use_sortable_display_order = false;
2968
-        $this->display_order_tickets = 100;
2969
-        $this->display_order_datetimes = 110;
2970
-        $this->display_order_event = 120;
2971
-        $this->display_order_venue = 130;
2972
-    }
2960
+	/**
2961
+	 *    class constructor
2962
+	 */
2963
+	public function __construct()
2964
+	{
2965
+		$this->display_status_banner_single = 0;
2966
+		$this->display_venue = 1;
2967
+		$this->use_sortable_display_order = false;
2968
+		$this->display_order_tickets = 100;
2969
+		$this->display_order_datetimes = 110;
2970
+		$this->display_order_event = 120;
2971
+		$this->display_order_venue = 130;
2972
+	}
2973 2973
 }
2974 2974
 
2975 2975
 /**
@@ -2978,172 +2978,172 @@  discard block
 block discarded – undo
2978 2978
 class EE_Ticket_Selector_Config extends EE_Config_Base
2979 2979
 {
2980 2980
 
2981
-    /**
2982
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2983
-     */
2984
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2985
-
2986
-    /**
2987
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2988
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2989
-     */
2990
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2991
-
2992
-    /**
2993
-     * @var boolean $show_ticket_sale_columns
2994
-     */
2995
-    public $show_ticket_sale_columns;
2996
-
2997
-    /**
2998
-     * @var boolean $show_ticket_details
2999
-     */
3000
-    public $show_ticket_details;
3001
-
3002
-    /**
3003
-     * @var boolean $show_expired_tickets
3004
-     */
3005
-    public $show_expired_tickets;
3006
-
3007
-    /**
3008
-     * whether or not to display a dropdown box populated with event datetimes
3009
-     * that toggles which tickets are displayed for a ticket selector.
3010
-     * uses one of the *_DATETIME_SELECTOR constants defined above
3011
-     *
3012
-     * @var string $show_datetime_selector
3013
-     */
3014
-    private $show_datetime_selector = 'no_datetime_selector';
3015
-
3016
-    /**
3017
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
3018
-     *
3019
-     * @var int $datetime_selector_threshold
3020
-     */
3021
-    private $datetime_selector_threshold = 3;
3022
-
3023
-    /**
3024
-     * determines the maximum number of "checked" dates in the date and time filter
3025
-     *
3026
-     * @var int $datetime_selector_checked
3027
-     */
3028
-    private $datetime_selector_max_checked = 10;
3029
-
3030
-
3031
-    /**
3032
-     *    class constructor
3033
-     */
3034
-    public function __construct()
3035
-    {
3036
-        $this->show_ticket_sale_columns = true;
3037
-        $this->show_ticket_details = true;
3038
-        $this->show_expired_tickets = true;
3039
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3040
-        $this->datetime_selector_threshold = 3;
3041
-        $this->datetime_selector_max_checked = 10;
3042
-    }
3043
-
3044
-
3045
-    /**
3046
-     * returns true if a datetime selector should be displayed
3047
-     *
3048
-     * @param array $datetimes
3049
-     * @return bool
3050
-     */
3051
-    public function showDatetimeSelector(array $datetimes)
3052
-    {
3053
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3054
-        return ! (
3055
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3056
-            || (
3057
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3058
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3059
-            )
3060
-        );
3061
-    }
3062
-
3063
-
3064
-    /**
3065
-     * @return string
3066
-     */
3067
-    public function getShowDatetimeSelector()
3068
-    {
3069
-        return $this->show_datetime_selector;
3070
-    }
3071
-
3072
-
3073
-    /**
3074
-     * @param bool $keys_only
3075
-     * @return array
3076
-     */
3077
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3078
-    {
3079
-        return $keys_only
3080
-            ? array(
3081
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3082
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3083
-            )
3084
-            : array(
3085
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3086
-                    'Do not show date & time filter',
3087
-                    'event_espresso'
3088
-                ),
3089
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3090
-                    'Maybe show date & time filter',
3091
-                    'event_espresso'
3092
-                ),
3093
-            );
3094
-    }
3095
-
3096
-
3097
-    /**
3098
-     * @param string $show_datetime_selector
3099
-     */
3100
-    public function setShowDatetimeSelector($show_datetime_selector)
3101
-    {
3102
-        $this->show_datetime_selector = in_array(
3103
-            $show_datetime_selector,
3104
-            $this->getShowDatetimeSelectorOptions(),
3105
-            true
3106
-        )
3107
-            ? $show_datetime_selector
3108
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3109
-    }
3110
-
3111
-
3112
-    /**
3113
-     * @return int
3114
-     */
3115
-    public function getDatetimeSelectorThreshold()
3116
-    {
3117
-        return $this->datetime_selector_threshold;
3118
-    }
3119
-
3120
-
3121
-    /**
3122
-     * @param int $datetime_selector_threshold
3123
-     */
3124
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3125
-    {
3126
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3127
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3128
-    }
3129
-
3130
-
3131
-    /**
3132
-     * @return int
3133
-     */
3134
-    public function getDatetimeSelectorMaxChecked()
3135
-    {
3136
-        return $this->datetime_selector_max_checked;
3137
-    }
3138
-
3139
-
3140
-    /**
3141
-     * @param int $datetime_selector_max_checked
3142
-     */
3143
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3144
-    {
3145
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3146
-    }
2981
+	/**
2982
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2983
+	 */
2984
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2985
+
2986
+	/**
2987
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2988
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2989
+	 */
2990
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2991
+
2992
+	/**
2993
+	 * @var boolean $show_ticket_sale_columns
2994
+	 */
2995
+	public $show_ticket_sale_columns;
2996
+
2997
+	/**
2998
+	 * @var boolean $show_ticket_details
2999
+	 */
3000
+	public $show_ticket_details;
3001
+
3002
+	/**
3003
+	 * @var boolean $show_expired_tickets
3004
+	 */
3005
+	public $show_expired_tickets;
3006
+
3007
+	/**
3008
+	 * whether or not to display a dropdown box populated with event datetimes
3009
+	 * that toggles which tickets are displayed for a ticket selector.
3010
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
3011
+	 *
3012
+	 * @var string $show_datetime_selector
3013
+	 */
3014
+	private $show_datetime_selector = 'no_datetime_selector';
3015
+
3016
+	/**
3017
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
3018
+	 *
3019
+	 * @var int $datetime_selector_threshold
3020
+	 */
3021
+	private $datetime_selector_threshold = 3;
3022
+
3023
+	/**
3024
+	 * determines the maximum number of "checked" dates in the date and time filter
3025
+	 *
3026
+	 * @var int $datetime_selector_checked
3027
+	 */
3028
+	private $datetime_selector_max_checked = 10;
3029
+
3030
+
3031
+	/**
3032
+	 *    class constructor
3033
+	 */
3034
+	public function __construct()
3035
+	{
3036
+		$this->show_ticket_sale_columns = true;
3037
+		$this->show_ticket_details = true;
3038
+		$this->show_expired_tickets = true;
3039
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3040
+		$this->datetime_selector_threshold = 3;
3041
+		$this->datetime_selector_max_checked = 10;
3042
+	}
3043
+
3044
+
3045
+	/**
3046
+	 * returns true if a datetime selector should be displayed
3047
+	 *
3048
+	 * @param array $datetimes
3049
+	 * @return bool
3050
+	 */
3051
+	public function showDatetimeSelector(array $datetimes)
3052
+	{
3053
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3054
+		return ! (
3055
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3056
+			|| (
3057
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3058
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3059
+			)
3060
+		);
3061
+	}
3062
+
3063
+
3064
+	/**
3065
+	 * @return string
3066
+	 */
3067
+	public function getShowDatetimeSelector()
3068
+	{
3069
+		return $this->show_datetime_selector;
3070
+	}
3071
+
3072
+
3073
+	/**
3074
+	 * @param bool $keys_only
3075
+	 * @return array
3076
+	 */
3077
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3078
+	{
3079
+		return $keys_only
3080
+			? array(
3081
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3082
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3083
+			)
3084
+			: array(
3085
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3086
+					'Do not show date & time filter',
3087
+					'event_espresso'
3088
+				),
3089
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3090
+					'Maybe show date & time filter',
3091
+					'event_espresso'
3092
+				),
3093
+			);
3094
+	}
3095
+
3096
+
3097
+	/**
3098
+	 * @param string $show_datetime_selector
3099
+	 */
3100
+	public function setShowDatetimeSelector($show_datetime_selector)
3101
+	{
3102
+		$this->show_datetime_selector = in_array(
3103
+			$show_datetime_selector,
3104
+			$this->getShowDatetimeSelectorOptions(),
3105
+			true
3106
+		)
3107
+			? $show_datetime_selector
3108
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3109
+	}
3110
+
3111
+
3112
+	/**
3113
+	 * @return int
3114
+	 */
3115
+	public function getDatetimeSelectorThreshold()
3116
+	{
3117
+		return $this->datetime_selector_threshold;
3118
+	}
3119
+
3120
+
3121
+	/**
3122
+	 * @param int $datetime_selector_threshold
3123
+	 */
3124
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3125
+	{
3126
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3127
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3128
+	}
3129
+
3130
+
3131
+	/**
3132
+	 * @return int
3133
+	 */
3134
+	public function getDatetimeSelectorMaxChecked()
3135
+	{
3136
+		return $this->datetime_selector_max_checked;
3137
+	}
3138
+
3139
+
3140
+	/**
3141
+	 * @param int $datetime_selector_max_checked
3142
+	 */
3143
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3144
+	{
3145
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3146
+	}
3147 3147
 }
3148 3148
 
3149 3149
 /**
@@ -3156,86 +3156,86 @@  discard block
 block discarded – undo
3156 3156
 class EE_Environment_Config extends EE_Config_Base
3157 3157
 {
3158 3158
 
3159
-    /**
3160
-     * Hold any php environment variables that we want to track.
3161
-     *
3162
-     * @var stdClass;
3163
-     */
3164
-    public $php;
3165
-
3166
-
3167
-    /**
3168
-     *    constructor
3169
-     */
3170
-    public function __construct()
3171
-    {
3172
-        $this->php = new stdClass();
3173
-        $this->_set_php_values();
3174
-    }
3175
-
3176
-
3177
-    /**
3178
-     * This sets the php environment variables.
3179
-     *
3180
-     * @since 4.4.0
3181
-     * @return void
3182
-     */
3183
-    protected function _set_php_values()
3184
-    {
3185
-        $this->php->max_input_vars = ini_get('max_input_vars');
3186
-        $this->php->version = phpversion();
3187
-    }
3188
-
3189
-
3190
-    /**
3191
-     * helper method for determining whether input_count is
3192
-     * reaching the potential maximum the server can handle
3193
-     * according to max_input_vars
3194
-     *
3195
-     * @param int   $input_count the count of input vars.
3196
-     * @return array {
3197
-     *                           An array that represents whether available space and if no available space the error
3198
-     *                           message.
3199
-     * @type bool   $has_space   whether more inputs can be added.
3200
-     * @type string $msg         Any message to be displayed.
3201
-     *                           }
3202
-     */
3203
-    public function max_input_vars_limit_check($input_count = 0)
3204
-    {
3205
-        if (! empty($this->php->max_input_vars)
3206
-            && ($input_count >= $this->php->max_input_vars)
3207
-        ) {
3208
-            // check the server setting because the config value could be stale
3209
-            $max_input_vars = ini_get('max_input_vars');
3210
-            if ($input_count >= $max_input_vars) {
3211
-                return sprintf(
3212
-                    esc_html__(
3213
-                        'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3214
-                        'event_espresso'
3215
-                    ),
3216
-                    '<br>',
3217
-                    $input_count,
3218
-                    $max_input_vars
3219
-                );
3220
-            } else {
3221
-                return '';
3222
-            }
3223
-        } else {
3224
-            return '';
3225
-        }
3226
-    }
3227
-
3228
-
3229
-    /**
3230
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3231
-     *
3232
-     * @since 4.4.1
3233
-     * @return void
3234
-     */
3235
-    public function recheck_values()
3236
-    {
3237
-        $this->_set_php_values();
3238
-    }
3159
+	/**
3160
+	 * Hold any php environment variables that we want to track.
3161
+	 *
3162
+	 * @var stdClass;
3163
+	 */
3164
+	public $php;
3165
+
3166
+
3167
+	/**
3168
+	 *    constructor
3169
+	 */
3170
+	public function __construct()
3171
+	{
3172
+		$this->php = new stdClass();
3173
+		$this->_set_php_values();
3174
+	}
3175
+
3176
+
3177
+	/**
3178
+	 * This sets the php environment variables.
3179
+	 *
3180
+	 * @since 4.4.0
3181
+	 * @return void
3182
+	 */
3183
+	protected function _set_php_values()
3184
+	{
3185
+		$this->php->max_input_vars = ini_get('max_input_vars');
3186
+		$this->php->version = phpversion();
3187
+	}
3188
+
3189
+
3190
+	/**
3191
+	 * helper method for determining whether input_count is
3192
+	 * reaching the potential maximum the server can handle
3193
+	 * according to max_input_vars
3194
+	 *
3195
+	 * @param int   $input_count the count of input vars.
3196
+	 * @return array {
3197
+	 *                           An array that represents whether available space and if no available space the error
3198
+	 *                           message.
3199
+	 * @type bool   $has_space   whether more inputs can be added.
3200
+	 * @type string $msg         Any message to be displayed.
3201
+	 *                           }
3202
+	 */
3203
+	public function max_input_vars_limit_check($input_count = 0)
3204
+	{
3205
+		if (! empty($this->php->max_input_vars)
3206
+			&& ($input_count >= $this->php->max_input_vars)
3207
+		) {
3208
+			// check the server setting because the config value could be stale
3209
+			$max_input_vars = ini_get('max_input_vars');
3210
+			if ($input_count >= $max_input_vars) {
3211
+				return sprintf(
3212
+					esc_html__(
3213
+						'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3214
+						'event_espresso'
3215
+					),
3216
+					'<br>',
3217
+					$input_count,
3218
+					$max_input_vars
3219
+				);
3220
+			} else {
3221
+				return '';
3222
+			}
3223
+		} else {
3224
+			return '';
3225
+		}
3226
+	}
3227
+
3228
+
3229
+	/**
3230
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3231
+	 *
3232
+	 * @since 4.4.1
3233
+	 * @return void
3234
+	 */
3235
+	public function recheck_values()
3236
+	{
3237
+		$this->_set_php_values();
3238
+	}
3239 3239
 }
3240 3240
 
3241 3241
 /**
@@ -3248,21 +3248,21 @@  discard block
 block discarded – undo
3248 3248
 class EE_Tax_Config extends EE_Config_Base
3249 3249
 {
3250 3250
 
3251
-    /*
3251
+	/*
3252 3252
      * flag to indicate whether or not to display ticket prices with the taxes included
3253 3253
      *
3254 3254
      * @var boolean $prices_displayed_including_taxes
3255 3255
      */
3256
-    public $prices_displayed_including_taxes;
3256
+	public $prices_displayed_including_taxes;
3257 3257
 
3258 3258
 
3259
-    /**
3260
-     *    class constructor
3261
-     */
3262
-    public function __construct()
3263
-    {
3264
-        $this->prices_displayed_including_taxes = true;
3265
-    }
3259
+	/**
3260
+	 *    class constructor
3261
+	 */
3262
+	public function __construct()
3263
+	{
3264
+		$this->prices_displayed_including_taxes = true;
3265
+	}
3266 3266
 }
3267 3267
 
3268 3268
 /**
@@ -3276,19 +3276,19 @@  discard block
 block discarded – undo
3276 3276
 class EE_Messages_Config extends EE_Config_Base
3277 3277
 {
3278 3278
 
3279
-    /**
3280
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3281
-     * A value of 0 represents never deleting.  Default is 0.
3282
-     *
3283
-     * @var integer
3284
-     */
3285
-    public $delete_threshold;
3279
+	/**
3280
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3281
+	 * A value of 0 represents never deleting.  Default is 0.
3282
+	 *
3283
+	 * @var integer
3284
+	 */
3285
+	public $delete_threshold;
3286 3286
 
3287 3287
 
3288
-    public function __construct()
3289
-    {
3290
-        $this->delete_threshold = 0;
3291
-    }
3288
+	public function __construct()
3289
+	{
3290
+		$this->delete_threshold = 0;
3291
+	}
3292 3292
 }
3293 3293
 
3294 3294
 /**
@@ -3299,31 +3299,31 @@  discard block
 block discarded – undo
3299 3299
 class EE_Gateway_Config extends EE_Config_Base
3300 3300
 {
3301 3301
 
3302
-    /**
3303
-     * Array with keys that are payment gateways slugs, and values are arrays
3304
-     * with any config info the gateway wants to store
3305
-     *
3306
-     * @var array
3307
-     */
3308
-    public $payment_settings;
3309
-
3310
-    /**
3311
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3312
-     * the gateway is stored in the uploads directory
3313
-     *
3314
-     * @var array
3315
-     */
3316
-    public $active_gateways;
3317
-
3318
-
3319
-    /**
3320
-     *    class constructor
3321
-     *
3322
-     * @deprecated
3323
-     */
3324
-    public function __construct()
3325
-    {
3326
-        $this->payment_settings = array();
3327
-        $this->active_gateways = array('Invoice' => false);
3328
-    }
3302
+	/**
3303
+	 * Array with keys that are payment gateways slugs, and values are arrays
3304
+	 * with any config info the gateway wants to store
3305
+	 *
3306
+	 * @var array
3307
+	 */
3308
+	public $payment_settings;
3309
+
3310
+	/**
3311
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3312
+	 * the gateway is stored in the uploads directory
3313
+	 *
3314
+	 * @var array
3315
+	 */
3316
+	public $active_gateways;
3317
+
3318
+
3319
+	/**
3320
+	 *    class constructor
3321
+	 *
3322
+	 * @deprecated
3323
+	 */
3324
+	public function __construct()
3325
+	{
3326
+		$this->payment_settings = array();
3327
+		$this->active_gateways = array('Invoice' => false);
3328
+	}
3329 3329
 }
Please login to merge, or discard this patch.
core/espresso_definitions.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@  discard block
 block discarded – undo
7 7
 define('EE_SUPPORT_EMAIL', '[email protected]');
8 8
 // used to be DIRECTORY_SEPARATOR, but that caused issues on windows
9 9
 if (! defined('DS')) {
10
-    define('DS', '/');
10
+	define('DS', '/');
11 11
 }
12 12
 if (! defined('PS')) {
13
-    define('PS', PATH_SEPARATOR);
13
+	define('PS', PATH_SEPARATOR);
14 14
 }
15 15
 if (! defined('SP')) {
16
-    define('SP', ' ');
16
+	define('SP', ' ');
17 17
 }
18 18
 if (! defined('EENL')) {
19
-    define('EENL', "\n");
19
+	define('EENL', "\n");
20 20
 }
21 21
 // define the plugin directory and URL
22 22
 define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
@@ -70,16 +70,16 @@  discard block
 block discarded – undo
70 70
 define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/');
71 71
 // check for DOMPDF fonts in uploads
72 72
 if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) {
73
-    define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/');
73
+	define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/');
74 74
 }
75 75
 // ajax constants
76 76
 define(
77
-    'EE_FRONT_AJAX',
78
-    isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax'])
77
+	'EE_FRONT_AJAX',
78
+	isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax'])
79 79
 );
80 80
 define(
81
-    'EE_ADMIN_AJAX',
82
-    isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax'])
81
+	'EE_ADMIN_AJAX',
82
+	isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax'])
83 83
 );
84 84
 // just a handy constant occasionally needed for finding values representing infinity in the DB
85 85
 // you're better to use this than its straight value (currently -1) in case you ever
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 define('EE_INF_IN_DB', -1);
88 88
 define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
89 89
 if (! defined('EE_DEBUG')) {
90
-    define('EE_DEBUG', false);
90
+	define('EE_DEBUG', false);
91 91
 }
92 92
 // for older WP versions
93 93
 if (! defined('MONTH_IN_SECONDS')) {
94
-    define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
94
+	define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
95 95
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -6,71 +6,71 @@  discard block
 block discarded – undo
6 6
 define('EE_MIN_PHP_VER_RECOMMENDED', '5.6.32');
7 7
 define('EE_SUPPORT_EMAIL', '[email protected]');
8 8
 // used to be DIRECTORY_SEPARATOR, but that caused issues on windows
9
-if (! defined('DS')) {
9
+if ( ! defined('DS')) {
10 10
     define('DS', '/');
11 11
 }
12
-if (! defined('PS')) {
12
+if ( ! defined('PS')) {
13 13
     define('PS', PATH_SEPARATOR);
14 14
 }
15
-if (! defined('SP')) {
15
+if ( ! defined('SP')) {
16 16
     define('SP', ' ');
17 17
 }
18
-if (! defined('EENL')) {
18
+if ( ! defined('EENL')) {
19 19
     define('EENL', "\n");
20 20
 }
21 21
 // define the plugin directory and URL
22 22
 define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
23
-define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE) . '/');
23
+define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE).'/');
24 24
 define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
25 25
 // main root folder paths
26
-define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages/');
27
-define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core/');
28
-define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules/');
29
-define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public/');
30
-define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes/');
31
-define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets/');
32
-define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods/');
33
-define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated/');
26
+define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages/');
27
+define('EE_CORE', EE_PLUGIN_DIR_PATH.'core/');
28
+define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules/');
29
+define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public/');
30
+define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes/');
31
+define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets/');
32
+define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods/');
33
+define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated/');
34 34
 // core system paths
35
-define('EE_ADMIN', EE_CORE . 'admin/');
36
-define('EE_CPTS', EE_CORE . 'CPTs/');
37
-define('EE_CLASSES', EE_CORE . 'db_classes/');
38
-define('EE_INTERFACES', EE_CORE . 'interfaces/');
39
-define('EE_BUSINESS', EE_CORE . 'business/');
40
-define('EE_MODELS', EE_CORE . 'db_models/');
41
-define('EE_HELPERS', EE_CORE . 'helpers/');
42
-define('EE_LIBRARIES', EE_CORE . 'libraries/');
43
-define('EE_TEMPLATES', EE_CORE . 'templates/');
44
-define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs/');
45
-define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets/');
46
-define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections/');
35
+define('EE_ADMIN', EE_CORE.'admin/');
36
+define('EE_CPTS', EE_CORE.'CPTs/');
37
+define('EE_CLASSES', EE_CORE.'db_classes/');
38
+define('EE_INTERFACES', EE_CORE.'interfaces/');
39
+define('EE_BUSINESS', EE_CORE.'business/');
40
+define('EE_MODELS', EE_CORE.'db_models/');
41
+define('EE_HELPERS', EE_CORE.'helpers/');
42
+define('EE_LIBRARIES', EE_CORE.'libraries/');
43
+define('EE_TEMPLATES', EE_CORE.'templates/');
44
+define('EE_THIRD_PARTY', EE_CORE.'third_party_libs/');
45
+define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets/');
46
+define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections/');
47 47
 // gateways
48
-define('EE_GATEWAYS', EE_MODULES . 'gateways/');
49
-define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules/gateways/');
48
+define('EE_GATEWAYS', EE_MODULES.'gateways/');
49
+define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules/gateways/');
50 50
 // asset URL paths
51
-define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core/templates/');
52
-define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets/');
53
-define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images/');
54
-define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core/third_party_libs/');
55
-define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
56
-define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
51
+define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core/templates/');
52
+define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets/');
53
+define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images/');
54
+define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core/third_party_libs/');
55
+define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/');
56
+define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/');
57 57
 // define upload paths
58 58
 $uploads = wp_upload_dir();
59 59
 // define the uploads directory and URL
60
-define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . '/espresso/');
61
-define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . '/espresso/');
60
+define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].'/espresso/');
61
+define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].'/espresso/');
62 62
 // define the templates directory and URL
63
-define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . '/espresso/templates/');
64
-define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . '/espresso/templates/');
63
+define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].'/espresso/templates/');
64
+define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].'/espresso/templates/');
65 65
 // define the gateway directory and URL
66
-define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . '/espresso/gateways/');
67
-define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . '/espresso/gateways/');
66
+define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].'/espresso/gateways/');
67
+define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].'/espresso/gateways/');
68 68
 // languages folder/path
69
-define('EE_LANGUAGES_SAFE_LOC', '../' . 'uploads/' . 'espresso/languages/');
70
-define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/');
69
+define('EE_LANGUAGES_SAFE_LOC', '../'.'uploads/'.'espresso/languages/');
70
+define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages/');
71 71
 // check for DOMPDF fonts in uploads
72
-if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) {
73
-    define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/');
72
+if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts/')) {
73
+    define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts/');
74 74
 }
75 75
 // ajax constants
76 76
 define(
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
 // want to change its default value! or find when -1 means infinity
87 87
 define('EE_INF_IN_DB', -1);
88 88
 define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
89
-if (! defined('EE_DEBUG')) {
89
+if ( ! defined('EE_DEBUG')) {
90 90
     define('EE_DEBUG', false);
91 91
 }
92 92
 // for older WP versions
93
-if (! defined('MONTH_IN_SECONDS')) {
93
+if ( ! defined('MONTH_IN_SECONDS')) {
94 94
     define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
95 95
 }
Please login to merge, or discard this patch.