Completed
Branch FET-9586-add-search-input (524ff8)
by
unknown
436:51 queued 422:19
created

EE_System::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 1
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
/**
3
 *
4
 * EE_System
5
 *
6
 * @package		Event Espresso
7
 * @subpackage	core/
8
 * @author		Brent Christensen, Michael Nelson
9
 *
10
 * ------------------------------------------------------------------------
11
 */
12
final class EE_System {
13
14
15
	/**
16
	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
17
	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
18
	 */
19
	const req_type_normal = 0;
20
21
	/**
22
	 * Indicates this is a brand new installation of EE so we should install
23
	 * tables and default data etc
24
	 */
25
	const req_type_new_activation = 1;
26
27
	/**
28
	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
29
	 * and we just exited maintenance mode). We MUST check the database is setup properly
30
	 * and that default data is setup too
31
	 */
32
	const req_type_reactivation = 2;
33
34
	/**
35
	 * indicates that EE has been upgraded since its previous request.
36
	 * We may have data migration scripts to call and will want to trigger maintenance mode
37
	 */
38
	const req_type_upgrade = 3;
39
40
	/**
41
	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
42
	 */
43
	const req_type_downgrade = 4;
44
45
	/**
46
	 * @deprecated since version 4.6.0.dev.006
47
	 * Now whenever a new_activation is detected the request type is still just
48
	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
49
	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
50
	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
51
	 * (Specifically, when the migration manager indicates migrations are finished
52
	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
53
	 */
54
	const req_type_activation_but_not_installed = 5;
55
56
	/**
57
	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
58
	 */
59
	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
60
61
62
	/**
63
	 *    instance of the EE_System object
64
	 *
65
	 * @var    $_instance
66
	 * @access    private
67
	 */
68
	private static $_instance = null;
69
70
	/**
71
	 * @type  EE_Registry $Registry
72
	 * @access    protected
73
	 */
74
	protected $registry;
75
76
	/**
77
	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
78
	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
79
	 * @var int
80
	 */
81
	private $_req_type;
82
83
84
85
	/**
86
	 * @singleton method used to instantiate class object
87
	 * @access public
88
	 * @param  \EE_Registry        $Registry
89
	 * @return \EE_System
90
	 */
91
	public static function instance( EE_Registry $Registry = null ) {
92
		// check if class object is instantiated
93
		if ( ! self::$_instance instanceof EE_System ) {
94
			self::$_instance = new self( $Registry );
0 ignored issues
show
Bug introduced by
It seems like $Registry defined by parameter $Registry on line 91 can be null; however, EE_System::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
95
		}
96
		return self::$_instance;
97
	}
98
99
100
	/**
101
	 * resets the instance and returns it
102
	 * @return EE_System
103
	 */
104
	public static function reset(){
105
		self::$_instance->_req_type = NULL;
106
		//we need to reset the migration manager in order for it to detect DMSs properly
107
		EE_Data_Migration_Manager::reset();
108
		//make sure none of the old hooks are left hanging around
109
		remove_all_actions( 'AHEE__EE_System__perform_activations_upgrades_and_migrations');
110
		self::instance()->detect_activations_or_upgrades();
111
		self::instance()->perform_activations_upgrades_and_migrations();
112
		return self::instance();
113
	}
114
115
116
117
	/**
118
	 *    sets hooks for running rest of system
119
	 *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
120
	 *    starting EE Addons from any other point may lead to problems
121
	 *
122
	 * @access private
123
	 * @param  \EE_Registry        $Registry
124
	 */
125
	private function __construct( EE_Registry $Registry ) {
126
		$this->registry = $Registry;
127
		do_action( 'AHEE__EE_System__construct__begin', $this );
128
		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
129
		add_action( 'AHEE__EE_Bootstrap__load_espresso_addons', array( $this, 'load_espresso_addons' ) );
130
		// when an ee addon is activated, we want to call the core hook(s) again
131
		// because the newly-activated addon didn't get a chance to run at all
132
		add_action( 'activate_plugin', array( $this, 'load_espresso_addons' ), 1 );
133
		// detect whether install or upgrade
134
		add_action( 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', array( $this, 'detect_activations_or_upgrades' ), 3 );
135
		// load EE_Config, EE_Textdomain, etc
136
		add_action( 'AHEE__EE_Bootstrap__load_core_configuration', array( $this, 'load_core_configuration' ), 5 );
137
		// load EE_Config, EE_Textdomain, etc
138
		add_action( 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', array( $this, 'register_shortcodes_modules_and_widgets' ), 7 );
139
		// you wanna get going? I wanna get going... let's get going!
140
		add_action( 'AHEE__EE_Bootstrap__brew_espresso', array( $this, 'brew_espresso' ), 9 );
141
		//other housekeeping
142
		//exclude EE critical pages from wp_list_pages
143
		add_filter( 'wp_list_pages_excludes', array( $this, 'remove_pages_from_wp_list_pages' ), 10 );
144
		// ALL EE Addons should use the following hook point to attach their initial setup too
145
		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
146
		do_action( 'AHEE__EE_System__construct__complete', $this );
147
	}
148
149
150
151
	/**
152
	 * load_espresso_addons
153
	 *
154
	 * allow addons to load first so that they can set hooks for running DMS's, etc
155
	 * this is hooked into both:
156
	 * 	'AHEE__EE_Bootstrap__load_core_configuration'
157
	 * 		which runs during the WP 'plugins_loaded' action at priority 5
158
	 * 	and the WP 'activate_plugin' hookpoint
159
	 *
160
	 * @access public
161
	 * @return void
162
	 */
163
	public function load_espresso_addons() {
164
		// set autoloaders for all of the classes implementing EEI_Plugin_API
165
		// which provide helpers for EE plugin authors to more easily register certain components with EE.
166
		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_LIBRARIES . 'plugin_api' );
167
		//load and setup EE_Capabilities
168
		$this->registry->load_core( 'Capabilities' );
169
		//caps need to be initialized on every request so that capability maps are set.
170
		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
171
		$this->registry->CAP->init_caps();
172
		do_action( 'AHEE__EE_System__load_espresso_addons' );
173
		//if the WP API basic auth plugin isn't already loaded, load it now.
174
		//We want it for mobile apps. Just include the entire plugin
175
		//also, don't load the basic auth when a plugin is getting activated, because
176
		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
177
		//and causes a fatal error
178
		if( !function_exists( 'json_basic_auth_handler' )
179
			&& ! function_exists( 'json_basic_auth_error' )
180
			&& ! (
181
				isset( $_GET[ 'action'] )
182
				&& in_array( $_GET[ 'action' ], array( 'activate', 'activate-selected' ) )
183
			)
184
			&& ! (
185
				isset( $_GET['activate' ] )
186
				&& $_GET['activate' ] === 'true'
187
			)
188
		) {
189
			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
190
		}
191
	}
192
193
194
	/**
195
	 * detect_activations_or_upgrades
196
	 *
197
	 * Checks for activation or upgrade of core first;
198
	 * then also checks if any registered addons have been activated or upgraded
199
	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
200
	 * which runs during the WP 'plugins_loaded' action at priority 3
201
	 *
202
	 * @access public
203
	 * @return void
204
	 */
205
	public function detect_activations_or_upgrades(){
206
		//first off: let's make sure to handle core
207
		$this->detect_if_activation_or_upgrade();
208
		foreach($this->registry->addons as $addon){
209
			//detect teh request type for that addon
210
			$addon->detect_activation_or_upgrade();
211
		}
212
	}
213
214
215
216
	/**
217
	* detect_if_activation_or_upgrade
218
	*
219
	* Takes care of detecting whether this is a brand new install or code upgrade,
220
	* and either setting up the DB or setting up maintenance mode etc.
221
	*
222
	* @access public
223
	* @return void
224
	*/
225
	public function detect_if_activation_or_upgrade() {
226
		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
227
228
		// load M-Mode class
229
		$this->registry->load_core( 'Maintenance_Mode' );
230
		// check if db has been updated, or if its a brand-new installation
231
232
		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
233
		$request_type =  $this->detect_req_type($espresso_db_update);
234
		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
235
236
		switch($request_type){
237
			case EE_System::req_type_new_activation:
238
				do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__new_activation' );
239
				$this->_handle_core_version_change( $espresso_db_update );
240
				break;
241
			case EE_System::req_type_reactivation:
242
				do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__reactivation' );
243
				$this->_handle_core_version_change( $espresso_db_update );
244
				break;
245
			case EE_System::req_type_upgrade:
246
				do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__upgrade' );
247
				//migrations may be required now that we've upgraded
248
				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
249
				$this->_handle_core_version_change( $espresso_db_update );
250
//				echo "done upgrade";die;
251
				break;
252
			case EE_System::req_type_downgrade:
253
				do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__downgrade' );
254
				//its possible migrations are no longer required
255
				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
256
				$this->_handle_core_version_change( $espresso_db_update );
257
				break;
258
			case EE_System::req_type_normal:
259
			default:
260
//				$this->_maybe_redirect_to_ee_about();
261
				break;
262
		}
263
		do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__complete' );
264
	}
265
266
	/**
267
	 * Updates the list of installed versions and sets hooks for
268
	 * initializing the database later during the request
269
	 * @param array $espresso_db_update
270
	 */
271
	protected function _handle_core_version_change( $espresso_db_update ){
272
		$this->update_list_of_installed_versions( $espresso_db_update );
273
		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
274
		add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ));
275
	}
276
277
278
279
280
	/**
281
	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
282
	 * information about what versions of EE have been installed and activated,
283
	 * NOT necessarily the state of the database
284
	 *
285
	 * @param null $espresso_db_update
286
	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it from the options table
287
	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
288
	 */
289
	private function fix_espresso_db_upgrade_option($espresso_db_update = null){
290
		do_action( 'FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update );
291
		if( ! $espresso_db_update){
292
			$espresso_db_update = get_option( 'espresso_db_update' );
293
		}
294
		// check that option is an array
295
		if( ! is_array( $espresso_db_update )) {
296
			// if option is FALSE, then it never existed
297
			if ( $espresso_db_update === FALSE ) {
298
				// make $espresso_db_update an array and save option with autoload OFF
299
				$espresso_db_update =  array();
300
				add_option( 'espresso_db_update', $espresso_db_update, '', 'no' );
301
			} else {
302
				// option is NOT FALSE but also is NOT an array, so make it an array and save it
303
				$espresso_db_update =  array( $espresso_db_update=>array() );
304
				update_option( 'espresso_db_update', $espresso_db_update );
305
			}
306
		}else{
307
			$corrected_db_update = array();
308
			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
309
			foreach($espresso_db_update as $should_be_version_string => $should_be_array){
310
				if(is_int($should_be_version_string) && ! is_array($should_be_array)){
311
					//the key is an int, and the value IS NOT an array
312
					//so it must be numerically-indexed, where values are versions installed...
313
					//fix it!
314
					$version_string = $should_be_array;
315
					$corrected_db_update[$version_string] = array('unknown-date');
316
				}else{
317
					//ok it checks out
318
					$corrected_db_update[$should_be_version_string] = $should_be_array;
319
				}
320
			}
321
			$espresso_db_update = $corrected_db_update;
322
			update_option( 'espresso_db_update', $espresso_db_update );
323
324
		}
325
326
		do_action( 'FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update );
327
		return $espresso_db_update;
328
	}
329
330
331
332
333
	/**
334
	 * Does the traditional work of setting up the plugin's database and adding default data.
335
	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
336
	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
337
	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
338
	 * so that it will be done when migrations are finished
339
	 *
340
	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
341
	 * @param boolean $verify_schema if true will re-check the database tables have the correct schema.
342
	 *                               This is a resource-intensive job
343
	 * so we prefer to only do it when necessary
344
	 * @return void
345
	 */
346
	public function initialize_db_if_no_migrations_required( $initialize_addons_too = FALSE, $verify_schema = true ){
347
		$request_type = $this->detect_req_type();
348
		//only initialize system if we're not in maintenance mode.
349
		if( EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance ){
350
			update_option( 'ee_flush_rewrite_rules', TRUE );
351
352
			if( $verify_schema ) {
353
				EEH_Activation::initialize_db_and_folders();
354
			}
355
			EEH_Activation::initialize_db_content();
356
			EEH_Activation::system_initialization();
357
			if( $initialize_addons_too ) {
358
				$this->initialize_addons();
359
			}
360
		}else{
361
			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for( 'Core' );
362
		}
363
		if ( $request_type == EE_System::req_type_new_activation || $request_type == EE_System::req_type_reactivation || $request_type == EE_System::req_type_upgrade ) {
364
			add_action( 'AHEE__EE_System__load_CPTs_and_session__start', array( $this, 'redirect_to_about_ee' ), 9 );
365
		}
366
	}
367
368
	/**
369
	 * Initializes the db for all registered addons
370
	 */
371
	public function initialize_addons(){
372
		//foreach registered addon, make sure its db is up-to-date too
373
		foreach($this->registry->addons as $addon){
374
			$addon->initialize_db_if_no_migrations_required();
375
		}
376
	}
377
378
379
	/**
380
	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
381
	 * @param 	array 	$version_history
382
	 * @param 	string 	$current_version_to_add 	version to be added to the version history
383
	 * @return 	boolean success as to whether or not this option was changed
384
	 */
385
	public function update_list_of_installed_versions($version_history = NULL,$current_version_to_add = NULL) {
386
		if( ! $version_history ) {
387
			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
0 ignored issues
show
Bug introduced by
It seems like $version_history defined by $this->fix_espresso_db_u...ption($version_history) on line 387 can also be of type array; however, EE_System::fix_espresso_db_upgrade_option() does only seem to accept null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
388
		}
389
		if( $current_version_to_add == NULL){
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $current_version_to_add of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
390
			$current_version_to_add = espresso_version();
391
		}
392
		$version_history[ $current_version_to_add ][] = date( 'Y-m-d H:i:s',time() );
393
		// re-save
394
		return update_option( 'espresso_db_update', $version_history );
395
	}
396
397
398
399
400
	/**
401
	 * Detects if the current version indicated in the has existed in the list of
402
	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
403
	 *
404
	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
405
	 *                            If not supplied, fetches it from the options table.
406
	 *                            Also, caches its result so later parts of the code can also know whether there's been an
407
	 *                            update or not. This way we can add the current version to espresso_db_update,
408
	 *                            but still know if this is a new install or not
409
	 * @return int one of the constants on EE_System::req_type_
410
	 */
411
	public function detect_req_type( $espresso_db_update = NULL ){
412
		if ( $this->_req_type === NULL ){
413
			$espresso_db_update = ! empty( $espresso_db_update ) ? $espresso_db_update : $this->fix_espresso_db_upgrade_option();
414
			$this->_req_type = $this->detect_req_type_given_activation_history( $espresso_db_update, 'ee_espresso_activation', espresso_version() );
415
		}
416
		return $this->_req_type;
417
	}
418
419
420
421
	/**
422
	 * Determines the request type for any ee addon, given three piece of info: the current array of activation histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin
423
	 * was just activated to (for core that will always be espresso_version())
424
	 * @param array $activation_history_for_addon the option's value which stores the activation history for this ee plugin.
425
	 * for core that's 'espresso_db_update'
426
	 * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to indicate that this plugin was just activated
427
	 * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be espresso_version())
428
	 * @return int one of the constants on EE_System::req_type_*
429
	 */
430
	public static function detect_req_type_given_activation_history( $activation_history_for_addon, $activation_indicator_option_name, $version_to_upgrade_to ){
431
		$version_is_higher = self::_new_version_is_higher( $activation_history_for_addon, $version_to_upgrade_to );
432
		if( $activation_history_for_addon ){
0 ignored issues
show
Bug Best Practice introduced by
The expression $activation_history_for_addon of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
433
			//it exists, so this isn't a completely new install
434
			//check if this version already in that list of previously installed versions
435
			if ( ! isset( $activation_history_for_addon[ $version_to_upgrade_to ] )) {
436
				//it a version we haven't seen before
437
				if( $version_is_higher === 1 ){
438
					$req_type = EE_System::req_type_upgrade;
439
				}else{
440
					$req_type = EE_System::req_type_downgrade;
441
				}
442
				delete_option( $activation_indicator_option_name );
443
			} else {
444
				// its not an update. maybe a reactivation?
445
				if( get_option( $activation_indicator_option_name, FALSE ) ){
446 View Code Duplication
					if ( $version_is_higher === -1 ){
447
						$req_type = EE_System::req_type_downgrade;
448
					}elseif( $version_is_higher === 0 ){
449
						//we've seen this version before, but it's an activation. must be a reactivation
450
						$req_type = EE_System::req_type_reactivation;
451
					}else{//$version_is_higher === 1
452
						$req_type = EE_System::req_type_upgrade;
453
					}
454
					delete_option( $activation_indicator_option_name );
455 View Code Duplication
				} else {
456
					//we've seen this version before and the activation indicate doesn't show it was just activated
457
					if ( $version_is_higher === -1 ){
458
						$req_type = EE_System::req_type_downgrade;
459
					}elseif( $version_is_higher === 0 ){
460
						//we've seen this version before and it's not an activation. its normal request
461
						$req_type = EE_System::req_type_normal;
462
					}else{//$version_is_higher === 1
463
						$req_type = EE_System::req_type_upgrade;
464
					}
465
				}
466
			}
467
		} else {
468
			//brand new install
469
			$req_type = EE_System::req_type_new_activation;
470
			delete_option( $activation_indicator_option_name );
471
		}
472
		return $req_type;
473
	}
474
475
476
477
	/**
478
	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
479
	 * the $activation_history_for_addon
480
	 * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated,
481
	 * sometimes containing 'unknown-date'
482
	 * @param string $version_to_upgrade_to (current version)
483
	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
484
	 *	ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
485
	 *		0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
486
	 *		1 if $version_to_upgrade_to is HIGHER (upgrade) ;
487
	 */
488
	protected static function _new_version_is_higher( $activation_history_for_addon, $version_to_upgrade_to ){
489
		//find the most recently-activated version
490
		$most_recently_active_version_activation = '1970-01-01 00:00:00';
491
		$most_recently_active_version = '0.0.0.dev.000';
492
		if( is_array( $activation_history_for_addon ) ){
493
			foreach( $activation_history_for_addon as $version => $times_activated ){
494
				//check there is a record of when this version was activated. Otherwise,
495
				//mark it as unknown
496
				if( ! $times_activated ){
497
					$times_activated = array( 'unknown-date');
498
				}
499
				if( is_string( $times_activated ) ){
500
					$times_activated = array( $times_activated );
501
				}
502
				foreach( $times_activated as $an_activation ){
503
					if( $an_activation != 'unknown-date' &&
504
							$an_activation > $most_recently_active_version_activation  ){
505
						$most_recently_active_version = $version;
506
						$most_recently_active_version_activation = $an_activation == 'unknown-date' ? '1970-01-01 00:00:00' : $an_activation;
507
					}
508
				}
509
			}
510
		}
511
		return version_compare( $version_to_upgrade_to, $most_recently_active_version );
512
	}
513
514
515
516
	/**
517
	 * This redirects to the about EE page after activation
518
	 * @return void
519
	 */
520
	public function redirect_to_about_ee() {
521
		$notices = EE_Error::get_notices( FALSE );
522
		//if current user is an admin and it's not an ajax request
523
		if (
524
			$this->registry->CAP->current_user_can( 'manage_options', 'espresso_about_default' )
525
			&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
526
			&& ! isset( $notices[ 'errors' ] )
527
		) {
528
			$query_params =  array( 'page' => 'espresso_about' );
529
530
			if ( EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation ) {
531
			    $query_params['new_activation'] = TRUE;
532
			}
533
534
			if ( EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation ) {
535
			    $query_params['reactivation'] = TRUE;
536
			}
537
			$url = add_query_arg( $query_params, admin_url( 'admin.php' ) );
538
			wp_safe_redirect( $url );
539
			exit();
540
		}
541
	}
542
543
544
	/**
545
	 * load_core_configuration
546
	 *
547
	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
548
	 * which runs during the WP 'plugins_loaded' action at priority 5
549
	 *
550
	 * @return void
551
	 */
552
	public function load_core_configuration(){
553
		do_action( 'AHEE__EE_System__load_core_configuration__begin', $this );
554
		$this->registry->load_core( 'EE_Load_Textdomain' );
555
		//load textdomain
556
		EE_Load_Textdomain::load_textdomain();
557
		// load and setup EE_Config and EE_Network_Config
558
		$this->registry->load_core( 'Config' );
559
		$this->registry->load_core( 'Network_Config' );
560
		// setup autoloaders
561
		// enable logging?
562
		if ( $this->registry->CFG->admin->use_full_logging ) {
563
			$this->registry->load_core( 'Log' );
564
		}
565
		// check for activation errors
566
		$activation_errors = get_option( 'ee_plugin_activation_errors', FALSE );
567
		if ( $activation_errors ) {
568
			EE_Error::add_error( $activation_errors, __FILE__, __FUNCTION__, __LINE__ );
569
			update_option( 'ee_plugin_activation_errors', FALSE );
570
		}
571
		// get model names
572
		$this->_parse_model_names();
573
574
		//load caf stuff a chance to play during the activation process too.
575
		$this->_maybe_brew_regular();
576
		do_action( 'AHEE__EE_System__load_core_configuration__complete', $this );
577
	}
578
579
580
	/**
581
	 * cycles through all of the models/*.model.php files, and assembles an array of model names
582
	 *
583
	 * @return void
584
	 */
585
	private function _parse_model_names(){
586
		//get all the files in the EE_MODELS folder that end in .model.php
587
		$models = glob( EE_MODELS.'*.model.php');
588
		$model_names = array();
589
		$non_abstract_db_models = array();
590
		foreach( $models as $model ){
591
			// get model classname
592
			$classname = EEH_File::get_classname_from_filepath_with_standard_filename( $model );
593
			$short_name = str_replace( 'EEM_', '', $classname );
594
			$reflectionClass = new ReflectionClass($classname);
595
			if( $reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()){
596
				$non_abstract_db_models[ $short_name ] = $classname;
597
			}
598
			$model_names[ $short_name ] = $classname;
599
		}
600
		$this->registry->models = apply_filters( 'FHEE__EE_System__parse_model_names', $model_names );
601
		$this->registry->non_abstract_db_models = apply_filters( 'FHEE__EE_System__parse_implemented_model_names', $non_abstract_db_models );
602
	}
603
604
605
606
	/**
607
	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks that need to be setup before our EE_System launches.
608
	 * @return void
609
	 */
610
	private function _maybe_brew_regular() {
611
		if (( ! defined( 'EE_DECAF' ) ||  EE_DECAF !== TRUE ) && is_readable( EE_CAFF_PATH . 'brewing_regular.php' )) {
612
			require_once EE_CAFF_PATH . 'brewing_regular.php';
613
		}
614
	}
615
616
617
618
	/**
619
	 * register_shortcodes_modules_and_widgets
620
	 *
621
	 * generate lists of shortcodes and modules, then verify paths and classes
622
	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
623
	 * which runs during the WP 'plugins_loaded' action at priority 7
624
	 *
625
	 * @access public
626
	 * @return void
627
	 */
628
	public function register_shortcodes_modules_and_widgets() {
629
		do_action( 'AHEE__EE_System__register_shortcodes_modules_and_widgets' );
630
		// check for addons using old hookpoint
631
		if ( has_action( 'AHEE__EE_System__register_shortcodes_modules_and_addons' )) {
632
			$this->_incompatible_addon_error();
633
		}
634
	}
635
636
637
	/**
638
	* _incompatible_addon_error
639
	*
640
	* @access public
641
	* @return void
642
	*/
643
	private function _incompatible_addon_error() {
644
		// get array of classes hooking into here
645
		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( 'AHEE__EE_System__register_shortcodes_modules_and_addons' );
646
		if ( ! empty( $class_names )) {
647
			$msg = __( 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', 'event_espresso' );
648
			$msg .= '<ul>';
649
			foreach ( $class_names as $class_name ) {
650
				$msg .= '<li><b>Event Espresso - ' . str_replace( array( 'EE_', 'EEM_', 'EED_', 'EES_', 'EEW_' ), '', $class_name ) . '</b></li>';
651
			}
652
			$msg .= '</ul>';
653
			$msg .= __( 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', 'event_espresso' );
654
			// save list of incompatible addons to wp-options for later use
655
			add_option( 'ee_incompatible_addons', $class_names, '', 'no' );
656
			if ( is_admin() ) {
657
				EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
658
			}
659
		}
660
	}
661
662
663
664
665
	/**
666
	 * brew_espresso
667
	 *
668
	 * begins the process of setting hooks for initializing EE in the correct order
669
	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
670
	 * which runs during the WP 'plugins_loaded' action at priority 9
671
	 *
672
	 * @return void
673
	 */
674
	public function brew_espresso(){
675
		do_action( 'AHEE__EE_System__brew_espresso__begin', $this );
676
		// load some final core systems
677
		add_action( 'init', array( $this, 'set_hooks_for_core' ), 1 );
678
		add_action( 'init', array( $this, 'perform_activations_upgrades_and_migrations' ), 3 );
679
		add_action( 'init', array( $this, 'load_CPTs_and_session' ), 5 );
680
		add_action( 'init', array( $this, 'load_controllers' ), 7 );
681
		add_action( 'init', array( $this, 'core_loaded_and_ready' ), 9 );
682
		add_action( 'init', array( $this, 'initialize' ), 10 );
683
		add_action( 'init', array( $this, 'initialize_last' ), 100 );
684
		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 25 );
685
		add_action('admin_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 25 );
686
		add_action( 'admin_bar_menu', array( $this, 'espresso_toolbar_items' ), 100 );
687
688
		if ( is_admin() && apply_filters( 'FHEE__EE_System__brew_espresso__load_pue', TRUE )  ) {
689
			// pew pew pew
690
			$this->registry->load_core( 'PUE' );
691
			do_action( 'AHEE__EE_System__brew_espresso__after_pue_init' );
692
		}
693
		do_action( 'AHEE__EE_System__brew_espresso__complete', $this );
694
	}
695
696
697
698
699
	/**
700
	 * 	set_hooks_for_core
701
	 *
702
	 *  	@access public
703
	 *  	@return 	void
704
	 */
705
	public function set_hooks_for_core() {
706
		$this->_deactivate_incompatible_addons();
707
		do_action( 'AHEE__EE_System__set_hooks_for_core' );
708
	}
709
710
711
712
	/**
713
	 * Using the information gathered in EE_System::_incompatible_addon_error,
714
	 * deactivates any addons considered incompatible with the current version of EE
715
	 */
716
	private function _deactivate_incompatible_addons(){
717
		$incompatible_addons = get_option( 'ee_incompatible_addons', array() );
718
		if ( ! empty( $incompatible_addons )) {
719
			$active_plugins = get_option( 'active_plugins', array() );
720
			foreach ( $active_plugins as $active_plugin ) {
721
				foreach ( $incompatible_addons as $incompatible_addon ) {
722
					if ( strpos( $active_plugin,  $incompatible_addon ) !== FALSE ) {
723
						unset( $_GET['activate'] );
724
						espresso_deactivate_plugin( $active_plugin );
725
					}
726
				}
727
			}
728
		}
729
	}
730
731
732
733
	/**
734
	 * 	perform_activations_upgrades_and_migrations
735
	 *
736
	 *  	@access public
737
	 *  	@return 	void
738
	 */
739
	public function perform_activations_upgrades_and_migrations() {
740
		//first check if we had previously attempted to setup EE's directories but failed
741
		if( EEH_Activation::upload_directories_incomplete() ) {
742
			EEH_Activation::create_upload_directories();
743
		}
744
		do_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations' );
745
	}
746
747
748
749
	/**
750
	 * 	load_CPTs_and_session
751
	 *
752
	 *  	@access public
753
	 *  	@return 	void
754
	 */
755
	public function load_CPTs_and_session() {
756
		do_action( 'AHEE__EE_System__load_CPTs_and_session__start' );
757
		// register Custom Post Types
758
		$this->registry->load_core( 'Register_CPTs' );
759
		do_action( 'AHEE__EE_System__load_CPTs_and_session__complete' );
760
	}
761
762
763
764
	/**
765
	* load_controllers
766
	*
767
	* this is the best place to load any additional controllers that needs access to EE core.
768
	* it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this time
769
	*
770
	* @access public
771
	* @return void
772
	*/
773
	public function load_controllers() {
774
		do_action( 'AHEE__EE_System__load_controllers__start' );
775
		// let's get it started
776
		if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level() ) {
777
			do_action( 'AHEE__EE_System__load_controllers__load_front_controllers' );
778
			$this->registry->load_core( 'Front_Controller', array(), false, true );
0 ignored issues
show
Unused Code introduced by
The call to EE_Registry::load_core() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
779
		} else if ( ! EE_FRONT_AJAX ) {
780
			do_action( 'AHEE__EE_System__load_controllers__load_admin_controllers' );
781
			EE_Registry::instance()->load_core( 'Admin' );
782
		}
783
		do_action( 'AHEE__EE_System__load_controllers__complete' );
784
	}
785
786
787
788
	/**
789
	* core_loaded_and_ready
790
	*
791
	* all of the basic EE core should be loaded at this point and available regardless of M-Mode
792
	*
793
	* @access public
794
	* @return void
795
	*/
796
	public function core_loaded_and_ready() {
797
		do_action( 'AHEE__EE_System__core_loaded_and_ready' );
798
		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
799
		$this->registry->load_core( 'Session' );
800
		//		add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 );
801
	}
802
803
804
805
	/**
806
	* initialize
807
	*
808
	* this is the best place to begin initializing client code
809
	*
810
	* @access public
811
	* @return void
812
	*/
813
	public function initialize() {
814
		do_action( 'AHEE__EE_System__initialize' );
815
	}
816
817
818
819
	/**
820
	* initialize_last
821
	*
822
	* this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to initialize has done so
823
	*
824
	* @access public
825
	* @return void
826
	*/
827
	public function initialize_last() {
828
		do_action( 'AHEE__EE_System__initialize_last' );
829
	}
830
831
832
833
834
	/**
835
	* set_hooks_for_shortcodes_modules_and_addons
836
	*
837
	* this is the best place for other systems to set callbacks for hooking into other parts of EE
838
	* this happens at the very beginning of the wp_loaded hookpoint
839
	*
840
	* @access public
841
	* @return void
842
	*/
843
	public function set_hooks_for_shortcodes_modules_and_addons() {
844
//		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
845
	}
846
847
848
849
850
	/**
851
	* do_not_cache
852
	*
853
	* sets no cache headers and defines no cache constants for WP plugins
854
	*
855
	* @access public
856
	* @return void
857
	*/
858
	public static function do_not_cache() {
859
		// set no cache constants
860
		if ( ! defined( 'DONOTCACHEPAGE' ) ) {
861
			define( 'DONOTCACHEPAGE', true );
862
		}
863
		if ( ! defined( 'DONOTCACHCEOBJECT' ) ) {
864
			define( 'DONOTCACHCEOBJECT', true );
865
		}
866
		if ( ! defined( 'DONOTCACHEDB' ) ) {
867
			define( 'DONOTCACHEDB', true );
868
		}
869
		// add no cache headers
870
		add_action( 'send_headers' , array( 'EE_System', 'nocache_headers' ), 10 );
871
		// plus a little extra for nginx and Google Chrome
872
		add_filter( 'nocache_headers', array( 'EE_System', 'extra_nocache_headers' ), 10, 1 );
873
		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
874
		remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
875
	}
876
877
878
879
	/**
880
	 *    extra_nocache_headers
881
	 *
882
	 * @access    public
883
	 * @param $headers
884
	 * @return    array
885
	 */
886
	public static function extra_nocache_headers ( $headers ) {
887
		// for NGINX
888
		$headers['X-Accel-Expires'] = 0;
889
		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
890
		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
891
		return $headers;
892
	}
893
894
895
896
	/**
897
	 * 	nocache_headers
898
	 *
899
	 *  @access 	public
900
	 *  @return 	void
901
	 */
902
	public static function nocache_headers() {
903
		nocache_headers();
904
	}
905
906
907
908
	/**
909
	 *    espresso_toolbar_items
910
	 *
911
	 * @access public
912
	 * @param  WP_Admin_Bar $admin_bar
913
	 * @return void
914
	 */
915
	public function espresso_toolbar_items( WP_Admin_Bar $admin_bar ) {
916
917
		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
918
		if ( EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance || defined( 'DOING_AJAX' ) || ! $this->registry->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_top_level' )) {
919
			return;
920
		}
921
922
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
923
		$menu_class = 'espresso_menu_item_class';
924
		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
925
		//because they're only defined in each of their respective constructors
926
		//and this might be a frontend request, in which case they aren't available
927
		$events_admin_url = admin_url("admin.php?page=espresso_events");
928
		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
929
		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
930
931
		//Top Level
932
		$admin_bar->add_menu(array(
933
				'id' => 'espresso-toolbar',
934
				'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') . '</span>',
935
				'href' => $events_admin_url,
936
				'meta' => array(
937
						'title' => __('Event Espresso', 'event_espresso'),
938
						'class' => $menu_class . 'first'
939
				),
940
		));
941
942
		//Events
943 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events' ) ) {
944
			$admin_bar->add_menu(array(
945
					'id' => 'espresso-toolbar-events',
946
					'parent' => 'espresso-toolbar',
947
					'title' => __( 'Events', 'event_espresso' ),
948
					'href' => $events_admin_url,
949
					'meta' => array(
950
							'title' => __('Events', 'event_espresso'),
951
							'target' => '',
952
							'class' => $menu_class
953
					),
954
			));
955
		}
956
957
958
		if ( $this->registry->CAP->current_user_can( 'ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new' ) ) {
959
			//Events Add New
960
			$admin_bar->add_menu(array(
961
					'id' => 'espresso-toolbar-events-new',
962
					'parent' => 'espresso-toolbar-events',
963
					'title' => __('Add New', 'event_espresso'),
964
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'create_new' ), $events_admin_url ),
965
					'meta' => array(
966
							'title' => __('Add New', 'event_espresso'),
967
							'target' => '',
968
							'class' => $menu_class
969
					),
970
			));
971
		}
972
973
		if ( is_single() && ( get_post_type() == 'espresso_events' ) ) {
974
975
			//Current post
976
			global $post;
977
978
	    	if ( $this->registry->CAP->current_user_can( 'ee_edit_event', 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID ) ) {
979
				//Events Edit Current Event
980
				$admin_bar->add_menu(array(
981
						'id' => 'espresso-toolbar-events-edit',
982
						'parent' => 'espresso-toolbar-events',
983
						'title' => __('Edit Event', 'event_espresso'),
984
						'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'edit', 'post'=>$post->ID ), $events_admin_url ),
985
						'meta' => array(
986
								'title' => __('Edit Event', 'event_espresso'),
987
								'target' => '',
988
								'class' => $menu_class
989
						),
990
				));
991
			}
992
993
		}
994
995
		//Events View
996 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-view' ) ) {
997
			$admin_bar->add_menu(array(
998
					'id' => 'espresso-toolbar-events-view',
999
					'parent' => 'espresso-toolbar-events',
1000
					'title' => __( 'View', 'event_espresso' ),
1001
					'href' => $events_admin_url,
1002
					'meta' => array(
1003
							'title' => __('View', 'event_espresso'),
1004
							'target' => '',
1005
							'class' => $menu_class
1006
					),
1007
			));
1008
		}
1009
1010 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all' ) ) {
1011
			//Events View All
1012
			$admin_bar->add_menu(array(
1013
					'id' => 'espresso-toolbar-events-all',
1014
					'parent' => 'espresso-toolbar-events-view',
1015
					'title' => __( 'All', 'event_espresso' ),
1016
					'href' => $events_admin_url,
1017
					'meta' => array(
1018
							'title' => __('All', 'event_espresso'),
1019
							'target' => '',
1020
							'class' => $menu_class
1021
					),
1022
			));
1023
		}
1024
1025
1026 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-today' ) ) {
1027
			//Events View Today
1028
			$admin_bar->add_menu(array(
1029
					'id' => 'espresso-toolbar-events-today',
1030
					'parent' => 'espresso-toolbar-events-view',
1031
					'title' => __('Today', 'event_espresso'),
1032
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $events_admin_url ),
1033
					'meta' => array(
1034
							'title' => __('Today', 'event_espresso'),
1035
							'target' => '',
1036
							'class' => $menu_class
1037
					),
1038
			));
1039
		}
1040
1041
1042 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-month' ) ) {
1043
			//Events View This Month
1044
			$admin_bar->add_menu(array(
1045
					'id' => 'espresso-toolbar-events-month',
1046
					'parent' => 'espresso-toolbar-events-view',
1047
					'title' => __( 'This Month', 'event_espresso'),
1048
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $events_admin_url ),
1049
					'meta' => array(
1050
							'title' => __('This Month', 'event_espresso'),
1051
							'target' => '',
1052
							'class' => $menu_class
1053
					),
1054
			));
1055
		}
1056
1057
		//Registration Overview
1058 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations' ) ) {
1059
			$admin_bar->add_menu(array(
1060
					'id' => 'espresso-toolbar-registrations',
1061
					'parent' => 'espresso-toolbar',
1062
					'title' => __( 'Registrations', 'event_espresso' ),
1063
					'href' => $reg_admin_url,
1064
					'meta' => array(
1065
							'title' => __('Registrations', 'event_espresso'),
1066
							'target' => '',
1067
							'class' => $menu_class
1068
					),
1069
			));
1070
		}
1071
1072
		//Registration Overview Today
1073 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today' ) ) {
1074
			$admin_bar->add_menu(array(
1075
					'id' => 'espresso-toolbar-registrations-today',
1076
					'parent' => 'espresso-toolbar-registrations',
1077
					'title' => __( 'Today', 'event_espresso'),
1078
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $reg_admin_url ),
1079
					'meta' => array(
1080
							'title' => __('Today', 'event_espresso'),
1081
							'target' => '',
1082
							'class' => $menu_class
1083
					),
1084
			));
1085
		}
1086
1087
		//Registration Overview Today Completed
1088 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' ) ) {
1089
			$admin_bar->add_menu(array(
1090
					'id' => 'espresso-toolbar-registrations-today-approved',
1091
					'parent' => 'espresso-toolbar-registrations-today',
1092
					'title' => __( 'Approved', 'event_espresso' ),
1093
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ),
1094
					'meta' => array(
1095
							'title' => __('Approved', 'event_espresso' ),
1096
							'target' => '',
1097
							'class' => $menu_class
1098
					),
1099
			));
1100
		}
1101
1102
		//Registration Overview Today Pending\
1103 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' ) ) {
1104
			$admin_bar->add_menu(array(
1105
					'id' => 'espresso-toolbar-registrations-today-pending',
1106
					'parent' => 'espresso-toolbar-registrations-today',
1107
					'title' => __( 'Pending', 'event_espresso' ),
1108
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', 'reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ),
1109
					'meta' => array(
1110
							'title' => __('Pending Payment', 'event_espresso' ),
1111
							'target' => '',
1112
							'class' => $menu_class
1113
					),
1114
			));
1115
		}
1116
1117
		//Registration Overview Today Incomplete
1118 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' ) ) {
1119
			$admin_bar->add_menu(array(
1120
					'id' => 'espresso-toolbar-registrations-today-not-approved',
1121
					'parent' => 'espresso-toolbar-registrations-today',
1122
					'title' => __( 'Not Approved', 'event_espresso' ),
1123
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ),
1124
					'meta' => array(
1125
							'title' => __('Not Approved', 'event_espresso' ),
1126
							'target' => '',
1127
							'class' => $menu_class
1128
					),
1129
			));
1130
		}
1131
1132
		//Registration Overview Today Incomplete
1133 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' ) ) {
1134
			$admin_bar->add_menu(array(
1135
					'id' => 'espresso-toolbar-registrations-today-cancelled',
1136
					'parent' => 'espresso-toolbar-registrations-today',
1137
					'title' => __( 'Cancelled', 'event_espresso'),
1138
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ),
1139
					'meta' => array(
1140
							'title' => __('Cancelled', 'event_espresso'),
1141
							'target' => '',
1142
							'class' => $menu_class
1143
					),
1144
			));
1145
		}
1146
1147
		//Registration Overview This Month
1148 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month' ) ) {
1149
			$admin_bar->add_menu(array(
1150
					'id' => 'espresso-toolbar-registrations-month',
1151
					'parent' => 'espresso-toolbar-registrations',
1152
					'title' => __( 'This Month', 'event_espresso' ),
1153
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $reg_admin_url ),
1154
					'meta' => array(
1155
							'title' => __('This Month', 'event_espresso'),
1156
							'target' => '',
1157
							'class' => $menu_class
1158
					),
1159
			));
1160
		}
1161
1162
		//Registration Overview This Month Approved
1163 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' ) ) {
1164
			$admin_bar->add_menu(array(
1165
					'id' => 'espresso-toolbar-registrations-month-approved',
1166
					'parent' => 'espresso-toolbar-registrations-month',
1167
					'title' => __( 'Approved', 'event_espresso' ),
1168
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ),
1169
					'meta' => array(
1170
							'title' => __('Approved', 'event_espresso'),
1171
							'target' => '',
1172
							'class' => $menu_class
1173
					),
1174
			));
1175
		}
1176
1177
		//Registration Overview This Month Pending
1178 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' ) ) {
1179
			$admin_bar->add_menu(array(
1180
					'id' => 'espresso-toolbar-registrations-month-pending',
1181
					'parent' => 'espresso-toolbar-registrations-month',
1182
					'title' => __( 'Pending', 'event_espresso'),
1183
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ),
1184
					'meta' => array(
1185
							'title' => __('Pending', 'event_espresso'),
1186
							'target' => '',
1187
							'class' => $menu_class
1188
					),
1189
			));
1190
		}
1191
1192
		//Registration Overview This Month Not Approved
1193 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' ) ) {
1194
			$admin_bar->add_menu(array(
1195
					'id' => 'espresso-toolbar-registrations-month-not-approved',
1196
					'parent' => 'espresso-toolbar-registrations-month',
1197
					'title' => __( 'Not Approved', 'event_espresso'),
1198
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ),
1199
					'meta' => array(
1200
							'title' => __('Not Approved', 'event_espresso' ),
1201
							'target' => '',
1202
							'class' => $menu_class
1203
					),
1204
			));
1205
		}
1206
1207
1208
		//Registration Overview This Month Cancelled
1209 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' ) ) {
1210
			$admin_bar->add_menu(array(
1211
					'id' => 'espresso-toolbar-registrations-month-cancelled',
1212
					'parent' => 'espresso-toolbar-registrations-month',
1213
					'title' => __('Cancelled', 'event_espresso'),
1214
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ),
1215
					'meta' => array(
1216
							'title' => __('Cancelled', 'event_espresso'),
1217
							'target' => '',
1218
							'class' => $menu_class
1219
					),
1220
			));
1221
		}
1222
1223
		//Extensions & Services
1224 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' ) ) {
1225
			$admin_bar->add_menu(array(
1226
					'id' => 'espresso-toolbar-extensions-and-services',
1227
					'parent' => 'espresso-toolbar',
1228
					'title' => __( 'Extensions & Services', 'event_espresso' ),
1229
					'href' => $extensions_admin_url,
1230
					'meta' => array(
1231
							'title' => __('Extensions & Services', 'event_espresso'),
1232
							'target' => '',
1233
							'class' => $menu_class
1234
					),
1235
			));
1236
		}
1237
	}
1238
1239
1240
1241
1242
1243
	/**
1244
	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are never returned with the function.
1245
	 *
1246
	 *
1247
	 * @param  array  $exclude_array any existing pages being excluded are in this array.
1248
	 * @return array
1249
	 */
1250
	public function remove_pages_from_wp_list_pages( $exclude_array ) {
1251
		return  array_merge( $exclude_array, $this->registry->CFG->core->get_critical_pages_array() );
1252
	}
1253
1254
1255
1256
1257
1258
1259
	/*********************************************** 		WP_ENQUEUE_SCRIPTS HOOK		 ***********************************************/
1260
1261
1262
1263
	/**
1264
	 * 	wp_enqueue_scripts
1265
	 *
1266
	 *  	@access 	public
1267
	 *  	@return 	void
1268
	 */
1269
	public function wp_enqueue_scripts() {
1270
		// unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' );
1271 View Code Duplication
		if ( apply_filters( 'FHEE_load_EE_System_scripts', TRUE ) ) {
1272
			// jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
1273
			if ( apply_filters( 'FHEE_load_jquery_validate', FALSE ) ) {
1274
				// register jQuery Validate and additional methods
1275
				wp_register_script( 'jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', array('jquery' ), '1.15.0', TRUE );
1276
				wp_register_script( 'jquery-validate-extra-methods', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', array( 'jquery', 'jquery-validate' ), '1.15.0', TRUE );
1277
			}
1278
			wp_register_script( 'select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true );
1279
			wp_register_style( 'select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all' );
1280
		}
1281
	}
1282
1283
1284
1285
}
1286
// End of file EE_System.core.php
1287
// Location: /core/EE_System.core.php
1288