Completed
Branch BUG-11107-submit-button-text (11bd3b)
by
unknown
30:51 queued 19:49
created
core/services/collections/iterators/CollectionFilterCallbackIterator.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -9,51 +9,51 @@
 block discarded – undo
9 9
 class CollectionFilterCallbackIterator extends FilterIterator
10 10
 {
11 11
 
12
-    /**
13
-     * Used for determining whether the iterated object in the Collection is "valid" or not.
14
-     * @var Closure
15
-     */
16
-    private $acceptance_callback;
17
-
18
-
19
-    /**
20
-     * CollectionFilterCallbackIterator constructor.
21
-     *
22
-     * @param Collection $collection
23
-     * @param Closure    $acceptance_callback  The closure will receive an instance of whatever object is stored on the
24
-     *                                         collection when iterating over the collection and should return boolean.
25
-     */
26
-    public function __construct(Collection $collection, Closure $acceptance_callback)
27
-    {
28
-        $this->acceptance_callback = $acceptance_callback;
29
-        parent::__construct($collection);
30
-    }
31
-
32
-    /**
33
-     * Check whether the current element of the iterator is acceptable
34
-     *
35
-     * @link  http://php.net/manual/en/filteriterator.accept.php
36
-     * @return bool true if the current element is acceptable, otherwise false.
37
-     */
38
-    public function accept()
39
-    {
40
-        $acceptance_callback = $this->acceptance_callback;
41
-        return $acceptance_callback($this->getInnerIterator()->current());
42
-    }
43
-
44
-
45
-
46
-    /**
47
-     * Returns a filtered array of objects from the collection using the provided acceptance callback
48
-     * @return array
49
-     */
50
-    public function getFiltered()
51
-    {
52
-        $filtered_array = array();
53
-        $this->rewind();
54
-        foreach ($this as $filtered_object) {
55
-            $filtered_array[] = $filtered_object;
56
-        }
57
-        return $filtered_array;
58
-    }
12
+	/**
13
+	 * Used for determining whether the iterated object in the Collection is "valid" or not.
14
+	 * @var Closure
15
+	 */
16
+	private $acceptance_callback;
17
+
18
+
19
+	/**
20
+	 * CollectionFilterCallbackIterator constructor.
21
+	 *
22
+	 * @param Collection $collection
23
+	 * @param Closure    $acceptance_callback  The closure will receive an instance of whatever object is stored on the
24
+	 *                                         collection when iterating over the collection and should return boolean.
25
+	 */
26
+	public function __construct(Collection $collection, Closure $acceptance_callback)
27
+	{
28
+		$this->acceptance_callback = $acceptance_callback;
29
+		parent::__construct($collection);
30
+	}
31
+
32
+	/**
33
+	 * Check whether the current element of the iterator is acceptable
34
+	 *
35
+	 * @link  http://php.net/manual/en/filteriterator.accept.php
36
+	 * @return bool true if the current element is acceptable, otherwise false.
37
+	 */
38
+	public function accept()
39
+	{
40
+		$acceptance_callback = $this->acceptance_callback;
41
+		return $acceptance_callback($this->getInnerIterator()->current());
42
+	}
43
+
44
+
45
+
46
+	/**
47
+	 * Returns a filtered array of objects from the collection using the provided acceptance callback
48
+	 * @return array
49
+	 */
50
+	public function getFiltered()
51
+	{
52
+		$filtered_array = array();
53
+		$this->rewind();
54
+		foreach ($this as $filtered_object) {
55
+			$filtered_array[] = $filtered_object;
56
+		}
57
+		return $filtered_array;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
core/services/collections/iterators/FilterIteratorsHelper.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -17,18 +17,18 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Uses CollectionFilterCallbackIterator on a provided collection with provided Closure for filtering each object
22
-     * in the collection.
23
-     * The closure receives an instance of the object and should return false if it is not "valid" and true if it is.
24
-     *
25
-     * @param Collection $collection
26
-     * @param Closure    $acceptance_callback
27
-     * @return array
28
-     */
29
-    public static function getFilteredObjectsFromCollection(Collection $collection, Closure $acceptance_callback)
30
-    {
31
-        $collection_filter_iterator = new CollectionFilterCallbackIterator($collection, $acceptance_callback);
32
-        return $collection_filter_iterator->getFiltered();
33
-    }
20
+	/**
21
+	 * Uses CollectionFilterCallbackIterator on a provided collection with provided Closure for filtering each object
22
+	 * in the collection.
23
+	 * The closure receives an instance of the object and should return false if it is not "valid" and true if it is.
24
+	 *
25
+	 * @param Collection $collection
26
+	 * @param Closure    $acceptance_callback
27
+	 * @return array
28
+	 */
29
+	public static function getFilteredObjectsFromCollection(Collection $collection, Closure $acceptance_callback)
30
+	{
31
+		$collection_filter_iterator = new CollectionFilterCallbackIterator($collection, $acceptance_callback);
32
+		return $collection_filter_iterator->getFiltered();
33
+	}
34 34
 }
35 35
\ No newline at end of file
Please login to merge, or discard this patch.
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		$this->_columns = array_merge( $columns, $this->_columns );
91 91
 		$this->_primary_column = '_REG_att_checked_in';
92 92
 		if ( ! empty( $evt_id )
93
-		     && EE_Registry::instance()->CAP->current_user_can(
93
+			 && EE_Registry::instance()->CAP->current_user_can(
94 94
 				'ee_read_registrations',
95 95
 				'espresso_registrations_registrations_reports',
96 96
 				$evt_id
@@ -107,44 +107,44 @@  discard block
 block discarded – undo
107 107
 				),
108 108
 			);
109 109
 		}
110
-        $this->_bottom_buttons['report_filtered'] = array(
111
-            'route'         => 'registrations_checkin_report',
112
-            'extra_request' => array(
113
-                'use_filters' => true,
114
-                'filters'     => array_merge(
115
-                    array(
116
-                        'EVT_ID' => $evt_id,
117
-                    ),
118
-                    array_diff_key(
119
-                        $this->_req_data,
120
-                        array_flip(
121
-                            array(
122
-                                'page',
123
-                                'action',
124
-                                'default_nonce',
125
-                            )
126
-                        )
127
-                    )
128
-                ),
129
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
130
-            ),
131
-        );
110
+		$this->_bottom_buttons['report_filtered'] = array(
111
+			'route'         => 'registrations_checkin_report',
112
+			'extra_request' => array(
113
+				'use_filters' => true,
114
+				'filters'     => array_merge(
115
+					array(
116
+						'EVT_ID' => $evt_id,
117
+					),
118
+					array_diff_key(
119
+						$this->_req_data,
120
+						array_flip(
121
+							array(
122
+								'page',
123
+								'action',
124
+								'default_nonce',
125
+							)
126
+						)
127
+					)
128
+				),
129
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
130
+			),
131
+		);
132 132
 		$this->_sortable_columns = array(
133
-            /**
134
-             * Allows users to change the default sort if they wish.
135
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
136
-             *
137
-             * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
138
-             * change the sorts on any list table involving registration contacts.  If you want to only change the filter
139
-             * for a specific list table you can use the provided reference to this object instance.
140
-             */
133
+			/**
134
+			 * Allows users to change the default sort if they wish.
135
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
136
+			 *
137
+			 * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
138
+			 * change the sorts on any list table involving registration contacts.  If you want to only change the filter
139
+			 * for a specific list table you can use the provided reference to this object instance.
140
+			 */
141 141
 			'ATT_name' => array(
142
-                    'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
143
-                    true,
144
-                    $this
145
-                )
146
-                ? array( 'ATT_lname' => true )
147
-                : array( 'ATT_fname' => true ),
142
+					'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
143
+					true,
144
+					$this
145
+				)
146
+				? array( 'ATT_lname' => true )
147
+				: array( 'ATT_fname' => true ),
148 148
 			'Event'    => array( 'Event.EVT.Name' => false ),
149 149
 		);
150 150
 		$this->_hidden_columns = array();
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 				if ( ! $evt->get_count_of_all_registrations() ) {
204 204
 					continue;
205 205
 				}
206
-                                $evts[] = array(
206
+								$evts[] = array(
207 207
 					'id'    => $evt->ID(),
208 208
 					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt),
209 209
 					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 			if ( count( $this->_dtts_for_event ) > 1 ) {
228 228
 				$dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' );
229 229
 				foreach ( $this->_dtts_for_event as $dtt ) {
230
-                    $datetime_string = $dtt->name();
231
-                    $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
230
+					$datetime_string = $dtt->name();
231
+					$datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
232 232
 					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
233 233
 					$dtts[ $dtt->ID() ] = $datetime_string;
234 234
 				}
@@ -301,16 +301,16 @@  discard block
 block discarded – undo
301 301
 
302 302
 
303 303
 
304
-    /**
305
-     * column_REG_att_checked_in
306
-     *
307
-     * @param EE_Registration $item
308
-     * @return string
309
-     * @throws EE_Error
310
-     * @throws InvalidArgumentException
311
-     * @throws InvalidDataTypeException
312
-     * @throws InvalidInterfaceException
313
-     */
304
+	/**
305
+	 * column_REG_att_checked_in
306
+	 *
307
+	 * @param EE_Registration $item
308
+	 * @return string
309
+	 * @throws EE_Error
310
+	 * @throws InvalidArgumentException
311
+	 * @throws InvalidDataTypeException
312
+	 * @throws InvalidInterfaceException
313
+	 */
314 314
 	public function column__REG_att_checked_in( EE_Registration $item ) {
315 315
 		$attendee = $item->attendee();
316 316
 		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
@@ -321,13 +321,13 @@  discard block
 block discarded – undo
321 321
 				$this->_cur_dtt_id = $latest_related_datetime->ID();
322 322
 			}
323 323
 		}
324
-        $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
325
-		    $item,
326
-            $this->_cur_dtt_id
327
-        );
324
+		$checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
325
+			$item,
326
+			$this->_cur_dtt_id
327
+		);
328 328
 		$nonce = wp_create_nonce( 'checkin_nonce' );
329 329
 		$toggle_active = ! empty ( $this->_cur_dtt_id )
330
-		                 && EE_Registry::instance()->CAP->current_user_can(
330
+						 && EE_Registry::instance()->CAP->current_user_can(
331 331
 			'ee_edit_checkin',
332 332
 			'espresso_registrations_toggle_checkin_status',
333 333
 			$item->ID()
@@ -336,11 +336,11 @@  discard block
 block discarded – undo
336 336
 			: '';
337 337
 		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
338 338
 		return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
339
-		       . ' data-_regid="' . $item->ID() . '"'
340
-		       . ' data-dttid="' . $this->_cur_dtt_id . '"'
341
-		       . ' data-nonce="' . $nonce . '">'
342
-		       . '</span>'
343
-		       . $mobile_view_content;
339
+			   . ' data-_regid="' . $item->ID() . '"'
340
+			   . ' data-dttid="' . $this->_cur_dtt_id . '"'
341
+			   . ' data-nonce="' . $nonce . '">'
342
+			   . '</span>'
343
+			   . $mobile_view_content;
344 344
 	}
345 345
 
346 346
 
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
 			'espresso_registrations_edit_attendee'
366 366
 		)
367 367
 			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
368
-			    . $item->attendee()->full_name()
369
-			    . '</a>'
368
+				. $item->attendee()->full_name()
369
+				. '</a>'
370 370
 			: $item->attendee()->full_name();
371 371
 		$name_link .= $item->count() === 1
372 372
 			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
@@ -401,14 +401,14 @@  discard block
 block discarded – undo
401 401
 			? $latest_related_datetime->ID()
402 402
 			: $DTT_ID;
403 403
 		if ( ! empty( $DTT_ID )
404
-		     && EE_Registry::instance()->CAP->current_user_can(
404
+			 && EE_Registry::instance()->CAP->current_user_can(
405 405
 				'ee_read_checkins',
406 406
 				'espresso_registrations_registration_checkins'
407 407
 			)
408 408
 		) {
409 409
 			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
410 410
 				array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID ),
411
-                REG_ADMIN_URL
411
+				REG_ADMIN_URL
412 412
 			);
413 413
 			// get the timestamps for this registration's checkins, related to the selected datetime
414 414
 			$timestamps = $item->get_many_related( 'Checkin', array( array( 'DTT_ID' => $DTT_ID ) ) );
@@ -516,15 +516,15 @@  discard block
 block discarded – undo
516 516
 				) ? '
517 517
 				<span class="reg-pad-rght">
518 518
 					<a class="status-'
519
-				    . $item->transaction()->status_ID()
520
-				    . '" href="'
521
-				    . $view_txn_lnk_url
522
-				    . '"  title="'
523
-				    . esc_attr__( 'View Transaction', 'event_espresso' )
524
-				    . '">
519
+					. $item->transaction()->status_ID()
520
+					. '" href="'
521
+					. $view_txn_lnk_url
522
+					. '"  title="'
523
+					. esc_attr__( 'View Transaction', 'event_espresso' )
524
+					. '">
525 525
 						'
526
-				    . $item->transaction()->pretty_paid()
527
-				    . '
526
+					. $item->transaction()->pretty_paid()
527
+					. '
528 528
 					</a>
529 529
 				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
530 530
 			}
@@ -557,12 +557,12 @@  discard block
 block discarded – undo
557 557
 				'ee_read_transaction',
558 558
 				'espresso_transactions_view_transaction'
559 559
 			) ? '<a href="'
560
-			    . $view_txn_url
561
-			    . '" title="'
562
-			    . esc_attr__( 'View Transaction', 'event_espresso' )
563
-			    . '"><span class="reg-pad-rght">'
564
-			    . $txn_total
565
-			    . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
560
+				. $view_txn_url
561
+				. '" title="'
562
+				. esc_attr__( 'View Transaction', 'event_espresso' )
563
+				. '"><span class="reg-pad-rght">'
564
+				. $txn_total
565
+				. '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
566 566
 		} else {
567 567
 			return '<span class="reg-pad-rght"></span>';
568 568
 		}
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -45,51 +45,51 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @param \Registrations_Admin_Page $admin_page
47 47
 	 */
48
-	public function __construct( $admin_page ) {
49
-		parent::__construct( $admin_page );
48
+	public function __construct($admin_page) {
49
+		parent::__construct($admin_page);
50 50
 		$this->_status = $this->_admin_page->get_registration_status_array();
51 51
 	}
52 52
 
53 53
 
54 54
 
55 55
 	protected function _setup_data() {
56
-		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( $this->_per_page )
57
-			: $this->_admin_page->get_event_attendees( $this->_per_page, false, true );
56
+		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
57
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
58 58
 		$this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
59 59
 			$this->_per_page,
60 60
 			true
61
-		) : $this->_admin_page->get_event_attendees( $this->_per_page, true, true );
61
+		) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
62 62
 	}
63 63
 
64 64
 
65 65
 
66 66
 	protected function _set_properties() {
67
-		$evt_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null;
67
+		$evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
68 68
 		$this->_wp_list_args = array(
69
-			'singular' => __( 'registrant', 'event_espresso' ),
70
-			'plural'   => __( 'registrants', 'event_espresso' ),
69
+			'singular' => __('registrant', 'event_espresso'),
70
+			'plural'   => __('registrants', 'event_espresso'),
71 71
 			'ajax'     => true,
72 72
 			'screen'   => $this->_admin_page->get_current_screen()->id,
73 73
 		);
74 74
 		$columns = array();
75 75
 		//$columns['_Reg_Status'] = '';
76
-		if ( ! empty( $evt_id ) ) {
76
+		if ( ! empty($evt_id)) {
77 77
 			$columns['cb'] = '<input type="checkbox" />'; //Render a checkbox instead of text
78 78
 			$this->_has_checkbox_column = true;
79 79
 		}
80 80
 		$this->_columns = array(
81 81
 			'_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
82
-			'ATT_name'            => __( 'Registrant', 'event_espresso' ),
83
-			'ATT_email'           => __( 'Email Address', 'event_espresso' ),
84
-			'Event'               => __( 'Event', 'event_espresso' ),
85
-			'PRC_name'            => __( 'TKT Option', 'event_espresso' ),
86
-			'_REG_final_price'    => __( 'Price', 'event_espresso' ),
87
-			'TXN_paid'            => __( 'Paid', 'event_espresso' ),
88
-			'TXN_total'           => __( 'Total', 'event_espresso' ),
82
+			'ATT_name'            => __('Registrant', 'event_espresso'),
83
+			'ATT_email'           => __('Email Address', 'event_espresso'),
84
+			'Event'               => __('Event', 'event_espresso'),
85
+			'PRC_name'            => __('TKT Option', 'event_espresso'),
86
+			'_REG_final_price'    => __('Price', 'event_espresso'),
87
+			'TXN_paid'            => __('Paid', 'event_espresso'),
88
+			'TXN_total'           => __('Total', 'event_espresso'),
89 89
 		);
90
-		$this->_columns = array_merge( $columns, $this->_columns );
90
+		$this->_columns = array_merge($columns, $this->_columns);
91 91
 		$this->_primary_column = '_REG_att_checked_in';
92
-		if ( ! empty( $evt_id )
92
+		if ( ! empty($evt_id)
93 93
 		     && EE_Registry::instance()->CAP->current_user_can(
94 94
 				'ee_read_registrations',
95 95
 				'espresso_registrations_registrations_reports',
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 					'extra_request' =>
103 103
 						array(
104 104
 							'EVT_ID'     => $evt_id,
105
-							'return_url' => urlencode( "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ),
105
+							'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
106 106
 						),
107 107
 				),
108 108
 			);
@@ -143,12 +143,12 @@  discard block
 block discarded – undo
143 143
                     true,
144 144
                     $this
145 145
                 )
146
-                ? array( 'ATT_lname' => true )
147
-                : array( 'ATT_fname' => true ),
148
-			'Event'    => array( 'Event.EVT.Name' => false ),
146
+                ? array('ATT_lname' => true)
147
+                : array('ATT_fname' => true),
148
+			'Event'    => array('Event.EVT.Name' => false),
149 149
 		);
150 150
 		$this->_hidden_columns = array();
151
-		$this->_evt = EEM_Event::instance()->get_one_by_ID( $evt_id );
151
+		$this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
152 152
 		$this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
153 153
 	}
154 154
 
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
 	 * @param \EE_Registration $item
159 159
 	 * @return string
160 160
 	 */
161
-	protected function _get_row_class( $item ) {
162
-		$class = parent::_get_row_class( $item );
161
+	protected function _get_row_class($item) {
162
+		$class = parent::_get_row_class($item);
163 163
 		//add status class
164
-		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
165
-		if ( $this->_has_checkbox_column ) {
164
+		$class .= ' ee-status-strip reg-status-'.$item->status_ID();
165
+		if ($this->_has_checkbox_column) {
166 166
 			$class .= ' has-checkbox-column';
167 167
 		}
168 168
 		return $class;
@@ -176,61 +176,61 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	protected function _get_table_filters() {
178 178
 		$filters = $where = array();
179
-		$current_EVT_ID = isset( $this->_req_data['event_id'] ) ? (int) $this->_req_data['event_id'] : 0;
180
-		if ( empty( $this->_dtts_for_event ) || count( $this->_dtts_for_event ) === 1 ) {
179
+		$current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
180
+		if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
181 181
 			//this means we don't have an event so let's setup a filter dropdown for all the events to select
182 182
 			//note possible capability restrictions
183
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) {
184
-				$where['status**'] = array( '!=', 'private' );
183
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
184
+				$where['status**'] = array('!=', 'private');
185 185
 			}
186
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) {
186
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
187 187
 				$where['EVT_wp_user'] = get_current_user_id();
188 188
 			}
189 189
 			$events = EEM_Event::instance()->get_all(
190 190
 				array(
191 191
 					$where,
192
-					'order_by' => array( 'Datetime.DTT_EVT_start' => 'DESC' ),
192
+					'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
193 193
 				)
194 194
 			);
195 195
 			$evts[] = array(
196 196
 				'id'   => 0,
197
-				'text' => __( 'To toggle Check-in status, select an event', 'event_espresso' ),
197
+				'text' => __('To toggle Check-in status, select an event', 'event_espresso'),
198 198
 			);
199 199
 			$checked = 'checked';
200 200
 			/** @var EE_Event $evt */
201
-			foreach ( $events as $evt ) {
201
+			foreach ($events as $evt) {
202 202
 				//any registrations for this event?
203
-				if ( ! $evt->get_count_of_all_registrations() ) {
203
+				if ( ! $evt->get_count_of_all_registrations()) {
204 204
 					continue;
205 205
 				}
206 206
                                 $evts[] = array(
207 207
 					'id'    => $evt->ID(),
208
-					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt),
208
+					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get('EVT_name'), $evt),
209 209
 					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
210 210
 				);
211
-				if ( $evt->ID() === $current_EVT_ID && $evt->is_expired() ) {
211
+				if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
212 212
 					$checked = '';
213 213
 				}
214 214
 			}
215 215
 			$event_filter = '<div class="ee-event-filter">';
216
-			$event_filter .= EEH_Form_Fields::select_input( 'event_id', $evts, $current_EVT_ID );
216
+			$event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
217 217
 			$event_filter .= '<span class="ee-event-filter-toggle">';
218
-			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
219
-			$event_filter .= __( 'Hide Expired Events', 'event_espresso' );
218
+			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> ';
219
+			$event_filter .= __('Hide Expired Events', 'event_espresso');
220 220
 			$event_filter .= '</span>';
221 221
 			$event_filter .= '</div>';
222 222
 			$filters[] = $event_filter;
223 223
 		}
224
-		if ( ! empty( $this->_dtts_for_event ) ) {
224
+		if ( ! empty($this->_dtts_for_event)) {
225 225
 			//DTT datetimes filter
226
-			$this->_cur_dtt_id = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0;
227
-			if ( count( $this->_dtts_for_event ) > 1 ) {
228
-				$dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' );
229
-				foreach ( $this->_dtts_for_event as $dtt ) {
226
+			$this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
227
+			if (count($this->_dtts_for_event) > 1) {
228
+				$dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso');
229
+				foreach ($this->_dtts_for_event as $dtt) {
230 230
                     $datetime_string = $dtt->name();
231
-                    $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
232
-					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
233
-					$dtts[ $dtt->ID() ] = $datetime_string;
231
+                    $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : '';
232
+					$datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string;
233
+					$dtts[$dtt->ID()] = $datetime_string;
234 234
 				}
235 235
 				$input = new EE_Select_Input(
236 236
 					$dtts,
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 					)
242 242
 				);
243 243
 				$filters[] = $input->get_html_for_input();
244
-				$filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
244
+				$filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">';
245 245
 			}
246 246
 		}
247 247
 		return $filters;
@@ -260,22 +260,22 @@  discard block
 block discarded – undo
260 260
 	 * @throws \EE_Error
261 261
 	 */
262 262
 	protected function _get_total_event_attendees() {
263
-		$EVT_ID = isset( $this->_req_data['event_id'] ) ? absint( $this->_req_data['event_id'] ) : false;
263
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
264 264
 		$DTT_ID = $this->_cur_dtt_id;
265 265
 		$query_params = array();
266
-		if ( $EVT_ID ) {
266
+		if ($EVT_ID) {
267 267
 			$query_params[0]['EVT_ID'] = $EVT_ID;
268 268
 		}
269 269
 		//if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
270
-		if ( $DTT_ID ) {
270
+		if ($DTT_ID) {
271 271
 			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
272 272
 		}
273 273
 		$status_ids_array = apply_filters(
274 274
 			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
275
-			array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved )
275
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
276 276
 		);
277
-		$query_params[0]['STS_ID'] = array( 'IN', $status_ids_array );
278
-		return EEM_Registration::instance()->count( $query_params );
277
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
278
+		return EEM_Registration::instance()->count($query_params);
279 279
 	}
280 280
 
281 281
 
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * @param \EE_Registration $item
285 285
 	 * @return string
286 286
 	 */
287
-	public function column__Reg_Status( EE_Registration $item ) {
288
-		return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
287
+	public function column__Reg_Status(EE_Registration $item) {
288
+		return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>';
289 289
 	}
290 290
 
291 291
 
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @return string
296 296
 	 * @throws \EE_Error
297 297
 	 */
298
-	public function column_cb( $item ) {
299
-		return sprintf( '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID() );
298
+	public function column_cb($item) {
299
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
300 300
 	}
301 301
 
302 302
 
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
      * @throws InvalidDataTypeException
312 312
      * @throws InvalidInterfaceException
313 313
      */
314
-	public function column__REG_att_checked_in( EE_Registration $item ) {
314
+	public function column__REG_att_checked_in(EE_Registration $item) {
315 315
 		$attendee = $item->attendee();
316 316
 		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
317 317
 
318
-		if ( $this->_cur_dtt_id === 0 && count( $this->_dtts_for_event ) === 1 ) {
318
+		if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
319 319
 			$latest_related_datetime = $item->get_latest_related_datetime();
320
-			if ( $latest_related_datetime instanceof EE_Datetime ) {
320
+			if ($latest_related_datetime instanceof EE_Datetime) {
321 321
 				$this->_cur_dtt_id = $latest_related_datetime->ID();
322 322
 			}
323 323
 		}
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 		    $item,
326 326
             $this->_cur_dtt_id
327 327
         );
328
-		$nonce = wp_create_nonce( 'checkin_nonce' );
329
-		$toggle_active = ! empty ( $this->_cur_dtt_id )
328
+		$nonce = wp_create_nonce('checkin_nonce');
329
+		$toggle_active = ! empty ($this->_cur_dtt_id)
330 330
 		                 && EE_Registry::instance()->CAP->current_user_can(
331 331
 			'ee_edit_checkin',
332 332
 			'espresso_registrations_toggle_checkin_status',
@@ -334,11 +334,11 @@  discard block
 block discarded – undo
334 334
 		)
335 335
 			? ' clickable trigger-checkin'
336 336
 			: '';
337
-		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
338
-		return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
339
-		       . ' data-_regid="' . $item->ID() . '"'
340
-		       . ' data-dttid="' . $this->_cur_dtt_id . '"'
341
-		       . ' data-nonce="' . $nonce . '">'
337
+		$mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>';
338
+		return '<span class="'.$checkin_status_dashicon->cssClasses().$toggle_active.'"'
339
+		       . ' data-_regid="'.$item->ID().'"'
340
+		       . ' data-dttid="'.$this->_cur_dtt_id.'"'
341
+		       . ' data-nonce="'.$nonce.'">'
342 342
 		       . '</span>'
343 343
 		       . $mobile_view_content;
344 344
 	}
@@ -350,21 +350,21 @@  discard block
 block discarded – undo
350 350
 	 * @return mixed|string|void
351 351
 	 * @throws \EE_Error
352 352
 	 */
353
-	public function column_ATT_name( EE_Registration $item ) {
353
+	public function column_ATT_name(EE_Registration $item) {
354 354
 		$attendee = $item->attendee();
355
-		if ( ! $attendee instanceof EE_Attendee ) {
356
-			return __( 'No contact record for this registration.', 'event_espresso' );
355
+		if ( ! $attendee instanceof EE_Attendee) {
356
+			return __('No contact record for this registration.', 'event_espresso');
357 357
 		}
358 358
 		// edit attendee link
359 359
 		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
360
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
360
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
361 361
 			REG_ADMIN_URL
362 362
 		);
363 363
 		$name_link = EE_Registry::instance()->CAP->current_user_can(
364 364
 			'ee_edit_contacts',
365 365
 			'espresso_registrations_edit_attendee'
366 366
 		)
367
-			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
367
+			? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
368 368
 			    . $item->attendee()->full_name()
369 369
 			    . '</a>'
370 370
 			: $item->attendee()->full_name();
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
 			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
373 373
 			: '';
374 374
 		//add group details
375
-		$name_link .= '&nbsp;' . sprintf( __( '(%s of %s)', 'event_espresso' ), $item->count(), $item->group_size() );
375
+		$name_link .= '&nbsp;'.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
376 376
 		//add regcode
377 377
 		$link = EE_Admin_Page::add_query_args_and_nonce(
378
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
378
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
379 379
 			REG_ADMIN_URL
380 380
 		);
381 381
 		$name_link .= '<br>';
@@ -384,51 +384,51 @@  discard block
 block discarded – undo
384 384
 			'view_registration',
385 385
 			$item->ID()
386 386
 		)
387
-			? '<a href="' . $link . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
387
+			? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
388 388
 			  . $item->reg_code()
389 389
 			  . '</a>'
390 390
 			: $item->reg_code();
391 391
 		//status
392 392
 		$name_link .= '<br><span class="ee-status-text-small">';
393
-		$name_link .= EEH_Template::pretty_status( $item->status_ID(), false, 'sentence' );
393
+		$name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
394 394
 		$name_link .= '</span>';
395 395
 		$actions = array();
396 396
 		$DTT_ID = $this->_cur_dtt_id;
397
-		$latest_related_datetime = empty( $DTT_ID ) && ! empty( $this->_req_data['event_id'] ) && $item instanceof EE_Registration
397
+		$latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
398 398
 			? $item->get_latest_related_datetime()
399 399
 			: null;
400 400
 		$DTT_ID = $latest_related_datetime instanceof EE_Datetime
401 401
 			? $latest_related_datetime->ID()
402 402
 			: $DTT_ID;
403
-		if ( ! empty( $DTT_ID )
403
+		if ( ! empty($DTT_ID)
404 404
 		     && EE_Registry::instance()->CAP->current_user_can(
405 405
 				'ee_read_checkins',
406 406
 				'espresso_registrations_registration_checkins'
407 407
 			)
408 408
 		) {
409 409
 			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
410
-				array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID ),
410
+				array('action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID),
411 411
                 REG_ADMIN_URL
412 412
 			);
413 413
 			// get the timestamps for this registration's checkins, related to the selected datetime
414
-			$timestamps = $item->get_many_related( 'Checkin', array( array( 'DTT_ID' => $DTT_ID ) ) );
415
-			if( ! empty( $timestamps ) ) {
414
+			$timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
415
+			if ( ! empty($timestamps)) {
416 416
 				// get the last timestamp
417
-				$last_timestamp = end( $timestamps );
417
+				$last_timestamp = end($timestamps);
418 418
 				// checked in or checked out?
419
-				$checkin_status = $last_timestamp->get( 'CHK_in' )
420
-					? esc_html__( 'Checked In', 'event_espresso' )
421
-					: esc_html__( 'Checked Out', 'event_espresso' );
419
+				$checkin_status = $last_timestamp->get('CHK_in')
420
+					? esc_html__('Checked In', 'event_espresso')
421
+					: esc_html__('Checked Out', 'event_espresso');
422 422
 				// get timestamp string
423
-				$timestamp_string = $last_timestamp->get_datetime( 'CHK_timestamp' );
424
-				$actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' . esc_attr__(
423
+				$timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
424
+				$actions['checkin'] = '<a href="'.$checkin_list_url.'" title="'.esc_attr__(
425 425
 						'View this registrant\'s check-ins/checkouts for the datetime',
426 426
 						'event_espresso'
427
-					) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
427
+					).'">'.$checkin_status.': '.$timestamp_string.'</a>';
428 428
 			}
429 429
 		}
430
-		return ( ! empty( $DTT_ID ) && ! empty( $timestamps ) )
431
-			? sprintf( '%1$s %2$s', $name_link, $this->row_actions( $actions, true ) )
430
+		return ( ! empty($DTT_ID) && ! empty($timestamps))
431
+			? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
432 432
 			: $name_link;
433 433
 	}
434 434
 
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 	 * @param \EE_Registration $item
439 439
 	 * @return string
440 440
 	 */
441
-	public function column_ATT_email( EE_Registration $item ) {
441
+	public function column_ATT_email(EE_Registration $item) {
442 442
 		$attendee = $item->attendee();
443 443
 		return $attendee instanceof EE_Attendee ? $attendee->email() : '';
444 444
 	}
@@ -450,22 +450,22 @@  discard block
 block discarded – undo
450 450
 	 * @return bool|string
451 451
 	 * @throws \EE_Error
452 452
 	 */
453
-	public function column_Event( EE_Registration $item ) {
453
+	public function column_Event(EE_Registration $item) {
454 454
 		try {
455 455
 			$event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
456 456
 			$chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
457
-				array( 'action' => 'event_registrations', 'event_id' => $event->ID() ),
457
+				array('action' => 'event_registrations', 'event_id' => $event->ID()),
458 458
 				REG_ADMIN_URL
459 459
 			);
460 460
 			$event_label = EE_Registry::instance()->CAP->current_user_can(
461 461
 				'ee_read_checkins',
462 462
 				'espresso_registrations_registration_checkins'
463
-			) ? '<a href="' . $chkin_lnk_url . '" title="' . esc_attr__(
463
+			) ? '<a href="'.$chkin_lnk_url.'" title="'.esc_attr__(
464 464
 					'View Checkins for this Event',
465 465
 					'event_espresso'
466
-				) . '">' . $event->name() . '</a>' : $event->name();
467
-		} catch ( \EventEspresso\core\exceptions\EntityNotFoundException $e ) {
468
-			$event_label = esc_html__( 'Unknown', 'event_espresso' );
466
+				).'">'.$event->name().'</a>' : $event->name();
467
+		} catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
468
+			$event_label = esc_html__('Unknown', 'event_espresso');
469 469
 		}
470 470
 		return $event_label;
471 471
 	}
@@ -476,8 +476,8 @@  discard block
 block discarded – undo
476 476
 	 * @param \EE_Registration $item
477 477
 	 * @return mixed|string|void
478 478
 	 */
479
-	public function column_PRC_name( EE_Registration $item ) {
480
-		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __( "Unknown", "event_espresso" );
479
+	public function column_PRC_name(EE_Registration $item) {
480
+		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso");
481 481
 	}
482 482
 
483 483
 
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
 	 * @param \EE_Registration $item
489 489
 	 * @return string
490 490
 	 */
491
-	public function column__REG_final_price( EE_Registration $item ) {
492
-		return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
491
+	public function column__REG_final_price(EE_Registration $item) {
492
+		return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>';
493 493
 	}
494 494
 
495 495
 
@@ -501,13 +501,13 @@  discard block
 block discarded – undo
501 501
 	 * @return string
502 502
 	 * @throws \EE_Error
503 503
 	 */
504
-	public function column_TXN_paid( EE_Registration $item ) {
505
-		if ( $item->count() === 1 ) {
506
-			if ( $item->transaction()->paid() >= $item->transaction()->total() ) {
504
+	public function column_TXN_paid(EE_Registration $item) {
505
+		if ($item->count() === 1) {
506
+			if ($item->transaction()->paid() >= $item->transaction()->total()) {
507 507
 				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
508 508
 			} else {
509 509
 				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
510
-					array( 'action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID() ),
510
+					array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
511 511
 					TXN_ADMIN_URL
512 512
 				);
513 513
 				return EE_Registry::instance()->CAP->current_user_can(
@@ -520,13 +520,13 @@  discard block
 block discarded – undo
520 520
 				    . '" href="'
521 521
 				    . $view_txn_lnk_url
522 522
 				    . '"  title="'
523
-				    . esc_attr__( 'View Transaction', 'event_espresso' )
523
+				    . esc_attr__('View Transaction', 'event_espresso')
524 524
 				    . '">
525 525
 						'
526 526
 				    . $item->transaction()->pretty_paid()
527 527
 				    . '
528 528
 					</a>
529
-				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
529
+				<span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
530 530
 			}
531 531
 		} else {
532 532
 			return '<span class="reg-pad-rght"></span>';
@@ -542,13 +542,13 @@  discard block
 block discarded – undo
542 542
 	 * @return string
543 543
 	 * @throws \EE_Error
544 544
 	 */
545
-	public function column_TXN_total( EE_Registration $item ) {
545
+	public function column_TXN_total(EE_Registration $item) {
546 546
 		$txn = $item->transaction();
547
-		$view_txn_url = add_query_arg( array( 'action' => 'view_transaction', 'TXN_ID' => $txn->ID() ), TXN_ADMIN_URL );
548
-		if ( $item->get( 'REG_count' ) === 1 ) {
547
+		$view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
548
+		if ($item->get('REG_count') === 1) {
549 549
 			$line_total_obj = $txn->total_line_item();
550 550
 			$txn_total = $line_total_obj instanceof EE_Line_Item
551
-				? $line_total_obj->get_pretty( 'LIN_total' )
551
+				? $line_total_obj->get_pretty('LIN_total')
552 552
 				: __(
553 553
 					'View Transaction',
554 554
 					'event_espresso'
@@ -559,10 +559,10 @@  discard block
 block discarded – undo
559 559
 			) ? '<a href="'
560 560
 			    . $view_txn_url
561 561
 			    . '" title="'
562
-			    . esc_attr__( 'View Transaction', 'event_espresso' )
562
+			    . esc_attr__('View Transaction', 'event_espresso')
563 563
 			    . '"><span class="reg-pad-rght">'
564 564
 			    . $txn_total
565
-			    . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
565
+			    . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>';
566 566
 		} else {
567 567
 			return '<span class="reg-pad-rght"></span>';
568 568
 		}
Please login to merge, or discard this patch.
core/EE_Registry.core.php 1 patch
Indentation   +1579 added lines, -1579 removed lines patch added patch discarded remove patch
@@ -23,1585 +23,1585 @@
 block discarded – undo
23 23
 class EE_Registry implements ResettableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registry $_instance
28
-     */
29
-    private static $_instance;
30
-
31
-    /**
32
-     * @var EE_Dependency_Map $_dependency_map
33
-     */
34
-    protected $_dependency_map;
35
-
36
-    /**
37
-     * @var array $_class_abbreviations
38
-     */
39
-    protected $_class_abbreviations = array();
40
-
41
-    /**
42
-     * @var CommandBusInterface $BUS
43
-     */
44
-    public $BUS;
45
-
46
-    /**
47
-     * @var EE_Cart $CART
48
-     */
49
-    public $CART;
50
-
51
-    /**
52
-     * @var EE_Config $CFG
53
-     */
54
-    public $CFG;
55
-
56
-    /**
57
-     * @var EE_Network_Config $NET_CFG
58
-     */
59
-    public $NET_CFG;
60
-
61
-    /**
62
-     * StdClass object for storing library classes in
63
-     *
64
-     * @var StdClass $LIB
65
-     */
66
-    public $LIB;
67
-
68
-    /**
69
-     * @var EE_Request_Handler $REQ
70
-     */
71
-    public $REQ;
72
-
73
-    /**
74
-     * @var EE_Session $SSN
75
-     */
76
-    public $SSN;
77
-
78
-    /**
79
-     * @since 4.5.0
80
-     * @var EE_Capabilities $CAP
81
-     */
82
-    public $CAP;
83
-
84
-    /**
85
-     * @since 4.9.0
86
-     * @var EE_Message_Resource_Manager $MRM
87
-     */
88
-    public $MRM;
89
-
90
-
91
-    /**
92
-     * @var Registry $AssetsRegistry
93
-     */
94
-    public $AssetsRegistry;
95
-
96
-    /**
97
-     * StdClass object for holding addons which have registered themselves to work with EE core
98
-     *
99
-     * @var EE_Addon[] $addons
100
-     */
101
-    public $addons;
102
-
103
-    /**
104
-     * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
105
-     *
106
-     * @var EEM_Base[] $models
107
-     */
108
-    public $models = array();
109
-
110
-    /**
111
-     * @var EED_Module[] $modules
112
-     */
113
-    public $modules;
114
-
115
-    /**
116
-     * @var EES_Shortcode[] $shortcodes
117
-     */
118
-    public $shortcodes;
119
-
120
-    /**
121
-     * @var WP_Widget[] $widgets
122
-     */
123
-    public $widgets;
124
-
125
-    /**
126
-     * this is an array of all implemented model names (i.e. not the parent abstract models, or models
127
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
128
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
129
-     * classnames (eg "EEM_Event")
130
-     *
131
-     * @var array $non_abstract_db_models
132
-     */
133
-    public $non_abstract_db_models = array();
134
-
135
-
136
-    /**
137
-     * internationalization for JS strings
138
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
139
-     *    in js file:  var translatedString = eei18n.string_key;
140
-     *
141
-     * @var array $i18n_js_strings
142
-     */
143
-    public static $i18n_js_strings = array();
144
-
145
-
146
-    /**
147
-     * $main_file - path to espresso.php
148
-     *
149
-     * @var array $main_file
150
-     */
151
-    public $main_file;
152
-
153
-    /**
154
-     * array of ReflectionClass objects where the key is the class name
155
-     *
156
-     * @var ReflectionClass[] $_reflectors
157
-     */
158
-    public $_reflectors;
159
-
160
-    /**
161
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
162
-     *
163
-     * @var boolean $_cache_on
164
-     */
165
-    protected $_cache_on = true;
166
-
167
-
168
-
169
-    /**
170
-     * @singleton method used to instantiate class object
171
-     * @param  EE_Dependency_Map $dependency_map
172
-     * @return EE_Registry instance
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidInterfaceException
175
-     * @throws InvalidDataTypeException
176
-     */
177
-    public static function instance(EE_Dependency_Map $dependency_map = null)
178
-    {
179
-        // check if class object is instantiated
180
-        if (! self::$_instance instanceof EE_Registry) {
181
-            self::$_instance = new self($dependency_map);
182
-        }
183
-        return self::$_instance;
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * protected constructor to prevent direct creation
190
-     *
191
-     * @Constructor
192
-     * @param  EE_Dependency_Map $dependency_map
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws InvalidArgumentException
196
-     */
197
-    protected function __construct(EE_Dependency_Map $dependency_map)
198
-    {
199
-        $this->_dependency_map = $dependency_map;
200
-        // $registry_container = new RegistryContainer();
201
-        $this->LIB = new RegistryContainer();
202
-        $this->addons = new RegistryContainer();
203
-        $this->modules = new RegistryContainer();
204
-        $this->shortcodes = new RegistryContainer();
205
-        $this->widgets = new RegistryContainer();
206
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * initialize
213
-     *
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public function initialize()
218
-    {
219
-        $this->_class_abbreviations = apply_filters(
220
-            'FHEE__EE_Registry____construct___class_abbreviations',
221
-            array(
222
-                'EE_Config'                                       => 'CFG',
223
-                'EE_Session'                                      => 'SSN',
224
-                'EE_Capabilities'                                 => 'CAP',
225
-                'EE_Cart'                                         => 'CART',
226
-                'EE_Network_Config'                               => 'NET_CFG',
227
-                'EE_Request_Handler'                              => 'REQ',
228
-                'EE_Message_Resource_Manager'                     => 'MRM',
229
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
230
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
231
-            )
232
-        );
233
-        $this->load_core('Base', array(), true);
234
-        // add our request and response objects to the cache
235
-        $request_loader = $this->_dependency_map->class_loader('EE_Request');
236
-        $this->_set_cached_class(
237
-            $request_loader(),
238
-            'EE_Request'
239
-        );
240
-        $response_loader = $this->_dependency_map->class_loader('EE_Response');
241
-        $this->_set_cached_class(
242
-            $response_loader(),
243
-            'EE_Response'
244
-        );
245
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * @return void
252
-     */
253
-    public function init()
254
-    {
255
-        // Get current page protocol
256
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
257
-        // Output admin-ajax.php URL with same protocol as current page
258
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
259
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
260
-    }
261
-
262
-
263
-
264
-    /**
265
-     * localize_i18n_js_strings
266
-     *
267
-     * @return string
268
-     */
269
-    public static function localize_i18n_js_strings()
270
-    {
271
-        $i18n_js_strings = (array)self::$i18n_js_strings;
272
-        foreach ($i18n_js_strings as $key => $value) {
273
-            if (is_scalar($value)) {
274
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
275
-            }
276
-        }
277
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
278
-    }
279
-
280
-
281
-
282
-    /**
283
-     * @param mixed string | EED_Module $module
284
-     * @throws EE_Error
285
-     * @throws ReflectionException
286
-     */
287
-    public function add_module($module)
288
-    {
289
-        if ($module instanceof EED_Module) {
290
-            $module_class = get_class($module);
291
-            $this->modules->{$module_class} = $module;
292
-        } else {
293
-            if ( ! class_exists('EE_Module_Request_Router', false)) {
294
-                $this->load_core('Module_Request_Router');
295
-            }
296
-            EE_Module_Request_Router::module_factory($module);
297
-        }
298
-    }
299
-
300
-
301
-
302
-    /**
303
-     * @param string $module_name
304
-     * @return mixed EED_Module | NULL
305
-     */
306
-    public function get_module($module_name = '')
307
-    {
308
-        return isset($this->modules->{$module_name})
309
-            ? $this->modules->{$module_name}
310
-            : null;
311
-    }
312
-
313
-
314
-
315
-    /**
316
-     * loads core classes - must be singletons
317
-     *
318
-     * @param string $class_name - simple class name ie: session
319
-     * @param mixed  $arguments
320
-     * @param bool   $load_only
321
-     * @return mixed
322
-     * @throws EE_Error
323
-     * @throws ReflectionException
324
-     */
325
-    public function load_core($class_name, $arguments = array(), $load_only = false)
326
-    {
327
-        $core_paths = apply_filters(
328
-            'FHEE__EE_Registry__load_core__core_paths',
329
-            array(
330
-                EE_CORE,
331
-                EE_ADMIN,
332
-                EE_CPTS,
333
-                EE_CORE . 'data_migration_scripts' . DS,
334
-                EE_CORE . 'capabilities' . DS,
335
-                EE_CORE . 'request_stack' . DS,
336
-                EE_CORE . 'middleware' . DS,
337
-            )
338
-        );
339
-        // retrieve instantiated class
340
-        return $this->_load(
341
-            $core_paths,
342
-            'EE_',
343
-            $class_name,
344
-            'core',
345
-            $arguments,
346
-            false,
347
-            true,
348
-            $load_only
349
-        );
350
-    }
351
-
352
-
353
-
354
-    /**
355
-     * loads service classes
356
-     *
357
-     * @param string $class_name - simple class name ie: session
358
-     * @param mixed  $arguments
359
-     * @param bool   $load_only
360
-     * @return mixed
361
-     * @throws EE_Error
362
-     * @throws ReflectionException
363
-     */
364
-    public function load_service($class_name, $arguments = array(), $load_only = false)
365
-    {
366
-        $service_paths = apply_filters(
367
-            'FHEE__EE_Registry__load_service__service_paths',
368
-            array(
369
-                EE_CORE . 'services' . DS,
370
-            )
371
-        );
372
-        // retrieve instantiated class
373
-        return $this->_load(
374
-            $service_paths,
375
-            'EE_',
376
-            $class_name,
377
-            'class',
378
-            $arguments,
379
-            false,
380
-            true,
381
-            $load_only
382
-        );
383
-    }
384
-
385
-
386
-
387
-    /**
388
-     * loads data_migration_scripts
389
-     *
390
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
391
-     * @param mixed  $arguments
392
-     * @return EE_Data_Migration_Script_Base|mixed
393
-     * @throws EE_Error
394
-     * @throws ReflectionException
395
-     */
396
-    public function load_dms($class_name, $arguments = array())
397
-    {
398
-        // retrieve instantiated class
399
-        return $this->_load(
400
-            EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
401
-            'EE_DMS_',
402
-            $class_name,
403
-            'dms',
404
-            $arguments,
405
-            false,
406
-            false
407
-        );
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * loads object creating classes - must be singletons
414
-     *
415
-     * @param string $class_name - simple class name ie: attendee
416
-     * @param mixed  $arguments  - an array of arguments to pass to the class
417
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
418
-     *                           instantiate
419
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
420
-     *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
421
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
422
-     *                           (default)
423
-     * @return EE_Base_Class | bool
424
-     * @throws EE_Error
425
-     * @throws ReflectionException
426
-     */
427
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
428
-    {
429
-        $paths = apply_filters(
430
-            'FHEE__EE_Registry__load_class__paths', array(
431
-            EE_CORE,
432
-            EE_CLASSES,
433
-            EE_BUSINESS,
434
-        )
435
-        );
436
-        // retrieve instantiated class
437
-        return $this->_load(
438
-            $paths,
439
-            'EE_',
440
-            $class_name,
441
-            'class',
442
-            $arguments,
443
-            $from_db,
444
-            $cache,
445
-            $load_only
446
-        );
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     * loads helper classes - must be singletons
453
-     *
454
-     * @param string $class_name - simple class name ie: price
455
-     * @param mixed  $arguments
456
-     * @param bool   $load_only
457
-     * @return EEH_Base | bool
458
-     * @throws EE_Error
459
-     * @throws ReflectionException
460
-     */
461
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
462
-    {
463
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
464
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
465
-        // retrieve instantiated class
466
-        return $this->_load(
467
-            $helper_paths,
468
-            'EEH_',
469
-            $class_name,
470
-            'helper',
471
-            $arguments,
472
-            false,
473
-            true,
474
-            $load_only
475
-        );
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * loads core classes - must be singletons
482
-     *
483
-     * @param string $class_name - simple class name ie: session
484
-     * @param mixed  $arguments
485
-     * @param bool   $load_only
486
-     * @param bool   $cache      whether to cache the object or not.
487
-     * @return mixed
488
-     * @throws EE_Error
489
-     * @throws ReflectionException
490
-     */
491
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
492
-    {
493
-        $paths = array(
494
-            EE_LIBRARIES,
495
-            EE_LIBRARIES . 'messages' . DS,
496
-            EE_LIBRARIES . 'shortcodes' . DS,
497
-            EE_LIBRARIES . 'qtips' . DS,
498
-            EE_LIBRARIES . 'payment_methods' . DS,
499
-        );
500
-        // retrieve instantiated class
501
-        return $this->_load(
502
-            $paths,
503
-            'EE_',
504
-            $class_name,
505
-            'lib',
506
-            $arguments,
507
-            false,
508
-            $cache,
509
-            $load_only
510
-        );
511
-    }
512
-
513
-
514
-
515
-    /**
516
-     * loads model classes - must be singletons
517
-     *
518
-     * @param string $class_name - simple class name ie: price
519
-     * @param mixed  $arguments
520
-     * @param bool   $load_only
521
-     * @return EEM_Base | bool
522
-     * @throws EE_Error
523
-     * @throws ReflectionException
524
-     */
525
-    public function load_model($class_name, $arguments = array(), $load_only = false)
526
-    {
527
-        $paths = apply_filters(
528
-            'FHEE__EE_Registry__load_model__paths', array(
529
-            EE_MODELS,
530
-            EE_CORE,
531
-        )
532
-        );
533
-        // retrieve instantiated class
534
-        return $this->_load(
535
-            $paths,
536
-            'EEM_',
537
-            $class_name,
538
-            'model',
539
-            $arguments,
540
-            false,
541
-            true,
542
-            $load_only
543
-        );
544
-    }
545
-
546
-
547
-
548
-    /**
549
-     * loads model classes - must be singletons
550
-     *
551
-     * @param string $class_name - simple class name ie: price
552
-     * @param mixed  $arguments
553
-     * @param bool   $load_only
554
-     * @return mixed | bool
555
-     * @throws EE_Error
556
-     * @throws ReflectionException
557
-     */
558
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
559
-    {
560
-        $paths = array(
561
-            EE_MODELS . 'fields' . DS,
562
-            EE_MODELS . 'helpers' . DS,
563
-            EE_MODELS . 'relations' . DS,
564
-            EE_MODELS . 'strategies' . DS,
565
-        );
566
-        // retrieve instantiated class
567
-        return $this->_load(
568
-            $paths,
569
-            'EE_',
570
-            $class_name,
571
-            '',
572
-            $arguments,
573
-            false,
574
-            true,
575
-            $load_only
576
-        );
577
-    }
578
-
579
-
580
-
581
-    /**
582
-     * Determines if $model_name is the name of an actual EE model.
583
-     *
584
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
585
-     * @return boolean
586
-     */
587
-    public function is_model_name($model_name)
588
-    {
589
-        return isset($this->models[$model_name]);
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     * generic class loader
596
-     *
597
-     * @param string $path_to_file - directory path to file location, not including filename
598
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
599
-     * @param string $type         - file type - core? class? helper? model?
600
-     * @param mixed  $arguments
601
-     * @param bool   $load_only
602
-     * @return mixed
603
-     * @throws EE_Error
604
-     * @throws ReflectionException
605
-     */
606
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
607
-    {
608
-        // retrieve instantiated class
609
-        return $this->_load(
610
-            $path_to_file,
611
-            '',
612
-            $file_name,
613
-            $type,
614
-            $arguments,
615
-            false,
616
-            true,
617
-            $load_only
618
-        );
619
-    }
620
-
621
-
622
-
623
-    /**
624
-     * @param string $path_to_file - directory path to file location, not including filename
625
-     * @param string $class_name   - full class name  ie:  My_Class
626
-     * @param string $type         - file type - core? class? helper? model?
627
-     * @param mixed  $arguments
628
-     * @param bool   $load_only
629
-     * @return bool|EE_Addon|object
630
-     * @throws EE_Error
631
-     * @throws ReflectionException
632
-     */
633
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
634
-    {
635
-        // retrieve instantiated class
636
-        return $this->_load(
637
-            $path_to_file,
638
-            'addon',
639
-            $class_name,
640
-            $type,
641
-            $arguments,
642
-            false,
643
-            true,
644
-            $load_only
645
-        );
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * instantiates, caches, and automatically resolves dependencies
652
-     * for classes that use a Fully Qualified Class Name.
653
-     * if the class is not capable of being loaded using PSR-4 autoloading,
654
-     * then you need to use one of the existing load_*() methods
655
-     * which can resolve the classname and filepath from the passed arguments
656
-     *
657
-     * @param bool|string $class_name   Fully Qualified Class Name
658
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
659
-     * @param bool        $cache        whether to cache the instantiated object for reuse
660
-     * @param bool        $from_db      some classes are instantiated from the db
661
-     *                                  and thus call a different method to instantiate
662
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
663
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
664
-     * @return bool|null|mixed          null = failure to load or instantiate class object.
665
-     *                                  object = class loaded and instantiated successfully.
666
-     *                                  bool = fail or success when $load_only is true
667
-     * @throws EE_Error
668
-     * @throws ReflectionException
669
-     */
670
-    public function create(
671
-        $class_name = false,
672
-        $arguments = array(),
673
-        $cache = false,
674
-        $from_db = false,
675
-        $load_only = false,
676
-        $addon = false
677
-    ) {
678
-        $class_name = ltrim($class_name, '\\');
679
-        $class_name = $this->_dependency_map->get_alias($class_name);
680
-        $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
681
-        // if a non-FQCN was passed, then verifyClassExists() might return an object
682
-        // or it could return null if the class just could not be found anywhere
683
-        if ($class_exists instanceof $class_name || $class_exists === null){
684
-            // either way, return the results
685
-            return $class_exists;
686
-        }
687
-        $class_name = $class_exists;
688
-        // if we're only loading the class and it already exists, then let's just return true immediately
689
-        if ($load_only) {
690
-            return true;
691
-        }
692
-        $addon = $addon
693
-            ? 'addon'
694
-            : '';
695
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
696
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
697
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
698
-        if ($this->_cache_on && $cache && ! $load_only) {
699
-            // return object if it's already cached
700
-            $cached_class = $this->_get_cached_class($class_name, $addon);
701
-            if ($cached_class !== null) {
702
-                return $cached_class;
703
-            }
704
-        }
705
-        // obtain the loader method from the dependency map
706
-        $loader = $this->_dependency_map->class_loader($class_name);
707
-        // instantiate the requested object
708
-        if ($loader instanceof Closure) {
709
-            $class_obj = $loader($arguments);
710
-        } else if ($loader && method_exists($this, $loader)) {
711
-            $class_obj = $this->{$loader}($class_name, $arguments);
712
-        } else {
713
-            $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
714
-        }
715
-        if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
716
-            // save it for later... kinda like gum  { : $
717
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
718
-        }
719
-        $this->_cache_on = true;
720
-        return $class_obj;
721
-    }
722
-
723
-
724
-
725
-    /**
726
-     * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
727
-     *
728
-     * @param string $class_name
729
-     * @param array  $arguments
730
-     * @param int    $attempt
731
-     * @return mixed
732
-     */
733
-    private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
734
-        if (is_object($class_name) || class_exists($class_name)) {
735
-            return $class_name;
736
-        }
737
-        switch ($attempt) {
738
-            case 1:
739
-                // if it's a FQCN then maybe the class is registered with a preceding \
740
-                $class_name = strpos($class_name, '\\') !== false
741
-                    ? '\\' . ltrim($class_name, '\\')
742
-                    : $class_name;
743
-                break;
744
-            case 2:
745
-                //
746
-                $loader = $this->_dependency_map->class_loader($class_name);
747
-                if ($loader && method_exists($this, $loader)) {
748
-                    return $this->{$loader}($class_name, $arguments);
749
-                }
750
-                break;
751
-            case 3:
752
-            default;
753
-                return null;
754
-        }
755
-        $attempt++;
756
-        return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
757
-    }
758
-
759
-
760
-
761
-    /**
762
-     * instantiates, caches, and injects dependencies for classes
763
-     *
764
-     * @param array       $file_paths   an array of paths to folders to look in
765
-     * @param string      $class_prefix EE  or EEM or... ???
766
-     * @param bool|string $class_name   $class name
767
-     * @param string      $type         file type - core? class? helper? model?
768
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
769
-     * @param bool        $from_db      some classes are instantiated from the db
770
-     *                                  and thus call a different method to instantiate
771
-     * @param bool        $cache        whether to cache the instantiated object for reuse
772
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
773
-     * @return bool|null|object null = failure to load or instantiate class object.
774
-     *                                  object = class loaded and instantiated successfully.
775
-     *                                  bool = fail or success when $load_only is true
776
-     * @throws EE_Error
777
-     * @throws ReflectionException
778
-     */
779
-    protected function _load(
780
-        $file_paths = array(),
781
-        $class_prefix = 'EE_',
782
-        $class_name = false,
783
-        $type = 'class',
784
-        $arguments = array(),
785
-        $from_db = false,
786
-        $cache = true,
787
-        $load_only = false
788
-    ) {
789
-        $class_name = ltrim($class_name, '\\');
790
-        // strip php file extension
791
-        $class_name = str_replace('.php', '', trim($class_name));
792
-        // does the class have a prefix ?
793
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
794
-            // make sure $class_prefix is uppercase
795
-            $class_prefix = strtoupper(trim($class_prefix));
796
-            // add class prefix ONCE!!!
797
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
798
-        }
799
-        $class_name = $this->_dependency_map->get_alias($class_name);
800
-        $class_exists = class_exists($class_name, false);
801
-        // if we're only loading the class and it already exists, then let's just return true immediately
802
-        if ($load_only && $class_exists) {
803
-            return true;
804
-        }
805
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
806
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
807
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
808
-        if ($this->_cache_on && $cache && ! $load_only) {
809
-            // return object if it's already cached
810
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
811
-            if ($cached_class !== null) {
812
-                return $cached_class;
813
-            }
814
-        }
815
-        // if the class doesn't already exist.. then we need to try and find the file and load it
816
-        if (! $class_exists) {
817
-            // get full path to file
818
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
819
-            // load the file
820
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
821
-            // if loading failed, or we are only loading a file but NOT instantiating an object
822
-            if (! $loaded || $load_only) {
823
-                // return boolean if only loading, or null if an object was expected
824
-                return $load_only
825
-                    ? $loaded
826
-                    : null;
827
-            }
828
-        }
829
-        // instantiate the requested object
830
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
831
-        if ($this->_cache_on && $cache) {
832
-            // save it for later... kinda like gum  { : $
833
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
834
-        }
835
-        $this->_cache_on = true;
836
-        return $class_obj;
837
-    }
838
-
839
-
840
-
841
-    /**
842
-     * @param string $class_name
843
-     * @param string $default have to specify something, but not anything that will conflict
844
-     * @return mixed|string
845
-     */
846
-    protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
847
-    {
848
-        return isset($this->_class_abbreviations[$class_name])
849
-            ? $this->_class_abbreviations[$class_name]
850
-            : $default;
851
-    }
852
-
853
-    /**
854
-     * attempts to find a cached version of the requested class
855
-     * by looking in the following places:
856
-     *        $this->{$class_abbreviation}            ie:    $this->CART
857
-     *        $this->{$class_name}                        ie:    $this->Some_Class
858
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
859
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
860
-     *
861
-     * @param string $class_name
862
-     * @param string $class_prefix
863
-     * @return mixed
864
-     */
865
-    protected function _get_cached_class($class_name, $class_prefix = '')
866
-    {
867
-        if ($class_name === 'EE_Registry') {
868
-            return $this;
869
-        }
870
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
871
-        $class_name = str_replace('\\', '_', $class_name);
872
-        // check if class has already been loaded, and return it if it has been
873
-        if (isset($this->{$class_abbreviation})) {
874
-            return $this->{$class_abbreviation};
875
-        }
876
-        if (isset ($this->{$class_name})) {
877
-            return $this->{$class_name};
878
-        }
879
-        if (isset ($this->LIB->{$class_name})) {
880
-            return $this->LIB->{$class_name};
881
-        }
882
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
883
-            return $this->addons->{$class_name};
884
-        }
885
-        return null;
886
-    }
887
-
888
-
889
-
890
-    /**
891
-     * removes a cached version of the requested class
892
-     *
893
-     * @param string  $class_name
894
-     * @param boolean $addon
895
-     * @return boolean
896
-     */
897
-    public function clear_cached_class($class_name, $addon = false)
898
-    {
899
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
900
-        $class_name = str_replace('\\', '_', $class_name);
901
-        // check if class has already been loaded, and return it if it has been
902
-        if (isset($this->{$class_abbreviation})) {
903
-            $this->{$class_abbreviation} = null;
904
-            return true;
905
-        }
906
-        if (isset($this->{$class_name})) {
907
-            $this->{$class_name} = null;
908
-            return true;
909
-        }
910
-        if (isset($this->LIB->{$class_name})) {
911
-            unset($this->LIB->{$class_name});
912
-            return true;
913
-        }
914
-        if ($addon && isset($this->addons->{$class_name})) {
915
-            unset($this->addons->{$class_name});
916
-            return true;
917
-        }
918
-        return false;
919
-    }
920
-
921
-
922
-
923
-    /**
924
-     * attempts to find a full valid filepath for the requested class.
925
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
926
-     * then returns that path if the target file has been found and is readable
927
-     *
928
-     * @param string $class_name
929
-     * @param string $type
930
-     * @param array  $file_paths
931
-     * @return string | bool
932
-     */
933
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
934
-    {
935
-        // make sure $file_paths is an array
936
-        $file_paths = is_array($file_paths)
937
-            ? $file_paths
938
-            : array($file_paths);
939
-        // cycle thru paths
940
-        foreach ($file_paths as $key => $file_path) {
941
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
942
-            $file_path = $file_path
943
-                ? str_replace(array('/', '\\'), DS, $file_path)
944
-                : EE_CLASSES;
945
-            // prep file type
946
-            $type = ! empty($type)
947
-                ? trim($type, '.') . '.'
948
-                : '';
949
-            // build full file path
950
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
951
-            //does the file exist and can be read ?
952
-            if (is_readable($file_paths[$key])) {
953
-                return $file_paths[$key];
954
-            }
955
-        }
956
-        return false;
957
-    }
958
-
959
-
960
-
961
-    /**
962
-     * basically just performs a require_once()
963
-     * but with some error handling
964
-     *
965
-     * @param  string $path
966
-     * @param  string $class_name
967
-     * @param  string $type
968
-     * @param  array  $file_paths
969
-     * @return bool
970
-     * @throws EE_Error
971
-     * @throws ReflectionException
972
-     */
973
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
974
-    {
975
-        $this->resolve_legacy_class_parent($class_name);
976
-        // don't give up! you gotta...
977
-        try {
978
-            //does the file exist and can it be read ?
979
-            if (! $path) {
980
-                // just in case the file has already been autoloaded,
981
-                // but discrepancies in the naming schema are preventing it from
982
-                // being loaded via one of the EE_Registry::load_*() methods,
983
-                // then let's try one last hail mary before throwing an exception
984
-                // and call class_exists() again, but with autoloading turned ON
985
-                if(class_exists($class_name)) {
986
-                    return true;
987
-                }
988
-                // so sorry, can't find the file
989
-                throw new EE_Error (
990
-                    sprintf(
991
-                        esc_html__(
992
-                            'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
993
-                            'event_espresso'
994
-                        ),
995
-                        trim($type, '.'),
996
-                        $class_name,
997
-                        '<br />' . implode(',<br />', $file_paths)
998
-                    )
999
-                );
1000
-            }
1001
-            // get the file
1002
-            require_once($path);
1003
-            // if the class isn't already declared somewhere
1004
-            if (class_exists($class_name, false) === false) {
1005
-                // so sorry, not a class
1006
-                throw new EE_Error(
1007
-                    sprintf(
1008
-                        esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1009
-                        $type,
1010
-                        $path,
1011
-                        $class_name
1012
-                    )
1013
-                );
1014
-            }
1015
-        } catch (EE_Error $e) {
1016
-            $e->get_error();
1017
-            return false;
1018
-        }
1019
-        return true;
1020
-    }
1021
-
1022
-
1023
-
1024
-    /**
1025
-     * Some of our legacy classes that extended a parent class would simply use a require() statement
1026
-     * before their class declaration in order to ensure that the parent class was loaded.
1027
-     * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1028
-     * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1029
-     *
1030
-     * @param string $class_name
1031
-     */
1032
-    protected function resolve_legacy_class_parent($class_name = '')
1033
-    {
1034
-        try {
1035
-            $legacy_parent_class_map = array(
1036
-                'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1037
-            );
1038
-            if(isset($legacy_parent_class_map[$class_name])) {
1039
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1040
-            }
1041
-        } catch (Exception $exception) {
1042
-        }
1043
-    }
1044
-
1045
-
1046
-
1047
-    /**
1048
-     * _create_object
1049
-     * Attempts to instantiate the requested class via any of the
1050
-     * commonly used instantiation methods employed throughout EE.
1051
-     * The priority for instantiation is as follows:
1052
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1053
-     *        - model objects via their 'new_instance_from_db' method
1054
-     *        - model objects via their 'new_instance' method
1055
-     *        - "singleton" classes" via their 'instance' method
1056
-     *    - standard instantiable classes via their __constructor
1057
-     * Prior to instantiation, if the classname exists in the dependency_map,
1058
-     * then the constructor for the requested class will be examined to determine
1059
-     * if any dependencies exist, and if they can be injected.
1060
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1061
-     *
1062
-     * @param string $class_name
1063
-     * @param array  $arguments
1064
-     * @param string $type
1065
-     * @param bool   $from_db
1066
-     * @return null|object
1067
-     * @throws EE_Error
1068
-     * @throws ReflectionException
1069
-     */
1070
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1071
-    {
1072
-        // create reflection
1073
-        $reflector = $this->get_ReflectionClass($class_name);
1074
-        // make sure arguments are an array
1075
-        $arguments = is_array($arguments)
1076
-            ? $arguments
1077
-            : array($arguments);
1078
-        // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1079
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
1080
-        $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1081
-            ? $arguments
1082
-            : array($arguments);
1083
-        // attempt to inject dependencies ?
1084
-        if ($this->_dependency_map->has($class_name)) {
1085
-            $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1086
-        }
1087
-        // instantiate the class if possible
1088
-        if ($reflector->isAbstract()) {
1089
-            // nothing to instantiate, loading file was enough
1090
-            // does not throw an exception so $instantiation_mode is unused
1091
-            // $instantiation_mode = "1) no constructor abstract class";
1092
-            return true;
1093
-        }
1094
-        if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1095
-            // no constructor = static methods only... nothing to instantiate, loading file was enough
1096
-            // $instantiation_mode = "2) no constructor but instantiable";
1097
-            return $reflector->newInstance();
1098
-        }
1099
-        if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1100
-            // $instantiation_mode = "3) new_instance_from_db()";
1101
-            return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1102
-        }
1103
-        if (method_exists($class_name, 'new_instance')) {
1104
-            // $instantiation_mode = "4) new_instance()";
1105
-            return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1106
-        }
1107
-        if (method_exists($class_name, 'instance')) {
1108
-            // $instantiation_mode = "5) instance()";
1109
-            return call_user_func_array(array($class_name, 'instance'), $arguments);
1110
-        }
1111
-        if ($reflector->isInstantiable()) {
1112
-            // $instantiation_mode = "6) constructor";
1113
-            return $reflector->newInstanceArgs($arguments);
1114
-        }
1115
-        // heh ? something's not right !
1116
-        throw new EE_Error(
1117
-            sprintf(
1118
-                __('The %s file %s could not be instantiated.', 'event_espresso'),
1119
-                $type,
1120
-                $class_name
1121
-            )
1122
-        );
1123
-    }
1124
-
1125
-
1126
-
1127
-    /**
1128
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1129
-     * @param array $array
1130
-     * @return bool
1131
-     */
1132
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1133
-    {
1134
-        return ! empty($array)
1135
-            ? array_keys($array) === range(0, count($array) - 1)
1136
-            : true;
1137
-    }
1138
-
1139
-
1140
-
1141
-    /**
1142
-     * getReflectionClass
1143
-     * checks if a ReflectionClass object has already been generated for a class
1144
-     * and returns that instead of creating a new one
1145
-     *
1146
-     * @param string $class_name
1147
-     * @return ReflectionClass
1148
-     * @throws ReflectionException
1149
-     */
1150
-    public function get_ReflectionClass($class_name)
1151
-    {
1152
-        if (
1153
-            ! isset($this->_reflectors[$class_name])
1154
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
1155
-        ) {
1156
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
1157
-        }
1158
-        return $this->_reflectors[$class_name];
1159
-    }
1160
-
1161
-
1162
-
1163
-    /**
1164
-     * _resolve_dependencies
1165
-     * examines the constructor for the requested class to determine
1166
-     * if any dependencies exist, and if they can be injected.
1167
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1168
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1169
-     * For example:
1170
-     *        if attempting to load a class "Foo" with the following constructor:
1171
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1172
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1173
-     *        but only IF they are NOT already present in the incoming arguments array,
1174
-     *        and the correct classes can be loaded
1175
-     *
1176
-     * @param ReflectionClass $reflector
1177
-     * @param string          $class_name
1178
-     * @param array           $arguments
1179
-     * @return array
1180
-     * @throws EE_Error
1181
-     * @throws ReflectionException
1182
-     */
1183
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1184
-    {
1185
-        // let's examine the constructor
1186
-        $constructor = $reflector->getConstructor();
1187
-        // whu? huh? nothing?
1188
-        if (! $constructor) {
1189
-            return $arguments;
1190
-        }
1191
-        // get constructor parameters
1192
-        $params = $constructor->getParameters();
1193
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1194
-        $argument_keys = array_keys($arguments);
1195
-        // now loop thru all of the constructors expected parameters
1196
-        foreach ($params as $index => $param) {
1197
-            // is this a dependency for a specific class ?
1198
-            $param_class = $param->getClass()
1199
-                ? $param->getClass()->name
1200
-                : null;
1201
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1202
-            $param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1203
-                ? $this->_dependency_map->get_alias($param_class, $class_name)
1204
-                : $param_class;
1205
-            if (
1206
-                // param is not even a class
1207
-                $param_class === null
1208
-                // and something already exists in the incoming arguments for this param
1209
-                && array_key_exists($index, $argument_keys)
1210
-                && array_key_exists($argument_keys[$index], $arguments)
1211
-            ) {
1212
-                // so let's skip this argument and move on to the next
1213
-                continue;
1214
-            }
1215
-            if (
1216
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1217
-                $param_class !== null
1218
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1219
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1220
-            ) {
1221
-                // skip this argument and move on to the next
1222
-                continue;
1223
-            }
1224
-            if (
1225
-                // parameter is type hinted as a class, and should be injected
1226
-                $param_class !== null
1227
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1228
-            ) {
1229
-                $arguments = $this->_resolve_dependency(
1230
-                    $class_name,
1231
-                    $param_class,
1232
-                    $arguments,
1233
-                    $index,
1234
-                    $argument_keys
1235
-                );
1236
-            } else {
1237
-                try {
1238
-                    $arguments[$index] = $param->isDefaultValueAvailable()
1239
-                        ? $param->getDefaultValue()
1240
-                        : null;
1241
-                } catch (ReflectionException $e) {
1242
-                    throw new ReflectionException(
1243
-                        sprintf(
1244
-                            esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1245
-                            $e->getMessage(),
1246
-                            $param->getName(),
1247
-                            $class_name
1248
-                        )
1249
-                    );
1250
-                }
1251
-            }
1252
-        }
1253
-        return $arguments;
1254
-    }
1255
-
1256
-
1257
-
1258
-    /**
1259
-     * @param string $class_name
1260
-     * @param string $param_class
1261
-     * @param array  $arguments
1262
-     * @param mixed  $index
1263
-     * @param array  $argument_keys
1264
-     * @return array
1265
-     * @throws EE_Error
1266
-     * @throws ReflectionException
1267
-     * @throws InvalidArgumentException
1268
-     * @throws InvalidInterfaceException
1269
-     * @throws InvalidDataTypeException
1270
-     */
1271
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1272
-    {
1273
-        $dependency = null;
1274
-        // should dependency be loaded from cache ?
1275
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1276
-            $class_name,
1277
-            $param_class
1278
-        );
1279
-        $cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1280
-        // we might have a dependency...
1281
-        // let's MAYBE try and find it in our cache if that's what's been requested
1282
-        $cached_class = $cache_on
1283
-            ? $this->_get_cached_class($param_class)
1284
-            : null;
1285
-        // and grab it if it exists
1286
-        if ($cached_class instanceof $param_class) {
1287
-            $dependency = $cached_class;
1288
-        } else if ($param_class !== $class_name) {
1289
-            // obtain the loader method from the dependency map
1290
-            $loader = $this->_dependency_map->class_loader($param_class);
1291
-            // is loader a custom closure ?
1292
-            if ($loader instanceof Closure) {
1293
-                $dependency = $loader($arguments);
1294
-            } else {
1295
-                // set the cache on property for the recursive loading call
1296
-                $this->_cache_on = $cache_on;
1297
-                // if not, then let's try and load it via the registry
1298
-                if ($loader && method_exists($this, $loader)) {
1299
-                    $dependency = $this->{$loader}($param_class);
1300
-                } else {
1301
-                    $dependency = LoaderFactory::getLoader()->load(
1302
-                        $param_class,
1303
-                        array(),
1304
-                        $cache_on
1305
-                    );
1306
-                }
1307
-            }
1308
-        }
1309
-        // did we successfully find the correct dependency ?
1310
-        if ($dependency instanceof $param_class) {
1311
-            // then let's inject it into the incoming array of arguments at the correct location
1312
-            $arguments[$index] = $dependency;
1313
-        }
1314
-        return $arguments;
1315
-    }
1316
-
1317
-
1318
-
1319
-    /**
1320
-     * _set_cached_class
1321
-     * attempts to cache the instantiated class locally
1322
-     * in one of the following places, in the following order:
1323
-     *        $this->{class_abbreviation}   ie:    $this->CART
1324
-     *        $this->{$class_name}          ie:    $this->Some_Class
1325
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1326
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1327
-     *
1328
-     * @param object $class_obj
1329
-     * @param string $class_name
1330
-     * @param string $class_prefix
1331
-     * @param bool   $from_db
1332
-     * @return void
1333
-     */
1334
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1335
-    {
1336
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1337
-            return;
1338
-        }
1339
-        // return newly instantiated class
1340
-        $class_abbreviation = $this->get_class_abbreviation($class_name, '');
1341
-        if ($class_abbreviation) {
1342
-            $this->{$class_abbreviation} = $class_obj;
1343
-            return;
1344
-        }
1345
-        $class_name = str_replace('\\', '_', $class_name);
1346
-        if (property_exists($this, $class_name)) {
1347
-            $this->{$class_name} = $class_obj;
1348
-            return;
1349
-        }
1350
-        if ($class_prefix === 'addon') {
1351
-            $this->addons->{$class_name} = $class_obj;
1352
-            return;
1353
-        }
1354
-        if (! $from_db) {
1355
-            $this->LIB->{$class_name} = $class_obj;
1356
-        }
1357
-    }
1358
-
1359
-
1360
-
1361
-    /**
1362
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1363
-     *
1364
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1365
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1366
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1367
-     * @param array  $arguments
1368
-     * @return object
1369
-     */
1370
-    public static function factory($classname, $arguments = array())
1371
-    {
1372
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1373
-        if ($loader instanceof Closure) {
1374
-            return $loader($arguments);
1375
-        }
1376
-        if (method_exists(self::instance(), $loader)) {
1377
-            return self::instance()->{$loader}($classname, $arguments);
1378
-        }
1379
-        return null;
1380
-    }
1381
-
1382
-
1383
-
1384
-    /**
1385
-     * Gets the addon by its class name
1386
-     *
1387
-     * @param string $class_name
1388
-     * @return EE_Addon
1389
-     */
1390
-    public function getAddon($class_name)
1391
-    {
1392
-        $class_name = str_replace('\\', '_', $class_name);
1393
-        return $this->addons->{$class_name};
1394
-    }
1395
-
1396
-
1397
-    /**
1398
-     * removes the addon from the internal cache
1399
-     *
1400
-     * @param string $class_name
1401
-     * @return void
1402
-     */
1403
-    public function removeAddon($class_name)
1404
-    {
1405
-        $class_name = str_replace('\\', '_', $class_name);
1406
-        unset($this->addons->{$class_name});
1407
-    }
1408
-
1409
-
1410
-
1411
-    /**
1412
-     * Gets the addon by its name/slug (not classname. For that, just
1413
-     * use the get_addon() method above
1414
-     *
1415
-     * @param string $name
1416
-     * @return EE_Addon
1417
-     */
1418
-    public function get_addon_by_name($name)
1419
-    {
1420
-        foreach ($this->addons as $addon) {
1421
-            if ($addon->name() === $name) {
1422
-                return $addon;
1423
-            }
1424
-        }
1425
-        return null;
1426
-    }
1427
-
1428
-
1429
-
1430
-    /**
1431
-     * Gets an array of all the registered addons, where the keys are their names.
1432
-     * (ie, what each returns for their name() function)
1433
-     * They're already available on EE_Registry::instance()->addons as properties,
1434
-     * where each property's name is the addon's classname,
1435
-     * So if you just want to get the addon by classname,
1436
-     * OR use the get_addon() method above.
1437
-     * PLEASE  NOTE:
1438
-     * addons with Fully Qualified Class Names
1439
-     * have had the namespace separators converted to underscores,
1440
-     * so a classname like Fully\Qualified\ClassName
1441
-     * would have been converted to Fully_Qualified_ClassName
1442
-     *
1443
-     * @return EE_Addon[] where the KEYS are the addon's name()
1444
-     */
1445
-    public function get_addons_by_name()
1446
-    {
1447
-        $addons = array();
1448
-        foreach ($this->addons as $addon) {
1449
-            $addons[$addon->name()] = $addon;
1450
-        }
1451
-        return $addons;
1452
-    }
1453
-
1454
-
1455
-    /**
1456
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1457
-     * a stale copy of it around
1458
-     *
1459
-     * @param string $model_name
1460
-     * @return \EEM_Base
1461
-     * @throws \EE_Error
1462
-     */
1463
-    public function reset_model($model_name)
1464
-    {
1465
-        $model_class_name = strpos($model_name, 'EEM_') !== 0
1466
-            ? "EEM_{$model_name}"
1467
-            : $model_name;
1468
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1469
-            return null;
1470
-        }
1471
-        //get that model reset it and make sure we nuke the old reference to it
1472
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name
1473
-            && is_callable(
1474
-                array($model_class_name, 'reset')
1475
-            )) {
1476
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1477
-        } else {
1478
-            throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1479
-        }
1480
-        return $this->LIB->{$model_class_name};
1481
-    }
1482
-
1483
-
1484
-
1485
-    /**
1486
-     * Resets the registry.
1487
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when
1488
-     * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1489
-     * - $_dependency_map
1490
-     * - $_class_abbreviations
1491
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1492
-     * - $REQ:  Still on the same request so no need to change.
1493
-     * - $CAP: There is no site specific state in the EE_Capability class.
1494
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1495
-     * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1496
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1497
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1498
-     *             switch or on the restore.
1499
-     * - $modules
1500
-     * - $shortcodes
1501
-     * - $widgets
1502
-     *
1503
-     * @param boolean $hard             [deprecated]
1504
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1505
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1506
-     *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1507
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1508
-     *                                  client
1509
-     *                                  code instead can just change the model context to a different blog id if
1510
-     *                                  necessary
1511
-     * @return EE_Registry
1512
-     * @throws EE_Error
1513
-     * @throws ReflectionException
1514
-     */
1515
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1516
-    {
1517
-        $instance = self::instance();
1518
-        $instance->_cache_on = true;
1519
-        // reset some "special" classes
1520
-        EEH_Activation::reset();
1521
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1522
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1523
-        $instance->CART = null;
1524
-        $instance->MRM = null;
1525
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1526
-        //messages reset
1527
-        EED_Messages::reset();
1528
-        //handle of objects cached on LIB
1529
-        foreach (array('LIB', 'modules') as $cache) {
1530
-            foreach ($instance->{$cache} as $class_name => $class) {
1531
-                if (self::_reset_and_unset_object($class, $reset_models)) {
1532
-                    unset($instance->{$cache}->{$class_name});
1533
-                }
1534
-            }
1535
-        }
1536
-        return $instance;
1537
-    }
1538
-
1539
-
1540
-
1541
-    /**
1542
-     * if passed object implements ResettableInterface, then call it's reset() method
1543
-     * if passed object implements InterminableInterface, then return false,
1544
-     * to indicate that it should NOT be cleared from the Registry cache
1545
-     *
1546
-     * @param      $object
1547
-     * @param bool $reset_models
1548
-     * @return bool returns true if cached object should be unset
1549
-     */
1550
-    private static function _reset_and_unset_object($object, $reset_models)
1551
-    {
1552
-        if (! is_object($object)) {
1553
-            // don't unset anything that's not an object
1554
-            return false;
1555
-        }
1556
-        if ($object instanceof EED_Module) {
1557
-            $object::reset();
1558
-            // don't unset modules
1559
-            return false;
1560
-        }
1561
-        if ($object instanceof ResettableInterface) {
1562
-            if ($object instanceof EEM_Base) {
1563
-                if ($reset_models) {
1564
-                    $object->reset();
1565
-                    return true;
1566
-                }
1567
-                return false;
1568
-            }
1569
-            $object->reset();
1570
-            return true;
1571
-        }
1572
-        if (! $object instanceof InterminableInterface) {
1573
-            return true;
1574
-        }
1575
-        return false;
1576
-    }
1577
-
1578
-
1579
-
1580
-    /**
1581
-     * Gets all the custom post type models defined
1582
-     *
1583
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1584
-     */
1585
-    public function cpt_models()
1586
-    {
1587
-        $cpt_models = array();
1588
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1589
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1590
-                $cpt_models[$short_name] = $classname;
1591
-            }
1592
-        }
1593
-        return $cpt_models;
1594
-    }
1595
-
1596
-
1597
-
1598
-    /**
1599
-     * @return \EE_Config
1600
-     */
1601
-    public static function CFG()
1602
-    {
1603
-        return self::instance()->CFG;
1604
-    }
26
+	/**
27
+	 * @var EE_Registry $_instance
28
+	 */
29
+	private static $_instance;
30
+
31
+	/**
32
+	 * @var EE_Dependency_Map $_dependency_map
33
+	 */
34
+	protected $_dependency_map;
35
+
36
+	/**
37
+	 * @var array $_class_abbreviations
38
+	 */
39
+	protected $_class_abbreviations = array();
40
+
41
+	/**
42
+	 * @var CommandBusInterface $BUS
43
+	 */
44
+	public $BUS;
45
+
46
+	/**
47
+	 * @var EE_Cart $CART
48
+	 */
49
+	public $CART;
50
+
51
+	/**
52
+	 * @var EE_Config $CFG
53
+	 */
54
+	public $CFG;
55
+
56
+	/**
57
+	 * @var EE_Network_Config $NET_CFG
58
+	 */
59
+	public $NET_CFG;
60
+
61
+	/**
62
+	 * StdClass object for storing library classes in
63
+	 *
64
+	 * @var StdClass $LIB
65
+	 */
66
+	public $LIB;
67
+
68
+	/**
69
+	 * @var EE_Request_Handler $REQ
70
+	 */
71
+	public $REQ;
72
+
73
+	/**
74
+	 * @var EE_Session $SSN
75
+	 */
76
+	public $SSN;
77
+
78
+	/**
79
+	 * @since 4.5.0
80
+	 * @var EE_Capabilities $CAP
81
+	 */
82
+	public $CAP;
83
+
84
+	/**
85
+	 * @since 4.9.0
86
+	 * @var EE_Message_Resource_Manager $MRM
87
+	 */
88
+	public $MRM;
89
+
90
+
91
+	/**
92
+	 * @var Registry $AssetsRegistry
93
+	 */
94
+	public $AssetsRegistry;
95
+
96
+	/**
97
+	 * StdClass object for holding addons which have registered themselves to work with EE core
98
+	 *
99
+	 * @var EE_Addon[] $addons
100
+	 */
101
+	public $addons;
102
+
103
+	/**
104
+	 * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
105
+	 *
106
+	 * @var EEM_Base[] $models
107
+	 */
108
+	public $models = array();
109
+
110
+	/**
111
+	 * @var EED_Module[] $modules
112
+	 */
113
+	public $modules;
114
+
115
+	/**
116
+	 * @var EES_Shortcode[] $shortcodes
117
+	 */
118
+	public $shortcodes;
119
+
120
+	/**
121
+	 * @var WP_Widget[] $widgets
122
+	 */
123
+	public $widgets;
124
+
125
+	/**
126
+	 * this is an array of all implemented model names (i.e. not the parent abstract models, or models
127
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
128
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
129
+	 * classnames (eg "EEM_Event")
130
+	 *
131
+	 * @var array $non_abstract_db_models
132
+	 */
133
+	public $non_abstract_db_models = array();
134
+
135
+
136
+	/**
137
+	 * internationalization for JS strings
138
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
139
+	 *    in js file:  var translatedString = eei18n.string_key;
140
+	 *
141
+	 * @var array $i18n_js_strings
142
+	 */
143
+	public static $i18n_js_strings = array();
144
+
145
+
146
+	/**
147
+	 * $main_file - path to espresso.php
148
+	 *
149
+	 * @var array $main_file
150
+	 */
151
+	public $main_file;
152
+
153
+	/**
154
+	 * array of ReflectionClass objects where the key is the class name
155
+	 *
156
+	 * @var ReflectionClass[] $_reflectors
157
+	 */
158
+	public $_reflectors;
159
+
160
+	/**
161
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
162
+	 *
163
+	 * @var boolean $_cache_on
164
+	 */
165
+	protected $_cache_on = true;
166
+
167
+
168
+
169
+	/**
170
+	 * @singleton method used to instantiate class object
171
+	 * @param  EE_Dependency_Map $dependency_map
172
+	 * @return EE_Registry instance
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidInterfaceException
175
+	 * @throws InvalidDataTypeException
176
+	 */
177
+	public static function instance(EE_Dependency_Map $dependency_map = null)
178
+	{
179
+		// check if class object is instantiated
180
+		if (! self::$_instance instanceof EE_Registry) {
181
+			self::$_instance = new self($dependency_map);
182
+		}
183
+		return self::$_instance;
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * protected constructor to prevent direct creation
190
+	 *
191
+	 * @Constructor
192
+	 * @param  EE_Dependency_Map $dependency_map
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws InvalidArgumentException
196
+	 */
197
+	protected function __construct(EE_Dependency_Map $dependency_map)
198
+	{
199
+		$this->_dependency_map = $dependency_map;
200
+		// $registry_container = new RegistryContainer();
201
+		$this->LIB = new RegistryContainer();
202
+		$this->addons = new RegistryContainer();
203
+		$this->modules = new RegistryContainer();
204
+		$this->shortcodes = new RegistryContainer();
205
+		$this->widgets = new RegistryContainer();
206
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * initialize
213
+	 *
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public function initialize()
218
+	{
219
+		$this->_class_abbreviations = apply_filters(
220
+			'FHEE__EE_Registry____construct___class_abbreviations',
221
+			array(
222
+				'EE_Config'                                       => 'CFG',
223
+				'EE_Session'                                      => 'SSN',
224
+				'EE_Capabilities'                                 => 'CAP',
225
+				'EE_Cart'                                         => 'CART',
226
+				'EE_Network_Config'                               => 'NET_CFG',
227
+				'EE_Request_Handler'                              => 'REQ',
228
+				'EE_Message_Resource_Manager'                     => 'MRM',
229
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
230
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
231
+			)
232
+		);
233
+		$this->load_core('Base', array(), true);
234
+		// add our request and response objects to the cache
235
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
236
+		$this->_set_cached_class(
237
+			$request_loader(),
238
+			'EE_Request'
239
+		);
240
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
241
+		$this->_set_cached_class(
242
+			$response_loader(),
243
+			'EE_Response'
244
+		);
245
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * @return void
252
+	 */
253
+	public function init()
254
+	{
255
+		// Get current page protocol
256
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
257
+		// Output admin-ajax.php URL with same protocol as current page
258
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
259
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
260
+	}
261
+
262
+
263
+
264
+	/**
265
+	 * localize_i18n_js_strings
266
+	 *
267
+	 * @return string
268
+	 */
269
+	public static function localize_i18n_js_strings()
270
+	{
271
+		$i18n_js_strings = (array)self::$i18n_js_strings;
272
+		foreach ($i18n_js_strings as $key => $value) {
273
+			if (is_scalar($value)) {
274
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
275
+			}
276
+		}
277
+		return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
278
+	}
279
+
280
+
281
+
282
+	/**
283
+	 * @param mixed string | EED_Module $module
284
+	 * @throws EE_Error
285
+	 * @throws ReflectionException
286
+	 */
287
+	public function add_module($module)
288
+	{
289
+		if ($module instanceof EED_Module) {
290
+			$module_class = get_class($module);
291
+			$this->modules->{$module_class} = $module;
292
+		} else {
293
+			if ( ! class_exists('EE_Module_Request_Router', false)) {
294
+				$this->load_core('Module_Request_Router');
295
+			}
296
+			EE_Module_Request_Router::module_factory($module);
297
+		}
298
+	}
299
+
300
+
301
+
302
+	/**
303
+	 * @param string $module_name
304
+	 * @return mixed EED_Module | NULL
305
+	 */
306
+	public function get_module($module_name = '')
307
+	{
308
+		return isset($this->modules->{$module_name})
309
+			? $this->modules->{$module_name}
310
+			: null;
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * loads core classes - must be singletons
317
+	 *
318
+	 * @param string $class_name - simple class name ie: session
319
+	 * @param mixed  $arguments
320
+	 * @param bool   $load_only
321
+	 * @return mixed
322
+	 * @throws EE_Error
323
+	 * @throws ReflectionException
324
+	 */
325
+	public function load_core($class_name, $arguments = array(), $load_only = false)
326
+	{
327
+		$core_paths = apply_filters(
328
+			'FHEE__EE_Registry__load_core__core_paths',
329
+			array(
330
+				EE_CORE,
331
+				EE_ADMIN,
332
+				EE_CPTS,
333
+				EE_CORE . 'data_migration_scripts' . DS,
334
+				EE_CORE . 'capabilities' . DS,
335
+				EE_CORE . 'request_stack' . DS,
336
+				EE_CORE . 'middleware' . DS,
337
+			)
338
+		);
339
+		// retrieve instantiated class
340
+		return $this->_load(
341
+			$core_paths,
342
+			'EE_',
343
+			$class_name,
344
+			'core',
345
+			$arguments,
346
+			false,
347
+			true,
348
+			$load_only
349
+		);
350
+	}
351
+
352
+
353
+
354
+	/**
355
+	 * loads service classes
356
+	 *
357
+	 * @param string $class_name - simple class name ie: session
358
+	 * @param mixed  $arguments
359
+	 * @param bool   $load_only
360
+	 * @return mixed
361
+	 * @throws EE_Error
362
+	 * @throws ReflectionException
363
+	 */
364
+	public function load_service($class_name, $arguments = array(), $load_only = false)
365
+	{
366
+		$service_paths = apply_filters(
367
+			'FHEE__EE_Registry__load_service__service_paths',
368
+			array(
369
+				EE_CORE . 'services' . DS,
370
+			)
371
+		);
372
+		// retrieve instantiated class
373
+		return $this->_load(
374
+			$service_paths,
375
+			'EE_',
376
+			$class_name,
377
+			'class',
378
+			$arguments,
379
+			false,
380
+			true,
381
+			$load_only
382
+		);
383
+	}
384
+
385
+
386
+
387
+	/**
388
+	 * loads data_migration_scripts
389
+	 *
390
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
391
+	 * @param mixed  $arguments
392
+	 * @return EE_Data_Migration_Script_Base|mixed
393
+	 * @throws EE_Error
394
+	 * @throws ReflectionException
395
+	 */
396
+	public function load_dms($class_name, $arguments = array())
397
+	{
398
+		// retrieve instantiated class
399
+		return $this->_load(
400
+			EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
401
+			'EE_DMS_',
402
+			$class_name,
403
+			'dms',
404
+			$arguments,
405
+			false,
406
+			false
407
+		);
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * loads object creating classes - must be singletons
414
+	 *
415
+	 * @param string $class_name - simple class name ie: attendee
416
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
417
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
418
+	 *                           instantiate
419
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
420
+	 *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
421
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
422
+	 *                           (default)
423
+	 * @return EE_Base_Class | bool
424
+	 * @throws EE_Error
425
+	 * @throws ReflectionException
426
+	 */
427
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
428
+	{
429
+		$paths = apply_filters(
430
+			'FHEE__EE_Registry__load_class__paths', array(
431
+			EE_CORE,
432
+			EE_CLASSES,
433
+			EE_BUSINESS,
434
+		)
435
+		);
436
+		// retrieve instantiated class
437
+		return $this->_load(
438
+			$paths,
439
+			'EE_',
440
+			$class_name,
441
+			'class',
442
+			$arguments,
443
+			$from_db,
444
+			$cache,
445
+			$load_only
446
+		);
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 * loads helper classes - must be singletons
453
+	 *
454
+	 * @param string $class_name - simple class name ie: price
455
+	 * @param mixed  $arguments
456
+	 * @param bool   $load_only
457
+	 * @return EEH_Base | bool
458
+	 * @throws EE_Error
459
+	 * @throws ReflectionException
460
+	 */
461
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
462
+	{
463
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
464
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
465
+		// retrieve instantiated class
466
+		return $this->_load(
467
+			$helper_paths,
468
+			'EEH_',
469
+			$class_name,
470
+			'helper',
471
+			$arguments,
472
+			false,
473
+			true,
474
+			$load_only
475
+		);
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * loads core classes - must be singletons
482
+	 *
483
+	 * @param string $class_name - simple class name ie: session
484
+	 * @param mixed  $arguments
485
+	 * @param bool   $load_only
486
+	 * @param bool   $cache      whether to cache the object or not.
487
+	 * @return mixed
488
+	 * @throws EE_Error
489
+	 * @throws ReflectionException
490
+	 */
491
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
492
+	{
493
+		$paths = array(
494
+			EE_LIBRARIES,
495
+			EE_LIBRARIES . 'messages' . DS,
496
+			EE_LIBRARIES . 'shortcodes' . DS,
497
+			EE_LIBRARIES . 'qtips' . DS,
498
+			EE_LIBRARIES . 'payment_methods' . DS,
499
+		);
500
+		// retrieve instantiated class
501
+		return $this->_load(
502
+			$paths,
503
+			'EE_',
504
+			$class_name,
505
+			'lib',
506
+			$arguments,
507
+			false,
508
+			$cache,
509
+			$load_only
510
+		);
511
+	}
512
+
513
+
514
+
515
+	/**
516
+	 * loads model classes - must be singletons
517
+	 *
518
+	 * @param string $class_name - simple class name ie: price
519
+	 * @param mixed  $arguments
520
+	 * @param bool   $load_only
521
+	 * @return EEM_Base | bool
522
+	 * @throws EE_Error
523
+	 * @throws ReflectionException
524
+	 */
525
+	public function load_model($class_name, $arguments = array(), $load_only = false)
526
+	{
527
+		$paths = apply_filters(
528
+			'FHEE__EE_Registry__load_model__paths', array(
529
+			EE_MODELS,
530
+			EE_CORE,
531
+		)
532
+		);
533
+		// retrieve instantiated class
534
+		return $this->_load(
535
+			$paths,
536
+			'EEM_',
537
+			$class_name,
538
+			'model',
539
+			$arguments,
540
+			false,
541
+			true,
542
+			$load_only
543
+		);
544
+	}
545
+
546
+
547
+
548
+	/**
549
+	 * loads model classes - must be singletons
550
+	 *
551
+	 * @param string $class_name - simple class name ie: price
552
+	 * @param mixed  $arguments
553
+	 * @param bool   $load_only
554
+	 * @return mixed | bool
555
+	 * @throws EE_Error
556
+	 * @throws ReflectionException
557
+	 */
558
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
559
+	{
560
+		$paths = array(
561
+			EE_MODELS . 'fields' . DS,
562
+			EE_MODELS . 'helpers' . DS,
563
+			EE_MODELS . 'relations' . DS,
564
+			EE_MODELS . 'strategies' . DS,
565
+		);
566
+		// retrieve instantiated class
567
+		return $this->_load(
568
+			$paths,
569
+			'EE_',
570
+			$class_name,
571
+			'',
572
+			$arguments,
573
+			false,
574
+			true,
575
+			$load_only
576
+		);
577
+	}
578
+
579
+
580
+
581
+	/**
582
+	 * Determines if $model_name is the name of an actual EE model.
583
+	 *
584
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
585
+	 * @return boolean
586
+	 */
587
+	public function is_model_name($model_name)
588
+	{
589
+		return isset($this->models[$model_name]);
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 * generic class loader
596
+	 *
597
+	 * @param string $path_to_file - directory path to file location, not including filename
598
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
599
+	 * @param string $type         - file type - core? class? helper? model?
600
+	 * @param mixed  $arguments
601
+	 * @param bool   $load_only
602
+	 * @return mixed
603
+	 * @throws EE_Error
604
+	 * @throws ReflectionException
605
+	 */
606
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
607
+	{
608
+		// retrieve instantiated class
609
+		return $this->_load(
610
+			$path_to_file,
611
+			'',
612
+			$file_name,
613
+			$type,
614
+			$arguments,
615
+			false,
616
+			true,
617
+			$load_only
618
+		);
619
+	}
620
+
621
+
622
+
623
+	/**
624
+	 * @param string $path_to_file - directory path to file location, not including filename
625
+	 * @param string $class_name   - full class name  ie:  My_Class
626
+	 * @param string $type         - file type - core? class? helper? model?
627
+	 * @param mixed  $arguments
628
+	 * @param bool   $load_only
629
+	 * @return bool|EE_Addon|object
630
+	 * @throws EE_Error
631
+	 * @throws ReflectionException
632
+	 */
633
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
634
+	{
635
+		// retrieve instantiated class
636
+		return $this->_load(
637
+			$path_to_file,
638
+			'addon',
639
+			$class_name,
640
+			$type,
641
+			$arguments,
642
+			false,
643
+			true,
644
+			$load_only
645
+		);
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * instantiates, caches, and automatically resolves dependencies
652
+	 * for classes that use a Fully Qualified Class Name.
653
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
654
+	 * then you need to use one of the existing load_*() methods
655
+	 * which can resolve the classname and filepath from the passed arguments
656
+	 *
657
+	 * @param bool|string $class_name   Fully Qualified Class Name
658
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
659
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
660
+	 * @param bool        $from_db      some classes are instantiated from the db
661
+	 *                                  and thus call a different method to instantiate
662
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
663
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
664
+	 * @return bool|null|mixed          null = failure to load or instantiate class object.
665
+	 *                                  object = class loaded and instantiated successfully.
666
+	 *                                  bool = fail or success when $load_only is true
667
+	 * @throws EE_Error
668
+	 * @throws ReflectionException
669
+	 */
670
+	public function create(
671
+		$class_name = false,
672
+		$arguments = array(),
673
+		$cache = false,
674
+		$from_db = false,
675
+		$load_only = false,
676
+		$addon = false
677
+	) {
678
+		$class_name = ltrim($class_name, '\\');
679
+		$class_name = $this->_dependency_map->get_alias($class_name);
680
+		$class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
681
+		// if a non-FQCN was passed, then verifyClassExists() might return an object
682
+		// or it could return null if the class just could not be found anywhere
683
+		if ($class_exists instanceof $class_name || $class_exists === null){
684
+			// either way, return the results
685
+			return $class_exists;
686
+		}
687
+		$class_name = $class_exists;
688
+		// if we're only loading the class and it already exists, then let's just return true immediately
689
+		if ($load_only) {
690
+			return true;
691
+		}
692
+		$addon = $addon
693
+			? 'addon'
694
+			: '';
695
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
696
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
697
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
698
+		if ($this->_cache_on && $cache && ! $load_only) {
699
+			// return object if it's already cached
700
+			$cached_class = $this->_get_cached_class($class_name, $addon);
701
+			if ($cached_class !== null) {
702
+				return $cached_class;
703
+			}
704
+		}
705
+		// obtain the loader method from the dependency map
706
+		$loader = $this->_dependency_map->class_loader($class_name);
707
+		// instantiate the requested object
708
+		if ($loader instanceof Closure) {
709
+			$class_obj = $loader($arguments);
710
+		} else if ($loader && method_exists($this, $loader)) {
711
+			$class_obj = $this->{$loader}($class_name, $arguments);
712
+		} else {
713
+			$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
714
+		}
715
+		if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
716
+			// save it for later... kinda like gum  { : $
717
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
718
+		}
719
+		$this->_cache_on = true;
720
+		return $class_obj;
721
+	}
722
+
723
+
724
+
725
+	/**
726
+	 * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
727
+	 *
728
+	 * @param string $class_name
729
+	 * @param array  $arguments
730
+	 * @param int    $attempt
731
+	 * @return mixed
732
+	 */
733
+	private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
734
+		if (is_object($class_name) || class_exists($class_name)) {
735
+			return $class_name;
736
+		}
737
+		switch ($attempt) {
738
+			case 1:
739
+				// if it's a FQCN then maybe the class is registered with a preceding \
740
+				$class_name = strpos($class_name, '\\') !== false
741
+					? '\\' . ltrim($class_name, '\\')
742
+					: $class_name;
743
+				break;
744
+			case 2:
745
+				//
746
+				$loader = $this->_dependency_map->class_loader($class_name);
747
+				if ($loader && method_exists($this, $loader)) {
748
+					return $this->{$loader}($class_name, $arguments);
749
+				}
750
+				break;
751
+			case 3:
752
+			default;
753
+				return null;
754
+		}
755
+		$attempt++;
756
+		return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
757
+	}
758
+
759
+
760
+
761
+	/**
762
+	 * instantiates, caches, and injects dependencies for classes
763
+	 *
764
+	 * @param array       $file_paths   an array of paths to folders to look in
765
+	 * @param string      $class_prefix EE  or EEM or... ???
766
+	 * @param bool|string $class_name   $class name
767
+	 * @param string      $type         file type - core? class? helper? model?
768
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
769
+	 * @param bool        $from_db      some classes are instantiated from the db
770
+	 *                                  and thus call a different method to instantiate
771
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
772
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
773
+	 * @return bool|null|object null = failure to load or instantiate class object.
774
+	 *                                  object = class loaded and instantiated successfully.
775
+	 *                                  bool = fail or success when $load_only is true
776
+	 * @throws EE_Error
777
+	 * @throws ReflectionException
778
+	 */
779
+	protected function _load(
780
+		$file_paths = array(),
781
+		$class_prefix = 'EE_',
782
+		$class_name = false,
783
+		$type = 'class',
784
+		$arguments = array(),
785
+		$from_db = false,
786
+		$cache = true,
787
+		$load_only = false
788
+	) {
789
+		$class_name = ltrim($class_name, '\\');
790
+		// strip php file extension
791
+		$class_name = str_replace('.php', '', trim($class_name));
792
+		// does the class have a prefix ?
793
+		if (! empty($class_prefix) && $class_prefix !== 'addon') {
794
+			// make sure $class_prefix is uppercase
795
+			$class_prefix = strtoupper(trim($class_prefix));
796
+			// add class prefix ONCE!!!
797
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
798
+		}
799
+		$class_name = $this->_dependency_map->get_alias($class_name);
800
+		$class_exists = class_exists($class_name, false);
801
+		// if we're only loading the class and it already exists, then let's just return true immediately
802
+		if ($load_only && $class_exists) {
803
+			return true;
804
+		}
805
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
806
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
807
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
808
+		if ($this->_cache_on && $cache && ! $load_only) {
809
+			// return object if it's already cached
810
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
811
+			if ($cached_class !== null) {
812
+				return $cached_class;
813
+			}
814
+		}
815
+		// if the class doesn't already exist.. then we need to try and find the file and load it
816
+		if (! $class_exists) {
817
+			// get full path to file
818
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
819
+			// load the file
820
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
821
+			// if loading failed, or we are only loading a file but NOT instantiating an object
822
+			if (! $loaded || $load_only) {
823
+				// return boolean if only loading, or null if an object was expected
824
+				return $load_only
825
+					? $loaded
826
+					: null;
827
+			}
828
+		}
829
+		// instantiate the requested object
830
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
831
+		if ($this->_cache_on && $cache) {
832
+			// save it for later... kinda like gum  { : $
833
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
834
+		}
835
+		$this->_cache_on = true;
836
+		return $class_obj;
837
+	}
838
+
839
+
840
+
841
+	/**
842
+	 * @param string $class_name
843
+	 * @param string $default have to specify something, but not anything that will conflict
844
+	 * @return mixed|string
845
+	 */
846
+	protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
847
+	{
848
+		return isset($this->_class_abbreviations[$class_name])
849
+			? $this->_class_abbreviations[$class_name]
850
+			: $default;
851
+	}
852
+
853
+	/**
854
+	 * attempts to find a cached version of the requested class
855
+	 * by looking in the following places:
856
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
857
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
858
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
859
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
860
+	 *
861
+	 * @param string $class_name
862
+	 * @param string $class_prefix
863
+	 * @return mixed
864
+	 */
865
+	protected function _get_cached_class($class_name, $class_prefix = '')
866
+	{
867
+		if ($class_name === 'EE_Registry') {
868
+			return $this;
869
+		}
870
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
871
+		$class_name = str_replace('\\', '_', $class_name);
872
+		// check if class has already been loaded, and return it if it has been
873
+		if (isset($this->{$class_abbreviation})) {
874
+			return $this->{$class_abbreviation};
875
+		}
876
+		if (isset ($this->{$class_name})) {
877
+			return $this->{$class_name};
878
+		}
879
+		if (isset ($this->LIB->{$class_name})) {
880
+			return $this->LIB->{$class_name};
881
+		}
882
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
883
+			return $this->addons->{$class_name};
884
+		}
885
+		return null;
886
+	}
887
+
888
+
889
+
890
+	/**
891
+	 * removes a cached version of the requested class
892
+	 *
893
+	 * @param string  $class_name
894
+	 * @param boolean $addon
895
+	 * @return boolean
896
+	 */
897
+	public function clear_cached_class($class_name, $addon = false)
898
+	{
899
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
900
+		$class_name = str_replace('\\', '_', $class_name);
901
+		// check if class has already been loaded, and return it if it has been
902
+		if (isset($this->{$class_abbreviation})) {
903
+			$this->{$class_abbreviation} = null;
904
+			return true;
905
+		}
906
+		if (isset($this->{$class_name})) {
907
+			$this->{$class_name} = null;
908
+			return true;
909
+		}
910
+		if (isset($this->LIB->{$class_name})) {
911
+			unset($this->LIB->{$class_name});
912
+			return true;
913
+		}
914
+		if ($addon && isset($this->addons->{$class_name})) {
915
+			unset($this->addons->{$class_name});
916
+			return true;
917
+		}
918
+		return false;
919
+	}
920
+
921
+
922
+
923
+	/**
924
+	 * attempts to find a full valid filepath for the requested class.
925
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
926
+	 * then returns that path if the target file has been found and is readable
927
+	 *
928
+	 * @param string $class_name
929
+	 * @param string $type
930
+	 * @param array  $file_paths
931
+	 * @return string | bool
932
+	 */
933
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
934
+	{
935
+		// make sure $file_paths is an array
936
+		$file_paths = is_array($file_paths)
937
+			? $file_paths
938
+			: array($file_paths);
939
+		// cycle thru paths
940
+		foreach ($file_paths as $key => $file_path) {
941
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
942
+			$file_path = $file_path
943
+				? str_replace(array('/', '\\'), DS, $file_path)
944
+				: EE_CLASSES;
945
+			// prep file type
946
+			$type = ! empty($type)
947
+				? trim($type, '.') . '.'
948
+				: '';
949
+			// build full file path
950
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
951
+			//does the file exist and can be read ?
952
+			if (is_readable($file_paths[$key])) {
953
+				return $file_paths[$key];
954
+			}
955
+		}
956
+		return false;
957
+	}
958
+
959
+
960
+
961
+	/**
962
+	 * basically just performs a require_once()
963
+	 * but with some error handling
964
+	 *
965
+	 * @param  string $path
966
+	 * @param  string $class_name
967
+	 * @param  string $type
968
+	 * @param  array  $file_paths
969
+	 * @return bool
970
+	 * @throws EE_Error
971
+	 * @throws ReflectionException
972
+	 */
973
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
974
+	{
975
+		$this->resolve_legacy_class_parent($class_name);
976
+		// don't give up! you gotta...
977
+		try {
978
+			//does the file exist and can it be read ?
979
+			if (! $path) {
980
+				// just in case the file has already been autoloaded,
981
+				// but discrepancies in the naming schema are preventing it from
982
+				// being loaded via one of the EE_Registry::load_*() methods,
983
+				// then let's try one last hail mary before throwing an exception
984
+				// and call class_exists() again, but with autoloading turned ON
985
+				if(class_exists($class_name)) {
986
+					return true;
987
+				}
988
+				// so sorry, can't find the file
989
+				throw new EE_Error (
990
+					sprintf(
991
+						esc_html__(
992
+							'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
993
+							'event_espresso'
994
+						),
995
+						trim($type, '.'),
996
+						$class_name,
997
+						'<br />' . implode(',<br />', $file_paths)
998
+					)
999
+				);
1000
+			}
1001
+			// get the file
1002
+			require_once($path);
1003
+			// if the class isn't already declared somewhere
1004
+			if (class_exists($class_name, false) === false) {
1005
+				// so sorry, not a class
1006
+				throw new EE_Error(
1007
+					sprintf(
1008
+						esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1009
+						$type,
1010
+						$path,
1011
+						$class_name
1012
+					)
1013
+				);
1014
+			}
1015
+		} catch (EE_Error $e) {
1016
+			$e->get_error();
1017
+			return false;
1018
+		}
1019
+		return true;
1020
+	}
1021
+
1022
+
1023
+
1024
+	/**
1025
+	 * Some of our legacy classes that extended a parent class would simply use a require() statement
1026
+	 * before their class declaration in order to ensure that the parent class was loaded.
1027
+	 * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1028
+	 * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1029
+	 *
1030
+	 * @param string $class_name
1031
+	 */
1032
+	protected function resolve_legacy_class_parent($class_name = '')
1033
+	{
1034
+		try {
1035
+			$legacy_parent_class_map = array(
1036
+				'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1037
+			);
1038
+			if(isset($legacy_parent_class_map[$class_name])) {
1039
+				require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1040
+			}
1041
+		} catch (Exception $exception) {
1042
+		}
1043
+	}
1044
+
1045
+
1046
+
1047
+	/**
1048
+	 * _create_object
1049
+	 * Attempts to instantiate the requested class via any of the
1050
+	 * commonly used instantiation methods employed throughout EE.
1051
+	 * The priority for instantiation is as follows:
1052
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1053
+	 *        - model objects via their 'new_instance_from_db' method
1054
+	 *        - model objects via their 'new_instance' method
1055
+	 *        - "singleton" classes" via their 'instance' method
1056
+	 *    - standard instantiable classes via their __constructor
1057
+	 * Prior to instantiation, if the classname exists in the dependency_map,
1058
+	 * then the constructor for the requested class will be examined to determine
1059
+	 * if any dependencies exist, and if they can be injected.
1060
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1061
+	 *
1062
+	 * @param string $class_name
1063
+	 * @param array  $arguments
1064
+	 * @param string $type
1065
+	 * @param bool   $from_db
1066
+	 * @return null|object
1067
+	 * @throws EE_Error
1068
+	 * @throws ReflectionException
1069
+	 */
1070
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1071
+	{
1072
+		// create reflection
1073
+		$reflector = $this->get_ReflectionClass($class_name);
1074
+		// make sure arguments are an array
1075
+		$arguments = is_array($arguments)
1076
+			? $arguments
1077
+			: array($arguments);
1078
+		// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1079
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
1080
+		$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1081
+			? $arguments
1082
+			: array($arguments);
1083
+		// attempt to inject dependencies ?
1084
+		if ($this->_dependency_map->has($class_name)) {
1085
+			$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1086
+		}
1087
+		// instantiate the class if possible
1088
+		if ($reflector->isAbstract()) {
1089
+			// nothing to instantiate, loading file was enough
1090
+			// does not throw an exception so $instantiation_mode is unused
1091
+			// $instantiation_mode = "1) no constructor abstract class";
1092
+			return true;
1093
+		}
1094
+		if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1095
+			// no constructor = static methods only... nothing to instantiate, loading file was enough
1096
+			// $instantiation_mode = "2) no constructor but instantiable";
1097
+			return $reflector->newInstance();
1098
+		}
1099
+		if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1100
+			// $instantiation_mode = "3) new_instance_from_db()";
1101
+			return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1102
+		}
1103
+		if (method_exists($class_name, 'new_instance')) {
1104
+			// $instantiation_mode = "4) new_instance()";
1105
+			return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1106
+		}
1107
+		if (method_exists($class_name, 'instance')) {
1108
+			// $instantiation_mode = "5) instance()";
1109
+			return call_user_func_array(array($class_name, 'instance'), $arguments);
1110
+		}
1111
+		if ($reflector->isInstantiable()) {
1112
+			// $instantiation_mode = "6) constructor";
1113
+			return $reflector->newInstanceArgs($arguments);
1114
+		}
1115
+		// heh ? something's not right !
1116
+		throw new EE_Error(
1117
+			sprintf(
1118
+				__('The %s file %s could not be instantiated.', 'event_espresso'),
1119
+				$type,
1120
+				$class_name
1121
+			)
1122
+		);
1123
+	}
1124
+
1125
+
1126
+
1127
+	/**
1128
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1129
+	 * @param array $array
1130
+	 * @return bool
1131
+	 */
1132
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1133
+	{
1134
+		return ! empty($array)
1135
+			? array_keys($array) === range(0, count($array) - 1)
1136
+			: true;
1137
+	}
1138
+
1139
+
1140
+
1141
+	/**
1142
+	 * getReflectionClass
1143
+	 * checks if a ReflectionClass object has already been generated for a class
1144
+	 * and returns that instead of creating a new one
1145
+	 *
1146
+	 * @param string $class_name
1147
+	 * @return ReflectionClass
1148
+	 * @throws ReflectionException
1149
+	 */
1150
+	public function get_ReflectionClass($class_name)
1151
+	{
1152
+		if (
1153
+			! isset($this->_reflectors[$class_name])
1154
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
1155
+		) {
1156
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
1157
+		}
1158
+		return $this->_reflectors[$class_name];
1159
+	}
1160
+
1161
+
1162
+
1163
+	/**
1164
+	 * _resolve_dependencies
1165
+	 * examines the constructor for the requested class to determine
1166
+	 * if any dependencies exist, and if they can be injected.
1167
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1168
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1169
+	 * For example:
1170
+	 *        if attempting to load a class "Foo" with the following constructor:
1171
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1172
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1173
+	 *        but only IF they are NOT already present in the incoming arguments array,
1174
+	 *        and the correct classes can be loaded
1175
+	 *
1176
+	 * @param ReflectionClass $reflector
1177
+	 * @param string          $class_name
1178
+	 * @param array           $arguments
1179
+	 * @return array
1180
+	 * @throws EE_Error
1181
+	 * @throws ReflectionException
1182
+	 */
1183
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1184
+	{
1185
+		// let's examine the constructor
1186
+		$constructor = $reflector->getConstructor();
1187
+		// whu? huh? nothing?
1188
+		if (! $constructor) {
1189
+			return $arguments;
1190
+		}
1191
+		// get constructor parameters
1192
+		$params = $constructor->getParameters();
1193
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1194
+		$argument_keys = array_keys($arguments);
1195
+		// now loop thru all of the constructors expected parameters
1196
+		foreach ($params as $index => $param) {
1197
+			// is this a dependency for a specific class ?
1198
+			$param_class = $param->getClass()
1199
+				? $param->getClass()->name
1200
+				: null;
1201
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1202
+			$param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1203
+				? $this->_dependency_map->get_alias($param_class, $class_name)
1204
+				: $param_class;
1205
+			if (
1206
+				// param is not even a class
1207
+				$param_class === null
1208
+				// and something already exists in the incoming arguments for this param
1209
+				&& array_key_exists($index, $argument_keys)
1210
+				&& array_key_exists($argument_keys[$index], $arguments)
1211
+			) {
1212
+				// so let's skip this argument and move on to the next
1213
+				continue;
1214
+			}
1215
+			if (
1216
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1217
+				$param_class !== null
1218
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1219
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1220
+			) {
1221
+				// skip this argument and move on to the next
1222
+				continue;
1223
+			}
1224
+			if (
1225
+				// parameter is type hinted as a class, and should be injected
1226
+				$param_class !== null
1227
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1228
+			) {
1229
+				$arguments = $this->_resolve_dependency(
1230
+					$class_name,
1231
+					$param_class,
1232
+					$arguments,
1233
+					$index,
1234
+					$argument_keys
1235
+				);
1236
+			} else {
1237
+				try {
1238
+					$arguments[$index] = $param->isDefaultValueAvailable()
1239
+						? $param->getDefaultValue()
1240
+						: null;
1241
+				} catch (ReflectionException $e) {
1242
+					throw new ReflectionException(
1243
+						sprintf(
1244
+							esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1245
+							$e->getMessage(),
1246
+							$param->getName(),
1247
+							$class_name
1248
+						)
1249
+					);
1250
+				}
1251
+			}
1252
+		}
1253
+		return $arguments;
1254
+	}
1255
+
1256
+
1257
+
1258
+	/**
1259
+	 * @param string $class_name
1260
+	 * @param string $param_class
1261
+	 * @param array  $arguments
1262
+	 * @param mixed  $index
1263
+	 * @param array  $argument_keys
1264
+	 * @return array
1265
+	 * @throws EE_Error
1266
+	 * @throws ReflectionException
1267
+	 * @throws InvalidArgumentException
1268
+	 * @throws InvalidInterfaceException
1269
+	 * @throws InvalidDataTypeException
1270
+	 */
1271
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1272
+	{
1273
+		$dependency = null;
1274
+		// should dependency be loaded from cache ?
1275
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1276
+			$class_name,
1277
+			$param_class
1278
+		);
1279
+		$cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1280
+		// we might have a dependency...
1281
+		// let's MAYBE try and find it in our cache if that's what's been requested
1282
+		$cached_class = $cache_on
1283
+			? $this->_get_cached_class($param_class)
1284
+			: null;
1285
+		// and grab it if it exists
1286
+		if ($cached_class instanceof $param_class) {
1287
+			$dependency = $cached_class;
1288
+		} else if ($param_class !== $class_name) {
1289
+			// obtain the loader method from the dependency map
1290
+			$loader = $this->_dependency_map->class_loader($param_class);
1291
+			// is loader a custom closure ?
1292
+			if ($loader instanceof Closure) {
1293
+				$dependency = $loader($arguments);
1294
+			} else {
1295
+				// set the cache on property for the recursive loading call
1296
+				$this->_cache_on = $cache_on;
1297
+				// if not, then let's try and load it via the registry
1298
+				if ($loader && method_exists($this, $loader)) {
1299
+					$dependency = $this->{$loader}($param_class);
1300
+				} else {
1301
+					$dependency = LoaderFactory::getLoader()->load(
1302
+						$param_class,
1303
+						array(),
1304
+						$cache_on
1305
+					);
1306
+				}
1307
+			}
1308
+		}
1309
+		// did we successfully find the correct dependency ?
1310
+		if ($dependency instanceof $param_class) {
1311
+			// then let's inject it into the incoming array of arguments at the correct location
1312
+			$arguments[$index] = $dependency;
1313
+		}
1314
+		return $arguments;
1315
+	}
1316
+
1317
+
1318
+
1319
+	/**
1320
+	 * _set_cached_class
1321
+	 * attempts to cache the instantiated class locally
1322
+	 * in one of the following places, in the following order:
1323
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1324
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1325
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1326
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1327
+	 *
1328
+	 * @param object $class_obj
1329
+	 * @param string $class_name
1330
+	 * @param string $class_prefix
1331
+	 * @param bool   $from_db
1332
+	 * @return void
1333
+	 */
1334
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1335
+	{
1336
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1337
+			return;
1338
+		}
1339
+		// return newly instantiated class
1340
+		$class_abbreviation = $this->get_class_abbreviation($class_name, '');
1341
+		if ($class_abbreviation) {
1342
+			$this->{$class_abbreviation} = $class_obj;
1343
+			return;
1344
+		}
1345
+		$class_name = str_replace('\\', '_', $class_name);
1346
+		if (property_exists($this, $class_name)) {
1347
+			$this->{$class_name} = $class_obj;
1348
+			return;
1349
+		}
1350
+		if ($class_prefix === 'addon') {
1351
+			$this->addons->{$class_name} = $class_obj;
1352
+			return;
1353
+		}
1354
+		if (! $from_db) {
1355
+			$this->LIB->{$class_name} = $class_obj;
1356
+		}
1357
+	}
1358
+
1359
+
1360
+
1361
+	/**
1362
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1363
+	 *
1364
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1365
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1366
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1367
+	 * @param array  $arguments
1368
+	 * @return object
1369
+	 */
1370
+	public static function factory($classname, $arguments = array())
1371
+	{
1372
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1373
+		if ($loader instanceof Closure) {
1374
+			return $loader($arguments);
1375
+		}
1376
+		if (method_exists(self::instance(), $loader)) {
1377
+			return self::instance()->{$loader}($classname, $arguments);
1378
+		}
1379
+		return null;
1380
+	}
1381
+
1382
+
1383
+
1384
+	/**
1385
+	 * Gets the addon by its class name
1386
+	 *
1387
+	 * @param string $class_name
1388
+	 * @return EE_Addon
1389
+	 */
1390
+	public function getAddon($class_name)
1391
+	{
1392
+		$class_name = str_replace('\\', '_', $class_name);
1393
+		return $this->addons->{$class_name};
1394
+	}
1395
+
1396
+
1397
+	/**
1398
+	 * removes the addon from the internal cache
1399
+	 *
1400
+	 * @param string $class_name
1401
+	 * @return void
1402
+	 */
1403
+	public function removeAddon($class_name)
1404
+	{
1405
+		$class_name = str_replace('\\', '_', $class_name);
1406
+		unset($this->addons->{$class_name});
1407
+	}
1408
+
1409
+
1410
+
1411
+	/**
1412
+	 * Gets the addon by its name/slug (not classname. For that, just
1413
+	 * use the get_addon() method above
1414
+	 *
1415
+	 * @param string $name
1416
+	 * @return EE_Addon
1417
+	 */
1418
+	public function get_addon_by_name($name)
1419
+	{
1420
+		foreach ($this->addons as $addon) {
1421
+			if ($addon->name() === $name) {
1422
+				return $addon;
1423
+			}
1424
+		}
1425
+		return null;
1426
+	}
1427
+
1428
+
1429
+
1430
+	/**
1431
+	 * Gets an array of all the registered addons, where the keys are their names.
1432
+	 * (ie, what each returns for their name() function)
1433
+	 * They're already available on EE_Registry::instance()->addons as properties,
1434
+	 * where each property's name is the addon's classname,
1435
+	 * So if you just want to get the addon by classname,
1436
+	 * OR use the get_addon() method above.
1437
+	 * PLEASE  NOTE:
1438
+	 * addons with Fully Qualified Class Names
1439
+	 * have had the namespace separators converted to underscores,
1440
+	 * so a classname like Fully\Qualified\ClassName
1441
+	 * would have been converted to Fully_Qualified_ClassName
1442
+	 *
1443
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1444
+	 */
1445
+	public function get_addons_by_name()
1446
+	{
1447
+		$addons = array();
1448
+		foreach ($this->addons as $addon) {
1449
+			$addons[$addon->name()] = $addon;
1450
+		}
1451
+		return $addons;
1452
+	}
1453
+
1454
+
1455
+	/**
1456
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1457
+	 * a stale copy of it around
1458
+	 *
1459
+	 * @param string $model_name
1460
+	 * @return \EEM_Base
1461
+	 * @throws \EE_Error
1462
+	 */
1463
+	public function reset_model($model_name)
1464
+	{
1465
+		$model_class_name = strpos($model_name, 'EEM_') !== 0
1466
+			? "EEM_{$model_name}"
1467
+			: $model_name;
1468
+		if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1469
+			return null;
1470
+		}
1471
+		//get that model reset it and make sure we nuke the old reference to it
1472
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name
1473
+			&& is_callable(
1474
+				array($model_class_name, 'reset')
1475
+			)) {
1476
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1477
+		} else {
1478
+			throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1479
+		}
1480
+		return $this->LIB->{$model_class_name};
1481
+	}
1482
+
1483
+
1484
+
1485
+	/**
1486
+	 * Resets the registry.
1487
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when
1488
+	 * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1489
+	 * - $_dependency_map
1490
+	 * - $_class_abbreviations
1491
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1492
+	 * - $REQ:  Still on the same request so no need to change.
1493
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1494
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1495
+	 * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1496
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1497
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1498
+	 *             switch or on the restore.
1499
+	 * - $modules
1500
+	 * - $shortcodes
1501
+	 * - $widgets
1502
+	 *
1503
+	 * @param boolean $hard             [deprecated]
1504
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1505
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1506
+	 *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1507
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1508
+	 *                                  client
1509
+	 *                                  code instead can just change the model context to a different blog id if
1510
+	 *                                  necessary
1511
+	 * @return EE_Registry
1512
+	 * @throws EE_Error
1513
+	 * @throws ReflectionException
1514
+	 */
1515
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1516
+	{
1517
+		$instance = self::instance();
1518
+		$instance->_cache_on = true;
1519
+		// reset some "special" classes
1520
+		EEH_Activation::reset();
1521
+		$hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1522
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1523
+		$instance->CART = null;
1524
+		$instance->MRM = null;
1525
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1526
+		//messages reset
1527
+		EED_Messages::reset();
1528
+		//handle of objects cached on LIB
1529
+		foreach (array('LIB', 'modules') as $cache) {
1530
+			foreach ($instance->{$cache} as $class_name => $class) {
1531
+				if (self::_reset_and_unset_object($class, $reset_models)) {
1532
+					unset($instance->{$cache}->{$class_name});
1533
+				}
1534
+			}
1535
+		}
1536
+		return $instance;
1537
+	}
1538
+
1539
+
1540
+
1541
+	/**
1542
+	 * if passed object implements ResettableInterface, then call it's reset() method
1543
+	 * if passed object implements InterminableInterface, then return false,
1544
+	 * to indicate that it should NOT be cleared from the Registry cache
1545
+	 *
1546
+	 * @param      $object
1547
+	 * @param bool $reset_models
1548
+	 * @return bool returns true if cached object should be unset
1549
+	 */
1550
+	private static function _reset_and_unset_object($object, $reset_models)
1551
+	{
1552
+		if (! is_object($object)) {
1553
+			// don't unset anything that's not an object
1554
+			return false;
1555
+		}
1556
+		if ($object instanceof EED_Module) {
1557
+			$object::reset();
1558
+			// don't unset modules
1559
+			return false;
1560
+		}
1561
+		if ($object instanceof ResettableInterface) {
1562
+			if ($object instanceof EEM_Base) {
1563
+				if ($reset_models) {
1564
+					$object->reset();
1565
+					return true;
1566
+				}
1567
+				return false;
1568
+			}
1569
+			$object->reset();
1570
+			return true;
1571
+		}
1572
+		if (! $object instanceof InterminableInterface) {
1573
+			return true;
1574
+		}
1575
+		return false;
1576
+	}
1577
+
1578
+
1579
+
1580
+	/**
1581
+	 * Gets all the custom post type models defined
1582
+	 *
1583
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1584
+	 */
1585
+	public function cpt_models()
1586
+	{
1587
+		$cpt_models = array();
1588
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1589
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1590
+				$cpt_models[$short_name] = $classname;
1591
+			}
1592
+		}
1593
+		return $cpt_models;
1594
+	}
1595
+
1596
+
1597
+
1598
+	/**
1599
+	 * @return \EE_Config
1600
+	 */
1601
+	public static function CFG()
1602
+	{
1603
+		return self::instance()->CFG;
1604
+	}
1605 1605
 
1606 1606
 
1607 1607
 }
Please login to merge, or discard this patch.
core/EE_Error.core.php 2 patches
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
             default :
102 102
                 $to = get_option('admin_email');
103 103
         }
104
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
104
+        $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
105 105
         $msg = EE_Error::_format_error($type, $message, $file, $line);
106 106
         if (function_exists('wp_mail')) {
107 107
             add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
108 108
             wp_mail($to, $subject, $msg);
109 109
         }
110 110
         echo '<div id="message" class="espresso-notices error"><p>';
111
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
111
+        echo $type.': '.$message.'<br />'.$file.' line '.$line;
112 112
         echo '<br /></p></div>';
113 113
     }
114 114
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
             ? true
256 256
             : false;
257 257
         if ($check_stored && ! $has_error) {
258
-            $notices = (array)get_option('ee_notices', array());
258
+            $notices = (array) get_option('ee_notices', array());
259 259
             foreach ($notices as $type => $notice) {
260 260
                 if ($type === $type_to_check && $notice) {
261 261
                     return true;
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	}
331 331
 </style>
332 332
 <div id="ee-error-message" class="error">';
333
-        if (! WP_DEBUG) {
333
+        if ( ! WP_DEBUG) {
334 334
             $output .= '
335 335
 	<p>';
336 336
         }
@@ -389,14 +389,14 @@  discard block
 block discarded – undo
389 389
                     $class_dsply = ! empty($class) ? $class : '&nbsp;';
390 390
                     $type_dsply = ! empty($type) ? $type : '&nbsp;';
391 391
                     $function_dsply = ! empty($function) ? $function : '&nbsp;';
392
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
392
+                    $args_dsply = ! empty($args) ? '( '.$args.' )' : '';
393 393
                     $trace_details .= '
394 394
 					<tr>
395
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
396
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
397
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
398
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
399
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
395
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
396
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
397
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
398
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
399
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
400 400
 					</tr>';
401 401
                 }
402 402
                 $trace_details .= '
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
             }
406 406
             $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
407 407
             // add generic non-identifying messages for non-privileged users
408
-            if (! WP_DEBUG) {
408
+            if ( ! WP_DEBUG) {
409 409
                 $output .= '<span class="ee-error-user-msg-spn">'
410 410
                            . trim($ex['msg'])
411 411
                            . '</span> &nbsp; <sup>'
@@ -447,14 +447,14 @@  discard block
 block discarded – undo
447 447
                            . '-dv" class="ee-error-trace-dv" style="display: none;">
448 448
 				'
449 449
                            . $trace_details;
450
-                if (! empty($class)) {
450
+                if ( ! empty($class)) {
451 451
                     $output .= '
452 452
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
453 453
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
454 454
 						<h3>Class Details</h3>';
455 455
                     $a = new ReflectionClass($class);
456 456
                     $output .= '
457
-						<pre>' . $a . '</pre>
457
+						<pre>' . $a.'</pre>
458 458
 					</div>
459 459
 				</div>';
460 460
                 }
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
         }
467 467
         // remove last linebreak
468 468
         $output = substr($output, 0, -6);
469
-        if (! WP_DEBUG) {
469
+        if ( ! WP_DEBUG) {
470 470
             $output .= '
471 471
 	</p>';
472 472
         }
@@ -493,20 +493,20 @@  discard block
 block discarded – undo
493 493
     private function _convert_args_to_string($arguments = array(), $array = false)
494 494
     {
495 495
         $arg_string = '';
496
-        if (! empty($arguments)) {
496
+        if ( ! empty($arguments)) {
497 497
             $args = array();
498 498
             foreach ($arguments as $arg) {
499
-                if (! empty($arg)) {
499
+                if ( ! empty($arg)) {
500 500
                     if (is_string($arg)) {
501
-                        $args[] = " '" . $arg . "'";
501
+                        $args[] = " '".$arg."'";
502 502
                     } elseif (is_array($arg)) {
503
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
503
+                        $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true);
504 504
                     } elseif ($arg === null) {
505 505
                         $args[] = ' NULL';
506 506
                     } elseif (is_bool($arg)) {
507 507
                         $args[] = ($arg) ? ' TRUE' : ' FALSE';
508 508
                     } elseif (is_object($arg)) {
509
-                        $args[] = ' OBJECT ' . get_class($arg);
509
+                        $args[] = ' OBJECT '.get_class($arg);
510 510
                     } elseif (is_resource($arg)) {
511 511
                         $args[] = get_resource_type($arg);
512 512
                     } else {
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
     {
610 610
         if (empty($msg)) {
611 611
             EE_Error::doing_it_wrong(
612
-                'EE_Error::add_' . $type . '()',
612
+                'EE_Error::add_'.$type.'()',
613 613
                 sprintf(
614 614
                     __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
615 615
                         'event_espresso'),
@@ -645,11 +645,11 @@  discard block
 block discarded – undo
645 645
         do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
646 646
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
647 647
         // add notice if message exists
648
-        if (! empty($msg)) {
648
+        if ( ! empty($msg)) {
649 649
             // get error code
650 650
             $notice_code = EE_Error::generate_error_code($file, $func, $line);
651 651
             if (WP_DEBUG && $type === 'errors') {
652
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
652
+                $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
653 653
             }
654 654
             // add notice. Index by code if it's not blank
655 655
             if ($notice_code) {
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
         // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
776 776
         // either save notices to the db
777 777
         if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
778
-            $existing_notices  = get_option('ee_notices', array());
778
+            $existing_notices = get_option('ee_notices', array());
779 779
             $existing_notices = $existing_notices !== '' ? $existing_notices : array();
780 780
             self::$_espresso_notices = array_merge(
781 781
                 $existing_notices,
@@ -805,13 +805,13 @@  discard block
 block discarded – undo
805 805
         if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
806 806
             // combine messages
807 807
             $success_messages .= implode(self::$_espresso_notices['success'], '<br />');
808
-            $print_scripts    = true;
808
+            $print_scripts = true;
809 809
         }
810 810
         // check for attention messages
811 811
         if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
812 812
             // combine messages
813 813
             $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
814
-            $print_scripts      = true;
814
+            $print_scripts = true;
815 815
         }
816 816
         // check for error messages
817 817
         if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
                 : __('An error has occurred:<br />', 'event_espresso');
821 821
             // combine messages
822 822
             $error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
823
-            $print_scripts  = true;
823
+            $print_scripts = true;
824 824
         }
825 825
         if ($format_output) {
826 826
 
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
      */
903 903
     private static function _print_scripts($force_print = false)
904 904
     {
905
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
905
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
906 906
             if (wp_script_is('ee_error_js', 'enqueued')) {
907 907
                 return '';
908 908
             }
@@ -916,12 +916,12 @@  discard block
 block discarded – undo
916 916
             return '
917 917
 <script>
918 918
 /* <![CDATA[ */
919
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
919
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
920 920
 /* ]]> */
921 921
 </script>
922
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
923
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
924
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
922
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
923
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
924
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
925 925
 ';
926 926
         }
927 927
         return '';
@@ -952,8 +952,8 @@  discard block
 block discarded – undo
952 952
     {
953 953
         $file       = explode('.', basename($file));
954 954
         $error_code = ! empty($file[0]) ? $file[0] : '';
955
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
956
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
955
+        $error_code .= ! empty($func) ? ' - '.$func : '';
956
+        $error_code .= ! empty($line) ? ' - '.$line : '';
957 957
         return $error_code;
958 958
     }
959 959
 
@@ -979,18 +979,18 @@  discard block
 block discarded – undo
979 979
         if (empty($ex)) {
980 980
             return;
981 981
         }
982
-        if (! $time) {
982
+        if ( ! $time) {
983 983
             $time = time();
984 984
         }
985 985
         $exception_log = '----------------------------------------------------------------------------------------'
986 986
                          . PHP_EOL;
987
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
988
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
989
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
990
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
991
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
992
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
993
-        $exception_log .= $ex['string'] . PHP_EOL;
987
+        $exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
988
+        $exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
989
+        $exception_log .= 'Code: '.$ex['code'].PHP_EOL;
990
+        $exception_log .= 'File: '.$ex['file'].PHP_EOL;
991
+        $exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
992
+        $exception_log .= 'Stack trace: '.PHP_EOL;
993
+        $exception_log .= $ex['string'].PHP_EOL;
994 994
         $exception_log .= '----------------------------------------------------------------------------------------'
995 995
                           . PHP_EOL;
996 996
         try {
@@ -1163,14 +1163,14 @@  discard block
 block discarded – undo
1163 1163
     // js for error handling
1164 1164
     wp_register_script(
1165 1165
         'espresso_core',
1166
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1166
+        EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1167 1167
         array('jquery'),
1168 1168
         EVENT_ESPRESSO_VERSION,
1169 1169
         false
1170 1170
     );
1171 1171
     wp_register_script(
1172 1172
         'ee_error_js',
1173
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1173
+        EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1174 1174
         array('espresso_core'),
1175 1175
         EVENT_ESPRESSO_VERSION,
1176 1176
         false
Please login to merge, or discard this patch.
Indentation   +1027 added lines, -1027 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
 // if you're a dev and want to receive all errors via email
12 12
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
13 13
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
14
-    set_error_handler(array('EE_Error', 'error_handler'));
15
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
14
+	set_error_handler(array('EE_Error', 'error_handler'));
15
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
16 16
 }
17 17
 
18 18
 
@@ -28,253 +28,253 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * name of the file to log exceptions to
33
-     *
34
-     * @var string
35
-     */
36
-    private static $_exception_log_file = 'espresso_error_log.txt';
37
-
38
-    /**
39
-     *    stores details for all exception
40
-     *
41
-     * @var array
42
-     */
43
-    private static $_all_exceptions = array();
44
-
45
-    /**
46
-     *    tracks number of errors
47
-     *
48
-     * @var int
49
-     */
50
-    private static $_error_count = 0;
51
-
52
-    /**
53
-     * @var array $_espresso_notices
54
-     */
55
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
56
-
57
-
58
-
59
-    /**
60
-     * @override default exception handling
61
-     * @param string         $message
62
-     * @param int            $code
63
-     * @param Exception|null $previous
64
-     */
65
-    public function __construct($message, $code = 0, Exception $previous = null)
66
-    {
67
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
68
-            parent::__construct($message, $code);
69
-        } else {
70
-            parent::__construct($message, $code, $previous);
71
-        }
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     *    error_handler
78
-     *
79
-     * @param $code
80
-     * @param $message
81
-     * @param $file
82
-     * @param $line
83
-     * @return void
84
-     */
85
-    public static function error_handler($code, $message, $file, $line)
86
-    {
87
-        $type = EE_Error::error_type($code);
88
-        $site = site_url();
89
-        switch ($site) {
90
-            case 'http://ee4.eventespresso.com/' :
91
-            case 'http://ee4decaf.eventespresso.com/' :
92
-            case 'http://ee4hf.eventespresso.com/' :
93
-            case 'http://ee4a.eventespresso.com/' :
94
-            case 'http://ee4ad.eventespresso.com/' :
95
-            case 'http://ee4b.eventespresso.com/' :
96
-            case 'http://ee4bd.eventespresso.com/' :
97
-            case 'http://ee4d.eventespresso.com/' :
98
-            case 'http://ee4dd.eventespresso.com/' :
99
-                $to = '[email protected]';
100
-                break;
101
-            default :
102
-                $to = get_option('admin_email');
103
-        }
104
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
105
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
106
-        if (function_exists('wp_mail')) {
107
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
108
-            wp_mail($to, $subject, $msg);
109
-        }
110
-        echo '<div id="message" class="espresso-notices error"><p>';
111
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
112
-        echo '<br /></p></div>';
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * error_type
119
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
120
-     *
121
-     * @param $code
122
-     * @return string
123
-     */
124
-    public static function error_type($code)
125
-    {
126
-        switch ($code) {
127
-            case E_ERROR: // 1 //
128
-                return 'E_ERROR';
129
-            case E_WARNING: // 2 //
130
-                return 'E_WARNING';
131
-            case E_PARSE: // 4 //
132
-                return 'E_PARSE';
133
-            case E_NOTICE: // 8 //
134
-                return 'E_NOTICE';
135
-            case E_CORE_ERROR: // 16 //
136
-                return 'E_CORE_ERROR';
137
-            case E_CORE_WARNING: // 32 //
138
-                return 'E_CORE_WARNING';
139
-            case E_COMPILE_ERROR: // 64 //
140
-                return 'E_COMPILE_ERROR';
141
-            case E_COMPILE_WARNING: // 128 //
142
-                return 'E_COMPILE_WARNING';
143
-            case E_USER_ERROR: // 256 //
144
-                return 'E_USER_ERROR';
145
-            case E_USER_WARNING: // 512 //
146
-                return 'E_USER_WARNING';
147
-            case E_USER_NOTICE: // 1024 //
148
-                return 'E_USER_NOTICE';
149
-            case E_STRICT: // 2048 //
150
-                return 'E_STRICT';
151
-            case E_RECOVERABLE_ERROR: // 4096 //
152
-                return 'E_RECOVERABLE_ERROR';
153
-            case E_DEPRECATED: // 8192 //
154
-                return 'E_DEPRECATED';
155
-            case E_USER_DEPRECATED: // 16384 //
156
-                return 'E_USER_DEPRECATED';
157
-            case E_ALL: // 16384 //
158
-                return 'E_ALL';
159
-        }
160
-        return '';
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     *    fatal_error_handler
167
-     *
168
-     * @return void
169
-     */
170
-    public static function fatal_error_handler()
171
-    {
172
-        $last_error = error_get_last();
173
-        if ($last_error['type'] === E_ERROR) {
174
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
175
-        }
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * _format_error
182
-     *
183
-     * @param $code
184
-     * @param $message
185
-     * @param $file
186
-     * @param $line
187
-     * @return string
188
-     */
189
-    private static function _format_error($code, $message, $file, $line)
190
-    {
191
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
192
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
193
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
194
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
195
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
196
-        $html .= '</tbody></table>';
197
-        return $html;
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * set_content_type
204
-     *
205
-     * @param $content_type
206
-     * @return string
207
-     */
208
-    public static function set_content_type($content_type)
209
-    {
210
-        return 'text/html';
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * @return void
217
-     * @throws EE_Error
218
-     * @throws ReflectionException
219
-     */
220
-    public function get_error()
221
-    {
222
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
223
-            throw $this;
224
-        }
225
-        // get separate user and developer messages if they exist
226
-        $msg = explode('||', $this->getMessage());
227
-        $user_msg = $msg[0];
228
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
229
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
230
-        // add details to _all_exceptions array
231
-        $x_time = time();
232
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
233
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
234
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
235
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
236
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
237
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
238
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
239
-        self::$_error_count++;
240
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
241
-        $this->display_errors();
242
-    }
243
-
244
-
245
-
246
-    /**
247
-     * @param bool   $check_stored
248
-     * @param string $type_to_check
249
-     * @return bool
250
-     */
251
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
252
-    {
253
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
254
-                     && ! empty(self::$_espresso_notices[$type_to_check])
255
-            ? true
256
-            : false;
257
-        if ($check_stored && ! $has_error) {
258
-            $notices = (array)get_option('ee_notices', array());
259
-            foreach ($notices as $type => $notice) {
260
-                if ($type === $type_to_check && $notice) {
261
-                    return true;
262
-                }
263
-            }
264
-        }
265
-        return $has_error;
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     * @echo string
272
-     * @throws \ReflectionException
273
-     */
274
-    public function display_errors()
275
-    {
276
-        $trace_details = '';
277
-        $output = '
31
+	/**
32
+	 * name of the file to log exceptions to
33
+	 *
34
+	 * @var string
35
+	 */
36
+	private static $_exception_log_file = 'espresso_error_log.txt';
37
+
38
+	/**
39
+	 *    stores details for all exception
40
+	 *
41
+	 * @var array
42
+	 */
43
+	private static $_all_exceptions = array();
44
+
45
+	/**
46
+	 *    tracks number of errors
47
+	 *
48
+	 * @var int
49
+	 */
50
+	private static $_error_count = 0;
51
+
52
+	/**
53
+	 * @var array $_espresso_notices
54
+	 */
55
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
56
+
57
+
58
+
59
+	/**
60
+	 * @override default exception handling
61
+	 * @param string         $message
62
+	 * @param int            $code
63
+	 * @param Exception|null $previous
64
+	 */
65
+	public function __construct($message, $code = 0, Exception $previous = null)
66
+	{
67
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
68
+			parent::__construct($message, $code);
69
+		} else {
70
+			parent::__construct($message, $code, $previous);
71
+		}
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 *    error_handler
78
+	 *
79
+	 * @param $code
80
+	 * @param $message
81
+	 * @param $file
82
+	 * @param $line
83
+	 * @return void
84
+	 */
85
+	public static function error_handler($code, $message, $file, $line)
86
+	{
87
+		$type = EE_Error::error_type($code);
88
+		$site = site_url();
89
+		switch ($site) {
90
+			case 'http://ee4.eventespresso.com/' :
91
+			case 'http://ee4decaf.eventespresso.com/' :
92
+			case 'http://ee4hf.eventespresso.com/' :
93
+			case 'http://ee4a.eventespresso.com/' :
94
+			case 'http://ee4ad.eventespresso.com/' :
95
+			case 'http://ee4b.eventespresso.com/' :
96
+			case 'http://ee4bd.eventespresso.com/' :
97
+			case 'http://ee4d.eventespresso.com/' :
98
+			case 'http://ee4dd.eventespresso.com/' :
99
+				$to = '[email protected]';
100
+				break;
101
+			default :
102
+				$to = get_option('admin_email');
103
+		}
104
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
105
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
106
+		if (function_exists('wp_mail')) {
107
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
108
+			wp_mail($to, $subject, $msg);
109
+		}
110
+		echo '<div id="message" class="espresso-notices error"><p>';
111
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
112
+		echo '<br /></p></div>';
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * error_type
119
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
120
+	 *
121
+	 * @param $code
122
+	 * @return string
123
+	 */
124
+	public static function error_type($code)
125
+	{
126
+		switch ($code) {
127
+			case E_ERROR: // 1 //
128
+				return 'E_ERROR';
129
+			case E_WARNING: // 2 //
130
+				return 'E_WARNING';
131
+			case E_PARSE: // 4 //
132
+				return 'E_PARSE';
133
+			case E_NOTICE: // 8 //
134
+				return 'E_NOTICE';
135
+			case E_CORE_ERROR: // 16 //
136
+				return 'E_CORE_ERROR';
137
+			case E_CORE_WARNING: // 32 //
138
+				return 'E_CORE_WARNING';
139
+			case E_COMPILE_ERROR: // 64 //
140
+				return 'E_COMPILE_ERROR';
141
+			case E_COMPILE_WARNING: // 128 //
142
+				return 'E_COMPILE_WARNING';
143
+			case E_USER_ERROR: // 256 //
144
+				return 'E_USER_ERROR';
145
+			case E_USER_WARNING: // 512 //
146
+				return 'E_USER_WARNING';
147
+			case E_USER_NOTICE: // 1024 //
148
+				return 'E_USER_NOTICE';
149
+			case E_STRICT: // 2048 //
150
+				return 'E_STRICT';
151
+			case E_RECOVERABLE_ERROR: // 4096 //
152
+				return 'E_RECOVERABLE_ERROR';
153
+			case E_DEPRECATED: // 8192 //
154
+				return 'E_DEPRECATED';
155
+			case E_USER_DEPRECATED: // 16384 //
156
+				return 'E_USER_DEPRECATED';
157
+			case E_ALL: // 16384 //
158
+				return 'E_ALL';
159
+		}
160
+		return '';
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 *    fatal_error_handler
167
+	 *
168
+	 * @return void
169
+	 */
170
+	public static function fatal_error_handler()
171
+	{
172
+		$last_error = error_get_last();
173
+		if ($last_error['type'] === E_ERROR) {
174
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
175
+		}
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * _format_error
182
+	 *
183
+	 * @param $code
184
+	 * @param $message
185
+	 * @param $file
186
+	 * @param $line
187
+	 * @return string
188
+	 */
189
+	private static function _format_error($code, $message, $file, $line)
190
+	{
191
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
192
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
193
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
194
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
195
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
196
+		$html .= '</tbody></table>';
197
+		return $html;
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * set_content_type
204
+	 *
205
+	 * @param $content_type
206
+	 * @return string
207
+	 */
208
+	public static function set_content_type($content_type)
209
+	{
210
+		return 'text/html';
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * @return void
217
+	 * @throws EE_Error
218
+	 * @throws ReflectionException
219
+	 */
220
+	public function get_error()
221
+	{
222
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
223
+			throw $this;
224
+		}
225
+		// get separate user and developer messages if they exist
226
+		$msg = explode('||', $this->getMessage());
227
+		$user_msg = $msg[0];
228
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
229
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
230
+		// add details to _all_exceptions array
231
+		$x_time = time();
232
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
233
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
234
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
235
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
236
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
237
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
238
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
239
+		self::$_error_count++;
240
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
241
+		$this->display_errors();
242
+	}
243
+
244
+
245
+
246
+	/**
247
+	 * @param bool   $check_stored
248
+	 * @param string $type_to_check
249
+	 * @return bool
250
+	 */
251
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
252
+	{
253
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
254
+					 && ! empty(self::$_espresso_notices[$type_to_check])
255
+			? true
256
+			: false;
257
+		if ($check_stored && ! $has_error) {
258
+			$notices = (array)get_option('ee_notices', array());
259
+			foreach ($notices as $type => $notice) {
260
+				if ($type === $type_to_check && $notice) {
261
+					return true;
262
+				}
263
+			}
264
+		}
265
+		return $has_error;
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 * @echo string
272
+	 * @throws \ReflectionException
273
+	 */
274
+	public function display_errors()
275
+	{
276
+		$trace_details = '';
277
+		$output = '
278 278
 <style type="text/css">
279 279
 	#ee-error-message {
280 280
 		max-width:90% !important;
@@ -330,21 +330,21 @@  discard block
 block discarded – undo
330 330
 	}
331 331
 </style>
332 332
 <div id="ee-error-message" class="error">';
333
-        if (! WP_DEBUG) {
334
-            $output .= '
333
+		if (! WP_DEBUG) {
334
+			$output .= '
335 335
 	<p>';
336
-        }
337
-        // cycle thru errors
338
-        foreach (self::$_all_exceptions as $time => $ex) {
339
-            $error_code = '';
340
-            // process trace info
341
-            if (empty($ex['trace'])) {
342
-                $trace_details .= __(
343
-                    'Sorry, but no trace information was available for this exception.',
344
-                    'event_espresso'
345
-                );
346
-            } else {
347
-                $trace_details .= '
336
+		}
337
+		// cycle thru errors
338
+		foreach (self::$_all_exceptions as $time => $ex) {
339
+			$error_code = '';
340
+			// process trace info
341
+			if (empty($ex['trace'])) {
342
+				$trace_details .= __(
343
+					'Sorry, but no trace information was available for this exception.',
344
+					'event_espresso'
345
+				);
346
+			} else {
347
+				$trace_details .= '
348 348
 			<div id="ee-trace-details">
349 349
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
350 350
 				<tr>
@@ -354,43 +354,43 @@  discard block
 block discarded – undo
354 354
 					<th scope="col" align="left">Class</th>
355 355
 					<th scope="col" align="left">Method( arguments )</th>
356 356
 				</tr>';
357
-                $last_on_stack = count($ex['trace']) - 1;
358
-                // reverse array so that stack is in proper chronological order
359
-                $sorted_trace = array_reverse($ex['trace']);
360
-                foreach ($sorted_trace as $nmbr => $trace) {
361
-                    $file = isset($trace['file']) ? $trace['file'] : '';
362
-                    $class = isset($trace['class']) ? $trace['class'] : '';
363
-                    $type = isset($trace['type']) ? $trace['type'] : '';
364
-                    $function = isset($trace['function']) ? $trace['function'] : '';
365
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
366
-                    $line = isset($trace['line']) ? $trace['line'] : '';
367
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
368
-                    if (empty($file) && ! empty($class)) {
369
-                        $a = new ReflectionClass($class);
370
-                        $file = $a->getFileName();
371
-                        if (empty($line) && ! empty($function)) {
372
-                            try {
373
-                                //if $function is a closure, this throws an exception
374
-                                $b = new ReflectionMethod($class, $function);
375
-                                $line = $b->getStartLine();
376
-                            } catch (Exception $closure_exception) {
377
-                                $line = 'unknown';
378
-                            }
379
-                        }
380
-                    }
381
-                    if ($nmbr === $last_on_stack) {
382
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
383
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
384
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
385
-                    }
386
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
387
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
388
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
389
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
390
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
391
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
392
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
393
-                    $trace_details .= '
357
+				$last_on_stack = count($ex['trace']) - 1;
358
+				// reverse array so that stack is in proper chronological order
359
+				$sorted_trace = array_reverse($ex['trace']);
360
+				foreach ($sorted_trace as $nmbr => $trace) {
361
+					$file = isset($trace['file']) ? $trace['file'] : '';
362
+					$class = isset($trace['class']) ? $trace['class'] : '';
363
+					$type = isset($trace['type']) ? $trace['type'] : '';
364
+					$function = isset($trace['function']) ? $trace['function'] : '';
365
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
366
+					$line = isset($trace['line']) ? $trace['line'] : '';
367
+					$zebra = ($nmbr % 2) ? ' odd' : '';
368
+					if (empty($file) && ! empty($class)) {
369
+						$a = new ReflectionClass($class);
370
+						$file = $a->getFileName();
371
+						if (empty($line) && ! empty($function)) {
372
+							try {
373
+								//if $function is a closure, this throws an exception
374
+								$b = new ReflectionMethod($class, $function);
375
+								$line = $b->getStartLine();
376
+							} catch (Exception $closure_exception) {
377
+								$line = 'unknown';
378
+							}
379
+						}
380
+					}
381
+					if ($nmbr === $last_on_stack) {
382
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
383
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
384
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
385
+					}
386
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
387
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
388
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
389
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
390
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
391
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
392
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
393
+					$trace_details .= '
394 394
 					<tr>
395 395
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
396 396
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -398,523 +398,523 @@  discard block
 block discarded – undo
398 398
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
399 399
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
400 400
 					</tr>';
401
-                }
402
-                $trace_details .= '
401
+				}
402
+				$trace_details .= '
403 403
 			 </table>
404 404
 			</div>';
405
-            }
406
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
407
-            // add generic non-identifying messages for non-privileged users
408
-            if (! WP_DEBUG) {
409
-                $output .= '<span class="ee-error-user-msg-spn">'
410
-                           . trim($ex['msg'])
411
-                           . '</span> &nbsp; <sup>'
412
-                           . $ex['code']
413
-                           . '</sup><br />';
414
-            } else {
415
-                // or helpful developer messages if debugging is on
416
-                $output .= '
405
+			}
406
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
407
+			// add generic non-identifying messages for non-privileged users
408
+			if (! WP_DEBUG) {
409
+				$output .= '<span class="ee-error-user-msg-spn">'
410
+						   . trim($ex['msg'])
411
+						   . '</span> &nbsp; <sup>'
412
+						   . $ex['code']
413
+						   . '</sup><br />';
414
+			} else {
415
+				// or helpful developer messages if debugging is on
416
+				$output .= '
417 417
 		<div class="ee-error-dev-msg-dv">
418 418
 			<p class="ee-error-dev-msg-pg">
419 419
 				<strong class="ee-error-dev-msg-str">An '
420
-                           . $ex['name']
421
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
422
-                           . $ex['code']
423
-                           . '</span><br />
420
+						   . $ex['name']
421
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
422
+						   . $ex['code']
423
+						   . '</span><br />
424 424
 				<span class="big-text">"'
425
-                           . trim($ex['msg'])
426
-                           . '"</span><br/>
425
+						   . trim($ex['msg'])
426
+						   . '"</span><br/>
427 427
 				<a id="display-ee-error-trace-'
428
-                           . self::$_error_count
429
-                           . $time
430
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
431
-                           . self::$_error_count
432
-                           . $time
433
-                           . '">
428
+						   . self::$_error_count
429
+						   . $time
430
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
431
+						   . self::$_error_count
432
+						   . $time
433
+						   . '">
434 434
 					'
435
-                           . __('click to view backtrace and class/method details', 'event_espresso')
436
-                           . '
435
+						   . __('click to view backtrace and class/method details', 'event_espresso')
436
+						   . '
437 437
 				</a><br />
438 438
 				<span class="small-text lt-grey-text">'
439
-                           . $ex['file']
440
-                           . ' &nbsp; ( line no: '
441
-                           . $ex['line']
442
-                           . ' )</span>
439
+						   . $ex['file']
440
+						   . ' &nbsp; ( line no: '
441
+						   . $ex['line']
442
+						   . ' )</span>
443 443
 			</p>
444 444
 			<div id="ee-error-trace-'
445
-                           . self::$_error_count
446
-                           . $time
447
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
445
+						   . self::$_error_count
446
+						   . $time
447
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
448 448
 				'
449
-                           . $trace_details;
450
-                if (! empty($class)) {
451
-                    $output .= '
449
+						   . $trace_details;
450
+				if (! empty($class)) {
451
+					$output .= '
452 452
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
453 453
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
454 454
 						<h3>Class Details</h3>';
455
-                    $a = new ReflectionClass($class);
456
-                    $output .= '
455
+					$a = new ReflectionClass($class);
456
+					$output .= '
457 457
 						<pre>' . $a . '</pre>
458 458
 					</div>
459 459
 				</div>';
460
-                }
461
-                $output .= '
460
+				}
461
+				$output .= '
462 462
 			</div>
463 463
 		</div>
464 464
 		<br />';
465
-            }
466
-            $this->write_to_error_log($time, $ex);
467
-        }
468
-        // remove last linebreak
469
-        $output = substr($output, 0, -6);
470
-        if (! WP_DEBUG) {
471
-            $output .= '
465
+			}
466
+			$this->write_to_error_log($time, $ex);
467
+		}
468
+		// remove last linebreak
469
+		$output = substr($output, 0, -6);
470
+		if (! WP_DEBUG) {
471
+			$output .= '
472 472
 	</p>';
473
-        }
474
-        $output .= '
473
+		}
474
+		$output .= '
475 475
 </div>';
476
-        $output .= self::_print_scripts(true);
477
-        if (defined('DOING_AJAX')) {
478
-            echo wp_json_encode(array('error' => $output));
479
-            exit();
480
-        }
481
-        echo $output;
482
-        die();
483
-    }
484
-
485
-
486
-
487
-    /**
488
-     *    generate string from exception trace args
489
-     *
490
-     * @param array $arguments
491
-     * @param bool  $array
492
-     * @return string
493
-     */
494
-    private function _convert_args_to_string($arguments = array(), $array = false)
495
-    {
496
-        $arg_string = '';
497
-        if (! empty($arguments)) {
498
-            $args = array();
499
-            foreach ($arguments as $arg) {
500
-                if (! empty($arg)) {
501
-                    if (is_string($arg)) {
502
-                        $args[] = " '" . $arg . "'";
503
-                    } elseif (is_array($arg)) {
504
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
505
-                    } elseif ($arg === null) {
506
-                        $args[] = ' NULL';
507
-                    } elseif (is_bool($arg)) {
508
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
509
-                    } elseif (is_object($arg)) {
510
-                        $args[] = ' OBJECT ' . get_class($arg);
511
-                    } elseif (is_resource($arg)) {
512
-                        $args[] = get_resource_type($arg);
513
-                    } else {
514
-                        $args[] = $arg;
515
-                    }
516
-                }
517
-            }
518
-            $arg_string = implode(', ', $args);
519
-        }
520
-        if ($array) {
521
-            $arg_string .= ' )';
522
-        }
523
-        return $arg_string;
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     *    add error message
530
-     *
531
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
532
-     *                            separate messages for user || dev
533
-     * @param        string $file the file that the error occurred in - just use __FILE__
534
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
535
-     * @param        string $line the line number where the error occurred - just use __LINE__
536
-     * @return        void
537
-     */
538
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
539
-    {
540
-        self::_add_notice('errors', $msg, $file, $func, $line);
541
-        self::$_error_count++;
542
-    }
543
-
544
-
545
-
546
-    /**
547
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
548
-     * adds an error
549
-     *
550
-     * @param string $msg
551
-     * @param string $file
552
-     * @param string $func
553
-     * @param string $line
554
-     * @throws EE_Error
555
-     */
556
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
557
-    {
558
-        if (WP_DEBUG) {
559
-            throw new EE_Error($msg);
560
-        }
561
-        EE_Error::add_error($msg, $file, $func, $line);
562
-    }
563
-
564
-
565
-
566
-    /**
567
-     *    add success message
568
-     *
569
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
570
-     *                            separate messages for user || dev
571
-     * @param        string $file the file that the error occurred in - just use __FILE__
572
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
573
-     * @param        string $line the line number where the error occurred - just use __LINE__
574
-     * @return        void
575
-     */
576
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
577
-    {
578
-        self::_add_notice('success', $msg, $file, $func, $line);
579
-    }
580
-
581
-
582
-
583
-    /**
584
-     *    add attention message
585
-     *
586
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
587
-     *                            separate messages for user || dev
588
-     * @param        string $file the file that the error occurred in - just use __FILE__
589
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
590
-     * @param        string $line the line number where the error occurred - just use __LINE__
591
-     * @return        void
592
-     */
593
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
594
-    {
595
-        self::_add_notice('attention', $msg, $file, $func, $line);
596
-    }
597
-
598
-
599
-
600
-    /**
601
-     * @param string $type whether the message is for a success or error notification
602
-     * @param string $msg the message to display to users or developers
603
-     *                    - adding a double pipe || (OR) creates separate messages for user || dev
604
-     * @param string $file the file that the error occurred in - just use __FILE__
605
-     * @param string $func the function/method that the error occurred in - just use __FUNCTION__
606
-     * @param string $line the line number where the error occurred - just use __LINE__
607
-     * @return void
608
-     */
609
-    private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
610
-    {
611
-        if (empty($msg)) {
612
-            EE_Error::doing_it_wrong(
613
-                'EE_Error::add_' . $type . '()',
614
-                sprintf(
615
-                    __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
616
-                        'event_espresso'),
617
-                    $type,
618
-                    $file,
619
-                    $line
620
-                ),
621
-                EVENT_ESPRESSO_VERSION
622
-            );
623
-        }
624
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
625
-            EE_Error::doing_it_wrong(
626
-                'EE_Error::add_error()',
627
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
628
-                    'event_espresso'),
629
-                EVENT_ESPRESSO_VERSION
630
-            );
631
-        }
632
-        // get separate user and developer messages if they exist
633
-        $msg      = explode('||', $msg);
634
-        $user_msg = $msg[0];
635
-        $dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
636
-        /**
637
-         * Do an action so other code can be triggered when a notice is created
638
-         *
639
-         * @param string $type     can be 'errors', 'attention', or 'success'
640
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
641
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
642
-         * @param string $file     file where error was generated
643
-         * @param string $func     function where error was generated
644
-         * @param string $line     line where error was generated
645
-         */
646
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
647
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
648
-        // add notice if message exists
649
-        if (! empty($msg)) {
650
-            // get error code
651
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
652
-            if (WP_DEBUG && $type === 'errors') {
653
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
654
-            }
655
-            // add notice. Index by code if it's not blank
656
-            if ($notice_code) {
657
-                self::$_espresso_notices[$type][$notice_code] = $msg;
658
-            } else {
659
-                self::$_espresso_notices[$type][] = $msg;
660
-            }
661
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
662
-        }
663
-    }
664
-
665
-
666
-    /**
667
-     * in some case it may be necessary to overwrite the existing success messages
668
-     *
669
-     * @return        void
670
-     */
671
-    public static function overwrite_success()
672
-    {
673
-        self::$_espresso_notices['success'] = false;
674
-    }
675
-
676
-
677
-
678
-    /**
679
-     * in some case it may be necessary to overwrite the existing attention messages
680
-     *
681
-     * @return void
682
-     */
683
-    public static function overwrite_attention()
684
-    {
685
-        self::$_espresso_notices['attention'] = false;
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * in some case it may be necessary to overwrite the existing error messages
692
-     *
693
-     * @return void
694
-     */
695
-    public static function overwrite_errors()
696
-    {
697
-        self::$_espresso_notices['errors'] = false;
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * @return void
704
-     */
705
-    public static function reset_notices()
706
-    {
707
-        self::$_espresso_notices['success']   = false;
708
-        self::$_espresso_notices['attention'] = false;
709
-        self::$_espresso_notices['errors']    = false;
710
-    }
711
-
712
-
713
-
714
-    /**
715
-     * @return int
716
-     */
717
-    public static function has_notices()
718
-    {
719
-        $has_notices = 0;
720
-        // check for success messages
721
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
722
-            ? 3
723
-            : $has_notices;
724
-        // check for attention messages
725
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
726
-            ? 2
727
-            : $has_notices;
728
-        // check for error messages
729
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
730
-            ? 1
731
-            : $has_notices;
732
-        return $has_notices;
733
-    }
734
-
735
-
736
-    /**
737
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
738
-     *
739
-     * @since 4.9.0
740
-     * @return array
741
-     */
742
-    public static function get_vanilla_notices()
743
-    {
744
-        return array(
745
-            'success'   => isset(self::$_espresso_notices['success'])
746
-                ? self::$_espresso_notices['success']
747
-                : array(),
748
-            'attention' => isset(self::$_espresso_notices['attention'])
749
-                ? self::$_espresso_notices['attention']
750
-                : array(),
751
-            'errors'    => isset(self::$_espresso_notices['errors'])
752
-                ? self::$_espresso_notices['errors']
753
-                : array(),
754
-        );
755
-    }
756
-
757
-
758
-
759
-    /**
760
-     * compile all error or success messages into one string
761
-     *
762
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
763
-     * @param boolean $format_output     whether or not to format the messages for display in the WP admin
764
-     * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
765
-     *                                          - ONLY do this just before redirecting
766
-     * @param boolean $remove_empty      whether or not to unset empty messages
767
-     * @return array
768
-     */
769
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
770
-    {
771
-        // do_action('AHEE_log', __FILE__, __FUNCTION__, '');
772
-        $success_messages   = '';
773
-        $attention_messages = '';
774
-        $error_messages     = '';
775
-        $print_scripts      = false;
776
-        // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
777
-        // either save notices to the db
778
-        if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
779
-            $existing_notices  = get_option('ee_notices', array());
780
-            $existing_notices = $existing_notices !== '' ? $existing_notices : array();
781
-            self::$_espresso_notices = array_merge(
782
-                $existing_notices,
783
-                self::$_espresso_notices
784
-            );
785
-            update_option('ee_notices', self::$_espresso_notices);
786
-            return array();
787
-        }
788
-        // grab any notices that have been previously saved
789
-        if ($notices = get_option('ee_notices', false)) {
790
-            foreach ($notices as $type => $notice) {
791
-                if (is_array($notice) && ! empty($notice)) {
792
-                    // make sure that existing notice type is an array
793
-                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
794
-                                                      && ! empty(self::$_espresso_notices[$type])
795
-                        ? self::$_espresso_notices[$type]
796
-                        : array();
797
-                    // merge stored notices with any newly created ones
798
-                    self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
799
-                    $print_scripts                  = true;
800
-                }
801
-            }
802
-            // now clear any stored notices
803
-            update_option('ee_notices', false);
804
-        }
805
-        // check for success messages
806
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
807
-            // combine messages
808
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br />');
809
-            $print_scripts    = true;
810
-        }
811
-        // check for attention messages
812
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
813
-            // combine messages
814
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
815
-            $print_scripts      = true;
816
-        }
817
-        // check for error messages
818
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
819
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
820
-                ? __('The following errors have occurred:<br />', 'event_espresso')
821
-                : __('An error has occurred:<br />', 'event_espresso');
822
-            // combine messages
823
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
824
-            $print_scripts  = true;
825
-        }
826
-        if ($format_output) {
827
-
828
-            $notices = '<div id="espresso-notices">';
829
-            $close = is_admin() ? ''
830
-                : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
831
-            if ($success_messages !== '') {
832
-                $css_id    = is_admin() ? 'message' : 'espresso-notices-success';
833
-                $css_class = is_admin() ? 'updated fade' : 'success fade-away';
834
-                //showMessage( $success_messages );
835
-                $notices .= '<div id="'
836
-                            . $css_id
837
-                            . '" class="espresso-notices '
838
-                            . $css_class
839
-                            . '" style="display:none;"><p>'
840
-                            . $success_messages
841
-                            . '</p>'
842
-                            . $close
843
-                            . '</div>';
844
-            }
845
-            if ($attention_messages !== '') {
846
-                $css_id    = is_admin() ? 'message' : 'espresso-notices-attention';
847
-                $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
848
-                //showMessage( $error_messages, TRUE );
849
-                $notices .= '<div id="'
850
-                            . $css_id
851
-                            . '" class="espresso-notices '
852
-                            . $css_class
853
-                            . '" style="display:none;"><p>'
854
-                            . $attention_messages
855
-                            . '</p>'
856
-                            . $close
857
-                            . '</div>';
858
-            }
859
-            if ($error_messages !== '') {
860
-                $css_id    = is_admin() ? 'message' : 'espresso-notices-error';
861
-                $css_class = is_admin() ? 'error' : 'error fade-away';
862
-                //showMessage( $error_messages, TRUE );
863
-                $notices .= '<div id="'
864
-                            . $css_id
865
-                            . '" class="espresso-notices '
866
-                            . $css_class
867
-                            . '" style="display:none;"><p>'
868
-                            . $error_messages
869
-                            . '</p>'
870
-                            . $close
871
-                            . '</div>';
872
-            }
873
-            $notices .= '</div>';
874
-        } else {
875
-
876
-            $notices = array(
877
-                'success'   => $success_messages,
878
-                'attention' => $attention_messages,
879
-                'errors'    => $error_messages,
880
-            );
881
-            if ($remove_empty) {
882
-                // remove empty notices
883
-                foreach ($notices as $type => $notice) {
884
-                    if (empty($notice)) {
885
-                        unset($notices[$type]);
886
-                    }
887
-                }
888
-            }
889
-        }
890
-        if ($print_scripts) {
891
-            self::_print_scripts();
892
-        }
893
-        return $notices;
894
-    }
895
-
896
-
897
-
898
-    /**
899
-     * _print_scripts
900
-     *
901
-     * @param    bool $force_print
902
-     * @return    string
903
-     */
904
-    private static function _print_scripts($force_print = false)
905
-    {
906
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
907
-            if (wp_script_is('ee_error_js', 'enqueued')) {
908
-                return '';
909
-            }
910
-            if (wp_script_is('ee_error_js', 'registered')) {
911
-                wp_enqueue_style('espresso_default');
912
-                wp_enqueue_style('espresso_custom_css');
913
-                wp_enqueue_script('ee_error_js');
914
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
915
-            }
916
-        } else {
917
-            return '
476
+		$output .= self::_print_scripts(true);
477
+		if (defined('DOING_AJAX')) {
478
+			echo wp_json_encode(array('error' => $output));
479
+			exit();
480
+		}
481
+		echo $output;
482
+		die();
483
+	}
484
+
485
+
486
+
487
+	/**
488
+	 *    generate string from exception trace args
489
+	 *
490
+	 * @param array $arguments
491
+	 * @param bool  $array
492
+	 * @return string
493
+	 */
494
+	private function _convert_args_to_string($arguments = array(), $array = false)
495
+	{
496
+		$arg_string = '';
497
+		if (! empty($arguments)) {
498
+			$args = array();
499
+			foreach ($arguments as $arg) {
500
+				if (! empty($arg)) {
501
+					if (is_string($arg)) {
502
+						$args[] = " '" . $arg . "'";
503
+					} elseif (is_array($arg)) {
504
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
505
+					} elseif ($arg === null) {
506
+						$args[] = ' NULL';
507
+					} elseif (is_bool($arg)) {
508
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
509
+					} elseif (is_object($arg)) {
510
+						$args[] = ' OBJECT ' . get_class($arg);
511
+					} elseif (is_resource($arg)) {
512
+						$args[] = get_resource_type($arg);
513
+					} else {
514
+						$args[] = $arg;
515
+					}
516
+				}
517
+			}
518
+			$arg_string = implode(', ', $args);
519
+		}
520
+		if ($array) {
521
+			$arg_string .= ' )';
522
+		}
523
+		return $arg_string;
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 *    add error message
530
+	 *
531
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
532
+	 *                            separate messages for user || dev
533
+	 * @param        string $file the file that the error occurred in - just use __FILE__
534
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
535
+	 * @param        string $line the line number where the error occurred - just use __LINE__
536
+	 * @return        void
537
+	 */
538
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
539
+	{
540
+		self::_add_notice('errors', $msg, $file, $func, $line);
541
+		self::$_error_count++;
542
+	}
543
+
544
+
545
+
546
+	/**
547
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
548
+	 * adds an error
549
+	 *
550
+	 * @param string $msg
551
+	 * @param string $file
552
+	 * @param string $func
553
+	 * @param string $line
554
+	 * @throws EE_Error
555
+	 */
556
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
557
+	{
558
+		if (WP_DEBUG) {
559
+			throw new EE_Error($msg);
560
+		}
561
+		EE_Error::add_error($msg, $file, $func, $line);
562
+	}
563
+
564
+
565
+
566
+	/**
567
+	 *    add success message
568
+	 *
569
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
570
+	 *                            separate messages for user || dev
571
+	 * @param        string $file the file that the error occurred in - just use __FILE__
572
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
573
+	 * @param        string $line the line number where the error occurred - just use __LINE__
574
+	 * @return        void
575
+	 */
576
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
577
+	{
578
+		self::_add_notice('success', $msg, $file, $func, $line);
579
+	}
580
+
581
+
582
+
583
+	/**
584
+	 *    add attention message
585
+	 *
586
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
587
+	 *                            separate messages for user || dev
588
+	 * @param        string $file the file that the error occurred in - just use __FILE__
589
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
590
+	 * @param        string $line the line number where the error occurred - just use __LINE__
591
+	 * @return        void
592
+	 */
593
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
594
+	{
595
+		self::_add_notice('attention', $msg, $file, $func, $line);
596
+	}
597
+
598
+
599
+
600
+	/**
601
+	 * @param string $type whether the message is for a success or error notification
602
+	 * @param string $msg the message to display to users or developers
603
+	 *                    - adding a double pipe || (OR) creates separate messages for user || dev
604
+	 * @param string $file the file that the error occurred in - just use __FILE__
605
+	 * @param string $func the function/method that the error occurred in - just use __FUNCTION__
606
+	 * @param string $line the line number where the error occurred - just use __LINE__
607
+	 * @return void
608
+	 */
609
+	private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
610
+	{
611
+		if (empty($msg)) {
612
+			EE_Error::doing_it_wrong(
613
+				'EE_Error::add_' . $type . '()',
614
+				sprintf(
615
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
616
+						'event_espresso'),
617
+					$type,
618
+					$file,
619
+					$line
620
+				),
621
+				EVENT_ESPRESSO_VERSION
622
+			);
623
+		}
624
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
625
+			EE_Error::doing_it_wrong(
626
+				'EE_Error::add_error()',
627
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
628
+					'event_espresso'),
629
+				EVENT_ESPRESSO_VERSION
630
+			);
631
+		}
632
+		// get separate user and developer messages if they exist
633
+		$msg      = explode('||', $msg);
634
+		$user_msg = $msg[0];
635
+		$dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
636
+		/**
637
+		 * Do an action so other code can be triggered when a notice is created
638
+		 *
639
+		 * @param string $type     can be 'errors', 'attention', or 'success'
640
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
641
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
642
+		 * @param string $file     file where error was generated
643
+		 * @param string $func     function where error was generated
644
+		 * @param string $line     line where error was generated
645
+		 */
646
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
647
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
648
+		// add notice if message exists
649
+		if (! empty($msg)) {
650
+			// get error code
651
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
652
+			if (WP_DEBUG && $type === 'errors') {
653
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
654
+			}
655
+			// add notice. Index by code if it's not blank
656
+			if ($notice_code) {
657
+				self::$_espresso_notices[$type][$notice_code] = $msg;
658
+			} else {
659
+				self::$_espresso_notices[$type][] = $msg;
660
+			}
661
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
662
+		}
663
+	}
664
+
665
+
666
+	/**
667
+	 * in some case it may be necessary to overwrite the existing success messages
668
+	 *
669
+	 * @return        void
670
+	 */
671
+	public static function overwrite_success()
672
+	{
673
+		self::$_espresso_notices['success'] = false;
674
+	}
675
+
676
+
677
+
678
+	/**
679
+	 * in some case it may be necessary to overwrite the existing attention messages
680
+	 *
681
+	 * @return void
682
+	 */
683
+	public static function overwrite_attention()
684
+	{
685
+		self::$_espresso_notices['attention'] = false;
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * in some case it may be necessary to overwrite the existing error messages
692
+	 *
693
+	 * @return void
694
+	 */
695
+	public static function overwrite_errors()
696
+	{
697
+		self::$_espresso_notices['errors'] = false;
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * @return void
704
+	 */
705
+	public static function reset_notices()
706
+	{
707
+		self::$_espresso_notices['success']   = false;
708
+		self::$_espresso_notices['attention'] = false;
709
+		self::$_espresso_notices['errors']    = false;
710
+	}
711
+
712
+
713
+
714
+	/**
715
+	 * @return int
716
+	 */
717
+	public static function has_notices()
718
+	{
719
+		$has_notices = 0;
720
+		// check for success messages
721
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
722
+			? 3
723
+			: $has_notices;
724
+		// check for attention messages
725
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
726
+			? 2
727
+			: $has_notices;
728
+		// check for error messages
729
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
730
+			? 1
731
+			: $has_notices;
732
+		return $has_notices;
733
+	}
734
+
735
+
736
+	/**
737
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
738
+	 *
739
+	 * @since 4.9.0
740
+	 * @return array
741
+	 */
742
+	public static function get_vanilla_notices()
743
+	{
744
+		return array(
745
+			'success'   => isset(self::$_espresso_notices['success'])
746
+				? self::$_espresso_notices['success']
747
+				: array(),
748
+			'attention' => isset(self::$_espresso_notices['attention'])
749
+				? self::$_espresso_notices['attention']
750
+				: array(),
751
+			'errors'    => isset(self::$_espresso_notices['errors'])
752
+				? self::$_espresso_notices['errors']
753
+				: array(),
754
+		);
755
+	}
756
+
757
+
758
+
759
+	/**
760
+	 * compile all error or success messages into one string
761
+	 *
762
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
763
+	 * @param boolean $format_output     whether or not to format the messages for display in the WP admin
764
+	 * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
765
+	 *                                          - ONLY do this just before redirecting
766
+	 * @param boolean $remove_empty      whether or not to unset empty messages
767
+	 * @return array
768
+	 */
769
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
770
+	{
771
+		// do_action('AHEE_log', __FILE__, __FUNCTION__, '');
772
+		$success_messages   = '';
773
+		$attention_messages = '';
774
+		$error_messages     = '';
775
+		$print_scripts      = false;
776
+		// EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
777
+		// either save notices to the db
778
+		if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
779
+			$existing_notices  = get_option('ee_notices', array());
780
+			$existing_notices = $existing_notices !== '' ? $existing_notices : array();
781
+			self::$_espresso_notices = array_merge(
782
+				$existing_notices,
783
+				self::$_espresso_notices
784
+			);
785
+			update_option('ee_notices', self::$_espresso_notices);
786
+			return array();
787
+		}
788
+		// grab any notices that have been previously saved
789
+		if ($notices = get_option('ee_notices', false)) {
790
+			foreach ($notices as $type => $notice) {
791
+				if (is_array($notice) && ! empty($notice)) {
792
+					// make sure that existing notice type is an array
793
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
794
+													  && ! empty(self::$_espresso_notices[$type])
795
+						? self::$_espresso_notices[$type]
796
+						: array();
797
+					// merge stored notices with any newly created ones
798
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
799
+					$print_scripts                  = true;
800
+				}
801
+			}
802
+			// now clear any stored notices
803
+			update_option('ee_notices', false);
804
+		}
805
+		// check for success messages
806
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
807
+			// combine messages
808
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br />');
809
+			$print_scripts    = true;
810
+		}
811
+		// check for attention messages
812
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
813
+			// combine messages
814
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
815
+			$print_scripts      = true;
816
+		}
817
+		// check for error messages
818
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
819
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
820
+				? __('The following errors have occurred:<br />', 'event_espresso')
821
+				: __('An error has occurred:<br />', 'event_espresso');
822
+			// combine messages
823
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
824
+			$print_scripts  = true;
825
+		}
826
+		if ($format_output) {
827
+
828
+			$notices = '<div id="espresso-notices">';
829
+			$close = is_admin() ? ''
830
+				: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
831
+			if ($success_messages !== '') {
832
+				$css_id    = is_admin() ? 'message' : 'espresso-notices-success';
833
+				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
834
+				//showMessage( $success_messages );
835
+				$notices .= '<div id="'
836
+							. $css_id
837
+							. '" class="espresso-notices '
838
+							. $css_class
839
+							. '" style="display:none;"><p>'
840
+							. $success_messages
841
+							. '</p>'
842
+							. $close
843
+							. '</div>';
844
+			}
845
+			if ($attention_messages !== '') {
846
+				$css_id    = is_admin() ? 'message' : 'espresso-notices-attention';
847
+				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
848
+				//showMessage( $error_messages, TRUE );
849
+				$notices .= '<div id="'
850
+							. $css_id
851
+							. '" class="espresso-notices '
852
+							. $css_class
853
+							. '" style="display:none;"><p>'
854
+							. $attention_messages
855
+							. '</p>'
856
+							. $close
857
+							. '</div>';
858
+			}
859
+			if ($error_messages !== '') {
860
+				$css_id    = is_admin() ? 'message' : 'espresso-notices-error';
861
+				$css_class = is_admin() ? 'error' : 'error fade-away';
862
+				//showMessage( $error_messages, TRUE );
863
+				$notices .= '<div id="'
864
+							. $css_id
865
+							. '" class="espresso-notices '
866
+							. $css_class
867
+							. '" style="display:none;"><p>'
868
+							. $error_messages
869
+							. '</p>'
870
+							. $close
871
+							. '</div>';
872
+			}
873
+			$notices .= '</div>';
874
+		} else {
875
+
876
+			$notices = array(
877
+				'success'   => $success_messages,
878
+				'attention' => $attention_messages,
879
+				'errors'    => $error_messages,
880
+			);
881
+			if ($remove_empty) {
882
+				// remove empty notices
883
+				foreach ($notices as $type => $notice) {
884
+					if (empty($notice)) {
885
+						unset($notices[$type]);
886
+					}
887
+				}
888
+			}
889
+		}
890
+		if ($print_scripts) {
891
+			self::_print_scripts();
892
+		}
893
+		return $notices;
894
+	}
895
+
896
+
897
+
898
+	/**
899
+	 * _print_scripts
900
+	 *
901
+	 * @param    bool $force_print
902
+	 * @return    string
903
+	 */
904
+	private static function _print_scripts($force_print = false)
905
+	{
906
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
907
+			if (wp_script_is('ee_error_js', 'enqueued')) {
908
+				return '';
909
+			}
910
+			if (wp_script_is('ee_error_js', 'registered')) {
911
+				wp_enqueue_style('espresso_default');
912
+				wp_enqueue_style('espresso_custom_css');
913
+				wp_enqueue_script('ee_error_js');
914
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
915
+			}
916
+		} else {
917
+			return '
918 918
 <script>
919 919
 /* <![CDATA[ */
920 920
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -924,223 +924,223 @@  discard block
 block discarded – undo
924 924
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
925 925
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
926 926
 ';
927
-        }
928
-        return '';
929
-    }
930
-
931
-
932
-
933
-    /**
934
-     * @return void
935
-     */
936
-    public static function enqueue_error_scripts()
937
-    {
938
-        self::_print_scripts();
939
-    }
940
-
941
-
942
-
943
-    /**
944
-     * create error code from filepath, function name,
945
-     * and line number where exception or error was thrown
946
-     *
947
-     * @param string $file
948
-     * @param string $func
949
-     * @param string $line
950
-     * @return string
951
-     */
952
-    public static function generate_error_code($file = '', $func = '', $line = '')
953
-    {
954
-        $file       = explode('.', basename($file));
955
-        $error_code = ! empty($file[0]) ? $file[0] : '';
956
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
957
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
958
-        return $error_code;
959
-    }
960
-
961
-
962
-
963
-    /**
964
-     * write exception details to log file
965
-     * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
966
-     *
967
-     * @param int   $time
968
-     * @param array $ex
969
-     * @param bool  $clear
970
-     * @return void
971
-     */
972
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
973
-    {
974
-        if (empty($ex)) {
975
-            return;
976
-        }
977
-        if (! $time) {
978
-            $time = time();
979
-        }
980
-        $exception_log = '----------------------------------------------------------------------------------------'
981
-                         . PHP_EOL;
982
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
983
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
984
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
985
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
986
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
987
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
988
-        $exception_log .= $ex['string'] . PHP_EOL;
989
-        $exception_log .= '----------------------------------------------------------------------------------------'
990
-                          . PHP_EOL;
991
-        try {
992
-            error_log($exception_log);
993
-        } catch (EE_Error $e) {
994
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
995
-                'event_espresso'), $e->getMessage()));
996
-        }
997
-    }
998
-
999
-
1000
-
1001
-    /**
1002
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1003
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1004
-     * but the code execution is done in a manner that could lead to unexpected results
1005
-     * (i.e. running to early, or too late in WP or EE loading process).
1006
-     * A good test for knowing whether to use this method is:
1007
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1008
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1009
-     * 2. If this is loaded before something else, it won't break anything,
1010
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1011
-     *
1012
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1013
-     * @param string $function      The function that was called
1014
-     * @param string $message       A message explaining what has been done incorrectly
1015
-     * @param string $version       The version of Event Espresso where the error was added
1016
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1017
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1018
-     *                              but not have any notices appear until a later version. This allows developers
1019
-     *                              extra time to update their code before notices appear.
1020
-     * @param int    $error_type
1021
-     */
1022
-    public static function doing_it_wrong(
1023
-        $function,
1024
-        $message,
1025
-        $version,
1026
-        $applies_when = '',
1027
-        $error_type = null
1028
-    ) {
1029
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1030
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1031
-        }
1032
-    }
1033
-
1034
-
1035
-
1036
-    /**
1037
-     * Like get_notices, but returns an array of all the notices of the given type.
1038
-     *
1039
-     * @return array {
1040
-     *  @type array $success   all the success messages
1041
-     *  @type array $errors    all the error messages
1042
-     *  @type array $attention all the attention messages
1043
-     * }
1044
-     */
1045
-    public static function get_raw_notices()
1046
-    {
1047
-        return self::$_espresso_notices;
1048
-    }
1049
-
1050
-
1051
-
1052
-    /**
1053
-     * @deprecated 4.9.27
1054
-     * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1055
-     * @param string $pan_message  the message to be stored persistently until dismissed
1056
-     * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1057
-     * @return void
1058
-     * @throws InvalidDataTypeException
1059
-     */
1060
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1061
-    {
1062
-        new PersistentAdminNotice(
1063
-            $pan_name,
1064
-            $pan_message,
1065
-            $force_update
1066
-        );
1067
-        EE_Error::doing_it_wrong(
1068
-            __METHOD__,
1069
-            sprintf(
1070
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1071
-                '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1072
-            ),
1073
-            '4.9.27'
1074
-        );
1075
-    }
1076
-
1077
-
1078
-
1079
-    /**
1080
-     * @deprecated 4.9.27
1081
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1082
-     * @param bool   $purge
1083
-     * @param bool   $return
1084
-     * @throws DomainException
1085
-     * @throws InvalidInterfaceException
1086
-     * @throws InvalidDataTypeException
1087
-     * @throws ServiceNotFoundException
1088
-     * @throws InvalidArgumentException
1089
-     */
1090
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1091
-    {
1092
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1093
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1094
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1095
-        );
1096
-        $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1097
-        EE_Error::doing_it_wrong(
1098
-            __METHOD__,
1099
-            sprintf(
1100
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1101
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1102
-            ),
1103
-            '4.9.27'
1104
-        );
1105
-    }
1106
-
1107
-
1108
-
1109
-    /**
1110
-     * @deprecated 4.9.27
1111
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1112
-     * @param  string $pan_message the message to be stored persistently until dismissed
1113
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
1114
-     */
1115
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1116
-    {
1117
-        EE_Error::doing_it_wrong(
1118
-            __METHOD__,
1119
-            sprintf(
1120
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1121
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1122
-            ),
1123
-            '4.9.27'
1124
-        );
1125
-    }
1126
-
1127
-
1128
-
1129
-    /**
1130
-     * @deprecated 4.9.27
1131
-     * @param string $return_url
1132
-     */
1133
-    public static function get_persistent_admin_notices($return_url = '')
1134
-    {
1135
-        EE_Error::doing_it_wrong(
1136
-            __METHOD__,
1137
-            sprintf(
1138
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1139
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1140
-            ),
1141
-            '4.9.27'
1142
-        );
1143
-    }
927
+		}
928
+		return '';
929
+	}
930
+
931
+
932
+
933
+	/**
934
+	 * @return void
935
+	 */
936
+	public static function enqueue_error_scripts()
937
+	{
938
+		self::_print_scripts();
939
+	}
940
+
941
+
942
+
943
+	/**
944
+	 * create error code from filepath, function name,
945
+	 * and line number where exception or error was thrown
946
+	 *
947
+	 * @param string $file
948
+	 * @param string $func
949
+	 * @param string $line
950
+	 * @return string
951
+	 */
952
+	public static function generate_error_code($file = '', $func = '', $line = '')
953
+	{
954
+		$file       = explode('.', basename($file));
955
+		$error_code = ! empty($file[0]) ? $file[0] : '';
956
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
957
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
958
+		return $error_code;
959
+	}
960
+
961
+
962
+
963
+	/**
964
+	 * write exception details to log file
965
+	 * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
966
+	 *
967
+	 * @param int   $time
968
+	 * @param array $ex
969
+	 * @param bool  $clear
970
+	 * @return void
971
+	 */
972
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
973
+	{
974
+		if (empty($ex)) {
975
+			return;
976
+		}
977
+		if (! $time) {
978
+			$time = time();
979
+		}
980
+		$exception_log = '----------------------------------------------------------------------------------------'
981
+						 . PHP_EOL;
982
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
983
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
984
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
985
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
986
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
987
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
988
+		$exception_log .= $ex['string'] . PHP_EOL;
989
+		$exception_log .= '----------------------------------------------------------------------------------------'
990
+						  . PHP_EOL;
991
+		try {
992
+			error_log($exception_log);
993
+		} catch (EE_Error $e) {
994
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
995
+				'event_espresso'), $e->getMessage()));
996
+		}
997
+	}
998
+
999
+
1000
+
1001
+	/**
1002
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1003
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1004
+	 * but the code execution is done in a manner that could lead to unexpected results
1005
+	 * (i.e. running to early, or too late in WP or EE loading process).
1006
+	 * A good test for knowing whether to use this method is:
1007
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1008
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1009
+	 * 2. If this is loaded before something else, it won't break anything,
1010
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1011
+	 *
1012
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1013
+	 * @param string $function      The function that was called
1014
+	 * @param string $message       A message explaining what has been done incorrectly
1015
+	 * @param string $version       The version of Event Espresso where the error was added
1016
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1017
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1018
+	 *                              but not have any notices appear until a later version. This allows developers
1019
+	 *                              extra time to update their code before notices appear.
1020
+	 * @param int    $error_type
1021
+	 */
1022
+	public static function doing_it_wrong(
1023
+		$function,
1024
+		$message,
1025
+		$version,
1026
+		$applies_when = '',
1027
+		$error_type = null
1028
+	) {
1029
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1030
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1031
+		}
1032
+	}
1033
+
1034
+
1035
+
1036
+	/**
1037
+	 * Like get_notices, but returns an array of all the notices of the given type.
1038
+	 *
1039
+	 * @return array {
1040
+	 *  @type array $success   all the success messages
1041
+	 *  @type array $errors    all the error messages
1042
+	 *  @type array $attention all the attention messages
1043
+	 * }
1044
+	 */
1045
+	public static function get_raw_notices()
1046
+	{
1047
+		return self::$_espresso_notices;
1048
+	}
1049
+
1050
+
1051
+
1052
+	/**
1053
+	 * @deprecated 4.9.27
1054
+	 * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1055
+	 * @param string $pan_message  the message to be stored persistently until dismissed
1056
+	 * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1057
+	 * @return void
1058
+	 * @throws InvalidDataTypeException
1059
+	 */
1060
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1061
+	{
1062
+		new PersistentAdminNotice(
1063
+			$pan_name,
1064
+			$pan_message,
1065
+			$force_update
1066
+		);
1067
+		EE_Error::doing_it_wrong(
1068
+			__METHOD__,
1069
+			sprintf(
1070
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1071
+				'\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1072
+			),
1073
+			'4.9.27'
1074
+		);
1075
+	}
1076
+
1077
+
1078
+
1079
+	/**
1080
+	 * @deprecated 4.9.27
1081
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1082
+	 * @param bool   $purge
1083
+	 * @param bool   $return
1084
+	 * @throws DomainException
1085
+	 * @throws InvalidInterfaceException
1086
+	 * @throws InvalidDataTypeException
1087
+	 * @throws ServiceNotFoundException
1088
+	 * @throws InvalidArgumentException
1089
+	 */
1090
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1091
+	{
1092
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1093
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1094
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1095
+		);
1096
+		$persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1097
+		EE_Error::doing_it_wrong(
1098
+			__METHOD__,
1099
+			sprintf(
1100
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1101
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1102
+			),
1103
+			'4.9.27'
1104
+		);
1105
+	}
1106
+
1107
+
1108
+
1109
+	/**
1110
+	 * @deprecated 4.9.27
1111
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1112
+	 * @param  string $pan_message the message to be stored persistently until dismissed
1113
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
1114
+	 */
1115
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1116
+	{
1117
+		EE_Error::doing_it_wrong(
1118
+			__METHOD__,
1119
+			sprintf(
1120
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1121
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1122
+			),
1123
+			'4.9.27'
1124
+		);
1125
+	}
1126
+
1127
+
1128
+
1129
+	/**
1130
+	 * @deprecated 4.9.27
1131
+	 * @param string $return_url
1132
+	 */
1133
+	public static function get_persistent_admin_notices($return_url = '')
1134
+	{
1135
+		EE_Error::doing_it_wrong(
1136
+			__METHOD__,
1137
+			sprintf(
1138
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1139
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1140
+			),
1141
+			'4.9.27'
1142
+		);
1143
+	}
1144 1144
 
1145 1145
 
1146 1146
 
@@ -1155,27 +1155,27 @@  discard block
 block discarded – undo
1155 1155
  */
1156 1156
 function espresso_error_enqueue_scripts()
1157 1157
 {
1158
-    // js for error handling
1159
-    wp_register_script(
1160
-        'espresso_core',
1161
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1162
-        array('jquery'),
1163
-        EVENT_ESPRESSO_VERSION,
1164
-        false
1165
-    );
1166
-    wp_register_script(
1167
-        'ee_error_js',
1168
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1169
-        array('espresso_core'),
1170
-        EVENT_ESPRESSO_VERSION,
1171
-        false
1172
-    );
1158
+	// js for error handling
1159
+	wp_register_script(
1160
+		'espresso_core',
1161
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1162
+		array('jquery'),
1163
+		EVENT_ESPRESSO_VERSION,
1164
+		false
1165
+	);
1166
+	wp_register_script(
1167
+		'ee_error_js',
1168
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1169
+		array('espresso_core'),
1170
+		EVENT_ESPRESSO_VERSION,
1171
+		false
1172
+	);
1173 1173
 }
1174 1174
 
1175 1175
 if (is_admin()) {
1176
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1176
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1177 1177
 } else {
1178
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1178
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1179 1179
 }
1180 1180
 
1181 1181
 
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Indentation   +1236 added lines, -1236 removed lines patch added patch discarded remove patch
@@ -21,1242 +21,1242 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
26
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
27
-     */
28
-    const req_type_normal = 0;
29
-
30
-    /**
31
-     * Indicates this is a brand new installation of EE so we should install
32
-     * tables and default data etc
33
-     */
34
-    const req_type_new_activation = 1;
35
-
36
-    /**
37
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
38
-     * and we just exited maintenance mode). We MUST check the database is setup properly
39
-     * and that default data is setup too
40
-     */
41
-    const req_type_reactivation = 2;
42
-
43
-    /**
44
-     * indicates that EE has been upgraded since its previous request.
45
-     * We may have data migration scripts to call and will want to trigger maintenance mode
46
-     */
47
-    const req_type_upgrade = 3;
48
-
49
-    /**
50
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
51
-     */
52
-    const req_type_downgrade = 4;
53
-
54
-    /**
55
-     * @deprecated since version 4.6.0.dev.006
56
-     * Now whenever a new_activation is detected the request type is still just
57
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
58
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
59
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
60
-     * (Specifically, when the migration manager indicates migrations are finished
61
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
62
-     */
63
-    const req_type_activation_but_not_installed = 5;
64
-
65
-    /**
66
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
67
-     */
68
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
69
-
70
-
71
-    /**
72
-     * @var EE_System $_instance
73
-     */
74
-    private static $_instance;
75
-
76
-    /**
77
-     * @var EE_Registry $registry
78
-     */
79
-    private $registry;
80
-
81
-    /**
82
-     * @var LoaderInterface $loader
83
-     */
84
-    private $loader;
85
-
86
-    /**
87
-     * @var EE_Capabilities $capabilities
88
-     */
89
-    private $capabilities;
90
-
91
-    /**
92
-     * @var EE_Request $request
93
-     */
94
-    private $request;
95
-
96
-    /**
97
-     * @var EE_Maintenance_Mode $maintenance_mode
98
-     */
99
-    private $maintenance_mode;
100
-
101
-    /**
102
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
103
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
104
-     *
105
-     * @var int $_req_type
106
-     */
107
-    private $_req_type;
108
-
109
-    /**
110
-     * Whether or not there was a non-micro version change in EE core version during this request
111
-     *
112
-     * @var boolean $_major_version_change
113
-     */
114
-    private $_major_version_change = false;
115
-
116
-
117
-
118
-    /**
119
-     * @singleton method used to instantiate class object
120
-     * @param EE_Registry|null         $registry
121
-     * @param LoaderInterface|null     $loader
122
-     * @param EE_Capabilities|null     $capabilities
123
-     * @param EE_Request|null          $request
124
-     * @param EE_Maintenance_Mode|null $maintenance_mode
125
-     * @return EE_System
126
-     */
127
-    public static function instance(
128
-        EE_Registry $registry = null,
129
-        LoaderInterface $loader = null,
130
-        EE_Capabilities $capabilities = null,
131
-        EE_Request $request = null,
132
-        EE_Maintenance_Mode $maintenance_mode = null
133
-    ) {
134
-        // check if class object is instantiated
135
-        if (! self::$_instance instanceof EE_System) {
136
-            self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
137
-        }
138
-        return self::$_instance;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * resets the instance and returns it
145
-     *
146
-     * @return EE_System
147
-     */
148
-    public static function reset()
149
-    {
150
-        self::$_instance->_req_type = null;
151
-        //make sure none of the old hooks are left hanging around
152
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
153
-        //we need to reset the migration manager in order for it to detect DMSs properly
154
-        EE_Data_Migration_Manager::reset();
155
-        self::instance()->detect_activations_or_upgrades();
156
-        self::instance()->perform_activations_upgrades_and_migrations();
157
-        return self::instance();
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * sets hooks for running rest of system
164
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
165
-     * starting EE Addons from any other point may lead to problems
166
-     *
167
-     * @param EE_Registry         $registry
168
-     * @param LoaderInterface     $loader
169
-     * @param EE_Capabilities     $capabilities
170
-     * @param EE_Request          $request
171
-     * @param EE_Maintenance_Mode $maintenance_mode
172
-     */
173
-    private function __construct(
174
-        EE_Registry $registry,
175
-        LoaderInterface $loader,
176
-        EE_Capabilities $capabilities,
177
-        EE_Request $request,
178
-        EE_Maintenance_Mode $maintenance_mode
179
-    ) {
180
-        $this->registry = $registry;
181
-        $this->loader = $loader;
182
-        $this->capabilities = $capabilities;
183
-        $this->request = $request;
184
-        $this->maintenance_mode = $maintenance_mode;
185
-        do_action('AHEE__EE_System__construct__begin', $this);
186
-        add_action(
187
-            'AHEE__EE_Bootstrap__load_espresso_addons',
188
-            array($this, 'loadCapabilities'),
189
-            5
190
-        );
191
-        add_action(
192
-            'AHEE__EE_Bootstrap__load_espresso_addons',
193
-            array($this, 'loadCommandBus'),
194
-            7
195
-        );
196
-        add_action(
197
-            'AHEE__EE_Bootstrap__load_espresso_addons',
198
-            array($this, 'loadPluginApi'),
199
-            9
200
-        );
201
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
202
-        add_action(
203
-            'AHEE__EE_Bootstrap__load_espresso_addons',
204
-            array($this, 'load_espresso_addons')
205
-        );
206
-        // when an ee addon is activated, we want to call the core hook(s) again
207
-        // because the newly-activated addon didn't get a chance to run at all
208
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
209
-        // detect whether install or upgrade
210
-        add_action(
211
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
212
-            array($this, 'detect_activations_or_upgrades'),
213
-            3
214
-        );
215
-        // load EE_Config, EE_Textdomain, etc
216
-        add_action(
217
-            'AHEE__EE_Bootstrap__load_core_configuration',
218
-            array($this, 'load_core_configuration'),
219
-            5
220
-        );
221
-        // load EE_Config, EE_Textdomain, etc
222
-        add_action(
223
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
224
-            array($this, 'register_shortcodes_modules_and_widgets'),
225
-            7
226
-        );
227
-        // you wanna get going? I wanna get going... let's get going!
228
-        add_action(
229
-            'AHEE__EE_Bootstrap__brew_espresso',
230
-            array($this, 'brew_espresso'),
231
-            9
232
-        );
233
-        //other housekeeping
234
-        //exclude EE critical pages from wp_list_pages
235
-        add_filter(
236
-            'wp_list_pages_excludes',
237
-            array($this, 'remove_pages_from_wp_list_pages'),
238
-            10
239
-        );
240
-        // ALL EE Addons should use the following hook point to attach their initial setup too
241
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
242
-        do_action('AHEE__EE_System__construct__complete', $this);
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * load and setup EE_Capabilities
249
-     *
250
-     * @return void
251
-     * @throws EE_Error
252
-     */
253
-    public function loadCapabilities()
254
-    {
255
-        $this->loader->getShared('EE_Capabilities');
256
-        add_action(
257
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
258
-            function() {
259
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
260
-            }
261
-        );
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     * create and cache the CommandBus, and also add middleware
268
-     * The CapChecker middleware requires the use of EE_Capabilities
269
-     * which is why we need to load the CommandBus after Caps are set up
270
-     *
271
-     * @return void
272
-     * @throws EE_Error
273
-     */
274
-    public function loadCommandBus()
275
-    {
276
-        $this->loader->getShared(
277
-            'CommandBusInterface',
278
-            array(
279
-                null,
280
-                apply_filters(
281
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
282
-                    array(
283
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
284
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
285
-                    )
286
-                ),
287
-            )
288
-        );
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * @return void
295
-     * @throws EE_Error
296
-     */
297
-    public function loadPluginApi()
298
-    {
299
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
300
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
301
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
302
-    }
303
-
304
-
305
-    /**
306
-     * @param string $addon_name
307
-     * @param string $version_constant
308
-     * @param string $min_version_required
309
-     * @param string $load_callback
310
-     * @param string $plugin_file_constant
311
-     * @return void
312
-     */
313
-    private function deactivateIncompatibleAddon(
314
-        $addon_name,
315
-        $version_constant,
316
-        $min_version_required,
317
-        $load_callback,
318
-        $plugin_file_constant
319
-    ) {
320
-        if (! defined($version_constant)) {
321
-            return;
322
-        }
323
-        $addon_version = constant($version_constant);
324
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
325
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
326
-            if (! function_exists('deactivate_plugins')) {
327
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
328
-            }
329
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
330
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
331
-            EE_Error::add_error(
332
-                sprintf(
333
-                    esc_html__(
334
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
335
-                        'event_espresso'
336
-                    ),
337
-                    $addon_name,
338
-                    $min_version_required
339
-                ),
340
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
341
-            );
342
-            EE_Error::get_notices(false, true);
343
-        }
344
-    }
345
-
346
-
347
-    /**
348
-     * load_espresso_addons
349
-     * allow addons to load first so that they can set hooks for running DMS's, etc
350
-     * this is hooked into both:
351
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
352
-     *        which runs during the WP 'plugins_loaded' action at priority 5
353
-     *    and the WP 'activate_plugin' hook point
354
-     *
355
-     * @access public
356
-     * @return void
357
-     */
358
-    public function load_espresso_addons()
359
-    {
360
-        $this->deactivateIncompatibleAddon(
361
-            'Wait Lists',
362
-            'EE_WAIT_LISTS_VERSION',
363
-            '1.0.0.rc.074',
364
-            'load_espresso_wait_lists',
365
-            'EE_WAIT_LISTS_PLUGIN_FILE'
366
-        );
367
-        $this->deactivateIncompatibleAddon(
368
-            'Automated Upcoming Event Notifications',
369
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
370
-            '1.0.0.rc.091',
371
-            'load_espresso_automated_upcoming_event_notification',
372
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
373
-        );
374
-        do_action('AHEE__EE_System__load_espresso_addons');
375
-        //if the WP API basic auth plugin isn't already loaded, load it now.
376
-        //We want it for mobile apps. Just include the entire plugin
377
-        //also, don't load the basic auth when a plugin is getting activated, because
378
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
379
-        //and causes a fatal error
380
-        if (
381
-            ! (
382
-                isset($_GET['activate'])
383
-                && $_GET['activate'] === 'true'
384
-            )
385
-            && ! function_exists('json_basic_auth_handler')
386
-            && ! function_exists('json_basic_auth_error')
387
-            && ! (
388
-                isset($_GET['action'])
389
-                && in_array($_GET['action'], array('activate', 'activate-selected'), true)
390
-            )
391
-        ) {
392
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
393
-        }
394
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
395
-    }
396
-
397
-
398
-
399
-    /**
400
-     * detect_activations_or_upgrades
401
-     * Checks for activation or upgrade of core first;
402
-     * then also checks if any registered addons have been activated or upgraded
403
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
404
-     * which runs during the WP 'plugins_loaded' action at priority 3
405
-     *
406
-     * @access public
407
-     * @return void
408
-     */
409
-    public function detect_activations_or_upgrades()
410
-    {
411
-        //first off: let's make sure to handle core
412
-        $this->detect_if_activation_or_upgrade();
413
-        foreach ($this->registry->addons as $addon) {
414
-            if ($addon instanceof EE_Addon) {
415
-                //detect teh request type for that addon
416
-                $addon->detect_activation_or_upgrade();
417
-            }
418
-        }
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     * detect_if_activation_or_upgrade
425
-     * Takes care of detecting whether this is a brand new install or code upgrade,
426
-     * and either setting up the DB or setting up maintenance mode etc.
427
-     *
428
-     * @access public
429
-     * @return void
430
-     */
431
-    public function detect_if_activation_or_upgrade()
432
-    {
433
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
434
-        // check if db has been updated, or if its a brand-new installation
435
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
436
-        $request_type = $this->detect_req_type($espresso_db_update);
437
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
438
-        switch ($request_type) {
439
-            case EE_System::req_type_new_activation:
440
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
441
-                $this->_handle_core_version_change($espresso_db_update);
442
-                break;
443
-            case EE_System::req_type_reactivation:
444
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
445
-                $this->_handle_core_version_change($espresso_db_update);
446
-                break;
447
-            case EE_System::req_type_upgrade:
448
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
449
-                //migrations may be required now that we've upgraded
450
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
451
-                $this->_handle_core_version_change($espresso_db_update);
452
-                //				echo "done upgrade";die;
453
-                break;
454
-            case EE_System::req_type_downgrade:
455
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
456
-                //its possible migrations are no longer required
457
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
458
-                $this->_handle_core_version_change($espresso_db_update);
459
-                break;
460
-            case EE_System::req_type_normal:
461
-            default:
462
-                //				$this->_maybe_redirect_to_ee_about();
463
-                break;
464
-        }
465
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
466
-    }
467
-
468
-
469
-
470
-    /**
471
-     * Updates the list of installed versions and sets hooks for
472
-     * initializing the database later during the request
473
-     *
474
-     * @param array $espresso_db_update
475
-     */
476
-    private function _handle_core_version_change($espresso_db_update)
477
-    {
478
-        $this->update_list_of_installed_versions($espresso_db_update);
479
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
480
-        add_action(
481
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
482
-            array($this, 'initialize_db_if_no_migrations_required')
483
-        );
484
-    }
485
-
486
-
487
-
488
-    /**
489
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
490
-     * information about what versions of EE have been installed and activated,
491
-     * NOT necessarily the state of the database
492
-     *
493
-     * @param mixed $espresso_db_update the value of the WordPress option.
494
-     *                                            If not supplied, fetches it from the options table
495
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
496
-     */
497
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
498
-    {
499
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
500
-        if (! $espresso_db_update) {
501
-            $espresso_db_update = get_option('espresso_db_update');
502
-        }
503
-        // check that option is an array
504
-        if (! is_array($espresso_db_update)) {
505
-            // if option is FALSE, then it never existed
506
-            if ($espresso_db_update === false) {
507
-                // make $espresso_db_update an array and save option with autoload OFF
508
-                $espresso_db_update = array();
509
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
510
-            } else {
511
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
512
-                $espresso_db_update = array($espresso_db_update => array());
513
-                update_option('espresso_db_update', $espresso_db_update);
514
-            }
515
-        } else {
516
-            $corrected_db_update = array();
517
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
518
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
519
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
520
-                    //the key is an int, and the value IS NOT an array
521
-                    //so it must be numerically-indexed, where values are versions installed...
522
-                    //fix it!
523
-                    $version_string = $should_be_array;
524
-                    $corrected_db_update[$version_string] = array('unknown-date');
525
-                } else {
526
-                    //ok it checks out
527
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
528
-                }
529
-            }
530
-            $espresso_db_update = $corrected_db_update;
531
-            update_option('espresso_db_update', $espresso_db_update);
532
-        }
533
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
534
-        return $espresso_db_update;
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * Does the traditional work of setting up the plugin's database and adding default data.
541
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
542
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
543
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
544
-     * so that it will be done when migrations are finished
545
-     *
546
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
547
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
548
-     *                                       This is a resource-intensive job
549
-     *                                       so we prefer to only do it when necessary
550
-     * @return void
551
-     * @throws EE_Error
552
-     */
553
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
554
-    {
555
-        $request_type = $this->detect_req_type();
556
-        //only initialize system if we're not in maintenance mode.
557
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
558
-            update_option('ee_flush_rewrite_rules', true);
559
-            if ($verify_schema) {
560
-                EEH_Activation::initialize_db_and_folders();
561
-            }
562
-            EEH_Activation::initialize_db_content();
563
-            EEH_Activation::system_initialization();
564
-            if ($initialize_addons_too) {
565
-                $this->initialize_addons();
566
-            }
567
-        } else {
568
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
569
-        }
570
-        if ($request_type === EE_System::req_type_new_activation
571
-            || $request_type === EE_System::req_type_reactivation
572
-            || (
573
-                $request_type === EE_System::req_type_upgrade
574
-                && $this->is_major_version_change()
575
-            )
576
-        ) {
577
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
578
-        }
579
-    }
580
-
581
-
582
-
583
-    /**
584
-     * Initializes the db for all registered addons
585
-     *
586
-     * @throws EE_Error
587
-     */
588
-    public function initialize_addons()
589
-    {
590
-        //foreach registered addon, make sure its db is up-to-date too
591
-        foreach ($this->registry->addons as $addon) {
592
-            if ($addon instanceof EE_Addon) {
593
-                $addon->initialize_db_if_no_migrations_required();
594
-            }
595
-        }
596
-    }
597
-
598
-
599
-
600
-    /**
601
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
602
-     *
603
-     * @param    array  $version_history
604
-     * @param    string $current_version_to_add version to be added to the version history
605
-     * @return    boolean success as to whether or not this option was changed
606
-     */
607
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
608
-    {
609
-        if (! $version_history) {
610
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
611
-        }
612
-        if ($current_version_to_add === null) {
613
-            $current_version_to_add = espresso_version();
614
-        }
615
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
616
-        // re-save
617
-        return update_option('espresso_db_update', $version_history);
618
-    }
619
-
620
-
621
-
622
-    /**
623
-     * Detects if the current version indicated in the has existed in the list of
624
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
625
-     *
626
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
627
-     *                                  If not supplied, fetches it from the options table.
628
-     *                                  Also, caches its result so later parts of the code can also know whether
629
-     *                                  there's been an update or not. This way we can add the current version to
630
-     *                                  espresso_db_update, but still know if this is a new install or not
631
-     * @return int one of the constants on EE_System::req_type_
632
-     */
633
-    public function detect_req_type($espresso_db_update = null)
634
-    {
635
-        if ($this->_req_type === null) {
636
-            $espresso_db_update = ! empty($espresso_db_update)
637
-                ? $espresso_db_update
638
-                : $this->fix_espresso_db_upgrade_option();
639
-            $this->_req_type = EE_System::detect_req_type_given_activation_history(
640
-                $espresso_db_update,
641
-                'ee_espresso_activation', espresso_version()
642
-            );
643
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
644
-        }
645
-        return $this->_req_type;
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * Returns whether or not there was a non-micro version change (ie, change in either
652
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
653
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
654
-     *
655
-     * @param $activation_history
656
-     * @return bool
657
-     */
658
-    private function _detect_major_version_change($activation_history)
659
-    {
660
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
661
-        $previous_version_parts = explode('.', $previous_version);
662
-        $current_version_parts = explode('.', espresso_version());
663
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
664
-               && ($previous_version_parts[0] !== $current_version_parts[0]
665
-                   || $previous_version_parts[1] !== $current_version_parts[1]
666
-               );
667
-    }
668
-
669
-
670
-
671
-    /**
672
-     * Returns true if either the major or minor version of EE changed during this request.
673
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
674
-     *
675
-     * @return bool
676
-     */
677
-    public function is_major_version_change()
678
-    {
679
-        return $this->_major_version_change;
680
-    }
681
-
682
-
683
-
684
-    /**
685
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
686
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
687
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
688
-     * just activated to (for core that will always be espresso_version())
689
-     *
690
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
691
-     *                                                 ee plugin. for core that's 'espresso_db_update'
692
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
693
-     *                                                 indicate that this plugin was just activated
694
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
695
-     *                                                 espresso_version())
696
-     * @return int one of the constants on EE_System::req_type_*
697
-     */
698
-    public static function detect_req_type_given_activation_history(
699
-        $activation_history_for_addon,
700
-        $activation_indicator_option_name,
701
-        $version_to_upgrade_to
702
-    ) {
703
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
704
-        if ($activation_history_for_addon) {
705
-            //it exists, so this isn't a completely new install
706
-            //check if this version already in that list of previously installed versions
707
-            if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
708
-                //it a version we haven't seen before
709
-                if ($version_is_higher === 1) {
710
-                    $req_type = EE_System::req_type_upgrade;
711
-                } else {
712
-                    $req_type = EE_System::req_type_downgrade;
713
-                }
714
-                delete_option($activation_indicator_option_name);
715
-            } else {
716
-                // its not an update. maybe a reactivation?
717
-                if (get_option($activation_indicator_option_name, false)) {
718
-                    if ($version_is_higher === -1) {
719
-                        $req_type = EE_System::req_type_downgrade;
720
-                    } else if ($version_is_higher === 0) {
721
-                        //we've seen this version before, but it's an activation. must be a reactivation
722
-                        $req_type = EE_System::req_type_reactivation;
723
-                    } else {//$version_is_higher === 1
724
-                        $req_type = EE_System::req_type_upgrade;
725
-                    }
726
-                    delete_option($activation_indicator_option_name);
727
-                } else {
728
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
729
-                    if ($version_is_higher === -1) {
730
-                        $req_type = EE_System::req_type_downgrade;
731
-                    } else if ($version_is_higher === 0) {
732
-                        //we've seen this version before and it's not an activation. its normal request
733
-                        $req_type = EE_System::req_type_normal;
734
-                    } else {//$version_is_higher === 1
735
-                        $req_type = EE_System::req_type_upgrade;
736
-                    }
737
-                }
738
-            }
739
-        } else {
740
-            //brand new install
741
-            $req_type = EE_System::req_type_new_activation;
742
-            delete_option($activation_indicator_option_name);
743
-        }
744
-        return $req_type;
745
-    }
746
-
747
-
748
-
749
-    /**
750
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
751
-     * the $activation_history_for_addon
752
-     *
753
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
754
-     *                                             sometimes containing 'unknown-date'
755
-     * @param string $version_to_upgrade_to        (current version)
756
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
757
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
758
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
759
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
760
-     */
761
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
762
-    {
763
-        //find the most recently-activated version
764
-        $most_recently_active_version =
765
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
766
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
767
-    }
768
-
769
-
770
-
771
-    /**
772
-     * Gets the most recently active version listed in the activation history,
773
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
774
-     *
775
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
776
-     *                                   sometimes containing 'unknown-date'
777
-     * @return string
778
-     */
779
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
780
-    {
781
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
782
-        $most_recently_active_version = '0.0.0.dev.000';
783
-        if (is_array($activation_history)) {
784
-            foreach ($activation_history as $version => $times_activated) {
785
-                //check there is a record of when this version was activated. Otherwise,
786
-                //mark it as unknown
787
-                if (! $times_activated) {
788
-                    $times_activated = array('unknown-date');
789
-                }
790
-                if (is_string($times_activated)) {
791
-                    $times_activated = array($times_activated);
792
-                }
793
-                foreach ($times_activated as $an_activation) {
794
-                    if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
795
-                        $most_recently_active_version = $version;
796
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
797
-                            ? '1970-01-01 00:00:00'
798
-                            : $an_activation;
799
-                    }
800
-                }
801
-            }
802
-        }
803
-        return $most_recently_active_version;
804
-    }
805
-
806
-
807
-
808
-    /**
809
-     * This redirects to the about EE page after activation
810
-     *
811
-     * @return void
812
-     */
813
-    public function redirect_to_about_ee()
814
-    {
815
-        $notices = EE_Error::get_notices(false);
816
-        //if current user is an admin and it's not an ajax or rest request
817
-        if (
818
-            ! (defined('DOING_AJAX') && DOING_AJAX)
819
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
820
-            && ! isset($notices['errors'])
821
-            && apply_filters(
822
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
823
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
824
-            )
825
-        ) {
826
-            $query_params = array('page' => 'espresso_about');
827
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
828
-                $query_params['new_activation'] = true;
829
-            }
830
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
831
-                $query_params['reactivation'] = true;
832
-            }
833
-            $url = add_query_arg($query_params, admin_url('admin.php'));
834
-            wp_safe_redirect($url);
835
-            exit();
836
-        }
837
-    }
838
-
839
-
840
-
841
-    /**
842
-     * load_core_configuration
843
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
844
-     * which runs during the WP 'plugins_loaded' action at priority 5
845
-     *
846
-     * @return void
847
-     * @throws ReflectionException
848
-     */
849
-    public function load_core_configuration()
850
-    {
851
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
852
-        $this->loader->getShared('EE_Load_Textdomain');
853
-        //load textdomain
854
-        EE_Load_Textdomain::load_textdomain();
855
-        // load and setup EE_Config and EE_Network_Config
856
-        $config = $this->loader->getShared('EE_Config');
857
-        $this->loader->getShared('EE_Network_Config');
858
-        // setup autoloaders
859
-        // enable logging?
860
-        if ($config->admin->use_full_logging) {
861
-            $this->loader->getShared('EE_Log');
862
-        }
863
-        // check for activation errors
864
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
865
-        if ($activation_errors) {
866
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
867
-            update_option('ee_plugin_activation_errors', false);
868
-        }
869
-        // get model names
870
-        $this->_parse_model_names();
871
-        //load caf stuff a chance to play during the activation process too.
872
-        $this->_maybe_brew_regular();
873
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
874
-    }
875
-
876
-
877
-
878
-    /**
879
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
880
-     *
881
-     * @return void
882
-     * @throws ReflectionException
883
-     */
884
-    private function _parse_model_names()
885
-    {
886
-        //get all the files in the EE_MODELS folder that end in .model.php
887
-        $models = glob(EE_MODELS . '*.model.php');
888
-        $model_names = array();
889
-        $non_abstract_db_models = array();
890
-        foreach ($models as $model) {
891
-            // get model classname
892
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
893
-            $short_name = str_replace('EEM_', '', $classname);
894
-            $reflectionClass = new ReflectionClass($classname);
895
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
896
-                $non_abstract_db_models[$short_name] = $classname;
897
-            }
898
-            $model_names[$short_name] = $classname;
899
-        }
900
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
901
-        $this->registry->non_abstract_db_models = apply_filters(
902
-            'FHEE__EE_System__parse_implemented_model_names',
903
-            $non_abstract_db_models
904
-        );
905
-    }
906
-
907
-
908
-
909
-    /**
910
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
911
-     * that need to be setup before our EE_System launches.
912
-     *
913
-     * @return void
914
-     */
915
-    private function _maybe_brew_regular()
916
-    {
917
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
918
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
919
-        }
920
-    }
921
-
922
-
923
-
924
-    /**
925
-     * register_shortcodes_modules_and_widgets
926
-     * generate lists of shortcodes and modules, then verify paths and classes
927
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
928
-     * which runs during the WP 'plugins_loaded' action at priority 7
929
-     *
930
-     * @access public
931
-     * @return void
932
-     * @throws Exception
933
-     */
934
-    public function register_shortcodes_modules_and_widgets()
935
-    {
936
-        try {
937
-            // load, register, and add shortcodes the new way
938
-            $this->loader->getShared(
939
-                'EventEspresso\core\services\shortcodes\ShortcodesManager',
940
-                array(
941
-                    // and the old way, but we'll put it under control of the new system
942
-                    EE_Config::getLegacyShortcodesManager()
943
-                )
944
-            );
945
-        } catch (Exception $exception) {
946
-            new ExceptionStackTraceDisplay($exception);
947
-        }
948
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
949
-        // check for addons using old hook point
950
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
951
-            $this->_incompatible_addon_error();
952
-        }
953
-    }
954
-
955
-
956
-
957
-    /**
958
-     * _incompatible_addon_error
959
-     *
960
-     * @access public
961
-     * @return void
962
-     */
963
-    private function _incompatible_addon_error()
964
-    {
965
-        // get array of classes hooking into here
966
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
967
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
968
-        );
969
-        if (! empty($class_names)) {
970
-            $msg = __(
971
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
972
-                'event_espresso'
973
-            );
974
-            $msg .= '<ul>';
975
-            foreach ($class_names as $class_name) {
976
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
977
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
978
-                        $class_name
979
-                    ) . '</b></li>';
980
-            }
981
-            $msg .= '</ul>';
982
-            $msg .= __(
983
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
984
-                'event_espresso'
985
-            );
986
-            // save list of incompatible addons to wp-options for later use
987
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
988
-            if (is_admin()) {
989
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
990
-            }
991
-        }
992
-    }
993
-
994
-
995
-
996
-    /**
997
-     * brew_espresso
998
-     * begins the process of setting hooks for initializing EE in the correct order
999
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1000
-     * which runs during the WP 'plugins_loaded' action at priority 9
1001
-     *
1002
-     * @return void
1003
-     */
1004
-    public function brew_espresso()
1005
-    {
1006
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1007
-        // load some final core systems
1008
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1009
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1010
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1011
-        add_action('init', array($this, 'load_controllers'), 7);
1012
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1013
-        add_action('init', array($this, 'initialize'), 10);
1014
-        add_action('init', array($this, 'initialize_last'), 100);
1015
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1016
-            // pew pew pew
1017
-            $this->loader->getShared('EE_PUE');
1018
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1019
-        }
1020
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1021
-    }
1022
-
1023
-
1024
-
1025
-    /**
1026
-     *    set_hooks_for_core
1027
-     *
1028
-     * @access public
1029
-     * @return    void
1030
-     * @throws EE_Error
1031
-     */
1032
-    public function set_hooks_for_core()
1033
-    {
1034
-        $this->_deactivate_incompatible_addons();
1035
-        do_action('AHEE__EE_System__set_hooks_for_core');
1036
-        //caps need to be initialized on every request so that capability maps are set.
1037
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1038
-        $this->registry->CAP->init_caps();
1039
-    }
1040
-
1041
-
1042
-
1043
-    /**
1044
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1045
-     * deactivates any addons considered incompatible with the current version of EE
1046
-     */
1047
-    private function _deactivate_incompatible_addons()
1048
-    {
1049
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1050
-        if (! empty($incompatible_addons)) {
1051
-            $active_plugins = get_option('active_plugins', array());
1052
-            foreach ($active_plugins as $active_plugin) {
1053
-                foreach ($incompatible_addons as $incompatible_addon) {
1054
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1055
-                        unset($_GET['activate']);
1056
-                        espresso_deactivate_plugin($active_plugin);
1057
-                    }
1058
-                }
1059
-            }
1060
-        }
1061
-    }
1062
-
1063
-
1064
-
1065
-    /**
1066
-     *    perform_activations_upgrades_and_migrations
1067
-     *
1068
-     * @access public
1069
-     * @return    void
1070
-     */
1071
-    public function perform_activations_upgrades_and_migrations()
1072
-    {
1073
-        //first check if we had previously attempted to setup EE's directories but failed
1074
-        if (EEH_Activation::upload_directories_incomplete()) {
1075
-            EEH_Activation::create_upload_directories();
1076
-        }
1077
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1078
-    }
1079
-
1080
-
1081
-
1082
-    /**
1083
-     *    load_CPTs_and_session
1084
-     *
1085
-     * @access public
1086
-     * @return    void
1087
-     */
1088
-    public function load_CPTs_and_session()
1089
-    {
1090
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1091
-        // register Custom Post Types
1092
-        $this->loader->getShared('EE_Register_CPTs');
1093
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1094
-    }
1095
-
1096
-
1097
-
1098
-    /**
1099
-     * load_controllers
1100
-     * this is the best place to load any additional controllers that needs access to EE core.
1101
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1102
-     * time
1103
-     *
1104
-     * @access public
1105
-     * @return void
1106
-     */
1107
-    public function load_controllers()
1108
-    {
1109
-        do_action('AHEE__EE_System__load_controllers__start');
1110
-        // let's get it started
1111
-        if (! is_admin() && ! $this->maintenance_mode->level()) {
1112
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1113
-            $this->loader->getShared('EE_Front_Controller');
1114
-        } else if (! EE_FRONT_AJAX) {
1115
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1116
-            $this->loader->getShared('EE_Admin');
1117
-        }
1118
-        do_action('AHEE__EE_System__load_controllers__complete');
1119
-    }
1120
-
1121
-
1122
-
1123
-    /**
1124
-     * core_loaded_and_ready
1125
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1126
-     *
1127
-     * @access public
1128
-     * @return void
1129
-     */
1130
-    public function core_loaded_and_ready()
1131
-    {
1132
-        $this->loader->getShared('EE_Session');
1133
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1134
-        // load_espresso_template_tags
1135
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
1136
-            require_once(EE_PUBLIC . 'template_tags.php');
1137
-        }
1138
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1139
-        $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1140
-    }
1141
-
1142
-
1143
-
1144
-    /**
1145
-     * initialize
1146
-     * this is the best place to begin initializing client code
1147
-     *
1148
-     * @access public
1149
-     * @return void
1150
-     */
1151
-    public function initialize()
1152
-    {
1153
-        do_action('AHEE__EE_System__initialize');
1154
-    }
1155
-
1156
-
1157
-
1158
-    /**
1159
-     * initialize_last
1160
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1161
-     * initialize has done so
1162
-     *
1163
-     * @access public
1164
-     * @return void
1165
-     */
1166
-    public function initialize_last()
1167
-    {
1168
-        do_action('AHEE__EE_System__initialize_last');
1169
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1170
-    }
1171
-
1172
-
1173
-
1174
-    /**
1175
-     * @return void
1176
-     * @throws EE_Error
1177
-     */
1178
-    public function addEspressoToolbar()
1179
-    {
1180
-        $this->loader->getShared(
1181
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1182
-            array($this->registry->CAP)
1183
-        );
1184
-    }
1185
-
1186
-
1187
-
1188
-    /**
1189
-     * do_not_cache
1190
-     * sets no cache headers and defines no cache constants for WP plugins
1191
-     *
1192
-     * @access public
1193
-     * @return void
1194
-     */
1195
-    public static function do_not_cache()
1196
-    {
1197
-        // set no cache constants
1198
-        if (! defined('DONOTCACHEPAGE')) {
1199
-            define('DONOTCACHEPAGE', true);
1200
-        }
1201
-        if (! defined('DONOTCACHCEOBJECT')) {
1202
-            define('DONOTCACHCEOBJECT', true);
1203
-        }
1204
-        if (! defined('DONOTCACHEDB')) {
1205
-            define('DONOTCACHEDB', true);
1206
-        }
1207
-        // add no cache headers
1208
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1209
-        // plus a little extra for nginx and Google Chrome
1210
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1211
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1212
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1213
-    }
1214
-
1215
-
1216
-
1217
-    /**
1218
-     *    extra_nocache_headers
1219
-     *
1220
-     * @access    public
1221
-     * @param $headers
1222
-     * @return    array
1223
-     */
1224
-    public static function extra_nocache_headers($headers)
1225
-    {
1226
-        // for NGINX
1227
-        $headers['X-Accel-Expires'] = 0;
1228
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1229
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1230
-        return $headers;
1231
-    }
1232
-
1233
-
1234
-
1235
-    /**
1236
-     *    nocache_headers
1237
-     *
1238
-     * @access    public
1239
-     * @return    void
1240
-     */
1241
-    public static function nocache_headers()
1242
-    {
1243
-        nocache_headers();
1244
-    }
1245
-
1246
-
1247
-
1248
-
1249
-    /**
1250
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1251
-     * never returned with the function.
1252
-     *
1253
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1254
-     * @return array
1255
-     */
1256
-    public function remove_pages_from_wp_list_pages($exclude_array)
1257
-    {
1258
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1259
-    }
24
+	/**
25
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
26
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
27
+	 */
28
+	const req_type_normal = 0;
29
+
30
+	/**
31
+	 * Indicates this is a brand new installation of EE so we should install
32
+	 * tables and default data etc
33
+	 */
34
+	const req_type_new_activation = 1;
35
+
36
+	/**
37
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
38
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
39
+	 * and that default data is setup too
40
+	 */
41
+	const req_type_reactivation = 2;
42
+
43
+	/**
44
+	 * indicates that EE has been upgraded since its previous request.
45
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
46
+	 */
47
+	const req_type_upgrade = 3;
48
+
49
+	/**
50
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
51
+	 */
52
+	const req_type_downgrade = 4;
53
+
54
+	/**
55
+	 * @deprecated since version 4.6.0.dev.006
56
+	 * Now whenever a new_activation is detected the request type is still just
57
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
58
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
59
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
60
+	 * (Specifically, when the migration manager indicates migrations are finished
61
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
62
+	 */
63
+	const req_type_activation_but_not_installed = 5;
64
+
65
+	/**
66
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
67
+	 */
68
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
69
+
70
+
71
+	/**
72
+	 * @var EE_System $_instance
73
+	 */
74
+	private static $_instance;
75
+
76
+	/**
77
+	 * @var EE_Registry $registry
78
+	 */
79
+	private $registry;
80
+
81
+	/**
82
+	 * @var LoaderInterface $loader
83
+	 */
84
+	private $loader;
85
+
86
+	/**
87
+	 * @var EE_Capabilities $capabilities
88
+	 */
89
+	private $capabilities;
90
+
91
+	/**
92
+	 * @var EE_Request $request
93
+	 */
94
+	private $request;
95
+
96
+	/**
97
+	 * @var EE_Maintenance_Mode $maintenance_mode
98
+	 */
99
+	private $maintenance_mode;
100
+
101
+	/**
102
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
103
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
104
+	 *
105
+	 * @var int $_req_type
106
+	 */
107
+	private $_req_type;
108
+
109
+	/**
110
+	 * Whether or not there was a non-micro version change in EE core version during this request
111
+	 *
112
+	 * @var boolean $_major_version_change
113
+	 */
114
+	private $_major_version_change = false;
115
+
116
+
117
+
118
+	/**
119
+	 * @singleton method used to instantiate class object
120
+	 * @param EE_Registry|null         $registry
121
+	 * @param LoaderInterface|null     $loader
122
+	 * @param EE_Capabilities|null     $capabilities
123
+	 * @param EE_Request|null          $request
124
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
125
+	 * @return EE_System
126
+	 */
127
+	public static function instance(
128
+		EE_Registry $registry = null,
129
+		LoaderInterface $loader = null,
130
+		EE_Capabilities $capabilities = null,
131
+		EE_Request $request = null,
132
+		EE_Maintenance_Mode $maintenance_mode = null
133
+	) {
134
+		// check if class object is instantiated
135
+		if (! self::$_instance instanceof EE_System) {
136
+			self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
137
+		}
138
+		return self::$_instance;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * resets the instance and returns it
145
+	 *
146
+	 * @return EE_System
147
+	 */
148
+	public static function reset()
149
+	{
150
+		self::$_instance->_req_type = null;
151
+		//make sure none of the old hooks are left hanging around
152
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
153
+		//we need to reset the migration manager in order for it to detect DMSs properly
154
+		EE_Data_Migration_Manager::reset();
155
+		self::instance()->detect_activations_or_upgrades();
156
+		self::instance()->perform_activations_upgrades_and_migrations();
157
+		return self::instance();
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * sets hooks for running rest of system
164
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
165
+	 * starting EE Addons from any other point may lead to problems
166
+	 *
167
+	 * @param EE_Registry         $registry
168
+	 * @param LoaderInterface     $loader
169
+	 * @param EE_Capabilities     $capabilities
170
+	 * @param EE_Request          $request
171
+	 * @param EE_Maintenance_Mode $maintenance_mode
172
+	 */
173
+	private function __construct(
174
+		EE_Registry $registry,
175
+		LoaderInterface $loader,
176
+		EE_Capabilities $capabilities,
177
+		EE_Request $request,
178
+		EE_Maintenance_Mode $maintenance_mode
179
+	) {
180
+		$this->registry = $registry;
181
+		$this->loader = $loader;
182
+		$this->capabilities = $capabilities;
183
+		$this->request = $request;
184
+		$this->maintenance_mode = $maintenance_mode;
185
+		do_action('AHEE__EE_System__construct__begin', $this);
186
+		add_action(
187
+			'AHEE__EE_Bootstrap__load_espresso_addons',
188
+			array($this, 'loadCapabilities'),
189
+			5
190
+		);
191
+		add_action(
192
+			'AHEE__EE_Bootstrap__load_espresso_addons',
193
+			array($this, 'loadCommandBus'),
194
+			7
195
+		);
196
+		add_action(
197
+			'AHEE__EE_Bootstrap__load_espresso_addons',
198
+			array($this, 'loadPluginApi'),
199
+			9
200
+		);
201
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
202
+		add_action(
203
+			'AHEE__EE_Bootstrap__load_espresso_addons',
204
+			array($this, 'load_espresso_addons')
205
+		);
206
+		// when an ee addon is activated, we want to call the core hook(s) again
207
+		// because the newly-activated addon didn't get a chance to run at all
208
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
209
+		// detect whether install or upgrade
210
+		add_action(
211
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
212
+			array($this, 'detect_activations_or_upgrades'),
213
+			3
214
+		);
215
+		// load EE_Config, EE_Textdomain, etc
216
+		add_action(
217
+			'AHEE__EE_Bootstrap__load_core_configuration',
218
+			array($this, 'load_core_configuration'),
219
+			5
220
+		);
221
+		// load EE_Config, EE_Textdomain, etc
222
+		add_action(
223
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
224
+			array($this, 'register_shortcodes_modules_and_widgets'),
225
+			7
226
+		);
227
+		// you wanna get going? I wanna get going... let's get going!
228
+		add_action(
229
+			'AHEE__EE_Bootstrap__brew_espresso',
230
+			array($this, 'brew_espresso'),
231
+			9
232
+		);
233
+		//other housekeeping
234
+		//exclude EE critical pages from wp_list_pages
235
+		add_filter(
236
+			'wp_list_pages_excludes',
237
+			array($this, 'remove_pages_from_wp_list_pages'),
238
+			10
239
+		);
240
+		// ALL EE Addons should use the following hook point to attach their initial setup too
241
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
242
+		do_action('AHEE__EE_System__construct__complete', $this);
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * load and setup EE_Capabilities
249
+	 *
250
+	 * @return void
251
+	 * @throws EE_Error
252
+	 */
253
+	public function loadCapabilities()
254
+	{
255
+		$this->loader->getShared('EE_Capabilities');
256
+		add_action(
257
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
258
+			function() {
259
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
260
+			}
261
+		);
262
+	}
263
+
264
+
265
+
266
+	/**
267
+	 * create and cache the CommandBus, and also add middleware
268
+	 * The CapChecker middleware requires the use of EE_Capabilities
269
+	 * which is why we need to load the CommandBus after Caps are set up
270
+	 *
271
+	 * @return void
272
+	 * @throws EE_Error
273
+	 */
274
+	public function loadCommandBus()
275
+	{
276
+		$this->loader->getShared(
277
+			'CommandBusInterface',
278
+			array(
279
+				null,
280
+				apply_filters(
281
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
282
+					array(
283
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
284
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
285
+					)
286
+				),
287
+			)
288
+		);
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * @return void
295
+	 * @throws EE_Error
296
+	 */
297
+	public function loadPluginApi()
298
+	{
299
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
300
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
301
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
302
+	}
303
+
304
+
305
+	/**
306
+	 * @param string $addon_name
307
+	 * @param string $version_constant
308
+	 * @param string $min_version_required
309
+	 * @param string $load_callback
310
+	 * @param string $plugin_file_constant
311
+	 * @return void
312
+	 */
313
+	private function deactivateIncompatibleAddon(
314
+		$addon_name,
315
+		$version_constant,
316
+		$min_version_required,
317
+		$load_callback,
318
+		$plugin_file_constant
319
+	) {
320
+		if (! defined($version_constant)) {
321
+			return;
322
+		}
323
+		$addon_version = constant($version_constant);
324
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
325
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
326
+			if (! function_exists('deactivate_plugins')) {
327
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
328
+			}
329
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
330
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
331
+			EE_Error::add_error(
332
+				sprintf(
333
+					esc_html__(
334
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
335
+						'event_espresso'
336
+					),
337
+					$addon_name,
338
+					$min_version_required
339
+				),
340
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
341
+			);
342
+			EE_Error::get_notices(false, true);
343
+		}
344
+	}
345
+
346
+
347
+	/**
348
+	 * load_espresso_addons
349
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
350
+	 * this is hooked into both:
351
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
352
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
353
+	 *    and the WP 'activate_plugin' hook point
354
+	 *
355
+	 * @access public
356
+	 * @return void
357
+	 */
358
+	public function load_espresso_addons()
359
+	{
360
+		$this->deactivateIncompatibleAddon(
361
+			'Wait Lists',
362
+			'EE_WAIT_LISTS_VERSION',
363
+			'1.0.0.rc.074',
364
+			'load_espresso_wait_lists',
365
+			'EE_WAIT_LISTS_PLUGIN_FILE'
366
+		);
367
+		$this->deactivateIncompatibleAddon(
368
+			'Automated Upcoming Event Notifications',
369
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
370
+			'1.0.0.rc.091',
371
+			'load_espresso_automated_upcoming_event_notification',
372
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
373
+		);
374
+		do_action('AHEE__EE_System__load_espresso_addons');
375
+		//if the WP API basic auth plugin isn't already loaded, load it now.
376
+		//We want it for mobile apps. Just include the entire plugin
377
+		//also, don't load the basic auth when a plugin is getting activated, because
378
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
379
+		//and causes a fatal error
380
+		if (
381
+			! (
382
+				isset($_GET['activate'])
383
+				&& $_GET['activate'] === 'true'
384
+			)
385
+			&& ! function_exists('json_basic_auth_handler')
386
+			&& ! function_exists('json_basic_auth_error')
387
+			&& ! (
388
+				isset($_GET['action'])
389
+				&& in_array($_GET['action'], array('activate', 'activate-selected'), true)
390
+			)
391
+		) {
392
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
393
+		}
394
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
395
+	}
396
+
397
+
398
+
399
+	/**
400
+	 * detect_activations_or_upgrades
401
+	 * Checks for activation or upgrade of core first;
402
+	 * then also checks if any registered addons have been activated or upgraded
403
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
404
+	 * which runs during the WP 'plugins_loaded' action at priority 3
405
+	 *
406
+	 * @access public
407
+	 * @return void
408
+	 */
409
+	public function detect_activations_or_upgrades()
410
+	{
411
+		//first off: let's make sure to handle core
412
+		$this->detect_if_activation_or_upgrade();
413
+		foreach ($this->registry->addons as $addon) {
414
+			if ($addon instanceof EE_Addon) {
415
+				//detect teh request type for that addon
416
+				$addon->detect_activation_or_upgrade();
417
+			}
418
+		}
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * detect_if_activation_or_upgrade
425
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
426
+	 * and either setting up the DB or setting up maintenance mode etc.
427
+	 *
428
+	 * @access public
429
+	 * @return void
430
+	 */
431
+	public function detect_if_activation_or_upgrade()
432
+	{
433
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
434
+		// check if db has been updated, or if its a brand-new installation
435
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
436
+		$request_type = $this->detect_req_type($espresso_db_update);
437
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
438
+		switch ($request_type) {
439
+			case EE_System::req_type_new_activation:
440
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
441
+				$this->_handle_core_version_change($espresso_db_update);
442
+				break;
443
+			case EE_System::req_type_reactivation:
444
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
445
+				$this->_handle_core_version_change($espresso_db_update);
446
+				break;
447
+			case EE_System::req_type_upgrade:
448
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
449
+				//migrations may be required now that we've upgraded
450
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
451
+				$this->_handle_core_version_change($espresso_db_update);
452
+				//				echo "done upgrade";die;
453
+				break;
454
+			case EE_System::req_type_downgrade:
455
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
456
+				//its possible migrations are no longer required
457
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
458
+				$this->_handle_core_version_change($espresso_db_update);
459
+				break;
460
+			case EE_System::req_type_normal:
461
+			default:
462
+				//				$this->_maybe_redirect_to_ee_about();
463
+				break;
464
+		}
465
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
466
+	}
467
+
468
+
469
+
470
+	/**
471
+	 * Updates the list of installed versions and sets hooks for
472
+	 * initializing the database later during the request
473
+	 *
474
+	 * @param array $espresso_db_update
475
+	 */
476
+	private function _handle_core_version_change($espresso_db_update)
477
+	{
478
+		$this->update_list_of_installed_versions($espresso_db_update);
479
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
480
+		add_action(
481
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
482
+			array($this, 'initialize_db_if_no_migrations_required')
483
+		);
484
+	}
485
+
486
+
487
+
488
+	/**
489
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
490
+	 * information about what versions of EE have been installed and activated,
491
+	 * NOT necessarily the state of the database
492
+	 *
493
+	 * @param mixed $espresso_db_update the value of the WordPress option.
494
+	 *                                            If not supplied, fetches it from the options table
495
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
496
+	 */
497
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
498
+	{
499
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
500
+		if (! $espresso_db_update) {
501
+			$espresso_db_update = get_option('espresso_db_update');
502
+		}
503
+		// check that option is an array
504
+		if (! is_array($espresso_db_update)) {
505
+			// if option is FALSE, then it never existed
506
+			if ($espresso_db_update === false) {
507
+				// make $espresso_db_update an array and save option with autoload OFF
508
+				$espresso_db_update = array();
509
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
510
+			} else {
511
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
512
+				$espresso_db_update = array($espresso_db_update => array());
513
+				update_option('espresso_db_update', $espresso_db_update);
514
+			}
515
+		} else {
516
+			$corrected_db_update = array();
517
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
518
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
519
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
520
+					//the key is an int, and the value IS NOT an array
521
+					//so it must be numerically-indexed, where values are versions installed...
522
+					//fix it!
523
+					$version_string = $should_be_array;
524
+					$corrected_db_update[$version_string] = array('unknown-date');
525
+				} else {
526
+					//ok it checks out
527
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
528
+				}
529
+			}
530
+			$espresso_db_update = $corrected_db_update;
531
+			update_option('espresso_db_update', $espresso_db_update);
532
+		}
533
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
534
+		return $espresso_db_update;
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * Does the traditional work of setting up the plugin's database and adding default data.
541
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
542
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
543
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
544
+	 * so that it will be done when migrations are finished
545
+	 *
546
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
547
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
548
+	 *                                       This is a resource-intensive job
549
+	 *                                       so we prefer to only do it when necessary
550
+	 * @return void
551
+	 * @throws EE_Error
552
+	 */
553
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
554
+	{
555
+		$request_type = $this->detect_req_type();
556
+		//only initialize system if we're not in maintenance mode.
557
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
558
+			update_option('ee_flush_rewrite_rules', true);
559
+			if ($verify_schema) {
560
+				EEH_Activation::initialize_db_and_folders();
561
+			}
562
+			EEH_Activation::initialize_db_content();
563
+			EEH_Activation::system_initialization();
564
+			if ($initialize_addons_too) {
565
+				$this->initialize_addons();
566
+			}
567
+		} else {
568
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
569
+		}
570
+		if ($request_type === EE_System::req_type_new_activation
571
+			|| $request_type === EE_System::req_type_reactivation
572
+			|| (
573
+				$request_type === EE_System::req_type_upgrade
574
+				&& $this->is_major_version_change()
575
+			)
576
+		) {
577
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
578
+		}
579
+	}
580
+
581
+
582
+
583
+	/**
584
+	 * Initializes the db for all registered addons
585
+	 *
586
+	 * @throws EE_Error
587
+	 */
588
+	public function initialize_addons()
589
+	{
590
+		//foreach registered addon, make sure its db is up-to-date too
591
+		foreach ($this->registry->addons as $addon) {
592
+			if ($addon instanceof EE_Addon) {
593
+				$addon->initialize_db_if_no_migrations_required();
594
+			}
595
+		}
596
+	}
597
+
598
+
599
+
600
+	/**
601
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
602
+	 *
603
+	 * @param    array  $version_history
604
+	 * @param    string $current_version_to_add version to be added to the version history
605
+	 * @return    boolean success as to whether or not this option was changed
606
+	 */
607
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
608
+	{
609
+		if (! $version_history) {
610
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
611
+		}
612
+		if ($current_version_to_add === null) {
613
+			$current_version_to_add = espresso_version();
614
+		}
615
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
616
+		// re-save
617
+		return update_option('espresso_db_update', $version_history);
618
+	}
619
+
620
+
621
+
622
+	/**
623
+	 * Detects if the current version indicated in the has existed in the list of
624
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
625
+	 *
626
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
627
+	 *                                  If not supplied, fetches it from the options table.
628
+	 *                                  Also, caches its result so later parts of the code can also know whether
629
+	 *                                  there's been an update or not. This way we can add the current version to
630
+	 *                                  espresso_db_update, but still know if this is a new install or not
631
+	 * @return int one of the constants on EE_System::req_type_
632
+	 */
633
+	public function detect_req_type($espresso_db_update = null)
634
+	{
635
+		if ($this->_req_type === null) {
636
+			$espresso_db_update = ! empty($espresso_db_update)
637
+				? $espresso_db_update
638
+				: $this->fix_espresso_db_upgrade_option();
639
+			$this->_req_type = EE_System::detect_req_type_given_activation_history(
640
+				$espresso_db_update,
641
+				'ee_espresso_activation', espresso_version()
642
+			);
643
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
644
+		}
645
+		return $this->_req_type;
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * Returns whether or not there was a non-micro version change (ie, change in either
652
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
653
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
654
+	 *
655
+	 * @param $activation_history
656
+	 * @return bool
657
+	 */
658
+	private function _detect_major_version_change($activation_history)
659
+	{
660
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
661
+		$previous_version_parts = explode('.', $previous_version);
662
+		$current_version_parts = explode('.', espresso_version());
663
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
664
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
665
+				   || $previous_version_parts[1] !== $current_version_parts[1]
666
+			   );
667
+	}
668
+
669
+
670
+
671
+	/**
672
+	 * Returns true if either the major or minor version of EE changed during this request.
673
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
674
+	 *
675
+	 * @return bool
676
+	 */
677
+	public function is_major_version_change()
678
+	{
679
+		return $this->_major_version_change;
680
+	}
681
+
682
+
683
+
684
+	/**
685
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
686
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
687
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
688
+	 * just activated to (for core that will always be espresso_version())
689
+	 *
690
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
691
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
692
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
693
+	 *                                                 indicate that this plugin was just activated
694
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
695
+	 *                                                 espresso_version())
696
+	 * @return int one of the constants on EE_System::req_type_*
697
+	 */
698
+	public static function detect_req_type_given_activation_history(
699
+		$activation_history_for_addon,
700
+		$activation_indicator_option_name,
701
+		$version_to_upgrade_to
702
+	) {
703
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
704
+		if ($activation_history_for_addon) {
705
+			//it exists, so this isn't a completely new install
706
+			//check if this version already in that list of previously installed versions
707
+			if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
708
+				//it a version we haven't seen before
709
+				if ($version_is_higher === 1) {
710
+					$req_type = EE_System::req_type_upgrade;
711
+				} else {
712
+					$req_type = EE_System::req_type_downgrade;
713
+				}
714
+				delete_option($activation_indicator_option_name);
715
+			} else {
716
+				// its not an update. maybe a reactivation?
717
+				if (get_option($activation_indicator_option_name, false)) {
718
+					if ($version_is_higher === -1) {
719
+						$req_type = EE_System::req_type_downgrade;
720
+					} else if ($version_is_higher === 0) {
721
+						//we've seen this version before, but it's an activation. must be a reactivation
722
+						$req_type = EE_System::req_type_reactivation;
723
+					} else {//$version_is_higher === 1
724
+						$req_type = EE_System::req_type_upgrade;
725
+					}
726
+					delete_option($activation_indicator_option_name);
727
+				} else {
728
+					//we've seen this version before and the activation indicate doesn't show it was just activated
729
+					if ($version_is_higher === -1) {
730
+						$req_type = EE_System::req_type_downgrade;
731
+					} else if ($version_is_higher === 0) {
732
+						//we've seen this version before and it's not an activation. its normal request
733
+						$req_type = EE_System::req_type_normal;
734
+					} else {//$version_is_higher === 1
735
+						$req_type = EE_System::req_type_upgrade;
736
+					}
737
+				}
738
+			}
739
+		} else {
740
+			//brand new install
741
+			$req_type = EE_System::req_type_new_activation;
742
+			delete_option($activation_indicator_option_name);
743
+		}
744
+		return $req_type;
745
+	}
746
+
747
+
748
+
749
+	/**
750
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
751
+	 * the $activation_history_for_addon
752
+	 *
753
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
754
+	 *                                             sometimes containing 'unknown-date'
755
+	 * @param string $version_to_upgrade_to        (current version)
756
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
757
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
758
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
759
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
760
+	 */
761
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
762
+	{
763
+		//find the most recently-activated version
764
+		$most_recently_active_version =
765
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
766
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
767
+	}
768
+
769
+
770
+
771
+	/**
772
+	 * Gets the most recently active version listed in the activation history,
773
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
774
+	 *
775
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
776
+	 *                                   sometimes containing 'unknown-date'
777
+	 * @return string
778
+	 */
779
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
780
+	{
781
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
782
+		$most_recently_active_version = '0.0.0.dev.000';
783
+		if (is_array($activation_history)) {
784
+			foreach ($activation_history as $version => $times_activated) {
785
+				//check there is a record of when this version was activated. Otherwise,
786
+				//mark it as unknown
787
+				if (! $times_activated) {
788
+					$times_activated = array('unknown-date');
789
+				}
790
+				if (is_string($times_activated)) {
791
+					$times_activated = array($times_activated);
792
+				}
793
+				foreach ($times_activated as $an_activation) {
794
+					if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
795
+						$most_recently_active_version = $version;
796
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
797
+							? '1970-01-01 00:00:00'
798
+							: $an_activation;
799
+					}
800
+				}
801
+			}
802
+		}
803
+		return $most_recently_active_version;
804
+	}
805
+
806
+
807
+
808
+	/**
809
+	 * This redirects to the about EE page after activation
810
+	 *
811
+	 * @return void
812
+	 */
813
+	public function redirect_to_about_ee()
814
+	{
815
+		$notices = EE_Error::get_notices(false);
816
+		//if current user is an admin and it's not an ajax or rest request
817
+		if (
818
+			! (defined('DOING_AJAX') && DOING_AJAX)
819
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
820
+			&& ! isset($notices['errors'])
821
+			&& apply_filters(
822
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
823
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
824
+			)
825
+		) {
826
+			$query_params = array('page' => 'espresso_about');
827
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
828
+				$query_params['new_activation'] = true;
829
+			}
830
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
831
+				$query_params['reactivation'] = true;
832
+			}
833
+			$url = add_query_arg($query_params, admin_url('admin.php'));
834
+			wp_safe_redirect($url);
835
+			exit();
836
+		}
837
+	}
838
+
839
+
840
+
841
+	/**
842
+	 * load_core_configuration
843
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
844
+	 * which runs during the WP 'plugins_loaded' action at priority 5
845
+	 *
846
+	 * @return void
847
+	 * @throws ReflectionException
848
+	 */
849
+	public function load_core_configuration()
850
+	{
851
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
852
+		$this->loader->getShared('EE_Load_Textdomain');
853
+		//load textdomain
854
+		EE_Load_Textdomain::load_textdomain();
855
+		// load and setup EE_Config and EE_Network_Config
856
+		$config = $this->loader->getShared('EE_Config');
857
+		$this->loader->getShared('EE_Network_Config');
858
+		// setup autoloaders
859
+		// enable logging?
860
+		if ($config->admin->use_full_logging) {
861
+			$this->loader->getShared('EE_Log');
862
+		}
863
+		// check for activation errors
864
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
865
+		if ($activation_errors) {
866
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
867
+			update_option('ee_plugin_activation_errors', false);
868
+		}
869
+		// get model names
870
+		$this->_parse_model_names();
871
+		//load caf stuff a chance to play during the activation process too.
872
+		$this->_maybe_brew_regular();
873
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
874
+	}
875
+
876
+
877
+
878
+	/**
879
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
880
+	 *
881
+	 * @return void
882
+	 * @throws ReflectionException
883
+	 */
884
+	private function _parse_model_names()
885
+	{
886
+		//get all the files in the EE_MODELS folder that end in .model.php
887
+		$models = glob(EE_MODELS . '*.model.php');
888
+		$model_names = array();
889
+		$non_abstract_db_models = array();
890
+		foreach ($models as $model) {
891
+			// get model classname
892
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
893
+			$short_name = str_replace('EEM_', '', $classname);
894
+			$reflectionClass = new ReflectionClass($classname);
895
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
896
+				$non_abstract_db_models[$short_name] = $classname;
897
+			}
898
+			$model_names[$short_name] = $classname;
899
+		}
900
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
901
+		$this->registry->non_abstract_db_models = apply_filters(
902
+			'FHEE__EE_System__parse_implemented_model_names',
903
+			$non_abstract_db_models
904
+		);
905
+	}
906
+
907
+
908
+
909
+	/**
910
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
911
+	 * that need to be setup before our EE_System launches.
912
+	 *
913
+	 * @return void
914
+	 */
915
+	private function _maybe_brew_regular()
916
+	{
917
+		if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
918
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
919
+		}
920
+	}
921
+
922
+
923
+
924
+	/**
925
+	 * register_shortcodes_modules_and_widgets
926
+	 * generate lists of shortcodes and modules, then verify paths and classes
927
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
928
+	 * which runs during the WP 'plugins_loaded' action at priority 7
929
+	 *
930
+	 * @access public
931
+	 * @return void
932
+	 * @throws Exception
933
+	 */
934
+	public function register_shortcodes_modules_and_widgets()
935
+	{
936
+		try {
937
+			// load, register, and add shortcodes the new way
938
+			$this->loader->getShared(
939
+				'EventEspresso\core\services\shortcodes\ShortcodesManager',
940
+				array(
941
+					// and the old way, but we'll put it under control of the new system
942
+					EE_Config::getLegacyShortcodesManager()
943
+				)
944
+			);
945
+		} catch (Exception $exception) {
946
+			new ExceptionStackTraceDisplay($exception);
947
+		}
948
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
949
+		// check for addons using old hook point
950
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
951
+			$this->_incompatible_addon_error();
952
+		}
953
+	}
954
+
955
+
956
+
957
+	/**
958
+	 * _incompatible_addon_error
959
+	 *
960
+	 * @access public
961
+	 * @return void
962
+	 */
963
+	private function _incompatible_addon_error()
964
+	{
965
+		// get array of classes hooking into here
966
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
967
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
968
+		);
969
+		if (! empty($class_names)) {
970
+			$msg = __(
971
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
972
+				'event_espresso'
973
+			);
974
+			$msg .= '<ul>';
975
+			foreach ($class_names as $class_name) {
976
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
977
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
978
+						$class_name
979
+					) . '</b></li>';
980
+			}
981
+			$msg .= '</ul>';
982
+			$msg .= __(
983
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
984
+				'event_espresso'
985
+			);
986
+			// save list of incompatible addons to wp-options for later use
987
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
988
+			if (is_admin()) {
989
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
990
+			}
991
+		}
992
+	}
993
+
994
+
995
+
996
+	/**
997
+	 * brew_espresso
998
+	 * begins the process of setting hooks for initializing EE in the correct order
999
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1000
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1001
+	 *
1002
+	 * @return void
1003
+	 */
1004
+	public function brew_espresso()
1005
+	{
1006
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1007
+		// load some final core systems
1008
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1009
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1010
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1011
+		add_action('init', array($this, 'load_controllers'), 7);
1012
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1013
+		add_action('init', array($this, 'initialize'), 10);
1014
+		add_action('init', array($this, 'initialize_last'), 100);
1015
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1016
+			// pew pew pew
1017
+			$this->loader->getShared('EE_PUE');
1018
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1019
+		}
1020
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1021
+	}
1022
+
1023
+
1024
+
1025
+	/**
1026
+	 *    set_hooks_for_core
1027
+	 *
1028
+	 * @access public
1029
+	 * @return    void
1030
+	 * @throws EE_Error
1031
+	 */
1032
+	public function set_hooks_for_core()
1033
+	{
1034
+		$this->_deactivate_incompatible_addons();
1035
+		do_action('AHEE__EE_System__set_hooks_for_core');
1036
+		//caps need to be initialized on every request so that capability maps are set.
1037
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1038
+		$this->registry->CAP->init_caps();
1039
+	}
1040
+
1041
+
1042
+
1043
+	/**
1044
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1045
+	 * deactivates any addons considered incompatible with the current version of EE
1046
+	 */
1047
+	private function _deactivate_incompatible_addons()
1048
+	{
1049
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1050
+		if (! empty($incompatible_addons)) {
1051
+			$active_plugins = get_option('active_plugins', array());
1052
+			foreach ($active_plugins as $active_plugin) {
1053
+				foreach ($incompatible_addons as $incompatible_addon) {
1054
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1055
+						unset($_GET['activate']);
1056
+						espresso_deactivate_plugin($active_plugin);
1057
+					}
1058
+				}
1059
+			}
1060
+		}
1061
+	}
1062
+
1063
+
1064
+
1065
+	/**
1066
+	 *    perform_activations_upgrades_and_migrations
1067
+	 *
1068
+	 * @access public
1069
+	 * @return    void
1070
+	 */
1071
+	public function perform_activations_upgrades_and_migrations()
1072
+	{
1073
+		//first check if we had previously attempted to setup EE's directories but failed
1074
+		if (EEH_Activation::upload_directories_incomplete()) {
1075
+			EEH_Activation::create_upload_directories();
1076
+		}
1077
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1078
+	}
1079
+
1080
+
1081
+
1082
+	/**
1083
+	 *    load_CPTs_and_session
1084
+	 *
1085
+	 * @access public
1086
+	 * @return    void
1087
+	 */
1088
+	public function load_CPTs_and_session()
1089
+	{
1090
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1091
+		// register Custom Post Types
1092
+		$this->loader->getShared('EE_Register_CPTs');
1093
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1094
+	}
1095
+
1096
+
1097
+
1098
+	/**
1099
+	 * load_controllers
1100
+	 * this is the best place to load any additional controllers that needs access to EE core.
1101
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1102
+	 * time
1103
+	 *
1104
+	 * @access public
1105
+	 * @return void
1106
+	 */
1107
+	public function load_controllers()
1108
+	{
1109
+		do_action('AHEE__EE_System__load_controllers__start');
1110
+		// let's get it started
1111
+		if (! is_admin() && ! $this->maintenance_mode->level()) {
1112
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1113
+			$this->loader->getShared('EE_Front_Controller');
1114
+		} else if (! EE_FRONT_AJAX) {
1115
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1116
+			$this->loader->getShared('EE_Admin');
1117
+		}
1118
+		do_action('AHEE__EE_System__load_controllers__complete');
1119
+	}
1120
+
1121
+
1122
+
1123
+	/**
1124
+	 * core_loaded_and_ready
1125
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1126
+	 *
1127
+	 * @access public
1128
+	 * @return void
1129
+	 */
1130
+	public function core_loaded_and_ready()
1131
+	{
1132
+		$this->loader->getShared('EE_Session');
1133
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1134
+		// load_espresso_template_tags
1135
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
1136
+			require_once(EE_PUBLIC . 'template_tags.php');
1137
+		}
1138
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1139
+		$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1140
+	}
1141
+
1142
+
1143
+
1144
+	/**
1145
+	 * initialize
1146
+	 * this is the best place to begin initializing client code
1147
+	 *
1148
+	 * @access public
1149
+	 * @return void
1150
+	 */
1151
+	public function initialize()
1152
+	{
1153
+		do_action('AHEE__EE_System__initialize');
1154
+	}
1155
+
1156
+
1157
+
1158
+	/**
1159
+	 * initialize_last
1160
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1161
+	 * initialize has done so
1162
+	 *
1163
+	 * @access public
1164
+	 * @return void
1165
+	 */
1166
+	public function initialize_last()
1167
+	{
1168
+		do_action('AHEE__EE_System__initialize_last');
1169
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1170
+	}
1171
+
1172
+
1173
+
1174
+	/**
1175
+	 * @return void
1176
+	 * @throws EE_Error
1177
+	 */
1178
+	public function addEspressoToolbar()
1179
+	{
1180
+		$this->loader->getShared(
1181
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1182
+			array($this->registry->CAP)
1183
+		);
1184
+	}
1185
+
1186
+
1187
+
1188
+	/**
1189
+	 * do_not_cache
1190
+	 * sets no cache headers and defines no cache constants for WP plugins
1191
+	 *
1192
+	 * @access public
1193
+	 * @return void
1194
+	 */
1195
+	public static function do_not_cache()
1196
+	{
1197
+		// set no cache constants
1198
+		if (! defined('DONOTCACHEPAGE')) {
1199
+			define('DONOTCACHEPAGE', true);
1200
+		}
1201
+		if (! defined('DONOTCACHCEOBJECT')) {
1202
+			define('DONOTCACHCEOBJECT', true);
1203
+		}
1204
+		if (! defined('DONOTCACHEDB')) {
1205
+			define('DONOTCACHEDB', true);
1206
+		}
1207
+		// add no cache headers
1208
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1209
+		// plus a little extra for nginx and Google Chrome
1210
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1211
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1212
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1213
+	}
1214
+
1215
+
1216
+
1217
+	/**
1218
+	 *    extra_nocache_headers
1219
+	 *
1220
+	 * @access    public
1221
+	 * @param $headers
1222
+	 * @return    array
1223
+	 */
1224
+	public static function extra_nocache_headers($headers)
1225
+	{
1226
+		// for NGINX
1227
+		$headers['X-Accel-Expires'] = 0;
1228
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1229
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1230
+		return $headers;
1231
+	}
1232
+
1233
+
1234
+
1235
+	/**
1236
+	 *    nocache_headers
1237
+	 *
1238
+	 * @access    public
1239
+	 * @return    void
1240
+	 */
1241
+	public static function nocache_headers()
1242
+	{
1243
+		nocache_headers();
1244
+	}
1245
+
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1251
+	 * never returned with the function.
1252
+	 *
1253
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1254
+	 * @return array
1255
+	 */
1256
+	public function remove_pages_from_wp_list_pages($exclude_array)
1257
+	{
1258
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1259
+	}
1260 1260
 
1261 1261
 
1262 1262
 
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         EE_Maintenance_Mode $maintenance_mode = null
133 133
     ) {
134 134
         // check if class object is instantiated
135
-        if (! self::$_instance instanceof EE_System) {
135
+        if ( ! self::$_instance instanceof EE_System) {
136 136
             self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
137 137
         }
138 138
         return self::$_instance;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     {
299 299
         // set autoloaders for all of the classes implementing EEI_Plugin_API
300 300
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
301
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
301
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
302 302
     }
303 303
 
304 304
 
@@ -317,14 +317,14 @@  discard block
 block discarded – undo
317 317
         $load_callback,
318 318
         $plugin_file_constant
319 319
     ) {
320
-        if (! defined($version_constant)) {
320
+        if ( ! defined($version_constant)) {
321 321
             return;
322 322
         }
323 323
         $addon_version = constant($version_constant);
324 324
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
325 325
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
326
-            if (! function_exists('deactivate_plugins')) {
327
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
326
+            if ( ! function_exists('deactivate_plugins')) {
327
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
328 328
             }
329 329
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
330 330
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                     $addon_name,
338 338
                     $min_version_required
339 339
                 ),
340
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
340
+                __FILE__, __FUNCTION__."({$addon_name})", __LINE__
341 341
             );
342 342
             EE_Error::get_notices(false, true);
343 343
         }
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
                 && in_array($_GET['action'], array('activate', 'activate-selected'), true)
390 390
             )
391 391
         ) {
392
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
392
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
393 393
         }
394 394
         do_action('AHEE__EE_System__load_espresso_addons__complete');
395 395
     }
@@ -497,11 +497,11 @@  discard block
 block discarded – undo
497 497
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
498 498
     {
499 499
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
500
-        if (! $espresso_db_update) {
500
+        if ( ! $espresso_db_update) {
501 501
             $espresso_db_update = get_option('espresso_db_update');
502 502
         }
503 503
         // check that option is an array
504
-        if (! is_array($espresso_db_update)) {
504
+        if ( ! is_array($espresso_db_update)) {
505 505
             // if option is FALSE, then it never existed
506 506
             if ($espresso_db_update === false) {
507 507
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
      */
607 607
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
608 608
     {
609
-        if (! $version_history) {
609
+        if ( ! $version_history) {
610 610
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
611 611
         }
612 612
         if ($current_version_to_add === null) {
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
         if ($activation_history_for_addon) {
705 705
             //it exists, so this isn't a completely new install
706 706
             //check if this version already in that list of previously installed versions
707
-            if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
707
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
708 708
                 //it a version we haven't seen before
709 709
                 if ($version_is_higher === 1) {
710 710
                     $req_type = EE_System::req_type_upgrade;
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
             foreach ($activation_history as $version => $times_activated) {
785 785
                 //check there is a record of when this version was activated. Otherwise,
786 786
                 //mark it as unknown
787
-                if (! $times_activated) {
787
+                if ( ! $times_activated) {
788 788
                     $times_activated = array('unknown-date');
789 789
                 }
790 790
                 if (is_string($times_activated)) {
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
     private function _parse_model_names()
885 885
     {
886 886
         //get all the files in the EE_MODELS folder that end in .model.php
887
-        $models = glob(EE_MODELS . '*.model.php');
887
+        $models = glob(EE_MODELS.'*.model.php');
888 888
         $model_names = array();
889 889
         $non_abstract_db_models = array();
890 890
         foreach ($models as $model) {
@@ -914,8 +914,8 @@  discard block
 block discarded – undo
914 914
      */
915 915
     private function _maybe_brew_regular()
916 916
     {
917
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
918
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
917
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
918
+            require_once EE_CAFF_PATH.'brewing_regular.php';
919 919
         }
920 920
     }
921 921
 
@@ -966,17 +966,17 @@  discard block
 block discarded – undo
966 966
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
967 967
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
968 968
         );
969
-        if (! empty($class_names)) {
969
+        if ( ! empty($class_names)) {
970 970
             $msg = __(
971 971
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
972 972
                 'event_espresso'
973 973
             );
974 974
             $msg .= '<ul>';
975 975
             foreach ($class_names as $class_name) {
976
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
976
+                $msg .= '<li><b>Event Espresso - '.str_replace(
977 977
                         array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
978 978
                         $class_name
979
-                    ) . '</b></li>';
979
+                    ).'</b></li>';
980 980
             }
981 981
             $msg .= '</ul>';
982 982
             $msg .= __(
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
     private function _deactivate_incompatible_addons()
1048 1048
     {
1049 1049
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1050
-        if (! empty($incompatible_addons)) {
1050
+        if ( ! empty($incompatible_addons)) {
1051 1051
             $active_plugins = get_option('active_plugins', array());
1052 1052
             foreach ($active_plugins as $active_plugin) {
1053 1053
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1108,10 +1108,10 @@  discard block
 block discarded – undo
1108 1108
     {
1109 1109
         do_action('AHEE__EE_System__load_controllers__start');
1110 1110
         // let's get it started
1111
-        if (! is_admin() && ! $this->maintenance_mode->level()) {
1111
+        if ( ! is_admin() && ! $this->maintenance_mode->level()) {
1112 1112
             do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1113 1113
             $this->loader->getShared('EE_Front_Controller');
1114
-        } else if (! EE_FRONT_AJAX) {
1114
+        } else if ( ! EE_FRONT_AJAX) {
1115 1115
             do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1116 1116
             $this->loader->getShared('EE_Admin');
1117 1117
         }
@@ -1132,8 +1132,8 @@  discard block
 block discarded – undo
1132 1132
         $this->loader->getShared('EE_Session');
1133 1133
         do_action('AHEE__EE_System__core_loaded_and_ready');
1134 1134
         // load_espresso_template_tags
1135
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
1136
-            require_once(EE_PUBLIC . 'template_tags.php');
1135
+        if (is_readable(EE_PUBLIC.'template_tags.php')) {
1136
+            require_once(EE_PUBLIC.'template_tags.php');
1137 1137
         }
1138 1138
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1139 1139
         $this->loader->getShared('EventEspresso\core\services\assets\Registry');
@@ -1195,13 +1195,13 @@  discard block
 block discarded – undo
1195 1195
     public static function do_not_cache()
1196 1196
     {
1197 1197
         // set no cache constants
1198
-        if (! defined('DONOTCACHEPAGE')) {
1198
+        if ( ! defined('DONOTCACHEPAGE')) {
1199 1199
             define('DONOTCACHEPAGE', true);
1200 1200
         }
1201
-        if (! defined('DONOTCACHCEOBJECT')) {
1201
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1202 1202
             define('DONOTCACHCEOBJECT', true);
1203 1203
         }
1204
-        if (! defined('DONOTCACHEDB')) {
1204
+        if ( ! defined('DONOTCACHEDB')) {
1205 1205
             define('DONOTCACHEDB', true);
1206 1206
         }
1207 1207
         // add no cache headers
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -38,217 +38,217 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         *
70
-         * @return void
71
-         */
72
-        function espresso_minimum_php_version_error()
73
-        {
74
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 *
70
+		 * @return void
71
+		 */
72
+		function espresso_minimum_php_version_error()
73
+		{
74
+			?>
75 75
             <div class="error">
76 76
                 <p>
77 77
                     <?php
78
-                    printf(
79
-                        esc_html__(
80
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
81
-                            'event_espresso'
82
-                        ),
83
-                        EE_MIN_PHP_VER_REQUIRED,
84
-                        PHP_VERSION,
85
-                        '<br/>',
86
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
-                    );
88
-                    ?>
78
+					printf(
79
+						esc_html__(
80
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
81
+							'event_espresso'
82
+						),
83
+						EE_MIN_PHP_VER_REQUIRED,
84
+						PHP_VERSION,
85
+						'<br/>',
86
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
+					);
88
+					?>
89 89
                 </p>
90 90
             </div>
91 91
             <?php
92
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
93
-        }
92
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
93
+		}
94 94
 
95
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
-    } else {
97
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
-        /**
99
-         * espresso_version
100
-         * Returns the plugin version
101
-         *
102
-         * @return string
103
-         */
104
-        function espresso_version()
105
-        {
106
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.54.rc.015');
107
-        }
95
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
+	} else {
97
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
+		/**
99
+		 * espresso_version
100
+		 * Returns the plugin version
101
+		 *
102
+		 * @return string
103
+		 */
104
+		function espresso_version()
105
+		{
106
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.54.rc.015');
107
+		}
108 108
 
109
-        /**
110
-         * espresso_plugin_activation
111
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
-         */
113
-        function espresso_plugin_activation()
114
-        {
115
-            update_option('ee_espresso_activation', true);
116
-        }
109
+		/**
110
+		 * espresso_plugin_activation
111
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
+		 */
113
+		function espresso_plugin_activation()
114
+		{
115
+			update_option('ee_espresso_activation', true);
116
+		}
117 117
 
118
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
-        /**
120
-         *    espresso_load_error_handling
121
-         *    this function loads EE's class for handling exceptions and errors
122
-         */
123
-        function espresso_load_error_handling()
124
-        {
125
-            static $error_handling_loaded = false;
126
-            if ($error_handling_loaded) {
127
-                return;
128
-            }
129
-            // load debugging tools
130
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
-                \EEH_Debug_Tools::instance();
133
-            }
134
-            // load error handling
135
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
-                require_once EE_CORE . 'EE_Error.core.php';
137
-            } else {
138
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
-            }
140
-            $error_handling_loaded = true;
141
-        }
118
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
+		/**
120
+		 *    espresso_load_error_handling
121
+		 *    this function loads EE's class for handling exceptions and errors
122
+		 */
123
+		function espresso_load_error_handling()
124
+		{
125
+			static $error_handling_loaded = false;
126
+			if ($error_handling_loaded) {
127
+				return;
128
+			}
129
+			// load debugging tools
130
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
+				\EEH_Debug_Tools::instance();
133
+			}
134
+			// load error handling
135
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
+				require_once EE_CORE . 'EE_Error.core.php';
137
+			} else {
138
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
+			}
140
+			$error_handling_loaded = true;
141
+		}
142 142
 
143
-        /**
144
-         *    espresso_load_required
145
-         *    given a class name and path, this function will load that file or throw an exception
146
-         *
147
-         * @param    string $classname
148
-         * @param    string $full_path_to_file
149
-         * @throws    EE_Error
150
-         */
151
-        function espresso_load_required($classname, $full_path_to_file)
152
-        {
153
-            if (is_readable($full_path_to_file)) {
154
-                require_once $full_path_to_file;
155
-            } else {
156
-                throw new \EE_Error (
157
-                    sprintf(
158
-                        esc_html__(
159
-                            'The %s class file could not be located or is not readable due to file permissions.',
160
-                            'event_espresso'
161
-                        ),
162
-                        $classname
163
-                    )
164
-                );
165
-            }
166
-        }
143
+		/**
144
+		 *    espresso_load_required
145
+		 *    given a class name and path, this function will load that file or throw an exception
146
+		 *
147
+		 * @param    string $classname
148
+		 * @param    string $full_path_to_file
149
+		 * @throws    EE_Error
150
+		 */
151
+		function espresso_load_required($classname, $full_path_to_file)
152
+		{
153
+			if (is_readable($full_path_to_file)) {
154
+				require_once $full_path_to_file;
155
+			} else {
156
+				throw new \EE_Error (
157
+					sprintf(
158
+						esc_html__(
159
+							'The %s class file could not be located or is not readable due to file permissions.',
160
+							'event_espresso'
161
+						),
162
+						$classname
163
+					)
164
+				);
165
+			}
166
+		}
167 167
 
168
-        /**
169
-         * @since 4.9.27
170
-         * @throws \EE_Error
171
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
175
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
-         * @throws \OutOfBoundsException
179
-         */
180
-        function bootstrap_espresso()
181
-        {
182
-            require_once __DIR__ . '/core/espresso_definitions.php';
183
-            try {
184
-                espresso_load_error_handling();
185
-                espresso_load_required(
186
-                    'EEH_Base',
187
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
-                );
189
-                espresso_load_required(
190
-                    'EEH_File',
191
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
-                );
193
-                espresso_load_required(
194
-                    'EEH_File',
195
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
-                );
197
-                espresso_load_required(
198
-                    'EEH_Array',
199
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
-                );
201
-                // instantiate and configure PSR4 autoloader
202
-                espresso_load_required(
203
-                    'Psr4Autoloader',
204
-                    EE_CORE . 'Psr4Autoloader.php'
205
-                );
206
-                espresso_load_required(
207
-                    'EE_Psr4AutoloaderInit',
208
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
-                );
210
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
211
-                $AutoloaderInit->initializeAutoloader();
212
-                espresso_load_required(
213
-                    'EE_Request',
214
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
-                );
216
-                espresso_load_required(
217
-                    'EE_Response',
218
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
-                );
220
-                espresso_load_required(
221
-                    'EE_Bootstrap',
222
-                    EE_CORE . 'EE_Bootstrap.core.php'
223
-                );
224
-                // bootstrap EE and the request stack
225
-                new EE_Bootstrap(
226
-                    new EE_Request($_GET, $_POST, $_COOKIE),
227
-                    new EE_Response()
228
-                );
229
-            } catch (Exception $e) {
230
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
-            }
233
-        }
234
-        bootstrap_espresso();
235
-    }
168
+		/**
169
+		 * @since 4.9.27
170
+		 * @throws \EE_Error
171
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
175
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
+		 * @throws \OutOfBoundsException
179
+		 */
180
+		function bootstrap_espresso()
181
+		{
182
+			require_once __DIR__ . '/core/espresso_definitions.php';
183
+			try {
184
+				espresso_load_error_handling();
185
+				espresso_load_required(
186
+					'EEH_Base',
187
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
+				);
189
+				espresso_load_required(
190
+					'EEH_File',
191
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
+				);
193
+				espresso_load_required(
194
+					'EEH_File',
195
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
+				);
197
+				espresso_load_required(
198
+					'EEH_Array',
199
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
+				);
201
+				// instantiate and configure PSR4 autoloader
202
+				espresso_load_required(
203
+					'Psr4Autoloader',
204
+					EE_CORE . 'Psr4Autoloader.php'
205
+				);
206
+				espresso_load_required(
207
+					'EE_Psr4AutoloaderInit',
208
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
+				);
210
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
211
+				$AutoloaderInit->initializeAutoloader();
212
+				espresso_load_required(
213
+					'EE_Request',
214
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
+				);
216
+				espresso_load_required(
217
+					'EE_Response',
218
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
+				);
220
+				espresso_load_required(
221
+					'EE_Bootstrap',
222
+					EE_CORE . 'EE_Bootstrap.core.php'
223
+				);
224
+				// bootstrap EE and the request stack
225
+				new EE_Bootstrap(
226
+					new EE_Request($_GET, $_POST, $_COOKIE),
227
+					new EE_Response()
228
+				);
229
+			} catch (Exception $e) {
230
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
+			}
233
+		}
234
+		bootstrap_espresso();
235
+	}
236 236
 }
237 237
 if (! function_exists('espresso_deactivate_plugin')) {
238
-    /**
239
-     *    deactivate_plugin
240
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
-     *
242
-     * @access public
243
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
-     * @return    void
245
-     */
246
-    function espresso_deactivate_plugin($plugin_basename = '')
247
-    {
248
-        if (! function_exists('deactivate_plugins')) {
249
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
-        }
251
-        unset($_GET['activate'], $_REQUEST['activate']);
252
-        deactivate_plugins($plugin_basename);
253
-    }
238
+	/**
239
+	 *    deactivate_plugin
240
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
+	 *
242
+	 * @access public
243
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
+	 * @return    void
245
+	 */
246
+	function espresso_deactivate_plugin($plugin_basename = '')
247
+	{
248
+		if (! function_exists('deactivate_plugins')) {
249
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
+		}
251
+		unset($_GET['activate'], $_REQUEST['activate']);
252
+		deactivate_plugins($plugin_basename);
253
+	}
254 254
 }
Please login to merge, or discard this patch.
strategies/display/EE_Submit_Input_Display_Strategy.strategy.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -12,29 +12,29 @@
 block discarded – undo
12 12
 class EE_Submit_Input_Display_Strategy extends EE_Display_Strategy_Base
13 13
 {
14 14
 
15
-    /**
16
-     * @return string of html to display the input
17
-     */
18
-    public function display()
19
-    {
20
-        $default_value = $this->_input->get_default();
21
-        if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) {
22
-            $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value);
23
-        }
24
-        $html = $this->_opening_tag('input');
25
-        $html .= $this->_attributes_string(
26
-            array_merge(
27
-                $this->_standard_attributes_array(),
28
-                array(
29
-                    'type'  => 'submit',
30
-                    'value' => $default_value,
31
-                    //overwrite the standard id with the backwards compatible one
32
-                    'id' => $this->_input->html_id() . '-submit',
33
-                    'class' => $this->_input->html_class() . ' ' . $this->_input->button_css_attributes()
34
-                )
35
-            )
36
-        );
37
-        $html .= $this->_close_tag();
38
-        return $html;
15
+	/**
16
+	 * @return string of html to display the input
17
+	 */
18
+	public function display()
19
+	{
20
+		$default_value = $this->_input->get_default();
21
+		if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) {
22
+			$default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value);
23
+		}
24
+		$html = $this->_opening_tag('input');
25
+		$html .= $this->_attributes_string(
26
+			array_merge(
27
+				$this->_standard_attributes_array(),
28
+				array(
29
+					'type'  => 'submit',
30
+					'value' => $default_value,
31
+					//overwrite the standard id with the backwards compatible one
32
+					'id' => $this->_input->html_id() . '-submit',
33
+					'class' => $this->_input->html_class() . ' ' . $this->_input->button_css_attributes()
34
+				)
35
+			)
36
+		);
37
+		$html .= $this->_close_tag();
38
+		return $html;
39 39
 	}
40 40
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
                     'type'  => 'submit',
30 30
                     'value' => $default_value,
31 31
                     //overwrite the standard id with the backwards compatible one
32
-                    'id' => $this->_input->html_id() . '-submit',
33
-                    'class' => $this->_input->html_class() . ' ' . $this->_input->button_css_attributes()
32
+                    'id' => $this->_input->html_id().'-submit',
33
+                    'class' => $this->_input->html_class().' '.$this->_input->button_css_attributes()
34 34
                 )
35 35
             )
36 36
         );
Please login to merge, or discard this patch.