Completed
Branch BUG-9774-email-validation (c72797)
by
unknown
1171:55 queued 1157:09
created

EE_System::nocache_headers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

function notNullable(stdClass $x) { }

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

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

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