Completed
Branch FET-10768-extract-admin-bar (07b6f3)
by
unknown
127:29 queued 115:38
created
core/domain/entities/shortcodes/EspressoTicketSelector.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -21,63 +21,63 @@
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * the actual shortcode tag that gets registered with WordPress
26
-     *
27
-     * @return string
28
-     */
29
-    public function getTag()
30
-    {
31
-        return 'ESPRESSO_TICKET_SELECTOR';
32
-    }
33
-
34
-
35
-
36
-    /**
37
-     * the time in seconds to cache the results of the processShortcode() method
38
-     * 0 means the processShortcode() results will NOT be cached at all
39
-     *
40
-     * @return int
41
-     */
42
-    public function cacheExpiration()
43
-    {
44
-        return MINUTE_IN_SECONDS * 5;
45
-    }
46
-
47
-
48
-    /**
49
-     * a place for adding any initialization code that needs to run prior to wp_header().
50
-     * this may be required for shortcodes that utilize a corresponding module,
51
-     * and need to enqueue assets for that module
52
-     *
53
-     * @return void
54
-     */
55
-    public function initializeShortcode()
56
-    {
57
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
58
-        $this->shortcodeHasBeenInitialized();
59
-    }
60
-
61
-
62
-
63
-    /**
64
-     * callback that runs when the shortcode is encountered in post content.
65
-     * IMPORTANT !!!
66
-     * remember that shortcode content should be RETURNED and NOT echoed out
67
-     *
68
-     * @param array $attributes
69
-     * @return string
70
-     */
71
-    public function processShortcode($attributes = array())
72
-    {
73
-        extract($attributes, EXTR_OVERWRITE);
74
-        $event_id = isset($event_id) ? $event_id : 0;
75
-        $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
76
-        ob_start();
77
-        do_action('AHEE_event_details_before_post', $event_id);
78
-        espresso_ticket_selector($event);
79
-        do_action('AHEE_event_details_after_post');
80
-        return ob_get_clean();    }
24
+	/**
25
+	 * the actual shortcode tag that gets registered with WordPress
26
+	 *
27
+	 * @return string
28
+	 */
29
+	public function getTag()
30
+	{
31
+		return 'ESPRESSO_TICKET_SELECTOR';
32
+	}
33
+
34
+
35
+
36
+	/**
37
+	 * the time in seconds to cache the results of the processShortcode() method
38
+	 * 0 means the processShortcode() results will NOT be cached at all
39
+	 *
40
+	 * @return int
41
+	 */
42
+	public function cacheExpiration()
43
+	{
44
+		return MINUTE_IN_SECONDS * 5;
45
+	}
46
+
47
+
48
+	/**
49
+	 * a place for adding any initialization code that needs to run prior to wp_header().
50
+	 * this may be required for shortcodes that utilize a corresponding module,
51
+	 * and need to enqueue assets for that module
52
+	 *
53
+	 * @return void
54
+	 */
55
+	public function initializeShortcode()
56
+	{
57
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
58
+		$this->shortcodeHasBeenInitialized();
59
+	}
60
+
61
+
62
+
63
+	/**
64
+	 * callback that runs when the shortcode is encountered in post content.
65
+	 * IMPORTANT !!!
66
+	 * remember that shortcode content should be RETURNED and NOT echoed out
67
+	 *
68
+	 * @param array $attributes
69
+	 * @return string
70
+	 */
71
+	public function processShortcode($attributes = array())
72
+	{
73
+		extract($attributes, EXTR_OVERWRITE);
74
+		$event_id = isset($event_id) ? $event_id : 0;
75
+		$event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
76
+		ob_start();
77
+		do_action('AHEE_event_details_before_post', $event_id);
78
+		espresso_ticket_selector($event);
79
+		do_action('AHEE_event_details_after_post');
80
+		return ob_get_clean();    }
81 81
 }
82 82
 // End of file EspressoTicketSelector.php
83 83
 // Location: EventEspresso\core\domain\entities\shortcodes/EspressoTicketSelector.php
84 84
\ No newline at end of file
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoEventAttendees.php 1 patch
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -28,245 +28,245 @@
 block discarded – undo
28 28
 class EspressoEventAttendees extends EspressoShortcode
29 29
 {
30 30
 
31
-    private $query_params = array(
32
-        0 => array()
33
-    );
34
-
35
-    private $template_args = array(
36
-        'contacts'      => array(),
37
-        'event'         => null,
38
-        'datetime'      => null,
39
-        'ticket'        => null,
40
-    );
41
-
42
-    /**
43
-     * the actual shortcode tag that gets registered with WordPress
44
-     *
45
-     * @return string
46
-     */
47
-    public function getTag()
48
-    {
49
-        return 'ESPRESSO_EVENT_ATTENDEES';
50
-    }
51
-
52
-
53
-
54
-    /**
55
-     * the time in seconds to cache the results of the processShortcode() method
56
-     * 0 means the processShortcode() results will NOT be cached at all
57
-     *
58
-     * @return int
59
-     */
60
-    public function cacheExpiration()
61
-    {
62
-        return HOUR_IN_SECONDS;
63
-    }
64
-
65
-
66
-
67
-    /**
68
-     * a place for adding any initialization code that needs to run prior to wp_header().
69
-     * this may be required for shortcodes that utilize a corresponding module,
70
-     * and need to enqueue assets for that module
71
-     *
72
-     * @return void
73
-     */
74
-    public function initializeShortcode()
75
-    {
76
-        $this->shortcodeHasBeenInitialized();
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
83
-     *  [ESPRESSO_EVENT_ATTENDEES] - defaults to attendees for earliest active event, or earliest upcoming event.
84
-     *  [ESPRESSO_EVENT_ATTENDEES event_id=123] - attendees for specific event.
85
-     *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245] - attendees for a specific datetime.
86
-     *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123] - attendees for a specific ticket.
87
-     *  [ESPRESSO_EVENT_ATTENDEES status=all] - specific registration status (use status id) or all for all attendees
88
-     *                                          regardless of status.  Note default is to only return approved attendees
89
-     *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] - default is to not return gravatar.  Otherwise if this is set
90
-     *                                                  then return gravatar for email address given.
91
-     *  Note: because of the relationship between event_id, ticket_id, and datetime_id.
92
-     * If more than one of those params is included then preference is given to the following:
93
-     *  - event_id is used whenever its present and any others are ignored.
94
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
95
-     *  - otherwise ticket_id is used if present.
96
-     *
97
-     * @param array $attributes
98
-     * @return string
99
-     * @throws \EE_Error
100
-     */
101
-    public function processShortcode($attributes = array())
102
-    {
103
-        // grab attributes and merge with defaults
104
-        $attributes = $this->getAttributes((array)$attributes);
105
-        // add attributes to template args
106
-        $this->template_args['show_gravatar'] = $attributes['show_gravatar'];
107
-        // add required objects: event, datetime, and ticket
108
-        $this->template_args['event'] = $this->getEventAndQueryParams($attributes);
109
-        $this->template_args['datetime'] = $this->getDatetimeAndQueryParams($attributes);
110
-        $this->template_args['ticket'] = $this->getTicketAndQueryParams($attributes);
111
-
112
-        // if any of the above objects is invalid or missing,
113
-        // then there was an invalid parameter or the shortcode was used incorrectly
114
-        // so when WP_DEBUG is set and true, we'll show a message,
115
-        // otherwise we'll just return an empty string.
116
-         if (
117
-            ! $this->template_args['event'] instanceof EE_Event
118
-            || empty($this->query_params[0])
119
-            || ($attributes['datetime_id'] && ! $this->template_args['datetime'] instanceof EE_Datetime)
120
-            || ($attributes['ticket_id'] && ! $this->template_args['ticket'] instanceof EE_Ticket)
121
-        ) {
122
-            if (WP_DEBUG) {
123
-                return '<div class="important-notice ee-attention">'
124
-                       . esc_html__('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
125
-                        'event_espresso')
126
-                       . '</div>';
127
-            } else {
128
-                return '';
129
-            }
130
-        }
131
-        $this->setAdditionalQueryParams($attributes);
132
-        //get contacts!
133
-        $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
134
-        //all set let's load up the template and return.
135
-        return EEH_Template::locate_template('loop-espresso_event_attendees.php', $this->template_args, true, true);
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * merge incoming attributes with filtered defaults
142
-     *
143
-     * @param array $attributes
144
-     * @return array
145
-     */
146
-    private function getAttributes(array $attributes)
147
-    {
148
-        return array_merge(
149
-            (array) apply_filters(
150
-                'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
151
-                array(
152
-                    'event_id'      => null,
153
-                    'datetime_id'   => null,
154
-                    'ticket_id'     => null,
155
-                    'status'        => EEM_Registration::status_id_approved,
156
-                    'show_gravatar' => false
157
-                )
158
-            ),
159
-            $attributes
160
-        );
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * @param array $attributes
167
-     * @return EE_Event|null
168
-     * @throws \EE_Error
169
-     */
170
-    private function getEventAndQueryParams(array $attributes){
171
-        if ( ! empty($attributes['event_id'])) {
172
-            $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
173
-            if ($event instanceof EE_Event) {
174
-                $this->query_params[0]['Registration.EVT_ID'] = $attributes['event_id'];
175
-                return $event;
176
-            }
177
-        }
178
-        //seems like is_espresso_event_single() isn't working as expected. So using alternate method.
179
-        if (is_single() && is_espresso_event()) {
180
-            $event = EEH_Event_View::get_event();
181
-            if ($event instanceof EE_Event) {
182
-                $this->query_params[0]['Registration.EVT_ID'] = $event->ID();
183
-                return $event;
184
-            }
185
-        }
186
-        // one last shot...
187
-        // try getting the earliest active event
188
-        $events = EEM_Event::instance()->get_active_events(array(
189
-            'limit'    => 1,
190
-            'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
191
-        ));
192
-        //  if none then get the next upcoming
193
-        $events = empty($events)
194
-            ? EEM_Event::instance()->get_upcoming_events(array(
195
-                'limit'    => 1,
196
-                'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
197
-            ))
198
-            : $events;
199
-        $event = reset($events);
200
-        if ($event instanceof EE_Event) {
201
-            $this->query_params[0]['Registration.EVT_ID'] = $event->ID();
202
-            return $event;
203
-        }
204
-        return null;
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * @param array $attributes
211
-     * @return EE_Datetime|null
212
-     */
213
-    private function getDatetimeAndQueryParams(array $attributes)
214
-    {
215
-        if ( ! empty($attributes['datetime_id'])) {
216
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
217
-            if ($datetime instanceof EE_Datetime) {
218
-                $this->query_params[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id'];
219
-                $this->query_params['default_where_conditions'] = 'this_model_only';
220
-                if ( ! $this->template_args['event'] instanceof EE_Event) {
221
-                    $this->template_args['event'] = $datetime->event();
222
-                }
223
-                return $datetime;
224
-            }
225
-        }
226
-        return null;
227
-    }
228
-
229
-
230
-
231
-    /**
232
-     * @param array $attributes
233
-     * @return \EE_Base_Class|null
234
-     * @throws \EE_Error
235
-     */
236
-    private function getTicketAndQueryParams(array $attributes)
237
-    {
238
-        if ( ! empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) {
239
-            $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
240
-            if ($ticket instanceof EE_Ticket) {
241
-                $this->query_params[0]['Registration.TKT_ID'] = $attributes['ticket_id'];
242
-                if ( ! $this->template_args['event'] instanceof EE_Event) {
243
-                    $this->template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime
244
-                        ? $ticket->first_datetime()->event()
245
-                        : null;
246
-                }
247
-                return $ticket;
248
-            }
249
-        }
250
-        return null;
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * @param array $attributes
257
-     */
258
-    private function setAdditionalQueryParams(array $attributes)
259
-    {
260
-        $reg_status_array = EEM_Registration::reg_status_array();
261
-        if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) {
262
-            $this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
263
-        }
264
-        $this->query_params['group_by'] = array('ATT_ID');
265
-        $this->query_params['order_by'] = (array) apply_filters(
266
-            'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
267
-            array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
268
-        );
269
-    }
31
+	private $query_params = array(
32
+		0 => array()
33
+	);
34
+
35
+	private $template_args = array(
36
+		'contacts'      => array(),
37
+		'event'         => null,
38
+		'datetime'      => null,
39
+		'ticket'        => null,
40
+	);
41
+
42
+	/**
43
+	 * the actual shortcode tag that gets registered with WordPress
44
+	 *
45
+	 * @return string
46
+	 */
47
+	public function getTag()
48
+	{
49
+		return 'ESPRESSO_EVENT_ATTENDEES';
50
+	}
51
+
52
+
53
+
54
+	/**
55
+	 * the time in seconds to cache the results of the processShortcode() method
56
+	 * 0 means the processShortcode() results will NOT be cached at all
57
+	 *
58
+	 * @return int
59
+	 */
60
+	public function cacheExpiration()
61
+	{
62
+		return HOUR_IN_SECONDS;
63
+	}
64
+
65
+
66
+
67
+	/**
68
+	 * a place for adding any initialization code that needs to run prior to wp_header().
69
+	 * this may be required for shortcodes that utilize a corresponding module,
70
+	 * and need to enqueue assets for that module
71
+	 *
72
+	 * @return void
73
+	 */
74
+	public function initializeShortcode()
75
+	{
76
+		$this->shortcodeHasBeenInitialized();
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
83
+	 *  [ESPRESSO_EVENT_ATTENDEES] - defaults to attendees for earliest active event, or earliest upcoming event.
84
+	 *  [ESPRESSO_EVENT_ATTENDEES event_id=123] - attendees for specific event.
85
+	 *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245] - attendees for a specific datetime.
86
+	 *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123] - attendees for a specific ticket.
87
+	 *  [ESPRESSO_EVENT_ATTENDEES status=all] - specific registration status (use status id) or all for all attendees
88
+	 *                                          regardless of status.  Note default is to only return approved attendees
89
+	 *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] - default is to not return gravatar.  Otherwise if this is set
90
+	 *                                                  then return gravatar for email address given.
91
+	 *  Note: because of the relationship between event_id, ticket_id, and datetime_id.
92
+	 * If more than one of those params is included then preference is given to the following:
93
+	 *  - event_id is used whenever its present and any others are ignored.
94
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
95
+	 *  - otherwise ticket_id is used if present.
96
+	 *
97
+	 * @param array $attributes
98
+	 * @return string
99
+	 * @throws \EE_Error
100
+	 */
101
+	public function processShortcode($attributes = array())
102
+	{
103
+		// grab attributes and merge with defaults
104
+		$attributes = $this->getAttributes((array)$attributes);
105
+		// add attributes to template args
106
+		$this->template_args['show_gravatar'] = $attributes['show_gravatar'];
107
+		// add required objects: event, datetime, and ticket
108
+		$this->template_args['event'] = $this->getEventAndQueryParams($attributes);
109
+		$this->template_args['datetime'] = $this->getDatetimeAndQueryParams($attributes);
110
+		$this->template_args['ticket'] = $this->getTicketAndQueryParams($attributes);
111
+
112
+		// if any of the above objects is invalid or missing,
113
+		// then there was an invalid parameter or the shortcode was used incorrectly
114
+		// so when WP_DEBUG is set and true, we'll show a message,
115
+		// otherwise we'll just return an empty string.
116
+		 if (
117
+			! $this->template_args['event'] instanceof EE_Event
118
+			|| empty($this->query_params[0])
119
+			|| ($attributes['datetime_id'] && ! $this->template_args['datetime'] instanceof EE_Datetime)
120
+			|| ($attributes['ticket_id'] && ! $this->template_args['ticket'] instanceof EE_Ticket)
121
+		) {
122
+			if (WP_DEBUG) {
123
+				return '<div class="important-notice ee-attention">'
124
+					   . esc_html__('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
125
+						'event_espresso')
126
+					   . '</div>';
127
+			} else {
128
+				return '';
129
+			}
130
+		}
131
+		$this->setAdditionalQueryParams($attributes);
132
+		//get contacts!
133
+		$this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
134
+		//all set let's load up the template and return.
135
+		return EEH_Template::locate_template('loop-espresso_event_attendees.php', $this->template_args, true, true);
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * merge incoming attributes with filtered defaults
142
+	 *
143
+	 * @param array $attributes
144
+	 * @return array
145
+	 */
146
+	private function getAttributes(array $attributes)
147
+	{
148
+		return array_merge(
149
+			(array) apply_filters(
150
+				'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
151
+				array(
152
+					'event_id'      => null,
153
+					'datetime_id'   => null,
154
+					'ticket_id'     => null,
155
+					'status'        => EEM_Registration::status_id_approved,
156
+					'show_gravatar' => false
157
+				)
158
+			),
159
+			$attributes
160
+		);
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * @param array $attributes
167
+	 * @return EE_Event|null
168
+	 * @throws \EE_Error
169
+	 */
170
+	private function getEventAndQueryParams(array $attributes){
171
+		if ( ! empty($attributes['event_id'])) {
172
+			$event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
173
+			if ($event instanceof EE_Event) {
174
+				$this->query_params[0]['Registration.EVT_ID'] = $attributes['event_id'];
175
+				return $event;
176
+			}
177
+		}
178
+		//seems like is_espresso_event_single() isn't working as expected. So using alternate method.
179
+		if (is_single() && is_espresso_event()) {
180
+			$event = EEH_Event_View::get_event();
181
+			if ($event instanceof EE_Event) {
182
+				$this->query_params[0]['Registration.EVT_ID'] = $event->ID();
183
+				return $event;
184
+			}
185
+		}
186
+		// one last shot...
187
+		// try getting the earliest active event
188
+		$events = EEM_Event::instance()->get_active_events(array(
189
+			'limit'    => 1,
190
+			'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
191
+		));
192
+		//  if none then get the next upcoming
193
+		$events = empty($events)
194
+			? EEM_Event::instance()->get_upcoming_events(array(
195
+				'limit'    => 1,
196
+				'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
197
+			))
198
+			: $events;
199
+		$event = reset($events);
200
+		if ($event instanceof EE_Event) {
201
+			$this->query_params[0]['Registration.EVT_ID'] = $event->ID();
202
+			return $event;
203
+		}
204
+		return null;
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * @param array $attributes
211
+	 * @return EE_Datetime|null
212
+	 */
213
+	private function getDatetimeAndQueryParams(array $attributes)
214
+	{
215
+		if ( ! empty($attributes['datetime_id'])) {
216
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
217
+			if ($datetime instanceof EE_Datetime) {
218
+				$this->query_params[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id'];
219
+				$this->query_params['default_where_conditions'] = 'this_model_only';
220
+				if ( ! $this->template_args['event'] instanceof EE_Event) {
221
+					$this->template_args['event'] = $datetime->event();
222
+				}
223
+				return $datetime;
224
+			}
225
+		}
226
+		return null;
227
+	}
228
+
229
+
230
+
231
+	/**
232
+	 * @param array $attributes
233
+	 * @return \EE_Base_Class|null
234
+	 * @throws \EE_Error
235
+	 */
236
+	private function getTicketAndQueryParams(array $attributes)
237
+	{
238
+		if ( ! empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) {
239
+			$ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
240
+			if ($ticket instanceof EE_Ticket) {
241
+				$this->query_params[0]['Registration.TKT_ID'] = $attributes['ticket_id'];
242
+				if ( ! $this->template_args['event'] instanceof EE_Event) {
243
+					$this->template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime
244
+						? $ticket->first_datetime()->event()
245
+						: null;
246
+				}
247
+				return $ticket;
248
+			}
249
+		}
250
+		return null;
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * @param array $attributes
257
+	 */
258
+	private function setAdditionalQueryParams(array $attributes)
259
+	{
260
+		$reg_status_array = EEM_Registration::reg_status_array();
261
+		if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) {
262
+			$this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
263
+		}
264
+		$this->query_params['group_by'] = array('ATT_ID');
265
+		$this->query_params['order_by'] = (array) apply_filters(
266
+			'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
267
+			array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
268
+		);
269
+	}
270 270
 
271 271
 
272 272
 
Please login to merge, or discard this patch.
core/services/shortcodes/ShortcodeInterface.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -8,44 +8,44 @@
 block discarded – undo
8 8
 interface ShortcodeInterface
9 9
 {
10 10
 
11
-    /**
12
-     * the actual shortcode tag that gets registered with WordPress
13
-     *
14
-     * @return string
15
-     */
16
-    public function getTag();
17
-
18
-    /**
19
-     * the length of time in seconds to cache the results of the processShortcode() method
20
-     * 0 means the processShortcode() results will NOT be cached at all
21
-     *
22
-     * @return int
23
-     */
24
-    public function cacheExpiration();
25
-
26
-    /**
27
-     * a place for adding any initialization code that needs to run prior to wp_header().
28
-     * this may be required for shortcodes that utilize a corresponding module,
29
-     * and need to enqueue assets for that module
30
-     *
31
-     * !!! IMPORTANT !!!
32
-     * After performing any logic within this method required for initialization
33
-     *         $this->shortcodeHasBeenInitialized();
34
-     * should be called to ensure that the shortcode is setup correctly.
35
-     *
36
-     * @return void
37
-     */
38
-    public function initializeShortcode();
39
-
40
-    /**
41
-     * callback that runs when the shortcode is encountered in post content.
42
-     * IMPORTANT !!!
43
-     * remember that shortcode content should be RETURNED and NOT echoed out
44
-     *
45
-     * @param array $attributes
46
-     * @return string
47
-     */
48
-    public function processShortcode($attributes = array());
11
+	/**
12
+	 * the actual shortcode tag that gets registered with WordPress
13
+	 *
14
+	 * @return string
15
+	 */
16
+	public function getTag();
17
+
18
+	/**
19
+	 * the length of time in seconds to cache the results of the processShortcode() method
20
+	 * 0 means the processShortcode() results will NOT be cached at all
21
+	 *
22
+	 * @return int
23
+	 */
24
+	public function cacheExpiration();
25
+
26
+	/**
27
+	 * a place for adding any initialization code that needs to run prior to wp_header().
28
+	 * this may be required for shortcodes that utilize a corresponding module,
29
+	 * and need to enqueue assets for that module
30
+	 *
31
+	 * !!! IMPORTANT !!!
32
+	 * After performing any logic within this method required for initialization
33
+	 *         $this->shortcodeHasBeenInitialized();
34
+	 * should be called to ensure that the shortcode is setup correctly.
35
+	 *
36
+	 * @return void
37
+	 */
38
+	public function initializeShortcode();
39
+
40
+	/**
41
+	 * callback that runs when the shortcode is encountered in post content.
42
+	 * IMPORTANT !!!
43
+	 * remember that shortcode content should be RETURNED and NOT echoed out
44
+	 *
45
+	 * @param array $attributes
46
+	 * @return string
47
+	 */
48
+	public function processShortcode($attributes = array());
49 49
 
50 50
 }
51 51
 // End of file ShortcodeInterface.php
Please login to merge, or discard this patch.
core/services/shortcodes/EspressoShortcode.php 2 patches
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -20,219 +20,219 @@
 block discarded – undo
20 20
 abstract class EspressoShortcode implements ShortcodeInterface
21 21
 {
22 22
 
23
-    /**
24
-     * transient prefix
25
-     *
26
-     * @type string
27
-     */
28
-    const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
29
-
30
-    /**
31
-     * @var PostRelatedCacheManager $cache_manager
32
-     */
33
-    private $cache_manager;
34
-
35
-    /**
36
-     * true if ShortcodeInterface::initializeShortcode() has been called
37
-     * if false, then that will get called before processing
38
-     *
39
-     * @var boolean $initialized
40
-     */
41
-    private $initialized = false;
42
-
43
-
44
-
45
-    /**
46
-     * EspressoShortcode constructor
47
-     *
48
-     * @param PostRelatedCacheManager $cache_manager
49
-     */
50
-    public function __construct(PostRelatedCacheManager $cache_manager)
51
-    {
52
-        $this->cache_manager = $cache_manager;
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * @return void
59
-     */
60
-    public function shortcodeHasBeenInitialized()
61
-    {
62
-        $this->initialized = true;
63
-    }
64
-
65
-
66
-
67
-    /**
68
-     * enqueues scripts then processes the shortcode
69
-     *
70
-     * @param array $attributes
71
-     * @return string
72
-     * @throws \EE_Error
73
-     */
74
-    final public function processShortcodeCallback($attributes = array())
75
-    {
76
-        if ($this instanceof EnqueueAssetsInterface) {
77
-            if (is_admin()) {
78
-                $this->enqueueAdminScripts();
79
-            } else {
80
-                $this->enqueueScripts();
81
-            }
82
-        }
83
-        return $this->shortcodeContent(
84
-            $this->sanitizeAttributes((array)$attributes)
85
-        );
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * If shortcode caching is enabled for the shortcode,
92
-     * and cached results exist, then that will be returned
93
-     * else new content will be generated.
94
-     * If caching is enabled, then the new content will be cached for later.
95
-     *
96
-     * @param array $attributes
97
-     * @return mixed|string
98
-     * @throws \EE_Error
99
-     */
100
-    private function shortcodeContent(array $attributes)
101
-    {
102
-        $shortcode = $this;
103
-        $post_ID = $this->currentPostID();
104
-        // something like "SC_EVENTS-123"
105
-        $cache_ID = $this->shortcodeCacheID($post_ID);
106
-        $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
107
-        return $this->cache_manager->get(
108
-            $cache_ID,
109
-            // serialized attributes
110
-            wp_json_encode($attributes),
111
-            // Closure for generating content if cache is expired
112
-            function () use ($shortcode, $attributes) {
113
-                if($shortcode->initialized === false){
114
-                    $shortcode->initializeShortcode();
115
-                }
116
-                return $shortcode->processShortcode($attributes);
117
-            },
118
-            // filterable cache expiration set by each shortcode
119
-            apply_filters(
120
-                'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
121
-                $this->cacheExpiration(),
122
-                $this->getTag(),
123
-                $this
124
-            )
125
-        );
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * @return int
132
-     * @throws \EE_Error
133
-     */
134
-    private function currentPostID()
135
-    {
136
-        // try to get EE_Event any way we can
137
-        $event = EEH_Event_View::get_event();
138
-        // then get some kind of ID
139
-        if ($event instanceof \EE_Event) {
140
-            $post_ID = $event->ID();
141
-        } else {
142
-            global $post;
143
-            $post_ID = $post->ID;
144
-        }
145
-        return $post_ID;
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * @param int $post_ID
152
-     * @return string
153
-     * @throws \EE_Error
154
-     */
155
-    private function shortcodeCacheID($post_ID)
156
-    {
157
-        $tag = str_replace('ESPRESSO_', '', $this->getTag());
158
-        return "SC_{$tag}-{$post_ID}";
159
-    }
160
-
161
-
162
-
163
-    /**
164
-     * array for defining custom attribute sanitization callbacks,
165
-     * where keys match keys in your attributes array,
166
-     * and values represent the sanitization function you wish to be applied to that attribute.
167
-     * So for example, if you had an integer attribute named "event_id"
168
-     * that you wanted to be sanitized using absint(),
169
-     * then you would return the following:
170
-     *      array('event_id' => 'absint')
171
-     * Entering 'skip_sanitization' for the callback value
172
-     * means that no sanitization will be applied
173
-     * on the assumption that the attribute
174
-     * will be sanitized at some point... right?
175
-     * You wouldn't pass around unsanitized attributes would you?
176
-     * That would be very Tom Foolery of you!!!
177
-     *
178
-     * @return array
179
-     */
180
-    protected function customAttributeSanitizationMap()
181
-    {
182
-        return array();
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Performs basic sanitization on shortcode attributes
189
-     * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
190
-     * most attributes will by default be sanitized using the sanitize_text_field() function.
191
-     * This can be overridden using the customAttributeSanitizationMap() method (see above),
192
-     * all other attributes would be sanitized using the defaults in the switch statement below
193
-     *
194
-     * @param array $attributes
195
-     * @return array
196
-     */
197
-    private function sanitizeAttributes(array $attributes)
198
-    {
199
-        $custom_sanitization = $this->customAttributeSanitizationMap();
200
-        foreach ($attributes as $key => $value) {
201
-            // is a custom sanitization callback specified ?
202
-            if (isset($custom_sanitization[$key])) {
203
-                $callback = $custom_sanitization[$key];
204
-                if ($callback === 'skip_sanitization') {
205
-                    $attributes[$key] = $value;
206
-                    continue;
207
-                }
208
-                if (function_exists($callback)) {
209
-                    $attributes[$key] = $callback($value);
210
-                    continue;
211
-                }
212
-            }
213
-            switch (true) {
214
-                case $value === null :
215
-                case is_int($value) :
216
-                case is_float($value) :
217
-                    // typical booleans
218
-                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
219
-                    $attributes[$key] = $value;
220
-                    break;
221
-                case is_string($value) :
222
-                    $attributes[$key] = sanitize_text_field($value);
223
-                    break;
224
-                case is_array($value) :
225
-                    $attributes[$key] = $this->sanitizeAttributes($value);
226
-                    break;
227
-                default :
228
-                    // only remaining data types are Object and Resource
229
-                    // which are not allowed as shortcode attributes
230
-                    $attributes[$key] = null;
231
-                    break;
232
-            }
233
-        }
234
-        return $attributes;
235
-    }
23
+	/**
24
+	 * transient prefix
25
+	 *
26
+	 * @type string
27
+	 */
28
+	const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
29
+
30
+	/**
31
+	 * @var PostRelatedCacheManager $cache_manager
32
+	 */
33
+	private $cache_manager;
34
+
35
+	/**
36
+	 * true if ShortcodeInterface::initializeShortcode() has been called
37
+	 * if false, then that will get called before processing
38
+	 *
39
+	 * @var boolean $initialized
40
+	 */
41
+	private $initialized = false;
42
+
43
+
44
+
45
+	/**
46
+	 * EspressoShortcode constructor
47
+	 *
48
+	 * @param PostRelatedCacheManager $cache_manager
49
+	 */
50
+	public function __construct(PostRelatedCacheManager $cache_manager)
51
+	{
52
+		$this->cache_manager = $cache_manager;
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * @return void
59
+	 */
60
+	public function shortcodeHasBeenInitialized()
61
+	{
62
+		$this->initialized = true;
63
+	}
64
+
65
+
66
+
67
+	/**
68
+	 * enqueues scripts then processes the shortcode
69
+	 *
70
+	 * @param array $attributes
71
+	 * @return string
72
+	 * @throws \EE_Error
73
+	 */
74
+	final public function processShortcodeCallback($attributes = array())
75
+	{
76
+		if ($this instanceof EnqueueAssetsInterface) {
77
+			if (is_admin()) {
78
+				$this->enqueueAdminScripts();
79
+			} else {
80
+				$this->enqueueScripts();
81
+			}
82
+		}
83
+		return $this->shortcodeContent(
84
+			$this->sanitizeAttributes((array)$attributes)
85
+		);
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * If shortcode caching is enabled for the shortcode,
92
+	 * and cached results exist, then that will be returned
93
+	 * else new content will be generated.
94
+	 * If caching is enabled, then the new content will be cached for later.
95
+	 *
96
+	 * @param array $attributes
97
+	 * @return mixed|string
98
+	 * @throws \EE_Error
99
+	 */
100
+	private function shortcodeContent(array $attributes)
101
+	{
102
+		$shortcode = $this;
103
+		$post_ID = $this->currentPostID();
104
+		// something like "SC_EVENTS-123"
105
+		$cache_ID = $this->shortcodeCacheID($post_ID);
106
+		$this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
107
+		return $this->cache_manager->get(
108
+			$cache_ID,
109
+			// serialized attributes
110
+			wp_json_encode($attributes),
111
+			// Closure for generating content if cache is expired
112
+			function () use ($shortcode, $attributes) {
113
+				if($shortcode->initialized === false){
114
+					$shortcode->initializeShortcode();
115
+				}
116
+				return $shortcode->processShortcode($attributes);
117
+			},
118
+			// filterable cache expiration set by each shortcode
119
+			apply_filters(
120
+				'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
121
+				$this->cacheExpiration(),
122
+				$this->getTag(),
123
+				$this
124
+			)
125
+		);
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * @return int
132
+	 * @throws \EE_Error
133
+	 */
134
+	private function currentPostID()
135
+	{
136
+		// try to get EE_Event any way we can
137
+		$event = EEH_Event_View::get_event();
138
+		// then get some kind of ID
139
+		if ($event instanceof \EE_Event) {
140
+			$post_ID = $event->ID();
141
+		} else {
142
+			global $post;
143
+			$post_ID = $post->ID;
144
+		}
145
+		return $post_ID;
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * @param int $post_ID
152
+	 * @return string
153
+	 * @throws \EE_Error
154
+	 */
155
+	private function shortcodeCacheID($post_ID)
156
+	{
157
+		$tag = str_replace('ESPRESSO_', '', $this->getTag());
158
+		return "SC_{$tag}-{$post_ID}";
159
+	}
160
+
161
+
162
+
163
+	/**
164
+	 * array for defining custom attribute sanitization callbacks,
165
+	 * where keys match keys in your attributes array,
166
+	 * and values represent the sanitization function you wish to be applied to that attribute.
167
+	 * So for example, if you had an integer attribute named "event_id"
168
+	 * that you wanted to be sanitized using absint(),
169
+	 * then you would return the following:
170
+	 *      array('event_id' => 'absint')
171
+	 * Entering 'skip_sanitization' for the callback value
172
+	 * means that no sanitization will be applied
173
+	 * on the assumption that the attribute
174
+	 * will be sanitized at some point... right?
175
+	 * You wouldn't pass around unsanitized attributes would you?
176
+	 * That would be very Tom Foolery of you!!!
177
+	 *
178
+	 * @return array
179
+	 */
180
+	protected function customAttributeSanitizationMap()
181
+	{
182
+		return array();
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * Performs basic sanitization on shortcode attributes
189
+	 * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
190
+	 * most attributes will by default be sanitized using the sanitize_text_field() function.
191
+	 * This can be overridden using the customAttributeSanitizationMap() method (see above),
192
+	 * all other attributes would be sanitized using the defaults in the switch statement below
193
+	 *
194
+	 * @param array $attributes
195
+	 * @return array
196
+	 */
197
+	private function sanitizeAttributes(array $attributes)
198
+	{
199
+		$custom_sanitization = $this->customAttributeSanitizationMap();
200
+		foreach ($attributes as $key => $value) {
201
+			// is a custom sanitization callback specified ?
202
+			if (isset($custom_sanitization[$key])) {
203
+				$callback = $custom_sanitization[$key];
204
+				if ($callback === 'skip_sanitization') {
205
+					$attributes[$key] = $value;
206
+					continue;
207
+				}
208
+				if (function_exists($callback)) {
209
+					$attributes[$key] = $callback($value);
210
+					continue;
211
+				}
212
+			}
213
+			switch (true) {
214
+				case $value === null :
215
+				case is_int($value) :
216
+				case is_float($value) :
217
+					// typical booleans
218
+				case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
219
+					$attributes[$key] = $value;
220
+					break;
221
+				case is_string($value) :
222
+					$attributes[$key] = sanitize_text_field($value);
223
+					break;
224
+				case is_array($value) :
225
+					$attributes[$key] = $this->sanitizeAttributes($value);
226
+					break;
227
+				default :
228
+					// only remaining data types are Object and Resource
229
+					// which are not allowed as shortcode attributes
230
+					$attributes[$key] = null;
231
+					break;
232
+			}
233
+		}
234
+		return $attributes;
235
+	}
236 236
 
237 237
 
238 238
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
             }
82 82
         }
83 83
         return $this->shortcodeContent(
84
-            $this->sanitizeAttributes((array)$attributes)
84
+            $this->sanitizeAttributes((array) $attributes)
85 85
         );
86 86
     }
87 87
 
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
             // serialized attributes
110 110
             wp_json_encode($attributes),
111 111
             // Closure for generating content if cache is expired
112
-            function () use ($shortcode, $attributes) {
113
-                if($shortcode->initialized === false){
112
+            function() use ($shortcode, $attributes) {
113
+                if ($shortcode->initialized === false) {
114 114
                     $shortcode->initializeShortcode();
115 115
                 }
116 116
                 return $shortcode->processShortcode($attributes);
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php 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
-                ); ?>
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
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    '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.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'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.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.40.rc.009');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.40.rc.009');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.
core/domain/services/admin/AdminToolBar.php 1 patch
Indentation   +799 added lines, -799 removed lines patch added patch discarded remove patch
@@ -22,804 +22,804 @@
 block discarded – undo
22 22
 class AdminToolBar
23 23
 {
24 24
 
25
-    /**
26
-     * @var WP_Admin_Bar $admin_bar
27
-     */
28
-    private $admin_bar;
29
-
30
-    /**
31
-     * @var EE_Capabilities $capabilities
32
-     */
33
-    private $capabilities;
34
-
35
-    /**
36
-     * @var string $events_admin_url
37
-     */
38
-    private $events_admin_url;
39
-
40
-    /**
41
-     * @var string $menu_class
42
-     */
43
-    private $menu_class = 'espresso_menu_item_class';
44
-
45
-    /**
46
-     * @var string $reg_admin_url
47
-     */
48
-    private $reg_admin_url;
49
-
50
-
51
-
52
-    /**
53
-     * AdminToolBar constructor.
54
-     *
55
-     * @param EE_Capabilities $capabilities
56
-     */
57
-    public function __construct(EE_Capabilities $capabilities)
58
-    {
59
-        $this->capabilities = $capabilities;
60
-        add_action('admin_bar_menu', array($this, 'espressoToolbarItems'), 100);
61
-        $this->enqueueAssets();
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     *    espresso_toolbar_items
68
-     *
69
-     * @access public
70
-     * @param  WP_Admin_Bar $admin_bar
71
-     * @return void
72
-     */
73
-    public function espressoToolbarItems(WP_Admin_Bar $admin_bar)
74
-    {
75
-        // if its an AJAX request, or user is NOT an admin, or in full M-Mode
76
-        if (
77
-            defined('DOING_AJAX')
78
-            || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
79
-            || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
80
-        ) {
81
-            return;
82
-        }
83
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
84
-        $this->admin_bar = $admin_bar;
85
-        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
86
-        //because they're only defined in each of their respective constructors
87
-        //and this might be a frontend request, in which case they aren't available
88
-        $this->events_admin_url = admin_url('admin.php?page=espresso_events');
89
-        $this->reg_admin_url = admin_url('admin.php?page=espresso_registrations');
90
-        // now let's add all of the menu items
91
-        $this->addTopLevelMenu();
92
-        $this->addEventsSubMenu();
93
-        $this->addEventsAddEditHeader();
94
-        $this->addEventsAddNew();
95
-        $this->addEventsEditCurrentEvent();
96
-        $this->addEventsViewHeader();
97
-        $this->addEventsViewAll();
98
-        $this->addEventsViewToday();
99
-        $this->addEventsViewThisMonth();
100
-        $this->addRegistrationSubMenu();
101
-        $this->addRegistrationOverviewToday();
102
-        $this->addRegistrationOverviewTodayApproved();
103
-        $this->addRegistrationOverviewTodayPendingPayment();
104
-        $this->addRegistrationOverviewTodayNotApproved();
105
-        $this->addRegistrationOverviewTodayCancelled();
106
-        $this->addRegistrationOverviewThisMonth();
107
-        $this->addRegistrationOverviewThisMonthApproved();
108
-        $this->addRegistrationOverviewThisMonthPending();
109
-        $this->addRegistrationOverviewThisMonthNotApproved();
110
-        $this->addRegistrationOverviewThisMonthCancelled();
111
-        $this->addExtensionsAndServices();
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * @return void
118
-     */
119
-    private function enqueueAssets()
120
-    {
121
-        wp_register_style(
122
-            'espresso-admin-toolbar',
123
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css',
124
-            array('dashicons'),
125
-            EVENT_ESPRESSO_VERSION
126
-        );
127
-        wp_enqueue_style('espresso-admin-toolbar');
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return void
134
-     */
135
-    private function addTopLevelMenu()
136
-    {
137
-        $this->admin_bar->add_menu(
138
-            array(
139
-                'id'    => 'espresso-toolbar',
140
-                'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
141
-                    . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso')
142
-                    . '</span>',
143
-                'href'  => $this->events_admin_url,
144
-                'meta'  => array(
145
-                    'title' => esc_html__('Event Espresso', 'event_espresso'),
146
-                    'class' => $this->menu_class . 'first',
147
-                ),
148
-            )
149
-        );
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * @return void
156
-     */
157
-    private function addEventsSubMenu()
158
-    {
159
-        if (
160
-            $this->capabilities->current_user_can(
161
-                'ee_read_events',
162
-                'ee_admin_bar_menu_espresso-toolbar-events'
163
-            )
164
-        ) {
165
-            $this->admin_bar->add_menu(
166
-                array(
167
-                    'id'     => 'espresso-toolbar-events',
168
-                    'parent' => 'espresso-toolbar',
169
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
170
-                                . esc_html__('Events', 'event_espresso'),
171
-                    'href'   => $this->events_admin_url,
172
-                    'meta'   => array(
173
-                        'title'  => esc_html__('Events', 'event_espresso'),
174
-                        'target' => '',
175
-                        'class'  => $this->menu_class,
176
-                    ),
177
-                )
178
-            );
179
-        }
180
-    }
181
-
182
-
183
-
184
-    /**
185
-     * @return void
186
-     */
187
-    private function addEventsAddEditHeader()
188
-    {
189
-        if (
190
-        $this->capabilities->current_user_can(
191
-            'ee_read_events',
192
-            'ee_admin_bar_menu_espresso-toolbar-events-view'
193
-        )
194
-        ) {
195
-            $this->admin_bar->add_menu(
196
-                array(
197
-                    'id'     => 'espresso-toolbar-events-add-edit',
198
-                    'parent' => 'espresso-toolbar-events',
199
-                    'title'  => esc_html__('Add / Edit', 'event_espresso'),
200
-                    'href'   => '',
201
-                )
202
-            );
203
-        }
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * @return void
210
-     */
211
-    private function addEventsAddNew()
212
-    {
213
-        if (
214
-            $this->capabilities->current_user_can(
215
-                'ee_edit_events',
216
-                'ee_admin_bar_menu_espresso-toolbar-events-new'
217
-            )
218
-        ) {
219
-            $this->admin_bar->add_menu(
220
-                array(
221
-                    'id'     => 'espresso-toolbar-events-new',
222
-                    'parent' => 'espresso-toolbar-events',
223
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
224
-                                . esc_html__('Add New', 'event_espresso'),
225
-                    'href'   => EEH_URL::add_query_args_and_nonce(
226
-                        array('action' => 'create_new'),
227
-                        $this->events_admin_url
228
-                    ),
229
-                    'meta'   => array(
230
-                        'title'  => esc_html__('Add New', 'event_espresso'),
231
-                        'target' => '',
232
-                        'class'  => $this->menu_class,
233
-                    ),
234
-                )
235
-            );
236
-        }
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * @return void
243
-     */
244
-    private function addEventsEditCurrentEvent()
245
-    {
246
-        if (is_single() && (get_post_type() === 'espresso_events')) {
247
-            //Current post
248
-            global $post;
249
-            if (
250
-                $this->capabilities->current_user_can(
251
-                    'ee_edit_event',
252
-                    'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID
253
-                )
254
-            ) {
255
-                $this->admin_bar->add_menu(
256
-                    array(
257
-                        'id'     => 'espresso-toolbar-events-edit',
258
-                        'parent' => 'espresso-toolbar-events',
259
-                        'title'  => '<span class="ee-toolbar-icon"></span>'
260
-                                    . esc_html__('Edit Event', 'event_espresso'),
261
-                        'href'   => EEH_URL::add_query_args_and_nonce(
262
-                            array(
263
-                                'action' => 'edit',
264
-                                'post' => $post->ID
265
-                            ),
266
-                            $this->events_admin_url
267
-                        ),
268
-                        'meta'   => array(
269
-                            'title'  => esc_html__('Edit Event', 'event_espresso'),
270
-                            'target' => '',
271
-                            'class'  => $this->menu_class,
272
-                        ),
273
-                    )
274
-                );
275
-            }
276
-        }
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * @return void
283
-     */
284
-    private function addEventsViewHeader()
285
-    {
286
-        if (
287
-            $this->capabilities->current_user_can(
288
-                'ee_read_events',
289
-                'ee_admin_bar_menu_espresso-toolbar-events-view'
290
-            )
291
-        ) {
292
-            $this->admin_bar->add_menu(
293
-                array(
294
-                    'id'     => 'espresso-toolbar-events-view',
295
-                    'parent' => 'espresso-toolbar-events',
296
-                    'title'  => esc_html__('View', 'event_espresso'),
297
-                    'href'   => '',
298
-                )
299
-            );
300
-        }
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * @return void
307
-     */
308
-    private function addEventsViewAll()
309
-    {
310
-        if (
311
-            $this->capabilities->current_user_can(
312
-                'ee_read_events',
313
-                'ee_admin_bar_menu_espresso-toolbar-events-all'
314
-            )
315
-        ) {
316
-            $this->admin_bar->add_menu(
317
-                array(
318
-                    'id'     => 'espresso-toolbar-events-all',
319
-                    'parent' => 'espresso-toolbar-events',
320
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
321
-                                . esc_html__('All', 'event_espresso'),
322
-                    'href'   => $this->events_admin_url,
323
-                    'meta'   => array(
324
-                        'title'  => esc_html__('All', 'event_espresso'),
325
-                        'target' => '',
326
-                        'class'  => $this->menu_class,
327
-                    ),
328
-                )
329
-            );
330
-        }
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * @return void
337
-     */
338
-    private function addEventsViewToday()
339
-    {
340
-        if (
341
-            $this->capabilities->current_user_can(
342
-                'ee_read_events',
343
-                'ee_admin_bar_menu_espresso-toolbar-events-today'
344
-            )
345
-        ) {
346
-            $this->admin_bar->add_menu(
347
-                array(
348
-                    'id'     => 'espresso-toolbar-events-today',
349
-                    'parent' => 'espresso-toolbar-events',
350
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
351
-                                . esc_html__('Today', 'event_espresso'),
352
-                    'href'   => EEH_URL::add_query_args_and_nonce(
353
-                        array(
354
-                            'action' => 'default',
355
-                            'status' => 'today'
356
-                        ),
357
-                        $this->events_admin_url
358
-                    ),
359
-                    'meta'   => array(
360
-                        'title'  => esc_html__('Today', 'event_espresso'),
361
-                        'target' => '',
362
-                        'class'  => $this->menu_class,
363
-                    ),
364
-                )
365
-            );
366
-        }
367
-    }
368
-
369
-
370
-
371
-    /**
372
-     * @return void
373
-     */
374
-    private function addEventsViewThisMonth()
375
-    {
376
-        if (
377
-            $this->capabilities->current_user_can(
378
-                'ee_read_events',
379
-                'ee_admin_bar_menu_espresso-toolbar-events-month'
380
-            )
381
-        ) {
382
-            $this->admin_bar->add_menu(
383
-                array(
384
-                    'id'     => 'espresso-toolbar-events-month',
385
-                    'parent' => 'espresso-toolbar-events',
386
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
387
-                                . esc_html__('This Month', 'event_espresso'),
388
-                    'href'   => EEH_URL::add_query_args_and_nonce(
389
-                        array(
390
-                            'action' => 'default',
391
-                            'status' => 'month'
392
-                        ),
393
-                        $this->events_admin_url
394
-                    ),
395
-                    'meta'   => array(
396
-                        'title'  => esc_html__('This Month', 'event_espresso'),
397
-                        'target' => '',
398
-                        'class'  => $this->menu_class,
399
-                    ),
400
-                )
401
-            );
402
-        }
403
-    }
404
-
405
-
406
-
407
-    /**
408
-     * @return void
409
-     */
410
-    private function addRegistrationSubMenu()
411
-    {
412
-        if (
413
-            $this->capabilities->current_user_can(
414
-                'ee_read_registrations',
415
-                'ee_admin_bar_menu_espresso-toolbar-registrations'
416
-            )
417
-        ) {
418
-            $this->admin_bar->add_menu(
419
-                array(
420
-                    'id'     => 'espresso-toolbar-registrations',
421
-                    'parent' => 'espresso-toolbar',
422
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
423
-                                . esc_html__('Registrations', 'event_espresso'),
424
-                    'href'   => $this->reg_admin_url,
425
-                    'meta'   => array(
426
-                        'title'  => esc_html__('Registrations', 'event_espresso'),
427
-                        'target' => '',
428
-                        'class'  => $this->menu_class,
429
-                    ),
430
-                )
431
-            );
432
-        }
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     * @return void
439
-     */
440
-    private function addRegistrationOverviewToday()
441
-    {
442
-        if (
443
-            $this->capabilities->current_user_can(
444
-                'ee_read_registrations',
445
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today'
446
-            )
447
-        ) {
448
-            $this->admin_bar->add_menu(
449
-                array(
450
-                    'id'     => 'espresso-toolbar-registrations-today',
451
-                    'parent' => 'espresso-toolbar-registrations',
452
-                    'title'  => esc_html__('Today', 'event_espresso'),
453
-                    'href'   => '',
454
-                    'meta'   => array(
455
-                        'title'  => esc_html__('Today', 'event_espresso'),
456
-                        'target' => '',
457
-                        'class'  => $this->menu_class,
458
-                    ),
459
-                )
460
-            );
461
-        }
462
-    }
463
-
464
-
465
-
466
-    /**
467
-     * @return void
468
-     */
469
-    private function addRegistrationOverviewTodayApproved()
470
-    {
471
-        if (
472
-            $this->capabilities->current_user_can(
473
-                'ee_read_registrations',
474
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved'
475
-            )
476
-        ) {
477
-            $this->admin_bar->add_menu(
478
-                array(
479
-                    'id'     => 'espresso-toolbar-registrations-today-approved',
480
-                    'parent' => 'espresso-toolbar-registrations',
481
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
482
-                                . esc_html__('Approved', 'event_espresso'),
483
-                    'href'   => EEH_URL::add_query_args_and_nonce(
484
-                        array(
485
-                            'action'      => 'default',
486
-                            'status'      => 'today',
487
-                            '_reg_status' => EEM_Registration::status_id_approved,
488
-                        ),
489
-                        $this->reg_admin_url
490
-                    ),
491
-                    'meta'   => array(
492
-                        'title'  => esc_html__('Approved', 'event_espresso'),
493
-                        'target' => '',
494
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
495
-                    ),
496
-                )
497
-            );
498
-        }
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * @return void
505
-     */
506
-    private function addRegistrationOverviewTodayPendingPayment()
507
-    {
508
-        if (
509
-            $this->capabilities->current_user_can(
510
-                'ee_read_registrations',
511
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending'
512
-            )
513
-        ) {
514
-            $this->admin_bar->add_menu(
515
-                array(
516
-                    'id'     => 'espresso-toolbar-registrations-today-pending',
517
-                    'parent' => 'espresso-toolbar-registrations',
518
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
519
-                                . esc_html__('Pending', 'event_espresso'),
520
-                    'href'   => EEH_URL::add_query_args_and_nonce(
521
-                        array(
522
-                            'action'     => 'default',
523
-                            'status'     => 'today',
524
-                            'reg_status' => EEM_Registration::status_id_pending_payment,
525
-                        ),
526
-                        $this->reg_admin_url
527
-                    ),
528
-                    'meta'   => array(
529
-                        'title'  => esc_html__('Pending Payment', 'event_espresso'),
530
-                        'target' => '',
531
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
532
-                    ),
533
-                )
534
-            );
535
-        }
536
-    }
537
-
538
-
539
-
540
-    /**
541
-     * @return void
542
-     */
543
-    private function addRegistrationOverviewTodayNotApproved()
544
-    {
545
-        if (
546
-            $this->capabilities->current_user_can(
547
-                'ee_read_registrations',
548
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved'
549
-            )
550
-        ) {
551
-            $this->admin_bar->add_menu(
552
-                array(
553
-                    'id'     => 'espresso-toolbar-registrations-today-not-approved',
554
-                    'parent' => 'espresso-toolbar-registrations',
555
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
556
-                                . esc_html__('Not Approved', 'event_espresso'),
557
-                    'href'   => EEH_URL::add_query_args_and_nonce(
558
-                        array(
559
-                            'action'      => 'default',
560
-                            'status'      => 'today',
561
-                            '_reg_status' => EEM_Registration::status_id_not_approved,
562
-                        ),
563
-                        $this->reg_admin_url
564
-                    ),
565
-                    'meta'   => array(
566
-                        'title'  => esc_html__('Not Approved', 'event_espresso'),
567
-                        'target' => '',
568
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
569
-                    ),
570
-                )
571
-            );
572
-        }
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * @return void
579
-     */
580
-    private function addRegistrationOverviewTodayCancelled()
581
-    {
582
-        if (
583
-            $this->capabilities->current_user_can(
584
-                'ee_read_registrations',
585
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled'
586
-            )
587
-        ) {
588
-            $this->admin_bar->add_menu(
589
-                array(
590
-                    'id'     => 'espresso-toolbar-registrations-today-cancelled',
591
-                    'parent' => 'espresso-toolbar-registrations',
592
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
593
-                                . esc_html__('Cancelled', 'event_espresso'),
594
-                    'href'   => EEH_URL::add_query_args_and_nonce(
595
-                        array(
596
-                            'action'      => 'default',
597
-                            'status'      => 'today',
598
-                            '_reg_status' => EEM_Registration::status_id_cancelled,
599
-                        ),
600
-                        $this->reg_admin_url
601
-                    ),
602
-                    'meta'   => array(
603
-                        'title'  => esc_html__('Cancelled', 'event_espresso'),
604
-                        'target' => '',
605
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
606
-                    ),
607
-                )
608
-            );
609
-        }
610
-    }
611
-
612
-
613
-
614
-    /**
615
-     * @return void
616
-     */
617
-    private function addRegistrationOverviewThisMonth()
618
-    {
619
-        if (
620
-            $this->capabilities->current_user_can(
621
-                'ee_read_registrations',
622
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month'
623
-            )
624
-        ) {
625
-            $this->admin_bar->add_menu(
626
-                array(
627
-                    'id'     => 'espresso-toolbar-registrations-month',
628
-                    'parent' => 'espresso-toolbar-registrations',
629
-                    'title'  => esc_html__('This Month', 'event_espresso'),
630
-                    'href'   => '', //EEH_URL::add_query_args_and_nonce(
631
-                    //     array(
632
-                    //         'action' => 'default',
633
-                    //         'status' => 'month'
634
-                    //     ),
635
-                    //     $this->reg_admin_url
636
-                    // ),
637
-                    'meta'   => array(
638
-                        'title'  => esc_html__('This Month', 'event_espresso'),
639
-                        'target' => '',
640
-                        'class'  => $this->menu_class,
641
-                    ),
642
-                )
643
-            );
644
-        }
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * @return void
651
-     */
652
-    private function addRegistrationOverviewThisMonthApproved()
653
-    {
654
-        if (
655
-            $this->capabilities->current_user_can(
656
-                'ee_read_registrations',
657
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved'
658
-            )
659
-        ) {
660
-            $this->admin_bar->add_menu(
661
-                array(
662
-                    'id'     => 'espresso-toolbar-registrations-month-approved',
663
-                    'parent' => 'espresso-toolbar-registrations',
664
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
665
-                                . esc_html__('Approved', 'event_espresso'),
666
-                    'href'   => EEH_URL::add_query_args_and_nonce(
667
-                        array(
668
-                            'action'      => 'default',
669
-                            'status'      => 'month',
670
-                            '_reg_status' => EEM_Registration::status_id_approved,
671
-                        ),
672
-                        $this->reg_admin_url
673
-                    ),
674
-                    'meta'   => array(
675
-                        'title'  => esc_html__('Approved', 'event_espresso'),
676
-                        'target' => '',
677
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
678
-                    ),
679
-                )
680
-            );
681
-        }
682
-    }
683
-
684
-
685
-
686
-    /**
687
-     * @return void
688
-     */
689
-    private function addRegistrationOverviewThisMonthPending()
690
-    {
691
-        if (
692
-            $this->capabilities->current_user_can(
693
-                'ee_read_registrations',
694
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending'
695
-            )
696
-        ) {
697
-            $this->admin_bar->add_menu(
698
-                array(
699
-                    'id'     => 'espresso-toolbar-registrations-month-pending',
700
-                    'parent' => 'espresso-toolbar-registrations',
701
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
702
-                                . esc_html__('Pending', 'event_espresso'),
703
-                    'href'   => EEH_URL::add_query_args_and_nonce(
704
-                        array(
705
-                            'action'      => 'default',
706
-                            'status'      => 'month',
707
-                            '_reg_status' => EEM_Registration::status_id_pending_payment,
708
-                        ),
709
-                        $this->reg_admin_url
710
-                    ),
711
-                    'meta'   => array(
712
-                        'title'  => esc_html__('Pending', 'event_espresso'),
713
-                        'target' => '',
714
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
715
-                    ),
716
-                )
717
-            );
718
-        }
719
-    }
720
-
721
-
722
-
723
-    /**
724
-     * @return void
725
-     */
726
-    private function addRegistrationOverviewThisMonthNotApproved()
727
-    {
728
-        if (
729
-            $this->capabilities->current_user_can(
730
-                'ee_read_registrations',
731
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved'
732
-            )
733
-        ) {
734
-            $this->admin_bar->add_menu(
735
-                array(
736
-                    'id'     => 'espresso-toolbar-registrations-month-not-approved',
737
-                    'parent' => 'espresso-toolbar-registrations',
738
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
739
-                                . esc_html__('Not Approved', 'event_espresso'),
740
-                    'href'   => EEH_URL::add_query_args_and_nonce(
741
-                        array(
742
-                            'action'      => 'default',
743
-                            'status'      => 'month',
744
-                            '_reg_status' => EEM_Registration::status_id_not_approved,
745
-                        ),
746
-                        $this->reg_admin_url
747
-                    ),
748
-                    'meta'   => array(
749
-                        'title'  => esc_html__('Not Approved', 'event_espresso'),
750
-                        'target' => '',
751
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
752
-                    ),
753
-                )
754
-            );
755
-        }
756
-    }
757
-
758
-
759
-
760
-    /**
761
-     * @return void
762
-     */
763
-    private function addRegistrationOverviewThisMonthCancelled()
764
-    {
765
-        if (
766
-            $this->capabilities->current_user_can(
767
-                'ee_read_registrations',
768
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled'
769
-            )
770
-        ) {
771
-            $this->admin_bar->add_menu(
772
-                array(
773
-                    'id'     => 'espresso-toolbar-registrations-month-cancelled',
774
-                    'parent' => 'espresso-toolbar-registrations',
775
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
776
-                                . esc_html__('Cancelled', 'event_espresso'),
777
-                    'href'   => EEH_URL::add_query_args_and_nonce(
778
-                        array(
779
-                            'action'      => 'default',
780
-                            'status'      => 'month',
781
-                            '_reg_status' => EEM_Registration::status_id_cancelled,
782
-                        ),
783
-                        $this->reg_admin_url
784
-                    ),
785
-                    'meta'   => array(
786
-                        'title'  => esc_html__('Cancelled', 'event_espresso'),
787
-                        'target' => '',
788
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
789
-                    ),
790
-                )
791
-            );
792
-        }
793
-    }
794
-
795
-
796
-
797
-    /**
798
-     * @return void
799
-     */
800
-    private function addExtensionsAndServices()
801
-    {
802
-        if (
803
-            $this->capabilities->current_user_can(
804
-                'ee_read_ee',
805
-                'ee_admin_bar_menu_espresso-toolbar-extensions-and-services'
806
-            )
807
-        ) {
808
-            $this->admin_bar->add_menu(
809
-                array(
810
-                    'id'     => 'espresso-toolbar-extensions-and-services',
811
-                    'parent' => 'espresso-toolbar',
812
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
813
-                                . esc_html__('Extensions & Services', 'event_espresso'),
814
-                    'href'   => admin_url('admin.php?page=espresso_packages'),
815
-                    'meta'   => array(
816
-                        'title'  => esc_html__('Extensions & Services', 'event_espresso'),
817
-                        'target' => '',
818
-                        'class'  => $this->menu_class,
819
-                    ),
820
-                )
821
-            );
822
-        }
823
-    }
25
+	/**
26
+	 * @var WP_Admin_Bar $admin_bar
27
+	 */
28
+	private $admin_bar;
29
+
30
+	/**
31
+	 * @var EE_Capabilities $capabilities
32
+	 */
33
+	private $capabilities;
34
+
35
+	/**
36
+	 * @var string $events_admin_url
37
+	 */
38
+	private $events_admin_url;
39
+
40
+	/**
41
+	 * @var string $menu_class
42
+	 */
43
+	private $menu_class = 'espresso_menu_item_class';
44
+
45
+	/**
46
+	 * @var string $reg_admin_url
47
+	 */
48
+	private $reg_admin_url;
49
+
50
+
51
+
52
+	/**
53
+	 * AdminToolBar constructor.
54
+	 *
55
+	 * @param EE_Capabilities $capabilities
56
+	 */
57
+	public function __construct(EE_Capabilities $capabilities)
58
+	{
59
+		$this->capabilities = $capabilities;
60
+		add_action('admin_bar_menu', array($this, 'espressoToolbarItems'), 100);
61
+		$this->enqueueAssets();
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 *    espresso_toolbar_items
68
+	 *
69
+	 * @access public
70
+	 * @param  WP_Admin_Bar $admin_bar
71
+	 * @return void
72
+	 */
73
+	public function espressoToolbarItems(WP_Admin_Bar $admin_bar)
74
+	{
75
+		// if its an AJAX request, or user is NOT an admin, or in full M-Mode
76
+		if (
77
+			defined('DOING_AJAX')
78
+			|| ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
79
+			|| EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
80
+		) {
81
+			return;
82
+		}
83
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
84
+		$this->admin_bar = $admin_bar;
85
+		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
86
+		//because they're only defined in each of their respective constructors
87
+		//and this might be a frontend request, in which case they aren't available
88
+		$this->events_admin_url = admin_url('admin.php?page=espresso_events');
89
+		$this->reg_admin_url = admin_url('admin.php?page=espresso_registrations');
90
+		// now let's add all of the menu items
91
+		$this->addTopLevelMenu();
92
+		$this->addEventsSubMenu();
93
+		$this->addEventsAddEditHeader();
94
+		$this->addEventsAddNew();
95
+		$this->addEventsEditCurrentEvent();
96
+		$this->addEventsViewHeader();
97
+		$this->addEventsViewAll();
98
+		$this->addEventsViewToday();
99
+		$this->addEventsViewThisMonth();
100
+		$this->addRegistrationSubMenu();
101
+		$this->addRegistrationOverviewToday();
102
+		$this->addRegistrationOverviewTodayApproved();
103
+		$this->addRegistrationOverviewTodayPendingPayment();
104
+		$this->addRegistrationOverviewTodayNotApproved();
105
+		$this->addRegistrationOverviewTodayCancelled();
106
+		$this->addRegistrationOverviewThisMonth();
107
+		$this->addRegistrationOverviewThisMonthApproved();
108
+		$this->addRegistrationOverviewThisMonthPending();
109
+		$this->addRegistrationOverviewThisMonthNotApproved();
110
+		$this->addRegistrationOverviewThisMonthCancelled();
111
+		$this->addExtensionsAndServices();
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * @return void
118
+	 */
119
+	private function enqueueAssets()
120
+	{
121
+		wp_register_style(
122
+			'espresso-admin-toolbar',
123
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css',
124
+			array('dashicons'),
125
+			EVENT_ESPRESSO_VERSION
126
+		);
127
+		wp_enqueue_style('espresso-admin-toolbar');
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return void
134
+	 */
135
+	private function addTopLevelMenu()
136
+	{
137
+		$this->admin_bar->add_menu(
138
+			array(
139
+				'id'    => 'espresso-toolbar',
140
+				'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
141
+					. esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso')
142
+					. '</span>',
143
+				'href'  => $this->events_admin_url,
144
+				'meta'  => array(
145
+					'title' => esc_html__('Event Espresso', 'event_espresso'),
146
+					'class' => $this->menu_class . 'first',
147
+				),
148
+			)
149
+		);
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * @return void
156
+	 */
157
+	private function addEventsSubMenu()
158
+	{
159
+		if (
160
+			$this->capabilities->current_user_can(
161
+				'ee_read_events',
162
+				'ee_admin_bar_menu_espresso-toolbar-events'
163
+			)
164
+		) {
165
+			$this->admin_bar->add_menu(
166
+				array(
167
+					'id'     => 'espresso-toolbar-events',
168
+					'parent' => 'espresso-toolbar',
169
+					'title'  => '<span class="ee-toolbar-icon"></span>'
170
+								. esc_html__('Events', 'event_espresso'),
171
+					'href'   => $this->events_admin_url,
172
+					'meta'   => array(
173
+						'title'  => esc_html__('Events', 'event_espresso'),
174
+						'target' => '',
175
+						'class'  => $this->menu_class,
176
+					),
177
+				)
178
+			);
179
+		}
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * @return void
186
+	 */
187
+	private function addEventsAddEditHeader()
188
+	{
189
+		if (
190
+		$this->capabilities->current_user_can(
191
+			'ee_read_events',
192
+			'ee_admin_bar_menu_espresso-toolbar-events-view'
193
+		)
194
+		) {
195
+			$this->admin_bar->add_menu(
196
+				array(
197
+					'id'     => 'espresso-toolbar-events-add-edit',
198
+					'parent' => 'espresso-toolbar-events',
199
+					'title'  => esc_html__('Add / Edit', 'event_espresso'),
200
+					'href'   => '',
201
+				)
202
+			);
203
+		}
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * @return void
210
+	 */
211
+	private function addEventsAddNew()
212
+	{
213
+		if (
214
+			$this->capabilities->current_user_can(
215
+				'ee_edit_events',
216
+				'ee_admin_bar_menu_espresso-toolbar-events-new'
217
+			)
218
+		) {
219
+			$this->admin_bar->add_menu(
220
+				array(
221
+					'id'     => 'espresso-toolbar-events-new',
222
+					'parent' => 'espresso-toolbar-events',
223
+					'title'  => '<span class="ee-toolbar-icon"></span>'
224
+								. esc_html__('Add New', 'event_espresso'),
225
+					'href'   => EEH_URL::add_query_args_and_nonce(
226
+						array('action' => 'create_new'),
227
+						$this->events_admin_url
228
+					),
229
+					'meta'   => array(
230
+						'title'  => esc_html__('Add New', 'event_espresso'),
231
+						'target' => '',
232
+						'class'  => $this->menu_class,
233
+					),
234
+				)
235
+			);
236
+		}
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * @return void
243
+	 */
244
+	private function addEventsEditCurrentEvent()
245
+	{
246
+		if (is_single() && (get_post_type() === 'espresso_events')) {
247
+			//Current post
248
+			global $post;
249
+			if (
250
+				$this->capabilities->current_user_can(
251
+					'ee_edit_event',
252
+					'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID
253
+				)
254
+			) {
255
+				$this->admin_bar->add_menu(
256
+					array(
257
+						'id'     => 'espresso-toolbar-events-edit',
258
+						'parent' => 'espresso-toolbar-events',
259
+						'title'  => '<span class="ee-toolbar-icon"></span>'
260
+									. esc_html__('Edit Event', 'event_espresso'),
261
+						'href'   => EEH_URL::add_query_args_and_nonce(
262
+							array(
263
+								'action' => 'edit',
264
+								'post' => $post->ID
265
+							),
266
+							$this->events_admin_url
267
+						),
268
+						'meta'   => array(
269
+							'title'  => esc_html__('Edit Event', 'event_espresso'),
270
+							'target' => '',
271
+							'class'  => $this->menu_class,
272
+						),
273
+					)
274
+				);
275
+			}
276
+		}
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * @return void
283
+	 */
284
+	private function addEventsViewHeader()
285
+	{
286
+		if (
287
+			$this->capabilities->current_user_can(
288
+				'ee_read_events',
289
+				'ee_admin_bar_menu_espresso-toolbar-events-view'
290
+			)
291
+		) {
292
+			$this->admin_bar->add_menu(
293
+				array(
294
+					'id'     => 'espresso-toolbar-events-view',
295
+					'parent' => 'espresso-toolbar-events',
296
+					'title'  => esc_html__('View', 'event_espresso'),
297
+					'href'   => '',
298
+				)
299
+			);
300
+		}
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * @return void
307
+	 */
308
+	private function addEventsViewAll()
309
+	{
310
+		if (
311
+			$this->capabilities->current_user_can(
312
+				'ee_read_events',
313
+				'ee_admin_bar_menu_espresso-toolbar-events-all'
314
+			)
315
+		) {
316
+			$this->admin_bar->add_menu(
317
+				array(
318
+					'id'     => 'espresso-toolbar-events-all',
319
+					'parent' => 'espresso-toolbar-events',
320
+					'title'  => '<span class="ee-toolbar-icon"></span>'
321
+								. esc_html__('All', 'event_espresso'),
322
+					'href'   => $this->events_admin_url,
323
+					'meta'   => array(
324
+						'title'  => esc_html__('All', 'event_espresso'),
325
+						'target' => '',
326
+						'class'  => $this->menu_class,
327
+					),
328
+				)
329
+			);
330
+		}
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * @return void
337
+	 */
338
+	private function addEventsViewToday()
339
+	{
340
+		if (
341
+			$this->capabilities->current_user_can(
342
+				'ee_read_events',
343
+				'ee_admin_bar_menu_espresso-toolbar-events-today'
344
+			)
345
+		) {
346
+			$this->admin_bar->add_menu(
347
+				array(
348
+					'id'     => 'espresso-toolbar-events-today',
349
+					'parent' => 'espresso-toolbar-events',
350
+					'title'  => '<span class="ee-toolbar-icon"></span>'
351
+								. esc_html__('Today', 'event_espresso'),
352
+					'href'   => EEH_URL::add_query_args_and_nonce(
353
+						array(
354
+							'action' => 'default',
355
+							'status' => 'today'
356
+						),
357
+						$this->events_admin_url
358
+					),
359
+					'meta'   => array(
360
+						'title'  => esc_html__('Today', 'event_espresso'),
361
+						'target' => '',
362
+						'class'  => $this->menu_class,
363
+					),
364
+				)
365
+			);
366
+		}
367
+	}
368
+
369
+
370
+
371
+	/**
372
+	 * @return void
373
+	 */
374
+	private function addEventsViewThisMonth()
375
+	{
376
+		if (
377
+			$this->capabilities->current_user_can(
378
+				'ee_read_events',
379
+				'ee_admin_bar_menu_espresso-toolbar-events-month'
380
+			)
381
+		) {
382
+			$this->admin_bar->add_menu(
383
+				array(
384
+					'id'     => 'espresso-toolbar-events-month',
385
+					'parent' => 'espresso-toolbar-events',
386
+					'title'  => '<span class="ee-toolbar-icon"></span>'
387
+								. esc_html__('This Month', 'event_espresso'),
388
+					'href'   => EEH_URL::add_query_args_and_nonce(
389
+						array(
390
+							'action' => 'default',
391
+							'status' => 'month'
392
+						),
393
+						$this->events_admin_url
394
+					),
395
+					'meta'   => array(
396
+						'title'  => esc_html__('This Month', 'event_espresso'),
397
+						'target' => '',
398
+						'class'  => $this->menu_class,
399
+					),
400
+				)
401
+			);
402
+		}
403
+	}
404
+
405
+
406
+
407
+	/**
408
+	 * @return void
409
+	 */
410
+	private function addRegistrationSubMenu()
411
+	{
412
+		if (
413
+			$this->capabilities->current_user_can(
414
+				'ee_read_registrations',
415
+				'ee_admin_bar_menu_espresso-toolbar-registrations'
416
+			)
417
+		) {
418
+			$this->admin_bar->add_menu(
419
+				array(
420
+					'id'     => 'espresso-toolbar-registrations',
421
+					'parent' => 'espresso-toolbar',
422
+					'title'  => '<span class="ee-toolbar-icon"></span>'
423
+								. esc_html__('Registrations', 'event_espresso'),
424
+					'href'   => $this->reg_admin_url,
425
+					'meta'   => array(
426
+						'title'  => esc_html__('Registrations', 'event_espresso'),
427
+						'target' => '',
428
+						'class'  => $this->menu_class,
429
+					),
430
+				)
431
+			);
432
+		}
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 * @return void
439
+	 */
440
+	private function addRegistrationOverviewToday()
441
+	{
442
+		if (
443
+			$this->capabilities->current_user_can(
444
+				'ee_read_registrations',
445
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today'
446
+			)
447
+		) {
448
+			$this->admin_bar->add_menu(
449
+				array(
450
+					'id'     => 'espresso-toolbar-registrations-today',
451
+					'parent' => 'espresso-toolbar-registrations',
452
+					'title'  => esc_html__('Today', 'event_espresso'),
453
+					'href'   => '',
454
+					'meta'   => array(
455
+						'title'  => esc_html__('Today', 'event_espresso'),
456
+						'target' => '',
457
+						'class'  => $this->menu_class,
458
+					),
459
+				)
460
+			);
461
+		}
462
+	}
463
+
464
+
465
+
466
+	/**
467
+	 * @return void
468
+	 */
469
+	private function addRegistrationOverviewTodayApproved()
470
+	{
471
+		if (
472
+			$this->capabilities->current_user_can(
473
+				'ee_read_registrations',
474
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved'
475
+			)
476
+		) {
477
+			$this->admin_bar->add_menu(
478
+				array(
479
+					'id'     => 'espresso-toolbar-registrations-today-approved',
480
+					'parent' => 'espresso-toolbar-registrations',
481
+					'title'  => '<span class="ee-toolbar-icon"></span>'
482
+								. esc_html__('Approved', 'event_espresso'),
483
+					'href'   => EEH_URL::add_query_args_and_nonce(
484
+						array(
485
+							'action'      => 'default',
486
+							'status'      => 'today',
487
+							'_reg_status' => EEM_Registration::status_id_approved,
488
+						),
489
+						$this->reg_admin_url
490
+					),
491
+					'meta'   => array(
492
+						'title'  => esc_html__('Approved', 'event_espresso'),
493
+						'target' => '',
494
+						'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
495
+					),
496
+				)
497
+			);
498
+		}
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * @return void
505
+	 */
506
+	private function addRegistrationOverviewTodayPendingPayment()
507
+	{
508
+		if (
509
+			$this->capabilities->current_user_can(
510
+				'ee_read_registrations',
511
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending'
512
+			)
513
+		) {
514
+			$this->admin_bar->add_menu(
515
+				array(
516
+					'id'     => 'espresso-toolbar-registrations-today-pending',
517
+					'parent' => 'espresso-toolbar-registrations',
518
+					'title'  => '<span class="ee-toolbar-icon"></span>'
519
+								. esc_html__('Pending', 'event_espresso'),
520
+					'href'   => EEH_URL::add_query_args_and_nonce(
521
+						array(
522
+							'action'     => 'default',
523
+							'status'     => 'today',
524
+							'reg_status' => EEM_Registration::status_id_pending_payment,
525
+						),
526
+						$this->reg_admin_url
527
+					),
528
+					'meta'   => array(
529
+						'title'  => esc_html__('Pending Payment', 'event_espresso'),
530
+						'target' => '',
531
+						'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
532
+					),
533
+				)
534
+			);
535
+		}
536
+	}
537
+
538
+
539
+
540
+	/**
541
+	 * @return void
542
+	 */
543
+	private function addRegistrationOverviewTodayNotApproved()
544
+	{
545
+		if (
546
+			$this->capabilities->current_user_can(
547
+				'ee_read_registrations',
548
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved'
549
+			)
550
+		) {
551
+			$this->admin_bar->add_menu(
552
+				array(
553
+					'id'     => 'espresso-toolbar-registrations-today-not-approved',
554
+					'parent' => 'espresso-toolbar-registrations',
555
+					'title'  => '<span class="ee-toolbar-icon"></span>'
556
+								. esc_html__('Not Approved', 'event_espresso'),
557
+					'href'   => EEH_URL::add_query_args_and_nonce(
558
+						array(
559
+							'action'      => 'default',
560
+							'status'      => 'today',
561
+							'_reg_status' => EEM_Registration::status_id_not_approved,
562
+						),
563
+						$this->reg_admin_url
564
+					),
565
+					'meta'   => array(
566
+						'title'  => esc_html__('Not Approved', 'event_espresso'),
567
+						'target' => '',
568
+						'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
569
+					),
570
+				)
571
+			);
572
+		}
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * @return void
579
+	 */
580
+	private function addRegistrationOverviewTodayCancelled()
581
+	{
582
+		if (
583
+			$this->capabilities->current_user_can(
584
+				'ee_read_registrations',
585
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled'
586
+			)
587
+		) {
588
+			$this->admin_bar->add_menu(
589
+				array(
590
+					'id'     => 'espresso-toolbar-registrations-today-cancelled',
591
+					'parent' => 'espresso-toolbar-registrations',
592
+					'title'  => '<span class="ee-toolbar-icon"></span>'
593
+								. esc_html__('Cancelled', 'event_espresso'),
594
+					'href'   => EEH_URL::add_query_args_and_nonce(
595
+						array(
596
+							'action'      => 'default',
597
+							'status'      => 'today',
598
+							'_reg_status' => EEM_Registration::status_id_cancelled,
599
+						),
600
+						$this->reg_admin_url
601
+					),
602
+					'meta'   => array(
603
+						'title'  => esc_html__('Cancelled', 'event_espresso'),
604
+						'target' => '',
605
+						'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
606
+					),
607
+				)
608
+			);
609
+		}
610
+	}
611
+
612
+
613
+
614
+	/**
615
+	 * @return void
616
+	 */
617
+	private function addRegistrationOverviewThisMonth()
618
+	{
619
+		if (
620
+			$this->capabilities->current_user_can(
621
+				'ee_read_registrations',
622
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month'
623
+			)
624
+		) {
625
+			$this->admin_bar->add_menu(
626
+				array(
627
+					'id'     => 'espresso-toolbar-registrations-month',
628
+					'parent' => 'espresso-toolbar-registrations',
629
+					'title'  => esc_html__('This Month', 'event_espresso'),
630
+					'href'   => '', //EEH_URL::add_query_args_and_nonce(
631
+					//     array(
632
+					//         'action' => 'default',
633
+					//         'status' => 'month'
634
+					//     ),
635
+					//     $this->reg_admin_url
636
+					// ),
637
+					'meta'   => array(
638
+						'title'  => esc_html__('This Month', 'event_espresso'),
639
+						'target' => '',
640
+						'class'  => $this->menu_class,
641
+					),
642
+				)
643
+			);
644
+		}
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * @return void
651
+	 */
652
+	private function addRegistrationOverviewThisMonthApproved()
653
+	{
654
+		if (
655
+			$this->capabilities->current_user_can(
656
+				'ee_read_registrations',
657
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved'
658
+			)
659
+		) {
660
+			$this->admin_bar->add_menu(
661
+				array(
662
+					'id'     => 'espresso-toolbar-registrations-month-approved',
663
+					'parent' => 'espresso-toolbar-registrations',
664
+					'title'  => '<span class="ee-toolbar-icon"></span>'
665
+								. esc_html__('Approved', 'event_espresso'),
666
+					'href'   => EEH_URL::add_query_args_and_nonce(
667
+						array(
668
+							'action'      => 'default',
669
+							'status'      => 'month',
670
+							'_reg_status' => EEM_Registration::status_id_approved,
671
+						),
672
+						$this->reg_admin_url
673
+					),
674
+					'meta'   => array(
675
+						'title'  => esc_html__('Approved', 'event_espresso'),
676
+						'target' => '',
677
+						'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
678
+					),
679
+				)
680
+			);
681
+		}
682
+	}
683
+
684
+
685
+
686
+	/**
687
+	 * @return void
688
+	 */
689
+	private function addRegistrationOverviewThisMonthPending()
690
+	{
691
+		if (
692
+			$this->capabilities->current_user_can(
693
+				'ee_read_registrations',
694
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending'
695
+			)
696
+		) {
697
+			$this->admin_bar->add_menu(
698
+				array(
699
+					'id'     => 'espresso-toolbar-registrations-month-pending',
700
+					'parent' => 'espresso-toolbar-registrations',
701
+					'title'  => '<span class="ee-toolbar-icon"></span>'
702
+								. esc_html__('Pending', 'event_espresso'),
703
+					'href'   => EEH_URL::add_query_args_and_nonce(
704
+						array(
705
+							'action'      => 'default',
706
+							'status'      => 'month',
707
+							'_reg_status' => EEM_Registration::status_id_pending_payment,
708
+						),
709
+						$this->reg_admin_url
710
+					),
711
+					'meta'   => array(
712
+						'title'  => esc_html__('Pending', 'event_espresso'),
713
+						'target' => '',
714
+						'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
715
+					),
716
+				)
717
+			);
718
+		}
719
+	}
720
+
721
+
722
+
723
+	/**
724
+	 * @return void
725
+	 */
726
+	private function addRegistrationOverviewThisMonthNotApproved()
727
+	{
728
+		if (
729
+			$this->capabilities->current_user_can(
730
+				'ee_read_registrations',
731
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved'
732
+			)
733
+		) {
734
+			$this->admin_bar->add_menu(
735
+				array(
736
+					'id'     => 'espresso-toolbar-registrations-month-not-approved',
737
+					'parent' => 'espresso-toolbar-registrations',
738
+					'title'  => '<span class="ee-toolbar-icon"></span>'
739
+								. esc_html__('Not Approved', 'event_espresso'),
740
+					'href'   => EEH_URL::add_query_args_and_nonce(
741
+						array(
742
+							'action'      => 'default',
743
+							'status'      => 'month',
744
+							'_reg_status' => EEM_Registration::status_id_not_approved,
745
+						),
746
+						$this->reg_admin_url
747
+					),
748
+					'meta'   => array(
749
+						'title'  => esc_html__('Not Approved', 'event_espresso'),
750
+						'target' => '',
751
+						'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
752
+					),
753
+				)
754
+			);
755
+		}
756
+	}
757
+
758
+
759
+
760
+	/**
761
+	 * @return void
762
+	 */
763
+	private function addRegistrationOverviewThisMonthCancelled()
764
+	{
765
+		if (
766
+			$this->capabilities->current_user_can(
767
+				'ee_read_registrations',
768
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled'
769
+			)
770
+		) {
771
+			$this->admin_bar->add_menu(
772
+				array(
773
+					'id'     => 'espresso-toolbar-registrations-month-cancelled',
774
+					'parent' => 'espresso-toolbar-registrations',
775
+					'title'  => '<span class="ee-toolbar-icon"></span>'
776
+								. esc_html__('Cancelled', 'event_espresso'),
777
+					'href'   => EEH_URL::add_query_args_and_nonce(
778
+						array(
779
+							'action'      => 'default',
780
+							'status'      => 'month',
781
+							'_reg_status' => EEM_Registration::status_id_cancelled,
782
+						),
783
+						$this->reg_admin_url
784
+					),
785
+					'meta'   => array(
786
+						'title'  => esc_html__('Cancelled', 'event_espresso'),
787
+						'target' => '',
788
+						'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
789
+					),
790
+				)
791
+			);
792
+		}
793
+	}
794
+
795
+
796
+
797
+	/**
798
+	 * @return void
799
+	 */
800
+	private function addExtensionsAndServices()
801
+	{
802
+		if (
803
+			$this->capabilities->current_user_can(
804
+				'ee_read_ee',
805
+				'ee_admin_bar_menu_espresso-toolbar-extensions-and-services'
806
+			)
807
+		) {
808
+			$this->admin_bar->add_menu(
809
+				array(
810
+					'id'     => 'espresso-toolbar-extensions-and-services',
811
+					'parent' => 'espresso-toolbar',
812
+					'title'  => '<span class="ee-toolbar-icon"></span>'
813
+								. esc_html__('Extensions & Services', 'event_espresso'),
814
+					'href'   => admin_url('admin.php?page=espresso_packages'),
815
+					'meta'   => array(
816
+						'title'  => esc_html__('Extensions & Services', 'event_espresso'),
817
+						'target' => '',
818
+						'class'  => $this->menu_class,
819
+					),
820
+				)
821
+			);
822
+		}
823
+	}
824 824
 
825 825
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Indentation   +1027 added lines, -1027 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\services\shortcodes\ShortcodesManager;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -18,1032 +18,1032 @@  discard block
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
23
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
24
-     */
25
-    const req_type_normal = 0;
26
-
27
-    /**
28
-     * Indicates this is a brand new installation of EE so we should install
29
-     * tables and default data etc
30
-     */
31
-    const req_type_new_activation = 1;
32
-
33
-    /**
34
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
35
-     * and we just exited maintenance mode). We MUST check the database is setup properly
36
-     * and that default data is setup too
37
-     */
38
-    const req_type_reactivation = 2;
39
-
40
-    /**
41
-     * indicates that EE has been upgraded since its previous request.
42
-     * We may have data migration scripts to call and will want to trigger maintenance mode
43
-     */
44
-    const req_type_upgrade = 3;
45
-
46
-    /**
47
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
48
-     */
49
-    const req_type_downgrade = 4;
50
-
51
-    /**
52
-     * @deprecated since version 4.6.0.dev.006
53
-     * Now whenever a new_activation is detected the request type is still just
54
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
55
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
56
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
57
-     * (Specifically, when the migration manager indicates migrations are finished
58
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
59
-     */
60
-    const req_type_activation_but_not_installed = 5;
61
-
62
-    /**
63
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
64
-     */
65
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
66
-
67
-
68
-    /**
69
-     *    instance of the EE_System object
70
-     *
71
-     * @var    $_instance
72
-     * @access    private
73
-     */
74
-    private static $_instance = null;
75
-
76
-    /**
77
-     * @type  EE_Registry $Registry
78
-     * @access    protected
79
-     */
80
-    protected $registry;
81
-
82
-    /**
83
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
84
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
85
-     *
86
-     * @var int
87
-     */
88
-    private $_req_type;
89
-
90
-    /**
91
-     * Whether or not there was a non-micro version change in EE core version during this request
92
-     *
93
-     * @var boolean
94
-     */
95
-    private $_major_version_change = false;
96
-
97
-
98
-
99
-    /**
100
-     * @singleton method used to instantiate class object
101
-     * @access    public
102
-     * @param  \EE_Registry $Registry
103
-     * @return \EE_System
104
-     */
105
-    public static function instance(EE_Registry $Registry = null)
106
-    {
107
-        // check if class object is instantiated
108
-        if ( ! self::$_instance instanceof EE_System) {
109
-            self::$_instance = new self($Registry);
110
-        }
111
-        return self::$_instance;
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * resets the instance and returns it
118
-     *
119
-     * @return EE_System
120
-     */
121
-    public static function reset()
122
-    {
123
-        self::$_instance->_req_type = null;
124
-        //make sure none of the old hooks are left hanging around
125
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
126
-        //we need to reset the migration manager in order for it to detect DMSs properly
127
-        EE_Data_Migration_Manager::reset();
128
-        self::instance()->detect_activations_or_upgrades();
129
-        self::instance()->perform_activations_upgrades_and_migrations();
130
-        return self::instance();
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     *    sets hooks for running rest of system
137
-     *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
138
-     *    starting EE Addons from any other point may lead to problems
139
-     *
140
-     * @access private
141
-     * @param  \EE_Registry $Registry
142
-     */
143
-    private function __construct(EE_Registry $Registry)
144
-    {
145
-        $this->registry = $Registry;
146
-        do_action('AHEE__EE_System__construct__begin', $this);
147
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
148
-        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
149
-        // when an ee addon is activated, we want to call the core hook(s) again
150
-        // because the newly-activated addon didn't get a chance to run at all
151
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
152
-        // detect whether install or upgrade
153
-        add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
154
-            3);
155
-        // load EE_Config, EE_Textdomain, etc
156
-        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
157
-        // load EE_Config, EE_Textdomain, etc
158
-        add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
159
-            array($this, 'register_shortcodes_modules_and_widgets'), 7);
160
-        // you wanna get going? I wanna get going... let's get going!
161
-        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
162
-        //other housekeeping
163
-        //exclude EE critical pages from wp_list_pages
164
-        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
165
-        // ALL EE Addons should use the following hook point to attach their initial setup too
166
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
167
-        do_action('AHEE__EE_System__construct__complete', $this);
168
-    }
169
-
170
-
171
-
172
-    /**
173
-     * load_espresso_addons
174
-     * allow addons to load first so that they can set hooks for running DMS's, etc
175
-     * this is hooked into both:
176
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
177
-     *        which runs during the WP 'plugins_loaded' action at priority 5
178
-     *    and the WP 'activate_plugin' hookpoint
179
-     *
180
-     * @access public
181
-     * @return void
182
-     */
183
-    public function load_espresso_addons()
184
-    {
185
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
186
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
187
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
188
-        //load and setup EE_Capabilities
189
-        $this->registry->load_core('Capabilities');
190
-        //caps need to be initialized on every request so that capability maps are set.
191
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
192
-        $this->registry->CAP->init_caps();
193
-        do_action('AHEE__EE_System__load_espresso_addons');
194
-        //if the WP API basic auth plugin isn't already loaded, load it now.
195
-        //We want it for mobile apps. Just include the entire plugin
196
-        //also, don't load the basic auth when a plugin is getting activated, because
197
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
198
-        //and causes a fatal error
199
-        if ( ! function_exists('json_basic_auth_handler')
200
-             && ! function_exists('json_basic_auth_error')
201
-             && ! (
202
-                isset($_GET['action'])
203
-                && in_array($_GET['action'], array('activate', 'activate-selected'))
204
-            )
205
-             && ! (
206
-                isset($_GET['activate'])
207
-                && $_GET['activate'] === 'true'
208
-            )
209
-        ) {
210
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
211
-        }
212
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * detect_activations_or_upgrades
219
-     * Checks for activation or upgrade of core first;
220
-     * then also checks if any registered addons have been activated or upgraded
221
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
222
-     * which runs during the WP 'plugins_loaded' action at priority 3
223
-     *
224
-     * @access public
225
-     * @return void
226
-     */
227
-    public function detect_activations_or_upgrades()
228
-    {
229
-        //first off: let's make sure to handle core
230
-        $this->detect_if_activation_or_upgrade();
231
-        foreach ($this->registry->addons as $addon) {
232
-            //detect teh request type for that addon
233
-            $addon->detect_activation_or_upgrade();
234
-        }
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * detect_if_activation_or_upgrade
241
-     * Takes care of detecting whether this is a brand new install or code upgrade,
242
-     * and either setting up the DB or setting up maintenance mode etc.
243
-     *
244
-     * @access public
245
-     * @return void
246
-     */
247
-    public function detect_if_activation_or_upgrade()
248
-    {
249
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
250
-        // load M-Mode class
251
-        $this->registry->load_core('Maintenance_Mode');
252
-        // check if db has been updated, or if its a brand-new installation
253
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
254
-        $request_type = $this->detect_req_type($espresso_db_update);
255
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
256
-        switch ($request_type) {
257
-            case EE_System::req_type_new_activation:
258
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
259
-                $this->_handle_core_version_change($espresso_db_update);
260
-                break;
261
-            case EE_System::req_type_reactivation:
262
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
263
-                $this->_handle_core_version_change($espresso_db_update);
264
-                break;
265
-            case EE_System::req_type_upgrade:
266
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
267
-                //migrations may be required now that we've upgraded
268
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
269
-                $this->_handle_core_version_change($espresso_db_update);
270
-                //				echo "done upgrade";die;
271
-                break;
272
-            case EE_System::req_type_downgrade:
273
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
274
-                //its possible migrations are no longer required
275
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
276
-                $this->_handle_core_version_change($espresso_db_update);
277
-                break;
278
-            case EE_System::req_type_normal:
279
-            default:
280
-                //				$this->_maybe_redirect_to_ee_about();
281
-                break;
282
-        }
283
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * Updates the list of installed versions and sets hooks for
290
-     * initializing the database later during the request
291
-     *
292
-     * @param array $espresso_db_update
293
-     */
294
-    protected function _handle_core_version_change($espresso_db_update)
295
-    {
296
-        $this->update_list_of_installed_versions($espresso_db_update);
297
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
298
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
299
-            array($this, 'initialize_db_if_no_migrations_required'));
300
-    }
301
-
302
-
303
-
304
-    /**
305
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
306
-     * information about what versions of EE have been installed and activated,
307
-     * NOT necessarily the state of the database
308
-     *
309
-     * @param null $espresso_db_update
310
-     * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
311
-     *           from the options table
312
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
313
-     */
314
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
315
-    {
316
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
317
-        if ( ! $espresso_db_update) {
318
-            $espresso_db_update = get_option('espresso_db_update');
319
-        }
320
-        // check that option is an array
321
-        if ( ! is_array($espresso_db_update)) {
322
-            // if option is FALSE, then it never existed
323
-            if ($espresso_db_update === false) {
324
-                // make $espresso_db_update an array and save option with autoload OFF
325
-                $espresso_db_update = array();
326
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
327
-            } else {
328
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
329
-                $espresso_db_update = array($espresso_db_update => array());
330
-                update_option('espresso_db_update', $espresso_db_update);
331
-            }
332
-        } else {
333
-            $corrected_db_update = array();
334
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
335
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
336
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
337
-                    //the key is an int, and the value IS NOT an array
338
-                    //so it must be numerically-indexed, where values are versions installed...
339
-                    //fix it!
340
-                    $version_string = $should_be_array;
341
-                    $corrected_db_update[$version_string] = array('unknown-date');
342
-                } else {
343
-                    //ok it checks out
344
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
345
-                }
346
-            }
347
-            $espresso_db_update = $corrected_db_update;
348
-            update_option('espresso_db_update', $espresso_db_update);
349
-        }
350
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
351
-        return $espresso_db_update;
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * Does the traditional work of setting up the plugin's database and adding default data.
358
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
359
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
360
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
361
-     * so that it will be done when migrations are finished
362
-     *
363
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
364
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
365
-     *                                       This is a resource-intensive job
366
-     *                                       so we prefer to only do it when necessary
367
-     * @return void
368
-     */
369
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
370
-    {
371
-        $request_type = $this->detect_req_type();
372
-        //only initialize system if we're not in maintenance mode.
373
-        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
374
-            update_option('ee_flush_rewrite_rules', true);
375
-            if ($verify_schema) {
376
-                EEH_Activation::initialize_db_and_folders();
377
-            }
378
-            EEH_Activation::initialize_db_content();
379
-            EEH_Activation::system_initialization();
380
-            if ($initialize_addons_too) {
381
-                $this->initialize_addons();
382
-            }
383
-        } else {
384
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
385
-        }
386
-        if ($request_type === EE_System::req_type_new_activation
387
-            || $request_type === EE_System::req_type_reactivation
388
-            || (
389
-                $request_type === EE_System::req_type_upgrade
390
-                && $this->is_major_version_change()
391
-            )
392
-        ) {
393
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
394
-        }
395
-    }
396
-
397
-
398
-
399
-    /**
400
-     * Initializes the db for all registered addons
401
-     */
402
-    public function initialize_addons()
403
-    {
404
-        //foreach registered addon, make sure its db is up-to-date too
405
-        foreach ($this->registry->addons as $addon) {
406
-            $addon->initialize_db_if_no_migrations_required();
407
-        }
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
414
-     *
415
-     * @param    array  $version_history
416
-     * @param    string $current_version_to_add version to be added to the version history
417
-     * @return    boolean success as to whether or not this option was changed
418
-     */
419
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
420
-    {
421
-        if ( ! $version_history) {
422
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
423
-        }
424
-        if ($current_version_to_add == null) {
425
-            $current_version_to_add = espresso_version();
426
-        }
427
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
428
-        // re-save
429
-        return update_option('espresso_db_update', $version_history);
430
-    }
431
-
432
-
433
-
434
-    /**
435
-     * Detects if the current version indicated in the has existed in the list of
436
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
437
-     *
438
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
439
-     *                                  If not supplied, fetches it from the options table.
440
-     *                                  Also, caches its result so later parts of the code can also know whether
441
-     *                                  there's been an update or not. This way we can add the current version to
442
-     *                                  espresso_db_update, but still know if this is a new install or not
443
-     * @return int one of the constants on EE_System::req_type_
444
-     */
445
-    public function detect_req_type($espresso_db_update = null)
446
-    {
447
-        if ($this->_req_type === null) {
448
-            $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
449
-                : $this->fix_espresso_db_upgrade_option();
450
-            $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
451
-                'ee_espresso_activation', espresso_version());
452
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
453
-        }
454
-        return $this->_req_type;
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * Returns whether or not there was a non-micro version change (ie, change in either
461
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
462
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
463
-     *
464
-     * @param $activation_history
465
-     * @return bool
466
-     */
467
-    protected function _detect_major_version_change($activation_history)
468
-    {
469
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
470
-        $previous_version_parts = explode('.', $previous_version);
471
-        $current_version_parts = explode('.', espresso_version());
472
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
473
-               && ($previous_version_parts[0] !== $current_version_parts[0]
474
-                   || $previous_version_parts[1] !== $current_version_parts[1]
475
-               );
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * Returns true if either the major or minor version of EE changed during this request.
482
-     * 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
483
-     *
484
-     * @return bool
485
-     */
486
-    public function is_major_version_change()
487
-    {
488
-        return $this->_major_version_change;
489
-    }
490
-
491
-
492
-
493
-    /**
494
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
495
-     * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
496
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
497
-     * just activated to (for core that will always be espresso_version())
498
-     *
499
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
500
-     *                                                 ee plugin. for core that's 'espresso_db_update'
501
-     * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
502
-     *                                                 indicate that this plugin was just activated
503
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
504
-     *                                                 espresso_version())
505
-     * @return int one of the constants on EE_System::req_type_*
506
-     */
507
-    public static function detect_req_type_given_activation_history(
508
-        $activation_history_for_addon,
509
-        $activation_indicator_option_name,
510
-        $version_to_upgrade_to
511
-    ) {
512
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
513
-        if ($activation_history_for_addon) {
514
-            //it exists, so this isn't a completely new install
515
-            //check if this version already in that list of previously installed versions
516
-            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
517
-                //it a version we haven't seen before
518
-                if ($version_is_higher === 1) {
519
-                    $req_type = EE_System::req_type_upgrade;
520
-                } else {
521
-                    $req_type = EE_System::req_type_downgrade;
522
-                }
523
-                delete_option($activation_indicator_option_name);
524
-            } else {
525
-                // its not an update. maybe a reactivation?
526
-                if (get_option($activation_indicator_option_name, false)) {
527
-                    if ($version_is_higher === -1) {
528
-                        $req_type = EE_System::req_type_downgrade;
529
-                    } elseif ($version_is_higher === 0) {
530
-                        //we've seen this version before, but it's an activation. must be a reactivation
531
-                        $req_type = EE_System::req_type_reactivation;
532
-                    } else {//$version_is_higher === 1
533
-                        $req_type = EE_System::req_type_upgrade;
534
-                    }
535
-                    delete_option($activation_indicator_option_name);
536
-                } else {
537
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
538
-                    if ($version_is_higher === -1) {
539
-                        $req_type = EE_System::req_type_downgrade;
540
-                    } elseif ($version_is_higher === 0) {
541
-                        //we've seen this version before and it's not an activation. its normal request
542
-                        $req_type = EE_System::req_type_normal;
543
-                    } else {//$version_is_higher === 1
544
-                        $req_type = EE_System::req_type_upgrade;
545
-                    }
546
-                }
547
-            }
548
-        } else {
549
-            //brand new install
550
-            $req_type = EE_System::req_type_new_activation;
551
-            delete_option($activation_indicator_option_name);
552
-        }
553
-        return $req_type;
554
-    }
555
-
556
-
557
-
558
-    /**
559
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
560
-     * the $activation_history_for_addon
561
-     *
562
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
563
-     *                                             sometimes containing 'unknown-date'
564
-     * @param string $version_to_upgrade_to        (current version)
565
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
566
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
567
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
568
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
569
-     */
570
-    protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
571
-    {
572
-        //find the most recently-activated version
573
-        $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
574
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
575
-    }
576
-
577
-
578
-
579
-    /**
580
-     * Gets the most recently active version listed in the activation history,
581
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
582
-     *
583
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
584
-     *                                   sometimes containing 'unknown-date'
585
-     * @return string
586
-     */
587
-    protected static function _get_most_recently_active_version_from_activation_history($activation_history)
588
-    {
589
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
590
-        $most_recently_active_version = '0.0.0.dev.000';
591
-        if (is_array($activation_history)) {
592
-            foreach ($activation_history as $version => $times_activated) {
593
-                //check there is a record of when this version was activated. Otherwise,
594
-                //mark it as unknown
595
-                if ( ! $times_activated) {
596
-                    $times_activated = array('unknown-date');
597
-                }
598
-                if (is_string($times_activated)) {
599
-                    $times_activated = array($times_activated);
600
-                }
601
-                foreach ($times_activated as $an_activation) {
602
-                    if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
603
-                        $most_recently_active_version = $version;
604
-                        $most_recently_active_version_activation = $an_activation == 'unknown-date'
605
-                            ? '1970-01-01 00:00:00' : $an_activation;
606
-                    }
607
-                }
608
-            }
609
-        }
610
-        return $most_recently_active_version;
611
-    }
612
-
613
-
614
-
615
-    /**
616
-     * This redirects to the about EE page after activation
617
-     *
618
-     * @return void
619
-     */
620
-    public function redirect_to_about_ee()
621
-    {
622
-        $notices = EE_Error::get_notices(false);
623
-        //if current user is an admin and it's not an ajax or rest request
624
-        if (
625
-            ! (defined('DOING_AJAX') && DOING_AJAX)
626
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
627
-            && ! isset($notices['errors'])
628
-            && apply_filters(
629
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
630
-                $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
631
-            )
632
-        ) {
633
-            $query_params = array('page' => 'espresso_about');
634
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
635
-                $query_params['new_activation'] = true;
636
-            }
637
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
638
-                $query_params['reactivation'] = true;
639
-            }
640
-            $url = add_query_arg($query_params, admin_url('admin.php'));
641
-            wp_safe_redirect($url);
642
-            exit();
643
-        }
644
-    }
645
-
646
-
647
-
648
-    /**
649
-     * load_core_configuration
650
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
651
-     * which runs during the WP 'plugins_loaded' action at priority 5
652
-     *
653
-     * @return void
654
-     */
655
-    public function load_core_configuration()
656
-    {
657
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
658
-        $this->registry->load_core('EE_Load_Textdomain');
659
-        //load textdomain
660
-        EE_Load_Textdomain::load_textdomain();
661
-        // load and setup EE_Config and EE_Network_Config
662
-        $this->registry->load_core('Config');
663
-        $this->registry->load_core('Network_Config');
664
-        // setup autoloaders
665
-        // enable logging?
666
-        if ($this->registry->CFG->admin->use_full_logging) {
667
-            $this->registry->load_core('Log');
668
-        }
669
-        // check for activation errors
670
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
671
-        if ($activation_errors) {
672
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
673
-            update_option('ee_plugin_activation_errors', false);
674
-        }
675
-        // get model names
676
-        $this->_parse_model_names();
677
-        //load caf stuff a chance to play during the activation process too.
678
-        $this->_maybe_brew_regular();
679
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
680
-    }
681
-
682
-
683
-
684
-    /**
685
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
686
-     *
687
-     * @return void
688
-     */
689
-    private function _parse_model_names()
690
-    {
691
-        //get all the files in the EE_MODELS folder that end in .model.php
692
-        $models = glob(EE_MODELS . '*.model.php');
693
-        $model_names = array();
694
-        $non_abstract_db_models = array();
695
-        foreach ($models as $model) {
696
-            // get model classname
697
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
698
-            $short_name = str_replace('EEM_', '', $classname);
699
-            $reflectionClass = new ReflectionClass($classname);
700
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
701
-                $non_abstract_db_models[$short_name] = $classname;
702
-            }
703
-            $model_names[$short_name] = $classname;
704
-        }
705
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
706
-        $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
707
-            $non_abstract_db_models);
708
-    }
709
-
710
-
711
-
712
-    /**
713
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
714
-     * that need to be setup before our EE_System launches.
715
-     *
716
-     * @return void
717
-     */
718
-    private function _maybe_brew_regular()
719
-    {
720
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
721
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
722
-        }
723
-    }
724
-
725
-
726
-
727
-    /**
728
-     * register_shortcodes_modules_and_widgets
729
-     * generate lists of shortcodes and modules, then verify paths and classes
730
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
731
-     * which runs during the WP 'plugins_loaded' action at priority 7
732
-     *
733
-     * @access public
734
-     * @return void
735
-     */
736
-    public function register_shortcodes_modules_and_widgets()
737
-    {
738
-        try {
739
-            // load, register, and add shortcodes the new way
740
-            new ShortcodesManager(
741
-            // and the old way, but we'll put it under control of the new system
742
-                EE_Config::getLegacyShortcodesManager()
743
-            );
744
-        } catch (Exception $exception) {
745
-            new ExceptionStackTraceDisplay($exception);
746
-        }
747
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
748
-        // check for addons using old hookpoint
749
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
750
-            $this->_incompatible_addon_error();
751
-        }
752
-    }
753
-
754
-
755
-
756
-    /**
757
-     * _incompatible_addon_error
758
-     *
759
-     * @access public
760
-     * @return void
761
-     */
762
-    private function _incompatible_addon_error()
763
-    {
764
-        // get array of classes hooking into here
765
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
766
-        if ( ! empty($class_names)) {
767
-            $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
768
-                'event_espresso');
769
-            $msg .= '<ul>';
770
-            foreach ($class_names as $class_name) {
771
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
772
-                        $class_name) . '</b></li>';
773
-            }
774
-            $msg .= '</ul>';
775
-            $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
776
-                'event_espresso');
777
-            // save list of incompatible addons to wp-options for later use
778
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
779
-            if (is_admin()) {
780
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
781
-            }
782
-        }
783
-    }
784
-
785
-
786
-
787
-    /**
788
-     * brew_espresso
789
-     * begins the process of setting hooks for initializing EE in the correct order
790
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
791
-     * which runs during the WP 'plugins_loaded' action at priority 9
792
-     *
793
-     * @return void
794
-     */
795
-    public function brew_espresso()
796
-    {
797
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
798
-        // load some final core systems
799
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
800
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
801
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
802
-        add_action('init', array($this, 'load_controllers'), 7);
803
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
804
-        add_action('init', array($this, 'initialize'), 10);
805
-        add_action('init', array($this, 'initialize_last'), 100);
806
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
807
-            // pew pew pew
808
-            $this->registry->load_core('PUE');
809
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
810
-        }
811
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
812
-    }
813
-
814
-
815
-
816
-    /**
817
-     *    set_hooks_for_core
818
-     *
819
-     * @access public
820
-     * @return    void
821
-     */
822
-    public function set_hooks_for_core()
823
-    {
824
-        $this->_deactivate_incompatible_addons();
825
-        do_action('AHEE__EE_System__set_hooks_for_core');
826
-    }
827
-
828
-
829
-
830
-    /**
831
-     * Using the information gathered in EE_System::_incompatible_addon_error,
832
-     * deactivates any addons considered incompatible with the current version of EE
833
-     */
834
-    private function _deactivate_incompatible_addons()
835
-    {
836
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
837
-        if ( ! empty($incompatible_addons)) {
838
-            $active_plugins = get_option('active_plugins', array());
839
-            foreach ($active_plugins as $active_plugin) {
840
-                foreach ($incompatible_addons as $incompatible_addon) {
841
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
842
-                        unset($_GET['activate']);
843
-                        espresso_deactivate_plugin($active_plugin);
844
-                    }
845
-                }
846
-            }
847
-        }
848
-    }
849
-
850
-
851
-
852
-    /**
853
-     *    perform_activations_upgrades_and_migrations
854
-     *
855
-     * @access public
856
-     * @return    void
857
-     */
858
-    public function perform_activations_upgrades_and_migrations()
859
-    {
860
-        //first check if we had previously attempted to setup EE's directories but failed
861
-        if (EEH_Activation::upload_directories_incomplete()) {
862
-            EEH_Activation::create_upload_directories();
863
-        }
864
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
865
-    }
866
-
867
-
868
-
869
-    /**
870
-     *    load_CPTs_and_session
871
-     *
872
-     * @access public
873
-     * @return    void
874
-     */
875
-    public function load_CPTs_and_session()
876
-    {
877
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
878
-        // register Custom Post Types
879
-        $this->registry->load_core('Register_CPTs');
880
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
881
-    }
882
-
883
-
884
-
885
-    /**
886
-     * load_controllers
887
-     * this is the best place to load any additional controllers that needs access to EE core.
888
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
889
-     * time
890
-     *
891
-     * @access public
892
-     * @return void
893
-     */
894
-    public function load_controllers()
895
-    {
896
-        do_action('AHEE__EE_System__load_controllers__start');
897
-        // let's get it started
898
-        if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
899
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
900
-            $this->registry->load_core('Front_Controller');
901
-        } else if ( ! EE_FRONT_AJAX) {
902
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
903
-            EE_Registry::instance()->load_core('Admin');
904
-        }
905
-        do_action('AHEE__EE_System__load_controllers__complete');
906
-    }
907
-
908
-
909
-
910
-    /**
911
-     * core_loaded_and_ready
912
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
913
-     *
914
-     * @access public
915
-     * @return void
916
-     */
917
-    public function core_loaded_and_ready()
918
-    {
919
-        do_action('AHEE__EE_System__core_loaded_and_ready');
920
-        // load_espresso_template_tags
921
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
922
-            require_once(EE_PUBLIC . 'template_tags.php');
923
-        }
924
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
925
-        $this->registry->load_core('Session');
926
-        $this->registry->create('EventEspresso\core\services\assets\Registry');
927
-        wp_enqueue_script('espresso_core');
928
-    }
929
-
930
-
931
-
932
-    /**
933
-     * initialize
934
-     * this is the best place to begin initializing client code
935
-     *
936
-     * @access public
937
-     * @return void
938
-     */
939
-    public function initialize()
940
-    {
941
-        do_action('AHEE__EE_System__initialize');
942
-    }
943
-
944
-
945
-
946
-    /**
947
-     * initialize_last
948
-     * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
949
-     * initialize has done so
950
-     *
951
-     * @access public
952
-     * @return void
953
-     */
954
-    public function initialize_last()
955
-    {
956
-        do_action('AHEE__EE_System__initialize_last');
957
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
958
-    }
959
-
960
-
961
-
962
-    /**
963
-     * @return void
964
-     */
965
-    public function addEspressoToolbar()
966
-    {
967
-        $this->registry->create(
968
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
969
-            array($this->registry->CAP)
970
-        );
971
-    }
972
-
973
-
974
-
975
-    /**
976
-     * do_not_cache
977
-     * sets no cache headers and defines no cache constants for WP plugins
978
-     *
979
-     * @access public
980
-     * @return void
981
-     */
982
-    public static function do_not_cache()
983
-    {
984
-        // set no cache constants
985
-        if ( ! defined('DONOTCACHEPAGE')) {
986
-            define('DONOTCACHEPAGE', true);
987
-        }
988
-        if ( ! defined('DONOTCACHCEOBJECT')) {
989
-            define('DONOTCACHCEOBJECT', true);
990
-        }
991
-        if ( ! defined('DONOTCACHEDB')) {
992
-            define('DONOTCACHEDB', true);
993
-        }
994
-        // add no cache headers
995
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
996
-        // plus a little extra for nginx and Google Chrome
997
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
998
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
999
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1000
-    }
1001
-
1002
-
1003
-
1004
-    /**
1005
-     *    extra_nocache_headers
1006
-     *
1007
-     * @access    public
1008
-     * @param $headers
1009
-     * @return    array
1010
-     */
1011
-    public static function extra_nocache_headers($headers)
1012
-    {
1013
-        // for NGINX
1014
-        $headers['X-Accel-Expires'] = 0;
1015
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1016
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1017
-        return $headers;
1018
-    }
1019
-
1020
-
1021
-
1022
-    /**
1023
-     *    nocache_headers
1024
-     *
1025
-     * @access    public
1026
-     * @return    void
1027
-     */
1028
-    public static function nocache_headers()
1029
-    {
1030
-        nocache_headers();
1031
-    }
1032
-
1033
-
1034
-
1035
-
1036
-    /**
1037
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1038
-     * never returned with the function.
1039
-     *
1040
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1041
-     * @return array
1042
-     */
1043
-    public function remove_pages_from_wp_list_pages($exclude_array)
1044
-    {
1045
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1046
-    }
21
+	/**
22
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
23
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
24
+	 */
25
+	const req_type_normal = 0;
26
+
27
+	/**
28
+	 * Indicates this is a brand new installation of EE so we should install
29
+	 * tables and default data etc
30
+	 */
31
+	const req_type_new_activation = 1;
32
+
33
+	/**
34
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
35
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
36
+	 * and that default data is setup too
37
+	 */
38
+	const req_type_reactivation = 2;
39
+
40
+	/**
41
+	 * indicates that EE has been upgraded since its previous request.
42
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
43
+	 */
44
+	const req_type_upgrade = 3;
45
+
46
+	/**
47
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
48
+	 */
49
+	const req_type_downgrade = 4;
50
+
51
+	/**
52
+	 * @deprecated since version 4.6.0.dev.006
53
+	 * Now whenever a new_activation is detected the request type is still just
54
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
55
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
56
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
57
+	 * (Specifically, when the migration manager indicates migrations are finished
58
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
59
+	 */
60
+	const req_type_activation_but_not_installed = 5;
61
+
62
+	/**
63
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
64
+	 */
65
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
66
+
67
+
68
+	/**
69
+	 *    instance of the EE_System object
70
+	 *
71
+	 * @var    $_instance
72
+	 * @access    private
73
+	 */
74
+	private static $_instance = null;
75
+
76
+	/**
77
+	 * @type  EE_Registry $Registry
78
+	 * @access    protected
79
+	 */
80
+	protected $registry;
81
+
82
+	/**
83
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
84
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
85
+	 *
86
+	 * @var int
87
+	 */
88
+	private $_req_type;
89
+
90
+	/**
91
+	 * Whether or not there was a non-micro version change in EE core version during this request
92
+	 *
93
+	 * @var boolean
94
+	 */
95
+	private $_major_version_change = false;
96
+
97
+
98
+
99
+	/**
100
+	 * @singleton method used to instantiate class object
101
+	 * @access    public
102
+	 * @param  \EE_Registry $Registry
103
+	 * @return \EE_System
104
+	 */
105
+	public static function instance(EE_Registry $Registry = null)
106
+	{
107
+		// check if class object is instantiated
108
+		if ( ! self::$_instance instanceof EE_System) {
109
+			self::$_instance = new self($Registry);
110
+		}
111
+		return self::$_instance;
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * resets the instance and returns it
118
+	 *
119
+	 * @return EE_System
120
+	 */
121
+	public static function reset()
122
+	{
123
+		self::$_instance->_req_type = null;
124
+		//make sure none of the old hooks are left hanging around
125
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
126
+		//we need to reset the migration manager in order for it to detect DMSs properly
127
+		EE_Data_Migration_Manager::reset();
128
+		self::instance()->detect_activations_or_upgrades();
129
+		self::instance()->perform_activations_upgrades_and_migrations();
130
+		return self::instance();
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 *    sets hooks for running rest of system
137
+	 *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
138
+	 *    starting EE Addons from any other point may lead to problems
139
+	 *
140
+	 * @access private
141
+	 * @param  \EE_Registry $Registry
142
+	 */
143
+	private function __construct(EE_Registry $Registry)
144
+	{
145
+		$this->registry = $Registry;
146
+		do_action('AHEE__EE_System__construct__begin', $this);
147
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
148
+		add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
149
+		// when an ee addon is activated, we want to call the core hook(s) again
150
+		// because the newly-activated addon didn't get a chance to run at all
151
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
152
+		// detect whether install or upgrade
153
+		add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
154
+			3);
155
+		// load EE_Config, EE_Textdomain, etc
156
+		add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
157
+		// load EE_Config, EE_Textdomain, etc
158
+		add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
159
+			array($this, 'register_shortcodes_modules_and_widgets'), 7);
160
+		// you wanna get going? I wanna get going... let's get going!
161
+		add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
162
+		//other housekeeping
163
+		//exclude EE critical pages from wp_list_pages
164
+		add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
165
+		// ALL EE Addons should use the following hook point to attach their initial setup too
166
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
167
+		do_action('AHEE__EE_System__construct__complete', $this);
168
+	}
169
+
170
+
171
+
172
+	/**
173
+	 * load_espresso_addons
174
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
175
+	 * this is hooked into both:
176
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
177
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
178
+	 *    and the WP 'activate_plugin' hookpoint
179
+	 *
180
+	 * @access public
181
+	 * @return void
182
+	 */
183
+	public function load_espresso_addons()
184
+	{
185
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
186
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
187
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
188
+		//load and setup EE_Capabilities
189
+		$this->registry->load_core('Capabilities');
190
+		//caps need to be initialized on every request so that capability maps are set.
191
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
192
+		$this->registry->CAP->init_caps();
193
+		do_action('AHEE__EE_System__load_espresso_addons');
194
+		//if the WP API basic auth plugin isn't already loaded, load it now.
195
+		//We want it for mobile apps. Just include the entire plugin
196
+		//also, don't load the basic auth when a plugin is getting activated, because
197
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
198
+		//and causes a fatal error
199
+		if ( ! function_exists('json_basic_auth_handler')
200
+			 && ! function_exists('json_basic_auth_error')
201
+			 && ! (
202
+				isset($_GET['action'])
203
+				&& in_array($_GET['action'], array('activate', 'activate-selected'))
204
+			)
205
+			 && ! (
206
+				isset($_GET['activate'])
207
+				&& $_GET['activate'] === 'true'
208
+			)
209
+		) {
210
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
211
+		}
212
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * detect_activations_or_upgrades
219
+	 * Checks for activation or upgrade of core first;
220
+	 * then also checks if any registered addons have been activated or upgraded
221
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
222
+	 * which runs during the WP 'plugins_loaded' action at priority 3
223
+	 *
224
+	 * @access public
225
+	 * @return void
226
+	 */
227
+	public function detect_activations_or_upgrades()
228
+	{
229
+		//first off: let's make sure to handle core
230
+		$this->detect_if_activation_or_upgrade();
231
+		foreach ($this->registry->addons as $addon) {
232
+			//detect teh request type for that addon
233
+			$addon->detect_activation_or_upgrade();
234
+		}
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * detect_if_activation_or_upgrade
241
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
242
+	 * and either setting up the DB or setting up maintenance mode etc.
243
+	 *
244
+	 * @access public
245
+	 * @return void
246
+	 */
247
+	public function detect_if_activation_or_upgrade()
248
+	{
249
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
250
+		// load M-Mode class
251
+		$this->registry->load_core('Maintenance_Mode');
252
+		// check if db has been updated, or if its a brand-new installation
253
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
254
+		$request_type = $this->detect_req_type($espresso_db_update);
255
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
256
+		switch ($request_type) {
257
+			case EE_System::req_type_new_activation:
258
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
259
+				$this->_handle_core_version_change($espresso_db_update);
260
+				break;
261
+			case EE_System::req_type_reactivation:
262
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
263
+				$this->_handle_core_version_change($espresso_db_update);
264
+				break;
265
+			case EE_System::req_type_upgrade:
266
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
267
+				//migrations may be required now that we've upgraded
268
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
269
+				$this->_handle_core_version_change($espresso_db_update);
270
+				//				echo "done upgrade";die;
271
+				break;
272
+			case EE_System::req_type_downgrade:
273
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
274
+				//its possible migrations are no longer required
275
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
276
+				$this->_handle_core_version_change($espresso_db_update);
277
+				break;
278
+			case EE_System::req_type_normal:
279
+			default:
280
+				//				$this->_maybe_redirect_to_ee_about();
281
+				break;
282
+		}
283
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * Updates the list of installed versions and sets hooks for
290
+	 * initializing the database later during the request
291
+	 *
292
+	 * @param array $espresso_db_update
293
+	 */
294
+	protected function _handle_core_version_change($espresso_db_update)
295
+	{
296
+		$this->update_list_of_installed_versions($espresso_db_update);
297
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
298
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
299
+			array($this, 'initialize_db_if_no_migrations_required'));
300
+	}
301
+
302
+
303
+
304
+	/**
305
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
306
+	 * information about what versions of EE have been installed and activated,
307
+	 * NOT necessarily the state of the database
308
+	 *
309
+	 * @param null $espresso_db_update
310
+	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
311
+	 *           from the options table
312
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
313
+	 */
314
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
315
+	{
316
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
317
+		if ( ! $espresso_db_update) {
318
+			$espresso_db_update = get_option('espresso_db_update');
319
+		}
320
+		// check that option is an array
321
+		if ( ! is_array($espresso_db_update)) {
322
+			// if option is FALSE, then it never existed
323
+			if ($espresso_db_update === false) {
324
+				// make $espresso_db_update an array and save option with autoload OFF
325
+				$espresso_db_update = array();
326
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
327
+			} else {
328
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
329
+				$espresso_db_update = array($espresso_db_update => array());
330
+				update_option('espresso_db_update', $espresso_db_update);
331
+			}
332
+		} else {
333
+			$corrected_db_update = array();
334
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
335
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
336
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
337
+					//the key is an int, and the value IS NOT an array
338
+					//so it must be numerically-indexed, where values are versions installed...
339
+					//fix it!
340
+					$version_string = $should_be_array;
341
+					$corrected_db_update[$version_string] = array('unknown-date');
342
+				} else {
343
+					//ok it checks out
344
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
345
+				}
346
+			}
347
+			$espresso_db_update = $corrected_db_update;
348
+			update_option('espresso_db_update', $espresso_db_update);
349
+		}
350
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
351
+		return $espresso_db_update;
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * Does the traditional work of setting up the plugin's database and adding default data.
358
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
359
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
360
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
361
+	 * so that it will be done when migrations are finished
362
+	 *
363
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
364
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
365
+	 *                                       This is a resource-intensive job
366
+	 *                                       so we prefer to only do it when necessary
367
+	 * @return void
368
+	 */
369
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
370
+	{
371
+		$request_type = $this->detect_req_type();
372
+		//only initialize system if we're not in maintenance mode.
373
+		if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
374
+			update_option('ee_flush_rewrite_rules', true);
375
+			if ($verify_schema) {
376
+				EEH_Activation::initialize_db_and_folders();
377
+			}
378
+			EEH_Activation::initialize_db_content();
379
+			EEH_Activation::system_initialization();
380
+			if ($initialize_addons_too) {
381
+				$this->initialize_addons();
382
+			}
383
+		} else {
384
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
385
+		}
386
+		if ($request_type === EE_System::req_type_new_activation
387
+			|| $request_type === EE_System::req_type_reactivation
388
+			|| (
389
+				$request_type === EE_System::req_type_upgrade
390
+				&& $this->is_major_version_change()
391
+			)
392
+		) {
393
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
394
+		}
395
+	}
396
+
397
+
398
+
399
+	/**
400
+	 * Initializes the db for all registered addons
401
+	 */
402
+	public function initialize_addons()
403
+	{
404
+		//foreach registered addon, make sure its db is up-to-date too
405
+		foreach ($this->registry->addons as $addon) {
406
+			$addon->initialize_db_if_no_migrations_required();
407
+		}
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
414
+	 *
415
+	 * @param    array  $version_history
416
+	 * @param    string $current_version_to_add version to be added to the version history
417
+	 * @return    boolean success as to whether or not this option was changed
418
+	 */
419
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
420
+	{
421
+		if ( ! $version_history) {
422
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
423
+		}
424
+		if ($current_version_to_add == null) {
425
+			$current_version_to_add = espresso_version();
426
+		}
427
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
428
+		// re-save
429
+		return update_option('espresso_db_update', $version_history);
430
+	}
431
+
432
+
433
+
434
+	/**
435
+	 * Detects if the current version indicated in the has existed in the list of
436
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
437
+	 *
438
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
439
+	 *                                  If not supplied, fetches it from the options table.
440
+	 *                                  Also, caches its result so later parts of the code can also know whether
441
+	 *                                  there's been an update or not. This way we can add the current version to
442
+	 *                                  espresso_db_update, but still know if this is a new install or not
443
+	 * @return int one of the constants on EE_System::req_type_
444
+	 */
445
+	public function detect_req_type($espresso_db_update = null)
446
+	{
447
+		if ($this->_req_type === null) {
448
+			$espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
449
+				: $this->fix_espresso_db_upgrade_option();
450
+			$this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
451
+				'ee_espresso_activation', espresso_version());
452
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
453
+		}
454
+		return $this->_req_type;
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * Returns whether or not there was a non-micro version change (ie, change in either
461
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
462
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
463
+	 *
464
+	 * @param $activation_history
465
+	 * @return bool
466
+	 */
467
+	protected function _detect_major_version_change($activation_history)
468
+	{
469
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
470
+		$previous_version_parts = explode('.', $previous_version);
471
+		$current_version_parts = explode('.', espresso_version());
472
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
473
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
474
+				   || $previous_version_parts[1] !== $current_version_parts[1]
475
+			   );
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * Returns true if either the major or minor version of EE changed during this request.
482
+	 * 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
483
+	 *
484
+	 * @return bool
485
+	 */
486
+	public function is_major_version_change()
487
+	{
488
+		return $this->_major_version_change;
489
+	}
490
+
491
+
492
+
493
+	/**
494
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
495
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
496
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
497
+	 * just activated to (for core that will always be espresso_version())
498
+	 *
499
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
500
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
501
+	 * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
502
+	 *                                                 indicate that this plugin was just activated
503
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
504
+	 *                                                 espresso_version())
505
+	 * @return int one of the constants on EE_System::req_type_*
506
+	 */
507
+	public static function detect_req_type_given_activation_history(
508
+		$activation_history_for_addon,
509
+		$activation_indicator_option_name,
510
+		$version_to_upgrade_to
511
+	) {
512
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
513
+		if ($activation_history_for_addon) {
514
+			//it exists, so this isn't a completely new install
515
+			//check if this version already in that list of previously installed versions
516
+			if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
517
+				//it a version we haven't seen before
518
+				if ($version_is_higher === 1) {
519
+					$req_type = EE_System::req_type_upgrade;
520
+				} else {
521
+					$req_type = EE_System::req_type_downgrade;
522
+				}
523
+				delete_option($activation_indicator_option_name);
524
+			} else {
525
+				// its not an update. maybe a reactivation?
526
+				if (get_option($activation_indicator_option_name, false)) {
527
+					if ($version_is_higher === -1) {
528
+						$req_type = EE_System::req_type_downgrade;
529
+					} elseif ($version_is_higher === 0) {
530
+						//we've seen this version before, but it's an activation. must be a reactivation
531
+						$req_type = EE_System::req_type_reactivation;
532
+					} else {//$version_is_higher === 1
533
+						$req_type = EE_System::req_type_upgrade;
534
+					}
535
+					delete_option($activation_indicator_option_name);
536
+				} else {
537
+					//we've seen this version before and the activation indicate doesn't show it was just activated
538
+					if ($version_is_higher === -1) {
539
+						$req_type = EE_System::req_type_downgrade;
540
+					} elseif ($version_is_higher === 0) {
541
+						//we've seen this version before and it's not an activation. its normal request
542
+						$req_type = EE_System::req_type_normal;
543
+					} else {//$version_is_higher === 1
544
+						$req_type = EE_System::req_type_upgrade;
545
+					}
546
+				}
547
+			}
548
+		} else {
549
+			//brand new install
550
+			$req_type = EE_System::req_type_new_activation;
551
+			delete_option($activation_indicator_option_name);
552
+		}
553
+		return $req_type;
554
+	}
555
+
556
+
557
+
558
+	/**
559
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
560
+	 * the $activation_history_for_addon
561
+	 *
562
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
563
+	 *                                             sometimes containing 'unknown-date'
564
+	 * @param string $version_to_upgrade_to        (current version)
565
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
566
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
567
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
568
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
569
+	 */
570
+	protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
571
+	{
572
+		//find the most recently-activated version
573
+		$most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
574
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
575
+	}
576
+
577
+
578
+
579
+	/**
580
+	 * Gets the most recently active version listed in the activation history,
581
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
582
+	 *
583
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
584
+	 *                                   sometimes containing 'unknown-date'
585
+	 * @return string
586
+	 */
587
+	protected static function _get_most_recently_active_version_from_activation_history($activation_history)
588
+	{
589
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
590
+		$most_recently_active_version = '0.0.0.dev.000';
591
+		if (is_array($activation_history)) {
592
+			foreach ($activation_history as $version => $times_activated) {
593
+				//check there is a record of when this version was activated. Otherwise,
594
+				//mark it as unknown
595
+				if ( ! $times_activated) {
596
+					$times_activated = array('unknown-date');
597
+				}
598
+				if (is_string($times_activated)) {
599
+					$times_activated = array($times_activated);
600
+				}
601
+				foreach ($times_activated as $an_activation) {
602
+					if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
603
+						$most_recently_active_version = $version;
604
+						$most_recently_active_version_activation = $an_activation == 'unknown-date'
605
+							? '1970-01-01 00:00:00' : $an_activation;
606
+					}
607
+				}
608
+			}
609
+		}
610
+		return $most_recently_active_version;
611
+	}
612
+
613
+
614
+
615
+	/**
616
+	 * This redirects to the about EE page after activation
617
+	 *
618
+	 * @return void
619
+	 */
620
+	public function redirect_to_about_ee()
621
+	{
622
+		$notices = EE_Error::get_notices(false);
623
+		//if current user is an admin and it's not an ajax or rest request
624
+		if (
625
+			! (defined('DOING_AJAX') && DOING_AJAX)
626
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
627
+			&& ! isset($notices['errors'])
628
+			&& apply_filters(
629
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
630
+				$this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
631
+			)
632
+		) {
633
+			$query_params = array('page' => 'espresso_about');
634
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
635
+				$query_params['new_activation'] = true;
636
+			}
637
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
638
+				$query_params['reactivation'] = true;
639
+			}
640
+			$url = add_query_arg($query_params, admin_url('admin.php'));
641
+			wp_safe_redirect($url);
642
+			exit();
643
+		}
644
+	}
645
+
646
+
647
+
648
+	/**
649
+	 * load_core_configuration
650
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
651
+	 * which runs during the WP 'plugins_loaded' action at priority 5
652
+	 *
653
+	 * @return void
654
+	 */
655
+	public function load_core_configuration()
656
+	{
657
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
658
+		$this->registry->load_core('EE_Load_Textdomain');
659
+		//load textdomain
660
+		EE_Load_Textdomain::load_textdomain();
661
+		// load and setup EE_Config and EE_Network_Config
662
+		$this->registry->load_core('Config');
663
+		$this->registry->load_core('Network_Config');
664
+		// setup autoloaders
665
+		// enable logging?
666
+		if ($this->registry->CFG->admin->use_full_logging) {
667
+			$this->registry->load_core('Log');
668
+		}
669
+		// check for activation errors
670
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
671
+		if ($activation_errors) {
672
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
673
+			update_option('ee_plugin_activation_errors', false);
674
+		}
675
+		// get model names
676
+		$this->_parse_model_names();
677
+		//load caf stuff a chance to play during the activation process too.
678
+		$this->_maybe_brew_regular();
679
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
680
+	}
681
+
682
+
683
+
684
+	/**
685
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
686
+	 *
687
+	 * @return void
688
+	 */
689
+	private function _parse_model_names()
690
+	{
691
+		//get all the files in the EE_MODELS folder that end in .model.php
692
+		$models = glob(EE_MODELS . '*.model.php');
693
+		$model_names = array();
694
+		$non_abstract_db_models = array();
695
+		foreach ($models as $model) {
696
+			// get model classname
697
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
698
+			$short_name = str_replace('EEM_', '', $classname);
699
+			$reflectionClass = new ReflectionClass($classname);
700
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
701
+				$non_abstract_db_models[$short_name] = $classname;
702
+			}
703
+			$model_names[$short_name] = $classname;
704
+		}
705
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
706
+		$this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
707
+			$non_abstract_db_models);
708
+	}
709
+
710
+
711
+
712
+	/**
713
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
714
+	 * that need to be setup before our EE_System launches.
715
+	 *
716
+	 * @return void
717
+	 */
718
+	private function _maybe_brew_regular()
719
+	{
720
+		if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
721
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
722
+		}
723
+	}
724
+
725
+
726
+
727
+	/**
728
+	 * register_shortcodes_modules_and_widgets
729
+	 * generate lists of shortcodes and modules, then verify paths and classes
730
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
731
+	 * which runs during the WP 'plugins_loaded' action at priority 7
732
+	 *
733
+	 * @access public
734
+	 * @return void
735
+	 */
736
+	public function register_shortcodes_modules_and_widgets()
737
+	{
738
+		try {
739
+			// load, register, and add shortcodes the new way
740
+			new ShortcodesManager(
741
+			// and the old way, but we'll put it under control of the new system
742
+				EE_Config::getLegacyShortcodesManager()
743
+			);
744
+		} catch (Exception $exception) {
745
+			new ExceptionStackTraceDisplay($exception);
746
+		}
747
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
748
+		// check for addons using old hookpoint
749
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
750
+			$this->_incompatible_addon_error();
751
+		}
752
+	}
753
+
754
+
755
+
756
+	/**
757
+	 * _incompatible_addon_error
758
+	 *
759
+	 * @access public
760
+	 * @return void
761
+	 */
762
+	private function _incompatible_addon_error()
763
+	{
764
+		// get array of classes hooking into here
765
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
766
+		if ( ! empty($class_names)) {
767
+			$msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
768
+				'event_espresso');
769
+			$msg .= '<ul>';
770
+			foreach ($class_names as $class_name) {
771
+				$msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
772
+						$class_name) . '</b></li>';
773
+			}
774
+			$msg .= '</ul>';
775
+			$msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
776
+				'event_espresso');
777
+			// save list of incompatible addons to wp-options for later use
778
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
779
+			if (is_admin()) {
780
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
781
+			}
782
+		}
783
+	}
784
+
785
+
786
+
787
+	/**
788
+	 * brew_espresso
789
+	 * begins the process of setting hooks for initializing EE in the correct order
790
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
791
+	 * which runs during the WP 'plugins_loaded' action at priority 9
792
+	 *
793
+	 * @return void
794
+	 */
795
+	public function brew_espresso()
796
+	{
797
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
798
+		// load some final core systems
799
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
800
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
801
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
802
+		add_action('init', array($this, 'load_controllers'), 7);
803
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
804
+		add_action('init', array($this, 'initialize'), 10);
805
+		add_action('init', array($this, 'initialize_last'), 100);
806
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
807
+			// pew pew pew
808
+			$this->registry->load_core('PUE');
809
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
810
+		}
811
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
812
+	}
813
+
814
+
815
+
816
+	/**
817
+	 *    set_hooks_for_core
818
+	 *
819
+	 * @access public
820
+	 * @return    void
821
+	 */
822
+	public function set_hooks_for_core()
823
+	{
824
+		$this->_deactivate_incompatible_addons();
825
+		do_action('AHEE__EE_System__set_hooks_for_core');
826
+	}
827
+
828
+
829
+
830
+	/**
831
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
832
+	 * deactivates any addons considered incompatible with the current version of EE
833
+	 */
834
+	private function _deactivate_incompatible_addons()
835
+	{
836
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
837
+		if ( ! empty($incompatible_addons)) {
838
+			$active_plugins = get_option('active_plugins', array());
839
+			foreach ($active_plugins as $active_plugin) {
840
+				foreach ($incompatible_addons as $incompatible_addon) {
841
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
842
+						unset($_GET['activate']);
843
+						espresso_deactivate_plugin($active_plugin);
844
+					}
845
+				}
846
+			}
847
+		}
848
+	}
849
+
850
+
851
+
852
+	/**
853
+	 *    perform_activations_upgrades_and_migrations
854
+	 *
855
+	 * @access public
856
+	 * @return    void
857
+	 */
858
+	public function perform_activations_upgrades_and_migrations()
859
+	{
860
+		//first check if we had previously attempted to setup EE's directories but failed
861
+		if (EEH_Activation::upload_directories_incomplete()) {
862
+			EEH_Activation::create_upload_directories();
863
+		}
864
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
865
+	}
866
+
867
+
868
+
869
+	/**
870
+	 *    load_CPTs_and_session
871
+	 *
872
+	 * @access public
873
+	 * @return    void
874
+	 */
875
+	public function load_CPTs_and_session()
876
+	{
877
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
878
+		// register Custom Post Types
879
+		$this->registry->load_core('Register_CPTs');
880
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
881
+	}
882
+
883
+
884
+
885
+	/**
886
+	 * load_controllers
887
+	 * this is the best place to load any additional controllers that needs access to EE core.
888
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
889
+	 * time
890
+	 *
891
+	 * @access public
892
+	 * @return void
893
+	 */
894
+	public function load_controllers()
895
+	{
896
+		do_action('AHEE__EE_System__load_controllers__start');
897
+		// let's get it started
898
+		if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
899
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
900
+			$this->registry->load_core('Front_Controller');
901
+		} else if ( ! EE_FRONT_AJAX) {
902
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
903
+			EE_Registry::instance()->load_core('Admin');
904
+		}
905
+		do_action('AHEE__EE_System__load_controllers__complete');
906
+	}
907
+
908
+
909
+
910
+	/**
911
+	 * core_loaded_and_ready
912
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
913
+	 *
914
+	 * @access public
915
+	 * @return void
916
+	 */
917
+	public function core_loaded_and_ready()
918
+	{
919
+		do_action('AHEE__EE_System__core_loaded_and_ready');
920
+		// load_espresso_template_tags
921
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
922
+			require_once(EE_PUBLIC . 'template_tags.php');
923
+		}
924
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
925
+		$this->registry->load_core('Session');
926
+		$this->registry->create('EventEspresso\core\services\assets\Registry');
927
+		wp_enqueue_script('espresso_core');
928
+	}
929
+
930
+
931
+
932
+	/**
933
+	 * initialize
934
+	 * this is the best place to begin initializing client code
935
+	 *
936
+	 * @access public
937
+	 * @return void
938
+	 */
939
+	public function initialize()
940
+	{
941
+		do_action('AHEE__EE_System__initialize');
942
+	}
943
+
944
+
945
+
946
+	/**
947
+	 * initialize_last
948
+	 * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
949
+	 * initialize has done so
950
+	 *
951
+	 * @access public
952
+	 * @return void
953
+	 */
954
+	public function initialize_last()
955
+	{
956
+		do_action('AHEE__EE_System__initialize_last');
957
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
958
+	}
959
+
960
+
961
+
962
+	/**
963
+	 * @return void
964
+	 */
965
+	public function addEspressoToolbar()
966
+	{
967
+		$this->registry->create(
968
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
969
+			array($this->registry->CAP)
970
+		);
971
+	}
972
+
973
+
974
+
975
+	/**
976
+	 * do_not_cache
977
+	 * sets no cache headers and defines no cache constants for WP plugins
978
+	 *
979
+	 * @access public
980
+	 * @return void
981
+	 */
982
+	public static function do_not_cache()
983
+	{
984
+		// set no cache constants
985
+		if ( ! defined('DONOTCACHEPAGE')) {
986
+			define('DONOTCACHEPAGE', true);
987
+		}
988
+		if ( ! defined('DONOTCACHCEOBJECT')) {
989
+			define('DONOTCACHCEOBJECT', true);
990
+		}
991
+		if ( ! defined('DONOTCACHEDB')) {
992
+			define('DONOTCACHEDB', true);
993
+		}
994
+		// add no cache headers
995
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
996
+		// plus a little extra for nginx and Google Chrome
997
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
998
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
999
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1000
+	}
1001
+
1002
+
1003
+
1004
+	/**
1005
+	 *    extra_nocache_headers
1006
+	 *
1007
+	 * @access    public
1008
+	 * @param $headers
1009
+	 * @return    array
1010
+	 */
1011
+	public static function extra_nocache_headers($headers)
1012
+	{
1013
+		// for NGINX
1014
+		$headers['X-Accel-Expires'] = 0;
1015
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1016
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1017
+		return $headers;
1018
+	}
1019
+
1020
+
1021
+
1022
+	/**
1023
+	 *    nocache_headers
1024
+	 *
1025
+	 * @access    public
1026
+	 * @return    void
1027
+	 */
1028
+	public static function nocache_headers()
1029
+	{
1030
+		nocache_headers();
1031
+	}
1032
+
1033
+
1034
+
1035
+
1036
+	/**
1037
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1038
+	 * never returned with the function.
1039
+	 *
1040
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1041
+	 * @return array
1042
+	 */
1043
+	public function remove_pages_from_wp_list_pages($exclude_array)
1044
+	{
1045
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1046
+	}
1047 1047
 
1048 1048
 
1049 1049
 
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
     {
185 185
         // set autoloaders for all of the classes implementing EEI_Plugin_API
186 186
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
187
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
187
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
188 188
         //load and setup EE_Capabilities
189 189
         $this->registry->load_core('Capabilities');
190 190
         //caps need to be initialized on every request so that capability maps are set.
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
                 && $_GET['activate'] === 'true'
208 208
             )
209 209
         ) {
210
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
210
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
211 211
         }
212 212
         do_action('AHEE__EE_System__load_espresso_addons__complete');
213 213
     }
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
     private function _parse_model_names()
690 690
     {
691 691
         //get all the files in the EE_MODELS folder that end in .model.php
692
-        $models = glob(EE_MODELS . '*.model.php');
692
+        $models = glob(EE_MODELS.'*.model.php');
693 693
         $model_names = array();
694 694
         $non_abstract_db_models = array();
695 695
         foreach ($models as $model) {
@@ -717,8 +717,8 @@  discard block
 block discarded – undo
717 717
      */
718 718
     private function _maybe_brew_regular()
719 719
     {
720
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
721
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
720
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
721
+            require_once EE_CAFF_PATH.'brewing_regular.php';
722 722
         }
723 723
     }
724 724
 
@@ -768,8 +768,8 @@  discard block
 block discarded – undo
768 768
                 'event_espresso');
769 769
             $msg .= '<ul>';
770 770
             foreach ($class_names as $class_name) {
771
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
772
-                        $class_name) . '</b></li>';
771
+                $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
772
+                        $class_name).'</b></li>';
773 773
             }
774 774
             $msg .= '</ul>';
775 775
             $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
@@ -918,8 +918,8 @@  discard block
 block discarded – undo
918 918
     {
919 919
         do_action('AHEE__EE_System__core_loaded_and_ready');
920 920
         // load_espresso_template_tags
921
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
922
-            require_once(EE_PUBLIC . 'template_tags.php');
921
+        if (is_readable(EE_PUBLIC.'template_tags.php')) {
922
+            require_once(EE_PUBLIC.'template_tags.php');
923 923
         }
924 924
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
925 925
         $this->registry->load_core('Session');
Please login to merge, or discard this patch.