Completed
Branch BETA-4.9-message-activity (574755)
by
unknown
31:18 queued 14:02
created

EE_System::load_controllers()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 8.8571
cc 5
eloc 11
nc 4
nop 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
		if( $request_type != EE_System::req_type_normal){
236
			$this->registry->load_helper('Activation');
237
		}
238
239
		switch($request_type){
240
			case EE_System::req_type_new_activation:
241
				do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__new_activation' );
242
				$this->_handle_core_version_change( $espresso_db_update );
243
				break;
244
			case EE_System::req_type_reactivation:
245
				do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__reactivation' );
246
				$this->_handle_core_version_change( $espresso_db_update );
247
				break;
248
			case EE_System::req_type_upgrade:
249
				do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__upgrade' );
250
				//migrations may be required now that we've upgraded
251
				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
252
				$this->_handle_core_version_change( $espresso_db_update );
253
//				echo "done upgrade";die;
254
				break;
255
			case EE_System::req_type_downgrade:
256
				do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__downgrade' );
257
				//its possible migrations are no longer required
258
				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
259
				$this->_handle_core_version_change( $espresso_db_update );
260
				break;
261
			case EE_System::req_type_normal:
262
			default:
263
//				$this->_maybe_redirect_to_ee_about();
264
				break;
265
		}
266
		do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__complete' );
267
	}
268
269
	/**
270
	 * Updates the list of installed versions and sets hooks for
271
	 * initializing the database later during the request
272
	 * @param array $espresso_db_update
273
	 */
274
	protected function _handle_core_version_change( $espresso_db_update ){
275
		$this->update_list_of_installed_versions( $espresso_db_update );
276
		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
277
		add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ));
278
	}
279
280
281
282
283
	/**
284
	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
285
	 * information about what versions of EE have been installed and activated,
286
	 * NOT necessarily the state of the database
287
	 *
288
	 * @param null $espresso_db_update
289
	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it from the options table
290
	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
291
	 */
292
	private function fix_espresso_db_upgrade_option($espresso_db_update = null){
293
		do_action( 'FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update );
294
		if( ! $espresso_db_update){
295
			$espresso_db_update = get_option( 'espresso_db_update' );
296
		}
297
		// check that option is an array
298
		if( ! is_array( $espresso_db_update )) {
299
			// if option is FALSE, then it never existed
300
			if ( $espresso_db_update === FALSE ) {
301
				// make $espresso_db_update an array and save option with autoload OFF
302
				$espresso_db_update =  array();
303
				add_option( 'espresso_db_update', $espresso_db_update, '', 'no' );
304
			} else {
305
				// option is NOT FALSE but also is NOT an array, so make it an array and save it
306
				$espresso_db_update =  array( $espresso_db_update=>array() );
307
				update_option( 'espresso_db_update', $espresso_db_update );
308
			}
309
		}else{
310
			$corrected_db_update = array();
311
			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
312
			foreach($espresso_db_update as $should_be_version_string => $should_be_array){
313
				if(is_int($should_be_version_string) && ! is_array($should_be_array)){
314
					//the key is an int, and the value IS NOT an array
315
					//so it must be numerically-indexed, where values are versions installed...
316
					//fix it!
317
					$version_string = $should_be_array;
318
					$corrected_db_update[$version_string] = array('unknown-date');
319
				}else{
320
					//ok it checks out
321
					$corrected_db_update[$should_be_version_string] = $should_be_array;
322
				}
323
			}
324
			$espresso_db_update = $corrected_db_update;
325
			update_option( 'espresso_db_update', $espresso_db_update );
326
327
		}
328
329
		do_action( 'FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update );
330
		return $espresso_db_update;
331
	}
332
333
334
335
336
	/**
337
	 * Does the traditional work of setting up the plugin's database and adding default data.
338
	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
339
	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
340
	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
341
	 * so that it will be done when migrations are finished
342
	 *
343
	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
344
	 * @param boolean $verify_schema if true will re-check the database tables have the correct schema.
345
	 *                               This is a resource-intensive job
346
	 * so we prefer to only do it when necessary
347
	 * @return void
348
	 */
349
	public function initialize_db_if_no_migrations_required( $initialize_addons_too = FALSE, $verify_schema = true ){
350
		$request_type = $this->detect_req_type();
351
		//only initialize system if we're not in maintenance mode.
352
		if( EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance ){
353
			update_option( 'ee_flush_rewrite_rules', TRUE );
354
355
			if( $verify_schema ) {
356
				EEH_Activation::initialize_db_and_folders();
357
			}
358
			EEH_Activation::initialize_db_content();
359
			EEH_Activation::system_initialization();
360
			if( $initialize_addons_too ) {
361
				$this->initialize_addons();
362
			}
363
		}else{
364
			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for( 'Core' );
365
		}
366
		if ( $request_type == EE_System::req_type_new_activation || $request_type == EE_System::req_type_reactivation || $request_type == EE_System::req_type_upgrade ) {
367
			add_action( 'AHEE__EE_System__load_CPTs_and_session__start', array( $this, 'redirect_to_about_ee' ), 9 );
368
		}
369
	}
370
371
	/**
372
	 * Initializes the db for all registered addons
373
	 */
374
	public function initialize_addons(){
375
		//foreach registered addon, make sure its db is up-to-date too
376
		foreach($this->registry->addons as $addon){
377
			$addon->initialize_db_if_no_migrations_required();
378
		}
379
	}
380
381
382
	/**
383
	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
384
	 * @param 	array 	$version_history
385
	 * @param 	string 	$current_version_to_add 	version to be added to the version history
386
	 * @return 	boolean success as to whether or not this option was changed
387
	 */
388
	public function update_list_of_installed_versions($version_history = NULL,$current_version_to_add = NULL) {
389
		if( ! $version_history ) {
390
			$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 390 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...
391
		}
392
		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...
393
			$current_version_to_add = espresso_version();
394
		}
395
		$version_history[ $current_version_to_add ][] = date( 'Y-m-d H:i:s',time() );
396
		// re-save
397
		return update_option( 'espresso_db_update', $version_history );
398
	}
399
400
401
402
403
	/**
404
	 * Detects if the current version indicated in the has existed in the list of
405
	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
406
	 *
407
	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
408
	 *                            If not supplied, fetches it from the options table.
409
	 *                            Also, caches its result so later parts of the code can also know whether there's been an
410
	 *                            update or not. This way we can add the current version to espresso_db_update,
411
	 *                            but still know if this is a new install or not
412
	 * @return int one of the constants on EE_System::req_type_
413
	 */
414
	public function detect_req_type( $espresso_db_update = NULL ){
415
		if ( $this->_req_type === NULL ){
416
			$espresso_db_update = ! empty( $espresso_db_update ) ? $espresso_db_update : $this->fix_espresso_db_upgrade_option();
417
			$this->_req_type = $this->detect_req_type_given_activation_history( $espresso_db_update, 'ee_espresso_activation', espresso_version() );
418
		}
419
		return $this->_req_type;
420
	}
421
422
423
424
	/**
425
	 * 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
426
	 * was just activated to (for core that will always be espresso_version())
427
	 * @param array $activation_history_for_addon the option's value which stores the activation history for this ee plugin.
428
	 * for core that's 'espresso_db_update'
429
	 * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to indicate that this plugin was just activated
430
	 * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be espresso_version())
431
	 * @return int one of the constants on EE_System::req_type_*
432
	 */
433
	public static function detect_req_type_given_activation_history( $activation_history_for_addon, $activation_indicator_option_name, $version_to_upgrade_to ){
434
		$version_is_higher = self::_new_version_is_higher( $activation_history_for_addon, $version_to_upgrade_to );
435
		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...
436
			//it exists, so this isn't a completely new install
437
			//check if this version already in that list of previously installed versions
438
			if ( ! isset( $activation_history_for_addon[ $version_to_upgrade_to ] )) {
439
				//it a version we haven't seen before
440
				if( $version_is_higher === 1 ){
441
					$req_type = EE_System::req_type_upgrade;
442
				}else{
443
					$req_type = EE_System::req_type_downgrade;
444
				}
445
				delete_option( $activation_indicator_option_name );
446
			} else {
447
				// its not an update. maybe a reactivation?
448
				if( get_option( $activation_indicator_option_name, FALSE ) ){
449 View Code Duplication
					if ( $version_is_higher === -1 ){
450
						$req_type = EE_System::req_type_downgrade;
451
					}elseif( $version_is_higher === 0 ){
452
						//we've seen this version before, but it's an activation. must be a reactivation
453
						$req_type = EE_System::req_type_reactivation;
454
					}else{//$version_is_higher === 1
455
						$req_type = EE_System::req_type_upgrade;
456
					}
457
					delete_option( $activation_indicator_option_name );
458 View Code Duplication
				} else {
459
					//we've seen this version before and the activation indicate doesn't show it was just activated
460
					if ( $version_is_higher === -1 ){
461
						$req_type = EE_System::req_type_downgrade;
462
					}elseif( $version_is_higher === 0 ){
463
						//we've seen this version before and it's not an activation. its normal request
464
						$req_type = EE_System::req_type_normal;
465
					}else{//$version_is_higher === 1
466
						$req_type = EE_System::req_type_upgrade;
467
					}
468
				}
469
			}
470
		} else {
471
			//brand new install
472
			$req_type = EE_System::req_type_new_activation;
473
			delete_option( $activation_indicator_option_name );
474
		}
475
		return $req_type;
476
	}
477
478
479
480
	/**
481
	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
482
	 * the $activation_history_for_addon
483
	 * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated,
484
	 * sometimes containing 'unknown-date'
485
	 * @param string $version_to_upgrade_to (current version)
486
	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
487
	 *	ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
488
	 *		0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
489
	 *		1 if $version_to_upgrade_to is HIGHER (upgrade) ;
490
	 */
491
	protected static function _new_version_is_higher( $activation_history_for_addon, $version_to_upgrade_to ){
492
		//find the most recently-activated version
493
		$most_recently_active_version_activation = '1970-01-01 00:00:00';
494
		$most_recently_active_version = '0.0.0.dev.000';
495
		if( is_array( $activation_history_for_addon ) ){
496
			foreach( $activation_history_for_addon as $version => $times_activated ){
497
				//check there is a record of when this version was activated. Otherwise,
498
				//mark it as unknown
499
				if( ! $times_activated ){
500
					$times_activated = array( 'unknown-date');
501
				}
502
				if( is_string( $times_activated ) ){
503
					$times_activated = array( $times_activated );
504
				}
505
				foreach( $times_activated as $an_activation ){
506
					if( $an_activation != 'unknown-date' &&
507
							$an_activation > $most_recently_active_version_activation  ){
508
						$most_recently_active_version = $version;
509
						$most_recently_active_version_activation = $an_activation == 'unknown-date' ? '1970-01-01 00:00:00' : $an_activation;
510
					}
511
				}
512
			}
513
		}
514
		return version_compare( $version_to_upgrade_to, $most_recently_active_version );
515
	}
516
517
518
519
	/**
520
	 * This redirects to the about EE page after activation
521
	 * @return void
522
	 */
523
	public function redirect_to_about_ee() {
524
		$notices = EE_Error::get_notices( FALSE );
525
		//if current user is an admin and it's not an ajax request
526
		if (
527
			$this->registry->CAP->current_user_can( 'manage_options', 'espresso_about_default' )
528
			&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
529
			&& ! isset( $notices[ 'errors' ] )
530
		) {
531
			$query_params =  array( 'page' => 'espresso_about' );
532
533
			if ( EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation ) {
534
			    $query_params['new_activation'] = TRUE;
535
			}
536
537
			if ( EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation ) {
538
			    $query_params['reactivation'] = TRUE;
539
			}
540
			$url = add_query_arg( $query_params, admin_url( 'admin.php' ) );
541
			wp_safe_redirect( $url );
542
			exit();
543
		}
544
	}
545
546
547
	/**
548
	 * load_core_configuration
549
	 *
550
	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
551
	 * which runs during the WP 'plugins_loaded' action at priority 5
552
	 *
553
	 * @return void
554
	 */
555
	public function load_core_configuration(){
556
		do_action( 'AHEE__EE_System__load_core_configuration__begin', $this );
557
		$this->registry->load_core( 'EE_Load_Textdomain' );
558
		//load textdomain
559
		EE_Load_Textdomain::load_textdomain();
560
		// load and setup EE_Config and EE_Network_Config
561
		$this->registry->load_core( 'Config' );
562
		$this->registry->load_core( 'Network_Config' );
563
		// setup autoloaders
564
		// enable logging?
565
		if ( $this->registry->CFG->admin->use_full_logging ) {
566
			$this->registry->load_core( 'Log' );
567
		}
568
		// check for activation errors
569
		$activation_errors = get_option( 'ee_plugin_activation_errors', FALSE );
570
		if ( $activation_errors ) {
571
			EE_Error::add_error( $activation_errors, __FILE__, __FUNCTION__, __LINE__ );
572
			update_option( 'ee_plugin_activation_errors', FALSE );
573
		}
574
		// get model names
575
		$this->_parse_model_names();
576
577
		//load caf stuff a chance to play during the activation process too.
578
		$this->_maybe_brew_regular();
579
		do_action( 'AHEE__EE_System__load_core_configuration__complete', $this );
580
	}
581
582
583
	/**
584
	 * cycles through all of the models/*.model.php files, and assembles an array of model names
585
	 *
586
	 * @return void
587
	 */
588
	private function _parse_model_names(){
589
		//get all the files in the EE_MODELS folder that end in .model.php
590
		$models = glob( EE_MODELS.'*.model.php');
591
		$model_names = array();
592
		$non_abstract_db_models = array();
593
		foreach( $models as $model ){
594
			// get model classname
595
			$classname = EEH_File::get_classname_from_filepath_with_standard_filename( $model );
596
			$short_name = str_replace( 'EEM_', '', $classname );
597
			$reflectionClass = new ReflectionClass($classname);
598
			if( $reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()){
599
				$non_abstract_db_models[ $short_name ] = $classname;
600
			}
601
			$model_names[ $short_name ] = $classname;
602
		}
603
		$this->registry->models = apply_filters( 'FHEE__EE_System__parse_model_names', $model_names );
604
		$this->registry->non_abstract_db_models = apply_filters( 'FHEE__EE_System__parse_implemented_model_names', $non_abstract_db_models );
605
	}
606
607
608
609
	/**
610
	 * 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.
611
	 * @return void
612
	 */
613
	private function _maybe_brew_regular() {
614
		if (( ! defined( 'EE_DECAF' ) ||  EE_DECAF !== TRUE ) && is_readable( EE_CAFF_PATH . 'brewing_regular.php' )) {
615
			require_once EE_CAFF_PATH . 'brewing_regular.php';
616
		}
617
	}
618
619
620
621
	/**
622
	 * register_shortcodes_modules_and_widgets
623
	 *
624
	 * generate lists of shortcodes and modules, then verify paths and classes
625
	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
626
	 * which runs during the WP 'plugins_loaded' action at priority 7
627
	 *
628
	 * @access public
629
	 * @return void
630
	 */
631
	public function register_shortcodes_modules_and_widgets() {
632
		do_action( 'AHEE__EE_System__register_shortcodes_modules_and_widgets' );
633
		// check for addons using old hookpoint
634
		if ( has_action( 'AHEE__EE_System__register_shortcodes_modules_and_addons' )) {
635
			$this->_incompatible_addon_error();
636
		}
637
	}
638
639
640
	/**
641
	* _incompatible_addon_error
642
	*
643
	* @access public
644
	* @return void
645
	*/
646
	private function _incompatible_addon_error() {
647
		// get array of classes hooking into here
648
		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( 'AHEE__EE_System__register_shortcodes_modules_and_addons' );
649
		if ( ! empty( $class_names )) {
650
			$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' );
651
			$msg .= '<ul>';
652
			foreach ( $class_names as $class_name ) {
653
				$msg .= '<li><b>Event Espresso - ' . str_replace( array( 'EE_', 'EEM_', 'EED_', 'EES_', 'EEW_' ), '', $class_name ) . '</b></li>';
654
			}
655
			$msg .= '</ul>';
656
			$msg .= __( 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', 'event_espresso' );
657
			// save list of incompatible addons to wp-options for later use
658
			add_option( 'ee_incompatible_addons', $class_names, '', 'no' );
659
			if ( is_admin() ) {
660
				EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
661
			}
662
		}
663
	}
664
665
666
667
668
	/**
669
	 * brew_espresso
670
	 *
671
	 * begins the process of setting hooks for initializing EE in the correct order
672
	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
673
	 * which runs during the WP 'plugins_loaded' action at priority 9
674
	 *
675
	 * @return void
676
	 */
677
	public function brew_espresso(){
678
		do_action( 'AHEE__EE_System__brew_espresso__begin', $this );
679
		// load some final core systems
680
		add_action( 'init', array( $this, 'set_hooks_for_core' ), 1 );
681
		add_action( 'init', array( $this, 'perform_activations_upgrades_and_migrations' ), 3 );
682
		add_action( 'init', array( $this, 'load_CPTs_and_session' ), 5 );
683
		add_action( 'init', array( $this, 'load_controllers' ), 7 );
684
		add_action( 'init', array( $this, 'core_loaded_and_ready' ), 9 );
685
		add_action( 'init', array( $this, 'initialize' ), 10 );
686
		add_action( 'init', array( $this, 'initialize_last' ), 100 );
687
		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 25 );
688
		add_action( 'admin_bar_menu', array( $this, 'espresso_toolbar_items' ), 100 );
689
690
		if ( is_admin() && apply_filters( 'FHEE__EE_System__brew_espresso__load_pue', TRUE )  ) {
691
			// pew pew pew
692
			$this->registry->load_core( 'PUE' );
693
			do_action( 'AHEE__EE_System__brew_espresso__after_pue_init' );
694
		}
695
		do_action( 'AHEE__EE_System__brew_espresso__complete', $this );
696
	}
697
698
699
700
701
	/**
702
	 * 	set_hooks_for_core
703
	 *
704
	 *  	@access public
705
	 *  	@return 	void
706
	 */
707
	public function set_hooks_for_core() {
708
		$this->_deactivate_incompatible_addons();
709
		do_action( 'AHEE__EE_System__set_hooks_for_core' );
710
	}
711
712
713
714
	/**
715
	 * Using the information gathered in EE_System::_incompatible_addon_error,
716
	 * deactivates any addons considered incompatible with the current version of EE
717
	 */
718
	private function _deactivate_incompatible_addons(){
719
		$incompatible_addons = get_option( 'ee_incompatible_addons', array() );
720
		if ( ! empty( $incompatible_addons )) {
721
			$active_plugins = get_option( 'active_plugins', array() );
722
			foreach ( $active_plugins as $active_plugin ) {
723
				foreach ( $incompatible_addons as $incompatible_addon ) {
724
					if ( strpos( $active_plugin,  $incompatible_addon ) !== FALSE ) {
725
						unset( $_GET['activate'] );
726
						espresso_deactivate_plugin( $active_plugin );
727
					}
728
				}
729
			}
730
		}
731
	}
732
733
734
735
	/**
736
	 * 	perform_activations_upgrades_and_migrations
737
	 *
738
	 *  	@access public
739
	 *  	@return 	void
740
	 */
741
	public function perform_activations_upgrades_and_migrations() {
742
		//first check if we had previously attempted to setup EE's directories but failed
743
		if( EEH_Activation::upload_directories_incomplete() ) {
744
			EEH_Activation::create_upload_directories();
745
		}
746
		do_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations' );
747
	}
748
749
750
751
	/**
752
	 * 	load_CPTs_and_session
753
	 *
754
	 *  	@access public
755
	 *  	@return 	void
756
	 */
757
	public function load_CPTs_and_session() {
758
		do_action( 'AHEE__EE_System__load_CPTs_and_session__start' );
759
		// register Custom Post Types
760
		$this->registry->load_core( 'Register_CPTs' );
761
		do_action( 'AHEE__EE_System__load_CPTs_and_session__complete' );
762
	}
763
764
765
766
	/**
767
	* load_controllers
768
	*
769
	* this is the best place to load any additional controllers that needs access to EE core.
770
	* it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this time
771
	*
772
	* @access public
773
	* @return void
774
	*/
775
	public function load_controllers() {
776
		do_action( 'AHEE__EE_System__load_controllers__start' );
777
		// let's get it started
778
		if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level() ) {
779
			do_action( 'AHEE__EE_System__load_controllers__load_front_controllers' );
780
			$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...
781
		} else if ( ! EE_FRONT_AJAX ) {
782
			do_action( 'AHEE__EE_System__load_controllers__load_admin_controllers' );
783
			EE_Registry::instance()->load_core( 'Admin' );
784
		} else if ( EE_Maintenance_Mode::instance()->level() ) {
785
			// still need to make sure template helper functions are loaded in M-Mode
786
			$this->registry->load_helper( 'Template' );
787
		}
788
		do_action( 'AHEE__EE_System__load_controllers__complete' );
789
	}
790
791
792
793
	/**
794
	* core_loaded_and_ready
795
	*
796
	* all of the basic EE core should be loaded at this point and available regardless of M-Mode
797
	*
798
	* @access public
799
	* @return void
800
	*/
801
	public function core_loaded_and_ready() {
802
		do_action( 'AHEE__EE_System__core_loaded_and_ready' );
803
		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
804
		$this->registry->load_core( 'Session' );
805
		//		add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 );
806
	}
807
808
809
810
	/**
811
	* initialize
812
	*
813
	* this is the best place to begin initializing client code
814
	*
815
	* @access public
816
	* @return void
817
	*/
818
	public function initialize() {
819
		do_action( 'AHEE__EE_System__initialize' );
820
	}
821
822
823
824
	/**
825
	* initialize_last
826
	*
827
	* this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to initialize has done so
828
	*
829
	* @access public
830
	* @return void
831
	*/
832
	public function initialize_last() {
833
		do_action( 'AHEE__EE_System__initialize_last' );
834
	}
835
836
837
838
839
	/**
840
	* set_hooks_for_shortcodes_modules_and_addons
841
	*
842
	* this is the best place for other systems to set callbacks for hooking into other parts of EE
843
	* this happens at the very beginning of the wp_loaded hookpoint
844
	*
845
	* @access public
846
	* @return void
847
	*/
848
	public function set_hooks_for_shortcodes_modules_and_addons() {
849
//		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
850
	}
851
852
853
854
855
	/**
856
	* do_not_cache
857
	*
858
	* sets no cache headers and defines no cache constants for WP plugins
859
	*
860
	* @access public
861
	* @return void
862
	*/
863
	public static function do_not_cache() {
864
		// set no cache constants
865
		if ( ! defined( 'DONOTCACHEPAGE' ) ) {
866
			define( 'DONOTCACHEPAGE', true );
867
		}
868
		if ( ! defined( 'DONOTCACHCEOBJECT' ) ) {
869
			define( 'DONOTCACHCEOBJECT', true );
870
		}
871
		if ( ! defined( 'DONOTCACHEDB' ) ) {
872
			define( 'DONOTCACHEDB', true );
873
		}
874
		// add no cache headers
875
		add_action( 'send_headers' , array( 'EE_System', 'nocache_headers' ), 10 );
876
		// plus a little extra for nginx and Google Chrome
877
		add_filter( 'nocache_headers', array( 'EE_System', 'extra_nocache_headers' ), 10, 1 );
878
		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
879
		remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
880
	}
881
882
883
884
	/**
885
	 *    extra_nocache_headers
886
	 *
887
	 * @access    public
888
	 * @param $headers
889
	 * @return    array
890
	 */
891
	public static function extra_nocache_headers ( $headers ) {
892
		// for NGINX
893
		$headers['X-Accel-Expires'] = 0;
894
		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
895
		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
896
		return $headers;
897
	}
898
899
900
901
	/**
902
	 * 	nocache_headers
903
	 *
904
	 *  @access 	public
905
	 *  @return 	void
906
	 */
907
	public static function nocache_headers() {
908
		nocache_headers();
909
	}
910
911
912
913
	/**
914
	 *    espresso_toolbar_items
915
	 *
916
	 * @access public
917
	 * @param  WP_Admin_Bar $admin_bar
918
	 * @return void
919
	 */
920
	public function espresso_toolbar_items( WP_Admin_Bar $admin_bar ) {
921
922
		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
923
		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' )) {
924
			return;
925
		}
926
927
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
928
		$this->registry->load_helper( 'URL' );
929
		$menu_class = 'espresso_menu_item_class';
930
		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
931
		//because they're only defined in each of their respective constructors
932
		//and this might be a frontend request, in which case they aren't available
933
		$events_admin_url = admin_url("admin.php?page=espresso_events");
934
		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
935
		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
936
937
		//Top Level
938
		$admin_bar->add_menu(array(
939
				'id' => 'espresso-toolbar',
940
				'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>',
941
				'href' => $events_admin_url,
942
				'meta' => array(
943
						'title' => __('Event Espresso', 'event_espresso'),
944
						'class' => $menu_class . 'first'
945
				),
946
		));
947
948
		//Events
949 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events' ) ) {
950
			$admin_bar->add_menu(array(
951
					'id' => 'espresso-toolbar-events',
952
					'parent' => 'espresso-toolbar',
953
					'title' => __( 'Events', 'event_espresso' ),
954
					'href' => $events_admin_url,
955
					'meta' => array(
956
							'title' => __('Events', 'event_espresso'),
957
							'target' => '',
958
							'class' => $menu_class
959
					),
960
			));
961
		}
962
963
964
		if ( $this->registry->CAP->current_user_can( 'ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new' ) ) {
965
			//Events Add New
966
			$admin_bar->add_menu(array(
967
					'id' => 'espresso-toolbar-events-new',
968
					'parent' => 'espresso-toolbar-events',
969
					'title' => __('Add New', 'event_espresso'),
970
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'create_new' ), $events_admin_url ),
971
					'meta' => array(
972
							'title' => __('Add New', 'event_espresso'),
973
							'target' => '',
974
							'class' => $menu_class
975
					),
976
			));
977
		}
978
979
		if ( is_single() && ( get_post_type() == 'espresso_events' ) ) {
980
981
			//Current post
982
			global $post;
983
984
	    	if ( $this->registry->CAP->current_user_can( 'ee_edit_event', 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID ) ) {
985
				//Events Edit Current Event
986
				$admin_bar->add_menu(array(
987
						'id' => 'espresso-toolbar-events-edit',
988
						'parent' => 'espresso-toolbar-events',
989
						'title' => __('Edit Event', 'event_espresso'),
990
						'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'edit', 'post'=>$post->ID ), $events_admin_url ),
991
						'meta' => array(
992
								'title' => __('Edit Event', 'event_espresso'),
993
								'target' => '',
994
								'class' => $menu_class
995
						),
996
				));
997
			}
998
999
		}
1000
1001
		//Events View
1002 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-view' ) ) {
1003
			$admin_bar->add_menu(array(
1004
					'id' => 'espresso-toolbar-events-view',
1005
					'parent' => 'espresso-toolbar-events',
1006
					'title' => __( 'View', 'event_espresso' ),
1007
					'href' => $events_admin_url,
1008
					'meta' => array(
1009
							'title' => __('View', 'event_espresso'),
1010
							'target' => '',
1011
							'class' => $menu_class
1012
					),
1013
			));
1014
		}
1015
1016 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all' ) ) {
1017
			//Events View All
1018
			$admin_bar->add_menu(array(
1019
					'id' => 'espresso-toolbar-events-all',
1020
					'parent' => 'espresso-toolbar-events-view',
1021
					'title' => __( 'All', 'event_espresso' ),
1022
					'href' => $events_admin_url,
1023
					'meta' => array(
1024
							'title' => __('All', 'event_espresso'),
1025
							'target' => '',
1026
							'class' => $menu_class
1027
					),
1028
			));
1029
		}
1030
1031
1032 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-today' ) ) {
1033
			//Events View Today
1034
			$admin_bar->add_menu(array(
1035
					'id' => 'espresso-toolbar-events-today',
1036
					'parent' => 'espresso-toolbar-events-view',
1037
					'title' => __('Today', 'event_espresso'),
1038
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $events_admin_url ),
1039
					'meta' => array(
1040
							'title' => __('Today', 'event_espresso'),
1041
							'target' => '',
1042
							'class' => $menu_class
1043
					),
1044
			));
1045
		}
1046
1047
1048 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-month' ) ) {
1049
			//Events View This Month
1050
			$admin_bar->add_menu(array(
1051
					'id' => 'espresso-toolbar-events-month',
1052
					'parent' => 'espresso-toolbar-events-view',
1053
					'title' => __( 'This Month', 'event_espresso'),
1054
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $events_admin_url ),
1055
					'meta' => array(
1056
							'title' => __('This Month', 'event_espresso'),
1057
							'target' => '',
1058
							'class' => $menu_class
1059
					),
1060
			));
1061
		}
1062
1063
		//Registration Overview
1064 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations' ) ) {
1065
			$admin_bar->add_menu(array(
1066
					'id' => 'espresso-toolbar-registrations',
1067
					'parent' => 'espresso-toolbar',
1068
					'title' => __( 'Registrations', 'event_espresso' ),
1069
					'href' => $reg_admin_url,
1070
					'meta' => array(
1071
							'title' => __('Registrations', 'event_espresso'),
1072
							'target' => '',
1073
							'class' => $menu_class
1074
					),
1075
			));
1076
		}
1077
1078
		//Registration Overview Today
1079 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today' ) ) {
1080
			$admin_bar->add_menu(array(
1081
					'id' => 'espresso-toolbar-registrations-today',
1082
					'parent' => 'espresso-toolbar-registrations',
1083
					'title' => __( 'Today', 'event_espresso'),
1084
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $reg_admin_url ),
1085
					'meta' => array(
1086
							'title' => __('Today', 'event_espresso'),
1087
							'target' => '',
1088
							'class' => $menu_class
1089
					),
1090
			));
1091
		}
1092
1093
		//Registration Overview Today Completed
1094 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' ) ) {
1095
			$admin_bar->add_menu(array(
1096
					'id' => 'espresso-toolbar-registrations-today-approved',
1097
					'parent' => 'espresso-toolbar-registrations-today',
1098
					'title' => __( 'Approved', 'event_espresso' ),
1099
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ),
1100
					'meta' => array(
1101
							'title' => __('Approved', 'event_espresso' ),
1102
							'target' => '',
1103
							'class' => $menu_class
1104
					),
1105
			));
1106
		}
1107
1108
		//Registration Overview Today Pending\
1109 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' ) ) {
1110
			$admin_bar->add_menu(array(
1111
					'id' => 'espresso-toolbar-registrations-today-pending',
1112
					'parent' => 'espresso-toolbar-registrations-today',
1113
					'title' => __( 'Pending', 'event_espresso' ),
1114
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', 'reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ),
1115
					'meta' => array(
1116
							'title' => __('Pending Payment', 'event_espresso' ),
1117
							'target' => '',
1118
							'class' => $menu_class
1119
					),
1120
			));
1121
		}
1122
1123
		//Registration Overview Today Incomplete
1124 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' ) ) {
1125
			$admin_bar->add_menu(array(
1126
					'id' => 'espresso-toolbar-registrations-today-not-approved',
1127
					'parent' => 'espresso-toolbar-registrations-today',
1128
					'title' => __( 'Not Approved', 'event_espresso' ),
1129
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ),
1130
					'meta' => array(
1131
							'title' => __('Not Approved', 'event_espresso' ),
1132
							'target' => '',
1133
							'class' => $menu_class
1134
					),
1135
			));
1136
		}
1137
1138
		//Registration Overview Today Incomplete
1139 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' ) ) {
1140
			$admin_bar->add_menu(array(
1141
					'id' => 'espresso-toolbar-registrations-today-cancelled',
1142
					'parent' => 'espresso-toolbar-registrations-today',
1143
					'title' => __( 'Cancelled', 'event_espresso'),
1144
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ),
1145
					'meta' => array(
1146
							'title' => __('Cancelled', 'event_espresso'),
1147
							'target' => '',
1148
							'class' => $menu_class
1149
					),
1150
			));
1151
		}
1152
1153
		//Registration Overview This Month
1154 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month' ) ) {
1155
			$admin_bar->add_menu(array(
1156
					'id' => 'espresso-toolbar-registrations-month',
1157
					'parent' => 'espresso-toolbar-registrations',
1158
					'title' => __( 'This Month', 'event_espresso' ),
1159
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $reg_admin_url ),
1160
					'meta' => array(
1161
							'title' => __('This Month', 'event_espresso'),
1162
							'target' => '',
1163
							'class' => $menu_class
1164
					),
1165
			));
1166
		}
1167
1168
		//Registration Overview This Month Approved
1169 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' ) ) {
1170
			$admin_bar->add_menu(array(
1171
					'id' => 'espresso-toolbar-registrations-month-approved',
1172
					'parent' => 'espresso-toolbar-registrations-month',
1173
					'title' => __( 'Approved', 'event_espresso' ),
1174
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ),
1175
					'meta' => array(
1176
							'title' => __('Approved', 'event_espresso'),
1177
							'target' => '',
1178
							'class' => $menu_class
1179
					),
1180
			));
1181
		}
1182
1183
		//Registration Overview This Month Pending
1184 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' ) ) {
1185
			$admin_bar->add_menu(array(
1186
					'id' => 'espresso-toolbar-registrations-month-pending',
1187
					'parent' => 'espresso-toolbar-registrations-month',
1188
					'title' => __( 'Pending', 'event_espresso'),
1189
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ),
1190
					'meta' => array(
1191
							'title' => __('Pending', 'event_espresso'),
1192
							'target' => '',
1193
							'class' => $menu_class
1194
					),
1195
			));
1196
		}
1197
1198
		//Registration Overview This Month Not Approved
1199 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' ) ) {
1200
			$admin_bar->add_menu(array(
1201
					'id' => 'espresso-toolbar-registrations-month-not-approved',
1202
					'parent' => 'espresso-toolbar-registrations-month',
1203
					'title' => __( 'Not Approved', 'event_espresso'),
1204
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ),
1205
					'meta' => array(
1206
							'title' => __('Not Approved', 'event_espresso' ),
1207
							'target' => '',
1208
							'class' => $menu_class
1209
					),
1210
			));
1211
		}
1212
1213
1214
		//Registration Overview This Month Cancelled
1215 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' ) ) {
1216
			$admin_bar->add_menu(array(
1217
					'id' => 'espresso-toolbar-registrations-month-cancelled',
1218
					'parent' => 'espresso-toolbar-registrations-month',
1219
					'title' => __('Cancelled', 'event_espresso'),
1220
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ),
1221
					'meta' => array(
1222
							'title' => __('Cancelled', 'event_espresso'),
1223
							'target' => '',
1224
							'class' => $menu_class
1225
					),
1226
			));
1227
		}
1228
1229
		//Extensions & Services
1230 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' ) ) {
1231
			$admin_bar->add_menu(array(
1232
					'id' => 'espresso-toolbar-extensions-and-services',
1233
					'parent' => 'espresso-toolbar',
1234
					'title' => __( 'Extensions & Services', 'event_espresso' ),
1235
					'href' => $extensions_admin_url,
1236
					'meta' => array(
1237
							'title' => __('Extensions & Services', 'event_espresso'),
1238
							'target' => '',
1239
							'class' => $menu_class
1240
					),
1241
			));
1242
		}
1243
	}
1244
1245
1246
1247
1248
1249
	/**
1250
	 * 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.
1251
	 *
1252
	 *
1253
	 * @param  array  $exclude_array any existing pages being excluded are in this array.
1254
	 * @return array
1255
	 */
1256
	public function remove_pages_from_wp_list_pages( $exclude_array ) {
1257
		return  array_merge( $exclude_array, $this->registry->CFG->core->get_critical_pages_array() );
1258
	}
1259
1260
1261
1262
1263
1264
1265
	/*********************************************** 		WP_ENQUEUE_SCRIPTS HOOK		 ***********************************************/
1266
1267
1268
1269
	/**
1270
	 * 	wp_enqueue_scripts
1271
	 *
1272
	 *  	@access 	public
1273
	 *  	@return 	void
1274
	 */
1275
	public function wp_enqueue_scripts() {
1276
		// 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' );
1277 View Code Duplication
		if ( apply_filters( 'FHEE_load_EE_System_scripts', TRUE ) ) {
1278
			// 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' );
1279
			if ( apply_filters( 'FHEE_load_jquery_validate', FALSE ) ) {
1280
				// register jQuery Validate
1281
				wp_register_script( 'jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', array('jquery'), '1.15.0', TRUE );
1282
			}
1283
		}
1284
	}
1285
1286
1287
1288
}
1289
// End of file EE_System.core.php
1290
// Location: /core/EE_System.core.php
1291