Completed
Branch BUG-10236-refresh-fix-reset-ca... (5231fa)
by
unknown
14:37 queued 17s
created
core/libraries/payment_methods/EE_PMT_Base.lib.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 			$this->_gateway->set_template_helper( new EEH_Template() );
107 107
 			$this->_gateway->set_line_item_helper( new EEH_Line_Item() );
108 108
 			$this->_gateway->set_money_helper( new EEH_Money() );
109
-            $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
110
-            $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
111
-            do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway);
109
+			$this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
110
+			$this->_gateway->set_unsupported_character_remover(new AsciiOnly());
111
+			do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway);
112 112
 		}
113 113
 		if ( ! isset( $this->_has_billing_form ) ) {
114 114
 			// by default, On Site gateways have a billing form
@@ -281,17 +281,17 @@  discard block
 block discarded – undo
281 281
 		//if we know who the attendee is, and this is a billing form
282 282
 		//that uses attendee info, populate it
283 283
 		if (
284
-            apply_filters(
285
-                'FHEE__populate_billing_form_fields_from_attendee',
286
-                (
287
-                    $this->_billing_form instanceof EE_Billing_Attendee_Info_Form
288
-                    && $transaction instanceof EE_Transaction
289
-                    && $transaction->primary_registration() instanceof EE_Registration
290
-                    && $transaction->primary_registration()->attendee() instanceof EE_Attendee
291
-                ),
292
-                $this->_billing_form,
293
-                $transaction
294
-            )
284
+			apply_filters(
285
+				'FHEE__populate_billing_form_fields_from_attendee',
286
+				(
287
+					$this->_billing_form instanceof EE_Billing_Attendee_Info_Form
288
+					&& $transaction instanceof EE_Transaction
289
+					&& $transaction->primary_registration() instanceof EE_Registration
290
+					&& $transaction->primary_registration()->attendee() instanceof EE_Attendee
291
+				),
292
+				$this->_billing_form,
293
+				$transaction
294
+			)
295 295
 		){
296 296
 			$this->_billing_form->populate_from_attendee( $transaction->primary_registration()->attendee() );
297 297
 		}
@@ -703,11 +703,11 @@  discard block
 block discarded – undo
703 703
 	 * @return string
704 704
 	 */
705 705
 	public function cap_name(){
706
-	    /** @var EE_Payment_Method_Manager $payment_method_manager */
707
-	    $payment_method_manager = EE_Registry::instance()->load_lib('Payment_Method_Manager');
708
-	    if ($payment_method_manager instanceof EE_Payment_Method_Manager) {
709
-	        return $payment_method_manager->capability_slug_for_payment_method_name($this->system_name());
710
-        }
706
+		/** @var EE_Payment_Method_Manager $payment_method_manager */
707
+		$payment_method_manager = EE_Registry::instance()->load_lib('Payment_Method_Manager');
708
+		if ($payment_method_manager instanceof EE_Payment_Method_Manager) {
709
+			return $payment_method_manager->capability_slug_for_payment_method_name($this->system_name());
710
+		}
711 711
 		return 'ee_payment_method_' . strtolower( $this->system_name() );
712 712
 	}
713 713
 
Please login to merge, or discard this patch.
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @since 				$VID:$
17 17
  *
18 18
  */
19
-abstract class EE_PMT_Base{
19
+abstract class EE_PMT_Base {
20 20
 
21 21
 	const onsite = 'on-site';
22 22
 	const offsite = 'off-site';
@@ -97,34 +97,34 @@  discard block
 block discarded – undo
97 97
 	 * @return EE_PMT_Base
98 98
 	 */
99 99
 	function __construct($pm_instance = NULL) {
100
-		if ( $pm_instance instanceof EE_Payment_Method ){
100
+		if ($pm_instance instanceof EE_Payment_Method) {
101 101
 			$this->set_instance($pm_instance);
102 102
 		}
103
-		if($this->_gateway){
104
-			$this->_gateway->set_payment_model( EEM_Payment::instance() );
105
-			$this->_gateway->set_payment_log( EEM_Change_Log::instance() );
106
-			$this->_gateway->set_template_helper( new EEH_Template() );
107
-			$this->_gateway->set_line_item_helper( new EEH_Line_Item() );
108
-			$this->_gateway->set_money_helper( new EEH_Money() );
103
+		if ($this->_gateway) {
104
+			$this->_gateway->set_payment_model(EEM_Payment::instance());
105
+			$this->_gateway->set_payment_log(EEM_Change_Log::instance());
106
+			$this->_gateway->set_template_helper(new EEH_Template());
107
+			$this->_gateway->set_line_item_helper(new EEH_Line_Item());
108
+			$this->_gateway->set_money_helper(new EEH_Money());
109 109
             $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
110 110
             $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
111
-            do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway);
111
+            do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
112 112
 		}
113
-		if ( ! isset( $this->_has_billing_form ) ) {
113
+		if ( ! isset($this->_has_billing_form)) {
114 114
 			// by default, On Site gateways have a billing form
115
-			if ( $this->payment_occurs() == EE_PMT_Base::onsite ) {
116
-				$this->set_has_billing_form( true );
115
+			if ($this->payment_occurs() == EE_PMT_Base::onsite) {
116
+				$this->set_has_billing_form(true);
117 117
 			} else {
118
-				$this->set_has_billing_form( false );
118
+				$this->set_has_billing_form(false);
119 119
 			}
120 120
 		}
121 121
 
122
-		if( ! $this->_pretty_name){
122
+		if ( ! $this->_pretty_name) {
123 123
 			throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
124 124
 		}
125 125
 		//if the child didn't specify a default button, use the credit card one
126
-		if( $this->_default_button_url === NULL){
127
-			$this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
126
+		if ($this->_default_button_url === NULL) {
127
+			$this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods'.DS.'pay-by-credit-card.png';
128 128
 		}
129 129
 	}
130 130
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 	/**
134 134
 	 * @param boolean $has_billing_form
135 135
 	 */
136
-	public function set_has_billing_form( $has_billing_form ) {
137
-		$this->_has_billing_form = filter_var( $has_billing_form, FILTER_VALIDATE_BOOLEAN );
136
+	public function set_has_billing_form($has_billing_form) {
137
+		$this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
138 138
 	}
139 139
 
140 140
 
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
 	/**
143 143
 	 * sets the file_folder property
144 144
 	 */
145
-	protected function _set_file_folder(){
145
+	protected function _set_file_folder() {
146 146
 		$reflector = new ReflectionClass(get_class($this));
147 147
 		$fn = $reflector->getFileName();
148
-		$this->_file_folder =  dirname($fn).DS;
148
+		$this->_file_folder = dirname($fn).DS;
149 149
 	}
150 150
 
151 151
 
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 	/**
154 154
 	 * sets the file URL with a trailing slash for this PMT
155 155
 	 */
156
-	protected function _set_file_url(){
157
-		$plugins_dir_fixed = str_replace('\\',DS,WP_PLUGIN_DIR);
158
-		$file_folder_fixed = str_replace('\\',DS,$this->file_folder());
159
-		$file_path = str_replace($plugins_dir_fixed,WP_PLUGIN_URL,$file_folder_fixed);
156
+	protected function _set_file_url() {
157
+		$plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
158
+		$file_folder_fixed = str_replace('\\', DS, $this->file_folder());
159
+		$file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
160 160
 		$this->_file_url = $file_path;
161 161
 	}
162 162
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * Gets the default description on all payment methods of this type
165 165
 	 * @return string
166 166
 	 */
167
-	public function default_description(){
167
+	public function default_description() {
168 168
 		return $this->_default_description;
169 169
 	}
170 170
 
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
 	 * Returns the folder containing the PMT child class, with a trailing slash
175 175
 	 * @return string
176 176
 	 */
177
-	public function file_folder(){
178
-		if( ! $this->_file_folder ) {
177
+	public function file_folder() {
178
+		if ( ! $this->_file_folder) {
179 179
 			$this->_set_file_folder();
180 180
 		}
181 181
 		return $this->_file_folder;
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	/**
187 187
 	 * @return string
188 188
 	 */
189
-	public function file_url(){
190
-		if( ! $this->_file_url ) {
189
+	public function file_url() {
190
+		if ( ! $this->_file_url) {
191 191
 			$this->_set_file_url();
192 192
 		}
193 193
 		return $this->_file_url;
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
 	 * Its important teh payment method instance is set before
201 201
 	 * @param EE_Payment_Method $payment_method_instance
202 202
 	 */
203
-	function set_instance($payment_method_instance){
203
+	function set_instance($payment_method_instance) {
204 204
 		$this->_pm_instance = $payment_method_instance;
205 205
 		//if they have already requested the settings form, make sure its
206 206
 		//data matches this model object
207
-		if($this->_settings_form){
207
+		if ($this->_settings_form) {
208 208
 			$this->settings_form()->populate_model_obj($payment_method_instance);
209 209
 		}
210
-		if($this->_gateway && $this->_gateway instanceof EE_Gateway){
210
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
211 211
 			$this->_gateway->set_settings($payment_method_instance->settings_array());
212 212
 		}
213 213
 	}
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
 	 * Gets teh form for displaying to admins where they setup the payment method
219 219
 	 * @return EE_Payment_Method_Form
220 220
 	 */
221
-	function settings_form(){
222
-		if( ! $this->_settings_form){
221
+	function settings_form() {
222
+		if ( ! $this->_settings_form) {
223 223
 			$this->_settings_form = $this->generate_new_settings_form();
224
-			$this->_settings_form->set_payment_method_type( $this );
224
+			$this->_settings_form->set_payment_method_type($this);
225 225
 			//if we have already assigned a model object to this pmt, make
226 226
 			//sure its reflected in teh form we just generated
227
-			if($this->_pm_instance){
227
+			if ($this->_pm_instance) {
228 228
 				$this->_settings_form->populate_model_obj($this->_pm_instance);
229 229
 			}
230 230
 		}
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 * this payment method type's settings form later in the request
251 251
 	 * @param EE_Payment_Method_Form $form
252 252
 	 */
253
-	public function set_settings_form($form){
253
+	public function set_settings_form($form) {
254 254
 		$this->_settings_form = $form;
255 255
 	}
256 256
 
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
 	 * @param array $extra_args
274 274
 	 * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
275 275
 	 */
276
-	public function billing_form( EE_Transaction $transaction = NULL, $extra_args = array() ){
276
+	public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) {
277 277
 		// has billing form already been regenerated ? or overwrite cache?
278
-		if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form ){
279
-			$this->_billing_form = $this->generate_new_billing_form( $transaction, $extra_args );
278
+		if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
279
+			$this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
280 280
 		}
281 281
 		//if we know who the attendee is, and this is a billing form
282 282
 		//that uses attendee info, populate it
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
                 $this->_billing_form,
293 293
                 $transaction
294 294
             )
295
-		){
296
-			$this->_billing_form->populate_from_attendee( $transaction->primary_registration()->attendee() );
295
+		) {
296
+			$this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
297 297
 		}
298 298
 		return $this->_billing_form;
299 299
 	}
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @param \EE_Transaction $transaction
305 305
 	 * @return \EE_Billing_Info_Form
306 306
 	 */
307
-	abstract function generate_new_billing_form( EE_Transaction $transaction = NULL );
307
+	abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
308 308
 
309 309
 
310 310
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 * @param \EE_Billing_Info_Form $billing_form
316 316
 	 * @return \EE_Billing_Info_Form
317 317
 	 */
318
-	public function apply_billing_form_debug_settings( EE_Billing_Info_Form $billing_form ) {
318
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) {
319 319
 		return $billing_form;
320 320
 	}
321 321
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 * if you have form
327 327
 	 * @param EE_Payment_Method $form
328 328
 	 */
329
-	public function set_billing_form($form){
329
+	public function set_billing_form($form) {
330 330
 		$this->_billing_form = $form;
331 331
 	}
332 332
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 	 * Returns whether or not this payment method requires HTTPS to be used
337 337
 	 * @return boolean
338 338
 	 */
339
-	function requires_https(){
339
+	function requires_https() {
340 340
 		return $this->_requires_https;
341 341
 	}
342 342
 
@@ -354,9 +354,9 @@  discard block
 block discarded – undo
354 354
 	 * @return EE_Payment
355 355
 	 * @throws EE_Error
356 356
 	 */
357
-	function process_payment( EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null,$fail_url = '', $method = 'CART', $by_admin = false ){
357
+	function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false) {
358 358
 		// @todo: add surcharge for the payment method, if any
359
-		if ( $this->_gateway ) {
359
+		if ($this->_gateway) {
360 360
 			//there is a gateway, so we're going to make a payment object
361 361
 			//but wait! do they already have a payment in progress that we thought was failed?
362 362
 			$duplicate_properties = array(
@@ -367,10 +367,10 @@  discard block
 block discarded – undo
367 367
 				'PAY_amount' 					=> $amount !== null ? $amount : $transaction->remaining(),
368 368
 				'PAY_gateway_response' 	=> null,
369 369
 			);
370
-			$payment = EEM_Payment::instance()->get_one( array( $duplicate_properties ));
370
+			$payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
371 371
 			//if we didn't already have a payment in progress for the same thing,
372 372
 			//then we actually want to make a new payment
373
-			if ( ! $payment instanceof EE_Payment ){
373
+			if ( ! $payment instanceof EE_Payment) {
374 374
 				$payment = EE_Payment::new_instance(
375 375
 					array_merge(
376 376
 						$duplicate_properties,
@@ -386,10 +386,10 @@  discard block
 block discarded – undo
386 386
 			}
387 387
 			//make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
388 388
 			$payment->save();
389
-			$billing_values = $this->_get_billing_values_from_form( $billing_info );
389
+			$billing_values = $this->_get_billing_values_from_form($billing_info);
390 390
 
391 391
 			//  Offsite Gateway
392
-			if( $this->_gateway instanceof EE_Offsite_Gateway ){
392
+			if ($this->_gateway instanceof EE_Offsite_Gateway) {
393 393
 
394 394
 				$payment = $this->_gateway->set_redirection_info(
395 395
 					$payment,
@@ -405,17 +405,17 @@  discard block
 block discarded – undo
405 405
 				);
406 406
 				$payment->save();
407 407
 			//  Onsite Gateway
408
-			} elseif ( $this->_gateway instanceof EE_Onsite_Gateway ) {
408
+			} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
409 409
 
410
-				$payment = $this->_gateway->do_direct_payment($payment,$billing_values);
410
+				$payment = $this->_gateway->do_direct_payment($payment, $billing_values);
411 411
 				$payment->save();
412 412
 
413 413
 			} else {
414 414
 				throw new EE_Error(
415 415
 					sprintf(
416
-						__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso' ),
416
+						__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'),
417 417
 						get_class($this),
418
-						gettype( $this->_gateway )
418
+						gettype($this->_gateway)
419 419
 					)
420 420
 				);
421 421
 			}
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
 		}
438 438
 
439 439
 		// if there is billing info, clean it and save it now
440
-		if( $billing_info instanceof EE_Billing_Attendee_Info_Form ){
441
-			$this->_save_billing_info_to_attendee( $billing_info, $transaction );
440
+		if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
441
+			$this->_save_billing_info_to_attendee($billing_info, $transaction);
442 442
 		}
443 443
 
444 444
 		return $payment;
@@ -451,10 +451,10 @@  discard block
 block discarded – undo
451 451
 	 * @param EE_Billing_Info_Form $billing_form
452 452
 	 * @return array
453 453
 	 */
454
-	protected function _get_billing_values_from_form( $billing_form ){
455
-		if($billing_form instanceof EE_Form_Section_Proper ){
456
-			return $billing_form->input_pretty_values( true );
457
-		}else{
454
+	protected function _get_billing_values_from_form($billing_form) {
455
+		if ($billing_form instanceof EE_Form_Section_Proper) {
456
+			return $billing_form->input_pretty_values(true);
457
+		} else {
458 458
 			return NULL;
459 459
 		}
460 460
 	}
@@ -468,13 +468,13 @@  discard block
 block discarded – undo
468 468
 	 * @return EE_Payment
469 469
 	 * @throws EE_Error
470 470
 	 */
471
-	public function handle_ipn($req_data,$transaction){
471
+	public function handle_ipn($req_data, $transaction) {
472 472
 		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
473
-		if( ! $this->_gateway instanceof EE_Offsite_Gateway){
474
-			throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r( $this->_gateway, TRUE )));
473
+		if ( ! $this->_gateway instanceof EE_Offsite_Gateway) {
474
+			throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
475 475
 
476 476
 		}
477
-		$payment = $this->_gateway->handle_payment_update( $req_data, $transaction );
477
+		$payment = $this->_gateway->handle_payment_update($req_data, $transaction);
478 478
 		return $payment;
479 479
 	}
480 480
 
@@ -487,22 +487,22 @@  discard block
 block discarded – undo
487 487
 	 * @param EE_Transaction $transaction
488 488
 	 * @return boolean success
489 489
 	 */
490
-	protected function _save_billing_info_to_attendee($billing_form, $transaction){
491
-		if( ! $transaction || ! $transaction instanceof EE_Transaction){
490
+	protected function _save_billing_info_to_attendee($billing_form, $transaction) {
491
+		if ( ! $transaction || ! $transaction instanceof EE_Transaction) {
492 492
 			EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
493 493
 			return false;
494 494
 		}
495 495
 		$primary_reg = $transaction->primary_registration();
496
-		if( ! $primary_reg ){
496
+		if ( ! $primary_reg) {
497 497
 			EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
498 498
 			return false;
499 499
 		}
500 500
 		$attendee = $primary_reg->attendee();
501
-		if( ! $attendee ){
501
+		if ( ! $attendee) {
502 502
 			EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
503 503
 			return false;
504 504
 		}
505
-		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method() );
505
+		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
506 506
 
507 507
 	}
508 508
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 	 * @param array $req_data
516 516
 	 * @return EE_Payment
517 517
 	 */
518
-	protected function find_payment_for_ipn( EE_Transaction $transaction, $req_data = array() ){
518
+	protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) {
519 519
 		return $transaction->last_payment();
520 520
 	}
521 521
 
@@ -532,8 +532,8 @@  discard block
 block discarded – undo
532 532
 	 * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
533 533
 	 * @throws EE_Error
534 534
 	 */
535
-	public function handle_unclaimed_ipn( $req_data = array() ){
536
-		throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this) ));
535
+	public function handle_unclaimed_ipn($req_data = array()) {
536
+		throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
537 537
 	}
538 538
 
539 539
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 	 * @param EE_Transaction $transaction
550 550
 	 * @return EE_Payment
551 551
 	 */
552
-	public function finalize_payment_for($transaction){
552
+	public function finalize_payment_for($transaction) {
553 553
 		return $transaction->last_payment();
554 554
 	}
555 555
 
@@ -559,10 +559,10 @@  discard block
 block discarded – undo
559 559
 	 * Whether or not this payment method's gateway supports sending refund requests
560 560
 	 * @return boolean
561 561
 	 */
562
-	public function supports_sending_refunds(){
563
-		if($this->_gateway && $this->_gateway instanceof EE_Gateway){
562
+	public function supports_sending_refunds() {
563
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
564 564
 			return $this->_gateway->supports_sending_refunds();
565
-		}else{
565
+		} else {
566 566
 			return false;
567 567
 		}
568 568
 	}
@@ -576,14 +576,14 @@  discard block
 block discarded – undo
576 576
 	 * @throws EE_Error
577 577
 	 * @return EE_Payment
578 578
 	 */
579
-	public function process_refund( EE_Payment $payment, $refund_info = array()){
580
-		if ( $this->_gateway && $this->_gateway instanceof EE_Gateway ) {
581
-			return $this->_gateway->do_direct_refund( $payment, $refund_info );
579
+	public function process_refund(EE_Payment $payment, $refund_info = array()) {
580
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
581
+			return $this->_gateway->do_direct_refund($payment, $refund_info);
582 582
 		} else {
583 583
 			throw new EE_Error(
584 584
 				sprintf(
585
-					__( 'Payment Method Type "%s" does not support sending refund requests', 'event_espresso' ),
586
-					get_class( $this )
585
+					__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
586
+					get_class($this)
587 587
 				)
588 588
 			);
589 589
 		}
@@ -597,15 +597,15 @@  discard block
 block discarded – undo
597 597
 	 * @return string
598 598
 	 * @throws EE_Error
599 599
 	 */
600
-	public function payment_occurs(){
601
-		if( ! $this->_gateway){
600
+	public function payment_occurs() {
601
+		if ( ! $this->_gateway) {
602 602
 			return EE_PMT_Base::offline;
603
-		}elseif($this->_gateway instanceof EE_Onsite_Gateway){
603
+		}elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
604 604
 			return EE_PMT_Base::onsite;
605
-		}elseif($this->_gateway instanceof EE_Offsite_Gateway){
605
+		}elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
606 606
 			return EE_PMT_Base::offsite;
607
-		}else{
608
-			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"),get_class($this)));
607
+		} else {
608
+			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this)));
609 609
 		}
610 610
 	}
611 611
 
@@ -618,8 +618,8 @@  discard block
 block discarded – undo
618 618
 	 * @param EE_Payment $payment
619 619
 	 * @return string
620 620
 	 */
621
-	public function payment_overview_content(EE_Payment $payment){
622
-		return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance,'payment'=>$payment) , true);
621
+	public function payment_overview_content(EE_Payment $payment) {
622
+		return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance, 'payment'=>$payment), true);
623 623
 	}
624 624
 
625 625
 
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 	 *	@type array $template_args any arguments you want passed to the template file while rendering.
633 633
 	 *				Keys will be variable names and values with be their values.
634 634
 	 */
635
-	public function help_tabs_config(){
635
+	public function help_tabs_config() {
636 636
 		return array();
637 637
 	}
638 638
 
@@ -643,9 +643,9 @@  discard block
 block discarded – undo
643 643
 	 * the payment method's table's PMT_type column)
644 644
 	 * @return string
645 645
 	 */
646
-	public function system_name(){
646
+	public function system_name() {
647 647
 		$classname = get_class($this);
648
-		return str_replace("EE_PMT_",'',$classname);
648
+		return str_replace("EE_PMT_", '', $classname);
649 649
 	}
650 650
 
651 651
 
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	 * A pretty i18n version of the PMT name
655 655
 	 * @return string
656 656
 	 */
657
-	public function pretty_name(){
657
+	public function pretty_name() {
658 658
 		return $this->_pretty_name;
659 659
 	}
660 660
 
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 	 * Gets the default absolute URL to the payment method type's button
665 665
 	 * @return string
666 666
 	 */
667
-	public function default_button_url(){
667
+	public function default_button_url() {
668 668
 		return $this->_default_button_url;
669 669
 	}
670 670
 
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
 	 * Gets the gateway used by this payment method (if any)
675 675
 	 * @return EE_Gateway
676 676
 	 */
677
-	public function get_gateway(){
677
+	public function get_gateway() {
678 678
 		return $this->_gateway;
679 679
 	}
680 680
 
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
 	/**
684 684
 	 * @return string html for the link to a help tab
685 685
 	 */
686
-	public function get_help_tab_link(){
687
-		return EEH_Template::get_help_tab_link( $this->get_help_tab_name() );
686
+	public function get_help_tab_link() {
687
+		return EEH_Template::get_help_tab_link($this->get_help_tab_name());
688 688
 	}
689 689
 
690 690
 
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 	 * Returns the name of the help tab for this PMT
694 694
 	 * @return string
695 695
 	 */
696
-	public function get_help_tab_name(){
697
-		return 'ee_' . strtolower( $this->system_name() ) . '_help_tab';
696
+	public function get_help_tab_name() {
697
+		return 'ee_'.strtolower($this->system_name()).'_help_tab';
698 698
 	}
699 699
 
700 700
 	/**
@@ -702,13 +702,13 @@  discard block
 block discarded – undo
702 702
 	 * this PMT by an admin
703 703
 	 * @return string
704 704
 	 */
705
-	public function cap_name(){
705
+	public function cap_name() {
706 706
 	    /** @var EE_Payment_Method_Manager $payment_method_manager */
707 707
 	    $payment_method_manager = EE_Registry::instance()->load_lib('Payment_Method_Manager');
708 708
 	    if ($payment_method_manager instanceof EE_Payment_Method_Manager) {
709 709
 	        return $payment_method_manager->capability_slug_for_payment_method_name($this->system_name());
710 710
         }
711
-		return 'ee_payment_method_' . strtolower( $this->system_name() );
711
+		return 'ee_payment_method_'.strtolower($this->system_name());
712 712
 	}
713 713
 
714 714
 	/**
@@ -720,9 +720,9 @@  discard block
 block discarded – undo
720 720
 	 * @param EE_Payment $payment
721 721
 	 * @return void
722 722
 	 */
723
-	public function update_txn_based_on_payment( $payment ){
724
-		if( $this->_gateway instanceof EE_Gateway ){
725
-			$this->_gateway->update_txn_based_on_payment( $payment );
723
+	public function update_txn_based_on_payment($payment) {
724
+		if ($this->_gateway instanceof EE_Gateway) {
725
+			$this->_gateway->update_txn_based_on_payment($payment);
726 726
 		}
727 727
 	}
728 728
 
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
 	 * @return string
738 738
 	 */
739 739
 	public function introductory_html() {
740
-		return EEH_Template::locate_template( $this->file_folder() . 'templates' . DS . strtolower( $this->system_name() ) . '_intro.template.php', array( 'pmt_obj' => $this, 'pm_instance' => $this->_pm_instance ) );
740
+		return EEH_Template::locate_template($this->file_folder().'templates'.DS.strtolower($this->system_name()).'_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
741 741
 	}
742 742
 
743 743
 
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Capabilities.lib.php 2 patches
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @since           4.5.0
8 8
  */
9 9
 if (! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 /**
@@ -21,189 +21,189 @@  discard block
 block discarded – undo
21 21
 class EE_Register_Capabilities implements EEI_Plugin_API
22 22
 {
23 23
 
24
-    /**
25
-     * Holds the settings for a specific registration.
26
-     *
27
-     * @var array
28
-     */
29
-    protected static $_registry = array();
24
+	/**
25
+	 * Holds the settings for a specific registration.
26
+	 *
27
+	 * @var array
28
+	 */
29
+	protected static $_registry = array();
30 30
 
31 31
 
32
-    /**
33
-     * Used to register capability items with EE core.
34
-     *
35
-     * @since 4.5.0
36
-     * @param string $cap_reference     usually will be a class name that references capability related items setup for
37
-     *                                  something.
38
-     * @param array $setup_args         {
39
-     *                                  An array of items related to registering capabilities.
40
-     *                                  @type array $capabilities        An array mapping capability strings to core
41
-     *                                                                   WP Role. Something like: array(
42
-     *                                                                        'administrator'    => array(
43
-     *                                                                                'read_cap', 'edit_cap',
44
-     *                                                                                'delete_cap'),
45
-     *                                                                        'author' => array( 'read_cap' )
46
-     *                                                                   ).
47
-     *                                  @type array   $capability_maps   EE_Meta_Capability_Map[]
48
-     *                                                @see   EE_Capabilities.php for php docs on these objects.
49
-     *                                                       Should be indexed by the classname for the capability map
50
-     *                                                       and values representing the arguments for the map.
51
-     *                                  }
52
-     * @throws EE_Error
53
-     * @return void
54
-     */
55
-    public static function register($cap_reference = null, $setup_args = array())
56
-    {
57
-        //required fields MUST be present, so let's make sure they are.
58
-        if (! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
59
-            throw new EE_Error(
60
-                esc_html__(
61
-                    'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".',
62
-                    'event_espresso'
63
-                )
64
-            );
65
-        }
66
-        //make sure we don't register twice
67
-        if (isset(self::$_registry[$cap_reference])) {
68
-            return;
69
-        }
70
-        //make sure this is not registered too late or too early.
71
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
72
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
73
-        ) {
74
-            EE_Error::doing_it_wrong(
75
-                __METHOD__,
76
-                sprintf(
77
-                    esc_html__(
78
-                        '%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.',
79
-                        'event_espresso'
80
-                    ),
81
-                    $cap_reference
82
-                ),
83
-                '4.5.0'
84
-            );
85
-        }
86
-        //some preliminary sanitization and setting to the $_registry property
87
-        self::$_registry[$cap_reference] = array(
88
-            'caps'     => isset($setup_args['capabilities']) && is_array($setup_args['capabilities'])
89
-                ? $setup_args['capabilities']
90
-                : array(),
91
-            'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array(),
92
-        );
93
-        //set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once)
94
-        add_filter(
95
-            'FHEE__EE_Capabilities__init_caps_map__caps',
96
-            array('EE_Register_Capabilities', 'register_capabilities'),
97
-            10
98
-        );
99
-        //add filter for cap maps
100
-        add_filter(
101
-            'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
102
-            array('EE_Register_Capabilities', 'register_cap_maps'),
103
-            10
104
-        );
105
-    }
32
+	/**
33
+	 * Used to register capability items with EE core.
34
+	 *
35
+	 * @since 4.5.0
36
+	 * @param string $cap_reference     usually will be a class name that references capability related items setup for
37
+	 *                                  something.
38
+	 * @param array $setup_args         {
39
+	 *                                  An array of items related to registering capabilities.
40
+	 *                                  @type array $capabilities        An array mapping capability strings to core
41
+	 *                                                                   WP Role. Something like: array(
42
+	 *                                                                        'administrator'    => array(
43
+	 *                                                                                'read_cap', 'edit_cap',
44
+	 *                                                                                'delete_cap'),
45
+	 *                                                                        'author' => array( 'read_cap' )
46
+	 *                                                                   ).
47
+	 *                                  @type array   $capability_maps   EE_Meta_Capability_Map[]
48
+	 *                                                @see   EE_Capabilities.php for php docs on these objects.
49
+	 *                                                       Should be indexed by the classname for the capability map
50
+	 *                                                       and values representing the arguments for the map.
51
+	 *                                  }
52
+	 * @throws EE_Error
53
+	 * @return void
54
+	 */
55
+	public static function register($cap_reference = null, $setup_args = array())
56
+	{
57
+		//required fields MUST be present, so let's make sure they are.
58
+		if (! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
59
+			throw new EE_Error(
60
+				esc_html__(
61
+					'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".',
62
+					'event_espresso'
63
+				)
64
+			);
65
+		}
66
+		//make sure we don't register twice
67
+		if (isset(self::$_registry[$cap_reference])) {
68
+			return;
69
+		}
70
+		//make sure this is not registered too late or too early.
71
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
72
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
73
+		) {
74
+			EE_Error::doing_it_wrong(
75
+				__METHOD__,
76
+				sprintf(
77
+					esc_html__(
78
+						'%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.',
79
+						'event_espresso'
80
+					),
81
+					$cap_reference
82
+				),
83
+				'4.5.0'
84
+			);
85
+		}
86
+		//some preliminary sanitization and setting to the $_registry property
87
+		self::$_registry[$cap_reference] = array(
88
+			'caps'     => isset($setup_args['capabilities']) && is_array($setup_args['capabilities'])
89
+				? $setup_args['capabilities']
90
+				: array(),
91
+			'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array(),
92
+		);
93
+		//set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once)
94
+		add_filter(
95
+			'FHEE__EE_Capabilities__init_caps_map__caps',
96
+			array('EE_Register_Capabilities', 'register_capabilities'),
97
+			10
98
+		);
99
+		//add filter for cap maps
100
+		add_filter(
101
+			'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
102
+			array('EE_Register_Capabilities', 'register_cap_maps'),
103
+			10
104
+		);
105
+	}
106 106
 
107 107
 
108
-    /**
109
-     * callback for FHEE__EE_Capabilities__init_caps_map__caps filter.
110
-     * Takes care of registering additional capabilities to the caps map.   Note, that this also on the initial
111
-     * registration ensures that new capabilities are added to existing roles.
112
-     *
113
-     * @param array $incoming_caps The original caps map.
114
-     * @return array merged in new caps.
115
-     */
116
-    public static function register_capabilities($incoming_caps)
117
-    {
118
-        foreach (self::$_registry as $ref => $caps_and_cap_map) {
119
-            $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']);
120
-        }
121
-        return $incoming_caps;
122
-    }
108
+	/**
109
+	 * callback for FHEE__EE_Capabilities__init_caps_map__caps filter.
110
+	 * Takes care of registering additional capabilities to the caps map.   Note, that this also on the initial
111
+	 * registration ensures that new capabilities are added to existing roles.
112
+	 *
113
+	 * @param array $incoming_caps The original caps map.
114
+	 * @return array merged in new caps.
115
+	 */
116
+	public static function register_capabilities($incoming_caps)
117
+	{
118
+		foreach (self::$_registry as $ref => $caps_and_cap_map) {
119
+			$incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']);
120
+		}
121
+		return $incoming_caps;
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of
127
-     * capability maps for the WP meta_caps filter called in EE_Capabilities.
128
-     *
129
-     * @since 4.5.0
130
-     * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array.
131
-     * @return EE_Meta_Capability_Map[]
132
-     * @throws EE_Error
133
-     */
134
-    public static function register_cap_maps($cap_maps)
135
-    {
136
-        //loop through and instantiate cap maps.
137
-        foreach (self::$_registry as $cap_reference => $setup) {
138
-            if (! isset($setup['cap_maps'])) {
139
-                continue;
140
-            }
141
-            foreach ($setup['cap_maps'] as $cap_class => $args) {
125
+	/**
126
+	 * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of
127
+	 * capability maps for the WP meta_caps filter called in EE_Capabilities.
128
+	 *
129
+	 * @since 4.5.0
130
+	 * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array.
131
+	 * @return EE_Meta_Capability_Map[]
132
+	 * @throws EE_Error
133
+	 */
134
+	public static function register_cap_maps($cap_maps)
135
+	{
136
+		//loop through and instantiate cap maps.
137
+		foreach (self::$_registry as $cap_reference => $setup) {
138
+			if (! isset($setup['cap_maps'])) {
139
+				continue;
140
+			}
141
+			foreach ($setup['cap_maps'] as $cap_class => $args) {
142 142
 
143
-                /**
144
-                 * account for cases where capability maps may be indexed
145
-                 * numerically to allow for the same map class to be utilized
146
-                 * In those cases, maps will be setup in an array like:
147
-                 * array(
148
-                 *    0 => array( 'EE_Meta_Capability' => array(
149
-                 *        'ee_edit_cap', array( 'Object_Name',
150
-                 *        'ee_edit_published_cap',
151
-                 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
152
-                 *        ) )
153
-                 *    1 => ...
154
-                 * )
155
-                 * instead of:
156
-                 * array(
157
-                 *    'EE_Meta_Capability' => array(
158
-                 *        'ee_edit_cap', array( 'Object_Name',
159
-                 *        'ee_edit_published_cap',
160
-                 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
161
-                 *        ),
162
-                 *    ...
163
-                 * )
164
-                 */
165
-                if (is_numeric($cap_class)) {
166
-                    $cap_class = key($args);
167
-                    $args      = $args[$cap_class];
168
-                }
143
+				/**
144
+				 * account for cases where capability maps may be indexed
145
+				 * numerically to allow for the same map class to be utilized
146
+				 * In those cases, maps will be setup in an array like:
147
+				 * array(
148
+				 *    0 => array( 'EE_Meta_Capability' => array(
149
+				 *        'ee_edit_cap', array( 'Object_Name',
150
+				 *        'ee_edit_published_cap',
151
+				 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
152
+				 *        ) )
153
+				 *    1 => ...
154
+				 * )
155
+				 * instead of:
156
+				 * array(
157
+				 *    'EE_Meta_Capability' => array(
158
+				 *        'ee_edit_cap', array( 'Object_Name',
159
+				 *        'ee_edit_published_cap',
160
+				 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
161
+				 *        ),
162
+				 *    ...
163
+				 * )
164
+				 */
165
+				if (is_numeric($cap_class)) {
166
+					$cap_class = key($args);
167
+					$args      = $args[$cap_class];
168
+				}
169 169
 
170
-                if (! class_exists($cap_class)) {
171
-                    throw new EE_Error(
172
-                        sprintf(
173
-                            esc_html__(
174
-                                'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments',
175
-                                'event_espresso'
176
-                            ),
177
-                            $cap_reference
178
-                        )
179
-                    );
180
-                }
170
+				if (! class_exists($cap_class)) {
171
+					throw new EE_Error(
172
+						sprintf(
173
+							esc_html__(
174
+								'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments',
175
+								'event_espresso'
176
+							),
177
+							$cap_reference
178
+						)
179
+					);
180
+				}
181 181
 
182
-                if (count($args) !== 2) {
183
-                    throw new EE_Error(
184
-                        sprintf(
185
-                            esc_html__(
186
-                                'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.',
187
-                                'event_espresso'
188
-                            ),
189
-                            $cap_reference
190
-                        )
191
-                    );
192
-                }
193
-                $cap_maps[] = new $cap_class($args[0], $args[1]);
194
-            }
195
-        }
196
-        return $cap_maps;
197
-    }
182
+				if (count($args) !== 2) {
183
+					throw new EE_Error(
184
+						sprintf(
185
+							esc_html__(
186
+								'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.',
187
+								'event_espresso'
188
+							),
189
+							$cap_reference
190
+						)
191
+					);
192
+				}
193
+				$cap_maps[] = new $cap_class($args[0], $args[1]);
194
+			}
195
+		}
196
+		return $cap_maps;
197
+	}
198 198
 
199 199
 
200
-    public static function deregister($cap_reference = null)
201
-    {
202
-        if (! empty(self::$_registry[$cap_reference])) {
203
-            unset(self::$_registry[$cap_reference]);
204
-        }
200
+	public static function deregister($cap_reference = null)
201
+	{
202
+		if (! empty(self::$_registry[$cap_reference])) {
203
+			unset(self::$_registry[$cap_reference]);
204
+		}
205 205
 
206
-        //re init caps to grab the changes due to removed caps.
207
-        EE_Capabilities::instance()->init_caps();
208
-    }
206
+		//re init caps to grab the changes due to removed caps.
207
+		EE_Capabilities::instance()->init_caps();
208
+	}
209 209
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @subpackage      plugin api, capabilities
7 7
  * @since           4.5.0
8 8
  */
9
-if (! defined('EVENT_ESPRESSO_VERSION')) {
9
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10 10
     exit('No direct script access allowed');
11 11
 }
12 12
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     public static function register($cap_reference = null, $setup_args = array())
56 56
     {
57 57
         //required fields MUST be present, so let's make sure they are.
58
-        if (! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
58
+        if ( ! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
59 59
             throw new EE_Error(
60 60
                 esc_html__(
61 61
                     'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".',
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
             return;
69 69
         }
70 70
         //make sure this is not registered too late or too early.
71
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
71
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
72 72
             || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
73 73
         ) {
74 74
             EE_Error::doing_it_wrong(
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     {
136 136
         //loop through and instantiate cap maps.
137 137
         foreach (self::$_registry as $cap_reference => $setup) {
138
-            if (! isset($setup['cap_maps'])) {
138
+            if ( ! isset($setup['cap_maps'])) {
139 139
                 continue;
140 140
             }
141 141
             foreach ($setup['cap_maps'] as $cap_class => $args) {
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
                     $args      = $args[$cap_class];
168 168
                 }
169 169
 
170
-                if (! class_exists($cap_class)) {
170
+                if ( ! class_exists($cap_class)) {
171 171
                     throw new EE_Error(
172 172
                         sprintf(
173 173
                             esc_html__(
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 
200 200
     public static function deregister($cap_reference = null)
201 201
     {
202
-        if (! empty(self::$_registry[$cap_reference])) {
202
+        if ( ! empty(self::$_registry[$cap_reference])) {
203 203
             unset(self::$_registry[$cap_reference]);
204 204
         }
205 205
 
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 1 patch
Indentation   +1651 added lines, -1651 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,242 +14,242 @@  discard block
 block discarded – undo
14 14
 class EEH_Activation
15 15
 {
16 16
 
17
-    /**
18
-     * constant used to indicate a cron task is no longer in use
19
-     */
20
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
21
-
22
-    /**
23
-     * option name that will indicate whether or not we still
24
-     * need to create EE's folders in the uploads directory
25
-     * (because if EE was installed without file system access,
26
-     * we need to request credentials before we can create them)
27
-     */
28
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
-
30
-    /**
31
-     * WP_User->ID
32
-     *
33
-     * @var int
34
-     */
35
-    private static $_default_creator_id;
36
-
37
-    /**
38
-     * indicates whether or not we've already verified core's default data during this request,
39
-     * because after migrations are done, any addons activated while in maintenance mode
40
-     * will want to setup their own default data, and they might hook into core's default data
41
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
-     * This prevents doing that for EVERY single addon.
43
-     *
44
-     * @var boolean
45
-     */
46
-    protected static $_initialized_db_content_already_in_this_request = false;
47
-
48
-    /**
49
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
-     */
51
-    private static $table_analysis;
52
-
53
-    /**
54
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
55
-     */
56
-    private static $table_manager;
57
-
58
-
59
-    /**
60
-     * @return \EventEspresso\core\services\database\TableAnalysis
61
-     */
62
-    public static function getTableAnalysis()
63
-    {
64
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
-        }
67
-        return self::$table_analysis;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return \EventEspresso\core\services\database\TableManager
73
-     */
74
-    public static function getTableManager()
75
-    {
76
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
-        }
79
-        return self::$table_manager;
80
-    }
81
-
82
-
83
-    /**
84
-     *    _ensure_table_name_has_prefix
85
-     *
86
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
-     * @access     public
88
-     * @static
89
-     * @param $table_name
90
-     * @return string
91
-     */
92
-    public static function ensure_table_name_has_prefix($table_name)
93
-    {
94
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
-    }
96
-
97
-
98
-    /**
99
-     *    system_initialization
100
-     *    ensures the EE configuration settings are loaded with at least default options set
101
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
-     *
103
-     * @access public
104
-     * @static
105
-     * @return void
106
-     */
107
-    public static function system_initialization()
108
-    {
109
-        EEH_Activation::reset_and_update_config();
110
-        //which is fired BEFORE activation of plugin anyways
111
-        EEH_Activation::verify_default_pages_exist();
112
-    }
113
-
114
-
115
-    /**
116
-     * Sets the database schema and creates folders. This should
117
-     * be called on plugin activation and reactivation
118
-     *
119
-     * @return boolean success, whether the database and folders are setup properly
120
-     * @throws \EE_Error
121
-     */
122
-    public static function initialize_db_and_folders()
123
-    {
124
-        $good_filesystem = EEH_Activation::create_upload_directories();
125
-        $good_db         = EEH_Activation::create_database_tables();
126
-        return $good_filesystem && $good_db;
127
-    }
128
-
129
-
130
-    /**
131
-     * assuming we have an up-to-date database schema, this will populate it
132
-     * with default and initial data. This should be called
133
-     * upon activation of a new plugin, reactivation, and at the end
134
-     * of running migration scripts
135
-     *
136
-     * @throws \EE_Error
137
-     */
138
-    public static function initialize_db_content()
139
-    {
140
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
-            return;
143
-        }
144
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
-
146
-        EEH_Activation::initialize_system_questions();
147
-        EEH_Activation::insert_default_status_codes();
148
-        EEH_Activation::generate_default_message_templates();
149
-        EEH_Activation::create_no_ticket_prices_array();
150
-        EEH_Activation::validate_messages_system();
151
-        EEH_Activation::insert_default_payment_methods();
152
-        //in case we've
153
-        EEH_Activation::remove_cron_tasks();
154
-        EEH_Activation::create_cron_tasks();
155
-        // remove all TXN locks since that is being done via extra meta now
156
-        delete_option('ee_locked_transactions');
157
-        //also, check for CAF default db content
158
-        do_action('AHEE__EEH_Activation__initialize_db_content');
159
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
160
-        //which users really won't care about on initial activation
161
-        EE_Error::overwrite_success();
162
-    }
163
-
164
-
165
-    /**
166
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
167
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
168
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
169
-     * (null)
170
-     *
171
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
172
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
173
-     * @return array
174
-     * @throws \EE_Error
175
-     */
176
-    public static function get_cron_tasks($which_to_include)
177
-    {
178
-        $cron_tasks = apply_filters(
179
-            'FHEE__EEH_Activation__get_cron_tasks',
180
-            array(
181
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
17
+	/**
18
+	 * constant used to indicate a cron task is no longer in use
19
+	 */
20
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
21
+
22
+	/**
23
+	 * option name that will indicate whether or not we still
24
+	 * need to create EE's folders in the uploads directory
25
+	 * (because if EE was installed without file system access,
26
+	 * we need to request credentials before we can create them)
27
+	 */
28
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
+
30
+	/**
31
+	 * WP_User->ID
32
+	 *
33
+	 * @var int
34
+	 */
35
+	private static $_default_creator_id;
36
+
37
+	/**
38
+	 * indicates whether or not we've already verified core's default data during this request,
39
+	 * because after migrations are done, any addons activated while in maintenance mode
40
+	 * will want to setup their own default data, and they might hook into core's default data
41
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
+	 * This prevents doing that for EVERY single addon.
43
+	 *
44
+	 * @var boolean
45
+	 */
46
+	protected static $_initialized_db_content_already_in_this_request = false;
47
+
48
+	/**
49
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
+	 */
51
+	private static $table_analysis;
52
+
53
+	/**
54
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
55
+	 */
56
+	private static $table_manager;
57
+
58
+
59
+	/**
60
+	 * @return \EventEspresso\core\services\database\TableAnalysis
61
+	 */
62
+	public static function getTableAnalysis()
63
+	{
64
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
+		}
67
+		return self::$table_analysis;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return \EventEspresso\core\services\database\TableManager
73
+	 */
74
+	public static function getTableManager()
75
+	{
76
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
+		}
79
+		return self::$table_manager;
80
+	}
81
+
82
+
83
+	/**
84
+	 *    _ensure_table_name_has_prefix
85
+	 *
86
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
+	 * @access     public
88
+	 * @static
89
+	 * @param $table_name
90
+	 * @return string
91
+	 */
92
+	public static function ensure_table_name_has_prefix($table_name)
93
+	{
94
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
+	}
96
+
97
+
98
+	/**
99
+	 *    system_initialization
100
+	 *    ensures the EE configuration settings are loaded with at least default options set
101
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
+	 *
103
+	 * @access public
104
+	 * @static
105
+	 * @return void
106
+	 */
107
+	public static function system_initialization()
108
+	{
109
+		EEH_Activation::reset_and_update_config();
110
+		//which is fired BEFORE activation of plugin anyways
111
+		EEH_Activation::verify_default_pages_exist();
112
+	}
113
+
114
+
115
+	/**
116
+	 * Sets the database schema and creates folders. This should
117
+	 * be called on plugin activation and reactivation
118
+	 *
119
+	 * @return boolean success, whether the database and folders are setup properly
120
+	 * @throws \EE_Error
121
+	 */
122
+	public static function initialize_db_and_folders()
123
+	{
124
+		$good_filesystem = EEH_Activation::create_upload_directories();
125
+		$good_db         = EEH_Activation::create_database_tables();
126
+		return $good_filesystem && $good_db;
127
+	}
128
+
129
+
130
+	/**
131
+	 * assuming we have an up-to-date database schema, this will populate it
132
+	 * with default and initial data. This should be called
133
+	 * upon activation of a new plugin, reactivation, and at the end
134
+	 * of running migration scripts
135
+	 *
136
+	 * @throws \EE_Error
137
+	 */
138
+	public static function initialize_db_content()
139
+	{
140
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
+			return;
143
+		}
144
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
+
146
+		EEH_Activation::initialize_system_questions();
147
+		EEH_Activation::insert_default_status_codes();
148
+		EEH_Activation::generate_default_message_templates();
149
+		EEH_Activation::create_no_ticket_prices_array();
150
+		EEH_Activation::validate_messages_system();
151
+		EEH_Activation::insert_default_payment_methods();
152
+		//in case we've
153
+		EEH_Activation::remove_cron_tasks();
154
+		EEH_Activation::create_cron_tasks();
155
+		// remove all TXN locks since that is being done via extra meta now
156
+		delete_option('ee_locked_transactions');
157
+		//also, check for CAF default db content
158
+		do_action('AHEE__EEH_Activation__initialize_db_content');
159
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
160
+		//which users really won't care about on initial activation
161
+		EE_Error::overwrite_success();
162
+	}
163
+
164
+
165
+	/**
166
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
167
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
168
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
169
+	 * (null)
170
+	 *
171
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
172
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
173
+	 * @return array
174
+	 * @throws \EE_Error
175
+	 */
176
+	public static function get_cron_tasks($which_to_include)
177
+	{
178
+		$cron_tasks = apply_filters(
179
+			'FHEE__EEH_Activation__get_cron_tasks',
180
+			array(
181
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
182 182
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
183
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
184
-                //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
185
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
186
-            )
187
-        );
188
-        if ($which_to_include === 'old') {
189
-            $cron_tasks = array_filter(
190
-                $cron_tasks,
191
-                function ($value) {
192
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
193
-                }
194
-            );
195
-        } elseif ($which_to_include === 'current') {
196
-            $cron_tasks = array_filter($cron_tasks);
197
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
198
-            throw new EE_Error(
199
-                sprintf(
200
-                    __(
201
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
202
-                        'event_espresso'
203
-                    ),
204
-                    $which_to_include
205
-                )
206
-            );
207
-        }
208
-        return $cron_tasks;
209
-    }
210
-
211
-
212
-    /**
213
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
214
-     *
215
-     * @throws \EE_Error
216
-     */
217
-    public static function create_cron_tasks()
218
-    {
219
-
220
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
221
-            if (! wp_next_scheduled($hook_name)) {
222
-                /**
223
-                 * This allows client code to define the initial start timestamp for this schedule.
224
-                 */
225
-                if (is_array($frequency)
226
-                    && count($frequency) === 2
227
-                    && isset($frequency[0], $frequency[1])
228
-                ) {
229
-                    $start_timestamp = $frequency[0];
230
-                    $frequency = $frequency[1];
231
-                } else {
232
-                    $start_timestamp = time();
233
-                }
234
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
235
-            }
236
-        }
237
-
238
-    }
239
-
240
-
241
-    /**
242
-     * Remove the currently-existing and now-removed cron tasks.
243
-     *
244
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
245
-     * @throws \EE_Error
246
-     */
247
-    public static function remove_cron_tasks($remove_all = true)
248
-    {
249
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
250
-        $crons                = _get_cron_array();
251
-        $crons                = is_array($crons) ? $crons : array();
252
-        /* reminder of what $crons look like:
183
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
184
+				//there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
185
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
186
+			)
187
+		);
188
+		if ($which_to_include === 'old') {
189
+			$cron_tasks = array_filter(
190
+				$cron_tasks,
191
+				function ($value) {
192
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
193
+				}
194
+			);
195
+		} elseif ($which_to_include === 'current') {
196
+			$cron_tasks = array_filter($cron_tasks);
197
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
198
+			throw new EE_Error(
199
+				sprintf(
200
+					__(
201
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
202
+						'event_espresso'
203
+					),
204
+					$which_to_include
205
+				)
206
+			);
207
+		}
208
+		return $cron_tasks;
209
+	}
210
+
211
+
212
+	/**
213
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
214
+	 *
215
+	 * @throws \EE_Error
216
+	 */
217
+	public static function create_cron_tasks()
218
+	{
219
+
220
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
221
+			if (! wp_next_scheduled($hook_name)) {
222
+				/**
223
+				 * This allows client code to define the initial start timestamp for this schedule.
224
+				 */
225
+				if (is_array($frequency)
226
+					&& count($frequency) === 2
227
+					&& isset($frequency[0], $frequency[1])
228
+				) {
229
+					$start_timestamp = $frequency[0];
230
+					$frequency = $frequency[1];
231
+				} else {
232
+					$start_timestamp = time();
233
+				}
234
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
235
+			}
236
+		}
237
+
238
+	}
239
+
240
+
241
+	/**
242
+	 * Remove the currently-existing and now-removed cron tasks.
243
+	 *
244
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
245
+	 * @throws \EE_Error
246
+	 */
247
+	public static function remove_cron_tasks($remove_all = true)
248
+	{
249
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
250
+		$crons                = _get_cron_array();
251
+		$crons                = is_array($crons) ? $crons : array();
252
+		/* reminder of what $crons look like:
253 253
          * Top-level keys are timestamps, and their values are arrays.
254 254
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
255 255
          * and their values are arrays.
@@ -266,912 +266,912 @@  discard block
 block discarded – undo
266 266
          *					...
267 267
          *      ...
268 268
          */
269
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
270
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
271
-            if (is_array($hooks_to_fire_at_time)) {
272
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
273
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
274
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
275
-                    ) {
276
-                        unset($crons[$timestamp][$hook_name]);
277
-                    }
278
-                }
279
-                //also take care of any empty cron timestamps.
280
-                if (empty($hooks_to_fire_at_time)) {
281
-                    unset($crons[$timestamp]);
282
-                }
283
-            }
284
-        }
285
-        _set_cron_array($crons);
286
-    }
287
-
288
-
289
-    /**
290
-     *    CPT_initialization
291
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
292
-     *
293
-     * @access public
294
-     * @static
295
-     * @return void
296
-     */
297
-    public static function CPT_initialization()
298
-    {
299
-        // register Custom Post Types
300
-        EE_Registry::instance()->load_core('Register_CPTs');
301
-        flush_rewrite_rules();
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     *    reset_and_update_config
308
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
309
-     * If there is old calendar config data saved, then it will get converted on activation.
310
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
311
-     *
312
-     * @access public
313
-     * @static
314
-     * @return void
315
-     */
316
-    public static function reset_and_update_config()
317
-    {
318
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
319
-        add_filter(
320
-            'FHEE__EE_Config___load_core_config__config_settings',
321
-            array('EEH_Activation', 'migrate_old_config_data'),
322
-            10,
323
-            3
324
-        );
325
-        //EE_Config::reset();
326
-        if (! EE_Config::logging_enabled()) {
327
-            delete_option(EE_Config::LOG_NAME);
328
-        }
329
-    }
330
-
331
-
332
-    /**
333
-     *    load_calendar_config
334
-     *
335
-     * @access    public
336
-     * @return    void
337
-     */
338
-    public static function load_calendar_config()
339
-    {
340
-        // grab array of all plugin folders and loop thru it
341
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
342
-        if (empty($plugins)) {
343
-            return;
344
-        }
345
-        foreach ($plugins as $plugin_path) {
346
-            // grab plugin folder name from path
347
-            $plugin = basename($plugin_path);
348
-            // drill down to Espresso plugins
349
-            // then to calendar related plugins
350
-            if (
351
-                strpos($plugin, 'espresso') !== false
352
-                || strpos($plugin, 'Espresso') !== false
353
-                || strpos($plugin, 'ee4') !== false
354
-                || strpos($plugin, 'EE4') !== false
355
-                || strpos($plugin, 'calendar') !== false
356
-            ) {
357
-                // this is what we are looking for
358
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
359
-                // does it exist in this folder ?
360
-                if (is_readable($calendar_config)) {
361
-                    // YEAH! let's load it
362
-                    require_once($calendar_config);
363
-                }
364
-            }
365
-        }
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     *    _migrate_old_config_data
372
-     *
373
-     * @access    public
374
-     * @param array|stdClass $settings
375
-     * @param string         $config
376
-     * @param \EE_Config     $EE_Config
377
-     * @return \stdClass
378
-     */
379
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
380
-    {
381
-        $convert_from_array = array('addons');
382
-        // in case old settings were saved as an array
383
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
384
-            // convert existing settings to an object
385
-            $config_array = $settings;
386
-            $settings = new stdClass();
387
-            foreach ($config_array as $key => $value) {
388
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
389
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
390
-                } else {
391
-                    $settings->{$key} = $value;
392
-                }
393
-            }
394
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
395
-        }
396
-        return $settings;
397
-    }
398
-
399
-
400
-    /**
401
-     * deactivate_event_espresso
402
-     *
403
-     * @access public
404
-     * @static
405
-     * @return void
406
-     */
407
-    public static function deactivate_event_espresso()
408
-    {
409
-        // check permissions
410
-        if (current_user_can('activate_plugins')) {
411
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
412
-        }
413
-    }
414
-
415
-
416
-
417
-
418
-
419
-    /**
420
-     * verify_default_pages_exist
421
-     *
422
-     * @access public
423
-     * @static
424
-     * @return void
425
-     */
426
-    public static function verify_default_pages_exist()
427
-    {
428
-        $critical_page_problem = false;
429
-        $critical_pages = array(
430
-            array(
431
-                'id'   => 'reg_page_id',
432
-                'name' => __('Registration Checkout', 'event_espresso'),
433
-                'post' => null,
434
-                'code' => 'ESPRESSO_CHECKOUT',
435
-            ),
436
-            array(
437
-                'id'   => 'txn_page_id',
438
-                'name' => __('Transactions', 'event_espresso'),
439
-                'post' => null,
440
-                'code' => 'ESPRESSO_TXN_PAGE',
441
-            ),
442
-            array(
443
-                'id'   => 'thank_you_page_id',
444
-                'name' => __('Thank You', 'event_espresso'),
445
-                'post' => null,
446
-                'code' => 'ESPRESSO_THANK_YOU',
447
-            ),
448
-            array(
449
-                'id'   => 'cancel_page_id',
450
-                'name' => __('Registration Cancelled', 'event_espresso'),
451
-                'post' => null,
452
-                'code' => 'ESPRESSO_CANCELLED',
453
-            ),
454
-        );
455
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
456
-        foreach ($critical_pages as $critical_page) {
457
-            // is critical page ID set in config ?
458
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
459
-                // attempt to find post by ID
460
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
461
-            }
462
-            // no dice?
463
-            if ($critical_page['post'] === null) {
464
-                // attempt to find post by title
465
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
466
-                // still nothing?
467
-                if ($critical_page['post'] === null) {
468
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
469
-                    // REALLY? Still nothing ??!?!?
470
-                    if ($critical_page['post'] === null) {
471
-                        $msg = __(
472
-                            'The Event Espresso critical page configuration settings could not be updated.',
473
-                            'event_espresso'
474
-                        );
475
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
476
-                        break;
477
-                    }
478
-                }
479
-            }
480
-            // check that Post ID matches critical page ID in config
481
-            if (
482
-                isset($critical_page['post']->ID)
483
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
484
-            ) {
485
-                //update Config with post ID
486
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
487
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
488
-                    $msg = __(
489
-                        'The Event Espresso critical page configuration settings could not be updated.',
490
-                        'event_espresso'
491
-                    );
492
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
493
-                }
494
-            }
495
-            $critical_page_problem =
496
-                ! isset($critical_page['post']->post_status)
497
-                || $critical_page['post']->post_status !== 'publish'
498
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
499
-                    ? true
500
-                    : $critical_page_problem;
501
-        }
502
-        if ($critical_page_problem) {
503
-            $msg = sprintf(
504
-                __(
505
-                    'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
506
-                    'event_espresso'
507
-                ),
508
-                '<a href="'
509
-                . admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
510
-                . '">'
511
-                . __('Event Espresso Critical Pages Settings', 'event_espresso')
512
-                . '</a>'
513
-            );
514
-            EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
515
-        }
516
-        if (EE_Error::has_notices()) {
517
-            EE_Error::get_notices(false, true, true);
518
-        }
519
-    }
520
-
521
-
522
-
523
-    /**
524
-     * Returns the first post which uses the specified shortcode
525
-     *
526
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
527
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
528
-     *                             "[ESPRESSO_THANK_YOU"
529
-     *                             (we don't search for the closing shortcode bracket because they might have added
530
-     *                             parameter to the shortcode
531
-     * @return WP_Post or NULl
532
-     */
533
-    public static function get_page_by_ee_shortcode($ee_shortcode)
534
-    {
535
-        global $wpdb;
536
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
537
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
538
-        if ($post_id) {
539
-            return get_post($post_id);
540
-        } else {
541
-            return null;
542
-        }
543
-    }
544
-
545
-
546
-    /**
547
-     *    This function generates a post for critical espresso pages
548
-     *
549
-     * @access public
550
-     * @static
551
-     * @param array $critical_page
552
-     * @return array
553
-     */
554
-    public static function create_critical_page($critical_page)
555
-    {
556
-
557
-        $post_args = array(
558
-            'post_title'     => $critical_page['name'],
559
-            'post_status'    => 'publish',
560
-            'post_type'      => 'page',
561
-            'comment_status' => 'closed',
562
-            'post_content'   => '[' . $critical_page['code'] . ']',
563
-        );
564
-
565
-        $post_id = wp_insert_post($post_args);
566
-        if (! $post_id) {
567
-            $msg = sprintf(
568
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
569
-                $critical_page['name']
570
-            );
571
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
572
-            return $critical_page;
573
-        }
574
-        // get newly created post's details
575
-        if (! $critical_page['post'] = get_post($post_id)) {
576
-            $msg = sprintf(
577
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
578
-                $critical_page['name']
579
-            );
580
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
581
-        }
582
-
583
-        return $critical_page;
584
-
585
-    }
586
-
587
-
588
-
589
-
590
-    /**
591
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
592
-     * The role being used to check is filterable.
593
-     *
594
-     * @since  4.6.0
595
-     * @global WPDB $wpdb
596
-     * @return mixed null|int WP_user ID or NULL
597
-     */
598
-    public static function get_default_creator_id()
599
-    {
600
-        global $wpdb;
601
-        if ( ! empty(self::$_default_creator_id)) {
602
-            return self::$_default_creator_id;
603
-        }/**/
604
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
605
-        //let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
606
-        $pre_filtered_id = apply_filters(
607
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
608
-            false,
609
-            $role_to_check
610
-        );
611
-        if ($pre_filtered_id !== false) {
612
-            return (int)$pre_filtered_id;
613
-        }
614
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
615
-        $query = $wpdb->prepare(
616
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
617
-            '%' . $role_to_check . '%'
618
-        );
619
-        $user_id = $wpdb->get_var($query);
620
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
621
-        if ($user_id && (int)$user_id) {
622
-            self::$_default_creator_id = (int)$user_id;
623
-            return self::$_default_creator_id;
624
-        } else {
625
-            return null;
626
-        }
627
-    }
628
-
629
-
630
-
631
-    /**
632
-     * used by EE and EE addons during plugin activation to create tables.
633
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
634
-     * but includes extra logic regarding activations.
635
-     *
636
-     * @access public
637
-     * @static
638
-     * @param string  $table_name              without the $wpdb->prefix
639
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
640
-     *                                         table query)
641
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
642
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
643
-     *                                         and new once this function is done (ie, you really do want to CREATE a
644
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
645
-     *                                         you just want to verify the table exists and matches this definition
646
-     *                                         (and if it HAS data in it you want to leave it be)
647
-     * @return void
648
-     * @throws EE_Error if there are database errors
649
-     */
650
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
651
-    {
652
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
653
-            return;
654
-        }
655
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
656
-        if ( ! function_exists('dbDelta')) {
657
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
658
-        }
659
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
660
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
661
-        // do we need to first delete an existing version of this table ?
662
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
663
-            // ok, delete the table... but ONLY if it's empty
664
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
665
-            // table is NOT empty, are you SURE you want to delete this table ???
666
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
667
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
668
-            } else if ( ! $deleted_safely) {
669
-                // so we should be more cautious rather than just dropping tables so easily
670
-                error_log(
671
-                    sprintf(
672
-                        __(
673
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
674
-                            'event_espresso'
675
-                        ),
676
-                        $wp_table_name,
677
-                        '<br/>',
678
-                        'espresso_db_update'
679
-                    )
680
-                );
681
-            }
682
-        }
683
-        $engine = str_replace('ENGINE=', '', $engine);
684
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
685
-    }
686
-
687
-
688
-
689
-    /**
690
-     *    add_column_if_it_doesn't_exist
691
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
692
-     *
693
-     * @access     public
694
-     * @static
695
-     * @deprecated instead use TableManager::addColumn()
696
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
697
-     * @param string $column_name
698
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
699
-     *                            'VARCHAR(10)'
700
-     * @return bool|int
701
-     */
702
-    public static function add_column_if_it_doesnt_exist(
703
-        $table_name,
704
-        $column_name,
705
-        $column_info = 'INT UNSIGNED NOT NULL'
706
-    ) {
707
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
708
-    }
709
-
710
-
711
-    /**
712
-     * get_fields_on_table
713
-     * Gets all the fields on the database table.
714
-     *
715
-     * @access     public
716
-     * @deprecated instead use TableManager::getTableColumns()
717
-     * @static
718
-     * @param string $table_name , without prefixed $wpdb->prefix
719
-     * @return array of database column names
720
-     */
721
-    public static function get_fields_on_table($table_name = null)
722
-    {
723
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
724
-    }
725
-
726
-
727
-    /**
728
-     * db_table_is_empty
729
-     *
730
-     * @access     public\
731
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
732
-     * @static
733
-     * @param string $table_name
734
-     * @return bool
735
-     */
736
-    public static function db_table_is_empty($table_name)
737
-    {
738
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
739
-    }
740
-
741
-
742
-    /**
743
-     * delete_db_table_if_empty
744
-     *
745
-     * @access public
746
-     * @static
747
-     * @param string $table_name
748
-     * @return bool | int
749
-     */
750
-    public static function delete_db_table_if_empty($table_name)
751
-    {
752
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
753
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
754
-        }
755
-        return false;
756
-    }
757
-
758
-
759
-    /**
760
-     * delete_unused_db_table
761
-     *
762
-     * @access     public
763
-     * @static
764
-     * @deprecated instead use TableManager::dropTable()
765
-     * @param string $table_name
766
-     * @return bool | int
767
-     */
768
-    public static function delete_unused_db_table($table_name)
769
-    {
770
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
771
-    }
772
-
773
-
774
-    /**
775
-     * drop_index
776
-     *
777
-     * @access     public
778
-     * @static
779
-     * @deprecated instead use TableManager::dropIndex()
780
-     * @param string $table_name
781
-     * @param string $index_name
782
-     * @return bool | int
783
-     */
784
-    public static function drop_index($table_name, $index_name)
785
-    {
786
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
787
-    }
788
-
789
-
790
-
791
-    /**
792
-     * create_database_tables
793
-     *
794
-     * @access public
795
-     * @static
796
-     * @throws EE_Error
797
-     * @return boolean success (whether database is setup properly or not)
798
-     */
799
-    public static function create_database_tables()
800
-    {
801
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
802
-        //find the migration script that sets the database to be compatible with the code
803
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
804
-        if ($dms_name) {
805
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
806
-            $current_data_migration_script->set_migrating(false);
807
-            $current_data_migration_script->schema_changes_before_migration();
808
-            $current_data_migration_script->schema_changes_after_migration();
809
-            if ($current_data_migration_script->get_errors()) {
810
-                if (WP_DEBUG) {
811
-                    foreach ($current_data_migration_script->get_errors() as $error) {
812
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
813
-                    }
814
-                } else {
815
-                    EE_Error::add_error(
816
-                        __(
817
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
269
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
270
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
271
+			if (is_array($hooks_to_fire_at_time)) {
272
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
273
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
274
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
275
+					) {
276
+						unset($crons[$timestamp][$hook_name]);
277
+					}
278
+				}
279
+				//also take care of any empty cron timestamps.
280
+				if (empty($hooks_to_fire_at_time)) {
281
+					unset($crons[$timestamp]);
282
+				}
283
+			}
284
+		}
285
+		_set_cron_array($crons);
286
+	}
287
+
288
+
289
+	/**
290
+	 *    CPT_initialization
291
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
292
+	 *
293
+	 * @access public
294
+	 * @static
295
+	 * @return void
296
+	 */
297
+	public static function CPT_initialization()
298
+	{
299
+		// register Custom Post Types
300
+		EE_Registry::instance()->load_core('Register_CPTs');
301
+		flush_rewrite_rules();
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 *    reset_and_update_config
308
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
309
+	 * If there is old calendar config data saved, then it will get converted on activation.
310
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
311
+	 *
312
+	 * @access public
313
+	 * @static
314
+	 * @return void
315
+	 */
316
+	public static function reset_and_update_config()
317
+	{
318
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
319
+		add_filter(
320
+			'FHEE__EE_Config___load_core_config__config_settings',
321
+			array('EEH_Activation', 'migrate_old_config_data'),
322
+			10,
323
+			3
324
+		);
325
+		//EE_Config::reset();
326
+		if (! EE_Config::logging_enabled()) {
327
+			delete_option(EE_Config::LOG_NAME);
328
+		}
329
+	}
330
+
331
+
332
+	/**
333
+	 *    load_calendar_config
334
+	 *
335
+	 * @access    public
336
+	 * @return    void
337
+	 */
338
+	public static function load_calendar_config()
339
+	{
340
+		// grab array of all plugin folders and loop thru it
341
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
342
+		if (empty($plugins)) {
343
+			return;
344
+		}
345
+		foreach ($plugins as $plugin_path) {
346
+			// grab plugin folder name from path
347
+			$plugin = basename($plugin_path);
348
+			// drill down to Espresso plugins
349
+			// then to calendar related plugins
350
+			if (
351
+				strpos($plugin, 'espresso') !== false
352
+				|| strpos($plugin, 'Espresso') !== false
353
+				|| strpos($plugin, 'ee4') !== false
354
+				|| strpos($plugin, 'EE4') !== false
355
+				|| strpos($plugin, 'calendar') !== false
356
+			) {
357
+				// this is what we are looking for
358
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
359
+				// does it exist in this folder ?
360
+				if (is_readable($calendar_config)) {
361
+					// YEAH! let's load it
362
+					require_once($calendar_config);
363
+				}
364
+			}
365
+		}
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 *    _migrate_old_config_data
372
+	 *
373
+	 * @access    public
374
+	 * @param array|stdClass $settings
375
+	 * @param string         $config
376
+	 * @param \EE_Config     $EE_Config
377
+	 * @return \stdClass
378
+	 */
379
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
380
+	{
381
+		$convert_from_array = array('addons');
382
+		// in case old settings were saved as an array
383
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
384
+			// convert existing settings to an object
385
+			$config_array = $settings;
386
+			$settings = new stdClass();
387
+			foreach ($config_array as $key => $value) {
388
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
389
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
390
+				} else {
391
+					$settings->{$key} = $value;
392
+				}
393
+			}
394
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
395
+		}
396
+		return $settings;
397
+	}
398
+
399
+
400
+	/**
401
+	 * deactivate_event_espresso
402
+	 *
403
+	 * @access public
404
+	 * @static
405
+	 * @return void
406
+	 */
407
+	public static function deactivate_event_espresso()
408
+	{
409
+		// check permissions
410
+		if (current_user_can('activate_plugins')) {
411
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
412
+		}
413
+	}
414
+
415
+
416
+
417
+
418
+
419
+	/**
420
+	 * verify_default_pages_exist
421
+	 *
422
+	 * @access public
423
+	 * @static
424
+	 * @return void
425
+	 */
426
+	public static function verify_default_pages_exist()
427
+	{
428
+		$critical_page_problem = false;
429
+		$critical_pages = array(
430
+			array(
431
+				'id'   => 'reg_page_id',
432
+				'name' => __('Registration Checkout', 'event_espresso'),
433
+				'post' => null,
434
+				'code' => 'ESPRESSO_CHECKOUT',
435
+			),
436
+			array(
437
+				'id'   => 'txn_page_id',
438
+				'name' => __('Transactions', 'event_espresso'),
439
+				'post' => null,
440
+				'code' => 'ESPRESSO_TXN_PAGE',
441
+			),
442
+			array(
443
+				'id'   => 'thank_you_page_id',
444
+				'name' => __('Thank You', 'event_espresso'),
445
+				'post' => null,
446
+				'code' => 'ESPRESSO_THANK_YOU',
447
+			),
448
+			array(
449
+				'id'   => 'cancel_page_id',
450
+				'name' => __('Registration Cancelled', 'event_espresso'),
451
+				'post' => null,
452
+				'code' => 'ESPRESSO_CANCELLED',
453
+			),
454
+		);
455
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
456
+		foreach ($critical_pages as $critical_page) {
457
+			// is critical page ID set in config ?
458
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
459
+				// attempt to find post by ID
460
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
461
+			}
462
+			// no dice?
463
+			if ($critical_page['post'] === null) {
464
+				// attempt to find post by title
465
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
466
+				// still nothing?
467
+				if ($critical_page['post'] === null) {
468
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
469
+					// REALLY? Still nothing ??!?!?
470
+					if ($critical_page['post'] === null) {
471
+						$msg = __(
472
+							'The Event Espresso critical page configuration settings could not be updated.',
473
+							'event_espresso'
474
+						);
475
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
476
+						break;
477
+					}
478
+				}
479
+			}
480
+			// check that Post ID matches critical page ID in config
481
+			if (
482
+				isset($critical_page['post']->ID)
483
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
484
+			) {
485
+				//update Config with post ID
486
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
487
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
488
+					$msg = __(
489
+						'The Event Espresso critical page configuration settings could not be updated.',
490
+						'event_espresso'
491
+					);
492
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
493
+				}
494
+			}
495
+			$critical_page_problem =
496
+				! isset($critical_page['post']->post_status)
497
+				|| $critical_page['post']->post_status !== 'publish'
498
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
499
+					? true
500
+					: $critical_page_problem;
501
+		}
502
+		if ($critical_page_problem) {
503
+			$msg = sprintf(
504
+				__(
505
+					'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
506
+					'event_espresso'
507
+				),
508
+				'<a href="'
509
+				. admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
510
+				. '">'
511
+				. __('Event Espresso Critical Pages Settings', 'event_espresso')
512
+				. '</a>'
513
+			);
514
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
515
+		}
516
+		if (EE_Error::has_notices()) {
517
+			EE_Error::get_notices(false, true, true);
518
+		}
519
+	}
520
+
521
+
522
+
523
+	/**
524
+	 * Returns the first post which uses the specified shortcode
525
+	 *
526
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
527
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
528
+	 *                             "[ESPRESSO_THANK_YOU"
529
+	 *                             (we don't search for the closing shortcode bracket because they might have added
530
+	 *                             parameter to the shortcode
531
+	 * @return WP_Post or NULl
532
+	 */
533
+	public static function get_page_by_ee_shortcode($ee_shortcode)
534
+	{
535
+		global $wpdb;
536
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
537
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
538
+		if ($post_id) {
539
+			return get_post($post_id);
540
+		} else {
541
+			return null;
542
+		}
543
+	}
544
+
545
+
546
+	/**
547
+	 *    This function generates a post for critical espresso pages
548
+	 *
549
+	 * @access public
550
+	 * @static
551
+	 * @param array $critical_page
552
+	 * @return array
553
+	 */
554
+	public static function create_critical_page($critical_page)
555
+	{
556
+
557
+		$post_args = array(
558
+			'post_title'     => $critical_page['name'],
559
+			'post_status'    => 'publish',
560
+			'post_type'      => 'page',
561
+			'comment_status' => 'closed',
562
+			'post_content'   => '[' . $critical_page['code'] . ']',
563
+		);
564
+
565
+		$post_id = wp_insert_post($post_args);
566
+		if (! $post_id) {
567
+			$msg = sprintf(
568
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
569
+				$critical_page['name']
570
+			);
571
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
572
+			return $critical_page;
573
+		}
574
+		// get newly created post's details
575
+		if (! $critical_page['post'] = get_post($post_id)) {
576
+			$msg = sprintf(
577
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
578
+				$critical_page['name']
579
+			);
580
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
581
+		}
582
+
583
+		return $critical_page;
584
+
585
+	}
586
+
587
+
588
+
589
+
590
+	/**
591
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
592
+	 * The role being used to check is filterable.
593
+	 *
594
+	 * @since  4.6.0
595
+	 * @global WPDB $wpdb
596
+	 * @return mixed null|int WP_user ID or NULL
597
+	 */
598
+	public static function get_default_creator_id()
599
+	{
600
+		global $wpdb;
601
+		if ( ! empty(self::$_default_creator_id)) {
602
+			return self::$_default_creator_id;
603
+		}/**/
604
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
605
+		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
606
+		$pre_filtered_id = apply_filters(
607
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
608
+			false,
609
+			$role_to_check
610
+		);
611
+		if ($pre_filtered_id !== false) {
612
+			return (int)$pre_filtered_id;
613
+		}
614
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
615
+		$query = $wpdb->prepare(
616
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
617
+			'%' . $role_to_check . '%'
618
+		);
619
+		$user_id = $wpdb->get_var($query);
620
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
621
+		if ($user_id && (int)$user_id) {
622
+			self::$_default_creator_id = (int)$user_id;
623
+			return self::$_default_creator_id;
624
+		} else {
625
+			return null;
626
+		}
627
+	}
628
+
629
+
630
+
631
+	/**
632
+	 * used by EE and EE addons during plugin activation to create tables.
633
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
634
+	 * but includes extra logic regarding activations.
635
+	 *
636
+	 * @access public
637
+	 * @static
638
+	 * @param string  $table_name              without the $wpdb->prefix
639
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
640
+	 *                                         table query)
641
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
642
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
643
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
644
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
645
+	 *                                         you just want to verify the table exists and matches this definition
646
+	 *                                         (and if it HAS data in it you want to leave it be)
647
+	 * @return void
648
+	 * @throws EE_Error if there are database errors
649
+	 */
650
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
651
+	{
652
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
653
+			return;
654
+		}
655
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
656
+		if ( ! function_exists('dbDelta')) {
657
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
658
+		}
659
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
660
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
661
+		// do we need to first delete an existing version of this table ?
662
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
663
+			// ok, delete the table... but ONLY if it's empty
664
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
665
+			// table is NOT empty, are you SURE you want to delete this table ???
666
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
667
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
668
+			} else if ( ! $deleted_safely) {
669
+				// so we should be more cautious rather than just dropping tables so easily
670
+				error_log(
671
+					sprintf(
672
+						__(
673
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
674
+							'event_espresso'
675
+						),
676
+						$wp_table_name,
677
+						'<br/>',
678
+						'espresso_db_update'
679
+					)
680
+				);
681
+			}
682
+		}
683
+		$engine = str_replace('ENGINE=', '', $engine);
684
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
685
+	}
686
+
687
+
688
+
689
+	/**
690
+	 *    add_column_if_it_doesn't_exist
691
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
692
+	 *
693
+	 * @access     public
694
+	 * @static
695
+	 * @deprecated instead use TableManager::addColumn()
696
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
697
+	 * @param string $column_name
698
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
699
+	 *                            'VARCHAR(10)'
700
+	 * @return bool|int
701
+	 */
702
+	public static function add_column_if_it_doesnt_exist(
703
+		$table_name,
704
+		$column_name,
705
+		$column_info = 'INT UNSIGNED NOT NULL'
706
+	) {
707
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
708
+	}
709
+
710
+
711
+	/**
712
+	 * get_fields_on_table
713
+	 * Gets all the fields on the database table.
714
+	 *
715
+	 * @access     public
716
+	 * @deprecated instead use TableManager::getTableColumns()
717
+	 * @static
718
+	 * @param string $table_name , without prefixed $wpdb->prefix
719
+	 * @return array of database column names
720
+	 */
721
+	public static function get_fields_on_table($table_name = null)
722
+	{
723
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
724
+	}
725
+
726
+
727
+	/**
728
+	 * db_table_is_empty
729
+	 *
730
+	 * @access     public\
731
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
732
+	 * @static
733
+	 * @param string $table_name
734
+	 * @return bool
735
+	 */
736
+	public static function db_table_is_empty($table_name)
737
+	{
738
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
739
+	}
740
+
741
+
742
+	/**
743
+	 * delete_db_table_if_empty
744
+	 *
745
+	 * @access public
746
+	 * @static
747
+	 * @param string $table_name
748
+	 * @return bool | int
749
+	 */
750
+	public static function delete_db_table_if_empty($table_name)
751
+	{
752
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
753
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
754
+		}
755
+		return false;
756
+	}
757
+
758
+
759
+	/**
760
+	 * delete_unused_db_table
761
+	 *
762
+	 * @access     public
763
+	 * @static
764
+	 * @deprecated instead use TableManager::dropTable()
765
+	 * @param string $table_name
766
+	 * @return bool | int
767
+	 */
768
+	public static function delete_unused_db_table($table_name)
769
+	{
770
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
771
+	}
772
+
773
+
774
+	/**
775
+	 * drop_index
776
+	 *
777
+	 * @access     public
778
+	 * @static
779
+	 * @deprecated instead use TableManager::dropIndex()
780
+	 * @param string $table_name
781
+	 * @param string $index_name
782
+	 * @return bool | int
783
+	 */
784
+	public static function drop_index($table_name, $index_name)
785
+	{
786
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
787
+	}
788
+
789
+
790
+
791
+	/**
792
+	 * create_database_tables
793
+	 *
794
+	 * @access public
795
+	 * @static
796
+	 * @throws EE_Error
797
+	 * @return boolean success (whether database is setup properly or not)
798
+	 */
799
+	public static function create_database_tables()
800
+	{
801
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
802
+		//find the migration script that sets the database to be compatible with the code
803
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
804
+		if ($dms_name) {
805
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
806
+			$current_data_migration_script->set_migrating(false);
807
+			$current_data_migration_script->schema_changes_before_migration();
808
+			$current_data_migration_script->schema_changes_after_migration();
809
+			if ($current_data_migration_script->get_errors()) {
810
+				if (WP_DEBUG) {
811
+					foreach ($current_data_migration_script->get_errors() as $error) {
812
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
813
+					}
814
+				} else {
815
+					EE_Error::add_error(
816
+						__(
817
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
818 818
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
819
-                            'event_espresso'
820
-                        )
821
-                    );
822
-                }
823
-                return false;
824
-            }
825
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
826
-        } else {
827
-            EE_Error::add_error(
828
-                __(
829
-                    'Could not determine most up-to-date data migration script from which to pull database schema
819
+							'event_espresso'
820
+						)
821
+					);
822
+				}
823
+				return false;
824
+			}
825
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
826
+		} else {
827
+			EE_Error::add_error(
828
+				__(
829
+					'Could not determine most up-to-date data migration script from which to pull database schema
830 830
                      structure. So database is probably not setup properly',
831
-                    'event_espresso'
832
-                ),
833
-                __FILE__,
834
-                __FUNCTION__,
835
-                __LINE__
836
-            );
837
-            return false;
838
-        }
839
-        return true;
840
-    }
841
-
842
-
843
-
844
-    /**
845
-     * initialize_system_questions
846
-     *
847
-     * @access public
848
-     * @static
849
-     * @return void
850
-     */
851
-    public static function initialize_system_questions()
852
-    {
853
-        // QUESTION GROUPS
854
-        global $wpdb;
855
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
856
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
857
-        // what we have
858
-        $question_groups = $wpdb->get_col($SQL);
859
-        // check the response
860
-        $question_groups = is_array($question_groups) ? $question_groups : array();
861
-        // what we should have
862
-        $QSG_systems = array(1, 2);
863
-        // loop thru what we should have and compare to what we have
864
-        foreach ($QSG_systems as $QSG_system) {
865
-            // reset values array
866
-            $QSG_values = array();
867
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
868
-            if (! in_array("$QSG_system", $question_groups)) {
869
-                // add it
870
-                switch ($QSG_system) {
871
-                    case 1:
872
-                        $QSG_values = array(
873
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
874
-                            'QSG_identifier'      => 'personal-information-' . time(),
875
-                            'QSG_desc'            => '',
876
-                            'QSG_order'           => 1,
877
-                            'QSG_show_group_name' => 1,
878
-                            'QSG_show_group_desc' => 1,
879
-                            'QSG_system'          => EEM_Question_Group::system_personal,
880
-                            'QSG_deleted'         => 0,
881
-                        );
882
-                        break;
883
-                    case 2:
884
-                        $QSG_values = array(
885
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
886
-                            'QSG_identifier'      => 'address-information-' . time(),
887
-                            'QSG_desc'            => '',
888
-                            'QSG_order'           => 2,
889
-                            'QSG_show_group_name' => 1,
890
-                            'QSG_show_group_desc' => 1,
891
-                            'QSG_system'          => EEM_Question_Group::system_address,
892
-                            'QSG_deleted'         => 0,
893
-                        );
894
-                        break;
895
-                }
896
-                // make sure we have some values before inserting them
897
-                if (! empty($QSG_values)) {
898
-                    // insert system question
899
-                    $wpdb->insert(
900
-                        $table_name,
901
-                        $QSG_values,
902
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
903
-                    );
904
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
905
-                }
906
-            }
907
-        }
908
-        // QUESTIONS
909
-        global $wpdb;
910
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
911
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
912
-        // what we have
913
-        $questions = $wpdb->get_col($SQL);
914
-        // what we should have
915
-        $QST_systems = array(
916
-            'fname',
917
-            'lname',
918
-            'email',
919
-            'address',
920
-            'address2',
921
-            'city',
922
-            'country',
923
-            'state',
924
-            'zip',
925
-            'phone',
926
-        );
927
-        $order_for_group_1 = 1;
928
-        $order_for_group_2 = 1;
929
-        // loop thru what we should have and compare to what we have
930
-        foreach ($QST_systems as $QST_system) {
931
-            // reset values array
932
-            $QST_values = array();
933
-            // if we don't have what we should have
934
-            if (! in_array($QST_system, $questions)) {
935
-                // add it
936
-                switch ($QST_system) {
937
-                    case 'fname':
938
-                        $QST_values = array(
939
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
940
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
941
-                            'QST_system'        => 'fname',
942
-                            'QST_type'          => 'TEXT',
943
-                            'QST_required'      => 1,
944
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
945
-                            'QST_order'         => 1,
946
-                            'QST_admin_only'    => 0,
947
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
948
-                            'QST_wp_user'       => self::get_default_creator_id(),
949
-                            'QST_deleted'       => 0,
950
-                        );
951
-                        break;
952
-                    case 'lname':
953
-                        $QST_values = array(
954
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
955
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
956
-                            'QST_system'        => 'lname',
957
-                            'QST_type'          => 'TEXT',
958
-                            'QST_required'      => 1,
959
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
960
-                            'QST_order'         => 2,
961
-                            'QST_admin_only'    => 0,
962
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
963
-                            'QST_wp_user'       => self::get_default_creator_id(),
964
-                            'QST_deleted'       => 0,
965
-                        );
966
-                        break;
967
-                    case 'email':
968
-                        $QST_values = array(
969
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
970
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
971
-                            'QST_system'        => 'email',
972
-                            'QST_type'          => 'EMAIL',
973
-                            'QST_required'      => 1,
974
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
975
-                            'QST_order'         => 3,
976
-                            'QST_admin_only'    => 0,
977
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
978
-                            'QST_wp_user'       => self::get_default_creator_id(),
979
-                            'QST_deleted'       => 0,
980
-                        );
981
-                        break;
982
-                    case 'address':
983
-                        $QST_values = array(
984
-                            'QST_display_text'  => __('Address', 'event_espresso'),
985
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
986
-                            'QST_system'        => 'address',
987
-                            'QST_type'          => 'TEXT',
988
-                            'QST_required'      => 0,
989
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
990
-                            'QST_order'         => 4,
991
-                            'QST_admin_only'    => 0,
992
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
993
-                            'QST_wp_user'       => self::get_default_creator_id(),
994
-                            'QST_deleted'       => 0,
995
-                        );
996
-                        break;
997
-                    case 'address2':
998
-                        $QST_values = array(
999
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1000
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1001
-                            'QST_system'        => 'address2',
1002
-                            'QST_type'          => 'TEXT',
1003
-                            'QST_required'      => 0,
1004
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1005
-                            'QST_order'         => 5,
1006
-                            'QST_admin_only'    => 0,
1007
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1008
-                            'QST_wp_user'       => self::get_default_creator_id(),
1009
-                            'QST_deleted'       => 0,
1010
-                        );
1011
-                        break;
1012
-                    case 'city':
1013
-                        $QST_values = array(
1014
-                            'QST_display_text'  => __('City', 'event_espresso'),
1015
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1016
-                            'QST_system'        => 'city',
1017
-                            'QST_type'          => 'TEXT',
1018
-                            'QST_required'      => 0,
1019
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1020
-                            'QST_order'         => 6,
1021
-                            'QST_admin_only'    => 0,
1022
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1023
-                            'QST_wp_user'       => self::get_default_creator_id(),
1024
-                            'QST_deleted'       => 0,
1025
-                        );
1026
-                        break;
1027
-                    case 'country':
1028
-                        $QST_values = array(
1029
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1030
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1031
-                            'QST_system'        => 'country',
1032
-                            'QST_type'          => 'COUNTRY',
1033
-                            'QST_required'      => 0,
1034
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1035
-                            'QST_order'         => 7,
1036
-                            'QST_admin_only'    => 0,
1037
-                            'QST_wp_user'       => self::get_default_creator_id(),
1038
-                            'QST_deleted'       => 0,
1039
-                        );
1040
-                        break;
1041
-                    case 'state':
1042
-                        $QST_values = array(
1043
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1044
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1045
-                            'QST_system'        => 'state',
1046
-                            'QST_type'          => 'STATE',
1047
-                            'QST_required'      => 0,
1048
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1049
-                            'QST_order'         => 8,
1050
-                            'QST_admin_only'    => 0,
1051
-                            'QST_wp_user'       => self::get_default_creator_id(),
1052
-                            'QST_deleted'       => 0,
1053
-                        );
1054
-                        break;
1055
-                    case 'zip':
1056
-                        $QST_values = array(
1057
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1058
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1059
-                            'QST_system'        => 'zip',
1060
-                            'QST_type'          => 'TEXT',
1061
-                            'QST_required'      => 0,
1062
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1063
-                            'QST_order'         => 9,
1064
-                            'QST_admin_only'    => 0,
1065
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1066
-                            'QST_wp_user'       => self::get_default_creator_id(),
1067
-                            'QST_deleted'       => 0,
1068
-                        );
1069
-                        break;
1070
-                    case 'phone':
1071
-                        $QST_values = array(
1072
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1073
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1074
-                            'QST_system'        => 'phone',
1075
-                            'QST_type'          => 'TEXT',
1076
-                            'QST_required'      => 0,
1077
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1078
-                            'QST_order'         => 10,
1079
-                            'QST_admin_only'    => 0,
1080
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1081
-                            'QST_wp_user'       => self::get_default_creator_id(),
1082
-                            'QST_deleted'       => 0,
1083
-                        );
1084
-                        break;
1085
-                }
1086
-                if (! empty($QST_values)) {
1087
-                    // insert system question
1088
-                    $wpdb->insert(
1089
-                        $table_name,
1090
-                        $QST_values,
1091
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1092
-                    );
1093
-                    $QST_ID = $wpdb->insert_id;
1094
-                    // QUESTION GROUP QUESTIONS
1095
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1096
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1097
-                    } else {
1098
-                        $system_question_we_want = EEM_Question_Group::system_address;
1099
-                    }
1100
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1101
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1102
-                    } else {
1103
-                        $id_col = EEM_Question_Group::instance()
1104
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1105
-                        if (is_array($id_col)) {
1106
-                            $QSG_ID = reset($id_col);
1107
-                        } else {
1108
-                            //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1109
-                            EE_Log::instance()->log(
1110
-                                __FILE__,
1111
-                                __FUNCTION__,
1112
-                                sprintf(
1113
-                                    __(
1114
-                                        'Could not associate question %1$s to a question group because no system question
831
+					'event_espresso'
832
+				),
833
+				__FILE__,
834
+				__FUNCTION__,
835
+				__LINE__
836
+			);
837
+			return false;
838
+		}
839
+		return true;
840
+	}
841
+
842
+
843
+
844
+	/**
845
+	 * initialize_system_questions
846
+	 *
847
+	 * @access public
848
+	 * @static
849
+	 * @return void
850
+	 */
851
+	public static function initialize_system_questions()
852
+	{
853
+		// QUESTION GROUPS
854
+		global $wpdb;
855
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
856
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
857
+		// what we have
858
+		$question_groups = $wpdb->get_col($SQL);
859
+		// check the response
860
+		$question_groups = is_array($question_groups) ? $question_groups : array();
861
+		// what we should have
862
+		$QSG_systems = array(1, 2);
863
+		// loop thru what we should have and compare to what we have
864
+		foreach ($QSG_systems as $QSG_system) {
865
+			// reset values array
866
+			$QSG_values = array();
867
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
868
+			if (! in_array("$QSG_system", $question_groups)) {
869
+				// add it
870
+				switch ($QSG_system) {
871
+					case 1:
872
+						$QSG_values = array(
873
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
874
+							'QSG_identifier'      => 'personal-information-' . time(),
875
+							'QSG_desc'            => '',
876
+							'QSG_order'           => 1,
877
+							'QSG_show_group_name' => 1,
878
+							'QSG_show_group_desc' => 1,
879
+							'QSG_system'          => EEM_Question_Group::system_personal,
880
+							'QSG_deleted'         => 0,
881
+						);
882
+						break;
883
+					case 2:
884
+						$QSG_values = array(
885
+							'QSG_name'            => __('Address Information', 'event_espresso'),
886
+							'QSG_identifier'      => 'address-information-' . time(),
887
+							'QSG_desc'            => '',
888
+							'QSG_order'           => 2,
889
+							'QSG_show_group_name' => 1,
890
+							'QSG_show_group_desc' => 1,
891
+							'QSG_system'          => EEM_Question_Group::system_address,
892
+							'QSG_deleted'         => 0,
893
+						);
894
+						break;
895
+				}
896
+				// make sure we have some values before inserting them
897
+				if (! empty($QSG_values)) {
898
+					// insert system question
899
+					$wpdb->insert(
900
+						$table_name,
901
+						$QSG_values,
902
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
903
+					);
904
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
905
+				}
906
+			}
907
+		}
908
+		// QUESTIONS
909
+		global $wpdb;
910
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
911
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
912
+		// what we have
913
+		$questions = $wpdb->get_col($SQL);
914
+		// what we should have
915
+		$QST_systems = array(
916
+			'fname',
917
+			'lname',
918
+			'email',
919
+			'address',
920
+			'address2',
921
+			'city',
922
+			'country',
923
+			'state',
924
+			'zip',
925
+			'phone',
926
+		);
927
+		$order_for_group_1 = 1;
928
+		$order_for_group_2 = 1;
929
+		// loop thru what we should have and compare to what we have
930
+		foreach ($QST_systems as $QST_system) {
931
+			// reset values array
932
+			$QST_values = array();
933
+			// if we don't have what we should have
934
+			if (! in_array($QST_system, $questions)) {
935
+				// add it
936
+				switch ($QST_system) {
937
+					case 'fname':
938
+						$QST_values = array(
939
+							'QST_display_text'  => __('First Name', 'event_espresso'),
940
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
941
+							'QST_system'        => 'fname',
942
+							'QST_type'          => 'TEXT',
943
+							'QST_required'      => 1,
944
+							'QST_required_text' => __('This field is required', 'event_espresso'),
945
+							'QST_order'         => 1,
946
+							'QST_admin_only'    => 0,
947
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
948
+							'QST_wp_user'       => self::get_default_creator_id(),
949
+							'QST_deleted'       => 0,
950
+						);
951
+						break;
952
+					case 'lname':
953
+						$QST_values = array(
954
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
955
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
956
+							'QST_system'        => 'lname',
957
+							'QST_type'          => 'TEXT',
958
+							'QST_required'      => 1,
959
+							'QST_required_text' => __('This field is required', 'event_espresso'),
960
+							'QST_order'         => 2,
961
+							'QST_admin_only'    => 0,
962
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
963
+							'QST_wp_user'       => self::get_default_creator_id(),
964
+							'QST_deleted'       => 0,
965
+						);
966
+						break;
967
+					case 'email':
968
+						$QST_values = array(
969
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
970
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
971
+							'QST_system'        => 'email',
972
+							'QST_type'          => 'EMAIL',
973
+							'QST_required'      => 1,
974
+							'QST_required_text' => __('This field is required', 'event_espresso'),
975
+							'QST_order'         => 3,
976
+							'QST_admin_only'    => 0,
977
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
978
+							'QST_wp_user'       => self::get_default_creator_id(),
979
+							'QST_deleted'       => 0,
980
+						);
981
+						break;
982
+					case 'address':
983
+						$QST_values = array(
984
+							'QST_display_text'  => __('Address', 'event_espresso'),
985
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
986
+							'QST_system'        => 'address',
987
+							'QST_type'          => 'TEXT',
988
+							'QST_required'      => 0,
989
+							'QST_required_text' => __('This field is required', 'event_espresso'),
990
+							'QST_order'         => 4,
991
+							'QST_admin_only'    => 0,
992
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
993
+							'QST_wp_user'       => self::get_default_creator_id(),
994
+							'QST_deleted'       => 0,
995
+						);
996
+						break;
997
+					case 'address2':
998
+						$QST_values = array(
999
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1000
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1001
+							'QST_system'        => 'address2',
1002
+							'QST_type'          => 'TEXT',
1003
+							'QST_required'      => 0,
1004
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1005
+							'QST_order'         => 5,
1006
+							'QST_admin_only'    => 0,
1007
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1008
+							'QST_wp_user'       => self::get_default_creator_id(),
1009
+							'QST_deleted'       => 0,
1010
+						);
1011
+						break;
1012
+					case 'city':
1013
+						$QST_values = array(
1014
+							'QST_display_text'  => __('City', 'event_espresso'),
1015
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1016
+							'QST_system'        => 'city',
1017
+							'QST_type'          => 'TEXT',
1018
+							'QST_required'      => 0,
1019
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1020
+							'QST_order'         => 6,
1021
+							'QST_admin_only'    => 0,
1022
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1023
+							'QST_wp_user'       => self::get_default_creator_id(),
1024
+							'QST_deleted'       => 0,
1025
+						);
1026
+						break;
1027
+					case 'country':
1028
+						$QST_values = array(
1029
+							'QST_display_text'  => __('Country', 'event_espresso'),
1030
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1031
+							'QST_system'        => 'country',
1032
+							'QST_type'          => 'COUNTRY',
1033
+							'QST_required'      => 0,
1034
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1035
+							'QST_order'         => 7,
1036
+							'QST_admin_only'    => 0,
1037
+							'QST_wp_user'       => self::get_default_creator_id(),
1038
+							'QST_deleted'       => 0,
1039
+						);
1040
+						break;
1041
+					case 'state':
1042
+						$QST_values = array(
1043
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1044
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1045
+							'QST_system'        => 'state',
1046
+							'QST_type'          => 'STATE',
1047
+							'QST_required'      => 0,
1048
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1049
+							'QST_order'         => 8,
1050
+							'QST_admin_only'    => 0,
1051
+							'QST_wp_user'       => self::get_default_creator_id(),
1052
+							'QST_deleted'       => 0,
1053
+						);
1054
+						break;
1055
+					case 'zip':
1056
+						$QST_values = array(
1057
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1058
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1059
+							'QST_system'        => 'zip',
1060
+							'QST_type'          => 'TEXT',
1061
+							'QST_required'      => 0,
1062
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1063
+							'QST_order'         => 9,
1064
+							'QST_admin_only'    => 0,
1065
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1066
+							'QST_wp_user'       => self::get_default_creator_id(),
1067
+							'QST_deleted'       => 0,
1068
+						);
1069
+						break;
1070
+					case 'phone':
1071
+						$QST_values = array(
1072
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1073
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1074
+							'QST_system'        => 'phone',
1075
+							'QST_type'          => 'TEXT',
1076
+							'QST_required'      => 0,
1077
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1078
+							'QST_order'         => 10,
1079
+							'QST_admin_only'    => 0,
1080
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1081
+							'QST_wp_user'       => self::get_default_creator_id(),
1082
+							'QST_deleted'       => 0,
1083
+						);
1084
+						break;
1085
+				}
1086
+				if (! empty($QST_values)) {
1087
+					// insert system question
1088
+					$wpdb->insert(
1089
+						$table_name,
1090
+						$QST_values,
1091
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1092
+					);
1093
+					$QST_ID = $wpdb->insert_id;
1094
+					// QUESTION GROUP QUESTIONS
1095
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1096
+						$system_question_we_want = EEM_Question_Group::system_personal;
1097
+					} else {
1098
+						$system_question_we_want = EEM_Question_Group::system_address;
1099
+					}
1100
+					if (isset($QSG_IDs[$system_question_we_want])) {
1101
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1102
+					} else {
1103
+						$id_col = EEM_Question_Group::instance()
1104
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1105
+						if (is_array($id_col)) {
1106
+							$QSG_ID = reset($id_col);
1107
+						} else {
1108
+							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1109
+							EE_Log::instance()->log(
1110
+								__FILE__,
1111
+								__FUNCTION__,
1112
+								sprintf(
1113
+									__(
1114
+										'Could not associate question %1$s to a question group because no system question
1115 1115
                                          group existed',
1116
-                                        'event_espresso'
1117
-                                    ),
1118
-                                    $QST_ID),
1119
-                                'error');
1120
-                            continue;
1121
-                        }
1122
-                    }
1123
-                    // add system questions to groups
1124
-                    $wpdb->insert(
1125
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1126
-                        array(
1127
-                            'QSG_ID'    => $QSG_ID,
1128
-                            'QST_ID'    => $QST_ID,
1129
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1130
-                        ),
1131
-                        array('%d', '%d', '%d')
1132
-                    );
1133
-                }
1134
-            }
1135
-        }
1136
-    }
1137
-
1138
-
1139
-    /**
1140
-     * Makes sure the default payment method (Invoice) is active.
1141
-     * This used to be done automatically as part of constructing the old gateways config
1142
-     *
1143
-     * @throws \EE_Error
1144
-     */
1145
-    public static function insert_default_payment_methods()
1146
-    {
1147
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1148
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1149
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1150
-        } else {
1151
-            EEM_Payment_Method::instance()->verify_button_urls();
1152
-        }
1153
-    }
1154
-
1155
-    /**
1156
-     * insert_default_status_codes
1157
-     *
1158
-     * @access public
1159
-     * @static
1160
-     * @return void
1161
-     */
1162
-    public static function insert_default_status_codes()
1163
-    {
1164
-
1165
-        global $wpdb;
1166
-
1167
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1168
-
1169
-            $table_name = EEM_Status::instance()->table();
1170
-
1171
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1172
-            $wpdb->query($SQL);
1173
-
1174
-            $SQL = "INSERT INTO $table_name
1116
+										'event_espresso'
1117
+									),
1118
+									$QST_ID),
1119
+								'error');
1120
+							continue;
1121
+						}
1122
+					}
1123
+					// add system questions to groups
1124
+					$wpdb->insert(
1125
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1126
+						array(
1127
+							'QSG_ID'    => $QSG_ID,
1128
+							'QST_ID'    => $QST_ID,
1129
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1130
+						),
1131
+						array('%d', '%d', '%d')
1132
+					);
1133
+				}
1134
+			}
1135
+		}
1136
+	}
1137
+
1138
+
1139
+	/**
1140
+	 * Makes sure the default payment method (Invoice) is active.
1141
+	 * This used to be done automatically as part of constructing the old gateways config
1142
+	 *
1143
+	 * @throws \EE_Error
1144
+	 */
1145
+	public static function insert_default_payment_methods()
1146
+	{
1147
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1148
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1149
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1150
+		} else {
1151
+			EEM_Payment_Method::instance()->verify_button_urls();
1152
+		}
1153
+	}
1154
+
1155
+	/**
1156
+	 * insert_default_status_codes
1157
+	 *
1158
+	 * @access public
1159
+	 * @static
1160
+	 * @return void
1161
+	 */
1162
+	public static function insert_default_status_codes()
1163
+	{
1164
+
1165
+		global $wpdb;
1166
+
1167
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1168
+
1169
+			$table_name = EEM_Status::instance()->table();
1170
+
1171
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1172
+			$wpdb->query($SQL);
1173
+
1174
+			$SQL = "INSERT INTO $table_name
1175 1175
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1176 1176
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1177 1177
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1211,521 +1211,521 @@  discard block
 block discarded – undo
1211 1211
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1212 1212
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1213 1213
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1214
-            $wpdb->query($SQL);
1215
-
1216
-        }
1217
-
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     * create_upload_directories
1223
-     * Creates folders in the uploads directory to facilitate addons and templates
1224
-     *
1225
-     * @access public
1226
-     * @static
1227
-     * @return boolean success of verifying upload directories exist
1228
-     */
1229
-    public static function create_upload_directories()
1230
-    {
1231
-        // Create the required folders
1232
-        $folders = array(
1233
-            EVENT_ESPRESSO_TEMPLATE_DIR,
1234
-            EVENT_ESPRESSO_GATEWAY_DIR,
1235
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1236
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1237
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1238
-        );
1239
-        foreach ($folders as $folder) {
1240
-            try {
1241
-                EEH_File::ensure_folder_exists_and_is_writable($folder);
1242
-                @ chmod($folder, 0755);
1243
-            } catch (EE_Error $e) {
1244
-                EE_Error::add_error(
1245
-                    sprintf(
1246
-                        __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1247
-                        $folder,
1248
-                        '<br />' . $e->getMessage()
1249
-                    ),
1250
-                    __FILE__, __FUNCTION__, __LINE__
1251
-                );
1252
-                //indicate we'll need to fix this later
1253
-                update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1254
-                return false;
1255
-            }
1256
-        }
1257
-        //just add the .htaccess file to the logs directory to begin with. Even if logging
1258
-        //is disabled, there might be activation errors recorded in there
1259
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1260
-        //remember EE's folders are all good
1261
-        delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1262
-        return true;
1263
-    }
1264
-
1265
-    /**
1266
-     * Whether the upload directories need to be fixed or not.
1267
-     * If EE is installed but filesystem access isn't initially available,
1268
-     * we need to get the user's filesystem credentials and THEN create them,
1269
-     * so there might be period of time when EE is installed but its
1270
-     * upload directories aren't available. This indicates such a state
1271
-     *
1272
-     * @return boolean
1273
-     */
1274
-    public static function upload_directories_incomplete()
1275
-    {
1276
-        return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1277
-    }
1278
-
1279
-
1280
-    /**
1281
-     * generate_default_message_templates
1282
-     *
1283
-     * @static
1284
-     * @throws EE_Error
1285
-     * @return bool     true means new templates were created.
1286
-     *                  false means no templates were created.
1287
-     *                  This is NOT an error flag. To check for errors you will want
1288
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1289
-     */
1290
-    public static function generate_default_message_templates()
1291
-    {
1292
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1293
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1294
-        /*
1214
+			$wpdb->query($SQL);
1215
+
1216
+		}
1217
+
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 * create_upload_directories
1223
+	 * Creates folders in the uploads directory to facilitate addons and templates
1224
+	 *
1225
+	 * @access public
1226
+	 * @static
1227
+	 * @return boolean success of verifying upload directories exist
1228
+	 */
1229
+	public static function create_upload_directories()
1230
+	{
1231
+		// Create the required folders
1232
+		$folders = array(
1233
+			EVENT_ESPRESSO_TEMPLATE_DIR,
1234
+			EVENT_ESPRESSO_GATEWAY_DIR,
1235
+			EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1236
+			EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1237
+			EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1238
+		);
1239
+		foreach ($folders as $folder) {
1240
+			try {
1241
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1242
+				@ chmod($folder, 0755);
1243
+			} catch (EE_Error $e) {
1244
+				EE_Error::add_error(
1245
+					sprintf(
1246
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1247
+						$folder,
1248
+						'<br />' . $e->getMessage()
1249
+					),
1250
+					__FILE__, __FUNCTION__, __LINE__
1251
+				);
1252
+				//indicate we'll need to fix this later
1253
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1254
+				return false;
1255
+			}
1256
+		}
1257
+		//just add the .htaccess file to the logs directory to begin with. Even if logging
1258
+		//is disabled, there might be activation errors recorded in there
1259
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1260
+		//remember EE's folders are all good
1261
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1262
+		return true;
1263
+	}
1264
+
1265
+	/**
1266
+	 * Whether the upload directories need to be fixed or not.
1267
+	 * If EE is installed but filesystem access isn't initially available,
1268
+	 * we need to get the user's filesystem credentials and THEN create them,
1269
+	 * so there might be period of time when EE is installed but its
1270
+	 * upload directories aren't available. This indicates such a state
1271
+	 *
1272
+	 * @return boolean
1273
+	 */
1274
+	public static function upload_directories_incomplete()
1275
+	{
1276
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1277
+	}
1278
+
1279
+
1280
+	/**
1281
+	 * generate_default_message_templates
1282
+	 *
1283
+	 * @static
1284
+	 * @throws EE_Error
1285
+	 * @return bool     true means new templates were created.
1286
+	 *                  false means no templates were created.
1287
+	 *                  This is NOT an error flag. To check for errors you will want
1288
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1289
+	 */
1290
+	public static function generate_default_message_templates()
1291
+	{
1292
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1293
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1294
+		/*
1295 1295
          * This first method is taking care of ensuring any default messengers
1296 1296
          * that should be made active and have templates generated are done.
1297 1297
          */
1298
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1299
-            $message_resource_manager
1300
-        );
1301
-        /**
1302
-         * This method is verifying there are no NEW default message types
1303
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1304
-         */
1305
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1306
-            $message_resource_manager
1307
-        );
1308
-        //after all is done, let's persist these changes to the db.
1309
-        $message_resource_manager->update_has_activated_messengers_option();
1310
-        $message_resource_manager->update_active_messengers_option();
1311
-        // will return true if either of these are true.  Otherwise will return false.
1312
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1313
-    }
1314
-
1315
-
1316
-
1317
-    /**
1318
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1319
-     * @return array|bool
1320
-     * @throws \EE_Error
1321
-     */
1322
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1323
-        EE_Message_Resource_Manager $message_resource_manager
1324
-    ) {
1325
-        /** @type EE_messenger[] $active_messengers */
1326
-        $active_messengers = $message_resource_manager->active_messengers();
1327
-        $installed_message_types = $message_resource_manager->installed_message_types();
1328
-        $templates_created = false;
1329
-        foreach ($active_messengers as $active_messenger) {
1330
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1331
-            $default_message_type_names_to_activate = array();
1332
-            // looping through each default message type reported by the messenger
1333
-            // and setup the actual message types to activate.
1334
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1335
-                // if already active or has already been activated before we skip
1336
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1337
-                // we also skip if the message type is not installed.
1338
-                if (
1339
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1340
-                        $default_message_type_name_for_messenger,
1341
-                        $active_messenger->name
1342
-                    )
1343
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1344
-                        $active_messenger->name,
1345
-                        $default_message_type_name_for_messenger
1346
-                    )
1347
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1348
-                ) {
1349
-                    continue;
1350
-                }
1351
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1352
-            }
1353
-            //let's activate!
1354
-            $message_resource_manager->ensure_message_types_are_active(
1355
-                $default_message_type_names_to_activate,
1356
-                $active_messenger->name,
1357
-                false
1358
-            );
1359
-            //activate the templates for these message types
1360
-            if ( ! empty($default_message_type_names_to_activate)) {
1361
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1362
-                    $active_messenger->name,
1363
-                    $default_message_type_names_for_messenger,
1364
-                    '',
1365
-                    true
1366
-                );
1367
-            }
1368
-        }
1369
-        return $templates_created;
1370
-    }
1371
-
1372
-
1373
-
1374
-    /**
1375
-     * This will activate and generate default messengers and default message types for those messengers.
1376
-     *
1377
-     * @param EE_message_Resource_Manager $message_resource_manager
1378
-     * @return array|bool  True means there were default messengers and message type templates generated.
1379
-     *                     False means that there were no templates generated
1380
-     *                     (which could simply mean there are no default message types for a messenger).
1381
-     * @throws EE_Error
1382
-     */
1383
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1384
-        EE_Message_Resource_Manager $message_resource_manager
1385
-    ) {
1386
-        /** @type EE_messenger[] $messengers_to_generate */
1387
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1388
-        $installed_message_types = $message_resource_manager->installed_message_types();
1389
-        $templates_generated = false;
1390
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1391
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1392
-            //verify the default message types match an installed message type.
1393
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1394
-                if (
1395
-                    ! isset($installed_message_types[$name])
1396
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1397
-                        $name,
1398
-                        $messenger_to_generate->name
1399
-                    )
1400
-                ) {
1401
-                    unset($default_message_type_names_for_messenger[$key]);
1402
-                }
1403
-            }
1404
-            // in previous iterations, the active_messengers option in the db
1405
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1406
-            // This comment is left here just in case we discover that we _do_ need to update before
1407
-            // passing off to create templates (after the refactor is done).
1408
-            // @todo remove this comment when determined not necessary.
1409
-            $message_resource_manager->activate_messenger(
1410
-                $messenger_to_generate->name,
1411
-                $default_message_type_names_for_messenger,
1412
-                false
1413
-            );
1414
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1415
-            if ( ! empty($default_message_type_names_for_messenger)) {
1416
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1417
-                    $messenger_to_generate->name,
1418
-                    $default_message_type_names_for_messenger,
1419
-                    '',
1420
-                    true
1421
-                );
1422
-            }
1423
-        }
1424
-        return $templates_generated;
1425
-    }
1426
-
1427
-
1428
-    /**
1429
-     * This returns the default messengers to generate templates for on activation of EE.
1430
-     * It considers:
1431
-     * - whether a messenger is already active in the db.
1432
-     * - whether a messenger has been made active at any time in the past.
1433
-     *
1434
-     * @static
1435
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1436
-     * @return EE_messenger[]
1437
-     */
1438
-    protected static function _get_default_messengers_to_generate_on_activation(
1439
-        EE_Message_Resource_Manager $message_resource_manager
1440
-    ) {
1441
-        $active_messengers    = $message_resource_manager->active_messengers();
1442
-        $installed_messengers = $message_resource_manager->installed_messengers();
1443
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1444
-
1445
-        $messengers_to_generate = array();
1446
-        foreach ($installed_messengers as $installed_messenger) {
1447
-            //if installed messenger is a messenger that should be activated on install
1448
-            //and is not already active
1449
-            //and has never been activated
1450
-            if (
1451
-                ! $installed_messenger->activate_on_install
1452
-                || isset($active_messengers[$installed_messenger->name])
1453
-                || isset($has_activated[$installed_messenger->name])
1454
-            ) {
1455
-                continue;
1456
-            }
1457
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1458
-        }
1459
-        return $messengers_to_generate;
1460
-    }
1461
-
1462
-
1463
-    /**
1464
-     * This simply validates active message types to ensure they actually match installed
1465
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1466
-     * rows are set inactive.
1467
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1468
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1469
-     * are still handled in here.
1470
-     *
1471
-     * @since 4.3.1
1472
-     * @return void
1473
-     */
1474
-    public static function validate_messages_system()
1475
-    {
1476
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1477
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1478
-        $message_resource_manager->validate_active_message_types_are_installed();
1479
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1480
-    }
1481
-
1482
-
1483
-    /**
1484
-     * create_no_ticket_prices_array
1485
-     *
1486
-     * @access public
1487
-     * @static
1488
-     * @return void
1489
-     */
1490
-    public static function create_no_ticket_prices_array()
1491
-    {
1492
-        // this creates an array for tracking events that have no active ticket prices created
1493
-        // this allows us to warn admins of the situation so that it can be corrected
1494
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1495
-        if (! $espresso_no_ticket_prices) {
1496
-            add_option('ee_no_ticket_prices', array(), '', false);
1497
-        }
1498
-    }
1499
-
1500
-
1501
-    /**
1502
-     * plugin_deactivation
1503
-     *
1504
-     * @access public
1505
-     * @static
1506
-     * @return void
1507
-     */
1508
-    public static function plugin_deactivation()
1509
-    {
1510
-    }
1511
-
1512
-
1513
-    /**
1514
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1515
-     * (like post meta or term relations)
1516
-     *
1517
-     * @global wpdb $wpdb
1518
-     * @throws \EE_Error
1519
-     */
1520
-    public static function delete_all_espresso_cpt_data()
1521
-    {
1522
-        global $wpdb;
1523
-        //get all the CPT post_types
1524
-        $ee_post_types = array();
1525
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1526
-            if (method_exists($model_name, 'instance')) {
1527
-                $model_obj = call_user_func(array($model_name, 'instance'));
1528
-                if ($model_obj instanceof EEM_CPT_Base) {
1529
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1530
-                }
1531
-            }
1532
-        }
1533
-        //get all our CPTs
1534
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1535
-        $cpt_ids = $wpdb->get_col($query);
1536
-        //delete each post meta and term relations too
1537
-        foreach ($cpt_ids as $post_id) {
1538
-            wp_delete_post($post_id, true);
1539
-        }
1540
-    }
1541
-
1542
-    /**
1543
-     * Deletes all EE custom tables
1544
-     *
1545
-     * @return array
1546
-     */
1547
-    public static function drop_espresso_tables()
1548
-    {
1549
-        $tables = array();
1550
-        // load registry
1551
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1552
-            if (method_exists($model_name, 'instance')) {
1553
-                $model_obj = call_user_func(array($model_name, 'instance'));
1554
-                if ($model_obj instanceof EEM_Base) {
1555
-                    foreach ($model_obj->get_tables() as $table) {
1556
-                        if (strpos($table->get_table_name(), 'esp_')
1557
-                            &&
1558
-                            (
1559
-                                is_main_site()//main site? nuke them all
1560
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1561
-                            )
1562
-                        ) {
1563
-                            $tables[] = $table->get_table_name();
1564
-                        }
1565
-                    }
1566
-                }
1567
-            }
1568
-        }
1569
-
1570
-        //there are some tables whose models were removed.
1571
-        //they should be removed when removing all EE core's data
1572
-        $tables_without_models = array(
1573
-            'esp_promotion',
1574
-            'esp_promotion_applied',
1575
-            'esp_promotion_object',
1576
-            'esp_promotion_rule',
1577
-            'esp_rule',
1578
-        );
1579
-        foreach ($tables_without_models as $table) {
1580
-            $tables[] = $table;
1581
-        }
1582
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1583
-    }
1584
-
1585
-
1586
-
1587
-    /**
1588
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1589
-     * each table name provided has a wpdb prefix attached, and that it exists.
1590
-     * Returns the list actually deleted
1591
-     *
1592
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1593
-     * @global WPDB $wpdb
1594
-     * @param array $table_names
1595
-     * @return array of table names which we deleted
1596
-     */
1597
-    public static function drop_tables($table_names)
1598
-    {
1599
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1600
-    }
1601
-
1602
-
1603
-
1604
-    /**
1605
-     * plugin_uninstall
1606
-     *
1607
-     * @access public
1608
-     * @static
1609
-     * @param bool $remove_all
1610
-     * @return void
1611
-     */
1612
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1613
-    {
1614
-        global $wpdb;
1615
-        self::drop_espresso_tables();
1616
-        $wp_options_to_delete = array(
1617
-            'ee_no_ticket_prices'                => true,
1618
-            'ee_active_messengers'               => true,
1619
-            'ee_has_activated_messenger'         => true,
1620
-            'ee_flush_rewrite_rules'             => true,
1621
-            'ee_config'                          => false,
1622
-            'ee_data_migration_current_db_state' => true,
1623
-            'ee_data_migration_mapping_'         => false,
1624
-            'ee_data_migration_script_'          => false,
1625
-            'ee_data_migrations'                 => true,
1626
-            'ee_dms_map'                         => false,
1627
-            'ee_notices'                         => true,
1628
-            'lang_file_check_'                   => false,
1629
-            'ee_maintenance_mode'                => true,
1630
-            'ee_ueip_optin'                      => true,
1631
-            'ee_ueip_has_notified'               => true,
1632
-            'ee_plugin_activation_errors'        => true,
1633
-            'ee_id_mapping_from'                 => false,
1634
-            'espresso_persistent_admin_notices'  => true,
1635
-            'ee_encryption_key'                  => true,
1636
-            'pue_force_upgrade_'                 => false,
1637
-            'pue_json_error_'                    => false,
1638
-            'pue_install_key_'                   => false,
1639
-            'pue_verification_error_'            => false,
1640
-            'pu_dismissed_upgrade_'              => false,
1641
-            'external_updates-'                  => false,
1642
-            'ee_extra_data'                      => true,
1643
-            'ee_ssn_'                            => false,
1644
-            'ee_rss_'                            => false,
1645
-            'ee_rte_n_tx_'                       => false,
1646
-            'ee_pers_admin_notices'              => true,
1647
-            'ee_job_parameters_'                 => false,
1648
-            'ee_upload_directories_incomplete'   => true,
1649
-            'ee_verified_db_collations'          => true,
1650
-        );
1651
-        if (is_main_site()) {
1652
-            $wp_options_to_delete['ee_network_config'] = true;
1653
-        }
1654
-        $undeleted_options = array();
1655
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1656
-            if ($no_wildcard) {
1657
-                if ( ! delete_option($option_name)) {
1658
-                    $undeleted_options[] = $option_name;
1659
-                }
1660
-            } else {
1661
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1662
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1663
-                    if ( ! delete_option($option_name_from_wildcard)) {
1664
-                        $undeleted_options[] = $option_name_from_wildcard;
1665
-                    }
1666
-                }
1667
-            }
1668
-        }
1669
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1670
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1671
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1672
-            $db_update_sans_ee4 = array();
1673
-            foreach ($espresso_db_update as $version => $times_activated) {
1674
-                if ((string)$version[0] === '3') {//if its NON EE4
1675
-                    $db_update_sans_ee4[$version] = $times_activated;
1676
-                }
1677
-            }
1678
-            update_option('espresso_db_update', $db_update_sans_ee4);
1679
-        }
1680
-        $errors = '';
1681
-        if ( ! empty($undeleted_options)) {
1682
-            $errors .= sprintf(
1683
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1684
-                '<br/>',
1685
-                implode(',<br/>', $undeleted_options)
1686
-            );
1687
-        }
1688
-        if ( ! empty($errors)) {
1689
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1690
-        }
1691
-    }
1692
-
1693
-    /**
1694
-     * Gets the mysql error code from the last used query by wpdb
1695
-     *
1696
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1697
-     */
1698
-    public static function last_wpdb_error_code()
1699
-    {
1700
-        global $wpdb;
1701
-        if ($wpdb->use_mysqli) {
1702
-            return mysqli_errno($wpdb->dbh);
1703
-        } else {
1704
-            return mysql_errno($wpdb->dbh);
1705
-        }
1706
-    }
1707
-
1708
-    /**
1709
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1710
-     *
1711
-     * @global wpdb  $wpdb
1712
-     * @deprecated instead use TableAnalysis::tableExists()
1713
-     * @param string $table_name with or without $wpdb->prefix
1714
-     * @return boolean
1715
-     */
1716
-    public static function table_exists($table_name)
1717
-    {
1718
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1719
-    }
1720
-
1721
-    /**
1722
-     * Resets the cache on EEH_Activation
1723
-     */
1724
-    public static function reset()
1725
-    {
1726
-        self::$_default_creator_id                             = null;
1727
-        self::$_initialized_db_content_already_in_this_request = false;
1728
-    }
1298
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1299
+			$message_resource_manager
1300
+		);
1301
+		/**
1302
+		 * This method is verifying there are no NEW default message types
1303
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1304
+		 */
1305
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1306
+			$message_resource_manager
1307
+		);
1308
+		//after all is done, let's persist these changes to the db.
1309
+		$message_resource_manager->update_has_activated_messengers_option();
1310
+		$message_resource_manager->update_active_messengers_option();
1311
+		// will return true if either of these are true.  Otherwise will return false.
1312
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1313
+	}
1314
+
1315
+
1316
+
1317
+	/**
1318
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1319
+	 * @return array|bool
1320
+	 * @throws \EE_Error
1321
+	 */
1322
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1323
+		EE_Message_Resource_Manager $message_resource_manager
1324
+	) {
1325
+		/** @type EE_messenger[] $active_messengers */
1326
+		$active_messengers = $message_resource_manager->active_messengers();
1327
+		$installed_message_types = $message_resource_manager->installed_message_types();
1328
+		$templates_created = false;
1329
+		foreach ($active_messengers as $active_messenger) {
1330
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1331
+			$default_message_type_names_to_activate = array();
1332
+			// looping through each default message type reported by the messenger
1333
+			// and setup the actual message types to activate.
1334
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1335
+				// if already active or has already been activated before we skip
1336
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1337
+				// we also skip if the message type is not installed.
1338
+				if (
1339
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1340
+						$default_message_type_name_for_messenger,
1341
+						$active_messenger->name
1342
+					)
1343
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1344
+						$active_messenger->name,
1345
+						$default_message_type_name_for_messenger
1346
+					)
1347
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1348
+				) {
1349
+					continue;
1350
+				}
1351
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1352
+			}
1353
+			//let's activate!
1354
+			$message_resource_manager->ensure_message_types_are_active(
1355
+				$default_message_type_names_to_activate,
1356
+				$active_messenger->name,
1357
+				false
1358
+			);
1359
+			//activate the templates for these message types
1360
+			if ( ! empty($default_message_type_names_to_activate)) {
1361
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1362
+					$active_messenger->name,
1363
+					$default_message_type_names_for_messenger,
1364
+					'',
1365
+					true
1366
+				);
1367
+			}
1368
+		}
1369
+		return $templates_created;
1370
+	}
1371
+
1372
+
1373
+
1374
+	/**
1375
+	 * This will activate and generate default messengers and default message types for those messengers.
1376
+	 *
1377
+	 * @param EE_message_Resource_Manager $message_resource_manager
1378
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1379
+	 *                     False means that there were no templates generated
1380
+	 *                     (which could simply mean there are no default message types for a messenger).
1381
+	 * @throws EE_Error
1382
+	 */
1383
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1384
+		EE_Message_Resource_Manager $message_resource_manager
1385
+	) {
1386
+		/** @type EE_messenger[] $messengers_to_generate */
1387
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1388
+		$installed_message_types = $message_resource_manager->installed_message_types();
1389
+		$templates_generated = false;
1390
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1391
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1392
+			//verify the default message types match an installed message type.
1393
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1394
+				if (
1395
+					! isset($installed_message_types[$name])
1396
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1397
+						$name,
1398
+						$messenger_to_generate->name
1399
+					)
1400
+				) {
1401
+					unset($default_message_type_names_for_messenger[$key]);
1402
+				}
1403
+			}
1404
+			// in previous iterations, the active_messengers option in the db
1405
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1406
+			// This comment is left here just in case we discover that we _do_ need to update before
1407
+			// passing off to create templates (after the refactor is done).
1408
+			// @todo remove this comment when determined not necessary.
1409
+			$message_resource_manager->activate_messenger(
1410
+				$messenger_to_generate->name,
1411
+				$default_message_type_names_for_messenger,
1412
+				false
1413
+			);
1414
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1415
+			if ( ! empty($default_message_type_names_for_messenger)) {
1416
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1417
+					$messenger_to_generate->name,
1418
+					$default_message_type_names_for_messenger,
1419
+					'',
1420
+					true
1421
+				);
1422
+			}
1423
+		}
1424
+		return $templates_generated;
1425
+	}
1426
+
1427
+
1428
+	/**
1429
+	 * This returns the default messengers to generate templates for on activation of EE.
1430
+	 * It considers:
1431
+	 * - whether a messenger is already active in the db.
1432
+	 * - whether a messenger has been made active at any time in the past.
1433
+	 *
1434
+	 * @static
1435
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1436
+	 * @return EE_messenger[]
1437
+	 */
1438
+	protected static function _get_default_messengers_to_generate_on_activation(
1439
+		EE_Message_Resource_Manager $message_resource_manager
1440
+	) {
1441
+		$active_messengers    = $message_resource_manager->active_messengers();
1442
+		$installed_messengers = $message_resource_manager->installed_messengers();
1443
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1444
+
1445
+		$messengers_to_generate = array();
1446
+		foreach ($installed_messengers as $installed_messenger) {
1447
+			//if installed messenger is a messenger that should be activated on install
1448
+			//and is not already active
1449
+			//and has never been activated
1450
+			if (
1451
+				! $installed_messenger->activate_on_install
1452
+				|| isset($active_messengers[$installed_messenger->name])
1453
+				|| isset($has_activated[$installed_messenger->name])
1454
+			) {
1455
+				continue;
1456
+			}
1457
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1458
+		}
1459
+		return $messengers_to_generate;
1460
+	}
1461
+
1462
+
1463
+	/**
1464
+	 * This simply validates active message types to ensure they actually match installed
1465
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1466
+	 * rows are set inactive.
1467
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1468
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1469
+	 * are still handled in here.
1470
+	 *
1471
+	 * @since 4.3.1
1472
+	 * @return void
1473
+	 */
1474
+	public static function validate_messages_system()
1475
+	{
1476
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1477
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1478
+		$message_resource_manager->validate_active_message_types_are_installed();
1479
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1480
+	}
1481
+
1482
+
1483
+	/**
1484
+	 * create_no_ticket_prices_array
1485
+	 *
1486
+	 * @access public
1487
+	 * @static
1488
+	 * @return void
1489
+	 */
1490
+	public static function create_no_ticket_prices_array()
1491
+	{
1492
+		// this creates an array for tracking events that have no active ticket prices created
1493
+		// this allows us to warn admins of the situation so that it can be corrected
1494
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1495
+		if (! $espresso_no_ticket_prices) {
1496
+			add_option('ee_no_ticket_prices', array(), '', false);
1497
+		}
1498
+	}
1499
+
1500
+
1501
+	/**
1502
+	 * plugin_deactivation
1503
+	 *
1504
+	 * @access public
1505
+	 * @static
1506
+	 * @return void
1507
+	 */
1508
+	public static function plugin_deactivation()
1509
+	{
1510
+	}
1511
+
1512
+
1513
+	/**
1514
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1515
+	 * (like post meta or term relations)
1516
+	 *
1517
+	 * @global wpdb $wpdb
1518
+	 * @throws \EE_Error
1519
+	 */
1520
+	public static function delete_all_espresso_cpt_data()
1521
+	{
1522
+		global $wpdb;
1523
+		//get all the CPT post_types
1524
+		$ee_post_types = array();
1525
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1526
+			if (method_exists($model_name, 'instance')) {
1527
+				$model_obj = call_user_func(array($model_name, 'instance'));
1528
+				if ($model_obj instanceof EEM_CPT_Base) {
1529
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1530
+				}
1531
+			}
1532
+		}
1533
+		//get all our CPTs
1534
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1535
+		$cpt_ids = $wpdb->get_col($query);
1536
+		//delete each post meta and term relations too
1537
+		foreach ($cpt_ids as $post_id) {
1538
+			wp_delete_post($post_id, true);
1539
+		}
1540
+	}
1541
+
1542
+	/**
1543
+	 * Deletes all EE custom tables
1544
+	 *
1545
+	 * @return array
1546
+	 */
1547
+	public static function drop_espresso_tables()
1548
+	{
1549
+		$tables = array();
1550
+		// load registry
1551
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1552
+			if (method_exists($model_name, 'instance')) {
1553
+				$model_obj = call_user_func(array($model_name, 'instance'));
1554
+				if ($model_obj instanceof EEM_Base) {
1555
+					foreach ($model_obj->get_tables() as $table) {
1556
+						if (strpos($table->get_table_name(), 'esp_')
1557
+							&&
1558
+							(
1559
+								is_main_site()//main site? nuke them all
1560
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1561
+							)
1562
+						) {
1563
+							$tables[] = $table->get_table_name();
1564
+						}
1565
+					}
1566
+				}
1567
+			}
1568
+		}
1569
+
1570
+		//there are some tables whose models were removed.
1571
+		//they should be removed when removing all EE core's data
1572
+		$tables_without_models = array(
1573
+			'esp_promotion',
1574
+			'esp_promotion_applied',
1575
+			'esp_promotion_object',
1576
+			'esp_promotion_rule',
1577
+			'esp_rule',
1578
+		);
1579
+		foreach ($tables_without_models as $table) {
1580
+			$tables[] = $table;
1581
+		}
1582
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1583
+	}
1584
+
1585
+
1586
+
1587
+	/**
1588
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1589
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1590
+	 * Returns the list actually deleted
1591
+	 *
1592
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1593
+	 * @global WPDB $wpdb
1594
+	 * @param array $table_names
1595
+	 * @return array of table names which we deleted
1596
+	 */
1597
+	public static function drop_tables($table_names)
1598
+	{
1599
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1600
+	}
1601
+
1602
+
1603
+
1604
+	/**
1605
+	 * plugin_uninstall
1606
+	 *
1607
+	 * @access public
1608
+	 * @static
1609
+	 * @param bool $remove_all
1610
+	 * @return void
1611
+	 */
1612
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1613
+	{
1614
+		global $wpdb;
1615
+		self::drop_espresso_tables();
1616
+		$wp_options_to_delete = array(
1617
+			'ee_no_ticket_prices'                => true,
1618
+			'ee_active_messengers'               => true,
1619
+			'ee_has_activated_messenger'         => true,
1620
+			'ee_flush_rewrite_rules'             => true,
1621
+			'ee_config'                          => false,
1622
+			'ee_data_migration_current_db_state' => true,
1623
+			'ee_data_migration_mapping_'         => false,
1624
+			'ee_data_migration_script_'          => false,
1625
+			'ee_data_migrations'                 => true,
1626
+			'ee_dms_map'                         => false,
1627
+			'ee_notices'                         => true,
1628
+			'lang_file_check_'                   => false,
1629
+			'ee_maintenance_mode'                => true,
1630
+			'ee_ueip_optin'                      => true,
1631
+			'ee_ueip_has_notified'               => true,
1632
+			'ee_plugin_activation_errors'        => true,
1633
+			'ee_id_mapping_from'                 => false,
1634
+			'espresso_persistent_admin_notices'  => true,
1635
+			'ee_encryption_key'                  => true,
1636
+			'pue_force_upgrade_'                 => false,
1637
+			'pue_json_error_'                    => false,
1638
+			'pue_install_key_'                   => false,
1639
+			'pue_verification_error_'            => false,
1640
+			'pu_dismissed_upgrade_'              => false,
1641
+			'external_updates-'                  => false,
1642
+			'ee_extra_data'                      => true,
1643
+			'ee_ssn_'                            => false,
1644
+			'ee_rss_'                            => false,
1645
+			'ee_rte_n_tx_'                       => false,
1646
+			'ee_pers_admin_notices'              => true,
1647
+			'ee_job_parameters_'                 => false,
1648
+			'ee_upload_directories_incomplete'   => true,
1649
+			'ee_verified_db_collations'          => true,
1650
+		);
1651
+		if (is_main_site()) {
1652
+			$wp_options_to_delete['ee_network_config'] = true;
1653
+		}
1654
+		$undeleted_options = array();
1655
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1656
+			if ($no_wildcard) {
1657
+				if ( ! delete_option($option_name)) {
1658
+					$undeleted_options[] = $option_name;
1659
+				}
1660
+			} else {
1661
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1662
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1663
+					if ( ! delete_option($option_name_from_wildcard)) {
1664
+						$undeleted_options[] = $option_name_from_wildcard;
1665
+					}
1666
+				}
1667
+			}
1668
+		}
1669
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1670
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1671
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1672
+			$db_update_sans_ee4 = array();
1673
+			foreach ($espresso_db_update as $version => $times_activated) {
1674
+				if ((string)$version[0] === '3') {//if its NON EE4
1675
+					$db_update_sans_ee4[$version] = $times_activated;
1676
+				}
1677
+			}
1678
+			update_option('espresso_db_update', $db_update_sans_ee4);
1679
+		}
1680
+		$errors = '';
1681
+		if ( ! empty($undeleted_options)) {
1682
+			$errors .= sprintf(
1683
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1684
+				'<br/>',
1685
+				implode(',<br/>', $undeleted_options)
1686
+			);
1687
+		}
1688
+		if ( ! empty($errors)) {
1689
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1690
+		}
1691
+	}
1692
+
1693
+	/**
1694
+	 * Gets the mysql error code from the last used query by wpdb
1695
+	 *
1696
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1697
+	 */
1698
+	public static function last_wpdb_error_code()
1699
+	{
1700
+		global $wpdb;
1701
+		if ($wpdb->use_mysqli) {
1702
+			return mysqli_errno($wpdb->dbh);
1703
+		} else {
1704
+			return mysql_errno($wpdb->dbh);
1705
+		}
1706
+	}
1707
+
1708
+	/**
1709
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1710
+	 *
1711
+	 * @global wpdb  $wpdb
1712
+	 * @deprecated instead use TableAnalysis::tableExists()
1713
+	 * @param string $table_name with or without $wpdb->prefix
1714
+	 * @return boolean
1715
+	 */
1716
+	public static function table_exists($table_name)
1717
+	{
1718
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1719
+	}
1720
+
1721
+	/**
1722
+	 * Resets the cache on EEH_Activation
1723
+	 */
1724
+	public static function reset()
1725
+	{
1726
+		self::$_default_creator_id                             = null;
1727
+		self::$_initialized_db_content_already_in_this_request = false;
1728
+	}
1729 1729
 }
1730 1730
 // End of file EEH_Activation.helper.php
1731 1731
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.