Completed
Branch FET-9795-new-interfaces (4c886e)
by
unknown
196:07 queued 180:18
created

EE_System::brew_espresso()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 16
nc 2
nop 0
dl 0
loc 21
rs 9.3142
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 implements EventEspresso\core\interfaces\ResettableInterface {
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
107
		//make sure none of the old hooks are left hanging around
108
		remove_all_actions( 'AHEE__EE_System__perform_activations_upgrades_and_migrations' );
109
110
		//we need to reset the migration manager in order for it to detect DMSs properly
111
		EE_Data_Migration_Manager::reset();
112
		self::instance()->detect_activations_or_upgrades();
113
		self::instance()->perform_activations_upgrades_and_migrations();
114
115
		return self::instance();
116
	}
117
118
119
120
	/**
121
	 *    sets hooks for running rest of system
122
	 *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
123
	 *    starting EE Addons from any other point may lead to problems
124
	 *
125
	 * @access private
126
	 * @param  \EE_Registry        $Registry
127
	 */
128
	private function __construct( EE_Registry $Registry ) {
129
		$this->registry = $Registry;
130
		do_action( 'AHEE__EE_System__construct__begin', $this );
131
		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
132
		add_action( 'AHEE__EE_Bootstrap__load_espresso_addons', array( $this, 'load_espresso_addons' ) );
133
		// when an ee addon is activated, we want to call the core hook(s) again
134
		// because the newly-activated addon didn't get a chance to run at all
135
		add_action( 'activate_plugin', array( $this, 'load_espresso_addons' ), 1 );
136
		// detect whether install or upgrade
137
		add_action( 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', array( $this, 'detect_activations_or_upgrades' ), 3 );
138
		// load EE_Config, EE_Textdomain, etc
139
		add_action( 'AHEE__EE_Bootstrap__load_core_configuration', array( $this, 'load_core_configuration' ), 5 );
140
		// load EE_Config, EE_Textdomain, etc
141
		add_action( 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', array( $this, 'register_shortcodes_modules_and_widgets' ), 7 );
142
		// you wanna get going? I wanna get going... let's get going!
143
		add_action( 'AHEE__EE_Bootstrap__brew_espresso', array( $this, 'brew_espresso' ), 9 );
144
		//other housekeeping
145
		//exclude EE critical pages from wp_list_pages
146
		add_filter( 'wp_list_pages_excludes', array( $this, 'remove_pages_from_wp_list_pages' ), 10 );
147
		// ALL EE Addons should use the following hook point to attach their initial setup too
148
		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
149
		do_action( 'AHEE__EE_System__construct__complete', $this );
150
	}
151
152
153
154
	/**
155
	 * load_espresso_addons
156
	 *
157
	 * allow addons to load first so that they can set hooks for running DMS's, etc
158
	 * this is hooked into both:
159
	 * 	'AHEE__EE_Bootstrap__load_core_configuration'
160
	 * 		which runs during the WP 'plugins_loaded' action at priority 5
161
	 * 	and the WP 'activate_plugin' hookpoint
162
	 *
163
	 * @access public
164
	 * @return void
165
	 */
166
	public function load_espresso_addons() {
167
		// set autoloaders for all of the classes implementing EEI_Plugin_API
168
		// which provide helpers for EE plugin authors to more easily register certain components with EE.
169
		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_LIBRARIES . 'plugin_api' );
170
		//load and setup EE_Capabilities
171
		$this->registry->load_core( 'Capabilities' );
172
		//caps need to be initialized on every request so that capability maps are set.
173
		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
174
		$this->registry->CAP->init_caps();
175
		do_action( 'AHEE__EE_System__load_espresso_addons' );
176
		//if the WP API basic auth plugin isn't already loaded, load it now.
177
		//We want it for mobile apps. Just include the entire plugin
178
		//also, don't load the basic auth when a plugin is getting activated, because
179
		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
180
		//and causes a fatal error
181
		if( !function_exists( 'json_basic_auth_handler' )
182
			&& ! function_exists( 'json_basic_auth_error' )
183
			&& ! (
184
				isset( $_GET[ 'action'] )
185
				&& in_array( $_GET[ 'action' ], array( 'activate', 'activate-selected' ) )
186
			)
187
			&& ! (
188
				isset( $_GET['activate' ] )
189
				&& $_GET['activate' ] === 'true'
190
			)
191
		) {
192
			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
193
		}
194
	}
195
196
197
	/**
198
	 * detect_activations_or_upgrades
199
	 *
200
	 * Checks for activation or upgrade of core first;
201
	 * then also checks if any registered addons have been activated or upgraded
202
	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
203
	 * which runs during the WP 'plugins_loaded' action at priority 3
204
	 *
205
	 * @access public
206
	 * @return void
207
	 */
208
	public function detect_activations_or_upgrades(){
209
		//first off: let's make sure to handle core
210
		$this->detect_if_activation_or_upgrade();
211
		foreach($this->registry->addons as $addon){
212
			//detect teh request type for that addon
213
			$addon->detect_activation_or_upgrade();
214
		}
215
	}
216
217
218
219
	/**
220
	* detect_if_activation_or_upgrade
221
	*
222
	* Takes care of detecting whether this is a brand new install or code upgrade,
223
	* and either setting up the DB or setting up maintenance mode etc.
224
	*
225
	* @access public
226
	* @return void
227
	*/
228
	public function detect_if_activation_or_upgrade() {
229
		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
230
231
		// load M-Mode class
232
		$this->registry->load_core( 'Maintenance_Mode' );
233
		// check if db has been updated, or if its a brand-new installation
234
235
		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
236
		$request_type =  $this->detect_req_type($espresso_db_update);
237
		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
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_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 25 );
689
		add_action( 'admin_bar_menu', array( $this, 'espresso_toolbar_items' ), 100 );
690
691
		if ( is_admin() && apply_filters( 'FHEE__EE_System__brew_espresso__load_pue', TRUE )  ) {
692
			// pew pew pew
693
			$this->registry->load_core( 'PUE' );
694
			do_action( 'AHEE__EE_System__brew_espresso__after_pue_init' );
695
		}
696
		do_action( 'AHEE__EE_System__brew_espresso__complete', $this );
697
	}
698
699
700
701
702
	/**
703
	 * 	set_hooks_for_core
704
	 *
705
	 *  	@access public
706
	 *  	@return 	void
707
	 */
708
	public function set_hooks_for_core() {
709
		$this->_deactivate_incompatible_addons();
710
		do_action( 'AHEE__EE_System__set_hooks_for_core' );
711
	}
712
713
714
715
	/**
716
	 * Using the information gathered in EE_System::_incompatible_addon_error,
717
	 * deactivates any addons considered incompatible with the current version of EE
718
	 */
719
	private function _deactivate_incompatible_addons(){
720
		$incompatible_addons = get_option( 'ee_incompatible_addons', array() );
721
		if ( ! empty( $incompatible_addons )) {
722
			$active_plugins = get_option( 'active_plugins', array() );
723
			foreach ( $active_plugins as $active_plugin ) {
724
				foreach ( $incompatible_addons as $incompatible_addon ) {
725
					if ( strpos( $active_plugin,  $incompatible_addon ) !== FALSE ) {
726
						unset( $_GET['activate'] );
727
						espresso_deactivate_plugin( $active_plugin );
728
					}
729
				}
730
			}
731
		}
732
	}
733
734
735
736
	/**
737
	 * 	perform_activations_upgrades_and_migrations
738
	 *
739
	 *  	@access public
740
	 *  	@return 	void
741
	 */
742
	public function perform_activations_upgrades_and_migrations() {
743
		//first check if we had previously attempted to setup EE's directories but failed
744
		if( EEH_Activation::upload_directories_incomplete() ) {
745
			EEH_Activation::create_upload_directories();
746
		}
747
		do_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations' );
748
	}
749
750
751
752
	/**
753
	 * 	load_CPTs_and_session
754
	 *
755
	 *  	@access public
756
	 *  	@return 	void
757
	 */
758
	public function load_CPTs_and_session() {
759
		do_action( 'AHEE__EE_System__load_CPTs_and_session__start' );
760
		// register Custom Post Types
761
		$this->registry->load_core( 'Register_CPTs' );
762
		do_action( 'AHEE__EE_System__load_CPTs_and_session__complete' );
763
	}
764
765
766
767
	/**
768
	* load_controllers
769
	*
770
	* this is the best place to load any additional controllers that needs access to EE core.
771
	* it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this time
772
	*
773
	* @access public
774
	* @return void
775
	*/
776
	public function load_controllers() {
777
		do_action( 'AHEE__EE_System__load_controllers__start' );
778
		// let's get it started
779
		if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level() ) {
780
			do_action( 'AHEE__EE_System__load_controllers__load_front_controllers' );
781
			$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...
782
		} else if ( ! EE_FRONT_AJAX ) {
783
			do_action( 'AHEE__EE_System__load_controllers__load_admin_controllers' );
784
			EE_Registry::instance()->load_core( 'Admin' );
785
		}
786
		do_action( 'AHEE__EE_System__load_controllers__complete' );
787
	}
788
789
790
791
	/**
792
	* core_loaded_and_ready
793
	*
794
	* all of the basic EE core should be loaded at this point and available regardless of M-Mode
795
	*
796
	* @access public
797
	* @return void
798
	*/
799
	public function core_loaded_and_ready() {
800
		do_action( 'AHEE__EE_System__core_loaded_and_ready' );
801
		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
802
		$this->registry->load_core( 'Session' );
803
		//		add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 );
804
	}
805
806
807
808
	/**
809
	* initialize
810
	*
811
	* this is the best place to begin initializing client code
812
	*
813
	* @access public
814
	* @return void
815
	*/
816
	public function initialize() {
817
		do_action( 'AHEE__EE_System__initialize' );
818
	}
819
820
821
822
	/**
823
	* initialize_last
824
	*
825
	* this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to initialize has done so
826
	*
827
	* @access public
828
	* @return void
829
	*/
830
	public function initialize_last() {
831
		do_action( 'AHEE__EE_System__initialize_last' );
832
	}
833
834
835
836
837
	/**
838
	* set_hooks_for_shortcodes_modules_and_addons
839
	*
840
	* this is the best place for other systems to set callbacks for hooking into other parts of EE
841
	* this happens at the very beginning of the wp_loaded hookpoint
842
	*
843
	* @access public
844
	* @return void
845
	*/
846
	public function set_hooks_for_shortcodes_modules_and_addons() {
847
//		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
848
	}
849
850
851
852
853
	/**
854
	* do_not_cache
855
	*
856
	* sets no cache headers and defines no cache constants for WP plugins
857
	*
858
	* @access public
859
	* @return void
860
	*/
861
	public static function do_not_cache() {
862
		// set no cache constants
863
		if ( ! defined( 'DONOTCACHEPAGE' ) ) {
864
			define( 'DONOTCACHEPAGE', true );
865
		}
866
		if ( ! defined( 'DONOTCACHCEOBJECT' ) ) {
867
			define( 'DONOTCACHCEOBJECT', true );
868
		}
869
		if ( ! defined( 'DONOTCACHEDB' ) ) {
870
			define( 'DONOTCACHEDB', true );
871
		}
872
		// add no cache headers
873
		add_action( 'send_headers' , array( 'EE_System', 'nocache_headers' ), 10 );
874
		// plus a little extra for nginx and Google Chrome
875
		add_filter( 'nocache_headers', array( 'EE_System', 'extra_nocache_headers' ), 10, 1 );
876
		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
877
		remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
878
	}
879
880
881
882
	/**
883
	 *    extra_nocache_headers
884
	 *
885
	 * @access    public
886
	 * @param $headers
887
	 * @return    array
888
	 */
889
	public static function extra_nocache_headers ( $headers ) {
890
		// for NGINX
891
		$headers['X-Accel-Expires'] = 0;
892
		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
893
		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
894
		return $headers;
895
	}
896
897
898
899
	/**
900
	 * 	nocache_headers
901
	 *
902
	 *  @access 	public
903
	 *  @return 	void
904
	 */
905
	public static function nocache_headers() {
906
		nocache_headers();
907
	}
908
909
910
911
	/**
912
	 *    espresso_toolbar_items
913
	 *
914
	 * @access public
915
	 * @param  WP_Admin_Bar $admin_bar
916
	 * @return void
917
	 */
918
	public function espresso_toolbar_items( WP_Admin_Bar $admin_bar ) {
919
920
		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
921
		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' )) {
922
			return;
923
		}
924
925
		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
926
		$menu_class = 'espresso_menu_item_class';
927
		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
928
		//because they're only defined in each of their respective constructors
929
		//and this might be a frontend request, in which case they aren't available
930
		$events_admin_url = admin_url("admin.php?page=espresso_events");
931
		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
932
		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
933
934
		//Top Level
935
		$admin_bar->add_menu(array(
936
				'id' => 'espresso-toolbar',
937
				'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>',
938
				'href' => $events_admin_url,
939
				'meta' => array(
940
						'title' => __('Event Espresso', 'event_espresso'),
941
						'class' => $menu_class . 'first'
942
				),
943
		));
944
945
		//Events
946 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events' ) ) {
947
			$admin_bar->add_menu(array(
948
					'id' => 'espresso-toolbar-events',
949
					'parent' => 'espresso-toolbar',
950
					'title' => __( 'Events', 'event_espresso' ),
951
					'href' => $events_admin_url,
952
					'meta' => array(
953
							'title' => __('Events', 'event_espresso'),
954
							'target' => '',
955
							'class' => $menu_class
956
					),
957
			));
958
		}
959
960
961
		if ( $this->registry->CAP->current_user_can( 'ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new' ) ) {
962
			//Events Add New
963
			$admin_bar->add_menu(array(
964
					'id' => 'espresso-toolbar-events-new',
965
					'parent' => 'espresso-toolbar-events',
966
					'title' => __('Add New', 'event_espresso'),
967
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'create_new' ), $events_admin_url ),
968
					'meta' => array(
969
							'title' => __('Add New', 'event_espresso'),
970
							'target' => '',
971
							'class' => $menu_class
972
					),
973
			));
974
		}
975
976
		if ( is_single() && ( get_post_type() == 'espresso_events' ) ) {
977
978
			//Current post
979
			global $post;
980
981
	    	if ( $this->registry->CAP->current_user_can( 'ee_edit_event', 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID ) ) {
982
				//Events Edit Current Event
983
				$admin_bar->add_menu(array(
984
						'id' => 'espresso-toolbar-events-edit',
985
						'parent' => 'espresso-toolbar-events',
986
						'title' => __('Edit Event', 'event_espresso'),
987
						'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'edit', 'post'=>$post->ID ), $events_admin_url ),
988
						'meta' => array(
989
								'title' => __('Edit Event', 'event_espresso'),
990
								'target' => '',
991
								'class' => $menu_class
992
						),
993
				));
994
			}
995
996
		}
997
998
		//Events View
999 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-view' ) ) {
1000
			$admin_bar->add_menu(array(
1001
					'id' => 'espresso-toolbar-events-view',
1002
					'parent' => 'espresso-toolbar-events',
1003
					'title' => __( 'View', 'event_espresso' ),
1004
					'href' => $events_admin_url,
1005
					'meta' => array(
1006
							'title' => __('View', 'event_espresso'),
1007
							'target' => '',
1008
							'class' => $menu_class
1009
					),
1010
			));
1011
		}
1012
1013 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all' ) ) {
1014
			//Events View All
1015
			$admin_bar->add_menu(array(
1016
					'id' => 'espresso-toolbar-events-all',
1017
					'parent' => 'espresso-toolbar-events-view',
1018
					'title' => __( 'All', 'event_espresso' ),
1019
					'href' => $events_admin_url,
1020
					'meta' => array(
1021
							'title' => __('All', 'event_espresso'),
1022
							'target' => '',
1023
							'class' => $menu_class
1024
					),
1025
			));
1026
		}
1027
1028
1029 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-today' ) ) {
1030
			//Events View Today
1031
			$admin_bar->add_menu(array(
1032
					'id' => 'espresso-toolbar-events-today',
1033
					'parent' => 'espresso-toolbar-events-view',
1034
					'title' => __('Today', 'event_espresso'),
1035
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $events_admin_url ),
1036
					'meta' => array(
1037
							'title' => __('Today', 'event_espresso'),
1038
							'target' => '',
1039
							'class' => $menu_class
1040
					),
1041
			));
1042
		}
1043
1044
1045 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-month' ) ) {
1046
			//Events View This Month
1047
			$admin_bar->add_menu(array(
1048
					'id' => 'espresso-toolbar-events-month',
1049
					'parent' => 'espresso-toolbar-events-view',
1050
					'title' => __( 'This Month', 'event_espresso'),
1051
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $events_admin_url ),
1052
					'meta' => array(
1053
							'title' => __('This Month', 'event_espresso'),
1054
							'target' => '',
1055
							'class' => $menu_class
1056
					),
1057
			));
1058
		}
1059
1060
		//Registration Overview
1061 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations' ) ) {
1062
			$admin_bar->add_menu(array(
1063
					'id' => 'espresso-toolbar-registrations',
1064
					'parent' => 'espresso-toolbar',
1065
					'title' => __( 'Registrations', 'event_espresso' ),
1066
					'href' => $reg_admin_url,
1067
					'meta' => array(
1068
							'title' => __('Registrations', 'event_espresso'),
1069
							'target' => '',
1070
							'class' => $menu_class
1071
					),
1072
			));
1073
		}
1074
1075
		//Registration Overview Today
1076 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today' ) ) {
1077
			$admin_bar->add_menu(array(
1078
					'id' => 'espresso-toolbar-registrations-today',
1079
					'parent' => 'espresso-toolbar-registrations',
1080
					'title' => __( 'Today', 'event_espresso'),
1081
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $reg_admin_url ),
1082
					'meta' => array(
1083
							'title' => __('Today', 'event_espresso'),
1084
							'target' => '',
1085
							'class' => $menu_class
1086
					),
1087
			));
1088
		}
1089
1090
		//Registration Overview Today Completed
1091 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' ) ) {
1092
			$admin_bar->add_menu(array(
1093
					'id' => 'espresso-toolbar-registrations-today-approved',
1094
					'parent' => 'espresso-toolbar-registrations-today',
1095
					'title' => __( 'Approved', 'event_espresso' ),
1096
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ),
1097
					'meta' => array(
1098
							'title' => __('Approved', 'event_espresso' ),
1099
							'target' => '',
1100
							'class' => $menu_class
1101
					),
1102
			));
1103
		}
1104
1105
		//Registration Overview Today Pending\
1106 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' ) ) {
1107
			$admin_bar->add_menu(array(
1108
					'id' => 'espresso-toolbar-registrations-today-pending',
1109
					'parent' => 'espresso-toolbar-registrations-today',
1110
					'title' => __( 'Pending', 'event_espresso' ),
1111
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', 'reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ),
1112
					'meta' => array(
1113
							'title' => __('Pending Payment', 'event_espresso' ),
1114
							'target' => '',
1115
							'class' => $menu_class
1116
					),
1117
			));
1118
		}
1119
1120
		//Registration Overview Today Incomplete
1121 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' ) ) {
1122
			$admin_bar->add_menu(array(
1123
					'id' => 'espresso-toolbar-registrations-today-not-approved',
1124
					'parent' => 'espresso-toolbar-registrations-today',
1125
					'title' => __( 'Not Approved', 'event_espresso' ),
1126
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ),
1127
					'meta' => array(
1128
							'title' => __('Not Approved', 'event_espresso' ),
1129
							'target' => '',
1130
							'class' => $menu_class
1131
					),
1132
			));
1133
		}
1134
1135
		//Registration Overview Today Incomplete
1136 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' ) ) {
1137
			$admin_bar->add_menu(array(
1138
					'id' => 'espresso-toolbar-registrations-today-cancelled',
1139
					'parent' => 'espresso-toolbar-registrations-today',
1140
					'title' => __( 'Cancelled', 'event_espresso'),
1141
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ),
1142
					'meta' => array(
1143
							'title' => __('Cancelled', 'event_espresso'),
1144
							'target' => '',
1145
							'class' => $menu_class
1146
					),
1147
			));
1148
		}
1149
1150
		//Registration Overview This Month
1151 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month' ) ) {
1152
			$admin_bar->add_menu(array(
1153
					'id' => 'espresso-toolbar-registrations-month',
1154
					'parent' => 'espresso-toolbar-registrations',
1155
					'title' => __( 'This Month', 'event_espresso' ),
1156
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $reg_admin_url ),
1157
					'meta' => array(
1158
							'title' => __('This Month', 'event_espresso'),
1159
							'target' => '',
1160
							'class' => $menu_class
1161
					),
1162
			));
1163
		}
1164
1165
		//Registration Overview This Month Approved
1166 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' ) ) {
1167
			$admin_bar->add_menu(array(
1168
					'id' => 'espresso-toolbar-registrations-month-approved',
1169
					'parent' => 'espresso-toolbar-registrations-month',
1170
					'title' => __( 'Approved', 'event_espresso' ),
1171
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ),
1172
					'meta' => array(
1173
							'title' => __('Approved', 'event_espresso'),
1174
							'target' => '',
1175
							'class' => $menu_class
1176
					),
1177
			));
1178
		}
1179
1180
		//Registration Overview This Month Pending
1181 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' ) ) {
1182
			$admin_bar->add_menu(array(
1183
					'id' => 'espresso-toolbar-registrations-month-pending',
1184
					'parent' => 'espresso-toolbar-registrations-month',
1185
					'title' => __( 'Pending', 'event_espresso'),
1186
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ),
1187
					'meta' => array(
1188
							'title' => __('Pending', 'event_espresso'),
1189
							'target' => '',
1190
							'class' => $menu_class
1191
					),
1192
			));
1193
		}
1194
1195
		//Registration Overview This Month Not Approved
1196 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' ) ) {
1197
			$admin_bar->add_menu(array(
1198
					'id' => 'espresso-toolbar-registrations-month-not-approved',
1199
					'parent' => 'espresso-toolbar-registrations-month',
1200
					'title' => __( 'Not Approved', 'event_espresso'),
1201
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ),
1202
					'meta' => array(
1203
							'title' => __('Not Approved', 'event_espresso' ),
1204
							'target' => '',
1205
							'class' => $menu_class
1206
					),
1207
			));
1208
		}
1209
1210
1211
		//Registration Overview This Month Cancelled
1212 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' ) ) {
1213
			$admin_bar->add_menu(array(
1214
					'id' => 'espresso-toolbar-registrations-month-cancelled',
1215
					'parent' => 'espresso-toolbar-registrations-month',
1216
					'title' => __('Cancelled', 'event_espresso'),
1217
					'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ),
1218
					'meta' => array(
1219
							'title' => __('Cancelled', 'event_espresso'),
1220
							'target' => '',
1221
							'class' => $menu_class
1222
					),
1223
			));
1224
		}
1225
1226
		//Extensions & Services
1227 View Code Duplication
		if ( $this->registry->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' ) ) {
1228
			$admin_bar->add_menu(array(
1229
					'id' => 'espresso-toolbar-extensions-and-services',
1230
					'parent' => 'espresso-toolbar',
1231
					'title' => __( 'Extensions & Services', 'event_espresso' ),
1232
					'href' => $extensions_admin_url,
1233
					'meta' => array(
1234
							'title' => __('Extensions & Services', 'event_espresso'),
1235
							'target' => '',
1236
							'class' => $menu_class
1237
					),
1238
			));
1239
		}
1240
	}
1241
1242
1243
1244
1245
1246
	/**
1247
	 * 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.
1248
	 *
1249
	 *
1250
	 * @param  array  $exclude_array any existing pages being excluded are in this array.
1251
	 * @return array
1252
	 */
1253
	public function remove_pages_from_wp_list_pages( $exclude_array ) {
1254
		return  array_merge( $exclude_array, $this->registry->CFG->core->get_critical_pages_array() );
1255
	}
1256
1257
1258
1259
1260
1261
1262
	/*********************************************** 		WP_ENQUEUE_SCRIPTS HOOK		 ***********************************************/
1263
1264
1265
1266
	/**
1267
	 * 	wp_enqueue_scripts
1268
	 *
1269
	 *  	@access 	public
1270
	 *  	@return 	void
1271
	 */
1272
	public function wp_enqueue_scripts() {
1273
		// 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' );
1274 View Code Duplication
		if ( apply_filters( 'FHEE_load_EE_System_scripts', TRUE ) ) {
1275
			// 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' );
1276
			if ( apply_filters( 'FHEE_load_jquery_validate', FALSE ) ) {
1277
				// register jQuery Validate and additional methods
1278
				wp_register_script( 'jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', array('jquery' ), '1.15.0', TRUE );
1279
				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 );
1280
			}
1281
			wp_register_script( 'select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true );
1282
			wp_register_style( 'select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all' );
1283
		}
1284
	}
1285
1286
1287
1288
}
1289
// End of file EE_System.core.php
1290
// Location: /core/EE_System.core.php
1291