Completed
Branch FET/11400/gutenberg-block-mana... (002e7d)
by
unknown
13:10
created
core/libraries/messages/EE_messenger.lib.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -647,15 +647,15 @@
 block discarded – undo
647 647
 
648 648
 		if ( $send ) {
649 649
 			//are we overriding any existing template fields?
650
-            $settings = apply_filters(
651
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
652
-                $this->get_existing_test_settings(),
653
-                $this,
654
-                $send,
655
-                $message,
656
-                $message_type
657
-            );
658
-            if ( ! empty( $settings ) ) {
650
+			$settings = apply_filters(
651
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
652
+				$this->get_existing_test_settings(),
653
+				$this,
654
+				$send,
655
+				$message,
656
+				$message_type
657
+			);
658
+			if ( ! empty( $settings ) ) {
659 659
 				foreach ( $settings as $field => $value ) {
660 660
 					$this->_set_template_value( $field, $value );
661 661
 				}
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 use \EventEspresso\core\exceptions\SendMessageException;
3 3
 
4
-if (!defined('EVENT_ESPRESSO_VERSION') )
4
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
5 5
 	exit('NO direct script access allowed');
6 6
 
7 7
 /**
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	 * @return void
280 280
 	 */
281 281
 	public function enqueue_scripts_styles() {
282
-		do_action( 'AHEE__EE_messenger__enqueue_scripts_styles');
282
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283 283
 	}
284 284
 
285 285
 
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 
350 350
 		$this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.');
351 351
 
352
-		$this->_supports_labels = apply_filters( 'FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this );
352
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
353 353
 	}
354 354
 
355 355
 
@@ -364,10 +364,10 @@  discard block
 block discarded – undo
364 364
 	 * @return stdClass
365 365
 	 */
366 366
 	public function get_supports_labels() {
367
-		if ( empty( $this->_supports_labels->template_pack ) || empty( $this->_supports_labels->template_variation) ) {
367
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
368 368
 			$this->_set_supports_labels_defaults();
369 369
 		}
370
-		return apply_filters( 'FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this );
370
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
371 371
 	}
372 372
 
373 373
 
@@ -387,10 +387,10 @@  discard block
 block discarded – undo
387 387
 	 *
388 388
 	 * @return string                    path or url for the requested variation.
389 389
 	 */
390
-	public function get_variation( EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE ) {
390
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE) {
391 391
 		$this->_tmp_pack = $pack;
392
-		$variation_path = apply_filters( 'EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters );
393
-		$variation_path = empty( $variation_path ) ? $this->_tmp_pack->get_variation( $this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters ) : $variation_path;
392
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
393
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
394 394
 		return $variation_path;
395 395
 
396 396
 	}
@@ -408,13 +408,13 @@  discard block
 block discarded – undo
408 408
 	 * @return array
409 409
 	 */
410 410
 	public function get_default_message_types() {
411
-		$class = get_class( $this );
411
+		$class = get_class($this);
412 412
 
413 413
 		//messenger specific filter
414
-		$default_types = apply_filters( 'FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this );
414
+		$default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
415 415
 
416 416
 		//all messengers filter
417
-		$default_types = apply_filters( 'FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this );
417
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
418 418
 		return $default_types;
419 419
 	}
420 420
 
@@ -429,14 +429,14 @@  discard block
 block discarded – undo
429 429
 	 * @return array
430 430
 	 */
431 431
 	public function get_valid_message_types() {
432
-		$class = get_class( $this );
432
+		$class = get_class($this);
433 433
 
434 434
 		//messenger specific filter
435 435
 		//messenger specific filter
436
-		$valid_types = apply_filters( 'FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this );
436
+		$valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
437 437
 
438 438
 		//all messengers filter
439
-		$valid_types = apply_filters( 'FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this );
439
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
440 440
 		return $valid_types;
441 441
 	}
442 442
 
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 	 * @access public
451 451
 	 * @param array $new_config Whatever is put in here will reset the _validator_config property
452 452
 	 */
453
-	public function set_validator_config( $new_config ) {
453
+	public function set_validator_config($new_config) {
454 454
 		$this->_validator_config = $new_config;
455 455
 	}
456 456
 
@@ -466,8 +466,8 @@  discard block
 block discarded – undo
466 466
 	public function get_validator_config() {
467 467
 		$class = get_class($this);
468 468
 
469
-		$config = apply_filters( 'FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this );
470
-		$config = apply_filters( 'FHEE__EE_messenger__get_validator_config', $config, $this );
469
+		$config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
470
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
471 471
 		return $config;
472 472
 	}
473 473
 
@@ -484,8 +484,8 @@  discard block
 block discarded – undo
484 484
 	 * @access public
485 485
 	 * @return string content for page
486 486
 	 */
487
-	public function get_messenger_admin_page_content( $page, $action = null, $extra = array(), $message_types = array() ) {
488
-		return $this->_get_admin_page_content( $page, $action, $extra, $message_types );
487
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array()) {
488
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
489 489
 	}
490 490
 
491 491
 
@@ -495,20 +495,20 @@  discard block
 block discarded – undo
495 495
 	 * @param array $extra
496 496
 	 * @return mixed|string
497 497
 	 */
498
-	protected function _get_admin_content_events_edit( $message_types, $extra ) {
498
+	protected function _get_admin_content_events_edit($message_types, $extra) {
499 499
 		//defaults
500 500
 		$template_args = array();
501 501
 		$selector_rows = '';
502 502
 
503 503
 		//we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
504
-		$event_id = isset( $extra['event'] ) ? $extra['event'] : NULL;
504
+		$event_id = isset($extra['event']) ? $extra['event'] : NULL;
505 505
 
506
-		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
507
-		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
506
+		$template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
507
+		$template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';
508 508
 
509 509
 		//array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
510 510
 		$global_templates = EEM_Message_Template_Group::instance()->get_all(
511
-			array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
511
+			array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true))
512 512
 		);
513 513
 		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
514 514
 			$event_id,
@@ -517,55 +517,55 @@  discard block
 block discarded – undo
517 517
 				'MTP_is_active' => true
518 518
 			)
519 519
 		);
520
-		$templates_for_event = !empty( $templates_for_event ) ? $templates_for_event : array();
520
+		$templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
521 521
 
522 522
 		//so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
523
-		foreach ( $global_templates as $mtpgID => $mtpg ) {
524
-			if ( $mtpg instanceof EE_Message_Template_Group ) {
523
+		foreach ($global_templates as $mtpgID => $mtpg) {
524
+			if ($mtpg instanceof EE_Message_Template_Group) {
525 525
 				//verify this message type is supposed to show on this page
526 526
 				$mtp_obj = $mtpg->message_type_obj();
527
-				if ( ! $mtp_obj instanceof EE_message_type ) {
527
+				if ( ! $mtp_obj instanceof EE_message_type) {
528 528
 					continue;
529 529
 				}
530
-				$mtp_obj->admin_registered_pages = (array)$mtp_obj->admin_registered_pages;
531
-				if ( ! in_array( 'events_edit', $mtp_obj->admin_registered_pages ) ) {
530
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
531
+				if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
532 532
 					continue;
533 533
 				}
534 534
 				$select_values = array();
535
-				$select_values[ $mtpgID ] = __( 'Global', 'event_espresso' );
536
-				$default_value = array_key_exists( $mtpgID, $templates_for_event ) && ! $mtpg->get( 'MTP_is_override' ) ? $mtpgID : null;
535
+				$select_values[$mtpgID] = __('Global', 'event_espresso');
536
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
537 537
 				//if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
538
-				if ( ! $mtpg->get( 'MTP_is_override' ) ) {
538
+				if ( ! $mtpg->get('MTP_is_override')) {
539 539
 					//any custom templates for this message type?
540
-					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt( $this->name, $mtpg->message_type() );
541
-					foreach ( $custom_templates as $cmtpgID => $cmtpg ) {
542
-						$select_values[ $cmtpgID ] = $cmtpg->name();
543
-						$default_value = array_key_exists( $cmtpgID, $templates_for_event ) ? $cmtpgID : $default_value;
540
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
541
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
542
+						$select_values[$cmtpgID] = $cmtpg->name();
543
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
544 544
 					}
545 545
 				}
546 546
 				//if there is no $default_value then we set it as the global
547
-				$default_value = empty( $default_value ) ? $mtpgID : $default_value;
548
-				$edit_url = EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url( 'admin.php' ) );
549
-				$create_url = EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url( 'admin.php' ) );
550
-				$st_args[ 'mt_name' ] = ucwords( $mtp_obj->label[ 'singular' ] );
551
-				$st_args[ 'mt_slug' ] = $mtpg->message_type();
552
-				$st_args[ 'messenger_slug' ] = $this->name;
553
-				$st_args[ 'selector' ] = EEH_Form_Fields::select_input( 'event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector' );
547
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
548
+				$edit_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php'));
549
+				$create_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value), admin_url('admin.php'));
550
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
551
+				$st_args['mt_slug'] = $mtpg->message_type();
552
+				$st_args['messenger_slug'] = $this->name;
553
+				$st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation['.$mtpgID.']', $select_values, $default_value, 'data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'"', 'message-template-selector');
554 554
 				//note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
555
-				$st_args[ 'create_button' ] = $mtpg->get( 'MTP_is_override' ) ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __( 'Create New Custom', 'event_espresso' ) . '</a>';
556
-				$st_args[ 'create_button' ] = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_messages', 'espresso_messages_add_new_message_template' ) ? $st_args[ 'create_button' ] : '';
557
-				$st_args[ 'edit_button' ] = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID ) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __( 'Edit', 'event_espresso' ) . '</a>' : '';
558
-				$selector_rows .= EEH_Template::display_template( $template_row_path, $st_args, true );
555
+				$st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$create_url.'" class="button button-small create-mtpg-button">'.__('Create New Custom', 'event_espresso').'</a>';
556
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
557
+				$st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$edit_url.'" class="button button-small edit-mtpg-button">'.__('Edit', 'event_espresso').'</a>' : '';
558
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
559 559
 			}
560 560
 		}
561 561
 
562 562
 		//if no selectors present then get out.
563
-		if ( empty( $selector_rows ) ) {
563
+		if (empty($selector_rows)) {
564 564
 			return '';
565 565
 		}
566 566
 
567 567
 		$template_args['selector_rows'] = $selector_rows;
568
-		return EEH_Template::display_template( $template_wrapper_path, $template_args, TRUE );
568
+		return EEH_Template::display_template($template_wrapper_path, $template_args, TRUE);
569 569
 	}
570 570
 
571 571
 
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	 * @return array $this->_template_fields
581 581
 	 */
582 582
 	public function get_template_fields() {
583
-		$template_fields = apply_filters( 'FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this );
584
-		$template_fields = apply_filters( 'FHEE__EE_messenger__get_template_fields', $template_fields, $this );
583
+		$template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
584
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
585 585
 		return $template_fields;
586 586
 	}
587 587
 
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
 	 * @param mixed $value
596 596
 	 */
597 597
 	protected function _set_template_value($item, $value) {
598
-		if ( array_key_exists($item, $this->_template_fields) ) {
599
-			$prop = '_' . $item;
600
-			$this->{$prop}= $value;
598
+		if (array_key_exists($item, $this->_template_fields)) {
599
+			$prop = '_'.$item;
600
+			$this->{$prop} = $value;
601 601
 		}
602 602
 	}
603 603
 
@@ -615,18 +615,18 @@  discard block
 block discarded – undo
615 615
 	 *
616 616
 	 * @throws SendMessageException
617 617
 	 */
618
-	final public function send_message( $message, EE_message_type $message_type ) {
618
+	final public function send_message($message, EE_message_type $message_type) {
619 619
 		try {
620
-			$this->_validate_and_setup( $message );
620
+			$this->_validate_and_setup($message);
621 621
 			$this->_incoming_message_type = $message_type;
622 622
 			$response = $this->_send_message();
623
-			if ( $response instanceof WP_Error ) {
624
-				EE_Error::add_error( $response->get_error_message(), __FILE__, __FUNCTION__, __LINE__ );
623
+			if ($response instanceof WP_Error) {
624
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
625 625
 				$response = false;
626 626
 			}
627
-		} catch ( \Exception $e ) {
627
+		} catch (\Exception $e) {
628 628
 			//convert to an instance of SendMessageException
629
-			throw new SendMessageException( $e->getMessage() );
629
+			throw new SendMessageException($e->getMessage());
630 630
 		}
631 631
 		return $response;
632 632
 	}
@@ -640,12 +640,12 @@  discard block
 block discarded – undo
640 640
 	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
641 641
 	 * @return string          return the message html content
642 642
 	 */
643
-	public function get_preview( EE_Message $message, EE_message_type $message_type, $send = false ) {
644
-		$this->_validate_and_setup( $message );
643
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false) {
644
+		$this->_validate_and_setup($message);
645 645
 
646 646
 		$this->_incoming_message_type = $message_type;
647 647
 
648
-		if ( $send ) {
648
+		if ($send) {
649 649
 			//are we overriding any existing template fields?
650 650
             $settings = apply_filters(
651 651
                 'FHEE__EE_messenger__get_preview__messenger_test_settings',
@@ -655,20 +655,20 @@  discard block
 block discarded – undo
655 655
                 $message,
656 656
                 $message_type
657 657
             );
658
-            if ( ! empty( $settings ) ) {
659
-				foreach ( $settings as $field => $value ) {
660
-					$this->_set_template_value( $field, $value );
658
+            if ( ! empty($settings)) {
659
+				foreach ($settings as $field => $value) {
660
+					$this->_set_template_value($field, $value);
661 661
 				}
662 662
 			}
663 663
 		}
664 664
 
665 665
 		//enqueue preview js so that any links/buttons on the page are disabled.
666
-		if ( ! $send ) {
666
+		if ( ! $send) {
667 667
 			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
668 668
 			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
669
-			add_action( 'admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10 );
670
-			add_action( 'wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10 );
671
-			add_action( 'AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10 );
669
+			add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
670
+			add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
671
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
672 672
 		}
673 673
 
674 674
 		return $send ? $this->_send_message() : $this->_preview();
@@ -686,10 +686,10 @@  discard block
 block discarded – undo
686 686
 	 */
687 687
 	public function add_preview_script() {
688 688
 		//error message
689
-		EE_Registry::$i18n_js_strings[ 'links_disabled' ] = __( 'All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso' );
690
-		wp_register_script( 'ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true );
691
-		wp_localize_script( 'ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings );
692
-		wp_enqueue_script( 'ee-messages-preview-js' );
689
+		EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso');
690
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
691
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
692
+		wp_enqueue_script('ee-messages-preview-js');
693 693
 	}
694 694
 
695 695
 
@@ -700,13 +700,13 @@  discard block
 block discarded – undo
700 700
 	 * @param  EE_Message $message
701 701
 	 * @throws EE_Error
702 702
 	 */
703
-	protected function _validate_and_setup( EE_Message $message ) {
703
+	protected function _validate_and_setup(EE_Message $message) {
704 704
 		$template_pack = $message->get_template_pack();
705 705
 		$variation = $message->get_template_pack_variation();
706 706
 
707 707
 		//verify we have the required template pack value on the $message object.
708
-		if ( ! $template_pack instanceof EE_Messages_Template_Pack ) {
709
-			throw new EE_Error( __('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso' ) );
708
+		if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
709
+			throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
710 710
 		}
711 711
 
712 712
 		$this->_tmp_pack = $template_pack;
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
 
716 716
 		$template_fields = $this->get_template_fields();
717 717
 
718
-		foreach ( $template_fields as $template => $value ) {
719
-			if ( $template !== 'extra' ) {
720
-				$column_value = $message->get_field_or_extra_meta( 'MSG_' . $template );
718
+		foreach ($template_fields as $template => $value) {
719
+			if ($template !== 'extra') {
720
+				$column_value = $message->get_field_or_extra_meta('MSG_'.$template);
721 721
 				$message_template_value = $column_value ? $column_value : null;
722
-				$this->_set_template_value( $template, $message_template_value );
722
+				$this->_set_template_value($template, $message_template_value);
723 723
 			}
724 724
 		}
725 725
 	}
@@ -734,19 +734,19 @@  discard block
 block discarded – undo
734 734
 	 * @return string
735 735
 	 * @throws \EE_Error
736 736
 	 */
737
-	protected function _get_main_template( $preview = FALSE ) {
737
+	protected function _get_main_template($preview = FALSE) {
738 738
 		$type = $preview ? 'preview' : 'main';
739 739
 
740
-		$wrapper_template = $this->_tmp_pack->get_wrapper( $this->name, $type );
740
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
741 741
 
742 742
 		//check file exists and is readable
743
-		if ( !is_readable( $wrapper_template ) )
744
-			throw new EE_Error( sprintf( __('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso' ), ucwords($this->label['singular']) , $wrapper_template ) );
743
+		if ( ! is_readable($wrapper_template))
744
+			throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
745 745
 
746 746
 		//add message type to template args
747 747
 		$this->_template_args['message_type'] = $this->_incoming_message_type;
748 748
 
749
-		return EEH_Template::display_template( $wrapper_template, $this->_template_args, TRUE );
749
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE);
750 750
 	}
751 751
 
752 752
 
@@ -782,9 +782,9 @@  discard block
 block discarded – undo
782 782
 	 */
783 783
 	public function get_existing_test_settings() {
784 784
 		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
785
-		$Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
785
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
786 786
 		$settings = $Message_Resource_Manager->get_active_messengers_option();
787
-		return isset( $settings[ $this->name ]['test_settings'] ) ? $settings[ $this->name ]['test_settings'] : array();
787
+		return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
788 788
 	}
789 789
 
790 790
 
@@ -796,12 +796,12 @@  discard block
 block discarded – undo
796 796
 	 * @param $settings
797 797
 	 * @return bool success/fail
798 798
 	 */
799
-	public function set_existing_test_settings( $settings ) {
799
+	public function set_existing_test_settings($settings) {
800 800
 		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
801
-		$Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
801
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
802 802
 		$existing = $Message_Resource_Manager->get_active_messengers_option();
803
-		$existing[ $this->name ]['test_settings'] = $settings;
804
-		return $Message_Resource_Manager->update_active_messengers_option( $existing );
803
+		$existing[$this->name]['test_settings'] = $settings;
804
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
805 805
 	}
806 806
 
807 807
 
@@ -814,21 +814,21 @@  discard block
 block discarded – undo
814 814
 	 * @param string $field The field to retrieve the label for
815 815
 	 * @return string        	  The label
816 816
 	 */
817
-	public function get_field_label( $field ) {
817
+	public function get_field_label($field) {
818 818
 		//first let's see if the field requests is in the top level array.
819
-		if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) )
819
+		if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label']))
820 820
 			return $this->_template[$field]['label'];
821 821
 
822 822
 		//nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
823
-		if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] )  )
823
+		if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label']))
824 824
 			return $this->_template_fields['extra'][$field]['main']['label'];
825 825
 
826 826
 		//now it's possible this field may just be existing in any of the extra array items.
827
-		if ( !empty( $this->_template_fields['extra'] ) && is_array( $this->_template_fields['extra'] ) ) {
828
-			foreach ( $this->_template_fields['extra'] as $main_field => $subfields ) {
829
-				if ( !is_array( $subfields ) )
827
+		if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
828
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
829
+				if ( ! is_array($subfields))
830 830
 					continue;
831
-				if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) )
831
+				if (isset($subfields[$field]) && ! empty($subfields[$field]['label']))
832 832
 					return $subfields[$field]['label'];
833 833
 			}
834 834
 		}
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
 	 *
850 850
 	 * @return void
851 851
 	 */
852
-	public function do_secondary_messenger_hooks( $sending_messenger_name ) {
852
+	public function do_secondary_messenger_hooks($sending_messenger_name) {
853 853
 		return;
854 854
 	}
855 855
 
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +4113 added lines, -4113 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidInterfaceException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('NO direct script access allowed');
8
+	exit('NO direct script access allowed');
9 9
 }
10 10
 
11 11
 /**
@@ -23,2554 +23,2554 @@  discard block
 block discarded – undo
23 23
 class Messages_Admin_Page extends EE_Admin_Page
24 24
 {
25 25
     
26
-    /**
27
-     * @type EE_Message_Resource_Manager $_message_resource_manager
28
-     */
29
-    protected $_message_resource_manager;
26
+	/**
27
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
28
+	 */
29
+	protected $_message_resource_manager;
30 30
     
31
-    /**
32
-     * @type string $_active_message_type_name
33
-     */
34
-    protected $_active_message_type_name = '';
31
+	/**
32
+	 * @type string $_active_message_type_name
33
+	 */
34
+	protected $_active_message_type_name = '';
35 35
     
36
-    /**
37
-     * @type EE_messenger $_active_messenger
38
-     */
39
-    protected $_active_messenger;
40
-    protected $_activate_state;
41
-    protected $_activate_meta_box_type;
42
-    protected $_current_message_meta_box;
43
-    protected $_current_message_meta_box_object;
44
-    protected $_context_switcher;
45
-    protected $_shortcodes = array();
46
-    protected $_active_messengers = array();
47
-    protected $_active_message_types = array();
36
+	/**
37
+	 * @type EE_messenger $_active_messenger
38
+	 */
39
+	protected $_active_messenger;
40
+	protected $_activate_state;
41
+	protected $_activate_meta_box_type;
42
+	protected $_current_message_meta_box;
43
+	protected $_current_message_meta_box_object;
44
+	protected $_context_switcher;
45
+	protected $_shortcodes = array();
46
+	protected $_active_messengers = array();
47
+	protected $_active_message_types = array();
48 48
     
49
-    /**
50
-     * @var EE_Message_Template_Group $_message_template_group
51
-     */
52
-    protected $_message_template_group;
53
-    protected $_m_mt_settings = array();
49
+	/**
50
+	 * @var EE_Message_Template_Group $_message_template_group
51
+	 */
52
+	protected $_message_template_group;
53
+	protected $_m_mt_settings = array();
54 54
     
55 55
     
56
-    /**
57
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
-     * IF there is no group then it gets automatically set to the Default template pack.
59
-     *
60
-     * @since 4.5.0
61
-     *
62
-     * @var EE_Messages_Template_Pack
63
-     */
64
-    protected $_template_pack;
56
+	/**
57
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
+	 * IF there is no group then it gets automatically set to the Default template pack.
59
+	 *
60
+	 * @since 4.5.0
61
+	 *
62
+	 * @var EE_Messages_Template_Pack
63
+	 */
64
+	protected $_template_pack;
65 65
     
66 66
     
67
-    /**
68
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
-     * group is.  If there is no group then it automatically gets set to default.
70
-     *
71
-     * @since 4.5.0
72
-     *
73
-     * @var string
74
-     */
75
-    protected $_variation;
67
+	/**
68
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
+	 * group is.  If there is no group then it automatically gets set to default.
70
+	 *
71
+	 * @since 4.5.0
72
+	 *
73
+	 * @var string
74
+	 */
75
+	protected $_variation;
76 76
 
77 77
 
78
-    /**
79
-     * @param bool $routing
80
-     * @throws EE_Error
81
-     */
82
-    public function __construct($routing = true)
83
-    {
84
-        //make sure messages autoloader is running
85
-        EED_Messages::set_autoloaders();
86
-        parent::__construct($routing);
87
-    }
78
+	/**
79
+	 * @param bool $routing
80
+	 * @throws EE_Error
81
+	 */
82
+	public function __construct($routing = true)
83
+	{
84
+		//make sure messages autoloader is running
85
+		EED_Messages::set_autoloaders();
86
+		parent::__construct($routing);
87
+	}
88 88
     
89 89
     
90
-    protected function _init_page_props()
91
-    {
92
-        $this->page_slug        = EE_MSG_PG_SLUG;
93
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
94
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
95
-        $this->_admin_base_path = EE_MSG_ADMIN;
96
-        
97
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
98
-        
99
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
100
-        $this->_load_message_resource_manager();
101
-    }
90
+	protected function _init_page_props()
91
+	{
92
+		$this->page_slug        = EE_MSG_PG_SLUG;
93
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
94
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
95
+		$this->_admin_base_path = EE_MSG_ADMIN;
96
+        
97
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
98
+        
99
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
100
+		$this->_load_message_resource_manager();
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
106
-     *
107
-     * @throws EE_Error
108
-     * @throws InvalidDataTypeException
109
-     * @throws InvalidInterfaceException
110
-     * @throws InvalidArgumentException
111
-     * @throws ReflectionException
112
-     */
113
-    protected function _load_message_resource_manager()
114
-    {
115
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
116
-    }
104
+	/**
105
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
106
+	 *
107
+	 * @throws EE_Error
108
+	 * @throws InvalidDataTypeException
109
+	 * @throws InvalidInterfaceException
110
+	 * @throws InvalidArgumentException
111
+	 * @throws ReflectionException
112
+	 */
113
+	protected function _load_message_resource_manager()
114
+	{
115
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
116
+	}
117 117
 
118 118
 
119
-    /**
120
-     * @deprecated 4.9.9.rc.014
121
-     * @return array
122
-     * @throws EE_Error
123
-     * @throws InvalidArgumentException
124
-     * @throws InvalidDataTypeException
125
-     * @throws InvalidInterfaceException
126
-     */
127
-    public function get_messengers_for_list_table()
128
-    {
129
-        EE_Error::doing_it_wrong(
130
-            __METHOD__,
131
-            sprintf(
132
-                esc_html__(
133
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
134
-                    'event_espresso'
135
-                ),
136
-                'Messages_Admin_Page::get_messengers_select_input()'
137
-            ),
138
-            '4.9.9.rc.014'
139
-        );
140
-        
141
-        $m_values          = array();
142
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
143
-        //setup messengers for selects
144
-        $i = 1;
145
-        foreach ($active_messengers as $active_messenger) {
146
-            if ($active_messenger instanceof EE_Message) {
147
-                $m_values[$i]['id']   = $active_messenger->messenger();
148
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
149
-                $i++;
150
-            }
151
-        }
152
-        
153
-        return $m_values;
154
-    }
119
+	/**
120
+	 * @deprecated 4.9.9.rc.014
121
+	 * @return array
122
+	 * @throws EE_Error
123
+	 * @throws InvalidArgumentException
124
+	 * @throws InvalidDataTypeException
125
+	 * @throws InvalidInterfaceException
126
+	 */
127
+	public function get_messengers_for_list_table()
128
+	{
129
+		EE_Error::doing_it_wrong(
130
+			__METHOD__,
131
+			sprintf(
132
+				esc_html__(
133
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
134
+					'event_espresso'
135
+				),
136
+				'Messages_Admin_Page::get_messengers_select_input()'
137
+			),
138
+			'4.9.9.rc.014'
139
+		);
140
+        
141
+		$m_values          = array();
142
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
143
+		//setup messengers for selects
144
+		$i = 1;
145
+		foreach ($active_messengers as $active_messenger) {
146
+			if ($active_messenger instanceof EE_Message) {
147
+				$m_values[$i]['id']   = $active_messenger->messenger();
148
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
149
+				$i++;
150
+			}
151
+		}
152
+        
153
+		return $m_values;
154
+	}
155 155
 
156 156
 
157
-    /**
158
-     * @deprecated 4.9.9.rc.014
159
-     * @return array
160
-     * @throws EE_Error
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidInterfaceException
164
-     */
165
-    public function get_message_types_for_list_table()
166
-    {
167
-        EE_Error::doing_it_wrong(
168
-            __METHOD__,
169
-            sprintf(
170
-                esc_html__(
171
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
172
-                    'event_espresso'
173
-                ),
174
-                'Messages_Admin_Page::get_message_types_select_input()'
175
-            ),
176
-            '4.9.9.rc.014'
177
-        );
178
-        
179
-        $mt_values       = array();
180
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
181
-        $i               = 1;
182
-        foreach ($active_messages as $active_message) {
183
-            if ($active_message instanceof EE_Message) {
184
-                $mt_values[$i]['id']   = $active_message->message_type();
185
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
186
-                $i++;
187
-            }
188
-        }
189
-        
190
-        return $mt_values;
191
-    }
157
+	/**
158
+	 * @deprecated 4.9.9.rc.014
159
+	 * @return array
160
+	 * @throws EE_Error
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidInterfaceException
164
+	 */
165
+	public function get_message_types_for_list_table()
166
+	{
167
+		EE_Error::doing_it_wrong(
168
+			__METHOD__,
169
+			sprintf(
170
+				esc_html__(
171
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
172
+					'event_espresso'
173
+				),
174
+				'Messages_Admin_Page::get_message_types_select_input()'
175
+			),
176
+			'4.9.9.rc.014'
177
+		);
178
+        
179
+		$mt_values       = array();
180
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
181
+		$i               = 1;
182
+		foreach ($active_messages as $active_message) {
183
+			if ($active_message instanceof EE_Message) {
184
+				$mt_values[$i]['id']   = $active_message->message_type();
185
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
186
+				$i++;
187
+			}
188
+		}
189
+        
190
+		return $mt_values;
191
+	}
192 192
 
193 193
 
194
-    /**
195
-     * @deprecated 4.9.9.rc.014
196
-     * @return array
197
-     * @throws EE_Error
198
-     * @throws InvalidArgumentException
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidInterfaceException
201
-     */
202
-    public function get_contexts_for_message_types_for_list_table()
203
-    {
204
-        EE_Error::doing_it_wrong(
205
-            __METHOD__,
206
-            sprintf(
207
-                esc_html__(
208
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
209
-                    'event_espresso'
210
-                ),
211
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
212
-            ),
213
-            '4.9.9.rc.014'
214
-        );
215
-        
216
-        $contexts                = array();
217
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
218
-        foreach ($active_message_contexts as $active_message) {
219
-            if ($active_message instanceof EE_Message) {
220
-                $message_type = $active_message->message_type_object();
221
-                if ($message_type instanceof EE_message_type) {
222
-                    $message_type_contexts = $message_type->get_contexts();
223
-                    foreach ($message_type_contexts as $context => $context_details) {
224
-                        $contexts[$context] = $context_details['label'];
225
-                    }
226
-                }
227
-            }
228
-        }
229
-        
230
-        return $contexts;
231
-    }
194
+	/**
195
+	 * @deprecated 4.9.9.rc.014
196
+	 * @return array
197
+	 * @throws EE_Error
198
+	 * @throws InvalidArgumentException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidInterfaceException
201
+	 */
202
+	public function get_contexts_for_message_types_for_list_table()
203
+	{
204
+		EE_Error::doing_it_wrong(
205
+			__METHOD__,
206
+			sprintf(
207
+				esc_html__(
208
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
209
+					'event_espresso'
210
+				),
211
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
212
+			),
213
+			'4.9.9.rc.014'
214
+		);
215
+        
216
+		$contexts                = array();
217
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
218
+		foreach ($active_message_contexts as $active_message) {
219
+			if ($active_message instanceof EE_Message) {
220
+				$message_type = $active_message->message_type_object();
221
+				if ($message_type instanceof EE_message_type) {
222
+					$message_type_contexts = $message_type->get_contexts();
223
+					foreach ($message_type_contexts as $context => $context_details) {
224
+						$contexts[$context] = $context_details['label'];
225
+					}
226
+				}
227
+			}
228
+		}
229
+        
230
+		return $contexts;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * Generate select input with provided messenger options array.
236
-     *
237
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
238
-     *                                 labels.
239
-     * @return string
240
-     * @throws EE_Error
241
-     */
242
-    public function get_messengers_select_input($messenger_options)
243
-    {
244
-        //if empty or just one value then just return an empty string
245
-        if (empty($messenger_options)
246
-            || ! is_array($messenger_options)
247
-            || count($messenger_options) === 1
248
-        ) {
249
-            return '';
250
-        }
251
-        //merge in default
252
-        $messenger_options = array_merge(
253
-            array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
254
-            $messenger_options
255
-        );
256
-        $input             = new EE_Select_Input(
257
-            $messenger_options,
258
-            array(
259
-                'html_name'  => 'ee_messenger_filter_by',
260
-                'html_id'    => 'ee_messenger_filter_by',
261
-                'html_class' => 'wide',
262
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
263
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
264
-                    : 'none_selected'
265
-            )
266
-        );
267
-        
268
-        return $input->get_html_for_input();
269
-    }
234
+	/**
235
+	 * Generate select input with provided messenger options array.
236
+	 *
237
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
238
+	 *                                 labels.
239
+	 * @return string
240
+	 * @throws EE_Error
241
+	 */
242
+	public function get_messengers_select_input($messenger_options)
243
+	{
244
+		//if empty or just one value then just return an empty string
245
+		if (empty($messenger_options)
246
+			|| ! is_array($messenger_options)
247
+			|| count($messenger_options) === 1
248
+		) {
249
+			return '';
250
+		}
251
+		//merge in default
252
+		$messenger_options = array_merge(
253
+			array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
254
+			$messenger_options
255
+		);
256
+		$input             = new EE_Select_Input(
257
+			$messenger_options,
258
+			array(
259
+				'html_name'  => 'ee_messenger_filter_by',
260
+				'html_id'    => 'ee_messenger_filter_by',
261
+				'html_class' => 'wide',
262
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
263
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
264
+					: 'none_selected'
265
+			)
266
+		);
267
+        
268
+		return $input->get_html_for_input();
269
+	}
270 270
 
271 271
 
272
-    /**
273
-     * Generate select input with provided message type options array.
274
-     *
275
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
276
-     *                                    message type labels
277
-     * @return string
278
-     * @throws EE_Error
279
-     */
280
-    public function get_message_types_select_input($message_type_options)
281
-    {
282
-        //if empty or count of options is 1 then just return an empty string
283
-        if (empty($message_type_options)
284
-            || ! is_array($message_type_options)
285
-            || count($message_type_options) === 1
286
-        ) {
287
-            return '';
288
-        }
289
-        //merge in default
290
-        $message_type_options = array_merge(
291
-            array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
292
-            $message_type_options
293
-        );
294
-        $input                = new EE_Select_Input(
295
-            $message_type_options,
296
-            array(
297
-                'html_name'  => 'ee_message_type_filter_by',
298
-                'html_id'    => 'ee_message_type_filter_by',
299
-                'html_class' => 'wide',
300
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
301
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
302
-                    : 'none_selected',
303
-            )
304
-        );
305
-        
306
-        return $input->get_html_for_input();
307
-    }
272
+	/**
273
+	 * Generate select input with provided message type options array.
274
+	 *
275
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
276
+	 *                                    message type labels
277
+	 * @return string
278
+	 * @throws EE_Error
279
+	 */
280
+	public function get_message_types_select_input($message_type_options)
281
+	{
282
+		//if empty or count of options is 1 then just return an empty string
283
+		if (empty($message_type_options)
284
+			|| ! is_array($message_type_options)
285
+			|| count($message_type_options) === 1
286
+		) {
287
+			return '';
288
+		}
289
+		//merge in default
290
+		$message_type_options = array_merge(
291
+			array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
292
+			$message_type_options
293
+		);
294
+		$input                = new EE_Select_Input(
295
+			$message_type_options,
296
+			array(
297
+				'html_name'  => 'ee_message_type_filter_by',
298
+				'html_id'    => 'ee_message_type_filter_by',
299
+				'html_class' => 'wide',
300
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
301
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
302
+					: 'none_selected',
303
+			)
304
+		);
305
+        
306
+		return $input->get_html_for_input();
307
+	}
308 308
 
309 309
 
310
-    /**
311
-     * Generate select input with provide message type contexts array.
312
-     *
313
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
314
-     *                               context label.
315
-     * @return string
316
-     * @throws EE_Error
317
-     */
318
-    public function get_contexts_for_message_types_select_input($context_options)
319
-    {
320
-        //if empty or count of options is one then just return empty string
321
-        if (empty($context_options)
322
-            || ! is_array($context_options)
323
-            || count($context_options) === 1
324
-        ) {
325
-            return '';
326
-        }
327
-        //merge in default
328
-        $context_options = array_merge(
329
-            array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
-            $context_options
331
-        );
332
-        $input           = new EE_Select_Input(
333
-            $context_options,
334
-            array(
335
-                'html_name'  => 'ee_context_filter_by',
336
-                'html_id'    => 'ee_context_filter_by',
337
-                'html_class' => 'wide',
338
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
339
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
340
-                    : 'none_selected',
341
-            )
342
-        );
343
-        
344
-        return $input->get_html_for_input();
345
-    }
310
+	/**
311
+	 * Generate select input with provide message type contexts array.
312
+	 *
313
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
314
+	 *                               context label.
315
+	 * @return string
316
+	 * @throws EE_Error
317
+	 */
318
+	public function get_contexts_for_message_types_select_input($context_options)
319
+	{
320
+		//if empty or count of options is one then just return empty string
321
+		if (empty($context_options)
322
+			|| ! is_array($context_options)
323
+			|| count($context_options) === 1
324
+		) {
325
+			return '';
326
+		}
327
+		//merge in default
328
+		$context_options = array_merge(
329
+			array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
+			$context_options
331
+		);
332
+		$input           = new EE_Select_Input(
333
+			$context_options,
334
+			array(
335
+				'html_name'  => 'ee_context_filter_by',
336
+				'html_id'    => 'ee_context_filter_by',
337
+				'html_class' => 'wide',
338
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
339
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
340
+					: 'none_selected',
341
+			)
342
+		);
343
+        
344
+		return $input->get_html_for_input();
345
+	}
346 346
     
347 347
     
348
-    protected function _ajax_hooks()
349
-    {
350
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
-        add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
-    }
348
+	protected function _ajax_hooks()
349
+	{
350
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
+		add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
+	}
357 357
     
358 358
     
359
-    protected function _define_page_props()
360
-    {
361
-        $this->_admin_page_title = $this->page_label;
362
-        $this->_labels           = array(
363
-            'buttons'    => array(
364
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
-                'delete' => esc_html__('Delete Message Template', 'event_espresso')
367
-            ),
368
-            'publishbox' => esc_html__('Update Actions', 'event_espresso')
369
-        );
370
-    }
359
+	protected function _define_page_props()
360
+	{
361
+		$this->_admin_page_title = $this->page_label;
362
+		$this->_labels           = array(
363
+			'buttons'    => array(
364
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
+				'delete' => esc_html__('Delete Message Template', 'event_espresso')
367
+			),
368
+			'publishbox' => esc_html__('Update Actions', 'event_espresso')
369
+		);
370
+	}
371 371
     
372 372
     
373
-    /**
374
-     *        an array for storing key => value pairs of request actions and their corresponding methods
375
-     * @access protected
376
-     * @return void
377
-     */
378
-    protected function _set_page_routes()
379
-    {
380
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
381
-            ? $this->_req_data['GRP_ID']
382
-            : 0;
383
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
384
-            ? $this->_req_data['id']
385
-            : $grp_id;
386
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
387
-            ? $this->_req_data['MSG_ID']
388
-            : 0;
389
-        
390
-        $this->_page_routes = array(
391
-            'default'                          => array(
392
-                'func'       => '_message_queue_list_table',
393
-                'capability' => 'ee_read_global_messages'
394
-            ),
395
-            'global_mtps'                      => array(
396
-                'func'       => '_ee_default_messages_overview_list_table',
397
-                'capability' => 'ee_read_global_messages'
398
-            ),
399
-            'custom_mtps'                      => array(
400
-                'func'       => '_custom_mtps_preview',
401
-                'capability' => 'ee_read_messages'
402
-            ),
403
-            'add_new_message_template'         => array(
404
-                'func'       => '_add_message_template',
405
-                'capability' => 'ee_edit_messages',
406
-                'noheader'   => true
407
-            ),
408
-            'edit_message_template'            => array(
409
-                'func'       => '_edit_message_template',
410
-                'capability' => 'ee_edit_message',
411
-                'obj_id'     => $grp_id
412
-            ),
413
-            'preview_message'                  => array(
414
-                'func'               => '_preview_message',
415
-                'capability'         => 'ee_read_message',
416
-                'obj_id'             => $grp_id,
417
-                'noheader'           => true,
418
-                'headers_sent_route' => 'display_preview_message'
419
-            ),
420
-            'display_preview_message'          => array(
421
-                'func'       => '_display_preview_message',
422
-                'capability' => 'ee_read_message',
423
-                'obj_id'     => $grp_id
424
-            ),
425
-            'insert_message_template'          => array(
426
-                'func'       => '_insert_or_update_message_template',
427
-                'capability' => 'ee_edit_messages',
428
-                'args'       => array('new_template' => true),
429
-                'noheader'   => true
430
-            ),
431
-            'update_message_template'          => array(
432
-                'func'       => '_insert_or_update_message_template',
433
-                'capability' => 'ee_edit_message',
434
-                'obj_id'     => $grp_id,
435
-                'args'       => array('new_template' => false),
436
-                'noheader'   => true
437
-            ),
438
-            'trash_message_template'           => array(
439
-                'func'       => '_trash_or_restore_message_template',
440
-                'capability' => 'ee_delete_message',
441
-                'obj_id'     => $grp_id,
442
-                'args'       => array('trash' => true, 'all' => true),
443
-                'noheader'   => true
444
-            ),
445
-            'trash_message_template_context'   => array(
446
-                'func'       => '_trash_or_restore_message_template',
447
-                'capability' => 'ee_delete_message',
448
-                'obj_id'     => $grp_id,
449
-                'args'       => array('trash' => true),
450
-                'noheader'   => true
451
-            ),
452
-            'restore_message_template'         => array(
453
-                'func'       => '_trash_or_restore_message_template',
454
-                'capability' => 'ee_delete_message',
455
-                'obj_id'     => $grp_id,
456
-                'args'       => array('trash' => false, 'all' => true),
457
-                'noheader'   => true
458
-            ),
459
-            'restore_message_template_context' => array(
460
-                'func'       => '_trash_or_restore_message_template',
461
-                'capability' => 'ee_delete_message',
462
-                'obj_id'     => $grp_id,
463
-                'args'       => array('trash' => false),
464
-                'noheader'   => true
465
-            ),
466
-            'delete_message_template'          => array(
467
-                'func'       => '_delete_message_template',
468
-                'capability' => 'ee_delete_message',
469
-                'obj_id'     => $grp_id,
470
-                'noheader'   => true
471
-            ),
472
-            'reset_to_default'                 => array(
473
-                'func'       => '_reset_to_default_template',
474
-                'capability' => 'ee_edit_message',
475
-                'obj_id'     => $grp_id,
476
-                'noheader'   => true
477
-            ),
478
-            'settings'                         => array(
479
-                'func'       => '_settings',
480
-                'capability' => 'manage_options'
481
-            ),
482
-            'update_global_settings'           => array(
483
-                'func'       => '_update_global_settings',
484
-                'capability' => 'manage_options',
485
-                'noheader'   => true
486
-            ),
487
-            'generate_now'                     => array(
488
-                'func'       => '_generate_now',
489
-                'capability' => 'ee_send_message',
490
-                'noheader'   => true
491
-            ),
492
-            'generate_and_send_now'            => array(
493
-                'func'       => '_generate_and_send_now',
494
-                'capability' => 'ee_send_message',
495
-                'noheader'   => true
496
-            ),
497
-            'queue_for_resending'              => array(
498
-                'func'       => '_queue_for_resending',
499
-                'capability' => 'ee_send_message',
500
-                'noheader'   => true
501
-            ),
502
-            'send_now'                         => array(
503
-                'func'       => '_send_now',
504
-                'capability' => 'ee_send_message',
505
-                'noheader'   => true
506
-            ),
507
-            'delete_ee_message'                => array(
508
-                'func'       => '_delete_ee_messages',
509
-                'capability' => 'ee_delete_messages',
510
-                'noheader'   => true
511
-            ),
512
-            'delete_ee_messages'               => array(
513
-                'func'       => '_delete_ee_messages',
514
-                'capability' => 'ee_delete_messages',
515
-                'noheader'   => true,
516
-                'obj_id'     => $msg_id
517
-            )
518
-        );
519
-    }
373
+	/**
374
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
375
+	 * @access protected
376
+	 * @return void
377
+	 */
378
+	protected function _set_page_routes()
379
+	{
380
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
381
+			? $this->_req_data['GRP_ID']
382
+			: 0;
383
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
384
+			? $this->_req_data['id']
385
+			: $grp_id;
386
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
387
+			? $this->_req_data['MSG_ID']
388
+			: 0;
389
+        
390
+		$this->_page_routes = array(
391
+			'default'                          => array(
392
+				'func'       => '_message_queue_list_table',
393
+				'capability' => 'ee_read_global_messages'
394
+			),
395
+			'global_mtps'                      => array(
396
+				'func'       => '_ee_default_messages_overview_list_table',
397
+				'capability' => 'ee_read_global_messages'
398
+			),
399
+			'custom_mtps'                      => array(
400
+				'func'       => '_custom_mtps_preview',
401
+				'capability' => 'ee_read_messages'
402
+			),
403
+			'add_new_message_template'         => array(
404
+				'func'       => '_add_message_template',
405
+				'capability' => 'ee_edit_messages',
406
+				'noheader'   => true
407
+			),
408
+			'edit_message_template'            => array(
409
+				'func'       => '_edit_message_template',
410
+				'capability' => 'ee_edit_message',
411
+				'obj_id'     => $grp_id
412
+			),
413
+			'preview_message'                  => array(
414
+				'func'               => '_preview_message',
415
+				'capability'         => 'ee_read_message',
416
+				'obj_id'             => $grp_id,
417
+				'noheader'           => true,
418
+				'headers_sent_route' => 'display_preview_message'
419
+			),
420
+			'display_preview_message'          => array(
421
+				'func'       => '_display_preview_message',
422
+				'capability' => 'ee_read_message',
423
+				'obj_id'     => $grp_id
424
+			),
425
+			'insert_message_template'          => array(
426
+				'func'       => '_insert_or_update_message_template',
427
+				'capability' => 'ee_edit_messages',
428
+				'args'       => array('new_template' => true),
429
+				'noheader'   => true
430
+			),
431
+			'update_message_template'          => array(
432
+				'func'       => '_insert_or_update_message_template',
433
+				'capability' => 'ee_edit_message',
434
+				'obj_id'     => $grp_id,
435
+				'args'       => array('new_template' => false),
436
+				'noheader'   => true
437
+			),
438
+			'trash_message_template'           => array(
439
+				'func'       => '_trash_or_restore_message_template',
440
+				'capability' => 'ee_delete_message',
441
+				'obj_id'     => $grp_id,
442
+				'args'       => array('trash' => true, 'all' => true),
443
+				'noheader'   => true
444
+			),
445
+			'trash_message_template_context'   => array(
446
+				'func'       => '_trash_or_restore_message_template',
447
+				'capability' => 'ee_delete_message',
448
+				'obj_id'     => $grp_id,
449
+				'args'       => array('trash' => true),
450
+				'noheader'   => true
451
+			),
452
+			'restore_message_template'         => array(
453
+				'func'       => '_trash_or_restore_message_template',
454
+				'capability' => 'ee_delete_message',
455
+				'obj_id'     => $grp_id,
456
+				'args'       => array('trash' => false, 'all' => true),
457
+				'noheader'   => true
458
+			),
459
+			'restore_message_template_context' => array(
460
+				'func'       => '_trash_or_restore_message_template',
461
+				'capability' => 'ee_delete_message',
462
+				'obj_id'     => $grp_id,
463
+				'args'       => array('trash' => false),
464
+				'noheader'   => true
465
+			),
466
+			'delete_message_template'          => array(
467
+				'func'       => '_delete_message_template',
468
+				'capability' => 'ee_delete_message',
469
+				'obj_id'     => $grp_id,
470
+				'noheader'   => true
471
+			),
472
+			'reset_to_default'                 => array(
473
+				'func'       => '_reset_to_default_template',
474
+				'capability' => 'ee_edit_message',
475
+				'obj_id'     => $grp_id,
476
+				'noheader'   => true
477
+			),
478
+			'settings'                         => array(
479
+				'func'       => '_settings',
480
+				'capability' => 'manage_options'
481
+			),
482
+			'update_global_settings'           => array(
483
+				'func'       => '_update_global_settings',
484
+				'capability' => 'manage_options',
485
+				'noheader'   => true
486
+			),
487
+			'generate_now'                     => array(
488
+				'func'       => '_generate_now',
489
+				'capability' => 'ee_send_message',
490
+				'noheader'   => true
491
+			),
492
+			'generate_and_send_now'            => array(
493
+				'func'       => '_generate_and_send_now',
494
+				'capability' => 'ee_send_message',
495
+				'noheader'   => true
496
+			),
497
+			'queue_for_resending'              => array(
498
+				'func'       => '_queue_for_resending',
499
+				'capability' => 'ee_send_message',
500
+				'noheader'   => true
501
+			),
502
+			'send_now'                         => array(
503
+				'func'       => '_send_now',
504
+				'capability' => 'ee_send_message',
505
+				'noheader'   => true
506
+			),
507
+			'delete_ee_message'                => array(
508
+				'func'       => '_delete_ee_messages',
509
+				'capability' => 'ee_delete_messages',
510
+				'noheader'   => true
511
+			),
512
+			'delete_ee_messages'               => array(
513
+				'func'       => '_delete_ee_messages',
514
+				'capability' => 'ee_delete_messages',
515
+				'noheader'   => true,
516
+				'obj_id'     => $msg_id
517
+			)
518
+		);
519
+	}
520 520
     
521 521
     
522
-    protected function _set_page_config()
523
-    {
524
-        $this->_page_config = array(
525
-            'default'                  => array(
526
-                'nav'           => array(
527
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
528
-                    'order' => 10
529
-                ),
530
-                'list_table'    => 'EE_Message_List_Table',
531
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
532
-                'require_nonce' => false
533
-            ),
534
-            'global_mtps'              => array(
535
-                'nav'           => array(
536
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
537
-                    'order' => 20
538
-                ),
539
-                'list_table'    => 'Messages_Template_List_Table',
540
-                'help_tabs'     => array(
541
-                    'messages_overview_help_tab'                                => array(
542
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
543
-                        'filename' => 'messages_overview'
544
-                    ),
545
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
546
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
547
-                        'filename' => 'messages_overview_table_column_headings'
548
-                    ),
549
-                    'messages_overview_messages_filters_help_tab'               => array(
550
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
551
-                        'filename' => 'messages_overview_filters'
552
-                    ),
553
-                    'messages_overview_messages_views_help_tab'                 => array(
554
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
555
-                        'filename' => 'messages_overview_views'
556
-                    ),
557
-                    'message_overview_message_types_help_tab'                   => array(
558
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
559
-                        'filename' => 'messages_overview_types'
560
-                    ),
561
-                    'messages_overview_messengers_help_tab'                     => array(
562
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
563
-                        'filename' => 'messages_overview_messengers',
564
-                    ),
565
-                ),
566
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
567
-                'require_nonce' => false
568
-            ),
569
-            'custom_mtps'              => array(
570
-                'nav'           => array(
571
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
-                    'order' => 30
573
-                ),
574
-                'help_tabs'     => array(),
575
-                'help_tour'     => array(),
576
-                'require_nonce' => false
577
-            ),
578
-            'add_new_message_template' => array(
579
-                'nav'           => array(
580
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
581
-                    'order'      => 5,
582
-                    'persistent' => false
583
-                ),
584
-                'require_nonce' => false
585
-            ),
586
-            'edit_message_template'    => array(
587
-                'labels'        => array(
588
-                    'buttons'    => array(
589
-                        'reset' => esc_html__('Reset Templates'),
590
-                    ),
591
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso')
592
-                ),
593
-                'nav'           => array(
594
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
595
-                    'order'      => 5,
596
-                    'persistent' => false,
597
-                    'url'        => ''
598
-                ),
599
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
600
-                'has_metaboxes' => true,
601
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
602
-                'help_tabs'     => array(
603
-                    'edit_message_template'       => array(
604
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
605
-                        'callback' => 'edit_message_template_help_tab'
606
-                    ),
607
-                    'message_templates_help_tab'  => array(
608
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
609
-                        'filename' => 'messages_templates'
610
-                    ),
611
-                    'message_template_shortcodes' => array(
612
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
613
-                        'callback' => 'message_template_shortcodes_help_tab'
614
-                    ),
615
-                    'message_preview_help_tab'    => array(
616
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
617
-                        'filename' => 'messages_preview'
618
-                    ),
619
-                    'messages_overview_other_help_tab'                          => array(
620
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
621
-                        'filename' => 'messages_overview_other',
622
-                    ),
623
-                ),
624
-                'require_nonce' => false
625
-            ),
626
-            'display_preview_message'  => array(
627
-                'nav'           => array(
628
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
629
-                    'order'      => 5,
630
-                    'url'        => '',
631
-                    'persistent' => false
632
-                ),
633
-                'help_tabs'     => array(
634
-                    'preview_message' => array(
635
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
636
-                        'callback' => 'preview_message_help_tab'
637
-                    )
638
-                ),
639
-                'require_nonce' => false
640
-            ),
641
-            'settings'                 => array(
642
-                'nav'           => array(
643
-                    'label' => esc_html__('Settings', 'event_espresso'),
644
-                    'order' => 40
645
-                ),
646
-                'metaboxes'     => array('_messages_settings_metaboxes'),
647
-                'help_tabs'     => array(
648
-                    'messages_settings_help_tab'               => array(
649
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
650
-                        'filename' => 'messages_settings'
651
-                    ),
652
-                    'messages_settings_message_types_help_tab' => array(
653
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
654
-                        'filename' => 'messages_settings_message_types'
655
-                    ),
656
-                    'messages_settings_messengers_help_tab'    => array(
657
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
658
-                        'filename' => 'messages_settings_messengers'
659
-                    ),
660
-                ),
661
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
662
-                'require_nonce' => false
663
-            )
664
-        );
665
-    }
522
+	protected function _set_page_config()
523
+	{
524
+		$this->_page_config = array(
525
+			'default'                  => array(
526
+				'nav'           => array(
527
+					'label' => esc_html__('Message Activity', 'event_espresso'),
528
+					'order' => 10
529
+				),
530
+				'list_table'    => 'EE_Message_List_Table',
531
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
532
+				'require_nonce' => false
533
+			),
534
+			'global_mtps'              => array(
535
+				'nav'           => array(
536
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
537
+					'order' => 20
538
+				),
539
+				'list_table'    => 'Messages_Template_List_Table',
540
+				'help_tabs'     => array(
541
+					'messages_overview_help_tab'                                => array(
542
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
543
+						'filename' => 'messages_overview'
544
+					),
545
+					'messages_overview_messages_table_column_headings_help_tab' => array(
546
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
547
+						'filename' => 'messages_overview_table_column_headings'
548
+					),
549
+					'messages_overview_messages_filters_help_tab'               => array(
550
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
551
+						'filename' => 'messages_overview_filters'
552
+					),
553
+					'messages_overview_messages_views_help_tab'                 => array(
554
+						'title'    => esc_html__('Message Views', 'event_espresso'),
555
+						'filename' => 'messages_overview_views'
556
+					),
557
+					'message_overview_message_types_help_tab'                   => array(
558
+						'title'    => esc_html__('Message Types', 'event_espresso'),
559
+						'filename' => 'messages_overview_types'
560
+					),
561
+					'messages_overview_messengers_help_tab'                     => array(
562
+						'title'    => esc_html__('Messengers', 'event_espresso'),
563
+						'filename' => 'messages_overview_messengers',
564
+					),
565
+				),
566
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
567
+				'require_nonce' => false
568
+			),
569
+			'custom_mtps'              => array(
570
+				'nav'           => array(
571
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
+					'order' => 30
573
+				),
574
+				'help_tabs'     => array(),
575
+				'help_tour'     => array(),
576
+				'require_nonce' => false
577
+			),
578
+			'add_new_message_template' => array(
579
+				'nav'           => array(
580
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
581
+					'order'      => 5,
582
+					'persistent' => false
583
+				),
584
+				'require_nonce' => false
585
+			),
586
+			'edit_message_template'    => array(
587
+				'labels'        => array(
588
+					'buttons'    => array(
589
+						'reset' => esc_html__('Reset Templates'),
590
+					),
591
+					'publishbox' => esc_html__('Update Actions', 'event_espresso')
592
+				),
593
+				'nav'           => array(
594
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
595
+					'order'      => 5,
596
+					'persistent' => false,
597
+					'url'        => ''
598
+				),
599
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
600
+				'has_metaboxes' => true,
601
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
602
+				'help_tabs'     => array(
603
+					'edit_message_template'       => array(
604
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
605
+						'callback' => 'edit_message_template_help_tab'
606
+					),
607
+					'message_templates_help_tab'  => array(
608
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
609
+						'filename' => 'messages_templates'
610
+					),
611
+					'message_template_shortcodes' => array(
612
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
613
+						'callback' => 'message_template_shortcodes_help_tab'
614
+					),
615
+					'message_preview_help_tab'    => array(
616
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
617
+						'filename' => 'messages_preview'
618
+					),
619
+					'messages_overview_other_help_tab'                          => array(
620
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
621
+						'filename' => 'messages_overview_other',
622
+					),
623
+				),
624
+				'require_nonce' => false
625
+			),
626
+			'display_preview_message'  => array(
627
+				'nav'           => array(
628
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
629
+					'order'      => 5,
630
+					'url'        => '',
631
+					'persistent' => false
632
+				),
633
+				'help_tabs'     => array(
634
+					'preview_message' => array(
635
+						'title'    => esc_html__('About Previews', 'event_espresso'),
636
+						'callback' => 'preview_message_help_tab'
637
+					)
638
+				),
639
+				'require_nonce' => false
640
+			),
641
+			'settings'                 => array(
642
+				'nav'           => array(
643
+					'label' => esc_html__('Settings', 'event_espresso'),
644
+					'order' => 40
645
+				),
646
+				'metaboxes'     => array('_messages_settings_metaboxes'),
647
+				'help_tabs'     => array(
648
+					'messages_settings_help_tab'               => array(
649
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
650
+						'filename' => 'messages_settings'
651
+					),
652
+					'messages_settings_message_types_help_tab' => array(
653
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
654
+						'filename' => 'messages_settings_message_types'
655
+					),
656
+					'messages_settings_messengers_help_tab'    => array(
657
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
658
+						'filename' => 'messages_settings_messengers'
659
+					),
660
+				),
661
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
662
+				'require_nonce' => false
663
+			)
664
+		);
665
+	}
666 666
     
667 667
     
668
-    protected function _add_screen_options()
669
-    {
670
-        //todo
671
-    }
668
+	protected function _add_screen_options()
669
+	{
670
+		//todo
671
+	}
672 672
     
673 673
     
674
-    protected function _add_screen_options_global_mtps()
675
-    {
676
-        /**
677
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
678
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
679
-         */
680
-        $page_title              = $this->_admin_page_title;
681
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
682
-        $this->_per_page_screen_option();
683
-        $this->_admin_page_title = $page_title;
684
-    }
674
+	protected function _add_screen_options_global_mtps()
675
+	{
676
+		/**
677
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
678
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
679
+		 */
680
+		$page_title              = $this->_admin_page_title;
681
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
682
+		$this->_per_page_screen_option();
683
+		$this->_admin_page_title = $page_title;
684
+	}
685 685
     
686 686
     
687
-    protected function _add_screen_options_default()
688
-    {
689
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
690
-        $this->_per_page_screen_option();
691
-    }
687
+	protected function _add_screen_options_default()
688
+	{
689
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
690
+		$this->_per_page_screen_option();
691
+	}
692 692
     
693 693
     
694
-    //none of the below group are currently used for Messages
695
-    protected function _add_feature_pointers()
696
-    {
697
-    }
694
+	//none of the below group are currently used for Messages
695
+	protected function _add_feature_pointers()
696
+	{
697
+	}
698 698
     
699
-    public function admin_init()
700
-    {
701
-    }
699
+	public function admin_init()
700
+	{
701
+	}
702 702
     
703
-    public function admin_notices()
704
-    {
705
-    }
703
+	public function admin_notices()
704
+	{
705
+	}
706 706
     
707
-    public function admin_footer_scripts()
708
-    {
709
-    }
707
+	public function admin_footer_scripts()
708
+	{
709
+	}
710 710
     
711 711
     
712
-    public function messages_help_tab()
713
-    {
714
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
715
-    }
712
+	public function messages_help_tab()
713
+	{
714
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
715
+	}
716 716
     
717 717
     
718
-    public function messengers_help_tab()
719
-    {
720
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
721
-    }
718
+	public function messengers_help_tab()
719
+	{
720
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
721
+	}
722 722
     
723 723
     
724
-    public function message_types_help_tab()
725
-    {
726
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
727
-    }
724
+	public function message_types_help_tab()
725
+	{
726
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
727
+	}
728 728
     
729 729
     
730
-    public function messages_overview_help_tab()
731
-    {
732
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
733
-    }
730
+	public function messages_overview_help_tab()
731
+	{
732
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
733
+	}
734 734
     
735 735
     
736
-    public function message_templates_help_tab()
737
-    {
738
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
739
-    }
736
+	public function message_templates_help_tab()
737
+	{
738
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
739
+	}
740 740
     
741 741
     
742
-    public function edit_message_template_help_tab()
743
-    {
744
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
745
-                        . esc_attr__('Editor Title', 'event_espresso')
746
-                        . '" />';
747
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
748
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
749
-                        . '" />';
750
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
751
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
752
-                        . '" />';
753
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
754
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
755
-                        . '" />';
756
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
757
-                        . esc_attr__('Publish Metabox', 'event_espresso')
758
-                        . '" />';
759
-        EEH_Template::display_template(
760
-            EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
761
-            $args
762
-        );
763
-    }
742
+	public function edit_message_template_help_tab()
743
+	{
744
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
745
+						. esc_attr__('Editor Title', 'event_espresso')
746
+						. '" />';
747
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
748
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
749
+						. '" />';
750
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
751
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
752
+						. '" />';
753
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
754
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
755
+						. '" />';
756
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
757
+						. esc_attr__('Publish Metabox', 'event_espresso')
758
+						. '" />';
759
+		EEH_Template::display_template(
760
+			EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
761
+			$args
762
+		);
763
+	}
764 764
     
765 765
     
766
-    public function message_template_shortcodes_help_tab()
767
-    {
768
-        $this->_set_shortcodes();
769
-        $args['shortcodes'] = $this->_shortcodes;
770
-        EEH_Template::display_template(
771
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
772
-            $args
773
-        );
774
-    }
766
+	public function message_template_shortcodes_help_tab()
767
+	{
768
+		$this->_set_shortcodes();
769
+		$args['shortcodes'] = $this->_shortcodes;
770
+		EEH_Template::display_template(
771
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
772
+			$args
773
+		);
774
+	}
775 775
     
776 776
     
777
-    public function preview_message_help_tab()
778
-    {
779
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
780
-    }
777
+	public function preview_message_help_tab()
778
+	{
779
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
780
+	}
781 781
     
782 782
     
783
-    public function settings_help_tab()
784
-    {
785
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
786
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
787
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
788
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
789
-        $args['img3'] = '<div class="switch">'
790
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
791
-                        . ' type="checkbox" checked="checked">'
792
-                        . '<label for="ee-on-off-toggle-on"></label>'
793
-                        . '</div>';
794
-        $args['img4'] = '<div class="switch">'
795
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
-                        . ' type="checkbox">'
797
-                        . '<label for="ee-on-off-toggle-on"></label>'
798
-                        . '</div>';
799
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
800
-    }
783
+	public function settings_help_tab()
784
+	{
785
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
786
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
787
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
788
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
789
+		$args['img3'] = '<div class="switch">'
790
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
791
+						. ' type="checkbox" checked="checked">'
792
+						. '<label for="ee-on-off-toggle-on"></label>'
793
+						. '</div>';
794
+		$args['img4'] = '<div class="switch">'
795
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
+						. ' type="checkbox">'
797
+						. '<label for="ee-on-off-toggle-on"></label>'
798
+						. '</div>';
799
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
800
+	}
801 801
     
802 802
     
803
-    public function load_scripts_styles()
804
-    {
805
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806
-        wp_enqueue_style('espresso_ee_msg');
807
-        
808
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
809
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
810
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
811
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
812
-    }
803
+	public function load_scripts_styles()
804
+	{
805
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
806
+		wp_enqueue_style('espresso_ee_msg');
807
+        
808
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
809
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
810
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
811
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
812
+	}
813 813
     
814 814
     
815
-    public function load_scripts_styles_default()
816
-    {
817
-        wp_enqueue_script('ee-msg-list-table-js');
818
-    }
815
+	public function load_scripts_styles_default()
816
+	{
817
+		wp_enqueue_script('ee-msg-list-table-js');
818
+	}
819 819
     
820 820
     
821
-    public function wp_editor_css($mce_css)
822
-    {
823
-        //if we're on the edit_message_template route
824
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
825
-            $message_type_name = $this->_active_message_type_name;
821
+	public function wp_editor_css($mce_css)
822
+	{
823
+		//if we're on the edit_message_template route
824
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
825
+			$message_type_name = $this->_active_message_type_name;
826 826
             
827
-            //we're going to REPLACE the existing mce css
828
-            //we need to get the css file location from the active messenger
829
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
830
-                'wpeditor', $this->_variation);
831
-        }
832
-        
833
-        return $mce_css;
834
-    }
827
+			//we're going to REPLACE the existing mce css
828
+			//we need to get the css file location from the active messenger
829
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
830
+				'wpeditor', $this->_variation);
831
+		}
832
+        
833
+		return $mce_css;
834
+	}
835 835
     
836 836
     
837
-    public function load_scripts_styles_edit_message_template()
838
-    {
839
-        
840
-        $this->_set_shortcodes();
841
-        
842
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
843
-            esc_html__(
844
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
845
-                'event_espresso'
846
-            ),
847
-            $this->_message_template_group->messenger_obj()->label['singular'],
848
-            $this->_message_template_group->message_type_obj()->label['singular']
849
-        );
850
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
851
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
852
-            'event_espresso'
853
-        );
854
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
855
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
856
-            'event_espresso'
857
-        );
858
-        
859
-        wp_register_script(
860
-            'ee_msgs_edit_js',
861
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
862
-            array('jquery'),
863
-            EVENT_ESPRESSO_VERSION
864
-        );
865
-        
866
-        wp_enqueue_script('ee_admin_js');
867
-        wp_enqueue_script('ee_msgs_edit_js');
868
-        
869
-        //add in special css for tiny_mce
870
-        add_filter('mce_css', array($this, 'wp_editor_css'));
871
-    }
837
+	public function load_scripts_styles_edit_message_template()
838
+	{
839
+        
840
+		$this->_set_shortcodes();
841
+        
842
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
843
+			esc_html__(
844
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
845
+				'event_espresso'
846
+			),
847
+			$this->_message_template_group->messenger_obj()->label['singular'],
848
+			$this->_message_template_group->message_type_obj()->label['singular']
849
+		);
850
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
851
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
852
+			'event_espresso'
853
+		);
854
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
855
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
856
+			'event_espresso'
857
+		);
858
+        
859
+		wp_register_script(
860
+			'ee_msgs_edit_js',
861
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
862
+			array('jquery'),
863
+			EVENT_ESPRESSO_VERSION
864
+		);
865
+        
866
+		wp_enqueue_script('ee_admin_js');
867
+		wp_enqueue_script('ee_msgs_edit_js');
868
+        
869
+		//add in special css for tiny_mce
870
+		add_filter('mce_css', array($this, 'wp_editor_css'));
871
+	}
872 872
     
873 873
     
874
-    public function load_scripts_styles_display_preview_message()
875
-    {
876
-        
877
-        $this->_set_message_template_group();
878
-        
879
-        if (isset($this->_req_data['messenger'])) {
880
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
881
-                $this->_req_data['messenger']
882
-            );
883
-        }
884
-        
885
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
886
-        
887
-        
888
-        wp_enqueue_style('espresso_preview_css',
889
-            $this->_active_messenger->get_variation(
890
-                $this->_template_pack,
891
-                $message_type_name,
892
-                true,
893
-                'preview',
894
-                $this->_variation
895
-            )
896
-        );
897
-    }
874
+	public function load_scripts_styles_display_preview_message()
875
+	{
876
+        
877
+		$this->_set_message_template_group();
878
+        
879
+		if (isset($this->_req_data['messenger'])) {
880
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
881
+				$this->_req_data['messenger']
882
+			);
883
+		}
884
+        
885
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
886
+        
887
+        
888
+		wp_enqueue_style('espresso_preview_css',
889
+			$this->_active_messenger->get_variation(
890
+				$this->_template_pack,
891
+				$message_type_name,
892
+				true,
893
+				'preview',
894
+				$this->_variation
895
+			)
896
+		);
897
+	}
898 898
     
899 899
     
900
-    public function load_scripts_styles_settings()
901
-    {
902
-        wp_register_style(
903
-            'ee-message-settings',
904
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
905
-            array(),
906
-            EVENT_ESPRESSO_VERSION
907
-        );
908
-        wp_enqueue_style('ee-text-links');
909
-        wp_enqueue_style('ee-message-settings');
910
-        wp_enqueue_script('ee-messages-settings');
911
-    }
900
+	public function load_scripts_styles_settings()
901
+	{
902
+		wp_register_style(
903
+			'ee-message-settings',
904
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
905
+			array(),
906
+			EVENT_ESPRESSO_VERSION
907
+		);
908
+		wp_enqueue_style('ee-text-links');
909
+		wp_enqueue_style('ee-message-settings');
910
+		wp_enqueue_script('ee-messages-settings');
911
+	}
912 912
     
913 913
     
914
-    /**
915
-     * set views array for List Table
916
-     */
917
-    public function _set_list_table_views_global_mtps()
918
-    {
919
-        $this->_views = array(
920
-            'in_use' => array(
921
-                'slug'        => 'in_use',
922
-                'label'       => esc_html__('In Use', 'event_espresso'),
923
-                'count'       => 0,
924
-            )
925
-        );
926
-    }
914
+	/**
915
+	 * set views array for List Table
916
+	 */
917
+	public function _set_list_table_views_global_mtps()
918
+	{
919
+		$this->_views = array(
920
+			'in_use' => array(
921
+				'slug'        => 'in_use',
922
+				'label'       => esc_html__('In Use', 'event_espresso'),
923
+				'count'       => 0,
924
+			)
925
+		);
926
+	}
927 927
 
928 928
 
929
-    /**
930
-     * Set views array for the Custom Template List Table
931
-     */
932
-    public function _set_list_table_views_custom_mtps()
933
-    {
934
-        $this->_set_list_table_views_global_mtps();
935
-        $this->_views['in_use']['bulk_action'] = array(
936
-                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
937
-        );
938
-    }
929
+	/**
930
+	 * Set views array for the Custom Template List Table
931
+	 */
932
+	public function _set_list_table_views_custom_mtps()
933
+	{
934
+		$this->_set_list_table_views_global_mtps();
935
+		$this->_views['in_use']['bulk_action'] = array(
936
+				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
937
+		);
938
+	}
939 939
 
940 940
 
941
-    /**
942
-     * set views array for message queue list table
943
-     *
944
-     * @throws InvalidDataTypeException
945
-     * @throws InvalidInterfaceException
946
-     * @throws InvalidArgumentException
947
-     * @throws EE_Error
948
-     * @throws ReflectionException
949
-     */
950
-    public function _set_list_table_views_default()
951
-    {
952
-        EE_Registry::instance()->load_helper('Template');
953
-        
954
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
955
-            'ee_send_message',
956
-            'message_list_table_bulk_actions'
957
-        )
958
-            ? array(
959
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
960
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
961
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
962
-                'send_now'              => esc_html__('Send Now', 'event_espresso')
963
-            )
964
-            : array();
965
-        
966
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
967
-            'ee_delete_messages',
968
-            'message_list_table_bulk_actions'
969
-        )
970
-            ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
971
-            : array();
972
-        
973
-        
974
-        $this->_views = array(
975
-            'all' => array(
976
-                'slug'        => 'all',
977
-                'label'       => esc_html__('All', 'event_espresso'),
978
-                'count'       => 0,
979
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
980
-            )
981
-        );
982
-        
983
-        
984
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
985
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
986
-                continue;
987
-            }
988
-            $status_bulk_actions = $common_bulk_actions;
989
-            //unset bulk actions not applying to status
990
-            if (! empty($status_bulk_actions)) {
991
-                switch ($status) {
992
-                    case EEM_Message::status_idle:
993
-                    case EEM_Message::status_resend:
994
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
995
-                        break;
941
+	/**
942
+	 * set views array for message queue list table
943
+	 *
944
+	 * @throws InvalidDataTypeException
945
+	 * @throws InvalidInterfaceException
946
+	 * @throws InvalidArgumentException
947
+	 * @throws EE_Error
948
+	 * @throws ReflectionException
949
+	 */
950
+	public function _set_list_table_views_default()
951
+	{
952
+		EE_Registry::instance()->load_helper('Template');
953
+        
954
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
955
+			'ee_send_message',
956
+			'message_list_table_bulk_actions'
957
+		)
958
+			? array(
959
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
960
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
961
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
962
+				'send_now'              => esc_html__('Send Now', 'event_espresso')
963
+			)
964
+			: array();
965
+        
966
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
967
+			'ee_delete_messages',
968
+			'message_list_table_bulk_actions'
969
+		)
970
+			? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
971
+			: array();
972
+        
973
+        
974
+		$this->_views = array(
975
+			'all' => array(
976
+				'slug'        => 'all',
977
+				'label'       => esc_html__('All', 'event_espresso'),
978
+				'count'       => 0,
979
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
980
+			)
981
+		);
982
+        
983
+        
984
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
985
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
986
+				continue;
987
+			}
988
+			$status_bulk_actions = $common_bulk_actions;
989
+			//unset bulk actions not applying to status
990
+			if (! empty($status_bulk_actions)) {
991
+				switch ($status) {
992
+					case EEM_Message::status_idle:
993
+					case EEM_Message::status_resend:
994
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
995
+						break;
996 996
                     
997
-                    case EEM_Message::status_failed:
998
-                    case EEM_Message::status_debug_only:
999
-                    case EEM_Message::status_messenger_executing:
1000
-                        $status_bulk_actions = array();
1001
-                        break;
997
+					case EEM_Message::status_failed:
998
+					case EEM_Message::status_debug_only:
999
+					case EEM_Message::status_messenger_executing:
1000
+						$status_bulk_actions = array();
1001
+						break;
1002 1002
                     
1003
-                    case EEM_Message::status_incomplete:
1004
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1005
-                        break;
1003
+					case EEM_Message::status_incomplete:
1004
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1005
+						break;
1006 1006
                     
1007
-                    case EEM_Message::status_retry:
1008
-                    case EEM_Message::status_sent:
1009
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1010
-                        break;
1011
-                }
1012
-            }
1007
+					case EEM_Message::status_retry:
1008
+					case EEM_Message::status_sent:
1009
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1010
+						break;
1011
+				}
1012
+			}
1013 1013
 
1014
-            //skip adding messenger executing status to views because it will be included with the Failed view.
1015
-            if ( $status === EEM_Message::status_messenger_executing ) {
1016
-                continue;
1017
-            }
1014
+			//skip adding messenger executing status to views because it will be included with the Failed view.
1015
+			if ( $status === EEM_Message::status_messenger_executing ) {
1016
+				continue;
1017
+			}
1018 1018
             
1019
-            $this->_views[strtolower($status)] = array(
1020
-                'slug'        => strtolower($status),
1021
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1022
-                'count'       => 0,
1023
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1024
-            );
1025
-        }
1026
-    }
1019
+			$this->_views[strtolower($status)] = array(
1020
+				'slug'        => strtolower($status),
1021
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1022
+				'count'       => 0,
1023
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1024
+			);
1025
+		}
1026
+	}
1027 1027
     
1028 1028
     
1029
-    protected function _ee_default_messages_overview_list_table()
1030
-    {
1031
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1032
-        $this->display_admin_list_table_page_with_no_sidebar();
1033
-    }
1029
+	protected function _ee_default_messages_overview_list_table()
1030
+	{
1031
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1032
+		$this->display_admin_list_table_page_with_no_sidebar();
1033
+	}
1034 1034
     
1035 1035
     
1036
-    protected function _message_queue_list_table()
1037
-    {
1038
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1039
-        $this->_template_args['per_column']        = 6;
1040
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1041
-        $this->_template_args['before_list_table'] = '<h3>'
1042
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1043
-                                                     . '</h3>';
1044
-        $this->display_admin_list_table_page_with_no_sidebar();
1045
-    }
1036
+	protected function _message_queue_list_table()
1037
+	{
1038
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1039
+		$this->_template_args['per_column']        = 6;
1040
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1041
+		$this->_template_args['before_list_table'] = '<h3>'
1042
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1043
+													 . '</h3>';
1044
+		$this->display_admin_list_table_page_with_no_sidebar();
1045
+	}
1046 1046
     
1047 1047
     
1048
-    protected function _message_legend_items()
1049
-    {
1050
-        
1051
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1052
-        $action_items       = array();
1053
-        
1054
-        foreach ($action_css_classes as $action_item => $action_details) {
1055
-            if ($action_item === 'see_notifications_for') {
1056
-                continue;
1057
-            }
1058
-            $action_items[$action_item] = array(
1059
-                'class' => $action_details['css_class'],
1060
-                'desc'  => $action_details['label']
1061
-            );
1062
-        }
1063
-        
1064
-        /** @type array $status_items status legend setup */
1065
-        $status_items = array(
1066
-            'sent_status'       => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1068
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1069
-            ),
1070
-            'idle_status'       => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1072
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1073
-            ),
1074
-            'failed_status'     => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1076
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1077
-            ),
1078
-            'messenger_executing_status' => array(
1079
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1080
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1081
-            ),
1082
-            'resend_status'     => array(
1083
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1084
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1085
-            ),
1086
-            'incomplete_status' => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1089
-            ),
1090
-            'retry_status'      => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1092
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1093
-            )
1094
-        );
1095
-        if (EEM_Message::debug()) {
1096
-            $status_items['debug_only_status'] = array(
1097
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1098
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1099
-            );
1100
-        }
1101
-        
1102
-        return array_merge($action_items, $status_items);
1103
-    }
1048
+	protected function _message_legend_items()
1049
+	{
1050
+        
1051
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1052
+		$action_items       = array();
1053
+        
1054
+		foreach ($action_css_classes as $action_item => $action_details) {
1055
+			if ($action_item === 'see_notifications_for') {
1056
+				continue;
1057
+			}
1058
+			$action_items[$action_item] = array(
1059
+				'class' => $action_details['css_class'],
1060
+				'desc'  => $action_details['label']
1061
+			);
1062
+		}
1063
+        
1064
+		/** @type array $status_items status legend setup */
1065
+		$status_items = array(
1066
+			'sent_status'       => array(
1067
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1068
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1069
+			),
1070
+			'idle_status'       => array(
1071
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1072
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1073
+			),
1074
+			'failed_status'     => array(
1075
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1076
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1077
+			),
1078
+			'messenger_executing_status' => array(
1079
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1080
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1081
+			),
1082
+			'resend_status'     => array(
1083
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1084
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1085
+			),
1086
+			'incomplete_status' => array(
1087
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1089
+			),
1090
+			'retry_status'      => array(
1091
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1092
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1093
+			)
1094
+		);
1095
+		if (EEM_Message::debug()) {
1096
+			$status_items['debug_only_status'] = array(
1097
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1098
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1099
+			);
1100
+		}
1101
+        
1102
+		return array_merge($action_items, $status_items);
1103
+	}
1104 1104
     
1105 1105
     
1106
-    protected function _custom_mtps_preview()
1107
-    {
1108
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1109
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1110
-            . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1111
-        $this->_template_args['preview_text'] = '<strong>'
1112
-            . esc_html__(
1113
-                'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1114
-                'event_espresso'
1115
-            )
1116
-            . '</strong>';
1106
+	protected function _custom_mtps_preview()
1107
+	{
1108
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1109
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1110
+			. ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1111
+		$this->_template_args['preview_text'] = '<strong>'
1112
+			. esc_html__(
1113
+				'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1114
+				'event_espresso'
1115
+			)
1116
+			. '</strong>';
1117 1117
 
1118
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1119
-    }
1118
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1119
+	}
1120 1120
 
1121 1121
 
1122
-    /**
1123
-     * get_message_templates
1124
-     * This gets all the message templates for listing on the overview list.
1125
-     *
1126
-     * @access public
1127
-     * @param int    $perpage the amount of templates groups to show per page
1128
-     * @param string $type    the current _view we're getting templates for
1129
-     * @param bool   $count   return count?
1130
-     * @param bool   $all     disregard any paging info (get all data);
1131
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1132
-     * @return array
1133
-     * @throws EE_Error
1134
-     * @throws InvalidArgumentException
1135
-     * @throws InvalidDataTypeException
1136
-     * @throws InvalidInterfaceException
1137
-     */
1138
-    public function get_message_templates(
1139
-        $perpage = 10,
1140
-        $type = 'in_use',
1141
-        $count = false,
1142
-        $all = false,
1143
-        $global = true)
1144
-    {
1145
-        
1146
-        $MTP = EEM_Message_Template_Group::instance();
1147
-        
1148
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1149
-        $orderby                    = $this->_req_data['orderby'];
1150
-        
1151
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1152
-            ? $this->_req_data['order']
1153
-            : 'ASC';
1154
-        
1155
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1156
-            ? $this->_req_data['paged']
1157
-            : 1;
1158
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1159
-            ? $this->_req_data['perpage']
1160
-            : $perpage;
1161
-        
1162
-        $offset = ($current_page - 1) * $per_page;
1163
-        $limit  = $all ? null : array($offset, $per_page);
1164
-        
1165
-        
1166
-        //options will match what is in the _views array property
1167
-        switch ($type) {
1168
-            case 'in_use':
1169
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1170
-                break;
1171
-            default:
1172
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1173
-        }
1174
-        
1175
-        return $templates;
1176
-    }
1122
+	/**
1123
+	 * get_message_templates
1124
+	 * This gets all the message templates for listing on the overview list.
1125
+	 *
1126
+	 * @access public
1127
+	 * @param int    $perpage the amount of templates groups to show per page
1128
+	 * @param string $type    the current _view we're getting templates for
1129
+	 * @param bool   $count   return count?
1130
+	 * @param bool   $all     disregard any paging info (get all data);
1131
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1132
+	 * @return array
1133
+	 * @throws EE_Error
1134
+	 * @throws InvalidArgumentException
1135
+	 * @throws InvalidDataTypeException
1136
+	 * @throws InvalidInterfaceException
1137
+	 */
1138
+	public function get_message_templates(
1139
+		$perpage = 10,
1140
+		$type = 'in_use',
1141
+		$count = false,
1142
+		$all = false,
1143
+		$global = true)
1144
+	{
1145
+        
1146
+		$MTP = EEM_Message_Template_Group::instance();
1147
+        
1148
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1149
+		$orderby                    = $this->_req_data['orderby'];
1150
+        
1151
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1152
+			? $this->_req_data['order']
1153
+			: 'ASC';
1154
+        
1155
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1156
+			? $this->_req_data['paged']
1157
+			: 1;
1158
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1159
+			? $this->_req_data['perpage']
1160
+			: $perpage;
1161
+        
1162
+		$offset = ($current_page - 1) * $per_page;
1163
+		$limit  = $all ? null : array($offset, $per_page);
1164
+        
1165
+        
1166
+		//options will match what is in the _views array property
1167
+		switch ($type) {
1168
+			case 'in_use':
1169
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1170
+				break;
1171
+			default:
1172
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1173
+		}
1174
+        
1175
+		return $templates;
1176
+	}
1177 1177
     
1178 1178
     
1179
-    /**
1180
-     * filters etc might need a list of installed message_types
1181
-     * @return array an array of message type objects
1182
-     */
1183
-    public function get_installed_message_types()
1184
-    {
1185
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1186
-        $installed               = array();
1187
-        
1188
-        foreach ($installed_message_types as $message_type) {
1189
-            $installed[$message_type->name] = $message_type;
1190
-        }
1191
-        
1192
-        return $installed;
1193
-    }
1179
+	/**
1180
+	 * filters etc might need a list of installed message_types
1181
+	 * @return array an array of message type objects
1182
+	 */
1183
+	public function get_installed_message_types()
1184
+	{
1185
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1186
+		$installed               = array();
1187
+        
1188
+		foreach ($installed_message_types as $message_type) {
1189
+			$installed[$message_type->name] = $message_type;
1190
+		}
1191
+        
1192
+		return $installed;
1193
+	}
1194 1194
     
1195 1195
     
1196
-    /**
1197
-     * _add_message_template
1198
-     *
1199
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1200
-     *
1201
-     * @param string $message_type
1202
-     * @param string $messenger
1203
-     * @param string $GRP_ID
1204
-     *
1205
-     * @throws EE_error
1206
-     */
1207
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1208
-    {
1209
-        //set values override any request data
1210
-        $message_type = ! empty($message_type) ? $message_type : '';
1211
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1212
-            ? $this->_req_data['message_type']
1213
-            : $message_type;
1214
-        
1215
-        $messenger = ! empty($messenger) ? $messenger : '';
1216
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1217
-            ? $this->_req_data['messenger']
1218
-            : $messenger;
1219
-        
1220
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1221
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1222
-        
1223
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1224
-        if (empty($message_type) || empty($messenger)) {
1225
-            throw new EE_Error(
1226
-                esc_html__(
1227
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1228
-                    'event_espresso'
1229
-                )
1230
-            );
1231
-        }
1232
-        
1233
-        //we need the GRP_ID for the template being used as the base for the new template
1234
-        if (empty($GRP_ID)) {
1235
-            throw new EE_Error(
1236
-                esc_html__(
1237
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1238
-                    'event_espresso'
1239
-                )
1240
-            );
1241
-        }
1242
-        
1243
-        //let's just make sure the template gets generated!
1244
-        
1245
-        //we need to reassign some variables for what the insert is expecting
1246
-        $this->_req_data['MTP_messenger']    = $messenger;
1247
-        $this->_req_data['MTP_message_type'] = $message_type;
1248
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1249
-        $this->_insert_or_update_message_template(true);
1250
-    }
1196
+	/**
1197
+	 * _add_message_template
1198
+	 *
1199
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1200
+	 *
1201
+	 * @param string $message_type
1202
+	 * @param string $messenger
1203
+	 * @param string $GRP_ID
1204
+	 *
1205
+	 * @throws EE_error
1206
+	 */
1207
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1208
+	{
1209
+		//set values override any request data
1210
+		$message_type = ! empty($message_type) ? $message_type : '';
1211
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1212
+			? $this->_req_data['message_type']
1213
+			: $message_type;
1214
+        
1215
+		$messenger = ! empty($messenger) ? $messenger : '';
1216
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1217
+			? $this->_req_data['messenger']
1218
+			: $messenger;
1219
+        
1220
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1221
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1222
+        
1223
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1224
+		if (empty($message_type) || empty($messenger)) {
1225
+			throw new EE_Error(
1226
+				esc_html__(
1227
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1228
+					'event_espresso'
1229
+				)
1230
+			);
1231
+		}
1232
+        
1233
+		//we need the GRP_ID for the template being used as the base for the new template
1234
+		if (empty($GRP_ID)) {
1235
+			throw new EE_Error(
1236
+				esc_html__(
1237
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1238
+					'event_espresso'
1239
+				)
1240
+			);
1241
+		}
1242
+        
1243
+		//let's just make sure the template gets generated!
1244
+        
1245
+		//we need to reassign some variables for what the insert is expecting
1246
+		$this->_req_data['MTP_messenger']    = $messenger;
1247
+		$this->_req_data['MTP_message_type'] = $message_type;
1248
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1249
+		$this->_insert_or_update_message_template(true);
1250
+	}
1251 1251
 
1252 1252
 
1253
-    /**
1254
-     * public wrapper for the _add_message_template method
1255
-     *
1256
-     * @param string $message_type     message type slug
1257
-     * @param string $messenger        messenger slug
1258
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1259
-     *                                 off of.
1260
-     * @throws EE_error
1261
-     */
1262
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1263
-    {
1264
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1265
-    }
1253
+	/**
1254
+	 * public wrapper for the _add_message_template method
1255
+	 *
1256
+	 * @param string $message_type     message type slug
1257
+	 * @param string $messenger        messenger slug
1258
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1259
+	 *                                 off of.
1260
+	 * @throws EE_error
1261
+	 */
1262
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1263
+	{
1264
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1265
+	}
1266 1266
 
1267 1267
 
1268
-    /**
1269
-     * _edit_message_template
1270
-     *
1271
-     * @access protected
1272
-     * @return void
1273
-     * @throws InvalidIdentifierException
1274
-     * @throws DomainException
1275
-     * @throws EE_Error
1276
-     * @throws InvalidArgumentException
1277
-     * @throws ReflectionException
1278
-     * @throws InvalidDataTypeException
1279
-     * @throws InvalidInterfaceException
1280
-     */
1281
-    protected function _edit_message_template()
1282
-    {
1283
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1284
-        $template_fields = '';
1285
-        $sidebar_fields  = '';
1286
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1287
-        // valid html in the templates.
1288
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1289
-        
1290
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1291
-            ? absint($this->_req_data['id'])
1292
-            : false;
1293
-        
1294
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1295
-        $message_template_group = $this->_message_template_group;
1296
-        $c_label                = $message_template_group->context_label();
1297
-        $c_config               = $message_template_group->contexts_config();
1298
-        
1299
-        reset($c_config);
1300
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1301
-            ? strtolower($this->_req_data['context'])
1302
-            : key($c_config);
1303
-        
1304
-        
1305
-        if (empty($GRP_ID)) {
1306
-            $action = 'insert_message_template';
1307
-            $edit_message_template_form_url = add_query_arg(
1308
-                array('action' => $action, 'noheader' => true),
1309
-                EE_MSG_ADMIN_URL
1310
-            );
1311
-        } else {
1312
-            $action = 'update_message_template';
1313
-            $edit_message_template_form_url = add_query_arg(
1314
-                array('action' => $action, 'noheader' => true),
1315
-                EE_MSG_ADMIN_URL
1316
-            );
1317
-        }
1318
-        
1319
-        //set active messenger for this view
1320
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1321
-            $message_template_group->messenger()
1322
-        );
1323
-        $this->_active_message_type_name = $message_template_group->message_type();
1324
-        
1325
-        
1326
-        //Do we have any validation errors?
1327
-        $validators = $this->_get_transient();
1328
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1329
-        
1330
-        
1331
-        //we need to assemble the title from Various details
1332
-        $context_label = sprintf(
1333
-            esc_html__('(%s %s)', 'event_espresso'),
1334
-            $c_config[$context]['label'],
1335
-            ucwords($c_label['label'])
1336
-        );
1337
-        
1338
-        $title = sprintf(
1339
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1340
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1341
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1342
-            $context_label
1343
-        );
1344
-        
1345
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1346
-        $this->_template_args['message_template'] = $message_template_group;
1347
-        $this->_template_args['is_extra_fields']  = false;
1348
-        
1349
-        
1350
-        //let's get EEH_MSG_Template so we can get template form fields
1351
-        $template_field_structure = EEH_MSG_Template::get_fields(
1352
-            $message_template_group->messenger(),
1353
-            $message_template_group->message_type()
1354
-        );
1355
-        
1356
-        if ( ! $template_field_structure) {
1357
-            $template_field_structure = false;
1358
-            $template_fields          = esc_html__(
1359
-                'There was an error in assembling the fields for this display (you should see an error message)',
1360
-                'event_espresso'
1361
-            );
1362
-        }
1363
-        
1364
-        
1365
-        $message_templates = $message_template_group->context_templates();
1366
-        
1367
-        
1368
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1369
-        // will get handled in the "extra" array.
1370
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1371
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1372
-                unset($template_field_structure[$context][$reference_field]);
1373
-            }
1374
-        }
1375
-        
1376
-        //let's loop through the template_field_structure and actually assemble the input fields!
1377
-        if ( ! empty($template_field_structure)) {
1378
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1379
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1380
-                // the extra array and reset them.
1381
-                if ($template_field === 'extra') {
1382
-                    $this->_template_args['is_extra_fields'] = true;
1383
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1384
-                        $message_template = $message_templates[$context][$reference_field];
1385
-                        $content          = $message_template instanceof EE_Message_Template
1386
-                            ? $message_template->get('MTP_content')
1387
-                            : '';
1388
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1389
-                            //let's verify if we need this extra field via the shortcodes parameter.
1390
-                            $continue = false;
1391
-                            if (isset($extra_array['shortcodes_required'])) {
1392
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1393
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1394
-                                        $continue = true;
1395
-                                    }
1396
-                                }
1397
-                                if ($continue) {
1398
-                                    continue;
1399
-                                }
1400
-                            }
1268
+	/**
1269
+	 * _edit_message_template
1270
+	 *
1271
+	 * @access protected
1272
+	 * @return void
1273
+	 * @throws InvalidIdentifierException
1274
+	 * @throws DomainException
1275
+	 * @throws EE_Error
1276
+	 * @throws InvalidArgumentException
1277
+	 * @throws ReflectionException
1278
+	 * @throws InvalidDataTypeException
1279
+	 * @throws InvalidInterfaceException
1280
+	 */
1281
+	protected function _edit_message_template()
1282
+	{
1283
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1284
+		$template_fields = '';
1285
+		$sidebar_fields  = '';
1286
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1287
+		// valid html in the templates.
1288
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1289
+        
1290
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1291
+			? absint($this->_req_data['id'])
1292
+			: false;
1293
+        
1294
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1295
+		$message_template_group = $this->_message_template_group;
1296
+		$c_label                = $message_template_group->context_label();
1297
+		$c_config               = $message_template_group->contexts_config();
1298
+        
1299
+		reset($c_config);
1300
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1301
+			? strtolower($this->_req_data['context'])
1302
+			: key($c_config);
1303
+        
1304
+        
1305
+		if (empty($GRP_ID)) {
1306
+			$action = 'insert_message_template';
1307
+			$edit_message_template_form_url = add_query_arg(
1308
+				array('action' => $action, 'noheader' => true),
1309
+				EE_MSG_ADMIN_URL
1310
+			);
1311
+		} else {
1312
+			$action = 'update_message_template';
1313
+			$edit_message_template_form_url = add_query_arg(
1314
+				array('action' => $action, 'noheader' => true),
1315
+				EE_MSG_ADMIN_URL
1316
+			);
1317
+		}
1318
+        
1319
+		//set active messenger for this view
1320
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1321
+			$message_template_group->messenger()
1322
+		);
1323
+		$this->_active_message_type_name = $message_template_group->message_type();
1324
+        
1325
+        
1326
+		//Do we have any validation errors?
1327
+		$validators = $this->_get_transient();
1328
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1329
+        
1330
+        
1331
+		//we need to assemble the title from Various details
1332
+		$context_label = sprintf(
1333
+			esc_html__('(%s %s)', 'event_espresso'),
1334
+			$c_config[$context]['label'],
1335
+			ucwords($c_label['label'])
1336
+		);
1337
+        
1338
+		$title = sprintf(
1339
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1340
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1341
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1342
+			$context_label
1343
+		);
1344
+        
1345
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1346
+		$this->_template_args['message_template'] = $message_template_group;
1347
+		$this->_template_args['is_extra_fields']  = false;
1348
+        
1349
+        
1350
+		//let's get EEH_MSG_Template so we can get template form fields
1351
+		$template_field_structure = EEH_MSG_Template::get_fields(
1352
+			$message_template_group->messenger(),
1353
+			$message_template_group->message_type()
1354
+		);
1355
+        
1356
+		if ( ! $template_field_structure) {
1357
+			$template_field_structure = false;
1358
+			$template_fields          = esc_html__(
1359
+				'There was an error in assembling the fields for this display (you should see an error message)',
1360
+				'event_espresso'
1361
+			);
1362
+		}
1363
+        
1364
+        
1365
+		$message_templates = $message_template_group->context_templates();
1366
+        
1367
+        
1368
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1369
+		// will get handled in the "extra" array.
1370
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1371
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1372
+				unset($template_field_structure[$context][$reference_field]);
1373
+			}
1374
+		}
1375
+        
1376
+		//let's loop through the template_field_structure and actually assemble the input fields!
1377
+		if ( ! empty($template_field_structure)) {
1378
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1379
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1380
+				// the extra array and reset them.
1381
+				if ($template_field === 'extra') {
1382
+					$this->_template_args['is_extra_fields'] = true;
1383
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1384
+						$message_template = $message_templates[$context][$reference_field];
1385
+						$content          = $message_template instanceof EE_Message_Template
1386
+							? $message_template->get('MTP_content')
1387
+							: '';
1388
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1389
+							//let's verify if we need this extra field via the shortcodes parameter.
1390
+							$continue = false;
1391
+							if (isset($extra_array['shortcodes_required'])) {
1392
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1393
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1394
+										$continue = true;
1395
+									}
1396
+								}
1397
+								if ($continue) {
1398
+									continue;
1399
+								}
1400
+							}
1401 1401
                             
1402
-                            $field_id                                = $reference_field
1403
-                                                                       . '-'
1404
-                                                                       . $extra_field
1405
-                                                                       . '-content';
1406
-                            $template_form_fields[$field_id]         = $extra_array;
1407
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1408
-                                                                       . $reference_field
1409
-                                                                       . '][content]['
1410
-                                                                       . $extra_field . ']';
1411
-                            $css_class                               = isset($extra_array['css_class'])
1412
-                                ? $extra_array['css_class']
1413
-                                : '';
1402
+							$field_id                                = $reference_field
1403
+																	   . '-'
1404
+																	   . $extra_field
1405
+																	   . '-content';
1406
+							$template_form_fields[$field_id]         = $extra_array;
1407
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1408
+																	   . $reference_field
1409
+																	   . '][content]['
1410
+																	   . $extra_field . ']';
1411
+							$css_class                               = isset($extra_array['css_class'])
1412
+								? $extra_array['css_class']
1413
+								: '';
1414 1414
                             
1415
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1416
-                                && in_array($extra_field, $v_fields, true)
1417
-                                &&
1418
-                                (
1419
-                                    is_array($validators[$extra_field])
1420
-                                    && isset($validators[$extra_field]['msg'])
1421
-                                )
1422
-                                ? 'validate-error ' . $css_class
1423
-                                : $css_class;
1415
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1416
+								&& in_array($extra_field, $v_fields, true)
1417
+								&&
1418
+								(
1419
+									is_array($validators[$extra_field])
1420
+									&& isset($validators[$extra_field]['msg'])
1421
+								)
1422
+								? 'validate-error ' . $css_class
1423
+								: $css_class;
1424 1424
                             
1425
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1426
-                                                                        && isset($content[$extra_field])
1427
-                                ? $content[$extra_field]
1428
-                                : '';
1425
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1426
+																		&& isset($content[$extra_field])
1427
+								? $content[$extra_field]
1428
+								: '';
1429 1429
                             
1430
-                            //do we have a validation error?  if we do then let's use that value instead
1431
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1432
-                                ? $validators[$extra_field]['value']
1433
-                                : $template_form_fields[$field_id]['value'];
1430
+							//do we have a validation error?  if we do then let's use that value instead
1431
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1432
+								? $validators[$extra_field]['value']
1433
+								: $template_form_fields[$field_id]['value'];
1434 1434
                             
1435 1435
                             
1436
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1436
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1437 1437
                             
1438
-                            //shortcode selector
1439
-                            $field_name_to_use                                 = $extra_field === 'main'
1440
-                                ? 'content'
1441
-                                : $extra_field;
1442
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1443
-                                $field_name_to_use,
1444
-                                $field_id
1445
-                            );
1438
+							//shortcode selector
1439
+							$field_name_to_use                                 = $extra_field === 'main'
1440
+								? 'content'
1441
+								: $extra_field;
1442
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1443
+								$field_name_to_use,
1444
+								$field_id
1445
+							);
1446 1446
                             
1447
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1448
-                                //we want to decode the entities
1449
-                                $template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value'];
1447
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1448
+								//we want to decode the entities
1449
+								$template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value'];
1450 1450
                                 
1451
-                            }/**/
1452
-                        }
1453
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1454
-                        $templatefield_templatename_id = $reference_field . '-name';
1451
+							}/**/
1452
+						}
1453
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1454
+						$templatefield_templatename_id = $reference_field . '-name';
1455 1455
                         
1456
-                        $template_form_fields[$templatefield_MTP_id] = array(
1457
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1458
-                            'label'      => null,
1459
-                            'input'      => 'hidden',
1460
-                            'type'       => 'int',
1461
-                            'required'   => false,
1462
-                            'validation' => false,
1463
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1464
-                            'css_class'  => '',
1465
-                            'format'     => '%d',
1466
-                            'db-col'     => 'MTP_ID'
1467
-                        );
1456
+						$template_form_fields[$templatefield_MTP_id] = array(
1457
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1458
+							'label'      => null,
1459
+							'input'      => 'hidden',
1460
+							'type'       => 'int',
1461
+							'required'   => false,
1462
+							'validation' => false,
1463
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1464
+							'css_class'  => '',
1465
+							'format'     => '%d',
1466
+							'db-col'     => 'MTP_ID'
1467
+						);
1468 1468
                         
1469
-                        $template_form_fields[$templatefield_templatename_id] = array(
1470
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1471
-                            'label'      => null,
1472
-                            'input'      => 'hidden',
1473
-                            'type'       => 'string',
1474
-                            'required'   => false,
1475
-                            'validation' => true,
1476
-                            'value'      => $reference_field,
1477
-                            'css_class'  => '',
1478
-                            'format'     => '%s',
1479
-                            'db-col'     => 'MTP_template_field'
1480
-                        );
1481
-                    }
1482
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1483
-                } else {
1484
-                    $field_id                                 = $template_field . '-content';
1485
-                    $template_form_fields[$field_id]          = $field_setup_array;
1486
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1487
-                    $message_template                         = isset($message_templates[$context][$template_field])
1488
-                        ? $message_templates[$context][$template_field]
1489
-                        : null;
1490
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1491
-                                                                && is_array($message_templates[$context])
1492
-                                                                && $message_template instanceof EE_Message_Template
1493
-                        ? $message_template->get('MTP_content')
1494
-                        : '';
1469
+						$template_form_fields[$templatefield_templatename_id] = array(
1470
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1471
+							'label'      => null,
1472
+							'input'      => 'hidden',
1473
+							'type'       => 'string',
1474
+							'required'   => false,
1475
+							'validation' => true,
1476
+							'value'      => $reference_field,
1477
+							'css_class'  => '',
1478
+							'format'     => '%s',
1479
+							'db-col'     => 'MTP_template_field'
1480
+						);
1481
+					}
1482
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1483
+				} else {
1484
+					$field_id                                 = $template_field . '-content';
1485
+					$template_form_fields[$field_id]          = $field_setup_array;
1486
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1487
+					$message_template                         = isset($message_templates[$context][$template_field])
1488
+						? $message_templates[$context][$template_field]
1489
+						: null;
1490
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1491
+																&& is_array($message_templates[$context])
1492
+																&& $message_template instanceof EE_Message_Template
1493
+						? $message_template->get('MTP_content')
1494
+						: '';
1495 1495
                     
1496
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1497
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1498
-                        ? $validators[$template_field]['value']
1499
-                        : $template_form_fields[$field_id]['value'];
1496
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1497
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1498
+						? $validators[$template_field]['value']
1499
+						: $template_form_fields[$field_id]['value'];
1500 1500
                     
1501 1501
                     
1502
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1503
-                    $css_class                                    = isset($field_setup_array['css_class'])
1504
-                        ? $field_setup_array['css_class']
1505
-                        : '';
1506
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1507
-                                                                    && in_array($template_field, $v_fields, true)
1508
-                                                                    && isset($validators[$template_field]['msg'])
1509
-                        ? 'validate-error ' . $css_class
1510
-                        : $css_class;
1502
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1503
+					$css_class                                    = isset($field_setup_array['css_class'])
1504
+						? $field_setup_array['css_class']
1505
+						: '';
1506
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1507
+																	&& in_array($template_field, $v_fields, true)
1508
+																	&& isset($validators[$template_field]['msg'])
1509
+						? 'validate-error ' . $css_class
1510
+						: $css_class;
1511 1511
                     
1512
-                    //shortcode selector
1513
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1514
-                        $template_field, $field_id
1515
-                    );
1516
-                }
1512
+					//shortcode selector
1513
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1514
+						$template_field, $field_id
1515
+					);
1516
+				}
1517 1517
                 
1518
-                //k took care of content field(s) now let's take care of others.
1518
+				//k took care of content field(s) now let's take care of others.
1519 1519
                 
1520
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1521
-                $templatefield_field_templatename_id = $template_field . '-name';
1520
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1521
+				$templatefield_field_templatename_id = $template_field . '-name';
1522 1522
                 
1523
-                //foreach template field there are actually two form fields created
1524
-                $template_form_fields[$templatefield_MTP_id] = array(
1525
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1526
-                    'label'      => null,
1527
-                    'input'      => 'hidden',
1528
-                    'type'       => 'int',
1529
-                    'required'   => false,
1530
-                    'validation' => true,
1531
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1532
-                    'css_class'  => '',
1533
-                    'format'     => '%d',
1534
-                    'db-col'     => 'MTP_ID'
1535
-                );
1523
+				//foreach template field there are actually two form fields created
1524
+				$template_form_fields[$templatefield_MTP_id] = array(
1525
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1526
+					'label'      => null,
1527
+					'input'      => 'hidden',
1528
+					'type'       => 'int',
1529
+					'required'   => false,
1530
+					'validation' => true,
1531
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1532
+					'css_class'  => '',
1533
+					'format'     => '%d',
1534
+					'db-col'     => 'MTP_ID'
1535
+				);
1536 1536
                 
1537
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1538
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1539
-                    'label'      => null,
1540
-                    'input'      => 'hidden',
1541
-                    'type'       => 'string',
1542
-                    'required'   => false,
1543
-                    'validation' => true,
1544
-                    'value'      => $template_field,
1545
-                    'css_class'  => '',
1546
-                    'format'     => '%s',
1547
-                    'db-col'     => 'MTP_template_field'
1548
-                );
1537
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1538
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1539
+					'label'      => null,
1540
+					'input'      => 'hidden',
1541
+					'type'       => 'string',
1542
+					'required'   => false,
1543
+					'validation' => true,
1544
+					'value'      => $template_field,
1545
+					'css_class'  => '',
1546
+					'format'     => '%s',
1547
+					'db-col'     => 'MTP_template_field'
1548
+				);
1549 1549
                 
1550
-            }
1550
+			}
1551 1551
             
1552
-            //add other fields
1553
-            $template_form_fields['ee-msg-current-context'] = array(
1554
-                'name'       => 'MTP_context',
1555
-                'label'      => null,
1556
-                'input'      => 'hidden',
1557
-                'type'       => 'string',
1558
-                'required'   => false,
1559
-                'validation' => true,
1560
-                'value'      => $context,
1561
-                'css_class'  => '',
1562
-                'format'     => '%s',
1563
-                'db-col'     => 'MTP_context'
1564
-            );
1552
+			//add other fields
1553
+			$template_form_fields['ee-msg-current-context'] = array(
1554
+				'name'       => 'MTP_context',
1555
+				'label'      => null,
1556
+				'input'      => 'hidden',
1557
+				'type'       => 'string',
1558
+				'required'   => false,
1559
+				'validation' => true,
1560
+				'value'      => $context,
1561
+				'css_class'  => '',
1562
+				'format'     => '%s',
1563
+				'db-col'     => 'MTP_context'
1564
+			);
1565 1565
             
1566
-            $template_form_fields['ee-msg-grp-id'] = array(
1567
-                'name'       => 'GRP_ID',
1568
-                'label'      => null,
1569
-                'input'      => 'hidden',
1570
-                'type'       => 'int',
1571
-                'required'   => false,
1572
-                'validation' => true,
1573
-                'value'      => $GRP_ID,
1574
-                'css_class'  => '',
1575
-                'format'     => '%d',
1576
-                'db-col'     => 'GRP_ID'
1577
-            );
1566
+			$template_form_fields['ee-msg-grp-id'] = array(
1567
+				'name'       => 'GRP_ID',
1568
+				'label'      => null,
1569
+				'input'      => 'hidden',
1570
+				'type'       => 'int',
1571
+				'required'   => false,
1572
+				'validation' => true,
1573
+				'value'      => $GRP_ID,
1574
+				'css_class'  => '',
1575
+				'format'     => '%d',
1576
+				'db-col'     => 'GRP_ID'
1577
+			);
1578 1578
             
1579
-            $template_form_fields['ee-msg-messenger'] = array(
1580
-                'name'       => 'MTP_messenger',
1581
-                'label'      => null,
1582
-                'input'      => 'hidden',
1583
-                'type'       => 'string',
1584
-                'required'   => false,
1585
-                'validation' => true,
1586
-                'value'      => $message_template_group->messenger(),
1587
-                'css_class'  => '',
1588
-                'format'     => '%s',
1589
-                'db-col'     => 'MTP_messenger'
1590
-            );
1579
+			$template_form_fields['ee-msg-messenger'] = array(
1580
+				'name'       => 'MTP_messenger',
1581
+				'label'      => null,
1582
+				'input'      => 'hidden',
1583
+				'type'       => 'string',
1584
+				'required'   => false,
1585
+				'validation' => true,
1586
+				'value'      => $message_template_group->messenger(),
1587
+				'css_class'  => '',
1588
+				'format'     => '%s',
1589
+				'db-col'     => 'MTP_messenger'
1590
+			);
1591 1591
             
1592
-            $template_form_fields['ee-msg-message-type'] = array(
1593
-                'name'       => 'MTP_message_type',
1594
-                'label'      => null,
1595
-                'input'      => 'hidden',
1596
-                'type'       => 'string',
1597
-                'required'   => false,
1598
-                'validation' => true,
1599
-                'value'      => $message_template_group->message_type(),
1600
-                'css_class'  => '',
1601
-                'format'     => '%s',
1602
-                'db-col'     => 'MTP_message_type'
1603
-            );
1592
+			$template_form_fields['ee-msg-message-type'] = array(
1593
+				'name'       => 'MTP_message_type',
1594
+				'label'      => null,
1595
+				'input'      => 'hidden',
1596
+				'type'       => 'string',
1597
+				'required'   => false,
1598
+				'validation' => true,
1599
+				'value'      => $message_template_group->message_type(),
1600
+				'css_class'  => '',
1601
+				'format'     => '%s',
1602
+				'db-col'     => 'MTP_message_type'
1603
+			);
1604 1604
             
1605
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1606
-                'name'       => 'MTP_is_global',
1607
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1608
-                'input'      => 'hidden',
1609
-                'type'       => 'int',
1610
-                'required'   => false,
1611
-                'validation' => true,
1612
-                'value'      => $message_template_group->get('MTP_is_global'),
1613
-                'css_class'  => '',
1614
-                'format'     => '%d',
1615
-                'db-col'     => 'MTP_is_global'
1616
-            );
1605
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1606
+				'name'       => 'MTP_is_global',
1607
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1608
+				'input'      => 'hidden',
1609
+				'type'       => 'int',
1610
+				'required'   => false,
1611
+				'validation' => true,
1612
+				'value'      => $message_template_group->get('MTP_is_global'),
1613
+				'css_class'  => '',
1614
+				'format'     => '%d',
1615
+				'db-col'     => 'MTP_is_global'
1616
+			);
1617 1617
             
1618
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1619
-                'name'       => 'MTP_is_override',
1620
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1621
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1622
-                'type'       => 'int',
1623
-                'required'   => false,
1624
-                'validation' => true,
1625
-                'value'      => $message_template_group->get('MTP_is_override'),
1626
-                'css_class'  => '',
1627
-                'format'     => '%d',
1628
-                'db-col'     => 'MTP_is_override'
1629
-            );
1618
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1619
+				'name'       => 'MTP_is_override',
1620
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1621
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1622
+				'type'       => 'int',
1623
+				'required'   => false,
1624
+				'validation' => true,
1625
+				'value'      => $message_template_group->get('MTP_is_override'),
1626
+				'css_class'  => '',
1627
+				'format'     => '%d',
1628
+				'db-col'     => 'MTP_is_override'
1629
+			);
1630 1630
             
1631
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1632
-                'name'       => 'MTP_is_active',
1633
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1634
-                'input'      => 'hidden',
1635
-                'type'       => 'int',
1636
-                'required'   => false,
1637
-                'validation' => true,
1638
-                'value'      => $message_template_group->is_active(),
1639
-                'css_class'  => '',
1640
-                'format'     => '%d',
1641
-                'db-col'     => 'MTP_is_active'
1642
-            );
1631
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1632
+				'name'       => 'MTP_is_active',
1633
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1634
+				'input'      => 'hidden',
1635
+				'type'       => 'int',
1636
+				'required'   => false,
1637
+				'validation' => true,
1638
+				'value'      => $message_template_group->is_active(),
1639
+				'css_class'  => '',
1640
+				'format'     => '%d',
1641
+				'db-col'     => 'MTP_is_active'
1642
+			);
1643 1643
             
1644
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1645
-                'name'       => 'MTP_deleted',
1646
-                'label'      => null,
1647
-                'input'      => 'hidden',
1648
-                'type'       => 'int',
1649
-                'required'   => false,
1650
-                'validation' => true,
1651
-                'value'      => $message_template_group->get('MTP_deleted'),
1652
-                'css_class'  => '',
1653
-                'format'     => '%d',
1654
-                'db-col'     => 'MTP_deleted'
1655
-            );
1656
-            $sidebar_form_fields['ee-msg-author']  = array(
1657
-                'name'       => 'MTP_user_id',
1658
-                'label'      => esc_html__('Author', 'event_espresso'),
1659
-                'input'      => 'hidden',
1660
-                'type'       => 'int',
1661
-                'required'   => false,
1662
-                'validation' => false,
1663
-                'value'      => $message_template_group->user(),
1664
-                'format'     => '%d',
1665
-                'db-col'     => 'MTP_user_id'
1666
-            );
1644
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1645
+				'name'       => 'MTP_deleted',
1646
+				'label'      => null,
1647
+				'input'      => 'hidden',
1648
+				'type'       => 'int',
1649
+				'required'   => false,
1650
+				'validation' => true,
1651
+				'value'      => $message_template_group->get('MTP_deleted'),
1652
+				'css_class'  => '',
1653
+				'format'     => '%d',
1654
+				'db-col'     => 'MTP_deleted'
1655
+			);
1656
+			$sidebar_form_fields['ee-msg-author']  = array(
1657
+				'name'       => 'MTP_user_id',
1658
+				'label'      => esc_html__('Author', 'event_espresso'),
1659
+				'input'      => 'hidden',
1660
+				'type'       => 'int',
1661
+				'required'   => false,
1662
+				'validation' => false,
1663
+				'value'      => $message_template_group->user(),
1664
+				'format'     => '%d',
1665
+				'db-col'     => 'MTP_user_id'
1666
+			);
1667 1667
             
1668
-            $sidebar_form_fields['ee-msg-route'] = array(
1669
-                'name'  => 'action',
1670
-                'input' => 'hidden',
1671
-                'type'  => 'string',
1672
-                'value' => $action
1673
-            );
1668
+			$sidebar_form_fields['ee-msg-route'] = array(
1669
+				'name'  => 'action',
1670
+				'input' => 'hidden',
1671
+				'type'  => 'string',
1672
+				'value' => $action
1673
+			);
1674 1674
             
1675
-            $sidebar_form_fields['ee-msg-id']        = array(
1676
-                'name'  => 'id',
1677
-                'input' => 'hidden',
1678
-                'type'  => 'int',
1679
-                'value' => $GRP_ID
1680
-            );
1681
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1682
-                'name'  => $action . '_nonce',
1683
-                'input' => 'hidden',
1684
-                'type'  => 'string',
1685
-                'value' => wp_create_nonce($action . '_nonce')
1686
-            );
1675
+			$sidebar_form_fields['ee-msg-id']        = array(
1676
+				'name'  => 'id',
1677
+				'input' => 'hidden',
1678
+				'type'  => 'int',
1679
+				'value' => $GRP_ID
1680
+			);
1681
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1682
+				'name'  => $action . '_nonce',
1683
+				'input' => 'hidden',
1684
+				'type'  => 'string',
1685
+				'value' => wp_create_nonce($action . '_nonce')
1686
+			);
1687 1687
             
1688
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1689
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1690
-                    'name'  => 'template_switch',
1691
-                    'input' => 'hidden',
1692
-                    'type'  => 'int',
1693
-                    'value' => 1
1694
-                );
1695
-            }
1688
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1689
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1690
+					'name'  => 'template_switch',
1691
+					'input' => 'hidden',
1692
+					'type'  => 'int',
1693
+					'value' => 1
1694
+				);
1695
+			}
1696 1696
             
1697 1697
             
1698
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1699
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1698
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1699
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1700 1700
             
1701 1701
             
1702
-        } //end if ( !empty($template_field_structure) )
1703
-        
1704
-        //set extra content for publish box
1705
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1706
-        $this->_set_publish_post_box_vars(
1707
-            'id',
1708
-            $GRP_ID,
1709
-            false,
1710
-            add_query_arg(
1711
-                array('action' => 'global_mtps'),
1712
-                $this->_admin_base_url
1713
-            )
1714
-        );
1715
-        
1716
-        //add preview button
1717
-        $preview_url    = parent::add_query_args_and_nonce(
1718
-            array(
1719
-                'message_type' => $message_template_group->message_type(),
1720
-                'messenger'    => $message_template_group->messenger(),
1721
-                'context'      => $context,
1722
-                'GRP_ID'       => $GRP_ID,
1723
-                'action'       => 'preview_message'
1724
-            ),
1725
-            $this->_admin_base_url
1726
-        );
1727
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1728
-                          . esc_html__('Preview', 'event_espresso')
1729
-                          . '</a>';
1730
-        
1731
-        
1732
-        //setup context switcher
1733
-        $context_switcher_args = array(
1734
-            'page'    => 'espresso_messages',
1735
-            'action'  => 'edit_message_template',
1736
-            'id'      => $GRP_ID,
1737
-            'context' => $context,
1738
-            'extra'   => $preview_button
1739
-        );
1740
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1741
-        
1742
-        
1743
-        //main box
1744
-        $this->_template_args['template_fields']                         = $template_fields;
1745
-        $this->_template_args['sidebar_box_id']                          = 'details';
1746
-        $this->_template_args['action']                                  = $action;
1747
-        $this->_template_args['context']                                 = $context;
1748
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1749
-        $this->_template_args['learn_more_about_message_templates_link'] =
1750
-            $this->_learn_more_about_message_templates_link();
1751
-        
1752
-        
1753
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1754
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1755
-            $message_template_group,
1756
-            $context,
1757
-            $context_label
1758
-        );
1759
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1760
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1761
-        
1762
-        $this->_template_path = $this->_template_args['GRP_ID']
1763
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1764
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1765
-        
1766
-        //send along EE_Message_Template_Group object for further template use.
1767
-        $this->_template_args['MTP'] = $message_template_group;
1768
-        
1769
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1770
-            $this->_template_path,
1771
-            $this->_template_args,
1772
-            true
1773
-        );
1774
-        
1775
-        
1776
-        //finally, let's set the admin_page title
1777
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1778
-        
1779
-        
1780
-        //we need to take care of setting the shortcodes property for use elsewhere.
1781
-        $this->_set_shortcodes();
1782
-        
1783
-        
1784
-        //final template wrapper
1785
-        $this->display_admin_page_with_sidebar();
1786
-    }
1702
+		} //end if ( !empty($template_field_structure) )
1703
+        
1704
+		//set extra content for publish box
1705
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1706
+		$this->_set_publish_post_box_vars(
1707
+			'id',
1708
+			$GRP_ID,
1709
+			false,
1710
+			add_query_arg(
1711
+				array('action' => 'global_mtps'),
1712
+				$this->_admin_base_url
1713
+			)
1714
+		);
1715
+        
1716
+		//add preview button
1717
+		$preview_url    = parent::add_query_args_and_nonce(
1718
+			array(
1719
+				'message_type' => $message_template_group->message_type(),
1720
+				'messenger'    => $message_template_group->messenger(),
1721
+				'context'      => $context,
1722
+				'GRP_ID'       => $GRP_ID,
1723
+				'action'       => 'preview_message'
1724
+			),
1725
+			$this->_admin_base_url
1726
+		);
1727
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1728
+						  . esc_html__('Preview', 'event_espresso')
1729
+						  . '</a>';
1730
+        
1731
+        
1732
+		//setup context switcher
1733
+		$context_switcher_args = array(
1734
+			'page'    => 'espresso_messages',
1735
+			'action'  => 'edit_message_template',
1736
+			'id'      => $GRP_ID,
1737
+			'context' => $context,
1738
+			'extra'   => $preview_button
1739
+		);
1740
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1741
+        
1742
+        
1743
+		//main box
1744
+		$this->_template_args['template_fields']                         = $template_fields;
1745
+		$this->_template_args['sidebar_box_id']                          = 'details';
1746
+		$this->_template_args['action']                                  = $action;
1747
+		$this->_template_args['context']                                 = $context;
1748
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1749
+		$this->_template_args['learn_more_about_message_templates_link'] =
1750
+			$this->_learn_more_about_message_templates_link();
1751
+        
1752
+        
1753
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1754
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1755
+			$message_template_group,
1756
+			$context,
1757
+			$context_label
1758
+		);
1759
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1760
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1761
+        
1762
+		$this->_template_path = $this->_template_args['GRP_ID']
1763
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1764
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1765
+        
1766
+		//send along EE_Message_Template_Group object for further template use.
1767
+		$this->_template_args['MTP'] = $message_template_group;
1768
+        
1769
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1770
+			$this->_template_path,
1771
+			$this->_template_args,
1772
+			true
1773
+		);
1774
+        
1775
+        
1776
+		//finally, let's set the admin_page title
1777
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1778
+        
1779
+        
1780
+		//we need to take care of setting the shortcodes property for use elsewhere.
1781
+		$this->_set_shortcodes();
1782
+        
1783
+        
1784
+		//final template wrapper
1785
+		$this->display_admin_page_with_sidebar();
1786
+	}
1787 1787
     
1788 1788
     
1789
-    public function filter_tinymce_init($mceInit, $editor_id)
1790
-    {
1791
-        return $mceInit;
1792
-    }
1789
+	public function filter_tinymce_init($mceInit, $editor_id)
1790
+	{
1791
+		return $mceInit;
1792
+	}
1793 1793
     
1794 1794
     
1795
-    public function add_context_switcher()
1796
-    {
1797
-        return $this->_context_switcher;
1798
-    }
1795
+	public function add_context_switcher()
1796
+	{
1797
+		return $this->_context_switcher;
1798
+	}
1799 1799
 
1800 1800
 
1801
-    /**
1802
-     * Adds the activation/deactivation toggle for the message template context.
1803
-     *
1804
-     * @param EE_Message_Template_Group $message_template_group
1805
-     * @param string                    $context
1806
-     * @param string                    $context_label
1807
-     * @return string
1808
-     * @throws DomainException
1809
-     * @throws EE_Error
1810
-     * @throws InvalidIdentifierException
1811
-     */
1812
-    protected function add_active_context_element(
1813
-        EE_Message_Template_Group $message_template_group,
1814
-        $context,
1815
-        $context_label
1816
-    ) {
1817
-        $template_args = array(
1818
-            'context' => $context,
1819
-            'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1820
-            'is_active' => $message_template_group->is_context_active($context),
1821
-            'on_off_action' => $message_template_group->is_context_active($context)
1822
-                ? 'context-off'
1823
-                : 'context-on',
1824
-            'context_label' => str_replace(array('(', ')'), '', $context_label),
1825
-            'message_template_group_id' => $message_template_group->ID()
1826
-        );
1827
-        return EEH_Template::display_template(
1828
-          EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1829
-          $template_args,
1830
-          true
1831
-        );
1832
-    }
1801
+	/**
1802
+	 * Adds the activation/deactivation toggle for the message template context.
1803
+	 *
1804
+	 * @param EE_Message_Template_Group $message_template_group
1805
+	 * @param string                    $context
1806
+	 * @param string                    $context_label
1807
+	 * @return string
1808
+	 * @throws DomainException
1809
+	 * @throws EE_Error
1810
+	 * @throws InvalidIdentifierException
1811
+	 */
1812
+	protected function add_active_context_element(
1813
+		EE_Message_Template_Group $message_template_group,
1814
+		$context,
1815
+		$context_label
1816
+	) {
1817
+		$template_args = array(
1818
+			'context' => $context,
1819
+			'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1820
+			'is_active' => $message_template_group->is_context_active($context),
1821
+			'on_off_action' => $message_template_group->is_context_active($context)
1822
+				? 'context-off'
1823
+				: 'context-on',
1824
+			'context_label' => str_replace(array('(', ')'), '', $context_label),
1825
+			'message_template_group_id' => $message_template_group->ID()
1826
+		);
1827
+		return EEH_Template::display_template(
1828
+		  EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1829
+		  $template_args,
1830
+		  true
1831
+		);
1832
+	}
1833 1833
 
1834 1834
 
1835
-    /**
1836
-     * Ajax callback for `toggle_context_template` ajax action.
1837
-     * Handles toggling the message context on or off.
1838
-     * @throws EE_Error
1839
-     * @throws InvalidArgumentException
1840
-     * @throws InvalidDataTypeException
1841
-     * @throws InvalidIdentifierException
1842
-     * @throws InvalidInterfaceException
1843
-     */
1844
-    public function toggle_context_template()
1845
-    {
1846
-        $success = true;
1847
-        //check for required data
1848
-        if (!isset(
1849
-            $this->_req_data['message_template_group_id'],
1850
-            $this->_req_data['context'],
1851
-            $this->_req_data['status']
1852
-        )) {
1853
-            EE_Error::add_error(
1854
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1855
-                __FILE__,
1856
-                __FUNCTION__,
1857
-                __LINE__
1858
-            );
1859
-            $success = false;
1860
-        }
1835
+	/**
1836
+	 * Ajax callback for `toggle_context_template` ajax action.
1837
+	 * Handles toggling the message context on or off.
1838
+	 * @throws EE_Error
1839
+	 * @throws InvalidArgumentException
1840
+	 * @throws InvalidDataTypeException
1841
+	 * @throws InvalidIdentifierException
1842
+	 * @throws InvalidInterfaceException
1843
+	 */
1844
+	public function toggle_context_template()
1845
+	{
1846
+		$success = true;
1847
+		//check for required data
1848
+		if (!isset(
1849
+			$this->_req_data['message_template_group_id'],
1850
+			$this->_req_data['context'],
1851
+			$this->_req_data['status']
1852
+		)) {
1853
+			EE_Error::add_error(
1854
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1855
+				__FILE__,
1856
+				__FUNCTION__,
1857
+				__LINE__
1858
+			);
1859
+			$success = false;
1860
+		}
1861 1861
 
1862
-        $nonce = isset($this->_req_data['toggle_context_nonce'])
1863
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1864
-            : '';
1865
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1866
-        $this->_verify_nonce($nonce, $nonce_ref);
1867
-        $status = $this->_req_data['status'];
1868
-        if ($status !== 'off' && $status !=='on') {
1869
-            EE_Error::add_error(
1870
-                sprintf(
1871
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1872
-                    $this->_req_data['status']
1873
-                ),
1874
-                __FILE__,
1875
-                __FUNCTION__,
1876
-                __LINE__
1877
-            );
1878
-            $success = false;
1879
-        }
1880
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1881
-            $this->_req_data['message_template_group_id']
1882
-        );
1883
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1884
-            EE_Error::add_error(
1885
-                sprintf(
1886
-                    esc_html__(
1887
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1888
-                        'event_espresso'
1889
-                    ),
1890
-                    $this->_req_data['message_template_group_id'],
1891
-                    'EE_Message_Template_Group'
1892
-                ),
1893
-                __FILE__,
1894
-                __FUNCTION__,
1895
-                __LINE__
1896
-            );
1897
-            $success = false;
1898
-        }
1899
-        if ($success) {
1900
-            $success = $status === 'off'
1901
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1902
-                : $message_template_group->activate_context($this->_req_data['context']);
1903
-        }
1904
-        $this->_template_args['success'] = $success;
1905
-        $this->_return_json();
1906
-    }
1862
+		$nonce = isset($this->_req_data['toggle_context_nonce'])
1863
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1864
+			: '';
1865
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1866
+		$this->_verify_nonce($nonce, $nonce_ref);
1867
+		$status = $this->_req_data['status'];
1868
+		if ($status !== 'off' && $status !=='on') {
1869
+			EE_Error::add_error(
1870
+				sprintf(
1871
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1872
+					$this->_req_data['status']
1873
+				),
1874
+				__FILE__,
1875
+				__FUNCTION__,
1876
+				__LINE__
1877
+			);
1878
+			$success = false;
1879
+		}
1880
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1881
+			$this->_req_data['message_template_group_id']
1882
+		);
1883
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1884
+			EE_Error::add_error(
1885
+				sprintf(
1886
+					esc_html__(
1887
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1888
+						'event_espresso'
1889
+					),
1890
+					$this->_req_data['message_template_group_id'],
1891
+					'EE_Message_Template_Group'
1892
+				),
1893
+				__FILE__,
1894
+				__FUNCTION__,
1895
+				__LINE__
1896
+			);
1897
+			$success = false;
1898
+		}
1899
+		if ($success) {
1900
+			$success = $status === 'off'
1901
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1902
+				: $message_template_group->activate_context($this->_req_data['context']);
1903
+		}
1904
+		$this->_template_args['success'] = $success;
1905
+		$this->_return_json();
1906
+	}
1907 1907
 
1908 1908
 
1909 1909
     
1910
-    public function _add_form_element_before()
1911
-    {
1912
-        return '<form method="post" action="'
1913
-               . $this->_template_args["edit_message_template_form_url"]
1914
-               . '" id="ee-msg-edit-frm">';
1915
-    }
1910
+	public function _add_form_element_before()
1911
+	{
1912
+		return '<form method="post" action="'
1913
+			   . $this->_template_args["edit_message_template_form_url"]
1914
+			   . '" id="ee-msg-edit-frm">';
1915
+	}
1916 1916
     
1917
-    public function _add_form_element_after()
1918
-    {
1919
-        return '</form>';
1920
-    }
1917
+	public function _add_form_element_after()
1918
+	{
1919
+		return '</form>';
1920
+	}
1921 1921
 
1922 1922
 
1923
-    /**
1924
-     * This executes switching the template pack for a message template.
1925
-     *
1926
-     * @since 4.5.0
1927
-     * @throws EE_Error
1928
-     * @throws InvalidDataTypeException
1929
-     * @throws InvalidInterfaceException
1930
-     * @throws InvalidArgumentException
1931
-     * @throws ReflectionException
1932
-     */
1933
-    public function switch_template_pack()
1934
-    {
1935
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1936
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1937
-        
1938
-        //verify we have needed values.
1939
-        if (empty($GRP_ID) || empty($template_pack)) {
1940
-            $this->_template_args['error'] = true;
1941
-            EE_Error::add_error(
1942
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1943
-                __FILE__,
1944
-                __FUNCTION__,
1945
-                __LINE__
1946
-            );
1947
-        } else {
1948
-            //get template, set the new template_pack and then reset to default
1949
-            /** @type EE_Message_Template_Group $message_template_group */
1950
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1923
+	/**
1924
+	 * This executes switching the template pack for a message template.
1925
+	 *
1926
+	 * @since 4.5.0
1927
+	 * @throws EE_Error
1928
+	 * @throws InvalidDataTypeException
1929
+	 * @throws InvalidInterfaceException
1930
+	 * @throws InvalidArgumentException
1931
+	 * @throws ReflectionException
1932
+	 */
1933
+	public function switch_template_pack()
1934
+	{
1935
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1936
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1937
+        
1938
+		//verify we have needed values.
1939
+		if (empty($GRP_ID) || empty($template_pack)) {
1940
+			$this->_template_args['error'] = true;
1941
+			EE_Error::add_error(
1942
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1943
+				__FILE__,
1944
+				__FUNCTION__,
1945
+				__LINE__
1946
+			);
1947
+		} else {
1948
+			//get template, set the new template_pack and then reset to default
1949
+			/** @type EE_Message_Template_Group $message_template_group */
1950
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1951 1951
             
1952
-            $message_template_group->set_template_pack_name($template_pack);
1953
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1954
-            $this->_req_data['mt']   = $message_template_group->message_type();
1952
+			$message_template_group->set_template_pack_name($template_pack);
1953
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1954
+			$this->_req_data['mt']   = $message_template_group->message_type();
1955 1955
             
1956
-            $query_args = $this->_reset_to_default_template();
1956
+			$query_args = $this->_reset_to_default_template();
1957 1957
             
1958
-            if (empty($query_args['id'])) {
1959
-                EE_Error::add_error(
1960
-                    esc_html__(
1961
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1962
-                        'event_espresso'
1963
-                    ),
1964
-                    __FILE__,
1965
-                    __FUNCTION__,
1966
-                    __LINE__
1967
-                );
1968
-                $this->_template_args['error'] = true;
1969
-            } else {
1970
-                $template_label       = $message_template_group->get_template_pack()->label;
1971
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1972
-                EE_Error::add_success(
1973
-                    sprintf(
1974
-                        esc_html__(
1975
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1976
-                            'event_espresso'
1977
-                        ),
1978
-                        $template_label,
1979
-                        $template_pack_labels->template_pack
1980
-                    )
1981
-                );
1982
-                //generate the redirect url for js.
1983
-                $url                                          = self::add_query_args_and_nonce($query_args,
1984
-                    $this->_admin_base_url);
1985
-                $this->_template_args['data']['redirect_url'] = $url;
1986
-                $this->_template_args['success']              = true;
1987
-            }
1958
+			if (empty($query_args['id'])) {
1959
+				EE_Error::add_error(
1960
+					esc_html__(
1961
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1962
+						'event_espresso'
1963
+					),
1964
+					__FILE__,
1965
+					__FUNCTION__,
1966
+					__LINE__
1967
+				);
1968
+				$this->_template_args['error'] = true;
1969
+			} else {
1970
+				$template_label       = $message_template_group->get_template_pack()->label;
1971
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1972
+				EE_Error::add_success(
1973
+					sprintf(
1974
+						esc_html__(
1975
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1976
+							'event_espresso'
1977
+						),
1978
+						$template_label,
1979
+						$template_pack_labels->template_pack
1980
+					)
1981
+				);
1982
+				//generate the redirect url for js.
1983
+				$url                                          = self::add_query_args_and_nonce($query_args,
1984
+					$this->_admin_base_url);
1985
+				$this->_template_args['data']['redirect_url'] = $url;
1986
+				$this->_template_args['success']              = true;
1987
+			}
1988 1988
             
1989
-            $this->_return_json();
1989
+			$this->_return_json();
1990 1990
             
1991
-        }
1992
-    }
1991
+		}
1992
+	}
1993 1993
 
1994 1994
 
1995
-    /**
1996
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1997
-     * they want.
1998
-     *
1999
-     * @access protected
2000
-     * @return array|null
2001
-     * @throws EE_Error
2002
-     * @throws InvalidArgumentException
2003
-     * @throws InvalidDataTypeException
2004
-     * @throws InvalidInterfaceException
2005
-     */
2006
-    protected function _reset_to_default_template()
2007
-    {
2008
-        
2009
-        $templates = array();
2010
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2011
-        //we need to make sure we've got the info we need.
2012
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2013
-            EE_Error::add_error(
2014
-                esc_html__(
2015
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2016
-                    'event_espresso'
2017
-                ),
2018
-                __FILE__, __FUNCTION__, __LINE__
2019
-            );
2020
-        }
2021
-        
2022
-        // all templates will be reset to whatever the defaults are
2023
-        // for the global template matching the messenger and message type.
2024
-        $success = ! empty($GRP_ID) ? true : false;
2025
-        
2026
-        if ($success) {
1995
+	/**
1996
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1997
+	 * they want.
1998
+	 *
1999
+	 * @access protected
2000
+	 * @return array|null
2001
+	 * @throws EE_Error
2002
+	 * @throws InvalidArgumentException
2003
+	 * @throws InvalidDataTypeException
2004
+	 * @throws InvalidInterfaceException
2005
+	 */
2006
+	protected function _reset_to_default_template()
2007
+	{
2008
+        
2009
+		$templates = array();
2010
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2011
+		//we need to make sure we've got the info we need.
2012
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2013
+			EE_Error::add_error(
2014
+				esc_html__(
2015
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2016
+					'event_espresso'
2017
+				),
2018
+				__FILE__, __FUNCTION__, __LINE__
2019
+			);
2020
+		}
2021
+        
2022
+		// all templates will be reset to whatever the defaults are
2023
+		// for the global template matching the messenger and message type.
2024
+		$success = ! empty($GRP_ID) ? true : false;
2025
+        
2026
+		if ($success) {
2027 2027
             
2028
-            //let's first determine if the incoming template is a global template,
2029
-            // if it isn't then we need to get the global template matching messenger and message type.
2030
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2028
+			//let's first determine if the incoming template is a global template,
2029
+			// if it isn't then we need to get the global template matching messenger and message type.
2030
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2031 2031
             
2032 2032
             
2033
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2034
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2033
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2034
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2035 2035
             
2036
-            if ($success) {
2037
-                // if successfully deleted, lets generate the new ones.
2038
-                // Note. We set GLOBAL to true, because resets on ANY template
2039
-                // will use the related global template defaults for regeneration.
2040
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2041
-                // HOWEVER, we DO keep the template pack and template variation set
2042
-                // for the current custom template when resetting.
2043
-                $templates = $this->_generate_new_templates(
2044
-                    $this->_req_data['msgr'],
2045
-                    $this->_req_data['mt'],
2046
-                    $GRP_ID,
2047
-                    true
2048
-                );
2049
-            }
2036
+			if ($success) {
2037
+				// if successfully deleted, lets generate the new ones.
2038
+				// Note. We set GLOBAL to true, because resets on ANY template
2039
+				// will use the related global template defaults for regeneration.
2040
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2041
+				// HOWEVER, we DO keep the template pack and template variation set
2042
+				// for the current custom template when resetting.
2043
+				$templates = $this->_generate_new_templates(
2044
+					$this->_req_data['msgr'],
2045
+					$this->_req_data['mt'],
2046
+					$GRP_ID,
2047
+					true
2048
+				);
2049
+			}
2050 2050
             
2051
-        }
2052
-        
2053
-        //any error messages?
2054
-        if ( ! $success) {
2055
-            EE_Error::add_error(
2056
-                esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2057
-                    'event_espresso'),
2058
-                __FILE__, __FUNCTION__, __LINE__
2059
-            );
2060
-        }
2061
-        
2062
-        //all good, let's add a success message!
2063
-        if ($success && ! empty($templates)) {
2064
-            //the info for the template we generated is the first element in the returned array
2065
-            // $templates = $templates[0];
2066
-            EE_Error::overwrite_success();
2067
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2068
-        }
2069
-        
2070
-        
2071
-        $query_args = array(
2072
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2073
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2074
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2075
-        );
2076
-        
2077
-        //if called via ajax then we return query args otherwise redirect
2078
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2079
-            return $query_args;
2080
-        } else {
2081
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2051
+		}
2052
+        
2053
+		//any error messages?
2054
+		if ( ! $success) {
2055
+			EE_Error::add_error(
2056
+				esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2057
+					'event_espresso'),
2058
+				__FILE__, __FUNCTION__, __LINE__
2059
+			);
2060
+		}
2061
+        
2062
+		//all good, let's add a success message!
2063
+		if ($success && ! empty($templates)) {
2064
+			//the info for the template we generated is the first element in the returned array
2065
+			// $templates = $templates[0];
2066
+			EE_Error::overwrite_success();
2067
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2068
+		}
2069
+        
2070
+        
2071
+		$query_args = array(
2072
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2073
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2074
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2075
+		);
2076
+        
2077
+		//if called via ajax then we return query args otherwise redirect
2078
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2079
+			return $query_args;
2080
+		} else {
2081
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2082 2082
 
2083
-            return null;
2084
-        }
2085
-    }
2083
+			return null;
2084
+		}
2085
+	}
2086 2086
 
2087 2087
 
2088
-    /**
2089
-     * Retrieve and set the message preview for display.
2090
-     *
2091
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2092
-     * @return string
2093
-     * @throws ReflectionException
2094
-     * @throws EE_Error
2095
-     * @throws InvalidArgumentException
2096
-     * @throws InvalidDataTypeException
2097
-     * @throws InvalidInterfaceException
2098
-     */
2099
-    public function _preview_message($send = false)
2100
-    {
2101
-        //first make sure we've got the necessary parameters
2102
-        if (
2103
-        ! isset(
2104
-            $this->_req_data['message_type'],
2105
-            $this->_req_data['messenger'],
2106
-            $this->_req_data['messenger'],
2107
-            $this->_req_data['GRP_ID']
2108
-        )
2109
-        ) {
2110
-            EE_Error::add_error(
2111
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2112
-                __FILE__, __FUNCTION__, __LINE__
2113
-            );
2114
-        }
2115
-        
2116
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2117
-        
2118
-        
2119
-        //get the preview!
2120
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2121
-            $this->_req_data['messenger'], $send);
2122
-        
2123
-        if ($send) {
2124
-            return $preview;
2125
-        }
2126
-        
2127
-        //let's add a button to go back to the edit view
2128
-        $query_args             = array(
2129
-            'id'      => $this->_req_data['GRP_ID'],
2130
-            'context' => $this->_req_data['context'],
2131
-            'action'  => 'edit_message_template'
2132
-        );
2133
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2134
-        $preview_button         = '<a href="'
2135
-                                  . $go_back_url
2136
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2137
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2138
-                                  . '</a>';
2139
-        $message_types          = $this->get_installed_message_types();
2140
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger(
2141
-                $this->_req_data['messenger']
2142
-        );
2143
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2144
-            ? ucwords($active_messenger->label['singular'])
2145
-            : esc_html__('Unknown Messenger', 'event_espresso');
2146
-        //let's provide a helpful title for context
2147
-        $preview_title = sprintf(
2148
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2149
-            $active_messenger_label,
2150
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2151
-        );
2152
-        //setup display of preview.
2153
-        $this->_admin_page_title                    = $preview_title;
2154
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2155
-        $this->_template_args['data']['force_json'] = true;
2156
-        
2157
-        return '';
2158
-    }
2088
+	/**
2089
+	 * Retrieve and set the message preview for display.
2090
+	 *
2091
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2092
+	 * @return string
2093
+	 * @throws ReflectionException
2094
+	 * @throws EE_Error
2095
+	 * @throws InvalidArgumentException
2096
+	 * @throws InvalidDataTypeException
2097
+	 * @throws InvalidInterfaceException
2098
+	 */
2099
+	public function _preview_message($send = false)
2100
+	{
2101
+		//first make sure we've got the necessary parameters
2102
+		if (
2103
+		! isset(
2104
+			$this->_req_data['message_type'],
2105
+			$this->_req_data['messenger'],
2106
+			$this->_req_data['messenger'],
2107
+			$this->_req_data['GRP_ID']
2108
+		)
2109
+		) {
2110
+			EE_Error::add_error(
2111
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2112
+				__FILE__, __FUNCTION__, __LINE__
2113
+			);
2114
+		}
2115
+        
2116
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2117
+        
2118
+        
2119
+		//get the preview!
2120
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2121
+			$this->_req_data['messenger'], $send);
2122
+        
2123
+		if ($send) {
2124
+			return $preview;
2125
+		}
2126
+        
2127
+		//let's add a button to go back to the edit view
2128
+		$query_args             = array(
2129
+			'id'      => $this->_req_data['GRP_ID'],
2130
+			'context' => $this->_req_data['context'],
2131
+			'action'  => 'edit_message_template'
2132
+		);
2133
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2134
+		$preview_button         = '<a href="'
2135
+								  . $go_back_url
2136
+								  . '" class="button-secondary messages-preview-go-back-button">'
2137
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2138
+								  . '</a>';
2139
+		$message_types          = $this->get_installed_message_types();
2140
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger(
2141
+				$this->_req_data['messenger']
2142
+		);
2143
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2144
+			? ucwords($active_messenger->label['singular'])
2145
+			: esc_html__('Unknown Messenger', 'event_espresso');
2146
+		//let's provide a helpful title for context
2147
+		$preview_title = sprintf(
2148
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2149
+			$active_messenger_label,
2150
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2151
+		);
2152
+		//setup display of preview.
2153
+		$this->_admin_page_title                    = $preview_title;
2154
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2155
+		$this->_template_args['data']['force_json'] = true;
2156
+        
2157
+		return '';
2158
+	}
2159 2159
     
2160 2160
     
2161
-    /**
2162
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2163
-     * gets called automatically.
2164
-     *
2165
-     * @since 4.5.0
2166
-     *
2167
-     * @return string
2168
-     */
2169
-    protected function _display_preview_message()
2170
-    {
2171
-        $this->display_admin_page_with_no_sidebar();
2172
-    }
2161
+	/**
2162
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2163
+	 * gets called automatically.
2164
+	 *
2165
+	 * @since 4.5.0
2166
+	 *
2167
+	 * @return string
2168
+	 */
2169
+	protected function _display_preview_message()
2170
+	{
2171
+		$this->display_admin_page_with_no_sidebar();
2172
+	}
2173 2173
     
2174 2174
     
2175
-    /**
2176
-     * registers metaboxes that should show up on the "edit_message_template" page
2177
-     *
2178
-     * @access protected
2179
-     * @return void
2180
-     */
2181
-    protected function _register_edit_meta_boxes()
2182
-    {
2183
-        add_meta_box(
2184
-            'mtp_valid_shortcodes',
2185
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2186
-            array($this, 'shortcode_meta_box'),
2187
-            $this->_current_screen->id,
2188
-            'side',
2189
-            'default');
2190
-        add_meta_box(
2191
-            'mtp_extra_actions',
2192
-            esc_html__('Extra Actions', 'event_espresso'),
2193
-            array($this, 'extra_actions_meta_box'),
2194
-            $this->_current_screen->id,
2195
-            'side',
2196
-            'high'
2197
-        );
2198
-        add_meta_box(
2199
-            'mtp_templates',
2200
-            esc_html__('Template Styles', 'event_espresso'),
2201
-            array($this, 'template_pack_meta_box'),
2202
-            $this->_current_screen->id,
2203
-            'side',
2204
-            'high'
2205
-        );
2206
-    }
2175
+	/**
2176
+	 * registers metaboxes that should show up on the "edit_message_template" page
2177
+	 *
2178
+	 * @access protected
2179
+	 * @return void
2180
+	 */
2181
+	protected function _register_edit_meta_boxes()
2182
+	{
2183
+		add_meta_box(
2184
+			'mtp_valid_shortcodes',
2185
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2186
+			array($this, 'shortcode_meta_box'),
2187
+			$this->_current_screen->id,
2188
+			'side',
2189
+			'default');
2190
+		add_meta_box(
2191
+			'mtp_extra_actions',
2192
+			esc_html__('Extra Actions', 'event_espresso'),
2193
+			array($this, 'extra_actions_meta_box'),
2194
+			$this->_current_screen->id,
2195
+			'side',
2196
+			'high'
2197
+		);
2198
+		add_meta_box(
2199
+			'mtp_templates',
2200
+			esc_html__('Template Styles', 'event_espresso'),
2201
+			array($this, 'template_pack_meta_box'),
2202
+			$this->_current_screen->id,
2203
+			'side',
2204
+			'high'
2205
+		);
2206
+	}
2207 2207
 
2208 2208
 
2209
-    /**
2210
-     * metabox content for all template pack and variation selection.
2211
-     *
2212
-     * @since 4.5.0
2213
-     * @return string
2214
-     * @throws DomainException
2215
-     * @throws EE_Error
2216
-     * @throws InvalidArgumentException
2217
-     * @throws ReflectionException
2218
-     * @throws InvalidDataTypeException
2219
-     * @throws InvalidInterfaceException
2220
-     */
2221
-    public function template_pack_meta_box()
2222
-    {
2223
-        $this->_set_message_template_group();
2224
-        
2225
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2226
-        
2227
-        $tp_select_values = array();
2228
-        
2229
-        foreach ($tp_collection as $tp) {
2230
-            //only include template packs that support this messenger and message type!
2231
-            $supports = $tp->get_supports();
2232
-            if (
2233
-                ! isset($supports[$this->_message_template_group->messenger()])
2234
-                || ! in_array(
2235
-                    $this->_message_template_group->message_type(),
2236
-                    $supports[$this->_message_template_group->messenger()],
2237
-                    true
2238
-                )
2239
-            ) {
2240
-                //not supported
2241
-                continue;
2242
-            }
2209
+	/**
2210
+	 * metabox content for all template pack and variation selection.
2211
+	 *
2212
+	 * @since 4.5.0
2213
+	 * @return string
2214
+	 * @throws DomainException
2215
+	 * @throws EE_Error
2216
+	 * @throws InvalidArgumentException
2217
+	 * @throws ReflectionException
2218
+	 * @throws InvalidDataTypeException
2219
+	 * @throws InvalidInterfaceException
2220
+	 */
2221
+	public function template_pack_meta_box()
2222
+	{
2223
+		$this->_set_message_template_group();
2224
+        
2225
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2226
+        
2227
+		$tp_select_values = array();
2228
+        
2229
+		foreach ($tp_collection as $tp) {
2230
+			//only include template packs that support this messenger and message type!
2231
+			$supports = $tp->get_supports();
2232
+			if (
2233
+				! isset($supports[$this->_message_template_group->messenger()])
2234
+				|| ! in_array(
2235
+					$this->_message_template_group->message_type(),
2236
+					$supports[$this->_message_template_group->messenger()],
2237
+					true
2238
+				)
2239
+			) {
2240
+				//not supported
2241
+				continue;
2242
+			}
2243 2243
             
2244
-            $tp_select_values[] = array(
2245
-                'text' => $tp->label,
2246
-                'id'   => $tp->dbref
2247
-            );
2248
-        }
2249
-        
2250
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2251
-        // the default template pack.  This still allows for the odd template pack to override.
2252
-        if (empty($tp_select_values)) {
2253
-            $tp_select_values[] = array(
2254
-                'text' => esc_html__('Default', 'event_espresso'),
2255
-                'id'   => 'default'
2256
-            );
2257
-        }
2258
-        
2259
-        //setup variation select values for the currently selected template.
2260
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2261
-            $this->_message_template_group->messenger(),
2262
-            $this->_message_template_group->message_type()
2263
-        );
2264
-        $variations_select_values = array();
2265
-        foreach ($variations as $variation => $label) {
2266
-            $variations_select_values[] = array(
2267
-                'text' => $label,
2268
-                'id'   => $variation
2269
-            );
2270
-        }
2271
-        
2272
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2273
-        
2274
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2275
-            'MTP_template_pack',
2276
-            $tp_select_values,
2277
-            $this->_message_template_group->get_template_pack_name()
2278
-        );
2279
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2280
-            'MTP_template_variation',
2281
-            $variations_select_values,
2282
-            $this->_message_template_group->get_template_pack_variation()
2283
-        );
2284
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2285
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2286
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2287
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2288
-        
2289
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2290
-        
2291
-        EEH_Template::display_template($template, $template_args);
2292
-    }
2244
+			$tp_select_values[] = array(
2245
+				'text' => $tp->label,
2246
+				'id'   => $tp->dbref
2247
+			);
2248
+		}
2249
+        
2250
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2251
+		// the default template pack.  This still allows for the odd template pack to override.
2252
+		if (empty($tp_select_values)) {
2253
+			$tp_select_values[] = array(
2254
+				'text' => esc_html__('Default', 'event_espresso'),
2255
+				'id'   => 'default'
2256
+			);
2257
+		}
2258
+        
2259
+		//setup variation select values for the currently selected template.
2260
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2261
+			$this->_message_template_group->messenger(),
2262
+			$this->_message_template_group->message_type()
2263
+		);
2264
+		$variations_select_values = array();
2265
+		foreach ($variations as $variation => $label) {
2266
+			$variations_select_values[] = array(
2267
+				'text' => $label,
2268
+				'id'   => $variation
2269
+			);
2270
+		}
2271
+        
2272
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2273
+        
2274
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2275
+			'MTP_template_pack',
2276
+			$tp_select_values,
2277
+			$this->_message_template_group->get_template_pack_name()
2278
+		);
2279
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2280
+			'MTP_template_variation',
2281
+			$variations_select_values,
2282
+			$this->_message_template_group->get_template_pack_variation()
2283
+		);
2284
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2285
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2286
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2287
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2288
+        
2289
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2290
+        
2291
+		EEH_Template::display_template($template, $template_args);
2292
+	}
2293 2293
     
2294 2294
     
2295
-    /**
2296
-     * This meta box holds any extra actions related to Message Templates
2297
-     * For now, this includes Resetting templates to defaults and sending a test email.
2298
-     *
2299
-     * @access  public
2300
-     * @return void
2301
-     * @throws EE_Error
2302
-     */
2303
-    public function extra_actions_meta_box()
2304
-    {
2305
-        $template_form_fields = array();
2306
-        
2307
-        $extra_args = array(
2308
-            'msgr'   => $this->_message_template_group->messenger(),
2309
-            'mt'     => $this->_message_template_group->message_type(),
2310
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2311
-        );
2312
-        //first we need to see if there are any fields
2313
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2314
-        
2315
-        if ( ! empty($fields)) {
2316
-            //yup there be fields
2317
-            foreach ($fields as $field => $config) {
2318
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2319
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2320
-                $default  = isset($config['default']) ? $config['default'] : '';
2321
-                $default  = isset($config['value']) ? $config['value'] : $default;
2295
+	/**
2296
+	 * This meta box holds any extra actions related to Message Templates
2297
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2298
+	 *
2299
+	 * @access  public
2300
+	 * @return void
2301
+	 * @throws EE_Error
2302
+	 */
2303
+	public function extra_actions_meta_box()
2304
+	{
2305
+		$template_form_fields = array();
2306
+        
2307
+		$extra_args = array(
2308
+			'msgr'   => $this->_message_template_group->messenger(),
2309
+			'mt'     => $this->_message_template_group->message_type(),
2310
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2311
+		);
2312
+		//first we need to see if there are any fields
2313
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2314
+        
2315
+		if ( ! empty($fields)) {
2316
+			//yup there be fields
2317
+			foreach ($fields as $field => $config) {
2318
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2319
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2320
+				$default  = isset($config['default']) ? $config['default'] : '';
2321
+				$default  = isset($config['value']) ? $config['value'] : $default;
2322 2322
                 
2323
-                // if type is hidden and the value is empty
2324
-                // something may have gone wrong so let's correct with the defaults
2325
-                $fix              = $config['input'] === 'hidden'
2326
-                                    && isset($existing[$field])
2327
-                                    && empty($existing[$field])
2328
-                    ? $default
2329
-                    : '';
2330
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2331
-                    ? $existing[$field]
2332
-                    : $fix;
2323
+				// if type is hidden and the value is empty
2324
+				// something may have gone wrong so let's correct with the defaults
2325
+				$fix              = $config['input'] === 'hidden'
2326
+									&& isset($existing[$field])
2327
+									&& empty($existing[$field])
2328
+					? $default
2329
+					: '';
2330
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2331
+					? $existing[$field]
2332
+					: $fix;
2333 2333
                 
2334
-                $template_form_fields[$field_id] = array(
2335
-                    'name'       => 'test_settings_fld[' . $field . ']',
2336
-                    'label'      => $config['label'],
2337
-                    'input'      => $config['input'],
2338
-                    'type'       => $config['type'],
2339
-                    'required'   => $config['required'],
2340
-                    'validation' => $config['validation'],
2341
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2342
-                    'css_class'  => $config['css_class'],
2343
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2344
-                    'default'    => $default,
2345
-                    'format'     => $config['format']
2346
-                );
2347
-            }
2348
-        }
2349
-        
2350
-        $test_settings_fields = ! empty($template_form_fields)
2351
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2352
-            : '';
2353
-        
2354
-        $test_settings_html = '';
2355
-        //print out $test_settings_fields
2356
-        if ( ! empty($test_settings_fields)) {
2357
-            echo $test_settings_fields;
2358
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2359
-            $test_settings_html .= 'name="test_button" value="';
2360
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2361
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2362
-        }
2363
-        
2364
-        //and button
2365
-        $test_settings_html .= '<p>'
2366
-                               . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2367
-                               . '</p>';
2368
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2369
-        $test_settings_html .= $this->get_action_link_or_button(
2370
-            'reset_to_default',
2371
-            'reset',
2372
-            $extra_args,
2373
-            'button-primary reset-default-button'
2374
-        );
2375
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2376
-        echo $test_settings_html;
2377
-    }
2334
+				$template_form_fields[$field_id] = array(
2335
+					'name'       => 'test_settings_fld[' . $field . ']',
2336
+					'label'      => $config['label'],
2337
+					'input'      => $config['input'],
2338
+					'type'       => $config['type'],
2339
+					'required'   => $config['required'],
2340
+					'validation' => $config['validation'],
2341
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2342
+					'css_class'  => $config['css_class'],
2343
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2344
+					'default'    => $default,
2345
+					'format'     => $config['format']
2346
+				);
2347
+			}
2348
+		}
2349
+        
2350
+		$test_settings_fields = ! empty($template_form_fields)
2351
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2352
+			: '';
2353
+        
2354
+		$test_settings_html = '';
2355
+		//print out $test_settings_fields
2356
+		if ( ! empty($test_settings_fields)) {
2357
+			echo $test_settings_fields;
2358
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2359
+			$test_settings_html .= 'name="test_button" value="';
2360
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2361
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2362
+		}
2363
+        
2364
+		//and button
2365
+		$test_settings_html .= '<p>'
2366
+							   . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2367
+							   . '</p>';
2368
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2369
+		$test_settings_html .= $this->get_action_link_or_button(
2370
+			'reset_to_default',
2371
+			'reset',
2372
+			$extra_args,
2373
+			'button-primary reset-default-button'
2374
+		);
2375
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2376
+		echo $test_settings_html;
2377
+	}
2378 2378
 
2379 2379
 
2380
-    /**
2381
-     * This returns the shortcode selector skeleton for a given context and field.
2382
-     *
2383
-     * @since 4.9.rc.000
2384
-     * @param string $field           The name of the field retrieving shortcodes for.
2385
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2386
-     * @return string
2387
-     * @throws DomainException
2388
-     * @throws EE_Error
2389
-     * @throws InvalidArgumentException
2390
-     * @throws ReflectionException
2391
-     * @throws InvalidDataTypeException
2392
-     * @throws InvalidInterfaceException
2393
-     */
2394
-    protected function _get_shortcode_selector($field, $linked_input_id)
2395
-    {
2396
-        $template_args = array(
2397
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2398
-            'fieldname'       => $field,
2399
-            'linked_input_id' => $linked_input_id
2400
-        );
2401
-        
2402
-        return EEH_Template::display_template(
2403
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2404
-            $template_args,
2405
-            true
2406
-        );
2407
-    }
2380
+	/**
2381
+	 * This returns the shortcode selector skeleton for a given context and field.
2382
+	 *
2383
+	 * @since 4.9.rc.000
2384
+	 * @param string $field           The name of the field retrieving shortcodes for.
2385
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2386
+	 * @return string
2387
+	 * @throws DomainException
2388
+	 * @throws EE_Error
2389
+	 * @throws InvalidArgumentException
2390
+	 * @throws ReflectionException
2391
+	 * @throws InvalidDataTypeException
2392
+	 * @throws InvalidInterfaceException
2393
+	 */
2394
+	protected function _get_shortcode_selector($field, $linked_input_id)
2395
+	{
2396
+		$template_args = array(
2397
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2398
+			'fieldname'       => $field,
2399
+			'linked_input_id' => $linked_input_id
2400
+		);
2401
+        
2402
+		return EEH_Template::display_template(
2403
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2404
+			$template_args,
2405
+			true
2406
+		);
2407
+	}
2408 2408
 
2409 2409
 
2410
-    /**
2411
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2412
-     * page)
2413
-     *
2414
-     * @access public
2415
-     * @return void
2416
-     * @throws EE_Error
2417
-     * @throws InvalidArgumentException
2418
-     * @throws ReflectionException
2419
-     * @throws InvalidDataTypeException
2420
-     * @throws InvalidInterfaceException
2421
-     */
2422
-    public function shortcode_meta_box()
2423
-    {
2424
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2425
-        //$messenger = $this->_message_template_group->messenger_obj();
2426
-        //now let's set the content depending on the status of the shortcodes array
2427
-        if (empty($shortcodes)) {
2428
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2429
-            echo $content;
2430
-        } else {
2431
-            //$alt = 0;
2432
-            ?>
2410
+	/**
2411
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2412
+	 * page)
2413
+	 *
2414
+	 * @access public
2415
+	 * @return void
2416
+	 * @throws EE_Error
2417
+	 * @throws InvalidArgumentException
2418
+	 * @throws ReflectionException
2419
+	 * @throws InvalidDataTypeException
2420
+	 * @throws InvalidInterfaceException
2421
+	 */
2422
+	public function shortcode_meta_box()
2423
+	{
2424
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2425
+		//$messenger = $this->_message_template_group->messenger_obj();
2426
+		//now let's set the content depending on the status of the shortcodes array
2427
+		if (empty($shortcodes)) {
2428
+			$content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2429
+			echo $content;
2430
+		} else {
2431
+			//$alt = 0;
2432
+			?>
2433 2433
             <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2434 2434
             <p class="small-text"><?php printf(
2435
-                    esc_html__(
2436
-                        'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2437
-                        'event_espresso'
2438
-                    ),
2439
-                    '<span class="dashicons dashicons-menu"></span>'
2440
-                ); ?></p>
2435
+					esc_html__(
2436
+						'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2437
+						'event_espresso'
2438
+					),
2439
+					'<span class="dashicons dashicons-menu"></span>'
2440
+				); ?></p>
2441 2441
             <?php
2442
-        }
2442
+		}
2443 2443
         
2444 2444
         
2445
-    }
2445
+	}
2446 2446
 
2447 2447
 
2448
-    /**
2449
-     * used to set the $_shortcodes property for when its needed elsewhere.
2450
-     *
2451
-     * @access protected
2452
-     * @return void
2453
-     * @throws EE_Error
2454
-     * @throws InvalidArgumentException
2455
-     * @throws ReflectionException
2456
-     * @throws InvalidDataTypeException
2457
-     * @throws InvalidInterfaceException
2458
-     */
2459
-    protected function _set_shortcodes()
2460
-    {
2461
-        
2462
-        //no need to run this if the property is already set
2463
-        if ( ! empty($this->_shortcodes)) {
2464
-            return;
2465
-        }
2466
-        
2467
-        $this->_shortcodes = $this->_get_shortcodes();
2468
-    }
2448
+	/**
2449
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2450
+	 *
2451
+	 * @access protected
2452
+	 * @return void
2453
+	 * @throws EE_Error
2454
+	 * @throws InvalidArgumentException
2455
+	 * @throws ReflectionException
2456
+	 * @throws InvalidDataTypeException
2457
+	 * @throws InvalidInterfaceException
2458
+	 */
2459
+	protected function _set_shortcodes()
2460
+	{
2461
+        
2462
+		//no need to run this if the property is already set
2463
+		if ( ! empty($this->_shortcodes)) {
2464
+			return;
2465
+		}
2466
+        
2467
+		$this->_shortcodes = $this->_get_shortcodes();
2468
+	}
2469 2469
 
2470 2470
 
2471
-    /**
2472
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2473
-     * property)
2474
-     *
2475
-     * @access  protected
2476
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2477
-     *                         for. Defaults to all (for the given context)
2478
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2479
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2480
-     *                         true just an array of shortcode/label pairs.
2481
-     * @throws EE_Error
2482
-     * @throws InvalidArgumentException
2483
-     * @throws ReflectionException
2484
-     * @throws InvalidDataTypeException
2485
-     * @throws InvalidInterfaceException
2486
-     */
2487
-    protected function _get_shortcodes($fields = array(), $merged = true)
2488
-    {
2489
-        $this->_set_message_template_group();
2490
-        
2491
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2492
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2493
-            ? absint($this->_req_data['id'])
2494
-            : false;
2495
-        $context = isset($this->_req_data['context'])
2496
-            ? $this->_req_data['context']
2497
-            : key($this->_message_template_group->contexts_config());
2498
-        
2499
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2500
-    }
2471
+	/**
2472
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2473
+	 * property)
2474
+	 *
2475
+	 * @access  protected
2476
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2477
+	 *                         for. Defaults to all (for the given context)
2478
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2479
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2480
+	 *                         true just an array of shortcode/label pairs.
2481
+	 * @throws EE_Error
2482
+	 * @throws InvalidArgumentException
2483
+	 * @throws ReflectionException
2484
+	 * @throws InvalidDataTypeException
2485
+	 * @throws InvalidInterfaceException
2486
+	 */
2487
+	protected function _get_shortcodes($fields = array(), $merged = true)
2488
+	{
2489
+		$this->_set_message_template_group();
2490
+        
2491
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2492
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2493
+			? absint($this->_req_data['id'])
2494
+			: false;
2495
+		$context = isset($this->_req_data['context'])
2496
+			? $this->_req_data['context']
2497
+			: key($this->_message_template_group->contexts_config());
2498
+        
2499
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2500
+	}
2501 2501
 
2502 2502
 
2503
-    /**
2504
-     * This sets the _message_template property (containing the called message_template object)
2505
-     *
2506
-     * @access protected
2507
-     * @return void
2508
-     * @throws EE_Error
2509
-     * @throws InvalidArgumentException
2510
-     * @throws ReflectionException
2511
-     * @throws InvalidDataTypeException
2512
-     * @throws InvalidInterfaceException
2513
-     */
2514
-    protected function _set_message_template_group()
2515
-    {
2516
-        
2517
-        if ( ! empty($this->_message_template_group)) {
2518
-            return;
2519
-        } //get out if this is already set.
2520
-        
2521
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2522
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2523
-        
2524
-        //let's get the message templates
2525
-        $MTP = EEM_Message_Template_Group::instance();
2526
-        
2527
-        if (empty($GRP_ID)) {
2528
-            $this->_message_template_group = $MTP->create_default_object();
2529
-        } else {
2530
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2531
-        }
2532
-        
2533
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2534
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2535
-        
2536
-    }
2503
+	/**
2504
+	 * This sets the _message_template property (containing the called message_template object)
2505
+	 *
2506
+	 * @access protected
2507
+	 * @return void
2508
+	 * @throws EE_Error
2509
+	 * @throws InvalidArgumentException
2510
+	 * @throws ReflectionException
2511
+	 * @throws InvalidDataTypeException
2512
+	 * @throws InvalidInterfaceException
2513
+	 */
2514
+	protected function _set_message_template_group()
2515
+	{
2516
+        
2517
+		if ( ! empty($this->_message_template_group)) {
2518
+			return;
2519
+		} //get out if this is already set.
2520
+        
2521
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2522
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2523
+        
2524
+		//let's get the message templates
2525
+		$MTP = EEM_Message_Template_Group::instance();
2526
+        
2527
+		if (empty($GRP_ID)) {
2528
+			$this->_message_template_group = $MTP->create_default_object();
2529
+		} else {
2530
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2531
+		}
2532
+        
2533
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2534
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2535
+        
2536
+	}
2537 2537
 
2538 2538
 
2539
-    /**
2540
-     * sets up a context switcher for edit forms
2541
-     *
2542
-     * @access  protected
2543
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2544
-     * @param array                      $args                  various things the context switcher needs.
2545
-     * @throws EE_Error
2546
-     */
2547
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2548
-    {
2549
-        $context_details = $template_group_object->contexts_config();
2550
-        $context_label   = $template_group_object->context_label();
2551
-        ob_start();
2552
-        ?>
2539
+	/**
2540
+	 * sets up a context switcher for edit forms
2541
+	 *
2542
+	 * @access  protected
2543
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2544
+	 * @param array                      $args                  various things the context switcher needs.
2545
+	 * @throws EE_Error
2546
+	 */
2547
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2548
+	{
2549
+		$context_details = $template_group_object->contexts_config();
2550
+		$context_label   = $template_group_object->context_label();
2551
+		ob_start();
2552
+		?>
2553 2553
         <div class="ee-msg-switcher-container">
2554 2554
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2555 2555
                 <?php
2556
-                foreach ($args as $name => $value) {
2557
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2558
-                        continue;
2559
-                    }
2560
-                    ?>
2556
+				foreach ($args as $name => $value) {
2557
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2558
+						continue;
2559
+					}
2560
+					?>
2561 2561
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2562 2562
                     <?php
2563
-                }
2564
-                //setup nonce_url
2565
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2566
-                ?>
2563
+				}
2564
+				//setup nonce_url
2565
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2566
+				?>
2567 2567
                 <select name="context">
2568 2568
                     <?php
2569
-                    $context_templates = $template_group_object->context_templates();
2570
-                    if (is_array($context_templates)) :
2571
-                        foreach ($context_templates as $context => $template_fields) :
2572
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2573
-                            ?>
2569
+					$context_templates = $template_group_object->context_templates();
2570
+					if (is_array($context_templates)) :
2571
+						foreach ($context_templates as $context => $template_fields) :
2572
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2573
+							?>
2574 2574
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2575 2575
                                 <?php echo $context_details[$context]['label']; ?>
2576 2576
                             </option>
@@ -2583,1898 +2583,1898 @@  discard block
 block discarded – undo
2583 2583
             <?php echo $args['extra']; ?>
2584 2584
         </div> <!-- end .ee-msg-switcher-container -->
2585 2585
         <?php
2586
-        $output = ob_get_contents();
2587
-        ob_clean();
2588
-        $this->_context_switcher = $output;
2589
-    }
2586
+		$output = ob_get_contents();
2587
+		ob_clean();
2588
+		$this->_context_switcher = $output;
2589
+	}
2590 2590
     
2591 2591
     
2592
-    /**
2593
-     * utility for sanitizing new values coming in.
2594
-     * Note: this is only used when updating a context.
2595
-     *
2596
-     * @access protected
2597
-     *
2598
-     * @param int $index This helps us know which template field to select from the request array.
2599
-     *
2600
-     * @return array
2601
-     */
2602
-    protected function _set_message_template_column_values($index)
2603
-    {
2604
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2605
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2606
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2607
-            }
2608
-        }
2609
-        
2610
-        
2611
-        $set_column_values = array(
2612
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2613
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2614
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2615
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2616
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2617
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2618
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2619
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2620
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2621
-                ? absint($this->_req_data['MTP_is_global'])
2622
-                : 0,
2623
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2624
-                ? absint($this->_req_data['MTP_is_override'])
2625
-                : 0,
2626
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2627
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2628
-        );
2629
-        
2630
-        
2631
-        return $set_column_values;
2632
-    }
2592
+	/**
2593
+	 * utility for sanitizing new values coming in.
2594
+	 * Note: this is only used when updating a context.
2595
+	 *
2596
+	 * @access protected
2597
+	 *
2598
+	 * @param int $index This helps us know which template field to select from the request array.
2599
+	 *
2600
+	 * @return array
2601
+	 */
2602
+	protected function _set_message_template_column_values($index)
2603
+	{
2604
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2605
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2606
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2607
+			}
2608
+		}
2609
+        
2610
+        
2611
+		$set_column_values = array(
2612
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2613
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2614
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2615
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2616
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2617
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2618
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2619
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2620
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2621
+				? absint($this->_req_data['MTP_is_global'])
2622
+				: 0,
2623
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2624
+				? absint($this->_req_data['MTP_is_override'])
2625
+				: 0,
2626
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2627
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2628
+		);
2629
+        
2630
+        
2631
+		return $set_column_values;
2632
+	}
2633 2633
     
2634 2634
     
2635
-    protected function _insert_or_update_message_template($new = false)
2636
-    {
2637
-        
2638
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2639
-        $success  = 0;
2640
-        $override = false;
2641
-        
2642
-        //setup notices description
2643
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2644
-        
2645
-        //need the message type and messenger objects to be able to use the labels for the notices
2646
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2647
-        $messenger_label  = $messenger_object instanceof EE_messenger
2648
-            ? ucwords($messenger_object->label['singular'])
2649
-            : '';
2650
-        
2651
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2652
-            ? $this->_req_data['MTP_message_type']
2653
-            : '';
2654
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2655
-        
2656
-        $message_type_label = $message_type_object instanceof EE_message_type
2657
-            ? ucwords($message_type_object->label['singular'])
2658
-            : '';
2659
-        
2660
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2661
-            ? $this->_req_data['MTP_context']
2662
-            : '';
2663
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2664
-        
2665
-        $item_desc = $messenger_label && $message_type_label
2666
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2667
-            : '';
2668
-        $item_desc .= 'Message Template';
2669
-        $query_args  = array();
2670
-        $edit_array  = array();
2671
-        $action_desc = '';
2672
-        
2673
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2674
-        // user to edit.
2675
-        if ($new) {
2676
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2677
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2678
-                if (empty($edit_array)) {
2679
-                    $success = 0;
2680
-                } else {
2681
-                    $success    = 1;
2682
-                    $edit_array = $edit_array[0];
2683
-                    $query_args = array(
2684
-                        'id'      => $edit_array['GRP_ID'],
2685
-                        'context' => $edit_array['MTP_context'],
2686
-                        'action'  => 'edit_message_template'
2687
-                    );
2688
-                }
2689
-            }
2690
-            $action_desc = 'created';
2691
-        } else {
2692
-            $MTPG = EEM_Message_Template_Group::instance();
2693
-            $MTP  = EEM_Message_Template::instance();
2635
+	protected function _insert_or_update_message_template($new = false)
2636
+	{
2637
+        
2638
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2639
+		$success  = 0;
2640
+		$override = false;
2641
+        
2642
+		//setup notices description
2643
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2644
+        
2645
+		//need the message type and messenger objects to be able to use the labels for the notices
2646
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2647
+		$messenger_label  = $messenger_object instanceof EE_messenger
2648
+			? ucwords($messenger_object->label['singular'])
2649
+			: '';
2650
+        
2651
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2652
+			? $this->_req_data['MTP_message_type']
2653
+			: '';
2654
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2655
+        
2656
+		$message_type_label = $message_type_object instanceof EE_message_type
2657
+			? ucwords($message_type_object->label['singular'])
2658
+			: '';
2659
+        
2660
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2661
+			? $this->_req_data['MTP_context']
2662
+			: '';
2663
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2664
+        
2665
+		$item_desc = $messenger_label && $message_type_label
2666
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2667
+			: '';
2668
+		$item_desc .= 'Message Template';
2669
+		$query_args  = array();
2670
+		$edit_array  = array();
2671
+		$action_desc = '';
2672
+        
2673
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2674
+		// user to edit.
2675
+		if ($new) {
2676
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2677
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2678
+				if (empty($edit_array)) {
2679
+					$success = 0;
2680
+				} else {
2681
+					$success    = 1;
2682
+					$edit_array = $edit_array[0];
2683
+					$query_args = array(
2684
+						'id'      => $edit_array['GRP_ID'],
2685
+						'context' => $edit_array['MTP_context'],
2686
+						'action'  => 'edit_message_template'
2687
+					);
2688
+				}
2689
+			}
2690
+			$action_desc = 'created';
2691
+		} else {
2692
+			$MTPG = EEM_Message_Template_Group::instance();
2693
+			$MTP  = EEM_Message_Template::instance();
2694 2694
             
2695 2695
             
2696
-            //run update for each template field in displayed context
2697
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2698
-                EE_Error::add_error(
2699
-                    esc_html__(
2700
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2701
-                        'event_espresso'
2702
-                    ),
2703
-                    __FILE__,
2704
-                    __FUNCTION__,
2705
-                    __LINE__
2706
-                );
2707
-                $success = 0;
2696
+			//run update for each template field in displayed context
2697
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2698
+				EE_Error::add_error(
2699
+					esc_html__(
2700
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2701
+						'event_espresso'
2702
+					),
2703
+					__FILE__,
2704
+					__FUNCTION__,
2705
+					__LINE__
2706
+				);
2707
+				$success = 0;
2708 2708
                 
2709
-            } else {
2710
-                //first validate all fields!
2711
-                // this filter allows client code to add its own validation to the template fields as well.
2712
-                // returning an empty array means everything passed validation.
2713
-                // errors in validation should be represented in an array with the following shape:
2714
-                // array(
2715
-                //   'fieldname' => array(
2716
-                //          'msg' => 'error message'
2717
-                //          'value' => 'value for field producing error'
2718
-                // )
2719
-                $custom_validation = (array) apply_filters(
2720
-                    'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2721
-                    array(),
2722
-                    $this->_req_data['MTP_template_fields'],
2723
-                    $context_slug,
2724
-                    $messenger_slug,
2725
-                    $message_type_slug
2726
-                );
2709
+			} else {
2710
+				//first validate all fields!
2711
+				// this filter allows client code to add its own validation to the template fields as well.
2712
+				// returning an empty array means everything passed validation.
2713
+				// errors in validation should be represented in an array with the following shape:
2714
+				// array(
2715
+				//   'fieldname' => array(
2716
+				//          'msg' => 'error message'
2717
+				//          'value' => 'value for field producing error'
2718
+				// )
2719
+				$custom_validation = (array) apply_filters(
2720
+					'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2721
+					array(),
2722
+					$this->_req_data['MTP_template_fields'],
2723
+					$context_slug,
2724
+					$messenger_slug,
2725
+					$message_type_slug
2726
+				);
2727 2727
 
2728
-                $system_validation = $MTPG->validate(
2729
-                    $this->_req_data['MTP_template_fields'],
2730
-                    $context_slug,
2731
-                    $messenger_slug,
2732
-                    $message_type_slug
2733
-                );
2728
+				$system_validation = $MTPG->validate(
2729
+					$this->_req_data['MTP_template_fields'],
2730
+					$context_slug,
2731
+					$messenger_slug,
2732
+					$message_type_slug
2733
+				);
2734 2734
 
2735
-                $system_validation = ! is_array($system_validation) && $system_validation ? array() : $system_validation;
2736
-                $validates = array_merge($custom_validation, $system_validation);
2735
+				$system_validation = ! is_array($system_validation) && $system_validation ? array() : $system_validation;
2736
+				$validates = array_merge($custom_validation, $system_validation);
2737 2737
                 
2738
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2739
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2740
-                //  WE need to make sure there is no actual error messages in validates.
2741
-                if (is_array($validates) && ! empty($validates)) {
2742
-                    //add the transient so when the form loads we know which fields to highlight
2743
-                    $this->_add_transient('edit_message_template', $validates);
2738
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2739
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2740
+				//  WE need to make sure there is no actual error messages in validates.
2741
+				if (is_array($validates) && ! empty($validates)) {
2742
+					//add the transient so when the form loads we know which fields to highlight
2743
+					$this->_add_transient('edit_message_template', $validates);
2744 2744
                     
2745
-                    $success = 0;
2745
+					$success = 0;
2746 2746
                     
2747
-                    //setup notices
2748
-                    foreach ($validates as $field => $error) {
2749
-                        if (isset($error['msg'])) {
2750
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2751
-                        }
2752
-                    }
2747
+					//setup notices
2748
+					foreach ($validates as $field => $error) {
2749
+						if (isset($error['msg'])) {
2750
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2751
+						}
2752
+					}
2753 2753
                     
2754
-                } else {
2755
-                    $set_column_values = array();
2756
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2757
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2754
+				} else {
2755
+					$set_column_values = array();
2756
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2757
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2758 2758
                         
2759
-                        $where_cols_n_values = array(
2760
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2761
-                        );
2762
-                        //if they aren't allowed to use all JS, restrict them to just posty-y tags
2763
-                        if (! current_user_can('unfiltered_html')){
2764
-                            if (is_array($set_column_values['MTP_content'])){
2765
-                                 foreach($set_column_values['MTP_content'] as $key => $value) {
2766
-                                     //remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2767
-                                     //only removes slashes from double-quotes, so attributes using single quotes always
2768
-                                     //appear invalid.) But currently the models expect slashed data, so after wp_kses
2769
-                                     //runs we need to re-slash the data. Sheesh. See
2770
-                                     //https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2771
-                                     $set_column_values['MTP_content'][$key] = addslashes(
2772
-                                             wp_kses(
2773
-                                                 stripslashes($value),
2774
-                                                 wp_kses_allowed_html('post')
2775
-                                             )
2776
-                                     );
2777
-                                 }
2778
-                            } else {
2779
-                                $set_column_values['MTP_content'] = wp_kses(
2780
-                                    $set_column_values['MTP_content'],
2781
-                                    wp_kses_allowed_html('post')
2782
-                                );
2783
-                            }
2784
-                        }
2785
-                        $message_template_fields = array(
2786
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2787
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2788
-                            'MTP_context'        => $set_column_values['MTP_context'],
2789
-                            'MTP_content'        => $set_column_values['MTP_content']
2790
-                        );
2791
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2792
-                            if ($updated === false) {
2793
-                                EE_Error::add_error(
2794
-                                    sprintf(
2795
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2796
-                                        $template_field
2797
-                                    ),
2798
-                                    __FILE__,
2799
-                                    __FUNCTION__,
2800
-                                    __LINE__
2801
-                                );
2802
-                            } else {
2803
-                                $success = 1;
2804
-                            }
2805
-                        } else {
2806
-                            //only do this logic if we don't have a MTP_ID for this field
2807
-                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2808
-                                //this has already been through the template field validator and sanitized, so it will be
2809
-                                //safe to insert this field.  Why insert?  This typically happens when we introduce a new
2810
-                                //message template field in a messenger/message type and existing users don't have the
2811
-                                //default setup for it.
2812
-                                //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2813
-                                $updated = $MTP->insert($message_template_fields);
2814
-                                if (! $updated || is_wp_error($updated)) {
2815
-                                    EE_Error::add_error(
2816
-                                        sprintf(
2817
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2818
-                                            $template_field
2819
-                                        ),
2820
-                                        __FILE__,
2821
-                                        __FUNCTION__,
2822
-                                        __LINE__
2823
-                                    );
2824
-                                    $success = 0;
2825
-                                } else {
2826
-                                    $success = 1;
2827
-                                }
2828
-                            }
2829
-                        }
2830
-                        $action_desc = 'updated';
2831
-                    }
2759
+						$where_cols_n_values = array(
2760
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2761
+						);
2762
+						//if they aren't allowed to use all JS, restrict them to just posty-y tags
2763
+						if (! current_user_can('unfiltered_html')){
2764
+							if (is_array($set_column_values['MTP_content'])){
2765
+								 foreach($set_column_values['MTP_content'] as $key => $value) {
2766
+									 //remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2767
+									 //only removes slashes from double-quotes, so attributes using single quotes always
2768
+									 //appear invalid.) But currently the models expect slashed data, so after wp_kses
2769
+									 //runs we need to re-slash the data. Sheesh. See
2770
+									 //https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2771
+									 $set_column_values['MTP_content'][$key] = addslashes(
2772
+											 wp_kses(
2773
+												 stripslashes($value),
2774
+												 wp_kses_allowed_html('post')
2775
+											 )
2776
+									 );
2777
+								 }
2778
+							} else {
2779
+								$set_column_values['MTP_content'] = wp_kses(
2780
+									$set_column_values['MTP_content'],
2781
+									wp_kses_allowed_html('post')
2782
+								);
2783
+							}
2784
+						}
2785
+						$message_template_fields = array(
2786
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2787
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2788
+							'MTP_context'        => $set_column_values['MTP_context'],
2789
+							'MTP_content'        => $set_column_values['MTP_content']
2790
+						);
2791
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2792
+							if ($updated === false) {
2793
+								EE_Error::add_error(
2794
+									sprintf(
2795
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2796
+										$template_field
2797
+									),
2798
+									__FILE__,
2799
+									__FUNCTION__,
2800
+									__LINE__
2801
+								);
2802
+							} else {
2803
+								$success = 1;
2804
+							}
2805
+						} else {
2806
+							//only do this logic if we don't have a MTP_ID for this field
2807
+							if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2808
+								//this has already been through the template field validator and sanitized, so it will be
2809
+								//safe to insert this field.  Why insert?  This typically happens when we introduce a new
2810
+								//message template field in a messenger/message type and existing users don't have the
2811
+								//default setup for it.
2812
+								//@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2813
+								$updated = $MTP->insert($message_template_fields);
2814
+								if (! $updated || is_wp_error($updated)) {
2815
+									EE_Error::add_error(
2816
+										sprintf(
2817
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2818
+											$template_field
2819
+										),
2820
+										__FILE__,
2821
+										__FUNCTION__,
2822
+										__LINE__
2823
+									);
2824
+									$success = 0;
2825
+								} else {
2826
+									$success = 1;
2827
+								}
2828
+							}
2829
+						}
2830
+						$action_desc = 'updated';
2831
+					}
2832 2832
                     
2833
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2834
-                    $mtpg_fields = array(
2835
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2836
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2837
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2838
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2839
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2840
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2841
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2842
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2843
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2844
-                            : '',
2845
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2846
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2847
-                            : ''
2848
-                    );
2833
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2834
+					$mtpg_fields = array(
2835
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2836
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2837
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2838
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2839
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2840
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2841
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2842
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2843
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2844
+							: '',
2845
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2846
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2847
+							: ''
2848
+					);
2849 2849
                     
2850
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2851
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2850
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2851
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2852 2852
                     
2853
-                    if ($updated === false) {
2854
-                        EE_Error::add_error(
2855
-                            sprintf(
2856
-                                esc_html__(
2857
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2858
-                                    'event_espresso'
2859
-                                ),
2860
-                                $set_column_values['GRP_ID']
2861
-                            ),
2862
-                            __FILE__,
2863
-                            __FUNCTION__,
2864
-                            __LINE__
2865
-                        );
2866
-                    } else {
2867
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2868
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2869
-                            ? $this->_req_data['MTP_template_pack']
2870
-                            : 'default';
2853
+					if ($updated === false) {
2854
+						EE_Error::add_error(
2855
+							sprintf(
2856
+								esc_html__(
2857
+									'The Message Template Group (%d) was NOT updated for some reason',
2858
+									'event_espresso'
2859
+								),
2860
+								$set_column_values['GRP_ID']
2861
+							),
2862
+							__FILE__,
2863
+							__FUNCTION__,
2864
+							__LINE__
2865
+						);
2866
+					} else {
2867
+						//k now we need to ensure the template_pack and template_variation fields are set.
2868
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2869
+							? $this->_req_data['MTP_template_pack']
2870
+							: 'default';
2871 2871
                         
2872
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2873
-                            ? $this->_req_data['MTP_template_variation']
2874
-                            : 'default';
2872
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2873
+							? $this->_req_data['MTP_template_variation']
2874
+							: 'default';
2875 2875
                         
2876
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2877
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2878
-                            $mtpg_obj->set_template_pack_name($template_pack);
2879
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2880
-                        }
2881
-                        $success = 1;
2882
-                    }
2883
-                }
2884
-            }
2876
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2877
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2878
+							$mtpg_obj->set_template_pack_name($template_pack);
2879
+							$mtpg_obj->set_template_pack_variation($template_variation);
2880
+						}
2881
+						$success = 1;
2882
+					}
2883
+				}
2884
+			}
2885 2885
             
2886
-        }
2887
-        
2888
-        //we return things differently if doing ajax
2889
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2890
-            $this->_template_args['success'] = $success;
2891
-            $this->_template_args['error']   = ! $success ? true : false;
2892
-            $this->_template_args['content'] = '';
2893
-            $this->_template_args['data']    = array(
2894
-                'grpID'        => $edit_array['GRP_ID'],
2895
-                'templateName' => $edit_array['template_name']
2896
-            );
2897
-            if ($success) {
2898
-                EE_Error::overwrite_success();
2899
-                EE_Error::add_success(
2900
-                    esc_html__(
2901
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2902
-                        'event_espresso'
2903
-                    )
2904
-                );
2905
-            }
2886
+		}
2887
+        
2888
+		//we return things differently if doing ajax
2889
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2890
+			$this->_template_args['success'] = $success;
2891
+			$this->_template_args['error']   = ! $success ? true : false;
2892
+			$this->_template_args['content'] = '';
2893
+			$this->_template_args['data']    = array(
2894
+				'grpID'        => $edit_array['GRP_ID'],
2895
+				'templateName' => $edit_array['template_name']
2896
+			);
2897
+			if ($success) {
2898
+				EE_Error::overwrite_success();
2899
+				EE_Error::add_success(
2900
+					esc_html__(
2901
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2902
+						'event_espresso'
2903
+					)
2904
+				);
2905
+			}
2906 2906
             
2907
-            $this->_return_json();
2908
-        }
2909
-        
2910
-        
2911
-        //was a test send triggered?
2912
-        if (isset($this->_req_data['test_button'])) {
2913
-            EE_Error::overwrite_success();
2914
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2915
-            $override = true;
2916
-        }
2917
-        
2918
-        if (empty($query_args)) {
2919
-            $query_args = array(
2920
-                'id'      => $this->_req_data['GRP_ID'],
2921
-                'context' => $context_slug,
2922
-                'action'  => 'edit_message_template'
2923
-            );
2924
-        }
2925
-        
2926
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2927
-    }
2907
+			$this->_return_json();
2908
+		}
2909
+        
2910
+        
2911
+		//was a test send triggered?
2912
+		if (isset($this->_req_data['test_button'])) {
2913
+			EE_Error::overwrite_success();
2914
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2915
+			$override = true;
2916
+		}
2917
+        
2918
+		if (empty($query_args)) {
2919
+			$query_args = array(
2920
+				'id'      => $this->_req_data['GRP_ID'],
2921
+				'context' => $context_slug,
2922
+				'action'  => 'edit_message_template'
2923
+			);
2924
+		}
2925
+        
2926
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2927
+	}
2928 2928
 
2929 2929
 
2930
-    /**
2931
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2932
-     *
2933
-     * @param  string $context      what context being tested
2934
-     * @param  string $messenger    messenger being tested
2935
-     * @param  string $message_type message type being tested
2936
-     * @throws EE_Error
2937
-     * @throws InvalidArgumentException
2938
-     * @throws InvalidDataTypeException
2939
-     * @throws InvalidInterfaceException
2940
-     */
2941
-    protected function _do_test_send($context, $messenger, $message_type)
2942
-    {
2943
-        //set things up for preview
2944
-        $this->_req_data['messenger']    = $messenger;
2945
-        $this->_req_data['message_type'] = $message_type;
2946
-        $this->_req_data['context']      = $context;
2947
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2948
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2949
-        
2950
-        //let's save any existing fields that might be required by the messenger
2951
-        if (
2952
-            isset($this->_req_data['test_settings_fld'])
2953
-            && $active_messenger instanceof EE_messenger
2954
-            && apply_filters(
2955
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2956
-                true,
2957
-                $this->_req_data['test_settings_fld'],
2958
-                $active_messenger
2959
-            )
2960
-        ) {
2961
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2962
-        }
2930
+	/**
2931
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2932
+	 *
2933
+	 * @param  string $context      what context being tested
2934
+	 * @param  string $messenger    messenger being tested
2935
+	 * @param  string $message_type message type being tested
2936
+	 * @throws EE_Error
2937
+	 * @throws InvalidArgumentException
2938
+	 * @throws InvalidDataTypeException
2939
+	 * @throws InvalidInterfaceException
2940
+	 */
2941
+	protected function _do_test_send($context, $messenger, $message_type)
2942
+	{
2943
+		//set things up for preview
2944
+		$this->_req_data['messenger']    = $messenger;
2945
+		$this->_req_data['message_type'] = $message_type;
2946
+		$this->_req_data['context']      = $context;
2947
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2948
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2949
+        
2950
+		//let's save any existing fields that might be required by the messenger
2951
+		if (
2952
+			isset($this->_req_data['test_settings_fld'])
2953
+			&& $active_messenger instanceof EE_messenger
2954
+			&& apply_filters(
2955
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2956
+				true,
2957
+				$this->_req_data['test_settings_fld'],
2958
+				$active_messenger
2959
+			)
2960
+		) {
2961
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2962
+		}
2963 2963
 
2964
-        /**
2965
-         * Use filter to add additional controls on whether message can send or not
2966
-         */
2967
-        if (apply_filters(
2968
-            'FHEE__Messages_Admin_Page__do_test_send__can_send',
2969
-            true,
2970
-            $context,
2971
-            $this->_req_data,
2972
-            $messenger,
2973
-            $message_type
2974
-        )) {
2975
-            $success = $this->_preview_message(true);
2976
-            if ($success) {
2977
-                EE_Error::add_success(__('Test message sent', 'event_espresso'));
2978
-            } else {
2979
-                EE_Error::add_error(
2980
-                    esc_html__('The test message was not sent', 'event_espresso'),
2981
-                    __FILE__,
2982
-                    __FUNCTION__,
2983
-                    __LINE__
2984
-                );
2985
-            }
2986
-        }
2987
-    }
2964
+		/**
2965
+		 * Use filter to add additional controls on whether message can send or not
2966
+		 */
2967
+		if (apply_filters(
2968
+			'FHEE__Messages_Admin_Page__do_test_send__can_send',
2969
+			true,
2970
+			$context,
2971
+			$this->_req_data,
2972
+			$messenger,
2973
+			$message_type
2974
+		)) {
2975
+			$success = $this->_preview_message(true);
2976
+			if ($success) {
2977
+				EE_Error::add_success(__('Test message sent', 'event_espresso'));
2978
+			} else {
2979
+				EE_Error::add_error(
2980
+					esc_html__('The test message was not sent', 'event_espresso'),
2981
+					__FILE__,
2982
+					__FUNCTION__,
2983
+					__LINE__
2984
+				);
2985
+			}
2986
+		}
2987
+	}
2988 2988
     
2989 2989
     
2990
-    /**
2991
-     * _generate_new_templates
2992
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2993
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2994
-     * for the event.
2995
-     *
2996
-     *
2997
-     * @param  string $messenger     the messenger we are generating templates for
2998
-     * @param array   $message_types array of message types that the templates are generated for.
2999
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
3000
-     *                               indicate the message_template_group being used as the base.
3001
-     *
3002
-     * @param bool    $global
3003
-     *
3004
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3005
-     *                               encountering problems.
3006
-     * @throws EE_Error
3007
-     */
3008
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3009
-    {
3010
-        
3011
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3012
-        // just don't generate any templates.
3013
-        if (empty($message_types)) {
3014
-            return true;
3015
-        }
3016
-        
3017
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3018
-    }
2990
+	/**
2991
+	 * _generate_new_templates
2992
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2993
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2994
+	 * for the event.
2995
+	 *
2996
+	 *
2997
+	 * @param  string $messenger     the messenger we are generating templates for
2998
+	 * @param array   $message_types array of message types that the templates are generated for.
2999
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
3000
+	 *                               indicate the message_template_group being used as the base.
3001
+	 *
3002
+	 * @param bool    $global
3003
+	 *
3004
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3005
+	 *                               encountering problems.
3006
+	 * @throws EE_Error
3007
+	 */
3008
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3009
+	{
3010
+        
3011
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3012
+		// just don't generate any templates.
3013
+		if (empty($message_types)) {
3014
+			return true;
3015
+		}
3016
+        
3017
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3018
+	}
3019 3019
 
3020 3020
 
3021
-    /**
3022
-     * [_trash_or_restore_message_template]
3023
-     *
3024
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3025
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3026
-     *                        an individual context (FALSE).
3027
-     * @return void
3028
-     * @throws EE_Error
3029
-     * @throws InvalidArgumentException
3030
-     * @throws InvalidDataTypeException
3031
-     * @throws InvalidInterfaceException
3032
-     */
3033
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3034
-    {
3035
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3036
-        $MTP = EEM_Message_Template_Group::instance();
3037
-        
3038
-        $success = 1;
3039
-        
3040
-        //incoming GRP_IDs
3041
-        if ($all) {
3042
-            //Checkboxes
3043
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3044
-                //if array has more than one element then success message should be plural.
3045
-                //todo: what about nonce?
3046
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3021
+	/**
3022
+	 * [_trash_or_restore_message_template]
3023
+	 *
3024
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3025
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3026
+	 *                        an individual context (FALSE).
3027
+	 * @return void
3028
+	 * @throws EE_Error
3029
+	 * @throws InvalidArgumentException
3030
+	 * @throws InvalidDataTypeException
3031
+	 * @throws InvalidInterfaceException
3032
+	 */
3033
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3034
+	{
3035
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3036
+		$MTP = EEM_Message_Template_Group::instance();
3037
+        
3038
+		$success = 1;
3039
+        
3040
+		//incoming GRP_IDs
3041
+		if ($all) {
3042
+			//Checkboxes
3043
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3044
+				//if array has more than one element then success message should be plural.
3045
+				//todo: what about nonce?
3046
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3047 3047
                 
3048
-                //cycle through checkboxes
3049
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3050
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3051
-                    if ( ! $trashed_or_restored) {
3052
-                        $success = 0;
3053
-                    }
3054
-                }
3055
-            } else {
3056
-                //grab single GRP_ID and handle
3057
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3058
-                if ( ! empty($GRP_ID)) {
3059
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3060
-                    if ( ! $trashed_or_restored) {
3061
-                        $success = 0;
3062
-                    }
3063
-                } else {
3064
-                    $success = 0;
3065
-                }
3066
-            }
3048
+				//cycle through checkboxes
3049
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3050
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3051
+					if ( ! $trashed_or_restored) {
3052
+						$success = 0;
3053
+					}
3054
+				}
3055
+			} else {
3056
+				//grab single GRP_ID and handle
3057
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3058
+				if ( ! empty($GRP_ID)) {
3059
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3060
+					if ( ! $trashed_or_restored) {
3061
+						$success = 0;
3062
+					}
3063
+				} else {
3064
+					$success = 0;
3065
+				}
3066
+			}
3067 3067
             
3068
-        }
3068
+		}
3069 3069
         
3070
-        $action_desc = $trash
3071
-            ? esc_html__('moved to the trash', 'event_espresso')
3072
-            : esc_html__('restored', 'event_espresso');
3070
+		$action_desc = $trash
3071
+			? esc_html__('moved to the trash', 'event_espresso')
3072
+			: esc_html__('restored', 'event_espresso');
3073 3073
         
3074
-        $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3074
+		$action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3075 3075
         
3076
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3077
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3076
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3077
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3078 3078
         
3079
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3080
-            'event_espresso') : $item_desc;
3079
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3080
+			'event_espresso') : $item_desc;
3081 3081
         
3082
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
3082
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
3083 3083
         
3084
-    }
3084
+	}
3085 3085
 
3086 3086
 
3087
-    /**
3088
-     * [_delete_message_template]
3089
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3090
-     *
3091
-     * @return void
3092
-     * @throws EE_Error
3093
-     * @throws InvalidArgumentException
3094
-     * @throws InvalidDataTypeException
3095
-     * @throws InvalidInterfaceException
3096
-     */
3097
-    protected function _delete_message_template()
3098
-    {
3099
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3100
-        
3101
-        //checkboxes
3102
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3103
-            //if array has more than one element then success message should be plural
3104
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3087
+	/**
3088
+	 * [_delete_message_template]
3089
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3090
+	 *
3091
+	 * @return void
3092
+	 * @throws EE_Error
3093
+	 * @throws InvalidArgumentException
3094
+	 * @throws InvalidDataTypeException
3095
+	 * @throws InvalidInterfaceException
3096
+	 */
3097
+	protected function _delete_message_template()
3098
+	{
3099
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3100
+        
3101
+		//checkboxes
3102
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3103
+			//if array has more than one element then success message should be plural
3104
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3105 3105
             
3106
-            //cycle through bulk action checkboxes
3107
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3108
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3109
-            }
3110
-        } else {
3111
-            //grab single grp_id and delete
3112
-            $GRP_ID  = absint($this->_req_data['id']);
3113
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3114
-        }
3115
-        
3116
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3117
-        
3118
-    }
3106
+			//cycle through bulk action checkboxes
3107
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3108
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3109
+			}
3110
+		} else {
3111
+			//grab single grp_id and delete
3112
+			$GRP_ID  = absint($this->_req_data['id']);
3113
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3114
+		}
3115
+        
3116
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3117
+        
3118
+	}
3119 3119
 
3120 3120
 
3121
-    /**
3122
-     * helper for permanently deleting a mtP group and all related message_templates
3123
-     *
3124
-     * @param  int  $GRP_ID        The group being deleted
3125
-     * @param  bool $include_group whether to delete the Message Template Group as well.
3126
-     * @return bool boolean to indicate the success of the deletes or not.
3127
-     * @throws EE_Error
3128
-     * @throws InvalidArgumentException
3129
-     * @throws InvalidDataTypeException
3130
-     * @throws InvalidInterfaceException
3131
-     */
3132
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3133
-    {
3134
-        $success = 1;
3135
-        $MTPG    = EEM_Message_Template_Group::instance();
3136
-        //first let's GET this group
3137
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3138
-        //then delete permanently all the related Message Templates
3139
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3140
-        
3141
-        if ($deleted === 0) {
3142
-            $success = 0;
3143
-        }
3144
-        
3145
-        //now delete permanently this particular group
3146
-        
3147
-        if ($include_group && ! $MTG->delete_permanently()) {
3148
-            $success = 0;
3149
-        }
3150
-        
3151
-        return $success;
3152
-    }
3121
+	/**
3122
+	 * helper for permanently deleting a mtP group and all related message_templates
3123
+	 *
3124
+	 * @param  int  $GRP_ID        The group being deleted
3125
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
3126
+	 * @return bool boolean to indicate the success of the deletes or not.
3127
+	 * @throws EE_Error
3128
+	 * @throws InvalidArgumentException
3129
+	 * @throws InvalidDataTypeException
3130
+	 * @throws InvalidInterfaceException
3131
+	 */
3132
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3133
+	{
3134
+		$success = 1;
3135
+		$MTPG    = EEM_Message_Template_Group::instance();
3136
+		//first let's GET this group
3137
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3138
+		//then delete permanently all the related Message Templates
3139
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3140
+        
3141
+		if ($deleted === 0) {
3142
+			$success = 0;
3143
+		}
3144
+        
3145
+		//now delete permanently this particular group
3146
+        
3147
+		if ($include_group && ! $MTG->delete_permanently()) {
3148
+			$success = 0;
3149
+		}
3150
+        
3151
+		return $success;
3152
+	}
3153 3153
     
3154 3154
     
3155
-    /**
3156
-     *    _learn_more_about_message_templates_link
3157
-     * @access protected
3158
-     * @return string
3159
-     */
3160
-    protected function _learn_more_about_message_templates_link()
3161
-    {
3162
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3163
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3164
-               . '</a>';
3165
-    }
3155
+	/**
3156
+	 *    _learn_more_about_message_templates_link
3157
+	 * @access protected
3158
+	 * @return string
3159
+	 */
3160
+	protected function _learn_more_about_message_templates_link()
3161
+	{
3162
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3163
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3164
+			   . '</a>';
3165
+	}
3166 3166
 
3167 3167
 
3168
-    /**
3169
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3170
-     * ajax and other routes.
3171
-     *
3172
-     * @return void
3173
-     * @throws DomainException
3174
-     */
3175
-    protected function _settings()
3176
-    {
3177
-        
3178
-        
3179
-        $this->_set_m_mt_settings();
3180
-        
3181
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3182
-            ? $this->_req_data['selected_messenger']
3183
-            : 'email';
3184
-        
3185
-        //let's setup the messenger tabs
3186
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3187
-            $this->_m_mt_settings['messenger_tabs'],
3188
-            'messenger_links',
3189
-            '|',
3190
-            $selected_messenger
3191
-        );
3192
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3193
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3194
-        
3195
-        $this->display_admin_page_with_sidebar();
3196
-        
3197
-    }
3168
+	/**
3169
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3170
+	 * ajax and other routes.
3171
+	 *
3172
+	 * @return void
3173
+	 * @throws DomainException
3174
+	 */
3175
+	protected function _settings()
3176
+	{
3177
+        
3178
+        
3179
+		$this->_set_m_mt_settings();
3180
+        
3181
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3182
+			? $this->_req_data['selected_messenger']
3183
+			: 'email';
3184
+        
3185
+		//let's setup the messenger tabs
3186
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3187
+			$this->_m_mt_settings['messenger_tabs'],
3188
+			'messenger_links',
3189
+			'|',
3190
+			$selected_messenger
3191
+		);
3192
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3193
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3194
+        
3195
+		$this->display_admin_page_with_sidebar();
3196
+        
3197
+	}
3198 3198
 
3199 3199
 
3200
-    /**
3201
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3202
-     *
3203
-     * @access protected
3204
-     * @return void
3205
-     * @throws DomainException
3206
-     */
3207
-    protected function _set_m_mt_settings()
3208
-    {
3209
-        //first if this is already set then lets get out no need to regenerate data.
3210
-        if ( ! empty($this->_m_mt_settings)) {
3211
-            return;
3212
-        }
3213
-        
3214
-        //get all installed messengers and message_types
3215
-        /** @type EE_messenger[] $messengers */
3216
-        $messengers = $this->_message_resource_manager->installed_messengers();
3217
-        /** @type EE_message_type[] $message_types */
3218
-        $message_types = $this->_message_resource_manager->installed_message_types();
3219
-        
3220
-        
3221
-        //assemble the array for the _tab_text_links helper
3222
-        
3223
-        foreach ($messengers as $messenger) {
3224
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3225
-                'label' => ucwords($messenger->label['singular']),
3226
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3227
-                    ? 'messenger-active'
3228
-                    : '',
3229
-                'href'  => $messenger->name,
3230
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3231
-                'slug'  => $messenger->name,
3232
-                'obj'   => $messenger
3233
-            );
3200
+	/**
3201
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3202
+	 *
3203
+	 * @access protected
3204
+	 * @return void
3205
+	 * @throws DomainException
3206
+	 */
3207
+	protected function _set_m_mt_settings()
3208
+	{
3209
+		//first if this is already set then lets get out no need to regenerate data.
3210
+		if ( ! empty($this->_m_mt_settings)) {
3211
+			return;
3212
+		}
3213
+        
3214
+		//get all installed messengers and message_types
3215
+		/** @type EE_messenger[] $messengers */
3216
+		$messengers = $this->_message_resource_manager->installed_messengers();
3217
+		/** @type EE_message_type[] $message_types */
3218
+		$message_types = $this->_message_resource_manager->installed_message_types();
3219
+        
3220
+        
3221
+		//assemble the array for the _tab_text_links helper
3222
+        
3223
+		foreach ($messengers as $messenger) {
3224
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3225
+				'label' => ucwords($messenger->label['singular']),
3226
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3227
+					? 'messenger-active'
3228
+					: '',
3229
+				'href'  => $messenger->name,
3230
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3231
+				'slug'  => $messenger->name,
3232
+				'obj'   => $messenger
3233
+			);
3234 3234
             
3235 3235
             
3236
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3236
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3237 3237
             
3238
-            foreach ($message_types as $message_type) {
3239
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3240
-                // it shouldn't show in either the inactive OR active metabox.
3241
-                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3242
-                    continue;
3243
-                }
3238
+			foreach ($message_types as $message_type) {
3239
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3240
+				// it shouldn't show in either the inactive OR active metabox.
3241
+				if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3242
+					continue;
3243
+				}
3244 3244
                 
3245
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3246
-                    $messenger->name,
3247
-                    $message_type->name
3248
-                )
3249
-                    ? 'active'
3250
-                    : 'inactive';
3245
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3246
+					$messenger->name,
3247
+					$message_type->name
3248
+				)
3249
+					? 'active'
3250
+					: 'inactive';
3251 3251
                 
3252
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3253
-                    'label'    => ucwords($message_type->label['singular']),
3254
-                    'class'    => 'message-type-' . $a_or_i,
3255
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3256
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3257
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3258
-                    'title'    => $a_or_i === 'active'
3259
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3260
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3261
-                    'content'  => $a_or_i === 'active'
3262
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3263
-                        : $this->_message_type_settings_content($message_type, $messenger),
3264
-                    'slug'     => $message_type->name,
3265
-                    'active'   => $a_or_i === 'active',
3266
-                    'obj'      => $message_type
3267
-                );
3268
-            }
3269
-        }
3270
-    }
3252
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3253
+					'label'    => ucwords($message_type->label['singular']),
3254
+					'class'    => 'message-type-' . $a_or_i,
3255
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3256
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3257
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3258
+					'title'    => $a_or_i === 'active'
3259
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3260
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3261
+					'content'  => $a_or_i === 'active'
3262
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3263
+						: $this->_message_type_settings_content($message_type, $messenger),
3264
+					'slug'     => $message_type->name,
3265
+					'active'   => $a_or_i === 'active',
3266
+					'obj'      => $message_type
3267
+				);
3268
+			}
3269
+		}
3270
+	}
3271 3271
 
3272 3272
 
3273
-    /**
3274
-     * This just prepares the content for the message type settings
3275
-     *
3276
-     * @param  EE_message_type  $message_type The message type object
3277
-     * @param  EE_messenger  $messenger    The messenger object
3278
-     * @param  boolean $active       Whether the message type is active or not
3279
-     * @return string html output for the content
3280
-     * @throws DomainException
3281
-     */
3282
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3283
-    {
3284
-        //get message type fields
3285
-        $fields                                         = $message_type->get_admin_settings_fields();
3286
-        $settings_template_args['template_form_fields'] = '';
3287
-        
3288
-        if ( ! empty($fields) && $active) {
3273
+	/**
3274
+	 * This just prepares the content for the message type settings
3275
+	 *
3276
+	 * @param  EE_message_type  $message_type The message type object
3277
+	 * @param  EE_messenger  $messenger    The messenger object
3278
+	 * @param  boolean $active       Whether the message type is active or not
3279
+	 * @return string html output for the content
3280
+	 * @throws DomainException
3281
+	 */
3282
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3283
+	{
3284
+		//get message type fields
3285
+		$fields                                         = $message_type->get_admin_settings_fields();
3286
+		$settings_template_args['template_form_fields'] = '';
3287
+        
3288
+		if ( ! empty($fields) && $active) {
3289 3289
             
3290
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3290
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3291 3291
             
3292
-            foreach ($fields as $fldname => $fldprops) {
3293
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3294
-                $template_form_field[$field_id] = array(
3295
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3296
-                    'label'      => $fldprops['label'],
3297
-                    'input'      => $fldprops['field_type'],
3298
-                    'type'       => $fldprops['value_type'],
3299
-                    'required'   => $fldprops['required'],
3300
-                    'validation' => $fldprops['validation'],
3301
-                    'value'      => isset($existing_settings[$fldname])
3302
-                        ? $existing_settings[$fldname]
3303
-                        : $fldprops['default'],
3304
-                    'options'    => isset($fldprops['options'])
3305
-                        ? $fldprops['options']
3306
-                        : array(),
3307
-                    'default'    => isset($existing_settings[$fldname])
3308
-                        ? $existing_settings[$fldname]
3309
-                        : $fldprops['default'],
3310
-                    'css_class'  => 'no-drag',
3311
-                    'format'     => $fldprops['format']
3312
-                );
3313
-            }
3292
+			foreach ($fields as $fldname => $fldprops) {
3293
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3294
+				$template_form_field[$field_id] = array(
3295
+					'name'       => 'message_type_settings[' . $fldname . ']',
3296
+					'label'      => $fldprops['label'],
3297
+					'input'      => $fldprops['field_type'],
3298
+					'type'       => $fldprops['value_type'],
3299
+					'required'   => $fldprops['required'],
3300
+					'validation' => $fldprops['validation'],
3301
+					'value'      => isset($existing_settings[$fldname])
3302
+						? $existing_settings[$fldname]
3303
+						: $fldprops['default'],
3304
+					'options'    => isset($fldprops['options'])
3305
+						? $fldprops['options']
3306
+						: array(),
3307
+					'default'    => isset($existing_settings[$fldname])
3308
+						? $existing_settings[$fldname]
3309
+						: $fldprops['default'],
3310
+					'css_class'  => 'no-drag',
3311
+					'format'     => $fldprops['format']
3312
+				);
3313
+			}
3314 3314
             
3315 3315
             
3316
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3317
-                ? $this->_generate_admin_form_fields(
3318
-                    $template_form_field,
3319
-                    'string',
3320
-                    'ee_mt_activate_form'
3321
-                )
3322
-                : '';
3323
-        }
3324
-        
3325
-        $settings_template_args['description'] = $message_type->description;
3326
-        //we also need some hidden fields
3327
-        $settings_template_args['hidden_fields'] = array(
3328
-            'message_type_settings[messenger]'    => array(
3329
-                'type'  => 'hidden',
3330
-                'value' => $messenger->name
3331
-            ),
3332
-            'message_type_settings[message_type]' => array(
3333
-                'type'  => 'hidden',
3334
-                'value' => $message_type->name
3335
-            ),
3336
-            'type'                                => array(
3337
-                'type'  => 'hidden',
3338
-                'value' => 'message_type'
3339
-            )
3340
-        );
3341
-        
3342
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3343
-            $settings_template_args['hidden_fields'],
3344
-            'array'
3345
-        );
3346
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3347
-            ? ' hidden'
3348
-            : '';
3349
-        
3350
-        
3351
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3352
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
3353
-        
3354
-        return $content;
3355
-    }
3316
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3317
+				? $this->_generate_admin_form_fields(
3318
+					$template_form_field,
3319
+					'string',
3320
+					'ee_mt_activate_form'
3321
+				)
3322
+				: '';
3323
+		}
3324
+        
3325
+		$settings_template_args['description'] = $message_type->description;
3326
+		//we also need some hidden fields
3327
+		$settings_template_args['hidden_fields'] = array(
3328
+			'message_type_settings[messenger]'    => array(
3329
+				'type'  => 'hidden',
3330
+				'value' => $messenger->name
3331
+			),
3332
+			'message_type_settings[message_type]' => array(
3333
+				'type'  => 'hidden',
3334
+				'value' => $message_type->name
3335
+			),
3336
+			'type'                                => array(
3337
+				'type'  => 'hidden',
3338
+				'value' => 'message_type'
3339
+			)
3340
+		);
3341
+        
3342
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3343
+			$settings_template_args['hidden_fields'],
3344
+			'array'
3345
+		);
3346
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3347
+			? ' hidden'
3348
+			: '';
3349
+        
3350
+        
3351
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3352
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
3353
+        
3354
+		return $content;
3355
+	}
3356 3356
 
3357 3357
 
3358
-    /**
3359
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3360
-     *
3361
-     * @access protected
3362
-     * @return void
3363
-     * @throws DomainException
3364
-     */
3365
-    protected function _messages_settings_metaboxes()
3366
-    {
3367
-        $this->_set_m_mt_settings();
3368
-        $m_boxes         = $mt_boxes = array();
3369
-        $m_template_args = $mt_template_args = array();
3370
-        
3371
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3372
-            ? $this->_req_data['selected_messenger']
3373
-            : 'email';
3374
-        
3375
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3376
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3377
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3378
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3379
-                //messenger meta boxes
3380
-                $active                                 = $selected_messenger === $messenger;
3381
-                $active_mt_tabs                         = isset(
3382
-                    $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3383
-                )
3384
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3385
-                    : '';
3386
-                $m_boxes[$messenger . '_a_box']         = sprintf(
3387
-                    esc_html__('%s Settings', 'event_espresso'),
3388
-                    $tab_array['label']
3389
-                );
3390
-                $m_template_args[$messenger . '_a_box'] = array(
3391
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3392
-                    'inactive_message_types' => isset(
3393
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3394
-                    )
3395
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3396
-                        : '',
3397
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3398
-                    'hidden'                 => $active ? '' : ' hidden',
3399
-                    'hide_on_message'        => $hide_on_message,
3400
-                    'messenger'              => $messenger,
3401
-                    'active'                 => $active
3402
-                );
3403
-                // message type meta boxes
3404
-                // (which is really just the inactive container for each messenger
3405
-                // showing inactive message types for that messenger)
3406
-                $mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3407
-                $mt_template_args[$messenger . '_i_box'] = array(
3408
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3409
-                    'inactive_message_types' => isset(
3410
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3411
-                    )
3412
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3413
-                        : '',
3414
-                    'hidden'                 => $active ? '' : ' hidden',
3415
-                    'hide_on_message'        => $hide_on_message,
3416
-                    'hide_off_message'       => $hide_off_message,
3417
-                    'messenger'              => $messenger,
3418
-                    'active'                 => $active
3419
-                );
3420
-            }
3421
-        }
3422
-        
3423
-        
3424
-        //register messenger metaboxes
3425
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3426
-        foreach ($m_boxes as $box => $label) {
3427
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3428
-            $msgr          = str_replace('_a_box', '', $box);
3429
-            add_meta_box(
3430
-                'espresso_' . $msgr . '_settings',
3431
-                $label,
3432
-                function ($post, $metabox) {
3433
-                    echo EEH_Template::display_template(
3434
-                            $metabox["args"]["template_path"],
3435
-                            $metabox["args"]["template_args"],
3436
-                            true
3437
-                    );
3438
-                },
3439
-                $this->_current_screen->id,
3440
-                'normal',
3441
-                'high',
3442
-                $callback_args
3443
-            );
3444
-        }
3445
-        
3446
-        //register message type metaboxes
3447
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3448
-        foreach ($mt_boxes as $box => $label) {
3449
-            $callback_args = array(
3450
-                'template_path' => $mt_template_path,
3451
-                'template_args' => $mt_template_args[$box]
3452
-            );
3453
-            $mt            = str_replace('_i_box', '', $box);
3454
-            add_meta_box(
3455
-                'espresso_' . $mt . '_inactive_mts',
3456
-                $label,
3457
-                function ($post, $metabox) {
3458
-                    echo EEH_Template::display_template(
3459
-                            $metabox["args"]["template_path"],
3460
-                            $metabox["args"]["template_args"],
3461
-                            true
3462
-                    );
3463
-                },
3464
-                $this->_current_screen->id,
3465
-                'side',
3466
-                'high',
3467
-                $callback_args
3468
-            );
3469
-        }
3470
-        
3471
-        //register metabox for global messages settings but only when on the main site.  On single site installs this
3472
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3473
-        if (is_main_site()) {
3474
-            add_meta_box(
3475
-                'espresso_global_message_settings',
3476
-                esc_html__('Global Message Settings', 'event_espresso'),
3477
-                array($this, 'global_messages_settings_metabox_content'),
3478
-                $this->_current_screen->id,
3479
-                'normal',
3480
-                'low',
3481
-                array()
3482
-            );
3483
-        }
3484
-        
3485
-    }
3358
+	/**
3359
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3360
+	 *
3361
+	 * @access protected
3362
+	 * @return void
3363
+	 * @throws DomainException
3364
+	 */
3365
+	protected function _messages_settings_metaboxes()
3366
+	{
3367
+		$this->_set_m_mt_settings();
3368
+		$m_boxes         = $mt_boxes = array();
3369
+		$m_template_args = $mt_template_args = array();
3370
+        
3371
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3372
+			? $this->_req_data['selected_messenger']
3373
+			: 'email';
3374
+        
3375
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3376
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3377
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3378
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3379
+				//messenger meta boxes
3380
+				$active                                 = $selected_messenger === $messenger;
3381
+				$active_mt_tabs                         = isset(
3382
+					$this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3383
+				)
3384
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3385
+					: '';
3386
+				$m_boxes[$messenger . '_a_box']         = sprintf(
3387
+					esc_html__('%s Settings', 'event_espresso'),
3388
+					$tab_array['label']
3389
+				);
3390
+				$m_template_args[$messenger . '_a_box'] = array(
3391
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3392
+					'inactive_message_types' => isset(
3393
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3394
+					)
3395
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3396
+						: '',
3397
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3398
+					'hidden'                 => $active ? '' : ' hidden',
3399
+					'hide_on_message'        => $hide_on_message,
3400
+					'messenger'              => $messenger,
3401
+					'active'                 => $active
3402
+				);
3403
+				// message type meta boxes
3404
+				// (which is really just the inactive container for each messenger
3405
+				// showing inactive message types for that messenger)
3406
+				$mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3407
+				$mt_template_args[$messenger . '_i_box'] = array(
3408
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3409
+					'inactive_message_types' => isset(
3410
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3411
+					)
3412
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3413
+						: '',
3414
+					'hidden'                 => $active ? '' : ' hidden',
3415
+					'hide_on_message'        => $hide_on_message,
3416
+					'hide_off_message'       => $hide_off_message,
3417
+					'messenger'              => $messenger,
3418
+					'active'                 => $active
3419
+				);
3420
+			}
3421
+		}
3422
+        
3423
+        
3424
+		//register messenger metaboxes
3425
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3426
+		foreach ($m_boxes as $box => $label) {
3427
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3428
+			$msgr          = str_replace('_a_box', '', $box);
3429
+			add_meta_box(
3430
+				'espresso_' . $msgr . '_settings',
3431
+				$label,
3432
+				function ($post, $metabox) {
3433
+					echo EEH_Template::display_template(
3434
+							$metabox["args"]["template_path"],
3435
+							$metabox["args"]["template_args"],
3436
+							true
3437
+					);
3438
+				},
3439
+				$this->_current_screen->id,
3440
+				'normal',
3441
+				'high',
3442
+				$callback_args
3443
+			);
3444
+		}
3445
+        
3446
+		//register message type metaboxes
3447
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3448
+		foreach ($mt_boxes as $box => $label) {
3449
+			$callback_args = array(
3450
+				'template_path' => $mt_template_path,
3451
+				'template_args' => $mt_template_args[$box]
3452
+			);
3453
+			$mt            = str_replace('_i_box', '', $box);
3454
+			add_meta_box(
3455
+				'espresso_' . $mt . '_inactive_mts',
3456
+				$label,
3457
+				function ($post, $metabox) {
3458
+					echo EEH_Template::display_template(
3459
+							$metabox["args"]["template_path"],
3460
+							$metabox["args"]["template_args"],
3461
+							true
3462
+					);
3463
+				},
3464
+				$this->_current_screen->id,
3465
+				'side',
3466
+				'high',
3467
+				$callback_args
3468
+			);
3469
+		}
3470
+        
3471
+		//register metabox for global messages settings but only when on the main site.  On single site installs this
3472
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3473
+		if (is_main_site()) {
3474
+			add_meta_box(
3475
+				'espresso_global_message_settings',
3476
+				esc_html__('Global Message Settings', 'event_espresso'),
3477
+				array($this, 'global_messages_settings_metabox_content'),
3478
+				$this->_current_screen->id,
3479
+				'normal',
3480
+				'low',
3481
+				array()
3482
+			);
3483
+		}
3484
+        
3485
+	}
3486 3486
 
3487 3487
 
3488
-    /**
3489
-     *  This generates the content for the global messages settings metabox.
3490
-     *
3491
-     * @return string
3492
-     * @throws EE_Error
3493
-     * @throws InvalidArgumentException
3494
-     * @throws ReflectionException
3495
-     * @throws InvalidDataTypeException
3496
-     * @throws InvalidInterfaceException
3497
-     */
3498
-    public function global_messages_settings_metabox_content()
3499
-    {
3500
-        $form = $this->_generate_global_settings_form();
3501
-        echo $form->form_open(
3502
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3503
-                'POST'
3504
-            )
3505
-             . $form->get_html()
3506
-             . $form->form_close();
3507
-    }
3488
+	/**
3489
+	 *  This generates the content for the global messages settings metabox.
3490
+	 *
3491
+	 * @return string
3492
+	 * @throws EE_Error
3493
+	 * @throws InvalidArgumentException
3494
+	 * @throws ReflectionException
3495
+	 * @throws InvalidDataTypeException
3496
+	 * @throws InvalidInterfaceException
3497
+	 */
3498
+	public function global_messages_settings_metabox_content()
3499
+	{
3500
+		$form = $this->_generate_global_settings_form();
3501
+		echo $form->form_open(
3502
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3503
+				'POST'
3504
+			)
3505
+			 . $form->get_html()
3506
+			 . $form->form_close();
3507
+	}
3508 3508
 
3509 3509
 
3510
-    /**
3511
-     * This generates and returns the form object for the global messages settings.
3512
-     *
3513
-     * @return EE_Form_Section_Proper
3514
-     * @throws EE_Error
3515
-     * @throws InvalidArgumentException
3516
-     * @throws ReflectionException
3517
-     * @throws InvalidDataTypeException
3518
-     * @throws InvalidInterfaceException
3519
-     */
3520
-    protected function _generate_global_settings_form()
3521
-    {
3522
-        EE_Registry::instance()->load_helper('HTML');
3523
-        /** @var EE_Network_Core_Config $network_config */
3524
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3525
-        
3526
-        return new EE_Form_Section_Proper(
3527
-            array(
3528
-                'name'            => 'global_messages_settings',
3529
-                'html_id'         => 'global_messages_settings',
3530
-                'html_class'      => 'form-table',
3531
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3532
-                'subsections'     => apply_filters(
3533
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3534
-                    array(
3535
-                        'do_messages_on_same_request' => new EE_Select_Input(
3536
-                            array(
3537
-                                true  => esc_html__("On the same request", "event_espresso"),
3538
-                                false => esc_html__("On a separate request", "event_espresso")
3539
-                            ),
3540
-                            array(
3541
-                                'default'         => $network_config->do_messages_on_same_request,
3542
-                                'html_label_text' => esc_html__(
3543
-                                    'Generate and send all messages:',
3544
-                                    'event_espresso'
3545
-                                ),
3546
-                                'html_help_text'  => esc_html__(
3547
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3548
-                                    'event_espresso'
3549
-                                ),
3550
-                            )
3551
-                        ),
3552
-                        'delete_threshold' => new EE_Select_Input(
3553
-                            array(
3554
-                                0 => esc_html__('Forever', 'event_espresso'),
3555
-                                3 => esc_html__('3 Months', 'event_espresso'),
3556
-                                6 => esc_html__('6 Months', 'event_espresso'),
3557
-                                9 => esc_html__('9 Months', 'event_espresso'),
3558
-                                12 => esc_html__('12 Months', 'event_espresso'),
3559
-                                24 => esc_html__('24 Months', 'event_espresso'),
3560
-                                36 => esc_html__('36 Months', 'event_espresso')
3561
-                            ),
3562
-                            array(
3563
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3564
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3565
-                                'html_help_text' => esc_html__(
3566
-                                    'You can control how long a record of processed messages is kept via this option.',
3567
-                                    'event_espresso'
3568
-                                ),
3569
-                            )
3570
-                        ),
3571
-                        'update_settings'             => new EE_Submit_Input(
3572
-                            array(
3573
-                                'default'         => esc_html__('Update', 'event_espresso'),
3574
-                                'html_label_text' => '&nbsp'
3575
-                            )
3576
-                        )
3577
-                    )
3578
-                )
3579
-            )
3580
-        );
3581
-    }
3510
+	/**
3511
+	 * This generates and returns the form object for the global messages settings.
3512
+	 *
3513
+	 * @return EE_Form_Section_Proper
3514
+	 * @throws EE_Error
3515
+	 * @throws InvalidArgumentException
3516
+	 * @throws ReflectionException
3517
+	 * @throws InvalidDataTypeException
3518
+	 * @throws InvalidInterfaceException
3519
+	 */
3520
+	protected function _generate_global_settings_form()
3521
+	{
3522
+		EE_Registry::instance()->load_helper('HTML');
3523
+		/** @var EE_Network_Core_Config $network_config */
3524
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3525
+        
3526
+		return new EE_Form_Section_Proper(
3527
+			array(
3528
+				'name'            => 'global_messages_settings',
3529
+				'html_id'         => 'global_messages_settings',
3530
+				'html_class'      => 'form-table',
3531
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3532
+				'subsections'     => apply_filters(
3533
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3534
+					array(
3535
+						'do_messages_on_same_request' => new EE_Select_Input(
3536
+							array(
3537
+								true  => esc_html__("On the same request", "event_espresso"),
3538
+								false => esc_html__("On a separate request", "event_espresso")
3539
+							),
3540
+							array(
3541
+								'default'         => $network_config->do_messages_on_same_request,
3542
+								'html_label_text' => esc_html__(
3543
+									'Generate and send all messages:',
3544
+									'event_espresso'
3545
+								),
3546
+								'html_help_text'  => esc_html__(
3547
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3548
+									'event_espresso'
3549
+								),
3550
+							)
3551
+						),
3552
+						'delete_threshold' => new EE_Select_Input(
3553
+							array(
3554
+								0 => esc_html__('Forever', 'event_espresso'),
3555
+								3 => esc_html__('3 Months', 'event_espresso'),
3556
+								6 => esc_html__('6 Months', 'event_espresso'),
3557
+								9 => esc_html__('9 Months', 'event_espresso'),
3558
+								12 => esc_html__('12 Months', 'event_espresso'),
3559
+								24 => esc_html__('24 Months', 'event_espresso'),
3560
+								36 => esc_html__('36 Months', 'event_espresso')
3561
+							),
3562
+							array(
3563
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3564
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3565
+								'html_help_text' => esc_html__(
3566
+									'You can control how long a record of processed messages is kept via this option.',
3567
+									'event_espresso'
3568
+								),
3569
+							)
3570
+						),
3571
+						'update_settings'             => new EE_Submit_Input(
3572
+							array(
3573
+								'default'         => esc_html__('Update', 'event_espresso'),
3574
+								'html_label_text' => '&nbsp'
3575
+							)
3576
+						)
3577
+					)
3578
+				)
3579
+			)
3580
+		);
3581
+	}
3582 3582
 
3583 3583
 
3584
-    /**
3585
-     * This handles updating the global settings set on the admin page.
3586
-     *
3587
-     * @throws EE_Error
3588
-     * @throws InvalidDataTypeException
3589
-     * @throws InvalidInterfaceException
3590
-     * @throws InvalidArgumentException
3591
-     * @throws ReflectionException
3592
-     */
3593
-    protected function _update_global_settings()
3594
-    {
3595
-        /** @var EE_Network_Core_Config $network_config */
3596
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3597
-        $messages_config = EE_Registry::instance()->CFG->messages;
3598
-        $form           = $this->_generate_global_settings_form();
3599
-        if ($form->was_submitted()) {
3600
-            $form->receive_form_submission();
3601
-            if ($form->is_valid()) {
3602
-                $valid_data = $form->valid_data();
3603
-                foreach ($valid_data as $property => $value) {
3604
-                    $setter = 'set_' . $property;
3605
-                    if (method_exists($network_config, $setter)) {
3606
-                        $network_config->{$setter}($value);
3607
-                    } else if (
3608
-                        property_exists($network_config, $property)
3609
-                        && $network_config->{$property} !== $value
3610
-                    ) {
3611
-                        $network_config->{$property} = $value;
3612
-                    } else if (
3613
-                        property_exists($messages_config, $property)
3614
-                        && $messages_config->{$property} !== $value
3615
-                    ) {
3616
-                        $messages_config->{$property} = $value;
3617
-                    }
3618
-                }
3619
-                //only update if the form submission was valid!
3620
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3621
-                EE_Registry::instance()->CFG->update_espresso_config();
3622
-                EE_Error::overwrite_success();
3623
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3624
-            }
3625
-        }
3626
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3627
-    }
3584
+	/**
3585
+	 * This handles updating the global settings set on the admin page.
3586
+	 *
3587
+	 * @throws EE_Error
3588
+	 * @throws InvalidDataTypeException
3589
+	 * @throws InvalidInterfaceException
3590
+	 * @throws InvalidArgumentException
3591
+	 * @throws ReflectionException
3592
+	 */
3593
+	protected function _update_global_settings()
3594
+	{
3595
+		/** @var EE_Network_Core_Config $network_config */
3596
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3597
+		$messages_config = EE_Registry::instance()->CFG->messages;
3598
+		$form           = $this->_generate_global_settings_form();
3599
+		if ($form->was_submitted()) {
3600
+			$form->receive_form_submission();
3601
+			if ($form->is_valid()) {
3602
+				$valid_data = $form->valid_data();
3603
+				foreach ($valid_data as $property => $value) {
3604
+					$setter = 'set_' . $property;
3605
+					if (method_exists($network_config, $setter)) {
3606
+						$network_config->{$setter}($value);
3607
+					} else if (
3608
+						property_exists($network_config, $property)
3609
+						&& $network_config->{$property} !== $value
3610
+					) {
3611
+						$network_config->{$property} = $value;
3612
+					} else if (
3613
+						property_exists($messages_config, $property)
3614
+						&& $messages_config->{$property} !== $value
3615
+					) {
3616
+						$messages_config->{$property} = $value;
3617
+					}
3618
+				}
3619
+				//only update if the form submission was valid!
3620
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3621
+				EE_Registry::instance()->CFG->update_espresso_config();
3622
+				EE_Error::overwrite_success();
3623
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3624
+			}
3625
+		}
3626
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3627
+	}
3628 3628
 
3629 3629
 
3630
-    /**
3631
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3632
-     *
3633
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3634
-     * @return string html formatted tabs
3635
-     * @throws DomainException
3636
-     */
3637
-    protected function _get_mt_tabs($tab_array)
3638
-    {
3639
-        $tab_array = (array)$tab_array;
3640
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3641
-        $tabs      = '';
3642
-        
3643
-        foreach ($tab_array as $tab) {
3644
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3645
-        }
3646
-        
3647
-        return $tabs;
3648
-    }
3630
+	/**
3631
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3632
+	 *
3633
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3634
+	 * @return string html formatted tabs
3635
+	 * @throws DomainException
3636
+	 */
3637
+	protected function _get_mt_tabs($tab_array)
3638
+	{
3639
+		$tab_array = (array)$tab_array;
3640
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3641
+		$tabs      = '';
3642
+        
3643
+		foreach ($tab_array as $tab) {
3644
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3645
+		}
3646
+        
3647
+		return $tabs;
3648
+	}
3649 3649
 
3650 3650
 
3651
-    /**
3652
-     * This prepares the content of the messenger meta box admin settings
3653
-     *
3654
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3655
-     * @return string html formatted content
3656
-     * @throws DomainException
3657
-     */
3658
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3659
-    {
3651
+	/**
3652
+	 * This prepares the content of the messenger meta box admin settings
3653
+	 *
3654
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3655
+	 * @return string html formatted content
3656
+	 * @throws DomainException
3657
+	 */
3658
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3659
+	{
3660 3660
         
3661
-        $fields                                         = $messenger->get_admin_settings_fields();
3662
-        $settings_template_args['template_form_fields'] = '';
3661
+		$fields                                         = $messenger->get_admin_settings_fields();
3662
+		$settings_template_args['template_form_fields'] = '';
3663 3663
         
3664
-        //is $messenger active?
3665
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3664
+		//is $messenger active?
3665
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3666 3666
         
3667 3667
         
3668
-        if ( ! empty($fields)) {
3668
+		if ( ! empty($fields)) {
3669 3669
             
3670
-            $existing_settings = $messenger->get_existing_admin_settings();
3670
+			$existing_settings = $messenger->get_existing_admin_settings();
3671 3671
             
3672
-            foreach ($fields as $fldname => $fldprops) {
3673
-                $field_id                       = $messenger->name . '-' . $fldname;
3674
-                $template_form_field[$field_id] = array(
3675
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3676
-                    'label'      => $fldprops['label'],
3677
-                    'input'      => $fldprops['field_type'],
3678
-                    'type'       => $fldprops['value_type'],
3679
-                    'required'   => $fldprops['required'],
3680
-                    'validation' => $fldprops['validation'],
3681
-                    'value'      => isset($existing_settings[$field_id])
3682
-                        ? $existing_settings[$field_id]
3683
-                        : $fldprops['default'],
3684
-                    'css_class'  => '',
3685
-                    'format'     => $fldprops['format']
3686
-                );
3687
-            }
3672
+			foreach ($fields as $fldname => $fldprops) {
3673
+				$field_id                       = $messenger->name . '-' . $fldname;
3674
+				$template_form_field[$field_id] = array(
3675
+					'name'       => 'messenger_settings[' . $field_id . ']',
3676
+					'label'      => $fldprops['label'],
3677
+					'input'      => $fldprops['field_type'],
3678
+					'type'       => $fldprops['value_type'],
3679
+					'required'   => $fldprops['required'],
3680
+					'validation' => $fldprops['validation'],
3681
+					'value'      => isset($existing_settings[$field_id])
3682
+						? $existing_settings[$field_id]
3683
+						: $fldprops['default'],
3684
+					'css_class'  => '',
3685
+					'format'     => $fldprops['format']
3686
+				);
3687
+			}
3688 3688
             
3689 3689
             
3690
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3691
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3692
-                : '';
3693
-        }
3694
-        
3695
-        //we also need some hidden fields
3696
-        $settings_template_args['hidden_fields'] = array(
3697
-            'messenger_settings[messenger]' => array(
3698
-                'type'  => 'hidden',
3699
-                'value' => $messenger->name
3700
-            ),
3701
-            'type'                          => array(
3702
-                'type'  => 'hidden',
3703
-                'value' => 'messenger'
3704
-            )
3705
-        );
3706
-        
3707
-        //make sure any active message types that are existing are included in the hidden fields
3708
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3709
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3710
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3711
-                    'type'  => 'hidden',
3712
-                    'value' => $mt
3713
-                );
3714
-            }
3715
-        }
3716
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3717
-            $settings_template_args['hidden_fields'],
3718
-            'array'
3719
-        );
3720
-        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3721
-        
3722
-        $settings_template_args['messenger']           = $messenger->name;
3723
-        $settings_template_args['description']         = $messenger->description;
3724
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3725
-        
3726
-        
3727
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3728
-            $messenger->name
3729
-        )
3730
-            ? $settings_template_args['show_hide_edit_form']
3731
-            : ' hidden';
3732
-        
3733
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3734
-            ? ' hidden'
3735
-            : $settings_template_args['show_hide_edit_form'];
3736
-        
3737
-        
3738
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3739
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3740
-        $settings_template_args['on_off_status'] = $active ? true : false;
3741
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3742
-        $content                                 = EEH_Template::display_template(
3743
-            $template,
3744
-            $settings_template_args,
3745
-            true
3746
-        );
3747
-        
3748
-        return $content;
3749
-    }
3690
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3691
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3692
+				: '';
3693
+		}
3694
+        
3695
+		//we also need some hidden fields
3696
+		$settings_template_args['hidden_fields'] = array(
3697
+			'messenger_settings[messenger]' => array(
3698
+				'type'  => 'hidden',
3699
+				'value' => $messenger->name
3700
+			),
3701
+			'type'                          => array(
3702
+				'type'  => 'hidden',
3703
+				'value' => 'messenger'
3704
+			)
3705
+		);
3706
+        
3707
+		//make sure any active message types that are existing are included in the hidden fields
3708
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3709
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3710
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3711
+					'type'  => 'hidden',
3712
+					'value' => $mt
3713
+				);
3714
+			}
3715
+		}
3716
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3717
+			$settings_template_args['hidden_fields'],
3718
+			'array'
3719
+		);
3720
+		$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3721
+        
3722
+		$settings_template_args['messenger']           = $messenger->name;
3723
+		$settings_template_args['description']         = $messenger->description;
3724
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3725
+        
3726
+        
3727
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3728
+			$messenger->name
3729
+		)
3730
+			? $settings_template_args['show_hide_edit_form']
3731
+			: ' hidden';
3732
+        
3733
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3734
+			? ' hidden'
3735
+			: $settings_template_args['show_hide_edit_form'];
3736
+        
3737
+        
3738
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3739
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3740
+		$settings_template_args['on_off_status'] = $active ? true : false;
3741
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3742
+		$content                                 = EEH_Template::display_template(
3743
+			$template,
3744
+			$settings_template_args,
3745
+			true
3746
+		);
3747
+        
3748
+		return $content;
3749
+	}
3750 3750
 
3751 3751
 
3752
-    /**
3753
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3754
-     *
3755
-     * @throws DomainException
3756
-     * @throws EE_Error
3757
-     * @throws InvalidDataTypeException
3758
-     * @throws InvalidInterfaceException
3759
-     * @throws InvalidArgumentException
3760
-     * @throws ReflectionException
3761
-     */
3762
-    public function activate_messenger_toggle()
3763
-    {
3764
-        $success = true;
3765
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3766
-        //let's check that we have required data
3767
-        if ( ! isset($this->_req_data['messenger'])) {
3768
-            EE_Error::add_error(
3769
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3770
-                __FILE__,
3771
-                __FUNCTION__,
3772
-                __LINE__
3773
-            );
3774
-            $success = false;
3775
-        }
3776
-        
3777
-        //do a nonce check here since we're not arriving via a normal route
3778
-        $nonce     = isset($this->_req_data['activate_nonce'])
3779
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3780
-            : '';
3781
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3782
-        
3783
-        $this->_verify_nonce($nonce, $nonce_ref);
3784
-        
3785
-        
3786
-        if ( ! isset($this->_req_data['status'])) {
3787
-            EE_Error::add_error(
3788
-                esc_html__(
3789
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3790
-                    'event_espresso'
3791
-                ),
3792
-                __FILE__,
3793
-                __FUNCTION__,
3794
-                __LINE__
3795
-            );
3796
-            $success = false;
3797
-        }
3798
-        
3799
-        //do check to verify we have a valid status.
3800
-        $status = $this->_req_data['status'];
3801
-        
3802
-        if ($status !== 'off' && $status !== 'on') {
3803
-            EE_Error::add_error(
3804
-                sprintf(
3805
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3806
-                    $this->_req_data['status']
3807
-                ),
3808
-                __FILE__,
3809
-                __FUNCTION__,
3810
-                __LINE__
3811
-            );
3812
-            $success = false;
3813
-        }
3814
-        
3815
-        if ($success) {
3816
-            //made it here?  Stop dawdling then!!
3817
-            $success = $status === 'off'
3818
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3819
-                : $this->_activate_messenger($this->_req_data['messenger']);
3820
-        }
3821
-        
3822
-        $this->_template_args['success'] = $success;
3823
-        
3824
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3825
-        $this->_return_json();
3826
-        
3827
-    }
3752
+	/**
3753
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3754
+	 *
3755
+	 * @throws DomainException
3756
+	 * @throws EE_Error
3757
+	 * @throws InvalidDataTypeException
3758
+	 * @throws InvalidInterfaceException
3759
+	 * @throws InvalidArgumentException
3760
+	 * @throws ReflectionException
3761
+	 */
3762
+	public function activate_messenger_toggle()
3763
+	{
3764
+		$success = true;
3765
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3766
+		//let's check that we have required data
3767
+		if ( ! isset($this->_req_data['messenger'])) {
3768
+			EE_Error::add_error(
3769
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3770
+				__FILE__,
3771
+				__FUNCTION__,
3772
+				__LINE__
3773
+			);
3774
+			$success = false;
3775
+		}
3776
+        
3777
+		//do a nonce check here since we're not arriving via a normal route
3778
+		$nonce     = isset($this->_req_data['activate_nonce'])
3779
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3780
+			: '';
3781
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3782
+        
3783
+		$this->_verify_nonce($nonce, $nonce_ref);
3784
+        
3785
+        
3786
+		if ( ! isset($this->_req_data['status'])) {
3787
+			EE_Error::add_error(
3788
+				esc_html__(
3789
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3790
+					'event_espresso'
3791
+				),
3792
+				__FILE__,
3793
+				__FUNCTION__,
3794
+				__LINE__
3795
+			);
3796
+			$success = false;
3797
+		}
3798
+        
3799
+		//do check to verify we have a valid status.
3800
+		$status = $this->_req_data['status'];
3801
+        
3802
+		if ($status !== 'off' && $status !== 'on') {
3803
+			EE_Error::add_error(
3804
+				sprintf(
3805
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3806
+					$this->_req_data['status']
3807
+				),
3808
+				__FILE__,
3809
+				__FUNCTION__,
3810
+				__LINE__
3811
+			);
3812
+			$success = false;
3813
+		}
3814
+        
3815
+		if ($success) {
3816
+			//made it here?  Stop dawdling then!!
3817
+			$success = $status === 'off'
3818
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3819
+				: $this->_activate_messenger($this->_req_data['messenger']);
3820
+		}
3821
+        
3822
+		$this->_template_args['success'] = $success;
3823
+        
3824
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3825
+		$this->_return_json();
3826
+        
3827
+	}
3828 3828
 
3829 3829
 
3830
-    /**
3831
-     * used by ajax from the messages settings page to activate|deactivate a message type
3832
-     *
3833
-     * @throws DomainException
3834
-     * @throws EE_Error
3835
-     * @throws ReflectionException
3836
-     * @throws InvalidDataTypeException
3837
-     * @throws InvalidInterfaceException
3838
-     * @throws InvalidArgumentException
3839
-     */
3840
-    public function activate_mt_toggle()
3841
-    {
3842
-        $success = true;
3843
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3844
-        
3845
-        //let's make sure we have the necessary data
3846
-        if ( ! isset($this->_req_data['message_type'])) {
3847
-            EE_Error::add_error(
3848
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3849
-                __FILE__,
3850
-                __FUNCTION__,
3851
-                __LINE__
3852
-            );
3853
-            $success = false;
3854
-        }
3855
-        
3856
-        if ( ! isset($this->_req_data['messenger'])) {
3857
-            EE_Error::add_error(
3858
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3859
-                __FILE__,
3860
-                __FUNCTION__,
3861
-                __LINE__
3862
-            );
3863
-            $success = false;
3864
-        }
3865
-        
3866
-        if ( ! isset($this->_req_data['status'])) {
3867
-            EE_Error::add_error(
3868
-                esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3869
-                    'event_espresso'),
3870
-                __FILE__,
3871
-                __FUNCTION__,
3872
-                __LINE__
3873
-            );
3874
-            $success = false;
3875
-        }
3876
-        
3877
-        
3878
-        //do check to verify we have a valid status.
3879
-        $status = $this->_req_data['status'];
3880
-        
3881
-        if ($status !== 'activate' && $status !== 'deactivate') {
3882
-            EE_Error::add_error(
3883
-                sprintf(
3884
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3885
-                    $this->_req_data['status']
3886
-                ),
3887
-                __FILE__,
3888
-                __FUNCTION__,
3889
-                __LINE__
3890
-            );
3891
-            $success = false;
3892
-        }
3893
-        
3894
-        
3895
-        //do a nonce check here since we're not arriving via a normal route
3896
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3897
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3898
-        
3899
-        $this->_verify_nonce($nonce, $nonce_ref);
3900
-        
3901
-        if ($success) {
3902
-            //made it here? um, what are you waiting for then?
3903
-            $success = $status === 'deactivate'
3904
-                ? $this->_deactivate_message_type_for_messenger(
3905
-                    $this->_req_data['messenger'],
3906
-                    $this->_req_data['message_type']
3907
-                )
3908
-                : $this->_activate_message_type_for_messenger(
3909
-                    $this->_req_data['messenger'],
3910
-                    $this->_req_data['message_type']
3911
-                );
3912
-        }
3913
-        
3914
-        $this->_template_args['success'] = $success;
3915
-        $this->_return_json();
3916
-    }
3830
+	/**
3831
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3832
+	 *
3833
+	 * @throws DomainException
3834
+	 * @throws EE_Error
3835
+	 * @throws ReflectionException
3836
+	 * @throws InvalidDataTypeException
3837
+	 * @throws InvalidInterfaceException
3838
+	 * @throws InvalidArgumentException
3839
+	 */
3840
+	public function activate_mt_toggle()
3841
+	{
3842
+		$success = true;
3843
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3844
+        
3845
+		//let's make sure we have the necessary data
3846
+		if ( ! isset($this->_req_data['message_type'])) {
3847
+			EE_Error::add_error(
3848
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3849
+				__FILE__,
3850
+				__FUNCTION__,
3851
+				__LINE__
3852
+			);
3853
+			$success = false;
3854
+		}
3855
+        
3856
+		if ( ! isset($this->_req_data['messenger'])) {
3857
+			EE_Error::add_error(
3858
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3859
+				__FILE__,
3860
+				__FUNCTION__,
3861
+				__LINE__
3862
+			);
3863
+			$success = false;
3864
+		}
3865
+        
3866
+		if ( ! isset($this->_req_data['status'])) {
3867
+			EE_Error::add_error(
3868
+				esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3869
+					'event_espresso'),
3870
+				__FILE__,
3871
+				__FUNCTION__,
3872
+				__LINE__
3873
+			);
3874
+			$success = false;
3875
+		}
3876
+        
3877
+        
3878
+		//do check to verify we have a valid status.
3879
+		$status = $this->_req_data['status'];
3880
+        
3881
+		if ($status !== 'activate' && $status !== 'deactivate') {
3882
+			EE_Error::add_error(
3883
+				sprintf(
3884
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3885
+					$this->_req_data['status']
3886
+				),
3887
+				__FILE__,
3888
+				__FUNCTION__,
3889
+				__LINE__
3890
+			);
3891
+			$success = false;
3892
+		}
3893
+        
3894
+        
3895
+		//do a nonce check here since we're not arriving via a normal route
3896
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3897
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3898
+        
3899
+		$this->_verify_nonce($nonce, $nonce_ref);
3900
+        
3901
+		if ($success) {
3902
+			//made it here? um, what are you waiting for then?
3903
+			$success = $status === 'deactivate'
3904
+				? $this->_deactivate_message_type_for_messenger(
3905
+					$this->_req_data['messenger'],
3906
+					$this->_req_data['message_type']
3907
+				)
3908
+				: $this->_activate_message_type_for_messenger(
3909
+					$this->_req_data['messenger'],
3910
+					$this->_req_data['message_type']
3911
+				);
3912
+		}
3913
+        
3914
+		$this->_template_args['success'] = $success;
3915
+		$this->_return_json();
3916
+	}
3917 3917
 
3918 3918
 
3919
-    /**
3920
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3921
-     *
3922
-     * @param string $messenger_name The name of the messenger being activated
3923
-     * @return bool
3924
-     * @throws DomainException
3925
-     * @throws EE_Error
3926
-     * @throws InvalidArgumentException
3927
-     * @throws ReflectionException
3928
-     * @throws InvalidDataTypeException
3929
-     * @throws InvalidInterfaceException
3930
-     */
3931
-    protected function _activate_messenger($messenger_name)
3932
-    {
3933
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3934
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3935
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3936
-            ? $active_messenger->get_default_message_types()
3937
-            : array();
3938
-        
3939
-        //ensure is active
3940
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3941
-        
3942
-        //set response_data for reload
3943
-        foreach ($message_types_to_activate as $message_type_name) {
3944
-            /** @var EE_message_type $message_type */
3945
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3946
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3947
-                    $messenger_name,
3948
-                    $message_type_name
3949
-                )
3950
-                && $message_type instanceof EE_message_type
3951
-            ) {
3952
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3953
-                if ($message_type->get_admin_settings_fields()) {
3954
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3955
-                }
3956
-            }
3957
-        }
3958
-        
3959
-        //add success message for activating messenger
3960
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3961
-        
3962
-    }
3919
+	/**
3920
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3921
+	 *
3922
+	 * @param string $messenger_name The name of the messenger being activated
3923
+	 * @return bool
3924
+	 * @throws DomainException
3925
+	 * @throws EE_Error
3926
+	 * @throws InvalidArgumentException
3927
+	 * @throws ReflectionException
3928
+	 * @throws InvalidDataTypeException
3929
+	 * @throws InvalidInterfaceException
3930
+	 */
3931
+	protected function _activate_messenger($messenger_name)
3932
+	{
3933
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3934
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3935
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3936
+			? $active_messenger->get_default_message_types()
3937
+			: array();
3938
+        
3939
+		//ensure is active
3940
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3941
+        
3942
+		//set response_data for reload
3943
+		foreach ($message_types_to_activate as $message_type_name) {
3944
+			/** @var EE_message_type $message_type */
3945
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3946
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3947
+					$messenger_name,
3948
+					$message_type_name
3949
+				)
3950
+				&& $message_type instanceof EE_message_type
3951
+			) {
3952
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3953
+				if ($message_type->get_admin_settings_fields()) {
3954
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3955
+				}
3956
+			}
3957
+		}
3958
+        
3959
+		//add success message for activating messenger
3960
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3961
+        
3962
+	}
3963 3963
 
3964 3964
 
3965
-    /**
3966
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3967
-     *
3968
-     * @param string $messenger_name The name of the messenger being activated
3969
-     * @return bool
3970
-     * @throws DomainException
3971
-     * @throws EE_Error
3972
-     * @throws InvalidArgumentException
3973
-     * @throws ReflectionException
3974
-     * @throws InvalidDataTypeException
3975
-     * @throws InvalidInterfaceException
3976
-     */
3977
-    protected function _deactivate_messenger($messenger_name)
3978
-    {
3979
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3980
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3981
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3982
-        
3983
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3984
-    }
3965
+	/**
3966
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3967
+	 *
3968
+	 * @param string $messenger_name The name of the messenger being activated
3969
+	 * @return bool
3970
+	 * @throws DomainException
3971
+	 * @throws EE_Error
3972
+	 * @throws InvalidArgumentException
3973
+	 * @throws ReflectionException
3974
+	 * @throws InvalidDataTypeException
3975
+	 * @throws InvalidInterfaceException
3976
+	 */
3977
+	protected function _deactivate_messenger($messenger_name)
3978
+	{
3979
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3980
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3981
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3982
+        
3983
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3984
+	}
3985 3985
 
3986 3986
 
3987
-    /**
3988
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3989
-     *
3990
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3991
-     * @param string $message_type_name The name of the message type being activated for the messenger
3992
-     * @return bool
3993
-     * @throws DomainException
3994
-     * @throws EE_Error
3995
-     * @throws InvalidArgumentException
3996
-     * @throws ReflectionException
3997
-     * @throws InvalidDataTypeException
3998
-     * @throws InvalidInterfaceException
3999
-     */
4000
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4001
-    {
4002
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4003
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4004
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4005
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4006
-        
4007
-        //ensure is active
4008
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
4009
-        
4010
-        //set response for load
4011
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
4012
-            $message_type_name)
4013
-        ) {
4014
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4015
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4016
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4017
-            }
4018
-        }
4019
-        
4020
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
4021
-            $message_type_to_activate);
4022
-    }
3987
+	/**
3988
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3989
+	 *
3990
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3991
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3992
+	 * @return bool
3993
+	 * @throws DomainException
3994
+	 * @throws EE_Error
3995
+	 * @throws InvalidArgumentException
3996
+	 * @throws ReflectionException
3997
+	 * @throws InvalidDataTypeException
3998
+	 * @throws InvalidInterfaceException
3999
+	 */
4000
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4001
+	{
4002
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4003
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4004
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4005
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4006
+        
4007
+		//ensure is active
4008
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
4009
+        
4010
+		//set response for load
4011
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
4012
+			$message_type_name)
4013
+		) {
4014
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4015
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4016
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4017
+			}
4018
+		}
4019
+        
4020
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
4021
+			$message_type_to_activate);
4022
+	}
4023 4023
 
4024 4024
 
4025
-    /**
4026
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4027
-     *
4028
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4029
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4030
-     * @return bool
4031
-     * @throws DomainException
4032
-     * @throws EE_Error
4033
-     * @throws InvalidArgumentException
4034
-     * @throws ReflectionException
4035
-     * @throws InvalidDataTypeException
4036
-     * @throws InvalidInterfaceException
4037
-     */
4038
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4039
-    {
4040
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4041
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4042
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4043
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4044
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4045
-        
4046
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
4047
-            $message_type_to_deactivate);
4048
-    }
4025
+	/**
4026
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4027
+	 *
4028
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4029
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4030
+	 * @return bool
4031
+	 * @throws DomainException
4032
+	 * @throws EE_Error
4033
+	 * @throws InvalidArgumentException
4034
+	 * @throws ReflectionException
4035
+	 * @throws InvalidDataTypeException
4036
+	 * @throws InvalidInterfaceException
4037
+	 */
4038
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4039
+	{
4040
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4041
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4042
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4043
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4044
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4045
+        
4046
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
4047
+			$message_type_to_deactivate);
4048
+	}
4049 4049
     
4050 4050
     
4051
-    /**
4052
-     * This just initializes the defaults for activating messenger and message type responses.
4053
-     */
4054
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4055
-    {
4056
-        $this->_template_args['data']['active_mts'] = array();
4057
-        $this->_template_args['data']['mt_reload']  = array();
4058
-    }
4051
+	/**
4052
+	 * This just initializes the defaults for activating messenger and message type responses.
4053
+	 */
4054
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4055
+	{
4056
+		$this->_template_args['data']['active_mts'] = array();
4057
+		$this->_template_args['data']['mt_reload']  = array();
4058
+	}
4059 4059
 
4060 4060
 
4061
-    /**
4062
-     * Setup appropriate response for activating a messenger and/or message types
4063
-     *
4064
-     * @param EE_messenger         $messenger
4065
-     * @param EE_message_type|null $message_type
4066
-     * @return bool
4067
-     * @throws DomainException
4068
-     * @throws EE_Error
4069
-     * @throws InvalidArgumentException
4070
-     * @throws ReflectionException
4071
-     * @throws InvalidDataTypeException
4072
-     * @throws InvalidInterfaceException
4073
-     */
4074
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4075
-        $messenger,
4076
-        EE_Message_Type $message_type = null
4077
-    ) {
4078
-        //if $messenger isn't a valid messenger object then get out.
4079
-        if ( ! $messenger instanceof EE_Messenger) {
4080
-            EE_Error::add_error(
4081
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4082
-                __FILE__,
4083
-                __FUNCTION__,
4084
-                __LINE__
4085
-            );
4061
+	/**
4062
+	 * Setup appropriate response for activating a messenger and/or message types
4063
+	 *
4064
+	 * @param EE_messenger         $messenger
4065
+	 * @param EE_message_type|null $message_type
4066
+	 * @return bool
4067
+	 * @throws DomainException
4068
+	 * @throws EE_Error
4069
+	 * @throws InvalidArgumentException
4070
+	 * @throws ReflectionException
4071
+	 * @throws InvalidDataTypeException
4072
+	 * @throws InvalidInterfaceException
4073
+	 */
4074
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4075
+		$messenger,
4076
+		EE_Message_Type $message_type = null
4077
+	) {
4078
+		//if $messenger isn't a valid messenger object then get out.
4079
+		if ( ! $messenger instanceof EE_Messenger) {
4080
+			EE_Error::add_error(
4081
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4082
+				__FILE__,
4083
+				__FUNCTION__,
4084
+				__LINE__
4085
+			);
4086 4086
             
4087
-            return false;
4088
-        }
4089
-        //activated
4090
-        if ($this->_template_args['data']['active_mts']) {
4091
-            EE_Error::overwrite_success();
4092
-            //activated a message type with the messenger
4093
-            if ($message_type instanceof EE_message_type) {
4094
-                EE_Error::add_success(
4095
-                    sprintf(
4096
-                        esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4097
-                        ucwords($message_type->label['singular']),
4098
-                        ucwords($messenger->label['singular'])
4099
-                    )
4100
-                );
4087
+			return false;
4088
+		}
4089
+		//activated
4090
+		if ($this->_template_args['data']['active_mts']) {
4091
+			EE_Error::overwrite_success();
4092
+			//activated a message type with the messenger
4093
+			if ($message_type instanceof EE_message_type) {
4094
+				EE_Error::add_success(
4095
+					sprintf(
4096
+						esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4097
+						ucwords($message_type->label['singular']),
4098
+						ucwords($messenger->label['singular'])
4099
+					)
4100
+				);
4101 4101
                 
4102
-                //if message type was invoice then let's make sure we activate the invoice payment method.
4103
-                if ($message_type->name === 'invoice') {
4104
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4105
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4106
-                    if ($pm instanceof EE_Payment_Method) {
4107
-                        EE_Error::add_attention(
4108
-                            esc_html__(
4109
-                                'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4110
-                                'event_espresso'
4111
-                            )
4112
-                        );
4113
-                    }
4114
-                }
4115
-                //just toggles the entire messenger
4116
-            } else {
4117
-                EE_Error::add_success(
4118
-                    sprintf(
4119
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4120
-                        ucwords($messenger->label['singular'])
4121
-                    )
4122
-                );
4123
-            }
4102
+				//if message type was invoice then let's make sure we activate the invoice payment method.
4103
+				if ($message_type->name === 'invoice') {
4104
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4105
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4106
+					if ($pm instanceof EE_Payment_Method) {
4107
+						EE_Error::add_attention(
4108
+							esc_html__(
4109
+								'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4110
+								'event_espresso'
4111
+							)
4112
+						);
4113
+					}
4114
+				}
4115
+				//just toggles the entire messenger
4116
+			} else {
4117
+				EE_Error::add_success(
4118
+					sprintf(
4119
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4120
+						ucwords($messenger->label['singular'])
4121
+					)
4122
+				);
4123
+			}
4124 4124
             
4125
-            return true;
4125
+			return true;
4126 4126
             
4127
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4128
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4129
-            //in which case we just give a success message for the messenger being successfully activated.
4130
-        } else {
4131
-            if ( ! $messenger->get_default_message_types()) {
4132
-                //messenger doesn't have any default message types so still a success.
4133
-                EE_Error::add_success(
4134
-                    sprintf(
4135
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4136
-                        ucwords($messenger->label['singular'])
4137
-                    )
4138
-                );
4127
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4128
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4129
+			//in which case we just give a success message for the messenger being successfully activated.
4130
+		} else {
4131
+			if ( ! $messenger->get_default_message_types()) {
4132
+				//messenger doesn't have any default message types so still a success.
4133
+				EE_Error::add_success(
4134
+					sprintf(
4135
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4136
+						ucwords($messenger->label['singular'])
4137
+					)
4138
+				);
4139 4139
                 
4140
-                return true;
4141
-            } else {
4142
-                EE_Error::add_error(
4143
-                    $message_type instanceof EE_message_type
4144
-                        ? sprintf(
4145
-                        esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4146
-                        ucwords($message_type->label['singular']),
4147
-                        ucwords($messenger->label['singular'])
4148
-                    )
4149
-                        : sprintf(
4150
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4151
-                        ucwords($messenger->label['singular'])
4152
-                    ),
4153
-                    __FILE__,
4154
-                    __FUNCTION__,
4155
-                    __LINE__
4156
-                );
4140
+				return true;
4141
+			} else {
4142
+				EE_Error::add_error(
4143
+					$message_type instanceof EE_message_type
4144
+						? sprintf(
4145
+						esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4146
+						ucwords($message_type->label['singular']),
4147
+						ucwords($messenger->label['singular'])
4148
+					)
4149
+						: sprintf(
4150
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4151
+						ucwords($messenger->label['singular'])
4152
+					),
4153
+					__FILE__,
4154
+					__FUNCTION__,
4155
+					__LINE__
4156
+				);
4157 4157
                 
4158
-                return false;
4159
-            }
4160
-        }
4161
-    }
4158
+				return false;
4159
+			}
4160
+		}
4161
+	}
4162 4162
 
4163 4163
 
4164
-    /**
4165
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4166
-     *
4167
-     * @param EE_messenger         $messenger
4168
-     * @param EE_message_type|null $message_type
4169
-     * @return bool
4170
-     * @throws DomainException
4171
-     * @throws EE_Error
4172
-     * @throws InvalidArgumentException
4173
-     * @throws ReflectionException
4174
-     * @throws InvalidDataTypeException
4175
-     * @throws InvalidInterfaceException
4176
-     */
4177
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4178
-        $messenger,
4179
-        EE_message_type $message_type = null
4180
-    ) {
4181
-        EE_Error::overwrite_success();
4182
-        
4183
-        //if $messenger isn't a valid messenger object then get out.
4184
-        if ( ! $messenger instanceof EE_Messenger) {
4185
-            EE_Error::add_error(
4186
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4187
-                __FILE__,
4188
-                __FUNCTION__,
4189
-                __LINE__
4190
-            );
4164
+	/**
4165
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4166
+	 *
4167
+	 * @param EE_messenger         $messenger
4168
+	 * @param EE_message_type|null $message_type
4169
+	 * @return bool
4170
+	 * @throws DomainException
4171
+	 * @throws EE_Error
4172
+	 * @throws InvalidArgumentException
4173
+	 * @throws ReflectionException
4174
+	 * @throws InvalidDataTypeException
4175
+	 * @throws InvalidInterfaceException
4176
+	 */
4177
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4178
+		$messenger,
4179
+		EE_message_type $message_type = null
4180
+	) {
4181
+		EE_Error::overwrite_success();
4182
+        
4183
+		//if $messenger isn't a valid messenger object then get out.
4184
+		if ( ! $messenger instanceof EE_Messenger) {
4185
+			EE_Error::add_error(
4186
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4187
+				__FILE__,
4188
+				__FUNCTION__,
4189
+				__LINE__
4190
+			);
4191 4191
             
4192
-            return false;
4193
-        }
4194
-        
4195
-        if ($message_type instanceof EE_message_type) {
4196
-            $message_type_name = $message_type->name;
4197
-            EE_Error::add_success(
4198
-                sprintf(
4199
-                    esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4200
-                    ucwords($message_type->label['singular']),
4201
-                    ucwords($messenger->label['singular'])
4202
-                )
4203
-            );
4204
-        } else {
4205
-            $message_type_name = '';
4206
-            EE_Error::add_success(
4207
-                sprintf(
4208
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4209
-                    ucwords($messenger->label['singular'])
4210
-                )
4211
-            );
4212
-        }
4213
-        
4214
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4215
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4216
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4217
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4218
-            if ($count_updated > 0) {
4219
-                $msg = $message_type_name === 'invoice'
4220
-                    ? esc_html__(
4221
-                        'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4222
-                        'event_espresso'
4223
-                    )
4224
-                    : esc_html__(
4225
-                        'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4226
-                        'event_espresso'
4227
-                    );
4228
-                EE_Error::add_attention($msg);
4229
-            }
4230
-        }
4231
-        
4232
-        return true;
4233
-    }
4192
+			return false;
4193
+		}
4194
+        
4195
+		if ($message_type instanceof EE_message_type) {
4196
+			$message_type_name = $message_type->name;
4197
+			EE_Error::add_success(
4198
+				sprintf(
4199
+					esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4200
+					ucwords($message_type->label['singular']),
4201
+					ucwords($messenger->label['singular'])
4202
+				)
4203
+			);
4204
+		} else {
4205
+			$message_type_name = '';
4206
+			EE_Error::add_success(
4207
+				sprintf(
4208
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4209
+					ucwords($messenger->label['singular'])
4210
+				)
4211
+			);
4212
+		}
4213
+        
4214
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4215
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4216
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4217
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4218
+			if ($count_updated > 0) {
4219
+				$msg = $message_type_name === 'invoice'
4220
+					? esc_html__(
4221
+						'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4222
+						'event_espresso'
4223
+					)
4224
+					: esc_html__(
4225
+						'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4226
+						'event_espresso'
4227
+					);
4228
+				EE_Error::add_attention($msg);
4229
+			}
4230
+		}
4231
+        
4232
+		return true;
4233
+	}
4234 4234
 
4235 4235
 
4236
-    /**
4237
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4238
-     *
4239
-     * @throws DomainException
4240
-     */
4241
-    public function update_mt_form()
4242
-    {
4243
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4244
-            EE_Error::add_error(
4245
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4246
-                __FILE__,
4247
-                __FUNCTION__,
4248
-                __LINE__
4249
-            );
4250
-            $this->_return_json();
4251
-        }
4252
-        
4253
-        $message_types = $this->get_installed_message_types();
4254
-        
4255
-        $message_type = $message_types[$this->_req_data['message_type']];
4256
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4257
-        
4258
-        $content                         = $this->_message_type_settings_content(
4259
-            $message_type,
4260
-            $messenger,
4261
-            true
4262
-        );
4263
-        $this->_template_args['success'] = true;
4264
-        $this->_template_args['content'] = $content;
4265
-        $this->_return_json();
4266
-    }
4236
+	/**
4237
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4238
+	 *
4239
+	 * @throws DomainException
4240
+	 */
4241
+	public function update_mt_form()
4242
+	{
4243
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4244
+			EE_Error::add_error(
4245
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4246
+				__FILE__,
4247
+				__FUNCTION__,
4248
+				__LINE__
4249
+			);
4250
+			$this->_return_json();
4251
+		}
4252
+        
4253
+		$message_types = $this->get_installed_message_types();
4254
+        
4255
+		$message_type = $message_types[$this->_req_data['message_type']];
4256
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4257
+        
4258
+		$content                         = $this->_message_type_settings_content(
4259
+			$message_type,
4260
+			$messenger,
4261
+			true
4262
+		);
4263
+		$this->_template_args['success'] = true;
4264
+		$this->_template_args['content'] = $content;
4265
+		$this->_return_json();
4266
+	}
4267 4267
     
4268 4268
     
4269
-    /**
4270
-     * this handles saving the settings for a messenger or message type
4271
-     *
4272
-     */
4273
-    public function save_settings()
4274
-    {
4275
-        if ( ! isset($this->_req_data['type'])) {
4276
-            EE_Error::add_error(
4277
-                esc_html__(
4278
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4279
-                    'event_espresso'
4280
-                ),
4281
-                __FILE__,
4282
-                __FUNCTION__,
4283
-                __LINE__
4284
-            );
4285
-            $this->_template_args['error'] = true;
4286
-            $this->_return_json();
4287
-        }
4288
-        
4289
-        
4290
-        if ($this->_req_data['type'] === 'messenger') {
4291
-            //this should be an array.
4292
-            $settings  = $this->_req_data['messenger_settings'];
4293
-            $messenger = $settings['messenger'];
4294
-            //let's setup the settings data
4295
-            foreach ($settings as $key => $value) {
4296
-                switch ($key) {
4297
-                    case 'messenger' :
4298
-                        unset($settings['messenger']);
4299
-                        break;
4300
-                    case 'message_types' :
4301
-                        unset($settings['message_types']);
4302
-                        break;
4303
-                    default :
4304
-                        $settings[$key] = $value;
4305
-                        break;
4306
-                }
4307
-            }
4308
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4309
-        } elseif ($this->_req_data['type'] === 'message_type') {
4310
-            $settings     = $this->_req_data['message_type_settings'];
4311
-            $messenger    = $settings['messenger'];
4312
-            $message_type = $settings['message_type'];
4269
+	/**
4270
+	 * this handles saving the settings for a messenger or message type
4271
+	 *
4272
+	 */
4273
+	public function save_settings()
4274
+	{
4275
+		if ( ! isset($this->_req_data['type'])) {
4276
+			EE_Error::add_error(
4277
+				esc_html__(
4278
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4279
+					'event_espresso'
4280
+				),
4281
+				__FILE__,
4282
+				__FUNCTION__,
4283
+				__LINE__
4284
+			);
4285
+			$this->_template_args['error'] = true;
4286
+			$this->_return_json();
4287
+		}
4288
+        
4289
+        
4290
+		if ($this->_req_data['type'] === 'messenger') {
4291
+			//this should be an array.
4292
+			$settings  = $this->_req_data['messenger_settings'];
4293
+			$messenger = $settings['messenger'];
4294
+			//let's setup the settings data
4295
+			foreach ($settings as $key => $value) {
4296
+				switch ($key) {
4297
+					case 'messenger' :
4298
+						unset($settings['messenger']);
4299
+						break;
4300
+					case 'message_types' :
4301
+						unset($settings['message_types']);
4302
+						break;
4303
+					default :
4304
+						$settings[$key] = $value;
4305
+						break;
4306
+				}
4307
+			}
4308
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4309
+		} elseif ($this->_req_data['type'] === 'message_type') {
4310
+			$settings     = $this->_req_data['message_type_settings'];
4311
+			$messenger    = $settings['messenger'];
4312
+			$message_type = $settings['message_type'];
4313 4313
             
4314
-            foreach ($settings as $key => $value) {
4315
-                switch ($key) {
4316
-                    case 'messenger' :
4317
-                        unset($settings['messenger']);
4318
-                        break;
4319
-                    case 'message_type' :
4320
-                        unset($settings['message_type']);
4321
-                        break;
4322
-                    default :
4323
-                        $settings[$key] = $value;
4324
-                        break;
4325
-                }
4326
-            }
4314
+			foreach ($settings as $key => $value) {
4315
+				switch ($key) {
4316
+					case 'messenger' :
4317
+						unset($settings['messenger']);
4318
+						break;
4319
+					case 'message_type' :
4320
+						unset($settings['message_type']);
4321
+						break;
4322
+					default :
4323
+						$settings[$key] = $value;
4324
+						break;
4325
+				}
4326
+			}
4327 4327
             
4328
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4329
-        }
4330
-        
4331
-        //okay we should have the data all setup.  Now we just update!
4332
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4333
-        
4334
-        if ($success) {
4335
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
4336
-        } else {
4337
-            EE_Error::add_error(
4338
-                esc_html__(
4339
-                    'Settings did not get updated',
4340
-                    'event_espresso'
4341
-                ),
4342
-                __FILE__,
4343
-                __FUNCTION__,
4344
-                __LINE__
4345
-            );
4346
-        }
4347
-        
4348
-        $this->_template_args['success'] = $success;
4349
-        $this->_return_json();
4350
-    }
4328
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4329
+		}
4330
+        
4331
+		//okay we should have the data all setup.  Now we just update!
4332
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4333
+        
4334
+		if ($success) {
4335
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
4336
+		} else {
4337
+			EE_Error::add_error(
4338
+				esc_html__(
4339
+					'Settings did not get updated',
4340
+					'event_espresso'
4341
+				),
4342
+				__FILE__,
4343
+				__FUNCTION__,
4344
+				__LINE__
4345
+			);
4346
+		}
4347
+        
4348
+		$this->_template_args['success'] = $success;
4349
+		$this->_return_json();
4350
+	}
4351 4351
     
4352 4352
     
4353 4353
     
4354 4354
     
4355
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4355
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4356 4356
 
4357 4357
 
4358
-    /**
4359
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4360
-     * However, this does not send immediately, it just queues for sending.
4361
-     *
4362
-     * @since 4.9.0
4363
-     * @throws EE_Error
4364
-     * @throws InvalidDataTypeException
4365
-     * @throws InvalidInterfaceException
4366
-     * @throws InvalidArgumentException
4367
-     * @throws ReflectionException
4368
-     */
4369
-    protected function _generate_now()
4370
-    {
4371
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4372
-        $this->_redirect_after_action(false, '', '', array(), true);
4373
-    }
4358
+	/**
4359
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4360
+	 * However, this does not send immediately, it just queues for sending.
4361
+	 *
4362
+	 * @since 4.9.0
4363
+	 * @throws EE_Error
4364
+	 * @throws InvalidDataTypeException
4365
+	 * @throws InvalidInterfaceException
4366
+	 * @throws InvalidArgumentException
4367
+	 * @throws ReflectionException
4368
+	 */
4369
+	protected function _generate_now()
4370
+	{
4371
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4372
+		$this->_redirect_after_action(false, '', '', array(), true);
4373
+	}
4374 4374
 
4375 4375
 
4376
-    /**
4377
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4378
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4379
-     *
4380
-     * @since 4.9.0
4381
-     * @throws EE_Error
4382
-     * @throws InvalidDataTypeException
4383
-     * @throws InvalidInterfaceException
4384
-     * @throws InvalidArgumentException
4385
-     * @throws ReflectionException
4386
-     */
4387
-    protected function _generate_and_send_now()
4388
-    {
4389
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4390
-        $this->_redirect_after_action(false, '', '', array(), true);
4391
-    }
4376
+	/**
4377
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4378
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4379
+	 *
4380
+	 * @since 4.9.0
4381
+	 * @throws EE_Error
4382
+	 * @throws InvalidDataTypeException
4383
+	 * @throws InvalidInterfaceException
4384
+	 * @throws InvalidArgumentException
4385
+	 * @throws ReflectionException
4386
+	 */
4387
+	protected function _generate_and_send_now()
4388
+	{
4389
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4390
+		$this->_redirect_after_action(false, '', '', array(), true);
4391
+	}
4392 4392
 
4393 4393
 
4394
-    /**
4395
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4396
-     *
4397
-     * @since 4.9.0
4398
-     * @throws EE_Error
4399
-     * @throws InvalidDataTypeException
4400
-     * @throws InvalidInterfaceException
4401
-     * @throws InvalidArgumentException
4402
-     * @throws ReflectionException
4403
-     */
4404
-    protected function _queue_for_resending()
4405
-    {
4406
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4407
-        $this->_redirect_after_action(false, '', '', array(), true);
4408
-    }
4394
+	/**
4395
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4396
+	 *
4397
+	 * @since 4.9.0
4398
+	 * @throws EE_Error
4399
+	 * @throws InvalidDataTypeException
4400
+	 * @throws InvalidInterfaceException
4401
+	 * @throws InvalidArgumentException
4402
+	 * @throws ReflectionException
4403
+	 */
4404
+	protected function _queue_for_resending()
4405
+	{
4406
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4407
+		$this->_redirect_after_action(false, '', '', array(), true);
4408
+	}
4409 4409
 
4410 4410
 
4411
-    /**
4412
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4413
-     *
4414
-     * @since 4.9.0
4415
-     * @throws EE_Error
4416
-     * @throws InvalidDataTypeException
4417
-     * @throws InvalidInterfaceException
4418
-     * @throws InvalidArgumentException
4419
-     * @throws ReflectionException
4420
-     */
4421
-    protected function _send_now()
4422
-    {
4423
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4424
-        $this->_redirect_after_action(false, '', '', array(), true);
4425
-    }
4411
+	/**
4412
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4413
+	 *
4414
+	 * @since 4.9.0
4415
+	 * @throws EE_Error
4416
+	 * @throws InvalidDataTypeException
4417
+	 * @throws InvalidInterfaceException
4418
+	 * @throws InvalidArgumentException
4419
+	 * @throws ReflectionException
4420
+	 */
4421
+	protected function _send_now()
4422
+	{
4423
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4424
+		$this->_redirect_after_action(false, '', '', array(), true);
4425
+	}
4426 4426
 
4427 4427
 
4428
-    /**
4429
-     * Deletes EE_messages for IDs in the request.
4430
-     *
4431
-     * @since 4.9.0
4432
-     * @throws EE_Error
4433
-     * @throws InvalidDataTypeException
4434
-     * @throws InvalidInterfaceException
4435
-     * @throws InvalidArgumentException
4436
-     */
4437
-    protected function _delete_ee_messages()
4438
-    {
4439
-        $msg_ids       = $this->_get_msg_ids_from_request();
4440
-        $deleted_count = 0;
4441
-        foreach ($msg_ids as $msg_id) {
4442
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4443
-                $deleted_count++;
4444
-            }
4445
-        }
4446
-        if ($deleted_count) {
4447
-            EE_Error::add_success(esc_html(_n('Message successfully deleted', 'Messages successfully deleted', $deleted_count, 'event_espresso')));
4448
-            $this->_redirect_after_action(
4449
-                false,
4450
-                '',
4451
-                '',
4452
-                array(),
4453
-                true
4454
-            );
4455
-        } else {
4456
-            EE_Error::add_error(
4457
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4458
-                __FILE__, __FUNCTION__, __LINE__
4459
-            );
4460
-            $this->_redirect_after_action(false, '', '', array(), true);
4461
-        }
4462
-    }
4428
+	/**
4429
+	 * Deletes EE_messages for IDs in the request.
4430
+	 *
4431
+	 * @since 4.9.0
4432
+	 * @throws EE_Error
4433
+	 * @throws InvalidDataTypeException
4434
+	 * @throws InvalidInterfaceException
4435
+	 * @throws InvalidArgumentException
4436
+	 */
4437
+	protected function _delete_ee_messages()
4438
+	{
4439
+		$msg_ids       = $this->_get_msg_ids_from_request();
4440
+		$deleted_count = 0;
4441
+		foreach ($msg_ids as $msg_id) {
4442
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4443
+				$deleted_count++;
4444
+			}
4445
+		}
4446
+		if ($deleted_count) {
4447
+			EE_Error::add_success(esc_html(_n('Message successfully deleted', 'Messages successfully deleted', $deleted_count, 'event_espresso')));
4448
+			$this->_redirect_after_action(
4449
+				false,
4450
+				'',
4451
+				'',
4452
+				array(),
4453
+				true
4454
+			);
4455
+		} else {
4456
+			EE_Error::add_error(
4457
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4458
+				__FILE__, __FUNCTION__, __LINE__
4459
+			);
4460
+			$this->_redirect_after_action(false, '', '', array(), true);
4461
+		}
4462
+	}
4463 4463
     
4464 4464
     
4465
-    /**
4466
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4467
-     * @since 4.9.0
4468
-     * @return array
4469
-     */
4470
-    protected function _get_msg_ids_from_request()
4471
-    {
4472
-        if ( ! isset($this->_req_data['MSG_ID'])) {
4473
-            return array();
4474
-        }
4475
-        
4476
-        return is_array($this->_req_data['MSG_ID'])
4477
-            ? array_keys($this->_req_data['MSG_ID'])
4478
-            : array($this->_req_data['MSG_ID']);
4479
-    }
4465
+	/**
4466
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4467
+	 * @since 4.9.0
4468
+	 * @return array
4469
+	 */
4470
+	protected function _get_msg_ids_from_request()
4471
+	{
4472
+		if ( ! isset($this->_req_data['MSG_ID'])) {
4473
+			return array();
4474
+		}
4475
+        
4476
+		return is_array($this->_req_data['MSG_ID'])
4477
+			? array_keys($this->_req_data['MSG_ID'])
4478
+			: array($this->_req_data['MSG_ID']);
4479
+	}
4480 4480
 }
Please login to merge, or discard this patch.
admin_pages/payments/Payments_Admin_Page.core.php 1 patch
Indentation   +999 added lines, -999 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -27,838 +27,838 @@  discard block
 block discarded – undo
27 27
 class Payments_Admin_Page extends EE_Admin_Page
28 28
 {
29 29
 
30
-    /**
31
-     * Variables used for when we're re-sorting the logs results, in case
32
-     * we needed to do two queries and we need to resort
33
-     *
34
-     * @var string
35
-     */
36
-    private $_sort_logs_again_direction;
37
-
38
-
39
-
40
-    /**
41
-     * @Constructor
42
-     * @access public
43
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
44
-     * @return \Payments_Admin_Page
45
-     */
46
-    public function __construct($routing = true)
47
-    {
48
-        parent::__construct($routing);
49
-    }
50
-
51
-
52
-
53
-    protected function _init_page_props()
54
-    {
55
-        $this->page_slug = EE_PAYMENTS_PG_SLUG;
56
-        $this->page_label = __('Payment Methods', 'event_espresso');
57
-        $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
58
-        $this->_admin_base_path = EE_PAYMENTS_ADMIN;
59
-    }
60
-
61
-
62
-
63
-    protected function _ajax_hooks()
64
-    {
65
-        //todo: all hooks for ajax goes here.
66
-    }
67
-
68
-
69
-
70
-    protected function _define_page_props()
71
-    {
72
-        $this->_admin_page_title = $this->page_label;
73
-        $this->_labels = array(
74
-            'publishbox' => __('Update Settings', 'event_espresso'),
75
-        );
76
-    }
77
-
78
-
79
-
80
-    protected function _set_page_routes()
81
-    {
82
-        /**
83
-         * note that with payment method capabilities, although we've implemented
84
-         * capability mapping which will be used for accessing payment methods owned by
85
-         * other users.  This is not fully implemented yet in the payment method ui.
86
-         * Currently only the "plural" caps are in active use.
87
-         * When cap mapping is implemented, some routes will need to use the singular form of
88
-         * capability method and also include the $id of the payment method for the route.
89
-         **/
90
-        $this->_page_routes = array(
91
-            'default'                   => array(
92
-                'func'       => '_payment_methods_list',
93
-                'capability' => 'ee_edit_payment_methods',
94
-            ),
95
-            'payment_settings'          => array(
96
-                'func'       => '_payment_settings',
97
-                'capability' => 'ee_manage_gateways',
98
-            ),
99
-            'activate_payment_method'   => array(
100
-                'func'       => '_activate_payment_method',
101
-                'noheader'   => true,
102
-                'capability' => 'ee_edit_payment_methods',
103
-            ),
104
-            'deactivate_payment_method' => array(
105
-                'func'       => '_deactivate_payment_method',
106
-                'noheader'   => true,
107
-                'capability' => 'ee_delete_payment_methods',
108
-            ),
109
-            'update_payment_method'     => array(
110
-                'func'               => '_update_payment_method',
111
-                'noheader'           => true,
112
-                'headers_sent_route' => 'default',
113
-                'capability'         => 'ee_edit_payment_methods',
114
-            ),
115
-            'update_payment_settings'   => array(
116
-                'func'       => '_update_payment_settings',
117
-                'noheader'   => true,
118
-                'capability' => 'ee_manage_gateways',
119
-            ),
120
-            'payment_log'               => array(
121
-                'func'       => '_payment_log_overview_list_table',
122
-                'capability' => 'ee_read_payment_methods',
123
-            ),
124
-            'payment_log_details'       => array(
125
-                'func'       => '_payment_log_details',
126
-                'capability' => 'ee_read_payment_methods',
127
-            ),
128
-        );
129
-    }
130
-
131
-
132
-
133
-    protected function _set_page_config()
134
-    {
135
-        $payment_method_list_config = array(
136
-            'nav'           => array(
137
-                'label' => __('Payment Methods', 'event_espresso'),
138
-                'order' => 10,
139
-            ),
140
-            'metaboxes'     => $this->_default_espresso_metaboxes,
141
-            'help_tabs'     => array_merge(
142
-                array(
143
-                    'payment_methods_overview_help_tab' => array(
144
-                        'title'    => __('Payment Methods Overview', 'event_espresso'),
145
-                        'filename' => 'payment_methods_overview',
146
-                    ),
147
-                ),
148
-                $this->_add_payment_method_help_tabs()),
149
-            'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
150
-            'require_nonce' => false,
151
-        );
152
-        $this->_page_config = array(
153
-            'default'          => $payment_method_list_config,
154
-            'payment_settings' => array(
155
-                'nav'           => array(
156
-                    'label' => __('Settings', 'event_espresso'),
157
-                    'order' => 20,
158
-                ),
159
-                'help_tabs'     => array(
160
-                    'payment_methods_settings_help_tab' => array(
161
-                        'title'    => __('Payment Method Settings', 'event_espresso'),
162
-                        'filename' => 'payment_methods_settings',
163
-                    ),
164
-                ),
165
-                //'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
166
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
167
-                'require_nonce' => false,
168
-            ),
169
-            'payment_log'      => array(
170
-                'nav'           => array(
171
-                    'label' => __("Logs", 'event_espresso'),
172
-                    'order' => 30,
173
-                ),
174
-                'list_table'    => 'Payment_Log_Admin_List_Table',
175
-                'metaboxes'     => $this->_default_espresso_metaboxes,
176
-                'require_nonce' => false,
177
-            ),
178
-        );
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     * @return array
185
-     */
186
-    protected function _add_payment_method_help_tabs()
187
-    {
188
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
189
-        $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
190
-        $all_pmt_help_tabs_config = array();
191
-        foreach ($payment_method_types as $payment_method_type) {
192
-            if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(),
193
-                'specific_payment_method_type_access')
194
-            ) {
195
-                continue;
196
-            }
197
-            foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
198
-                $template_args = isset($config['template_args']) ? $config['template_args'] : array();
199
-                $template_args['admin_page_obj'] = $this;
200
-                $all_pmt_help_tabs_config[$help_tab_name] = array(
201
-                    'title'   => $config['title'],
202
-                    'content' => EEH_Template::display_template(
203
-                        $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php',
204
-                        $template_args,
205
-                        true),
206
-                );
207
-            }
208
-        }
209
-        return $all_pmt_help_tabs_config;
210
-    }
211
-
212
-
213
-
214
-    //none of the below group are currently used for Gateway Settings
215
-    protected function _add_screen_options()
216
-    {
217
-    }
218
-
219
-
220
-
221
-    protected function _add_feature_pointers()
222
-    {
223
-    }
224
-
225
-
226
-
227
-    public function admin_init()
228
-    {
229
-    }
230
-
231
-
232
-
233
-    public function admin_notices()
234
-    {
235
-    }
236
-
237
-
238
-
239
-    public function admin_footer_scripts()
240
-    {
241
-    }
242
-
243
-
244
-
245
-    public function load_scripts_styles()
246
-    {
247
-        wp_enqueue_script('ee_admin_js');
248
-        wp_enqueue_script('ee-text-links');
249
-        wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
250
-            array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true);
251
-    }
252
-
253
-
254
-
255
-    public function load_scripts_styles_default()
256
-    {
257
-        //styles
258
-        wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(),
259
-            EVENT_ESPRESSO_VERSION);
260
-        wp_enqueue_style('espresso_payments');
261
-        wp_enqueue_style('ee-text-links');
262
-        //scripts
263
-    }
264
-
265
-
266
-
267
-    protected function _payment_methods_list()
268
-    {
269
-        /**
270
-         * first let's ensure payment methods have been setup. We do this here because when people activate a
271
-         * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due
272
-         * to the loading process.  However, people MUST setup the details for the payment method so its safe to do a
273
-         * recheck here.
274
-         */
275
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
276
-        EEM_Payment_Method::instance()->verify_button_urls();
277
-        //setup tabs, one for each payment method type
278
-        $tabs = array();
279
-        $payment_methods = array();
280
-        foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
281
-            // we don't want to show admin-only PMTs for now
282
-            if ($pmt_obj instanceof EE_PMT_Admin_Only) {
283
-                continue;
284
-            }
285
-            //check access
286
-            if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(),
287
-                'specific_payment_method_type_access')
288
-            ) {
289
-                continue;
290
-            }
291
-            //check for any active pms of that type
292
-            $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
293
-            if (! $payment_method instanceof EE_Payment_Method) {
294
-                $payment_method = EE_Payment_Method::new_instance(
295
-                    array(
296
-                        'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
297
-                        'PMD_type'       => $pmt_obj->system_name(),
298
-                        'PMD_name'       => $pmt_obj->pretty_name(),
299
-                        'PMD_admin_name' => $pmt_obj->pretty_name(),
300
-                    )
301
-                );
302
-            }
303
-            $payment_methods[$payment_method->slug()] = $payment_method;
304
-        }
305
-        $payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
306
-            $payment_methods);
307
-        foreach ($payment_methods as $payment_method) {
308
-            if ($payment_method instanceof EE_Payment_Method) {
309
-                add_meta_box(
310
-                //html id
311
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
312
-                    //title
313
-                    sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
314
-                    //callback
315
-                    array($this, 'payment_method_settings_meta_box'),
316
-                    //post type
317
-                    null,
318
-                    //context
319
-                    'normal',
320
-                    //priority
321
-                    'default',
322
-                    //callback args
323
-                    array('payment_method' => $payment_method)
324
-                );
325
-                //setup for tabbed content
326
-                $tabs[$payment_method->slug()] = array(
327
-                    'label' => $payment_method->admin_name(),
328
-                    'class' => $payment_method->active() ? 'gateway-active' : '',
329
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
330
-                    'title' => __('Modify this Payment Method', 'event_espresso'),
331
-                    'slug'  => $payment_method->slug(),
332
-                );
333
-            }
334
-        }
335
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links',
336
-            '|', $this->_get_active_payment_method_slug());
337
-        $this->display_admin_page_with_sidebar();
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     *   _get_active_payment_method_slug
344
-     *
345
-     * @return string
346
-     */
347
-    protected function _get_active_payment_method_slug()
348
-    {
349
-        $payment_method_slug = false;
350
-        //decide which payment method tab to open first, as dictated by the request's 'payment_method'
351
-        if (isset($this->_req_data['payment_method'])) {
352
-            // if they provided the current payment method, use it
353
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
354
-        }
355
-        $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
356
-        // if that didn't work or wasn't provided, find another way to select the current pm
357
-        if (! $this->_verify_payment_method($payment_method)) {
358
-            // like, looking for an active one
359
-            $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
360
-            // test that one as well
361
-            if ($this->_verify_payment_method($payment_method)) {
362
-                $payment_method_slug = $payment_method->slug();
363
-            } else {
364
-                $payment_method_slug = 'paypal_standard';
365
-            }
366
-        }
367
-        return $payment_method_slug;
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     *    payment_method_settings_meta_box
374
-     *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
375
-     *    capabilities to access it
376
-     *
377
-     * @param \EE_Payment_Method $payment_method
378
-     * @return boolean
379
-     */
380
-    protected function _verify_payment_method($payment_method)
381
-    {
382
-        if (
383
-            $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
384
-            && EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(),
385
-                'specific_payment_method_type_access')
386
-        ) {
387
-            return true;
388
-        }
389
-        return false;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     *    payment_method_settings_meta_box
396
-     *
397
-     * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
398
-     * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
399
-     *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
400
-     * @return string
401
-     * @throws EE_Error
402
-     */
403
-    public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
404
-    {
405
-        $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
406
-            ? $metabox['args']['payment_method'] : null;
407
-        if (! $payment_method instanceof EE_Payment_Method) {
408
-            throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied',
409
-                'event_espresso')));
410
-        }
411
-        $payment_method_scopes = $payment_method->active();
412
-        // if the payment method really exists show its form, otherwise the activation template
413
-        if ($payment_method->ID() && ! empty($payment_method_scopes)) {
414
-            $form = $this->_generate_payment_method_settings_form($payment_method);
415
-            if ($form->form_data_present_in($this->_req_data)) {
416
-                $form->receive_form_submission($this->_req_data);
417
-            }
418
-            echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
419
-        } else {
420
-            echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
421
-        }
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * Gets the form for all the settings related to this payment method type
428
-     *
429
-     * @access protected
430
-     * @param \EE_Payment_Method $payment_method
431
-     * @return \EE_Form_Section_Proper
432
-     */
433
-    protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
434
-    {
435
-        if (! $payment_method instanceof EE_Payment_Method) {
436
-            return new EE_Form_Section_Proper();
437
-        }
438
-        return new EE_Form_Section_Proper(
439
-            array(
440
-                'name'            => $payment_method->slug() . '_settings_form',
441
-                'html_id'         => $payment_method->slug() . '_settings_form',
442
-                'action'          => EE_Admin_Page::add_query_args_and_nonce(
443
-                    array(
444
-                        'action'         => 'update_payment_method',
445
-                        'payment_method' => $payment_method->slug(),
446
-                    ),
447
-                    EE_PAYMENTS_ADMIN_URL
448
-                ),
449
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
450
-                'subsections'     => apply_filters(
451
-                    'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
452
-                    array(
453
-                        'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
454
-                        'currency_support'        => $this->_currency_support($payment_method),
455
-                        'payment_method_settings' => $this->_payment_method_settings($payment_method),
456
-                        'update'                  => $this->_update_payment_method_button($payment_method),
457
-                        'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
458
-                        'fine_print'              => $this->_fine_print(),
459
-                    ),
460
-                    $payment_method
461
-                ),
462
-            )
463
-        );
464
-    }
465
-
466
-
467
-
468
-    /**
469
-     * _pci_dss_compliance
470
-     *
471
-     * @access protected
472
-     * @param \EE_Payment_Method $payment_method
473
-     * @return \EE_Form_Section_Proper
474
-     */
475
-    protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
476
-    {
477
-        if ($payment_method->type_obj()->requires_https()) {
478
-            return new EE_Form_Section_HTML(
479
-                EEH_HTML::tr(
480
-                    EEH_HTML::th(
481
-                        EEH_HTML::label(
482
-                            EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
483
-                        )
484
-                    ) .
485
-                    EEH_HTML::td(
486
-                        EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
487
-                            'event_espresso'))
488
-                        .
489
-                        EEH_HTML::br()
490
-                        .
491
-                        __('Learn more about ', 'event_espresso')
492
-                        . EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php',
493
-                            __('PCI DSS compliance', 'event_espresso'))
494
-                    )
495
-                )
496
-            );
497
-        } else {
498
-            return new EE_Form_Section_HTML('');
499
-        }
500
-    }
501
-
502
-
503
-
504
-    /**
505
-     * _currency_support
506
-     *
507
-     * @access protected
508
-     * @param \EE_Payment_Method $payment_method
509
-     * @return \EE_Form_Section_Proper
510
-     */
511
-    protected function _currency_support(EE_Payment_Method $payment_method)
512
-    {
513
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
514
-            return new EE_Form_Section_HTML(
515
-                EEH_HTML::tr(
516
-                    EEH_HTML::th(
517
-                        EEH_HTML::label(
518
-                            EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
519
-                        )
520
-                    ) .
521
-                    EEH_HTML::td(
522
-                        EEH_HTML::strong(
523
-                            sprintf(
524
-                                __('This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
525
-                                    'event_espresso'),
526
-                                EE_Config::instance()->currency->code
527
-                            )
528
-                        )
529
-                    )
530
-                )
531
-            );
532
-        } else {
533
-            return new EE_Form_Section_HTML('');
534
-        }
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * _update_payment_method_button
541
-     *
542
-     * @access protected
543
-     * @param \EE_Payment_Method $payment_method
544
-     * @return \EE_Form_Section_HTML
545
-     */
546
-    protected function _payment_method_settings(EE_Payment_Method $payment_method)
547
-    {
548
-        //modify the form so we only have/show fields that will be implemented for this version
549
-        return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
550
-    }
551
-
552
-
553
-
554
-    /**
555
-     * Simplifies the form to merely reproduce 4.1's gateway settings functionality
556
-     *
557
-     * @param EE_Form_Section_Proper $form_section
558
-     * @param string                 $payment_method_name
559
-     * @return \EE_Payment_Method_Form
560
-     * @throws \EE_Error
561
-     */
562
-    protected function _simplify_form($form_section, $payment_method_name = '')
563
-    {
564
-        if ($form_section instanceof EE_Payment_Method_Form) {
565
-            $form_section->exclude(
566
-                array(
567
-                    'PMD_type', //dont want them changing the type
568
-                    'PMD_slug', //or the slug (probably never)
569
-                    'PMD_wp_user', //or the user's ID
570
-                    'Currency' //or the currency, until the rest of EE supports simultaneous currencies
571
-                )
572
-            );
573
-            return $form_section;
574
-        } else {
575
-            throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
576
-                'event_espresso'), $payment_method_name));
577
-        }
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * _update_payment_method_button
584
-     *
585
-     * @access protected
586
-     * @param \EE_Payment_Method $payment_method
587
-     * @return \EE_Form_Section_HTML
588
-     */
589
-    protected function _update_payment_method_button(EE_Payment_Method $payment_method)
590
-    {
591
-        $update_button = new EE_Submit_Input(
592
-            array(
593
-                'name'       => 'submit',
594
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
595
-                'default'    => sprintf(__('Update %s Payment Settings', 'event_espresso'),
596
-                    $payment_method->admin_name()),
597
-                'html_label' => EEH_HTML::nbsp(),
598
-            )
599
-        );
600
-        return new EE_Form_Section_HTML(
601
-            EEH_HTML::no_row(EEH_HTML::br(2)) .
602
-            EEH_HTML::tr(
603
-                EEH_HTML::th(__('Update Settings', 'event_espresso')) .
604
-                EEH_HTML::td(
605
-                    $update_button->get_html_for_input()
606
-                )
607
-            )
608
-        );
609
-    }
610
-
611
-
612
-
613
-    /**
614
-     * _deactivate_payment_method_button
615
-     *
616
-     * @access protected
617
-     * @param \EE_Payment_Method $payment_method
618
-     * @return \EE_Form_Section_Proper
619
-     */
620
-    protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
621
-    {
622
-        $link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'),
623
-            $payment_method->admin_name());
624
-        return new EE_Form_Section_HTML(
625
-            EEH_HTML::tr(
626
-                EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
627
-                EEH_HTML::td(
628
-                    EEH_HTML::link(
629
-                        EE_Admin_Page::add_query_args_and_nonce(
630
-                            array(
631
-                                'action'         => 'deactivate_payment_method',
632
-                                'payment_method' => $payment_method->slug(),
633
-                            ),
634
-                            EE_PAYMENTS_ADMIN_URL
635
-                        ),
636
-                        $link_text_and_title,
637
-                        $link_text_and_title,
638
-                        'deactivate_' . $payment_method->slug(),
639
-                        'espresso-button button-secondary'
640
-                    )
641
-                )
642
-            )
643
-        );
644
-    }
645
-
646
-
647
-
648
-    /**
649
-     * _activate_payment_method_button
650
-     *
651
-     * @access protected
652
-     * @param \EE_Payment_Method $payment_method
653
-     * @return \EE_Form_Section_Proper
654
-     */
655
-    protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
656
-    {
657
-        $link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'),
658
-            $payment_method->admin_name());
659
-        return new EE_Form_Section_Proper(
660
-            array(
661
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
662
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
663
-                'action'          => '#',
664
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
665
-                'subsections'     => apply_filters(
666
-                    'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
667
-                    array(
668
-                        new EE_Form_Section_HTML(
669
-                            EEH_HTML::tr(
670
-                                EEH_HTML::td($payment_method->type_obj()->introductory_html(),
671
-                                    '',
672
-                                    '',
673
-                                    '',
674
-                                    'colspan="2"'
675
-                                )
676
-                            ) .
677
-                            EEH_HTML::tr(
678
-                                EEH_HTML::th(
679
-                                    EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
680
-                                ) .
681
-                                EEH_HTML::td(
682
-                                    EEH_HTML::link(
683
-                                        EE_Admin_Page::add_query_args_and_nonce(
684
-                                            array(
685
-                                                'action'              => 'activate_payment_method',
686
-                                                'payment_method_type' => $payment_method->type(),
687
-                                            ),
688
-                                            EE_PAYMENTS_ADMIN_URL
689
-                                        ),
690
-                                        $link_text_and_title,
691
-                                        $link_text_and_title,
692
-                                        'activate_' . $payment_method->slug(),
693
-                                        'espresso-button-green button-primary'
694
-                                    )
695
-                                )
696
-                            )
697
-                        ),
698
-                    ),
699
-                    $payment_method
700
-                ),
701
-            )
702
-        );
703
-    }
704
-
705
-
706
-
707
-    /**
708
-     * _fine_print
709
-     *
710
-     * @access protected
711
-     * @return \EE_Form_Section_HTML
712
-     */
713
-    protected function _fine_print()
714
-    {
715
-        return new EE_Form_Section_HTML(
716
-            EEH_HTML::tr(
717
-                EEH_HTML::th() .
718
-                EEH_HTML::td(
719
-                    EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
720
-                )
721
-            )
722
-        );
723
-    }
724
-
725
-
726
-
727
-    /**
728
-     * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
729
-     *
730
-     * @global WP_User $current_user
731
-     */
732
-    protected function _activate_payment_method()
733
-    {
734
-        if (isset($this->_req_data['payment_method_type'])) {
735
-            $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
736
-            //see if one exists
737
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
738
-            $payment_method = EE_Payment_Method_Manager::instance()
739
-                                                       ->activate_a_payment_method_of_type($payment_method_type);
740
-            $this->_redirect_after_action(1, 'Payment Method', 'activated',
741
-                array('action' => 'default', 'payment_method' => $payment_method->slug()));
742
-        } else {
743
-            $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
744
-        }
745
-    }
746
-
747
-
748
-
749
-    /**
750
-     * Deactivates the payment method with the specified slug, and redirects.
751
-     */
752
-    protected function _deactivate_payment_method()
753
-    {
754
-        if (isset($this->_req_data['payment_method'])) {
755
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
756
-            //deactivate it
757
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
758
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
759
-            $this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated',
760
-                array('action' => 'default', 'payment_method' => $payment_method_slug));
761
-        } else {
762
-            $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
763
-        }
764
-    }
765
-
766
-
767
-
768
-    /**
769
-     * Processes the payment method form that was submitted. This is slightly trickier than usual form
770
-     * processing because we first need to identify WHICH form was processed and which payment method
771
-     * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
772
-     * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
773
-     * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
774
-     * subsequently called 'headers_sent_func' which is _payment_methods_list)
775
-     *
776
-     * @return void
777
-     */
778
-    protected function _update_payment_method()
779
-    {
780
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
781
-            //ok let's find which gateway form to use based on the form input
782
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
783
-            /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
784
-            $correct_pmt_form_to_use = null;
785
-            $payment_method = null;
786
-            foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
787
-                //get the form and simplify it, like what we do when we display it
788
-                $pmt_form = $this->_generate_payment_method_settings_form($payment_method);
789
-                if ($pmt_form->form_data_present_in($this->_req_data)) {
790
-                    $correct_pmt_form_to_use = $pmt_form;
791
-                    break;
792
-                }
793
-            }
794
-            //if we couldn't find the correct payment method type...
795
-            if (! $correct_pmt_form_to_use) {
796
-                EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support",
797
-                    'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
798
-                $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
799
-            }
800
-            $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
801
-            if ($correct_pmt_form_to_use->is_valid()) {
802
-                $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
803
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
804
-                    throw new EE_Error(
805
-                        sprintf(
806
-                            __('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
807
-                                'event_espresso'),
808
-                            'payment_method_settings'
809
-                        )
810
-                    );
811
-                }
812
-                $payment_settings_subform->save();
813
-                /** @var $pm EE_Payment_Method */
814
-                $this->_redirect_after_action(true, 'Payment Method', 'updated',
815
-                    array('action' => 'default', 'payment_method' => $payment_method->slug()));
816
-            } else {
817
-                EE_Error::add_error(
818
-                    sprintf(
819
-                        __('Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
820
-                            'event_espresso'),
821
-                        $payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
822
-                            : __('"(unknown)"', 'event_espresso')
823
-                    ),
824
-                    __FILE__,
825
-                    __FUNCTION__,
826
-                    __LINE__
827
-                );
828
-            }
829
-        }
830
-        return;
831
-    }
832
-
833
-
834
-
835
-    protected function _payment_settings()
836
-    {
837
-        $this->_template_args['values'] = $this->_yes_no_values;
838
-        $this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options)
839
-            ? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : false;
840
-        $this->_set_add_edit_form_tags('update_payment_settings');
841
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
842
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH
843
-                                                                                     . 'payment_settings.template.php',
844
-            $this->_template_args, true);
845
-        $this->display_admin_page_with_sidebar();
846
-    }
847
-
848
-
849
-
850
-    /**
851
-     *        _update_payment_settings
852
-     *
853
-     * @access protected
854
-     * @return array
855
-     */
856
-    protected function _update_payment_settings()
857
-    {
858
-        EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options'])
859
-            ? $this->_req_data['show_pending_payment_options'] : false;
860
-        EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG',
861
-            EE_Registry::instance()->CFG);
30
+	/**
31
+	 * Variables used for when we're re-sorting the logs results, in case
32
+	 * we needed to do two queries and we need to resort
33
+	 *
34
+	 * @var string
35
+	 */
36
+	private $_sort_logs_again_direction;
37
+
38
+
39
+
40
+	/**
41
+	 * @Constructor
42
+	 * @access public
43
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
44
+	 * @return \Payments_Admin_Page
45
+	 */
46
+	public function __construct($routing = true)
47
+	{
48
+		parent::__construct($routing);
49
+	}
50
+
51
+
52
+
53
+	protected function _init_page_props()
54
+	{
55
+		$this->page_slug = EE_PAYMENTS_PG_SLUG;
56
+		$this->page_label = __('Payment Methods', 'event_espresso');
57
+		$this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
58
+		$this->_admin_base_path = EE_PAYMENTS_ADMIN;
59
+	}
60
+
61
+
62
+
63
+	protected function _ajax_hooks()
64
+	{
65
+		//todo: all hooks for ajax goes here.
66
+	}
67
+
68
+
69
+
70
+	protected function _define_page_props()
71
+	{
72
+		$this->_admin_page_title = $this->page_label;
73
+		$this->_labels = array(
74
+			'publishbox' => __('Update Settings', 'event_espresso'),
75
+		);
76
+	}
77
+
78
+
79
+
80
+	protected function _set_page_routes()
81
+	{
82
+		/**
83
+		 * note that with payment method capabilities, although we've implemented
84
+		 * capability mapping which will be used for accessing payment methods owned by
85
+		 * other users.  This is not fully implemented yet in the payment method ui.
86
+		 * Currently only the "plural" caps are in active use.
87
+		 * When cap mapping is implemented, some routes will need to use the singular form of
88
+		 * capability method and also include the $id of the payment method for the route.
89
+		 **/
90
+		$this->_page_routes = array(
91
+			'default'                   => array(
92
+				'func'       => '_payment_methods_list',
93
+				'capability' => 'ee_edit_payment_methods',
94
+			),
95
+			'payment_settings'          => array(
96
+				'func'       => '_payment_settings',
97
+				'capability' => 'ee_manage_gateways',
98
+			),
99
+			'activate_payment_method'   => array(
100
+				'func'       => '_activate_payment_method',
101
+				'noheader'   => true,
102
+				'capability' => 'ee_edit_payment_methods',
103
+			),
104
+			'deactivate_payment_method' => array(
105
+				'func'       => '_deactivate_payment_method',
106
+				'noheader'   => true,
107
+				'capability' => 'ee_delete_payment_methods',
108
+			),
109
+			'update_payment_method'     => array(
110
+				'func'               => '_update_payment_method',
111
+				'noheader'           => true,
112
+				'headers_sent_route' => 'default',
113
+				'capability'         => 'ee_edit_payment_methods',
114
+			),
115
+			'update_payment_settings'   => array(
116
+				'func'       => '_update_payment_settings',
117
+				'noheader'   => true,
118
+				'capability' => 'ee_manage_gateways',
119
+			),
120
+			'payment_log'               => array(
121
+				'func'       => '_payment_log_overview_list_table',
122
+				'capability' => 'ee_read_payment_methods',
123
+			),
124
+			'payment_log_details'       => array(
125
+				'func'       => '_payment_log_details',
126
+				'capability' => 'ee_read_payment_methods',
127
+			),
128
+		);
129
+	}
130
+
131
+
132
+
133
+	protected function _set_page_config()
134
+	{
135
+		$payment_method_list_config = array(
136
+			'nav'           => array(
137
+				'label' => __('Payment Methods', 'event_espresso'),
138
+				'order' => 10,
139
+			),
140
+			'metaboxes'     => $this->_default_espresso_metaboxes,
141
+			'help_tabs'     => array_merge(
142
+				array(
143
+					'payment_methods_overview_help_tab' => array(
144
+						'title'    => __('Payment Methods Overview', 'event_espresso'),
145
+						'filename' => 'payment_methods_overview',
146
+					),
147
+				),
148
+				$this->_add_payment_method_help_tabs()),
149
+			'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
150
+			'require_nonce' => false,
151
+		);
152
+		$this->_page_config = array(
153
+			'default'          => $payment_method_list_config,
154
+			'payment_settings' => array(
155
+				'nav'           => array(
156
+					'label' => __('Settings', 'event_espresso'),
157
+					'order' => 20,
158
+				),
159
+				'help_tabs'     => array(
160
+					'payment_methods_settings_help_tab' => array(
161
+						'title'    => __('Payment Method Settings', 'event_espresso'),
162
+						'filename' => 'payment_methods_settings',
163
+					),
164
+				),
165
+				//'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
166
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
167
+				'require_nonce' => false,
168
+			),
169
+			'payment_log'      => array(
170
+				'nav'           => array(
171
+					'label' => __("Logs", 'event_espresso'),
172
+					'order' => 30,
173
+				),
174
+				'list_table'    => 'Payment_Log_Admin_List_Table',
175
+				'metaboxes'     => $this->_default_espresso_metaboxes,
176
+				'require_nonce' => false,
177
+			),
178
+		);
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 * @return array
185
+	 */
186
+	protected function _add_payment_method_help_tabs()
187
+	{
188
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
189
+		$payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
190
+		$all_pmt_help_tabs_config = array();
191
+		foreach ($payment_method_types as $payment_method_type) {
192
+			if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(),
193
+				'specific_payment_method_type_access')
194
+			) {
195
+				continue;
196
+			}
197
+			foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
198
+				$template_args = isset($config['template_args']) ? $config['template_args'] : array();
199
+				$template_args['admin_page_obj'] = $this;
200
+				$all_pmt_help_tabs_config[$help_tab_name] = array(
201
+					'title'   => $config['title'],
202
+					'content' => EEH_Template::display_template(
203
+						$payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php',
204
+						$template_args,
205
+						true),
206
+				);
207
+			}
208
+		}
209
+		return $all_pmt_help_tabs_config;
210
+	}
211
+
212
+
213
+
214
+	//none of the below group are currently used for Gateway Settings
215
+	protected function _add_screen_options()
216
+	{
217
+	}
218
+
219
+
220
+
221
+	protected function _add_feature_pointers()
222
+	{
223
+	}
224
+
225
+
226
+
227
+	public function admin_init()
228
+	{
229
+	}
230
+
231
+
232
+
233
+	public function admin_notices()
234
+	{
235
+	}
236
+
237
+
238
+
239
+	public function admin_footer_scripts()
240
+	{
241
+	}
242
+
243
+
244
+
245
+	public function load_scripts_styles()
246
+	{
247
+		wp_enqueue_script('ee_admin_js');
248
+		wp_enqueue_script('ee-text-links');
249
+		wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
250
+			array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true);
251
+	}
252
+
253
+
254
+
255
+	public function load_scripts_styles_default()
256
+	{
257
+		//styles
258
+		wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(),
259
+			EVENT_ESPRESSO_VERSION);
260
+		wp_enqueue_style('espresso_payments');
261
+		wp_enqueue_style('ee-text-links');
262
+		//scripts
263
+	}
264
+
265
+
266
+
267
+	protected function _payment_methods_list()
268
+	{
269
+		/**
270
+		 * first let's ensure payment methods have been setup. We do this here because when people activate a
271
+		 * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due
272
+		 * to the loading process.  However, people MUST setup the details for the payment method so its safe to do a
273
+		 * recheck here.
274
+		 */
275
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
276
+		EEM_Payment_Method::instance()->verify_button_urls();
277
+		//setup tabs, one for each payment method type
278
+		$tabs = array();
279
+		$payment_methods = array();
280
+		foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
281
+			// we don't want to show admin-only PMTs for now
282
+			if ($pmt_obj instanceof EE_PMT_Admin_Only) {
283
+				continue;
284
+			}
285
+			//check access
286
+			if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(),
287
+				'specific_payment_method_type_access')
288
+			) {
289
+				continue;
290
+			}
291
+			//check for any active pms of that type
292
+			$payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
293
+			if (! $payment_method instanceof EE_Payment_Method) {
294
+				$payment_method = EE_Payment_Method::new_instance(
295
+					array(
296
+						'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
297
+						'PMD_type'       => $pmt_obj->system_name(),
298
+						'PMD_name'       => $pmt_obj->pretty_name(),
299
+						'PMD_admin_name' => $pmt_obj->pretty_name(),
300
+					)
301
+				);
302
+			}
303
+			$payment_methods[$payment_method->slug()] = $payment_method;
304
+		}
305
+		$payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
306
+			$payment_methods);
307
+		foreach ($payment_methods as $payment_method) {
308
+			if ($payment_method instanceof EE_Payment_Method) {
309
+				add_meta_box(
310
+				//html id
311
+					'espresso_' . $payment_method->slug() . '_payment_settings',
312
+					//title
313
+					sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
314
+					//callback
315
+					array($this, 'payment_method_settings_meta_box'),
316
+					//post type
317
+					null,
318
+					//context
319
+					'normal',
320
+					//priority
321
+					'default',
322
+					//callback args
323
+					array('payment_method' => $payment_method)
324
+				);
325
+				//setup for tabbed content
326
+				$tabs[$payment_method->slug()] = array(
327
+					'label' => $payment_method->admin_name(),
328
+					'class' => $payment_method->active() ? 'gateway-active' : '',
329
+					'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
330
+					'title' => __('Modify this Payment Method', 'event_espresso'),
331
+					'slug'  => $payment_method->slug(),
332
+				);
333
+			}
334
+		}
335
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links',
336
+			'|', $this->_get_active_payment_method_slug());
337
+		$this->display_admin_page_with_sidebar();
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 *   _get_active_payment_method_slug
344
+	 *
345
+	 * @return string
346
+	 */
347
+	protected function _get_active_payment_method_slug()
348
+	{
349
+		$payment_method_slug = false;
350
+		//decide which payment method tab to open first, as dictated by the request's 'payment_method'
351
+		if (isset($this->_req_data['payment_method'])) {
352
+			// if they provided the current payment method, use it
353
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
354
+		}
355
+		$payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
356
+		// if that didn't work or wasn't provided, find another way to select the current pm
357
+		if (! $this->_verify_payment_method($payment_method)) {
358
+			// like, looking for an active one
359
+			$payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
360
+			// test that one as well
361
+			if ($this->_verify_payment_method($payment_method)) {
362
+				$payment_method_slug = $payment_method->slug();
363
+			} else {
364
+				$payment_method_slug = 'paypal_standard';
365
+			}
366
+		}
367
+		return $payment_method_slug;
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 *    payment_method_settings_meta_box
374
+	 *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
375
+	 *    capabilities to access it
376
+	 *
377
+	 * @param \EE_Payment_Method $payment_method
378
+	 * @return boolean
379
+	 */
380
+	protected function _verify_payment_method($payment_method)
381
+	{
382
+		if (
383
+			$payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
384
+			&& EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(),
385
+				'specific_payment_method_type_access')
386
+		) {
387
+			return true;
388
+		}
389
+		return false;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 *    payment_method_settings_meta_box
396
+	 *
397
+	 * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
398
+	 * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
399
+	 *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
400
+	 * @return string
401
+	 * @throws EE_Error
402
+	 */
403
+	public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
404
+	{
405
+		$payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
406
+			? $metabox['args']['payment_method'] : null;
407
+		if (! $payment_method instanceof EE_Payment_Method) {
408
+			throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied',
409
+				'event_espresso')));
410
+		}
411
+		$payment_method_scopes = $payment_method->active();
412
+		// if the payment method really exists show its form, otherwise the activation template
413
+		if ($payment_method->ID() && ! empty($payment_method_scopes)) {
414
+			$form = $this->_generate_payment_method_settings_form($payment_method);
415
+			if ($form->form_data_present_in($this->_req_data)) {
416
+				$form->receive_form_submission($this->_req_data);
417
+			}
418
+			echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
419
+		} else {
420
+			echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
421
+		}
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * Gets the form for all the settings related to this payment method type
428
+	 *
429
+	 * @access protected
430
+	 * @param \EE_Payment_Method $payment_method
431
+	 * @return \EE_Form_Section_Proper
432
+	 */
433
+	protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
434
+	{
435
+		if (! $payment_method instanceof EE_Payment_Method) {
436
+			return new EE_Form_Section_Proper();
437
+		}
438
+		return new EE_Form_Section_Proper(
439
+			array(
440
+				'name'            => $payment_method->slug() . '_settings_form',
441
+				'html_id'         => $payment_method->slug() . '_settings_form',
442
+				'action'          => EE_Admin_Page::add_query_args_and_nonce(
443
+					array(
444
+						'action'         => 'update_payment_method',
445
+						'payment_method' => $payment_method->slug(),
446
+					),
447
+					EE_PAYMENTS_ADMIN_URL
448
+				),
449
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
450
+				'subsections'     => apply_filters(
451
+					'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
452
+					array(
453
+						'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
454
+						'currency_support'        => $this->_currency_support($payment_method),
455
+						'payment_method_settings' => $this->_payment_method_settings($payment_method),
456
+						'update'                  => $this->_update_payment_method_button($payment_method),
457
+						'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
458
+						'fine_print'              => $this->_fine_print(),
459
+					),
460
+					$payment_method
461
+				),
462
+			)
463
+		);
464
+	}
465
+
466
+
467
+
468
+	/**
469
+	 * _pci_dss_compliance
470
+	 *
471
+	 * @access protected
472
+	 * @param \EE_Payment_Method $payment_method
473
+	 * @return \EE_Form_Section_Proper
474
+	 */
475
+	protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
476
+	{
477
+		if ($payment_method->type_obj()->requires_https()) {
478
+			return new EE_Form_Section_HTML(
479
+				EEH_HTML::tr(
480
+					EEH_HTML::th(
481
+						EEH_HTML::label(
482
+							EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
483
+						)
484
+					) .
485
+					EEH_HTML::td(
486
+						EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
487
+							'event_espresso'))
488
+						.
489
+						EEH_HTML::br()
490
+						.
491
+						__('Learn more about ', 'event_espresso')
492
+						. EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php',
493
+							__('PCI DSS compliance', 'event_espresso'))
494
+					)
495
+				)
496
+			);
497
+		} else {
498
+			return new EE_Form_Section_HTML('');
499
+		}
500
+	}
501
+
502
+
503
+
504
+	/**
505
+	 * _currency_support
506
+	 *
507
+	 * @access protected
508
+	 * @param \EE_Payment_Method $payment_method
509
+	 * @return \EE_Form_Section_Proper
510
+	 */
511
+	protected function _currency_support(EE_Payment_Method $payment_method)
512
+	{
513
+		if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
514
+			return new EE_Form_Section_HTML(
515
+				EEH_HTML::tr(
516
+					EEH_HTML::th(
517
+						EEH_HTML::label(
518
+							EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
519
+						)
520
+					) .
521
+					EEH_HTML::td(
522
+						EEH_HTML::strong(
523
+							sprintf(
524
+								__('This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
525
+									'event_espresso'),
526
+								EE_Config::instance()->currency->code
527
+							)
528
+						)
529
+					)
530
+				)
531
+			);
532
+		} else {
533
+			return new EE_Form_Section_HTML('');
534
+		}
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * _update_payment_method_button
541
+	 *
542
+	 * @access protected
543
+	 * @param \EE_Payment_Method $payment_method
544
+	 * @return \EE_Form_Section_HTML
545
+	 */
546
+	protected function _payment_method_settings(EE_Payment_Method $payment_method)
547
+	{
548
+		//modify the form so we only have/show fields that will be implemented for this version
549
+		return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
550
+	}
551
+
552
+
553
+
554
+	/**
555
+	 * Simplifies the form to merely reproduce 4.1's gateway settings functionality
556
+	 *
557
+	 * @param EE_Form_Section_Proper $form_section
558
+	 * @param string                 $payment_method_name
559
+	 * @return \EE_Payment_Method_Form
560
+	 * @throws \EE_Error
561
+	 */
562
+	protected function _simplify_form($form_section, $payment_method_name = '')
563
+	{
564
+		if ($form_section instanceof EE_Payment_Method_Form) {
565
+			$form_section->exclude(
566
+				array(
567
+					'PMD_type', //dont want them changing the type
568
+					'PMD_slug', //or the slug (probably never)
569
+					'PMD_wp_user', //or the user's ID
570
+					'Currency' //or the currency, until the rest of EE supports simultaneous currencies
571
+				)
572
+			);
573
+			return $form_section;
574
+		} else {
575
+			throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
576
+				'event_espresso'), $payment_method_name));
577
+		}
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * _update_payment_method_button
584
+	 *
585
+	 * @access protected
586
+	 * @param \EE_Payment_Method $payment_method
587
+	 * @return \EE_Form_Section_HTML
588
+	 */
589
+	protected function _update_payment_method_button(EE_Payment_Method $payment_method)
590
+	{
591
+		$update_button = new EE_Submit_Input(
592
+			array(
593
+				'name'       => 'submit',
594
+				'html_id'    => 'save_' . $payment_method->slug() . '_settings',
595
+				'default'    => sprintf(__('Update %s Payment Settings', 'event_espresso'),
596
+					$payment_method->admin_name()),
597
+				'html_label' => EEH_HTML::nbsp(),
598
+			)
599
+		);
600
+		return new EE_Form_Section_HTML(
601
+			EEH_HTML::no_row(EEH_HTML::br(2)) .
602
+			EEH_HTML::tr(
603
+				EEH_HTML::th(__('Update Settings', 'event_espresso')) .
604
+				EEH_HTML::td(
605
+					$update_button->get_html_for_input()
606
+				)
607
+			)
608
+		);
609
+	}
610
+
611
+
612
+
613
+	/**
614
+	 * _deactivate_payment_method_button
615
+	 *
616
+	 * @access protected
617
+	 * @param \EE_Payment_Method $payment_method
618
+	 * @return \EE_Form_Section_Proper
619
+	 */
620
+	protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
621
+	{
622
+		$link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'),
623
+			$payment_method->admin_name());
624
+		return new EE_Form_Section_HTML(
625
+			EEH_HTML::tr(
626
+				EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
627
+				EEH_HTML::td(
628
+					EEH_HTML::link(
629
+						EE_Admin_Page::add_query_args_and_nonce(
630
+							array(
631
+								'action'         => 'deactivate_payment_method',
632
+								'payment_method' => $payment_method->slug(),
633
+							),
634
+							EE_PAYMENTS_ADMIN_URL
635
+						),
636
+						$link_text_and_title,
637
+						$link_text_and_title,
638
+						'deactivate_' . $payment_method->slug(),
639
+						'espresso-button button-secondary'
640
+					)
641
+				)
642
+			)
643
+		);
644
+	}
645
+
646
+
647
+
648
+	/**
649
+	 * _activate_payment_method_button
650
+	 *
651
+	 * @access protected
652
+	 * @param \EE_Payment_Method $payment_method
653
+	 * @return \EE_Form_Section_Proper
654
+	 */
655
+	protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
656
+	{
657
+		$link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'),
658
+			$payment_method->admin_name());
659
+		return new EE_Form_Section_Proper(
660
+			array(
661
+				'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
662
+				'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
663
+				'action'          => '#',
664
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
665
+				'subsections'     => apply_filters(
666
+					'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
667
+					array(
668
+						new EE_Form_Section_HTML(
669
+							EEH_HTML::tr(
670
+								EEH_HTML::td($payment_method->type_obj()->introductory_html(),
671
+									'',
672
+									'',
673
+									'',
674
+									'colspan="2"'
675
+								)
676
+							) .
677
+							EEH_HTML::tr(
678
+								EEH_HTML::th(
679
+									EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
680
+								) .
681
+								EEH_HTML::td(
682
+									EEH_HTML::link(
683
+										EE_Admin_Page::add_query_args_and_nonce(
684
+											array(
685
+												'action'              => 'activate_payment_method',
686
+												'payment_method_type' => $payment_method->type(),
687
+											),
688
+											EE_PAYMENTS_ADMIN_URL
689
+										),
690
+										$link_text_and_title,
691
+										$link_text_and_title,
692
+										'activate_' . $payment_method->slug(),
693
+										'espresso-button-green button-primary'
694
+									)
695
+								)
696
+							)
697
+						),
698
+					),
699
+					$payment_method
700
+				),
701
+			)
702
+		);
703
+	}
704
+
705
+
706
+
707
+	/**
708
+	 * _fine_print
709
+	 *
710
+	 * @access protected
711
+	 * @return \EE_Form_Section_HTML
712
+	 */
713
+	protected function _fine_print()
714
+	{
715
+		return new EE_Form_Section_HTML(
716
+			EEH_HTML::tr(
717
+				EEH_HTML::th() .
718
+				EEH_HTML::td(
719
+					EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
720
+				)
721
+			)
722
+		);
723
+	}
724
+
725
+
726
+
727
+	/**
728
+	 * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
729
+	 *
730
+	 * @global WP_User $current_user
731
+	 */
732
+	protected function _activate_payment_method()
733
+	{
734
+		if (isset($this->_req_data['payment_method_type'])) {
735
+			$payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
736
+			//see if one exists
737
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
738
+			$payment_method = EE_Payment_Method_Manager::instance()
739
+													   ->activate_a_payment_method_of_type($payment_method_type);
740
+			$this->_redirect_after_action(1, 'Payment Method', 'activated',
741
+				array('action' => 'default', 'payment_method' => $payment_method->slug()));
742
+		} else {
743
+			$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
744
+		}
745
+	}
746
+
747
+
748
+
749
+	/**
750
+	 * Deactivates the payment method with the specified slug, and redirects.
751
+	 */
752
+	protected function _deactivate_payment_method()
753
+	{
754
+		if (isset($this->_req_data['payment_method'])) {
755
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
756
+			//deactivate it
757
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
758
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
759
+			$this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated',
760
+				array('action' => 'default', 'payment_method' => $payment_method_slug));
761
+		} else {
762
+			$this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
763
+		}
764
+	}
765
+
766
+
767
+
768
+	/**
769
+	 * Processes the payment method form that was submitted. This is slightly trickier than usual form
770
+	 * processing because we first need to identify WHICH form was processed and which payment method
771
+	 * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
772
+	 * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
773
+	 * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
774
+	 * subsequently called 'headers_sent_func' which is _payment_methods_list)
775
+	 *
776
+	 * @return void
777
+	 */
778
+	protected function _update_payment_method()
779
+	{
780
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
781
+			//ok let's find which gateway form to use based on the form input
782
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
783
+			/** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
784
+			$correct_pmt_form_to_use = null;
785
+			$payment_method = null;
786
+			foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
787
+				//get the form and simplify it, like what we do when we display it
788
+				$pmt_form = $this->_generate_payment_method_settings_form($payment_method);
789
+				if ($pmt_form->form_data_present_in($this->_req_data)) {
790
+					$correct_pmt_form_to_use = $pmt_form;
791
+					break;
792
+				}
793
+			}
794
+			//if we couldn't find the correct payment method type...
795
+			if (! $correct_pmt_form_to_use) {
796
+				EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support",
797
+					'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
798
+				$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
799
+			}
800
+			$correct_pmt_form_to_use->receive_form_submission($this->_req_data);
801
+			if ($correct_pmt_form_to_use->is_valid()) {
802
+				$payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
803
+				if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
804
+					throw new EE_Error(
805
+						sprintf(
806
+							__('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
807
+								'event_espresso'),
808
+							'payment_method_settings'
809
+						)
810
+					);
811
+				}
812
+				$payment_settings_subform->save();
813
+				/** @var $pm EE_Payment_Method */
814
+				$this->_redirect_after_action(true, 'Payment Method', 'updated',
815
+					array('action' => 'default', 'payment_method' => $payment_method->slug()));
816
+			} else {
817
+				EE_Error::add_error(
818
+					sprintf(
819
+						__('Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
820
+							'event_espresso'),
821
+						$payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
822
+							: __('"(unknown)"', 'event_espresso')
823
+					),
824
+					__FILE__,
825
+					__FUNCTION__,
826
+					__LINE__
827
+				);
828
+			}
829
+		}
830
+		return;
831
+	}
832
+
833
+
834
+
835
+	protected function _payment_settings()
836
+	{
837
+		$this->_template_args['values'] = $this->_yes_no_values;
838
+		$this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options)
839
+			? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : false;
840
+		$this->_set_add_edit_form_tags('update_payment_settings');
841
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
842
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH
843
+																					 . 'payment_settings.template.php',
844
+			$this->_template_args, true);
845
+		$this->display_admin_page_with_sidebar();
846
+	}
847
+
848
+
849
+
850
+	/**
851
+	 *        _update_payment_settings
852
+	 *
853
+	 * @access protected
854
+	 * @return array
855
+	 */
856
+	protected function _update_payment_settings()
857
+	{
858
+		EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options'])
859
+			? $this->_req_data['show_pending_payment_options'] : false;
860
+		EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG',
861
+			EE_Registry::instance()->CFG);
862 862
 //		 $superform = new EE_Form_Section_Proper(
863 863
 //		 	array(
864 864
 //		 		'subsections' => array(
@@ -876,176 +876,176 @@  discard block
 block discarded – undo
876 876
 //		 	);
877 877
 //		 	$this->_redirect_after_action( 0, 'settings', 'updated', array( 'action' => 'payment_settings' ) );
878 878
 //		 }
879
-        $what = __('Payment Settings', 'event_espresso');
880
-        $success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__,
881
-            __LINE__);
882
-        $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'),
883
-            array('action' => 'payment_settings'));
884
-    }
879
+		$what = __('Payment Settings', 'event_espresso');
880
+		$success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__,
881
+			__LINE__);
882
+		$this->_redirect_after_action($success, $what, __('updated', 'event_espresso'),
883
+			array('action' => 'payment_settings'));
884
+	}
885 885
 
886 886
 
887 887
 
888
-    protected function _payment_log_overview_list_table()
889
-    {
888
+	protected function _payment_log_overview_list_table()
889
+	{
890 890
 //		$this->_search_btn_label = __('Payment Log', 'event_espresso');
891
-        $this->display_admin_list_table_page_with_sidebar();
892
-    }
893
-
894
-
895
-
896
-    protected function _set_list_table_views_payment_log()
897
-    {
898
-        $this->_views = array(
899
-            'all' => array(
900
-                'slug'  => 'all',
901
-                'label' => __('View All Logs', 'event_espresso'),
902
-                'count' => 0,
903
-            ),
904
-        );
905
-    }
906
-
907
-
908
-
909
-    /**
910
-     * @param int  $per_page
911
-     * @param int  $current_page
912
-     * @param bool $count
913
-     * @return array
914
-     */
915
-    public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
916
-    {
917
-        EE_Registry::instance()->load_model('Change_Log');
918
-        //we may need to do multiple queries (joining differently), so we actually wan tan array of query params
919
-        $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
920
-        //check if they've selected a specific payment method
921
-        if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
922
-            $query_params[0]['OR*pm_or_pay_pm'] = array(
923
-                'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
924
-                'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
925
-            );
926
-        }
927
-        //take into account search
928
-        if (isset($this->_req_data['s']) && $this->_req_data['s']) {
929
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
930
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
931
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
932
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
933
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
934
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
935
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
936
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
937
-            $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
938
-            $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
939
-            $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
940
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
941
-        }
942
-        if (isset($this->_req_data['payment-filter-start-date'])
943
-            && isset($this->_req_data['payment-filter-end-date'])
944
-        ) {
945
-            //add date
946
-            $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
947
-            $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
948
-            //make sure our timestamps start and end right at the boundaries for each day
949
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
950
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
951
-            //convert to timestamps
952
-            $start_date = strtotime($start_date);
953
-            $end_date = strtotime($end_date);
954
-            //makes sure start date is the lowest value and vice versa
955
-            $start_date = min($start_date, $end_date);
956
-            $end_date = max($start_date, $end_date);
957
-            //convert for query
958
-            $start_date = EEM_Change_Log::instance()
959
-                                        ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date),
960
-                                            'Y-m-d H:i:s');
961
-            $end_date = EEM_Change_Log::instance()
962
-                                      ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date),
963
-                                          'Y-m-d H:i:s');
964
-            $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
965
-        }
966
-        if ($count) {
967
-            return EEM_Change_Log::instance()->count($query_params);
968
-        }
969
-        if (isset($this->_req_data['order'])) {
970
-            $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
971
-                : 'DESC';
972
-            $query_params['order_by'] = array('LOG_time' => $sort);
973
-        } else {
974
-            $query_params['order_by'] = array('LOG_time' => 'DESC');
975
-        }
976
-        $offset = ($current_page - 1) * $per_page;
977
-        if (! isset($this->_req_data['download_results'])) {
978
-            $query_params['limit'] = array($offset, $per_page);
979
-        }
980
-        //now they've requested to instead just download the file instead of viewing it.
981
-        if (isset($this->_req_data['download_results'])) {
982
-            $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
983
-            header('Content-Disposition: attachment');
984
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
985
-            echo "<h1>Payment Logs for " . site_url() . "</h1>";
986
-            echo "<h3>Query:</h3>";
987
-            var_dump($query_params);
988
-            echo "<h3>Results:</h3>";
989
-            var_dump($wpdb_results);
990
-            die;
991
-        }
992
-        $results = EEM_Change_Log::instance()->get_all($query_params);
993
-        return $results;
994
-    }
995
-
996
-
997
-
998
-    /**
999
-     * Used by usort to RE-sort log query results, because we lose the ordering
1000
-     * because we're possibly combining the results from two queries
1001
-     *
1002
-     * @param EE_Change_Log $logA
1003
-     * @param EE_Change_Log $logB
1004
-     * @return int
1005
-     */
1006
-    protected function _sort_logs_again($logA, $logB)
1007
-    {
1008
-        $timeA = $logA->get_raw('LOG_time');
1009
-        $timeB = $logB->get_raw('LOG_time');
1010
-        if ($timeA == $timeB) {
1011
-            return 0;
1012
-        }
1013
-        $comparison = $timeA < $timeB ? -1 : 1;
1014
-        if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1015
-            return $comparison * -1;
1016
-        } else {
1017
-            return $comparison;
1018
-        }
1019
-    }
1020
-
1021
-
1022
-
1023
-    protected function _payment_log_details()
1024
-    {
1025
-        EE_Registry::instance()->load_model('Change_Log');
1026
-        /** @var $payment_log EE_Change_Log */
1027
-        $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1028
-        $payment_method = null;
1029
-        $transaction = null;
1030
-        if ($payment_log instanceof EE_Change_Log) {
1031
-            if ($payment_log->object() instanceof EE_Payment) {
1032
-                $payment_method = $payment_log->object()->payment_method();
1033
-                $transaction = $payment_log->object()->transaction();
1034
-            } elseif ($payment_log->object() instanceof EE_Payment_Method) {
1035
-                $payment_method = $payment_log->object();
1036
-            }
1037
-        }
1038
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1039
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1040
-            array(
1041
-                'payment_log'    => $payment_log,
1042
-                'payment_method' => $payment_method,
1043
-                'transaction'    => $transaction,
1044
-            ),
1045
-            true
1046
-        );
1047
-        $this->display_admin_page_with_sidebar();
1048
-    }
891
+		$this->display_admin_list_table_page_with_sidebar();
892
+	}
893
+
894
+
895
+
896
+	protected function _set_list_table_views_payment_log()
897
+	{
898
+		$this->_views = array(
899
+			'all' => array(
900
+				'slug'  => 'all',
901
+				'label' => __('View All Logs', 'event_espresso'),
902
+				'count' => 0,
903
+			),
904
+		);
905
+	}
906
+
907
+
908
+
909
+	/**
910
+	 * @param int  $per_page
911
+	 * @param int  $current_page
912
+	 * @param bool $count
913
+	 * @return array
914
+	 */
915
+	public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
916
+	{
917
+		EE_Registry::instance()->load_model('Change_Log');
918
+		//we may need to do multiple queries (joining differently), so we actually wan tan array of query params
919
+		$query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
920
+		//check if they've selected a specific payment method
921
+		if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
922
+			$query_params[0]['OR*pm_or_pay_pm'] = array(
923
+				'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
924
+				'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
925
+			);
926
+		}
927
+		//take into account search
928
+		if (isset($this->_req_data['s']) && $this->_req_data['s']) {
929
+			$similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
930
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
931
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
932
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
933
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
934
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
935
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
936
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
937
+			$query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
938
+			$query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
939
+			$query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
940
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
941
+		}
942
+		if (isset($this->_req_data['payment-filter-start-date'])
943
+			&& isset($this->_req_data['payment-filter-end-date'])
944
+		) {
945
+			//add date
946
+			$start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
947
+			$end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
948
+			//make sure our timestamps start and end right at the boundaries for each day
949
+			$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
950
+			$end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
951
+			//convert to timestamps
952
+			$start_date = strtotime($start_date);
953
+			$end_date = strtotime($end_date);
954
+			//makes sure start date is the lowest value and vice versa
955
+			$start_date = min($start_date, $end_date);
956
+			$end_date = max($start_date, $end_date);
957
+			//convert for query
958
+			$start_date = EEM_Change_Log::instance()
959
+										->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date),
960
+											'Y-m-d H:i:s');
961
+			$end_date = EEM_Change_Log::instance()
962
+									  ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date),
963
+										  'Y-m-d H:i:s');
964
+			$query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
965
+		}
966
+		if ($count) {
967
+			return EEM_Change_Log::instance()->count($query_params);
968
+		}
969
+		if (isset($this->_req_data['order'])) {
970
+			$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
971
+				: 'DESC';
972
+			$query_params['order_by'] = array('LOG_time' => $sort);
973
+		} else {
974
+			$query_params['order_by'] = array('LOG_time' => 'DESC');
975
+		}
976
+		$offset = ($current_page - 1) * $per_page;
977
+		if (! isset($this->_req_data['download_results'])) {
978
+			$query_params['limit'] = array($offset, $per_page);
979
+		}
980
+		//now they've requested to instead just download the file instead of viewing it.
981
+		if (isset($this->_req_data['download_results'])) {
982
+			$wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
983
+			header('Content-Disposition: attachment');
984
+			header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
985
+			echo "<h1>Payment Logs for " . site_url() . "</h1>";
986
+			echo "<h3>Query:</h3>";
987
+			var_dump($query_params);
988
+			echo "<h3>Results:</h3>";
989
+			var_dump($wpdb_results);
990
+			die;
991
+		}
992
+		$results = EEM_Change_Log::instance()->get_all($query_params);
993
+		return $results;
994
+	}
995
+
996
+
997
+
998
+	/**
999
+	 * Used by usort to RE-sort log query results, because we lose the ordering
1000
+	 * because we're possibly combining the results from two queries
1001
+	 *
1002
+	 * @param EE_Change_Log $logA
1003
+	 * @param EE_Change_Log $logB
1004
+	 * @return int
1005
+	 */
1006
+	protected function _sort_logs_again($logA, $logB)
1007
+	{
1008
+		$timeA = $logA->get_raw('LOG_time');
1009
+		$timeB = $logB->get_raw('LOG_time');
1010
+		if ($timeA == $timeB) {
1011
+			return 0;
1012
+		}
1013
+		$comparison = $timeA < $timeB ? -1 : 1;
1014
+		if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1015
+			return $comparison * -1;
1016
+		} else {
1017
+			return $comparison;
1018
+		}
1019
+	}
1020
+
1021
+
1022
+
1023
+	protected function _payment_log_details()
1024
+	{
1025
+		EE_Registry::instance()->load_model('Change_Log');
1026
+		/** @var $payment_log EE_Change_Log */
1027
+		$payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1028
+		$payment_method = null;
1029
+		$transaction = null;
1030
+		if ($payment_log instanceof EE_Change_Log) {
1031
+			if ($payment_log->object() instanceof EE_Payment) {
1032
+				$payment_method = $payment_log->object()->payment_method();
1033
+				$transaction = $payment_log->object()->transaction();
1034
+			} elseif ($payment_log->object() instanceof EE_Payment_Method) {
1035
+				$payment_method = $payment_log->object();
1036
+			}
1037
+		}
1038
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1039
+			EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1040
+			array(
1041
+				'payment_log'    => $payment_log,
1042
+				'payment_method' => $payment_method,
1043
+				'transaction'    => $transaction,
1044
+			),
1045
+			true
1046
+		);
1047
+		$this->display_admin_page_with_sidebar();
1048
+	}
1049 1049
 
1050 1050
 
1051 1051
 } //end Payments_Admin_Page class
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4120 added lines, -4120 removed lines patch added patch discarded remove patch
@@ -20,4205 +20,4205 @@
 block discarded – undo
20 20
 {
21 21
 
22 22
 
23
-    //set in _init_page_props()
24
-    public $page_slug;
23
+	//set in _init_page_props()
24
+	public $page_slug;
25 25
 
26
-    public $page_label;
26
+	public $page_label;
27 27
 
28
-    public $page_folder;
28
+	public $page_folder;
29 29
 
30
-    //set in define_page_props()
31
-    protected $_admin_base_url;
30
+	//set in define_page_props()
31
+	protected $_admin_base_url;
32 32
 
33
-    protected $_admin_base_path;
33
+	protected $_admin_base_path;
34 34
 
35
-    protected $_admin_page_title;
35
+	protected $_admin_page_title;
36 36
 
37
-    protected $_labels;
37
+	protected $_labels;
38 38
 
39 39
 
40
-    //set early within EE_Admin_Init
41
-    protected $_wp_page_slug;
40
+	//set early within EE_Admin_Init
41
+	protected $_wp_page_slug;
42 42
 
43
-    //navtabs
44
-    protected $_nav_tabs;
43
+	//navtabs
44
+	protected $_nav_tabs;
45 45
 
46
-    protected $_default_nav_tab_name;
46
+	protected $_default_nav_tab_name;
47 47
 
48
-    /**
49
-     * @var array $_help_tour
50
-     */
51
-    protected $_help_tour = array();
48
+	/**
49
+	 * @var array $_help_tour
50
+	 */
51
+	protected $_help_tour = array();
52 52
 
53 53
 
54
-    //template variables (used by templates)
55
-    protected $_template_path;
54
+	//template variables (used by templates)
55
+	protected $_template_path;
56 56
 
57
-    protected $_column_template_path;
57
+	protected $_column_template_path;
58 58
 
59
-    /**
60
-     * @var array $_template_args
61
-     */
62
-    protected $_template_args = array();
59
+	/**
60
+	 * @var array $_template_args
61
+	 */
62
+	protected $_template_args = array();
63 63
 
64
-    /**
65
-     * this will hold the list table object for a given view.
66
-     *
67
-     * @var EE_Admin_List_Table $_list_table_object
68
-     */
69
-    protected $_list_table_object;
64
+	/**
65
+	 * this will hold the list table object for a given view.
66
+	 *
67
+	 * @var EE_Admin_List_Table $_list_table_object
68
+	 */
69
+	protected $_list_table_object;
70 70
 
71
-    //bools
72
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
71
+	//bools
72
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
73 73
 
74
-    protected $_routing;
74
+	protected $_routing;
75 75
 
76
-    //list table args
77
-    protected $_view;
76
+	//list table args
77
+	protected $_view;
78 78
 
79
-    protected $_views;
79
+	protected $_views;
80 80
 
81 81
 
82
-    //action => method pairs used for routing incoming requests
83
-    protected $_page_routes;
82
+	//action => method pairs used for routing incoming requests
83
+	protected $_page_routes;
84 84
 
85
-    /**
86
-     * @var array $_page_config
87
-     */
88
-    protected $_page_config;
85
+	/**
86
+	 * @var array $_page_config
87
+	 */
88
+	protected $_page_config;
89 89
 
90
-    /**
91
-     * the current page route and route config
92
-     *
93
-     * @var string $_route
94
-     */
95
-    protected $_route;
90
+	/**
91
+	 * the current page route and route config
92
+	 *
93
+	 * @var string $_route
94
+	 */
95
+	protected $_route;
96 96
 
97
-    /**
98
-     * @var string $_cpt_route
99
-     */
100
-    protected $_cpt_route;
97
+	/**
98
+	 * @var string $_cpt_route
99
+	 */
100
+	protected $_cpt_route;
101 101
 
102
-    /**
103
-     * @var array $_route_config
104
-     */
105
-    protected $_route_config;
102
+	/**
103
+	 * @var array $_route_config
104
+	 */
105
+	protected $_route_config;
106 106
 
107
-    /**
108
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
109
-     * actions.
110
-     *
111
-     * @since 4.6.x
112
-     * @var array.
113
-     */
114
-    protected $_default_route_query_args;
115
-
116
-    //set via request page and action args.
117
-    protected $_current_page;
107
+	/**
108
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
109
+	 * actions.
110
+	 *
111
+	 * @since 4.6.x
112
+	 * @var array.
113
+	 */
114
+	protected $_default_route_query_args;
115
+
116
+	//set via request page and action args.
117
+	protected $_current_page;
118 118
 
119
-    protected $_current_view;
119
+	protected $_current_view;
120 120
 
121
-    protected $_current_page_view_url;
121
+	protected $_current_page_view_url;
122 122
 
123
-    //sanitized request action (and nonce)
123
+	//sanitized request action (and nonce)
124 124
 
125
-    /**
126
-     * @var string $_req_action
127
-     */
128
-    protected $_req_action;
129
-
130
-    /**
131
-     * @var string $_req_nonce
132
-     */
133
-    protected $_req_nonce;
134
-
135
-    //search related
136
-    protected $_search_btn_label;
137
-
138
-    protected $_search_box_callback;
139
-
140
-    /**
141
-     * WP Current Screen object
142
-     *
143
-     * @var WP_Screen
144
-     */
145
-    protected $_current_screen;
146
-
147
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
148
-    protected $_hook_obj;
149
-
150
-    //for holding incoming request data
151
-    protected $_req_data;
152
-
153
-    // yes / no array for admin form fields
154
-    protected $_yes_no_values = array();
155
-
156
-    //some default things shared by all child classes
157
-    protected $_default_espresso_metaboxes;
158
-
159
-    /**
160
-     *    EE_Registry Object
161
-     *
162
-     * @var    EE_Registry
163
-     */
164
-    protected $EE = null;
165
-
166
-
167
-
168
-    /**
169
-     * This is just a property that flags whether the given route is a caffeinated route or not.
170
-     *
171
-     * @var boolean
172
-     */
173
-    protected $_is_caf = false;
174
-
175
-
176
-
177
-    /**
178
-     * @Constructor
179
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
180
-     * @throws EE_Error
181
-     * @throws InvalidArgumentException
182
-     * @throws ReflectionException
183
-     * @throws InvalidDataTypeException
184
-     * @throws InvalidInterfaceException
185
-     */
186
-    public function __construct($routing = true)
187
-    {
188
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
189
-            $this->_is_caf = true;
190
-        }
191
-        $this->_yes_no_values = array(
192
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
193
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
194
-        );
195
-        //set the _req_data property.
196
-        $this->_req_data = array_merge($_GET, $_POST);
197
-        //routing enabled?
198
-        $this->_routing = $routing;
199
-        //set initial page props (child method)
200
-        $this->_init_page_props();
201
-        //set global defaults
202
-        $this->_set_defaults();
203
-        //set early because incoming requests could be ajax related and we need to register those hooks.
204
-        $this->_global_ajax_hooks();
205
-        $this->_ajax_hooks();
206
-        //other_page_hooks have to be early too.
207
-        $this->_do_other_page_hooks();
208
-        //This just allows us to have extending classes do something specific
209
-        // before the parent constructor runs _page_setup().
210
-        if (method_exists($this, '_before_page_setup')) {
211
-            $this->_before_page_setup();
212
-        }
213
-        //set up page dependencies
214
-        $this->_page_setup();
215
-    }
216
-
217
-
218
-
219
-    /**
220
-     * _init_page_props
221
-     * Child classes use to set at least the following properties:
222
-     * $page_slug.
223
-     * $page_label.
224
-     *
225
-     * @abstract
226
-     * @return void
227
-     */
228
-    abstract protected function _init_page_props();
229
-
230
-
231
-
232
-    /**
233
-     * _ajax_hooks
234
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
235
-     * Note: within the ajax callback methods.
236
-     *
237
-     * @abstract
238
-     * @return void
239
-     */
240
-    abstract protected function _ajax_hooks();
241
-
242
-
243
-
244
-    /**
245
-     * _define_page_props
246
-     * child classes define page properties in here.  Must include at least:
247
-     * $_admin_base_url = base_url for all admin pages
248
-     * $_admin_page_title = default admin_page_title for admin pages
249
-     * $_labels = array of default labels for various automatically generated elements:
250
-     *    array(
251
-     *        'buttons' => array(
252
-     *            'add' => esc_html__('label for add new button'),
253
-     *            'edit' => esc_html__('label for edit button'),
254
-     *            'delete' => esc_html__('label for delete button')
255
-     *            )
256
-     *        )
257
-     *
258
-     * @abstract
259
-     * @return void
260
-     */
261
-    abstract protected function _define_page_props();
262
-
263
-
264
-
265
-    /**
266
-     * _set_page_routes
267
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
268
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
269
-     * have a 'default' route. Here's the format
270
-     * $this->_page_routes = array(
271
-     *        'default' => array(
272
-     *            'func' => '_default_method_handling_route',
273
-     *            'args' => array('array','of','args'),
274
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
275
-     *            ajax request, backend processing)
276
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
277
-     *            headers route after.  The string you enter here should match the defined route reference for a
278
-     *            headers sent route.
279
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
280
-     *            this route.
281
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
282
-     *            checks).
283
-     *        ),
284
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
285
-     *        handling method.
286
-     *        )
287
-     * )
288
-     *
289
-     * @abstract
290
-     * @return void
291
-     */
292
-    abstract protected function _set_page_routes();
293
-
294
-
295
-
296
-    /**
297
-     * _set_page_config
298
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
299
-     * array corresponds to the page_route for the loaded page. Format:
300
-     * $this->_page_config = array(
301
-     *        'default' => array(
302
-     *            'labels' => array(
303
-     *                'buttons' => array(
304
-     *                    'add' => esc_html__('label for adding item'),
305
-     *                    'edit' => esc_html__('label for editing item'),
306
-     *                    'delete' => esc_html__('label for deleting item')
307
-     *                ),
308
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
309
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
310
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
311
-     *            _define_page_props() method
312
-     *            'nav' => array(
313
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
314
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
315
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
316
-     *                'order' => 10, //required to indicate tab position.
317
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
318
-     *                displayed then add this parameter.
319
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
320
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
321
-     *            metaboxes set for eventespresso admin pages.
322
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
323
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
324
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
325
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
326
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
327
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
328
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
329
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
330
-     *            want to display.
331
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
332
-     *                'tab_id' => array(
333
-     *                    'title' => 'tab_title',
334
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
335
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
336
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
337
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
338
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
339
-     *                    attempt to use the callback which should match the name of a method in the class
340
-     *                    ),
341
-     *                'tab2_id' => array(
342
-     *                    'title' => 'tab2 title',
343
-     *                    'filename' => 'file_name_2'
344
-     *                    'callback' => 'callback_method_for_content',
345
-     *                 ),
346
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
347
-     *            help tab area on an admin page. @link
348
-     *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
349
-     *            'help_tour' => array(
350
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
351
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
352
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
353
-     *            ),
354
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
355
-     *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
356
-     *            just set
357
-     *            'require_nonce' to FALSE
358
-     *            )
359
-     * )
360
-     *
361
-     * @abstract
362
-     * @return void
363
-     */
364
-    abstract protected function _set_page_config();
365
-
366
-
367
-
368
-
369
-
370
-    /** end sample help_tour methods **/
371
-    /**
372
-     * _add_screen_options
373
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
374
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
375
-     * to a particular view.
376
-     *
377
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
378
-     *         see also WP_Screen object documents...
379
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
380
-     * @abstract
381
-     * @return void
382
-     */
383
-    abstract protected function _add_screen_options();
384
-
385
-
386
-
387
-    /**
388
-     * _add_feature_pointers
389
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
390
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
391
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
392
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
393
-     * extended) also see:
394
-     *
395
-     * @link   http://eamann.com/tech/wordpress-portland/
396
-     * @abstract
397
-     * @return void
398
-     */
399
-    abstract protected function _add_feature_pointers();
400
-
401
-
402
-
403
-    /**
404
-     * load_scripts_styles
405
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
406
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
407
-     * scripts/styles per view by putting them in a dynamic function in this format
408
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
409
-     *
410
-     * @abstract
411
-     * @return void
412
-     */
413
-    abstract public function load_scripts_styles();
414
-
415
-
416
-
417
-    /**
418
-     * admin_init
419
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
420
-     * all pages/views loaded by child class.
421
-     *
422
-     * @abstract
423
-     * @return void
424
-     */
425
-    abstract public function admin_init();
426
-
427
-
428
-
429
-    /**
430
-     * admin_notices
431
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
432
-     * all pages/views loaded by child class.
433
-     *
434
-     * @abstract
435
-     * @return void
436
-     */
437
-    abstract public function admin_notices();
438
-
439
-
440
-
441
-    /**
442
-     * admin_footer_scripts
443
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
444
-     * will apply to all pages/views loaded by child class.
445
-     *
446
-     * @return void
447
-     */
448
-    abstract public function admin_footer_scripts();
449
-
450
-
451
-
452
-    /**
453
-     * admin_footer
454
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
455
-     * apply to all pages/views loaded by child class.
456
-     *
457
-     * @return void
458
-     */
459
-    public function admin_footer()
460
-    {
461
-    }
462
-
463
-
464
-
465
-    /**
466
-     * _global_ajax_hooks
467
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
468
-     * Note: within the ajax callback methods.
469
-     *
470
-     * @abstract
471
-     * @return void
472
-     */
473
-    protected function _global_ajax_hooks()
474
-    {
475
-        //for lazy loading of metabox content
476
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
477
-    }
478
-
479
-
480
-
481
-    public function ajax_metabox_content()
482
-    {
483
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
484
-        $url       = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
485
-        self::cached_rss_display($contentid, $url);
486
-        wp_die();
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * _page_setup
493
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
494
-     * doesn't match the object.
495
-     *
496
-     * @final
497
-     * @return void
498
-     * @throws EE_Error
499
-     * @throws InvalidArgumentException
500
-     * @throws ReflectionException
501
-     * @throws InvalidDataTypeException
502
-     * @throws InvalidInterfaceException
503
-     */
504
-    final protected function _page_setup()
505
-    {
506
-        //requires?
507
-        //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
508
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
509
-        //next verify if we need to load anything...
510
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
511
-        $this->page_folder   = strtolower(
512
-            str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
513
-        );
514
-        global $ee_menu_slugs;
515
-        $ee_menu_slugs = (array)$ee_menu_slugs;
516
-        if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) {
517
-            return;
518
-        }
519
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
520
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
521
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
522
-                ? $this->_req_data['action2']
523
-                : $this->_req_data['action'];
524
-        }
525
-        // then set blank or -1 action values to 'default'
526
-        $this->_req_action = isset($this->_req_data['action'])
527
-                             && ! empty($this->_req_data['action'])
528
-                             && $this->_req_data['action'] !== '-1'
529
-            ? sanitize_key($this->_req_data['action'])
530
-            : 'default';
531
-        // if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
532
-        //  This covers cases where we're coming in from a list table that isn't on the default route.
533
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
534
-            ? $this->_req_data['route'] : $this->_req_action;
535
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
536
-        $this->_req_action   = defined('DOING_AJAX') && isset($this->_req_data['route'])
537
-            ? $this->_req_data['route']
538
-            : $this->_req_action;
539
-        $this->_current_view = $this->_req_action;
540
-        $this->_req_nonce    = $this->_req_action . '_nonce';
541
-        $this->_define_page_props();
542
-        $this->_current_page_view_url = add_query_arg(
543
-            array('page' => $this->_current_page, 'action' => $this->_current_view),
544
-            $this->_admin_base_url
545
-        );
546
-        //default things
547
-        $this->_default_espresso_metaboxes = array(
548
-            '_espresso_news_post_box',
549
-            '_espresso_links_post_box',
550
-            '_espresso_ratings_request',
551
-            '_espresso_sponsors_post_box',
552
-        );
553
-        //set page configs
554
-        $this->_set_page_routes();
555
-        $this->_set_page_config();
556
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
557
-        if (isset($this->_req_data['wp_referer'])) {
558
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
559
-        }
560
-        //for caffeinated and other extended functionality.
561
-        //  If there is a _extend_page_config method
562
-        // then let's run that to modify the all the various page configuration arrays
563
-        if (method_exists($this, '_extend_page_config')) {
564
-            $this->_extend_page_config();
565
-        }
566
-        //for CPT and other extended functionality.
567
-        // If there is an _extend_page_config_for_cpt
568
-        // then let's run that to modify all the various page configuration arrays.
569
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
570
-            $this->_extend_page_config_for_cpt();
571
-        }
572
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
573
-        $this->_page_routes = apply_filters(
574
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
575
-            $this->_page_routes,
576
-            $this
577
-        );
578
-        $this->_page_config = apply_filters(
579
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
580
-            $this->_page_config,
581
-            $this
582
-        );
583
-        //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
584
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
585
-        if (
586
-            method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)
587
-        ) {
588
-            add_action(
589
-                'AHEE__EE_Admin_Page__route_admin_request',
590
-                array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
591
-                10,
592
-                2
593
-            );
594
-        }
595
-        //next route only if routing enabled
596
-        if ($this->_routing && ! defined('DOING_AJAX')) {
597
-            $this->_verify_routes();
598
-            //next let's just check user_access and kill if no access
599
-            $this->check_user_access();
600
-            if ($this->_is_UI_request) {
601
-                //admin_init stuff - global, all views for this page class, specific view
602
-                add_action('admin_init', array($this, 'admin_init'), 10);
603
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
604
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
605
-                }
606
-            } else {
607
-                //hijack regular WP loading and route admin request immediately
608
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
609
-                $this->route_admin_request();
610
-            }
611
-        }
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
618
-     *
619
-     * @return void
620
-     * @throws ReflectionException
621
-     * @throws EE_Error
622
-     */
623
-    private function _do_other_page_hooks()
624
-    {
625
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
626
-        foreach ($registered_pages as $page) {
627
-            //now let's setup the file name and class that should be present
628
-            $classname = str_replace('.class.php', '', $page);
629
-            //autoloaders should take care of loading file
630
-            if (! class_exists($classname)) {
631
-                $error_msg[] = sprintf(
632
-                    esc_html__(
633
-                        'Something went wrong with loading the %s admin hooks page.',
634
-                        'event_espresso'
635
-                    ),
636
-                    $page
637
-                );
638
-                $error_msg[] = $error_msg[0]
639
-                               . "\r\n"
640
-                               . sprintf(
641
-                                   esc_html__(
642
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
643
-                                       'event_espresso'
644
-                                   ),
645
-                                   $page,
646
-                                   '<br />',
647
-                                   '<strong>' . $classname . '</strong>'
648
-                               );
649
-                throw new EE_Error(implode('||', $error_msg));
650
-            }
651
-            $a = new ReflectionClass($classname);
652
-            //notice we are passing the instance of this class to the hook object.
653
-            $hookobj[] = $a->newInstance($this);
654
-        }
655
-    }
656
-
657
-
658
-
659
-    public function load_page_dependencies()
660
-    {
661
-        try {
662
-            $this->_load_page_dependencies();
663
-        } catch (EE_Error $e) {
664
-            $e->get_error();
665
-        }
666
-    }
667
-
668
-
669
-
670
-    /**
671
-     * load_page_dependencies
672
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
673
-     *
674
-     * @return void
675
-     * @throws DomainException
676
-     * @throws EE_Error
677
-     * @throws InvalidArgumentException
678
-     * @throws InvalidDataTypeException
679
-     * @throws InvalidInterfaceException
680
-     * @throws ReflectionException
681
-     */
682
-    protected function _load_page_dependencies()
683
-    {
684
-        //let's set the current_screen and screen options to override what WP set
685
-        $this->_current_screen = get_current_screen();
686
-        //load admin_notices - global, page class, and view specific
687
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
688
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
689
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
690
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
691
-        }
692
-        //load network admin_notices - global, page class, and view specific
693
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
694
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
695
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
696
-        }
697
-        //this will save any per_page screen options if they are present
698
-        $this->_set_per_page_screen_options();
699
-        //setup list table properties
700
-        $this->_set_list_table();
701
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
702
-        // However in some cases the metaboxes will need to be added within a route handling callback.
703
-        $this->_add_registered_meta_boxes();
704
-        $this->_add_screen_columns();
705
-        //add screen options - global, page child class, and view specific
706
-        $this->_add_global_screen_options();
707
-        $this->_add_screen_options();
708
-        $add_screen_options  = "_add_screen_options_{$this->_current_view}";
709
-        if (method_exists($this, $add_screen_options )) {
710
-            $this->{$add_screen_options}();
711
-        }
712
-        //add help tab(s) and tours- set via page_config and qtips.
713
-        $this->_add_help_tour();
714
-        $this->_add_help_tabs();
715
-        $this->_add_qtips();
716
-        //add feature_pointers - global, page child class, and view specific
717
-        $this->_add_feature_pointers();
718
-        $this->_add_global_feature_pointers();
719
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
720
-        if (method_exists($this, $add_feature_pointer )) {
721
-            $this->{$add_feature_pointer}();
722
-        }
723
-        //enqueue scripts/styles - global, page class, and view specific
724
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
725
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
726
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
727
-            add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
728
-        }
729
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
730
-        // admin_print_footer_scripts - global, page child class, and view specific.
731
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
732
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
733
-        // is a good use case. Notice the late priority we're giving these
734
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
735
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
736
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
737
-            add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
738
-        }
739
-        //admin footer scripts
740
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
741
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
742
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
743
-            add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
744
-        }
745
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
746
-        //targeted hook
747
-        do_action(
748
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
749
-
750
-        );
751
-    }
752
-
753
-
754
-
755
-    /**
756
-     * _set_defaults
757
-     * This sets some global defaults for class properties.
758
-     */
759
-    private function _set_defaults()
760
-    {
761
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
762
-        $this->_event = $this->_template_path = $this->_column_template_path = null;
763
-        $this->_nav_tabs = $this->_views = $this->_page_routes = array();
764
-        $this->_page_config = $this->_default_route_query_args = array();
765
-        $this->_default_nav_tab_name = 'overview';
766
-        //init template args
767
-        $this->_template_args = array(
768
-            'admin_page_header'  => '',
769
-            'admin_page_content' => '',
770
-            'post_body_content'  => '',
771
-            'before_list_table'  => '',
772
-            'after_list_table'   => '',
773
-        );
774
-    }
775
-
776
-
777
-
778
-    /**
779
-     * route_admin_request
780
-     *
781
-     * @see    _route_admin_request()
782
-     * @return exception|void error
783
-     * @throws InvalidArgumentException
784
-     * @throws InvalidInterfaceException
785
-     * @throws InvalidDataTypeException
786
-     * @throws EE_Error
787
-     * @throws ReflectionException
788
-     */
789
-    public function route_admin_request()
790
-    {
791
-        try {
792
-            $this->_route_admin_request();
793
-        } catch (EE_Error $e) {
794
-            $e->get_error();
795
-        }
796
-    }
797
-
798
-
799
-
800
-    public function set_wp_page_slug($wp_page_slug)
801
-    {
802
-        $this->_wp_page_slug = $wp_page_slug;
803
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
804
-        if (is_network_admin()) {
805
-            $this->_wp_page_slug .= '-network';
806
-        }
807
-    }
808
-
809
-
810
-
811
-    /**
812
-     * _verify_routes
813
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
814
-     * we know if we need to drop out.
815
-     *
816
-     * @return bool
817
-     * @throws EE_Error
818
-     */
819
-    protected function _verify_routes()
820
-    {
821
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
822
-        if (! $this->_current_page && ! defined('DOING_AJAX')) {
823
-            return false;
824
-        }
825
-        $this->_route = false;
826
-        // check that the page_routes array is not empty
827
-        if (empty($this->_page_routes)) {
828
-            // user error msg
829
-            $error_msg = sprintf(
830
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
831
-                $this->_admin_page_title
832
-            );
833
-            // developer error msg
834
-            $error_msg .= '||' . $error_msg . esc_html__(
835
-                ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
836
-                'event_espresso'
837
-            );
838
-            throw new EE_Error($error_msg);
839
-        }
840
-        // and that the requested page route exists
841
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
842
-            $this->_route        = $this->_page_routes[$this->_req_action];
843
-            $this->_route_config = isset($this->_page_config[$this->_req_action])
844
-                ? $this->_page_config[$this->_req_action] : array();
845
-        } else {
846
-            // user error msg
847
-            $error_msg = sprintf(
848
-                esc_html__(
849
-                        'The requested page route does not exist for the %s admin page.',
850
-                        'event_espresso'
851
-                ),
852
-                $this->_admin_page_title
853
-            );
854
-            // developer error msg
855
-            $error_msg .= '||' . $error_msg . sprintf(
856
-                    esc_html__(
857
-                        ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
858
-                        'event_espresso'
859
-                    ),
860
-                    $this->_req_action
861
-                );
862
-            throw new EE_Error($error_msg);
863
-        }
864
-        // and that a default route exists
865
-        if (! array_key_exists('default', $this->_page_routes)) {
866
-            // user error msg
867
-            $error_msg = sprintf(
868
-                esc_html__(
869
-                        'A default page route has not been set for the % admin page.',
870
-                        'event_espresso'
871
-                ),
872
-                $this->_admin_page_title
873
-            );
874
-            // developer error msg
875
-            $error_msg .= '||' . $error_msg . esc_html__(
876
-                ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
877
-                'event_espresso'
878
-            );
879
-            throw new EE_Error($error_msg);
880
-        }
881
-        //first lets' catch if the UI request has EVER been set.
882
-        if ($this->_is_UI_request === null) {
883
-            //lets set if this is a UI request or not.
884
-            $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
885
-            //wait a minute... we might have a noheader in the route array
886
-            $this->_is_UI_request = is_array($this->_route)
887
-                                    && isset($this->_route['noheader'])
888
-                                    && $this->_route['noheader'] ? false : $this->_is_UI_request;
889
-        }
890
-        $this->_set_current_labels();
891
-        return true;
892
-    }
893
-
894
-
895
-
896
-    /**
897
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
898
-     *
899
-     * @param  string $route the route name we're verifying
900
-     * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
901
-     * @throws EE_Error
902
-     */
903
-    protected function _verify_route($route)
904
-    {
905
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
906
-            return true;
907
-        }
908
-        // user error msg
909
-        $error_msg = sprintf(
910
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
911
-            $this->_admin_page_title
912
-        );
913
-        // developer error msg
914
-        $error_msg .= '||' . $error_msg . sprintf(
915
-                esc_html__(
916
-                    ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
917
-                    'event_espresso'
918
-                ),
919
-                $route
920
-            );
921
-        throw new EE_Error($error_msg);
922
-    }
923
-
924
-
925
-
926
-    /**
927
-     * perform nonce verification
928
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
929
-     * using this method (and save retyping!)
930
-     *
931
-     * @param  string $nonce     The nonce sent
932
-     * @param  string $nonce_ref The nonce reference string (name0)
933
-     * @return void
934
-     * @throws EE_Error
935
-     */
936
-    protected function _verify_nonce($nonce, $nonce_ref)
937
-    {
938
-        // verify nonce against expected value
939
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
940
-            // these are not the droids you are looking for !!!
941
-            $msg = sprintf(
942
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
943
-                '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
944
-                '</a>'
945
-            );
946
-            if (WP_DEBUG) {
947
-                $msg .= "\n  " . sprintf(
948
-                        esc_html__(
949
-                            'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
950
-                            'event_espresso'
951
-                        ),
952
-                        __CLASS__
953
-                    );
954
-            }
955
-            if (! defined('DOING_AJAX')) {
956
-                wp_die($msg);
957
-            } else {
958
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
959
-                $this->_return_json();
960
-            }
961
-        }
962
-    }
963
-
964
-
965
-
966
-    /**
967
-     * _route_admin_request()
968
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
969
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
970
-     * in the page routes and then will try to load the corresponding method.
971
-     *
972
-     * @return void
973
-     * @throws EE_Error
974
-     * @throws InvalidArgumentException
975
-     * @throws InvalidDataTypeException
976
-     * @throws InvalidInterfaceException
977
-     * @throws ReflectionException
978
-     */
979
-    protected function _route_admin_request()
980
-    {
981
-        if (! $this->_is_UI_request) {
982
-            $this->_verify_routes();
983
-        }
984
-        $nonce_check = isset($this->_route_config['require_nonce'])
985
-            ? $this->_route_config['require_nonce']
986
-            : true;
987
-        if ($this->_req_action !== 'default' && $nonce_check) {
988
-            // set nonce from post data
989
-            $nonce = isset($this->_req_data[$this->_req_nonce])
990
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
991
-                : '';
992
-            $this->_verify_nonce($nonce, $this->_req_nonce);
993
-        }
994
-        //set the nav_tabs array but ONLY if this is  UI_request
995
-        if ($this->_is_UI_request) {
996
-            $this->_set_nav_tabs();
997
-        }
998
-        // grab callback function
999
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
1000
-        // check if callback has args
1001
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1002
-        $error_msg = '';
1003
-        // action right before calling route
1004
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1005
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1006
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1007
-        }
1008
-        // right before calling the route, let's remove _wp_http_referer from the
1009
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1010
-        $_SERVER['REQUEST_URI'] = remove_query_arg(
1011
-                '_wp_http_referer',
1012
-                wp_unslash($_SERVER['REQUEST_URI'])
1013
-        );
1014
-        if (! empty($func)) {
1015
-            if (is_array($func)) {
1016
-                list($class, $method) = $func;
1017
-            } elseif (strpos($func, '::') !== false) {
1018
-                list($class, $method) = explode('::', $func);
1019
-            } else {
1020
-                $class  = $this;
1021
-                $method = $func;
1022
-            }
1023
-            if (! (is_object($class) && $class === $this)) {
1024
-                // send along this admin page object for access by addons.
1025
-                $args['admin_page_object'] = $this;
1026
-            }
1027
-            if (
1028
-                //is it a method on a class that doesn't work?
1029
-                (
1030
-                    (
1031
-                        method_exists($class, $method)
1032
-                        && call_user_func_array(array($class, $method), $args) === false
1033
-                    )
1034
-                    && (
1035
-                        //is it a standalone function that doesn't work?
1036
-                        function_exists($method)
1037
-                        && call_user_func_array(
1038
-                            $func,
1039
-                            array_merge(array('admin_page_object' => $this), $args)
1040
-                           ) === false
1041
-                    )
1042
-                )
1043
-                || (
1044
-                    //is it neither a class method NOR a standalone function?
1045
-                    ! method_exists($class, $method)
1046
-                    && ! function_exists($method)
1047
-                )
1048
-            ) {
1049
-                // user error msg
1050
-                $error_msg = esc_html__(
1051
-                    'An error occurred. The  requested page route could not be found.',
1052
-                    'event_espresso'
1053
-                );
1054
-                // developer error msg
1055
-                $error_msg .= '||';
1056
-                $error_msg .= sprintf(
1057
-                    esc_html__(
1058
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1059
-                        'event_espresso'
1060
-                    ),
1061
-                    $method
1062
-                );
1063
-            }
1064
-            if (! empty($error_msg)) {
1065
-                throw new EE_Error($error_msg);
1066
-            }
1067
-        }
1068
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1069
-        // then we need to reset the routing properties to the new route.
1070
-        //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1071
-        if ($this->_is_UI_request === false
1072
-            && is_array($this->_route)
1073
-            && ! empty($this->_route['headers_sent_route'])
1074
-        ) {
1075
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1076
-        }
1077
-    }
1078
-
1079
-
1080
-
1081
-    /**
1082
-     * This method just allows the resetting of page properties in the case where a no headers
1083
-     * route redirects to a headers route in its route config.
1084
-     *
1085
-     * @since   4.3.0
1086
-     * @param  string $new_route New (non header) route to redirect to.
1087
-     * @return   void
1088
-     * @throws ReflectionException
1089
-     * @throws InvalidArgumentException
1090
-     * @throws InvalidInterfaceException
1091
-     * @throws InvalidDataTypeException
1092
-     * @throws EE_Error
1093
-     */
1094
-    protected function _reset_routing_properties($new_route)
1095
-    {
1096
-        $this->_is_UI_request = true;
1097
-        //now we set the current route to whatever the headers_sent_route is set at
1098
-        $this->_req_data['action'] = $new_route;
1099
-        //rerun page setup
1100
-        $this->_page_setup();
1101
-    }
1102
-
1103
-
1104
-
1105
-    /**
1106
-     * _add_query_arg
1107
-     * adds nonce to array of arguments then calls WP add_query_arg function
1108
-     *(internally just uses EEH_URL's function with the same name)
1109
-     *
1110
-     * @param array  $args
1111
-     * @param string $url
1112
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1113
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1114
-     *                                        Example usage: If the current page is:
1115
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1116
-     *                                        &action=default&event_id=20&month_range=March%202015
1117
-     *                                        &_wpnonce=5467821
1118
-     *                                        and you call:
1119
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1120
-     *                                        array(
1121
-     *                                        'action' => 'resend_something',
1122
-     *                                        'page=>espresso_registrations'
1123
-     *                                        ),
1124
-     *                                        $some_url,
1125
-     *                                        true
1126
-     *                                        );
1127
-     *                                        It will produce a url in this structure:
1128
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1129
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1130
-     *                                        month_range]=March%202015
1131
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1132
-     * @return string
1133
-     */
1134
-    public static function add_query_args_and_nonce(
1135
-        $args = array(),
1136
-        $url = false,
1137
-        $sticky = false,
1138
-        $exclude_nonce = false
1139
-    ) {
1140
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
1141
-        if ($sticky) {
1142
-            $request = $_REQUEST;
1143
-            unset($request['_wp_http_referer']);
1144
-            unset($request['wp_referer']);
1145
-            foreach ($request as $key => $value) {
1146
-                //do not add nonces
1147
-                if (strpos($key, 'nonce') !== false) {
1148
-                    continue;
1149
-                }
1150
-                $args['wp_referer[' . $key . ']'] = $value;
1151
-            }
1152
-        }
1153
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1154
-    }
1155
-
1156
-
1157
-
1158
-    /**
1159
-     * This returns a generated link that will load the related help tab.
1160
-     *
1161
-     * @param  string $help_tab_id the id for the connected help tab
1162
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1163
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1164
-     * @uses EEH_Template::get_help_tab_link()
1165
-     * @return string              generated link
1166
-     */
1167
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1168
-    {
1169
-        return EEH_Template::get_help_tab_link(
1170
-            $help_tab_id,
1171
-            $this->page_slug,
1172
-            $this->_req_action,
1173
-            $icon_style,
1174
-            $help_text
1175
-        );
1176
-    }
1177
-
1178
-
1179
-
1180
-    /**
1181
-     * _add_help_tabs
1182
-     * Note child classes define their help tabs within the page_config array.
1183
-     *
1184
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1185
-     * @return void
1186
-     * @throws DomainException
1187
-     * @throws EE_Error
1188
-     */
1189
-    protected function _add_help_tabs()
1190
-    {
1191
-        $tour_buttons = '';
1192
-        if (isset($this->_page_config[$this->_req_action])) {
1193
-            $config = $this->_page_config[$this->_req_action];
1194
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1195
-            if (isset($this->_help_tour[$this->_req_action])) {
1196
-                $tb           = array();
1197
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1198
-                foreach ($this->_help_tour['tours'] as $tour) {
1199
-                    //if this is the end tour then we don't need to setup a button
1200
-                    if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1201
-                        continue;
1202
-                    }
1203
-                    $tb[] = '<button id="trigger-tour-'
1204
-                            . $tour->get_slug()
1205
-                            . '" class="button-primary trigger-ee-help-tour">'
1206
-                            . $tour->get_label()
1207
-                            . '</button>';
1208
-                }
1209
-                $tour_buttons .= implode('<br />', $tb);
1210
-                $tour_buttons .= '</div></div>';
1211
-            }
1212
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1213
-            if (is_array($config) && isset($config['help_sidebar'])) {
1214
-                //check that the callback given is valid
1215
-                if (! method_exists($this, $config['help_sidebar'])) {
1216
-                    throw new EE_Error(
1217
-                        sprintf(
1218
-                            esc_html__(
1219
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1220
-                                'event_espresso'
1221
-                            ),
1222
-                            $config['help_sidebar'],
1223
-                            get_class($this)
1224
-                        )
1225
-                    );
1226
-                }
1227
-                $content = apply_filters(
1228
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1229
-                    $this->{$config['help_sidebar']}()
1230
-                );
1231
-                $content .= $tour_buttons; //add help tour buttons.
1232
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1233
-                $this->_current_screen->set_help_sidebar($content);
1234
-            }
1235
-            //if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1236
-            if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1237
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1238
-            }
1239
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1240
-            if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1241
-                $_ht['id']      = $this->page_slug;
1242
-                $_ht['title']   = esc_html__('Help Tours', 'event_espresso');
1243
-                $_ht['content'] = '<p>' . esc_html__(
1244
-                        'The buttons to the right allow you to start/restart any help tours available for this page',
1245
-                        'event_espresso'
1246
-                    ) . '</p>';
1247
-                $this->_current_screen->add_help_tab($_ht);
1248
-            }
1249
-            if (! isset($config['help_tabs'])) {
1250
-                return;
1251
-            } //no help tabs for this route
1252
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1253
-                //we're here so there ARE help tabs!
1254
-                //make sure we've got what we need
1255
-                if (! isset($cfg['title'])) {
1256
-                    throw new EE_Error(
1257
-                        esc_html__(
1258
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1259
-                            'event_espresso'
1260
-                        )
1261
-                    );
1262
-                }
1263
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1264
-                    throw new EE_Error(
1265
-                        esc_html__(
1266
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1267
-                            'event_espresso'
1268
-                        )
1269
-                    );
1270
-                }
1271
-                //first priority goes to content.
1272
-                if (! empty($cfg['content'])) {
1273
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1274
-                    //second priority goes to filename
1275
-                } elseif (! empty($cfg['filename'])) {
1276
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1277
-                    //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1278
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1279
-                                                             . basename($this->_get_dir())
1280
-                                                             . '/help_tabs/'
1281
-                                                             . $cfg['filename']
1282
-                                                             . '.help_tab.php' : $file_path;
1283
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1284
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1285
-                        EE_Error::add_error(
1286
-                            sprintf(
1287
-                                esc_html__(
1288
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1289
-                                    'event_espresso'
1290
-                                ),
1291
-                                $tab_id,
1292
-                                key($config),
1293
-                                $file_path
1294
-                            ),
1295
-                            __FILE__,
1296
-                            __FUNCTION__,
1297
-                            __LINE__
1298
-                        );
1299
-                        return;
1300
-                    }
1301
-                    $template_args['admin_page_obj'] = $this;
1302
-                    $content = EEH_Template::display_template(
1303
-                        $file_path,
1304
-                        $template_args,
1305
-                        true
1306
-                    );
1307
-                } else {
1308
-                    $content = '';
1309
-                }
1310
-                //check if callback is valid
1311
-                if (
1312
-                    empty($content) && (
1313
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1314
-                    )
1315
-                ) {
1316
-                    EE_Error::add_error(
1317
-                        sprintf(
1318
-                            esc_html__(
1319
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1320
-                                'event_espresso'
1321
-                            ),
1322
-                            $cfg['title']
1323
-                        ),
1324
-                        __FILE__,
1325
-                        __FUNCTION__,
1326
-                        __LINE__
1327
-                    );
1328
-                    return;
1329
-                }
1330
-                //setup config array for help tab method
1331
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1332
-                $_ht = array(
1333
-                    'id'       => $id,
1334
-                    'title'    => $cfg['title'],
1335
-                    'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1336
-                    'content'  => $content,
1337
-                );
1338
-                $this->_current_screen->add_help_tab($_ht);
1339
-            }
1340
-        }
1341
-    }
1342
-
1343
-
1344
-
1345
-    /**
1346
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1347
-     * an array with properties for setting up usage of the joyride plugin
1348
-     *
1349
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1350
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1351
-     *         _set_page_config() comments
1352
-     * @return void
1353
-     * @throws EE_Error
1354
-     * @throws InvalidArgumentException
1355
-     * @throws InvalidDataTypeException
1356
-     * @throws InvalidInterfaceException
1357
-     */
1358
-    protected function _add_help_tour()
1359
-    {
1360
-        $tours            = array();
1361
-        $this->_help_tour = array();
1362
-        //exit early if help tours are turned off globally
1363
-        if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1364
-            || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1365
-        ) {
1366
-            return;
1367
-        }
1368
-        //loop through _page_config to find any help_tour defined
1369
-        foreach ($this->_page_config as $route => $config) {
1370
-            //we're only going to set things up for this route
1371
-            if ($route !== $this->_req_action) {
1372
-                continue;
1373
-            }
1374
-            if (isset($config['help_tour'])) {
1375
-                foreach ($config['help_tour'] as $tour) {
1376
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1377
-                    // let's see if we can get that file...
1378
-                    // if not its possible this is a decaf route not set in caffeinated
1379
-                    // so lets try and get the caffeinated equivalent
1380
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1381
-                                                             . basename($this->_get_dir())
1382
-                                                             . '/help_tours/'
1383
-                                                             . $tour
1384
-                                                             . '.class.php' : $file_path;
1385
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1386
-                    if (! is_readable($file_path)) {
1387
-                        EE_Error::add_error(
1388
-                            sprintf(
1389
-                                esc_html__(
1390
-                                    'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1391
-                                    'event_espresso'
1392
-                                ),
1393
-                                $file_path,
1394
-                                $tour
1395
-                            ),
1396
-                            __FILE__,
1397
-                            __FUNCTION__,
1398
-                            __LINE__
1399
-                        );
1400
-                        return;
1401
-                    }
1402
-                    require_once $file_path;
1403
-                    if (! class_exists($tour)) {
1404
-                        $error_msg[] = sprintf(
1405
-                            esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1406
-                            $tour
1407
-                        );
1408
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(
1409
-                                esc_html__(
1410
-                                    'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1411
-                                    'event_espresso'
1412
-                                ),
1413
-                                $tour,
1414
-                                '<br />',
1415
-                                $tour,
1416
-                                $this->_req_action,
1417
-                                get_class($this)
1418
-                            );
1419
-                        throw new EE_Error(implode('||', $error_msg));
1420
-                    }
1421
-                    $tour_obj                   = new $tour($this->_is_caf);
1422
-                    $tours[]                    = $tour_obj;
1423
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1424
-                }
1425
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1426
-                $end_stop_tour              = new EE_Help_Tour_final_stop($this->_is_caf);
1427
-                $tours[]                    = $end_stop_tour;
1428
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1429
-            }
1430
-        }
1431
-        if (! empty($tours)) {
1432
-            $this->_help_tour['tours'] = $tours;
1433
-        }
1434
-        // that's it!  Now that the $_help_tours property is set (or not)
1435
-        // the scripts and html should be taken care of automatically.
1436
-    }
1437
-
1438
-
1439
-
1440
-    /**
1441
-     * This simply sets up any qtips that have been defined in the page config
1442
-     *
1443
-     * @return void
1444
-     */
1445
-    protected function _add_qtips()
1446
-    {
1447
-        if (isset($this->_route_config['qtips'])) {
1448
-            $qtips = (array)$this->_route_config['qtips'];
1449
-            //load qtip loader
1450
-            $path = array(
1451
-                $this->_get_dir() . '/qtips/',
1452
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1453
-            );
1454
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1455
-        }
1456
-    }
1457
-
1458
-
1459
-
1460
-    /**
1461
-     * _set_nav_tabs
1462
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1463
-     * wish to add additional tabs or modify accordingly.
1464
-     *
1465
-     * @return void
1466
-     * @throws InvalidArgumentException
1467
-     * @throws InvalidInterfaceException
1468
-     * @throws InvalidDataTypeException
1469
-     */
1470
-    protected function _set_nav_tabs()
1471
-    {
1472
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1473
-        $i = 0;
1474
-        foreach ($this->_page_config as $slug => $config) {
1475
-            if (
1476
-                ! is_array($config)
1477
-                || (
1478
-                    is_array($config)
1479
-                    && (
1480
-                        (isset($config['nav']) && ! $config['nav'])
1481
-                        || ! isset($config['nav'])
1482
-                    )
1483
-                )
1484
-            ) {
1485
-                continue;
1486
-            }
1487
-            //no nav tab for this config
1488
-            //check for persistent flag
1489
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1490
-                // nav tab is only to appear when route requested.
1491
-                continue;
1492
-            }
1493
-            if (! $this->check_user_access($slug, true)) {
1494
-                // no nav tab because current user does not have access.
1495
-                continue;
1496
-            }
1497
-            $css_class              = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1498
-            $this->_nav_tabs[$slug] = array(
1499
-                'url'       => isset($config['nav']['url'])
1500
-                    ? $config['nav']['url']
1501
-                    : self::add_query_args_and_nonce(
1502
-                        array('action' => $slug),
1503
-                        $this->_admin_base_url
1504
-                    ),
1505
-                'link_text' => isset($config['nav']['label'])
1506
-                    ? $config['nav']['label']
1507
-                    : ucwords(
1508
-                        str_replace('_', ' ', $slug)
1509
-                    ),
1510
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1511
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1512
-            );
1513
-            $i++;
1514
-        }
1515
-        //if $this->_nav_tabs is empty then lets set the default
1516
-        if (empty($this->_nav_tabs)) {
1517
-            $this->_nav_tabs[$this->_default_nav_tab_name] = array(
1518
-                'url'       => $this->_admin_base_url,
1519
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1520
-                'css_class' => 'nav-tab-active',
1521
-                'order'     => 10,
1522
-            );
1523
-        }
1524
-        //now let's sort the tabs according to order
1525
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1526
-    }
1527
-
1528
-
1529
-
1530
-    /**
1531
-     * _set_current_labels
1532
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1533
-     * property array
1534
-     *
1535
-     * @return void
1536
-     */
1537
-    private function _set_current_labels()
1538
-    {
1539
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1540
-            foreach ($this->_route_config['labels'] as $label => $text) {
1541
-                if (is_array($text)) {
1542
-                    foreach ($text as $sublabel => $subtext) {
1543
-                        $this->_labels[$label][$sublabel] = $subtext;
1544
-                    }
1545
-                } else {
1546
-                    $this->_labels[$label] = $text;
1547
-                }
1548
-            }
1549
-        }
1550
-    }
1551
-
1552
-
1553
-
1554
-    /**
1555
-     *        verifies user access for this admin page
1556
-     *
1557
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1558
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1559
-     *                               return false if verify fail.
1560
-     * @return bool
1561
-     * @throws InvalidArgumentException
1562
-     * @throws InvalidDataTypeException
1563
-     * @throws InvalidInterfaceException
1564
-     */
1565
-    public function check_user_access($route_to_check = '', $verify_only = false)
1566
-    {
1567
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1568
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1569
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1570
-                          && is_array(
1571
-                              $this->_page_routes[$route_to_check]
1572
-                          )
1573
-                          && ! empty($this->_page_routes[$route_to_check]['capability'])
1574
-            ? $this->_page_routes[$route_to_check]['capability'] : null;
1575
-        if (empty($capability) && empty($route_to_check)) {
1576
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1577
-                : $this->_route['capability'];
1578
-        } else {
1579
-            $capability = empty($capability) ? 'manage_options' : $capability;
1580
-        }
1581
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1582
-        if (
1583
-            ! defined('DOING_AJAX')
1584
-            && (
1585
-                ! function_exists('is_admin')
1586
-                || ! EE_Registry::instance()->CAP->current_user_can(
1587
-                    $capability,
1588
-                    $this->page_slug
1589
-                    . '_'
1590
-                    . $route_to_check,
1591
-                    $id
1592
-                )
1593
-            )
1594
-        ) {
1595
-            if ($verify_only) {
1596
-                return false;
1597
-            }
1598
-            if (is_user_logged_in()) {
1599
-                wp_die(__('You do not have access to this route.', 'event_espresso'));
1600
-            } else {
1601
-                return false;
1602
-            }
1603
-        }
1604
-        return true;
1605
-    }
1606
-
1607
-
1608
-
1609
-    /**
1610
-     * admin_init_global
1611
-     * This runs all the code that we want executed within the WP admin_init hook.
1612
-     * This method executes for ALL EE Admin pages.
1613
-     *
1614
-     * @return void
1615
-     */
1616
-    public function admin_init_global()
1617
-    {
1618
-    }
1619
-
1620
-
1621
-
1622
-    /**
1623
-     * wp_loaded_global
1624
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1625
-     * EE_Admin page and will execute on every EE Admin Page load
1626
-     *
1627
-     * @return void
1628
-     */
1629
-    public function wp_loaded()
1630
-    {
1631
-    }
1632
-
1633
-
1634
-
1635
-    /**
1636
-     * admin_notices
1637
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1638
-     * ALL EE_Admin pages.
1639
-     *
1640
-     * @return void
1641
-     */
1642
-    public function admin_notices_global()
1643
-    {
1644
-        $this->_display_no_javascript_warning();
1645
-        $this->_display_espresso_notices();
1646
-    }
1647
-
1648
-
1649
-
1650
-    public function network_admin_notices_global()
1651
-    {
1652
-        $this->_display_no_javascript_warning();
1653
-        $this->_display_espresso_notices();
1654
-    }
1655
-
1656
-
1657
-
1658
-    /**
1659
-     * admin_footer_scripts_global
1660
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1661
-     * will apply on ALL EE_Admin pages.
1662
-     *
1663
-     * @return void
1664
-     */
1665
-    public function admin_footer_scripts_global()
1666
-    {
1667
-        $this->_add_admin_page_ajax_loading_img();
1668
-        $this->_add_admin_page_overlay();
1669
-        //if metaboxes are present we need to add the nonce field
1670
-        if (
1671
-             isset($this->_route_config['metaboxes'])
1672
-             || isset($this->_route_config['list_table'])
1673
-             || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1674
-        ) {
1675
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1676
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1677
-        }
1678
-    }
1679
-
1680
-
1681
-
1682
-    /**
1683
-     * admin_footer_global
1684
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1685
-     * ALL EE_Admin Pages.
1686
-     *
1687
-     * @return void
1688
-     * @throws EE_Error
1689
-     */
1690
-    public function admin_footer_global()
1691
-    {
1692
-        //dialog container for dialog helper
1693
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1694
-        $d_cont .= '<div class="ee-notices"></div>';
1695
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1696
-        $d_cont .= '</div>';
1697
-        echo $d_cont;
1698
-        //help tour stuff?
1699
-        if (isset($this->_help_tour[$this->_req_action])) {
1700
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1701
-        }
1702
-        //current set timezone for timezone js
1703
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1704
-    }
1705
-
1706
-
1707
-
1708
-    /**
1709
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1710
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1711
-     * help popups then in your templates or your content you set "triggers" for the content using the
1712
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1713
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1714
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1715
-     * for the
1716
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1717
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1718
-     *    'help_trigger_id' => array(
1719
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1720
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1721
-     *    )
1722
-     * );
1723
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1724
-     *
1725
-     * @param array $help_array
1726
-     * @param bool  $display
1727
-     * @return string content
1728
-     * @throws DomainException
1729
-     * @throws EE_Error
1730
-     */
1731
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1732
-    {
1733
-        $content       = '';
1734
-        $help_array    = empty($help_array) ? $this->_get_help_content() : $help_array;
1735
-        //loop through the array and setup content
1736
-        foreach ($help_array as $trigger => $help) {
1737
-            //make sure the array is setup properly
1738
-            if (! isset($help['title']) || ! isset($help['content'])) {
1739
-                throw new EE_Error(
1740
-                    esc_html__(
1741
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1742
-                        'event_espresso'
1743
-                    )
1744
-                );
1745
-            }
1746
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1747
-            $template_args = array(
1748
-                'help_popup_id'      => $trigger,
1749
-                'help_popup_title'   => $help['title'],
1750
-                'help_popup_content' => $help['content'],
1751
-            );
1752
-            $content       .= EEH_Template::display_template(
1753
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1754
-                $template_args,
1755
-                true
1756
-            );
1757
-        }
1758
-        if ($display) {
1759
-            echo $content;
1760
-            return '';
1761
-        }
1762
-        return $content;
1763
-    }
1764
-
1765
-
1766
-
1767
-    /**
1768
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1769
-     *
1770
-     * @return array properly formatted array for help popup content
1771
-     * @throws EE_Error
1772
-     */
1773
-    private function _get_help_content()
1774
-    {
1775
-        //what is the method we're looking for?
1776
-        $method_name = '_help_popup_content_' . $this->_req_action;
1777
-        //if method doesn't exist let's get out.
1778
-        if (! method_exists($this, $method_name)) {
1779
-            return array();
1780
-        }
1781
-        //k we're good to go let's retrieve the help array
1782
-        $help_array = call_user_func(array($this, $method_name));
1783
-        //make sure we've got an array!
1784
-        if (! is_array($help_array)) {
1785
-            throw new EE_Error(
1786
-                esc_html__(
1787
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1788
-                    'event_espresso'
1789
-                )
1790
-            );
1791
-        }
1792
-        return $help_array;
1793
-    }
1794
-
1795
-
1796
-
1797
-    /**
1798
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1799
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1800
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1801
-     *
1802
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1803
-     * @param boolean $display    if false then we return the trigger string
1804
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1805
-     * @return string
1806
-     * @throws DomainException
1807
-     * @throws EE_Error
1808
-     */
1809
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1810
-    {
1811
-        if (defined('DOING_AJAX')) {
1812
-            return '';
1813
-        }
1814
-        //let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1815
-        $help_array   = $this->_get_help_content();
1816
-        $help_content = '';
1817
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1818
-            $help_array[$trigger_id] = array(
1819
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1820
-                'content' => esc_html__(
1821
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1822
-                    'event_espresso'
1823
-                ),
1824
-            );
1825
-            $help_content            = $this->_set_help_popup_content($help_array, false);
1826
-        }
1827
-        //let's setup the trigger
1828
-        $content = '<a class="ee-dialog" href="?height='
1829
-                   . $dimensions[0]
1830
-                   . '&width='
1831
-                   . $dimensions[1]
1832
-                   . '&inlineId='
1833
-                   . $trigger_id
1834
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1835
-        $content .= $help_content;
1836
-        if ($display) {
1837
-            echo $content;
1838
-            return  '';
1839
-        }
1840
-        return $content;
1841
-    }
1842
-
1843
-
1844
-
1845
-    /**
1846
-     * _add_global_screen_options
1847
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1848
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1849
-     *
1850
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1851
-     *         see also WP_Screen object documents...
1852
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1853
-     * @abstract
1854
-     * @return void
1855
-     */
1856
-    private function _add_global_screen_options()
1857
-    {
1858
-    }
1859
-
1860
-
1861
-
1862
-    /**
1863
-     * _add_global_feature_pointers
1864
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1865
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1866
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1867
-     *
1868
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1869
-     *         extended) also see:
1870
-     * @link   http://eamann.com/tech/wordpress-portland/
1871
-     * @abstract
1872
-     * @return void
1873
-     */
1874
-    private function _add_global_feature_pointers()
1875
-    {
1876
-    }
1877
-
1878
-
1879
-
1880
-    /**
1881
-     * load_global_scripts_styles
1882
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1883
-     *
1884
-     * @return void
1885
-     * @throws EE_Error
1886
-     */
1887
-    public function load_global_scripts_styles()
1888
-    {
1889
-        /** STYLES **/
1890
-        // add debugging styles
1891
-        if (WP_DEBUG) {
1892
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1893
-        }
1894
-        // register all styles
1895
-        wp_register_style(
1896
-            'espresso-ui-theme',
1897
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1898
-            array(),
1899
-            EVENT_ESPRESSO_VERSION
1900
-        );
1901
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1902
-        //helpers styles
1903
-        wp_register_style(
1904
-            'ee-text-links',
1905
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1906
-            array(),
1907
-            EVENT_ESPRESSO_VERSION
1908
-        );
1909
-        /** SCRIPTS **/
1910
-        //register all scripts
1911
-        wp_register_script(
1912
-            'ee-dialog',
1913
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1914
-            array('jquery', 'jquery-ui-draggable'),
1915
-            EVENT_ESPRESSO_VERSION,
1916
-            true
1917
-        );
1918
-        wp_register_script(
1919
-            'ee_admin_js',
1920
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1921
-            array('espresso_core', 'ee-parse-uri', 'ee-dialog'),
1922
-            EVENT_ESPRESSO_VERSION,
1923
-            true
1924
-        );
1925
-        wp_register_script(
1926
-            'jquery-ui-timepicker-addon',
1927
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1928
-            array('jquery-ui-datepicker', 'jquery-ui-slider'),
1929
-            EVENT_ESPRESSO_VERSION,
1930
-            true
1931
-        );
1932
-        add_filter('FHEE_load_joyride', '__return_true');
1933
-        //script for sorting tables
1934
-        wp_register_script(
1935
-            'espresso_ajax_table_sorting',
1936
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1937
-            array('ee_admin_js', 'jquery-ui-sortable'),
1938
-            EVENT_ESPRESSO_VERSION,
1939
-            true
1940
-        );
1941
-        //script for parsing uri's
1942
-        wp_register_script(
1943
-            'ee-parse-uri',
1944
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1945
-            array(),
1946
-            EVENT_ESPRESSO_VERSION,
1947
-            true
1948
-        );
1949
-        //and parsing associative serialized form elements
1950
-        wp_register_script(
1951
-            'ee-serialize-full-array',
1952
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1953
-            array('jquery'),
1954
-            EVENT_ESPRESSO_VERSION,
1955
-            true
1956
-        );
1957
-        //helpers scripts
1958
-        wp_register_script(
1959
-            'ee-text-links',
1960
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1961
-            array('jquery'),
1962
-            EVENT_ESPRESSO_VERSION,
1963
-            true
1964
-        );
1965
-        wp_register_script(
1966
-            'ee-moment-core',
1967
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1968
-            array(),
1969
-            EVENT_ESPRESSO_VERSION,
1970
-            true
1971
-        );
1972
-        wp_register_script(
1973
-            'ee-moment',
1974
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1975
-            array('ee-moment-core'),
1976
-            EVENT_ESPRESSO_VERSION,
1977
-            true
1978
-        );
1979
-        wp_register_script(
1980
-            'ee-datepicker',
1981
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1982
-            array('jquery-ui-timepicker-addon', 'ee-moment'),
1983
-            EVENT_ESPRESSO_VERSION,
1984
-            true
1985
-        );
1986
-        //google charts
1987
-        wp_register_script(
1988
-            'google-charts',
1989
-            'https://www.gstatic.com/charts/loader.js',
1990
-            array(),
1991
-            EVENT_ESPRESSO_VERSION,
1992
-            false
1993
-        );
1994
-        // ENQUEUE ALL BASICS BY DEFAULT
1995
-        wp_enqueue_style('ee-admin-css');
1996
-        wp_enqueue_script('ee_admin_js');
1997
-        wp_enqueue_script('ee-accounting');
1998
-        wp_enqueue_script('jquery-validate');
1999
-        //taking care of metaboxes
2000
-        if (
2001
-            empty($this->_cpt_route)
2002
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
2003
-        ) {
2004
-            wp_enqueue_script('dashboard');
2005
-        }
2006
-        // LOCALIZED DATA
2007
-        //localize script for ajax lazy loading
2008
-        $lazy_loader_container_ids = apply_filters(
2009
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
2010
-            array('espresso_news_post_box_content')
2011
-        );
2012
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
2013
-        /**
2014
-         * help tour stuff
2015
-         */
2016
-        if (! empty($this->_help_tour)) {
2017
-            //register the js for kicking things off
2018
-            wp_enqueue_script(
2019
-                'ee-help-tour',
2020
-                EE_ADMIN_URL . 'assets/ee-help-tour.js',
2021
-                array('jquery-joyride'),
2022
-                EVENT_ESPRESSO_VERSION,
2023
-                true
2024
-            );
2025
-            $tours = array();
2026
-            //setup tours for the js tour object
2027
-            foreach ($this->_help_tour['tours'] as $tour) {
2028
-                if ($tour instanceof EE_Help_Tour) {
2029
-                    $tours[] = array(
2030
-                        'id'      => $tour->get_slug(),
2031
-                        'options' => $tour->get_options(),
2032
-                    );
2033
-                }
2034
-            }
2035
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2036
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2037
-        }
2038
-    }
2039
-
2040
-
2041
-
2042
-    /**
2043
-     *        admin_footer_scripts_eei18n_js_strings
2044
-     *
2045
-     * @return        void
2046
-     */
2047
-    public function admin_footer_scripts_eei18n_js_strings()
2048
-    {
2049
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
2050
-        EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2051
-            'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2052
-            'event_espresso'
2053
-        );
2054
-        EE_Registry::$i18n_js_strings['January']        = esc_html__('January', 'event_espresso');
2055
-        EE_Registry::$i18n_js_strings['February']       = esc_html__('February', 'event_espresso');
2056
-        EE_Registry::$i18n_js_strings['March']          = esc_html__('March', 'event_espresso');
2057
-        EE_Registry::$i18n_js_strings['April']          = esc_html__('April', 'event_espresso');
2058
-        EE_Registry::$i18n_js_strings['May']            = esc_html__('May', 'event_espresso');
2059
-        EE_Registry::$i18n_js_strings['June']           = esc_html__('June', 'event_espresso');
2060
-        EE_Registry::$i18n_js_strings['July']           = esc_html__('July', 'event_espresso');
2061
-        EE_Registry::$i18n_js_strings['August']         = esc_html__('August', 'event_espresso');
2062
-        EE_Registry::$i18n_js_strings['September']      = esc_html__('September', 'event_espresso');
2063
-        EE_Registry::$i18n_js_strings['October']        = esc_html__('October', 'event_espresso');
2064
-        EE_Registry::$i18n_js_strings['November']       = esc_html__('November', 'event_espresso');
2065
-        EE_Registry::$i18n_js_strings['December']       = esc_html__('December', 'event_espresso');
2066
-        EE_Registry::$i18n_js_strings['Jan']            = esc_html__('Jan', 'event_espresso');
2067
-        EE_Registry::$i18n_js_strings['Feb']            = esc_html__('Feb', 'event_espresso');
2068
-        EE_Registry::$i18n_js_strings['Mar']            = esc_html__('Mar', 'event_espresso');
2069
-        EE_Registry::$i18n_js_strings['Apr']            = esc_html__('Apr', 'event_espresso');
2070
-        EE_Registry::$i18n_js_strings['May']            = esc_html__('May', 'event_espresso');
2071
-        EE_Registry::$i18n_js_strings['Jun']            = esc_html__('Jun', 'event_espresso');
2072
-        EE_Registry::$i18n_js_strings['Jul']            = esc_html__('Jul', 'event_espresso');
2073
-        EE_Registry::$i18n_js_strings['Aug']            = esc_html__('Aug', 'event_espresso');
2074
-        EE_Registry::$i18n_js_strings['Sep']            = esc_html__('Sep', 'event_espresso');
2075
-        EE_Registry::$i18n_js_strings['Oct']            = esc_html__('Oct', 'event_espresso');
2076
-        EE_Registry::$i18n_js_strings['Nov']            = esc_html__('Nov', 'event_espresso');
2077
-        EE_Registry::$i18n_js_strings['Dec']            = esc_html__('Dec', 'event_espresso');
2078
-        EE_Registry::$i18n_js_strings['Sunday']         = esc_html__('Sunday', 'event_espresso');
2079
-        EE_Registry::$i18n_js_strings['Monday']         = esc_html__('Monday', 'event_espresso');
2080
-        EE_Registry::$i18n_js_strings['Tuesday']        = esc_html__('Tuesday', 'event_espresso');
2081
-        EE_Registry::$i18n_js_strings['Wednesday']      = esc_html__('Wednesday', 'event_espresso');
2082
-        EE_Registry::$i18n_js_strings['Thursday']       = esc_html__('Thursday', 'event_espresso');
2083
-        EE_Registry::$i18n_js_strings['Friday']         = esc_html__('Friday', 'event_espresso');
2084
-        EE_Registry::$i18n_js_strings['Saturday']       = esc_html__('Saturday', 'event_espresso');
2085
-        EE_Registry::$i18n_js_strings['Sun']            = esc_html__('Sun', 'event_espresso');
2086
-        EE_Registry::$i18n_js_strings['Mon']            = esc_html__('Mon', 'event_espresso');
2087
-        EE_Registry::$i18n_js_strings['Tue']            = esc_html__('Tue', 'event_espresso');
2088
-        EE_Registry::$i18n_js_strings['Wed']            = esc_html__('Wed', 'event_espresso');
2089
-        EE_Registry::$i18n_js_strings['Thu']            = esc_html__('Thu', 'event_espresso');
2090
-        EE_Registry::$i18n_js_strings['Fri']            = esc_html__('Fri', 'event_espresso');
2091
-        EE_Registry::$i18n_js_strings['Sat']            = esc_html__('Sat', 'event_espresso');
2092
-    }
2093
-
2094
-
2095
-
2096
-    /**
2097
-     *        load enhanced xdebug styles for ppl with failing eyesight
2098
-     *
2099
-     * @return        void
2100
-     */
2101
-    public function add_xdebug_style()
2102
-    {
2103
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2104
-    }
2105
-
2106
-
2107
-    /************************/
2108
-    /** LIST TABLE METHODS **/
2109
-    /************************/
2110
-    /**
2111
-     * this sets up the list table if the current view requires it.
2112
-     *
2113
-     * @return void
2114
-     * @throws EE_Error
2115
-     */
2116
-    protected function _set_list_table()
2117
-    {
2118
-        //first is this a list_table view?
2119
-        if (! isset($this->_route_config['list_table'])) {
2120
-            return;
2121
-        } //not a list_table view so get out.
2122
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2123
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2124
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2125
-            //user error msg
2126
-            $error_msg = esc_html__(
2127
-                'An error occurred. The requested list table views could not be found.',
2128
-                'event_espresso'
2129
-            );
2130
-            //developer error msg
2131
-            $error_msg .= '||' . sprintf(
2132
-                    esc_html__(
2133
-                        'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2134
-                        'event_espresso'
2135
-                    ),
2136
-                    $this->_req_action,
2137
-                    $list_table_view
2138
-                );
2139
-            throw new EE_Error($error_msg);
2140
-        }
2141
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2142
-        $this->_views = apply_filters(
2143
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2144
-            $this->_views
2145
-        );
2146
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2147
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2148
-        $this->_set_list_table_view();
2149
-        $this->_set_list_table_object();
2150
-    }
2151
-
2152
-
2153
-
2154
-    /**
2155
-     * set current view for List Table
2156
-     *
2157
-     * @return void
2158
-     */
2159
-    protected function _set_list_table_view()
2160
-    {
2161
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2162
-        // looking at active items or dumpster diving ?
2163
-        if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2164
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2165
-        } else {
2166
-            $this->_view = sanitize_key($this->_req_data['status']);
2167
-        }
2168
-    }
2169
-
2170
-
2171
-
2172
-    /**
2173
-     * _set_list_table_object
2174
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2175
-     *
2176
-     * @throws EE_Error
2177
-     */
2178
-    protected function _set_list_table_object()
2179
-    {
2180
-        if (isset($this->_route_config['list_table'])) {
2181
-            if (! class_exists($this->_route_config['list_table'])) {
2182
-                throw new EE_Error(
2183
-                    sprintf(
2184
-                        esc_html__(
2185
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2186
-                            'event_espresso'
2187
-                        ),
2188
-                        $this->_route_config['list_table'],
2189
-                        get_class($this)
2190
-                    )
2191
-                );
2192
-            }
2193
-            $list_table               = $this->_route_config['list_table'];
2194
-            $this->_list_table_object = new $list_table($this);
2195
-        }
2196
-    }
2197
-
2198
-
2199
-
2200
-    /**
2201
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2202
-     *
2203
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2204
-     *                                                    urls.  The array should be indexed by the view it is being
2205
-     *                                                    added to.
2206
-     * @return array
2207
-     */
2208
-    public function get_list_table_view_RLs($extra_query_args = array())
2209
-    {
2210
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2211
-        if (empty($this->_views)) {
2212
-            $this->_views = array();
2213
-        }
2214
-        // cycle thru views
2215
-        foreach ($this->_views as $key => $view) {
2216
-            $query_args = array();
2217
-            // check for current view
2218
-            $this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2219
-            $query_args['action']                      = $this->_req_action;
2220
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2221
-            $query_args['status']                      = $view['slug'];
2222
-            //merge any other arguments sent in.
2223
-            if (isset($extra_query_args[$view['slug']])) {
2224
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
2225
-            }
2226
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2227
-        }
2228
-        return $this->_views;
2229
-    }
2230
-
2231
-
2232
-
2233
-    /**
2234
-     * _entries_per_page_dropdown
2235
-     * generates a drop down box for selecting the number of visible rows in an admin page list table
2236
-     *
2237
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2238
-     *         WP does it.
2239
-     * @param int $max_entries total number of rows in the table
2240
-     * @return string
2241
-     */
2242
-    protected function _entries_per_page_dropdown($max_entries = 0)
2243
-    {
2244
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2245
-        $values   = array(10, 25, 50, 100);
2246
-        $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2247
-        if ($max_entries) {
2248
-            $values[] = $max_entries;
2249
-            sort($values);
2250
-        }
2251
-        $entries_per_page_dropdown = '
125
+	/**
126
+	 * @var string $_req_action
127
+	 */
128
+	protected $_req_action;
129
+
130
+	/**
131
+	 * @var string $_req_nonce
132
+	 */
133
+	protected $_req_nonce;
134
+
135
+	//search related
136
+	protected $_search_btn_label;
137
+
138
+	protected $_search_box_callback;
139
+
140
+	/**
141
+	 * WP Current Screen object
142
+	 *
143
+	 * @var WP_Screen
144
+	 */
145
+	protected $_current_screen;
146
+
147
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
148
+	protected $_hook_obj;
149
+
150
+	//for holding incoming request data
151
+	protected $_req_data;
152
+
153
+	// yes / no array for admin form fields
154
+	protected $_yes_no_values = array();
155
+
156
+	//some default things shared by all child classes
157
+	protected $_default_espresso_metaboxes;
158
+
159
+	/**
160
+	 *    EE_Registry Object
161
+	 *
162
+	 * @var    EE_Registry
163
+	 */
164
+	protected $EE = null;
165
+
166
+
167
+
168
+	/**
169
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
170
+	 *
171
+	 * @var boolean
172
+	 */
173
+	protected $_is_caf = false;
174
+
175
+
176
+
177
+	/**
178
+	 * @Constructor
179
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
180
+	 * @throws EE_Error
181
+	 * @throws InvalidArgumentException
182
+	 * @throws ReflectionException
183
+	 * @throws InvalidDataTypeException
184
+	 * @throws InvalidInterfaceException
185
+	 */
186
+	public function __construct($routing = true)
187
+	{
188
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
189
+			$this->_is_caf = true;
190
+		}
191
+		$this->_yes_no_values = array(
192
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
193
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
194
+		);
195
+		//set the _req_data property.
196
+		$this->_req_data = array_merge($_GET, $_POST);
197
+		//routing enabled?
198
+		$this->_routing = $routing;
199
+		//set initial page props (child method)
200
+		$this->_init_page_props();
201
+		//set global defaults
202
+		$this->_set_defaults();
203
+		//set early because incoming requests could be ajax related and we need to register those hooks.
204
+		$this->_global_ajax_hooks();
205
+		$this->_ajax_hooks();
206
+		//other_page_hooks have to be early too.
207
+		$this->_do_other_page_hooks();
208
+		//This just allows us to have extending classes do something specific
209
+		// before the parent constructor runs _page_setup().
210
+		if (method_exists($this, '_before_page_setup')) {
211
+			$this->_before_page_setup();
212
+		}
213
+		//set up page dependencies
214
+		$this->_page_setup();
215
+	}
216
+
217
+
218
+
219
+	/**
220
+	 * _init_page_props
221
+	 * Child classes use to set at least the following properties:
222
+	 * $page_slug.
223
+	 * $page_label.
224
+	 *
225
+	 * @abstract
226
+	 * @return void
227
+	 */
228
+	abstract protected function _init_page_props();
229
+
230
+
231
+
232
+	/**
233
+	 * _ajax_hooks
234
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
235
+	 * Note: within the ajax callback methods.
236
+	 *
237
+	 * @abstract
238
+	 * @return void
239
+	 */
240
+	abstract protected function _ajax_hooks();
241
+
242
+
243
+
244
+	/**
245
+	 * _define_page_props
246
+	 * child classes define page properties in here.  Must include at least:
247
+	 * $_admin_base_url = base_url for all admin pages
248
+	 * $_admin_page_title = default admin_page_title for admin pages
249
+	 * $_labels = array of default labels for various automatically generated elements:
250
+	 *    array(
251
+	 *        'buttons' => array(
252
+	 *            'add' => esc_html__('label for add new button'),
253
+	 *            'edit' => esc_html__('label for edit button'),
254
+	 *            'delete' => esc_html__('label for delete button')
255
+	 *            )
256
+	 *        )
257
+	 *
258
+	 * @abstract
259
+	 * @return void
260
+	 */
261
+	abstract protected function _define_page_props();
262
+
263
+
264
+
265
+	/**
266
+	 * _set_page_routes
267
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
268
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
269
+	 * have a 'default' route. Here's the format
270
+	 * $this->_page_routes = array(
271
+	 *        'default' => array(
272
+	 *            'func' => '_default_method_handling_route',
273
+	 *            'args' => array('array','of','args'),
274
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
275
+	 *            ajax request, backend processing)
276
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
277
+	 *            headers route after.  The string you enter here should match the defined route reference for a
278
+	 *            headers sent route.
279
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
280
+	 *            this route.
281
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
282
+	 *            checks).
283
+	 *        ),
284
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
285
+	 *        handling method.
286
+	 *        )
287
+	 * )
288
+	 *
289
+	 * @abstract
290
+	 * @return void
291
+	 */
292
+	abstract protected function _set_page_routes();
293
+
294
+
295
+
296
+	/**
297
+	 * _set_page_config
298
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
299
+	 * array corresponds to the page_route for the loaded page. Format:
300
+	 * $this->_page_config = array(
301
+	 *        'default' => array(
302
+	 *            'labels' => array(
303
+	 *                'buttons' => array(
304
+	 *                    'add' => esc_html__('label for adding item'),
305
+	 *                    'edit' => esc_html__('label for editing item'),
306
+	 *                    'delete' => esc_html__('label for deleting item')
307
+	 *                ),
308
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
309
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
310
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
311
+	 *            _define_page_props() method
312
+	 *            'nav' => array(
313
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
314
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
315
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
316
+	 *                'order' => 10, //required to indicate tab position.
317
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
318
+	 *                displayed then add this parameter.
319
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
320
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
321
+	 *            metaboxes set for eventespresso admin pages.
322
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
323
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
324
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
325
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
326
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
327
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
328
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
329
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
330
+	 *            want to display.
331
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
332
+	 *                'tab_id' => array(
333
+	 *                    'title' => 'tab_title',
334
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
335
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
336
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
337
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
338
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
339
+	 *                    attempt to use the callback which should match the name of a method in the class
340
+	 *                    ),
341
+	 *                'tab2_id' => array(
342
+	 *                    'title' => 'tab2 title',
343
+	 *                    'filename' => 'file_name_2'
344
+	 *                    'callback' => 'callback_method_for_content',
345
+	 *                 ),
346
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
347
+	 *            help tab area on an admin page. @link
348
+	 *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
349
+	 *            'help_tour' => array(
350
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
351
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
352
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
353
+	 *            ),
354
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
355
+	 *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
356
+	 *            just set
357
+	 *            'require_nonce' to FALSE
358
+	 *            )
359
+	 * )
360
+	 *
361
+	 * @abstract
362
+	 * @return void
363
+	 */
364
+	abstract protected function _set_page_config();
365
+
366
+
367
+
368
+
369
+
370
+	/** end sample help_tour methods **/
371
+	/**
372
+	 * _add_screen_options
373
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
374
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
375
+	 * to a particular view.
376
+	 *
377
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
378
+	 *         see also WP_Screen object documents...
379
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
380
+	 * @abstract
381
+	 * @return void
382
+	 */
383
+	abstract protected function _add_screen_options();
384
+
385
+
386
+
387
+	/**
388
+	 * _add_feature_pointers
389
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
390
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
391
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
392
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
393
+	 * extended) also see:
394
+	 *
395
+	 * @link   http://eamann.com/tech/wordpress-portland/
396
+	 * @abstract
397
+	 * @return void
398
+	 */
399
+	abstract protected function _add_feature_pointers();
400
+
401
+
402
+
403
+	/**
404
+	 * load_scripts_styles
405
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
406
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
407
+	 * scripts/styles per view by putting them in a dynamic function in this format
408
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
409
+	 *
410
+	 * @abstract
411
+	 * @return void
412
+	 */
413
+	abstract public function load_scripts_styles();
414
+
415
+
416
+
417
+	/**
418
+	 * admin_init
419
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
420
+	 * all pages/views loaded by child class.
421
+	 *
422
+	 * @abstract
423
+	 * @return void
424
+	 */
425
+	abstract public function admin_init();
426
+
427
+
428
+
429
+	/**
430
+	 * admin_notices
431
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
432
+	 * all pages/views loaded by child class.
433
+	 *
434
+	 * @abstract
435
+	 * @return void
436
+	 */
437
+	abstract public function admin_notices();
438
+
439
+
440
+
441
+	/**
442
+	 * admin_footer_scripts
443
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
444
+	 * will apply to all pages/views loaded by child class.
445
+	 *
446
+	 * @return void
447
+	 */
448
+	abstract public function admin_footer_scripts();
449
+
450
+
451
+
452
+	/**
453
+	 * admin_footer
454
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
455
+	 * apply to all pages/views loaded by child class.
456
+	 *
457
+	 * @return void
458
+	 */
459
+	public function admin_footer()
460
+	{
461
+	}
462
+
463
+
464
+
465
+	/**
466
+	 * _global_ajax_hooks
467
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
468
+	 * Note: within the ajax callback methods.
469
+	 *
470
+	 * @abstract
471
+	 * @return void
472
+	 */
473
+	protected function _global_ajax_hooks()
474
+	{
475
+		//for lazy loading of metabox content
476
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
477
+	}
478
+
479
+
480
+
481
+	public function ajax_metabox_content()
482
+	{
483
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
484
+		$url       = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
485
+		self::cached_rss_display($contentid, $url);
486
+		wp_die();
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * _page_setup
493
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
494
+	 * doesn't match the object.
495
+	 *
496
+	 * @final
497
+	 * @return void
498
+	 * @throws EE_Error
499
+	 * @throws InvalidArgumentException
500
+	 * @throws ReflectionException
501
+	 * @throws InvalidDataTypeException
502
+	 * @throws InvalidInterfaceException
503
+	 */
504
+	final protected function _page_setup()
505
+	{
506
+		//requires?
507
+		//admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
508
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
509
+		//next verify if we need to load anything...
510
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
511
+		$this->page_folder   = strtolower(
512
+			str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
513
+		);
514
+		global $ee_menu_slugs;
515
+		$ee_menu_slugs = (array)$ee_menu_slugs;
516
+		if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) {
517
+			return;
518
+		}
519
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
520
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
521
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
522
+				? $this->_req_data['action2']
523
+				: $this->_req_data['action'];
524
+		}
525
+		// then set blank or -1 action values to 'default'
526
+		$this->_req_action = isset($this->_req_data['action'])
527
+							 && ! empty($this->_req_data['action'])
528
+							 && $this->_req_data['action'] !== '-1'
529
+			? sanitize_key($this->_req_data['action'])
530
+			: 'default';
531
+		// if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
532
+		//  This covers cases where we're coming in from a list table that isn't on the default route.
533
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
534
+			? $this->_req_data['route'] : $this->_req_action;
535
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
536
+		$this->_req_action   = defined('DOING_AJAX') && isset($this->_req_data['route'])
537
+			? $this->_req_data['route']
538
+			: $this->_req_action;
539
+		$this->_current_view = $this->_req_action;
540
+		$this->_req_nonce    = $this->_req_action . '_nonce';
541
+		$this->_define_page_props();
542
+		$this->_current_page_view_url = add_query_arg(
543
+			array('page' => $this->_current_page, 'action' => $this->_current_view),
544
+			$this->_admin_base_url
545
+		);
546
+		//default things
547
+		$this->_default_espresso_metaboxes = array(
548
+			'_espresso_news_post_box',
549
+			'_espresso_links_post_box',
550
+			'_espresso_ratings_request',
551
+			'_espresso_sponsors_post_box',
552
+		);
553
+		//set page configs
554
+		$this->_set_page_routes();
555
+		$this->_set_page_config();
556
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
557
+		if (isset($this->_req_data['wp_referer'])) {
558
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
559
+		}
560
+		//for caffeinated and other extended functionality.
561
+		//  If there is a _extend_page_config method
562
+		// then let's run that to modify the all the various page configuration arrays
563
+		if (method_exists($this, '_extend_page_config')) {
564
+			$this->_extend_page_config();
565
+		}
566
+		//for CPT and other extended functionality.
567
+		// If there is an _extend_page_config_for_cpt
568
+		// then let's run that to modify all the various page configuration arrays.
569
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
570
+			$this->_extend_page_config_for_cpt();
571
+		}
572
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
573
+		$this->_page_routes = apply_filters(
574
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
575
+			$this->_page_routes,
576
+			$this
577
+		);
578
+		$this->_page_config = apply_filters(
579
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
580
+			$this->_page_config,
581
+			$this
582
+		);
583
+		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
584
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
585
+		if (
586
+			method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)
587
+		) {
588
+			add_action(
589
+				'AHEE__EE_Admin_Page__route_admin_request',
590
+				array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
591
+				10,
592
+				2
593
+			);
594
+		}
595
+		//next route only if routing enabled
596
+		if ($this->_routing && ! defined('DOING_AJAX')) {
597
+			$this->_verify_routes();
598
+			//next let's just check user_access and kill if no access
599
+			$this->check_user_access();
600
+			if ($this->_is_UI_request) {
601
+				//admin_init stuff - global, all views for this page class, specific view
602
+				add_action('admin_init', array($this, 'admin_init'), 10);
603
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
604
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
605
+				}
606
+			} else {
607
+				//hijack regular WP loading and route admin request immediately
608
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
609
+				$this->route_admin_request();
610
+			}
611
+		}
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
618
+	 *
619
+	 * @return void
620
+	 * @throws ReflectionException
621
+	 * @throws EE_Error
622
+	 */
623
+	private function _do_other_page_hooks()
624
+	{
625
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
626
+		foreach ($registered_pages as $page) {
627
+			//now let's setup the file name and class that should be present
628
+			$classname = str_replace('.class.php', '', $page);
629
+			//autoloaders should take care of loading file
630
+			if (! class_exists($classname)) {
631
+				$error_msg[] = sprintf(
632
+					esc_html__(
633
+						'Something went wrong with loading the %s admin hooks page.',
634
+						'event_espresso'
635
+					),
636
+					$page
637
+				);
638
+				$error_msg[] = $error_msg[0]
639
+							   . "\r\n"
640
+							   . sprintf(
641
+								   esc_html__(
642
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
643
+									   'event_espresso'
644
+								   ),
645
+								   $page,
646
+								   '<br />',
647
+								   '<strong>' . $classname . '</strong>'
648
+							   );
649
+				throw new EE_Error(implode('||', $error_msg));
650
+			}
651
+			$a = new ReflectionClass($classname);
652
+			//notice we are passing the instance of this class to the hook object.
653
+			$hookobj[] = $a->newInstance($this);
654
+		}
655
+	}
656
+
657
+
658
+
659
+	public function load_page_dependencies()
660
+	{
661
+		try {
662
+			$this->_load_page_dependencies();
663
+		} catch (EE_Error $e) {
664
+			$e->get_error();
665
+		}
666
+	}
667
+
668
+
669
+
670
+	/**
671
+	 * load_page_dependencies
672
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
673
+	 *
674
+	 * @return void
675
+	 * @throws DomainException
676
+	 * @throws EE_Error
677
+	 * @throws InvalidArgumentException
678
+	 * @throws InvalidDataTypeException
679
+	 * @throws InvalidInterfaceException
680
+	 * @throws ReflectionException
681
+	 */
682
+	protected function _load_page_dependencies()
683
+	{
684
+		//let's set the current_screen and screen options to override what WP set
685
+		$this->_current_screen = get_current_screen();
686
+		//load admin_notices - global, page class, and view specific
687
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
688
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
689
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
690
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
691
+		}
692
+		//load network admin_notices - global, page class, and view specific
693
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
694
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
695
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
696
+		}
697
+		//this will save any per_page screen options if they are present
698
+		$this->_set_per_page_screen_options();
699
+		//setup list table properties
700
+		$this->_set_list_table();
701
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
702
+		// However in some cases the metaboxes will need to be added within a route handling callback.
703
+		$this->_add_registered_meta_boxes();
704
+		$this->_add_screen_columns();
705
+		//add screen options - global, page child class, and view specific
706
+		$this->_add_global_screen_options();
707
+		$this->_add_screen_options();
708
+		$add_screen_options  = "_add_screen_options_{$this->_current_view}";
709
+		if (method_exists($this, $add_screen_options )) {
710
+			$this->{$add_screen_options}();
711
+		}
712
+		//add help tab(s) and tours- set via page_config and qtips.
713
+		$this->_add_help_tour();
714
+		$this->_add_help_tabs();
715
+		$this->_add_qtips();
716
+		//add feature_pointers - global, page child class, and view specific
717
+		$this->_add_feature_pointers();
718
+		$this->_add_global_feature_pointers();
719
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
720
+		if (method_exists($this, $add_feature_pointer )) {
721
+			$this->{$add_feature_pointer}();
722
+		}
723
+		//enqueue scripts/styles - global, page class, and view specific
724
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
725
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
726
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
727
+			add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
728
+		}
729
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
730
+		// admin_print_footer_scripts - global, page child class, and view specific.
731
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
732
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
733
+		// is a good use case. Notice the late priority we're giving these
734
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
735
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
736
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
737
+			add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
738
+		}
739
+		//admin footer scripts
740
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
741
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
742
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
743
+			add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
744
+		}
745
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
746
+		//targeted hook
747
+		do_action(
748
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
749
+
750
+		);
751
+	}
752
+
753
+
754
+
755
+	/**
756
+	 * _set_defaults
757
+	 * This sets some global defaults for class properties.
758
+	 */
759
+	private function _set_defaults()
760
+	{
761
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
762
+		$this->_event = $this->_template_path = $this->_column_template_path = null;
763
+		$this->_nav_tabs = $this->_views = $this->_page_routes = array();
764
+		$this->_page_config = $this->_default_route_query_args = array();
765
+		$this->_default_nav_tab_name = 'overview';
766
+		//init template args
767
+		$this->_template_args = array(
768
+			'admin_page_header'  => '',
769
+			'admin_page_content' => '',
770
+			'post_body_content'  => '',
771
+			'before_list_table'  => '',
772
+			'after_list_table'   => '',
773
+		);
774
+	}
775
+
776
+
777
+
778
+	/**
779
+	 * route_admin_request
780
+	 *
781
+	 * @see    _route_admin_request()
782
+	 * @return exception|void error
783
+	 * @throws InvalidArgumentException
784
+	 * @throws InvalidInterfaceException
785
+	 * @throws InvalidDataTypeException
786
+	 * @throws EE_Error
787
+	 * @throws ReflectionException
788
+	 */
789
+	public function route_admin_request()
790
+	{
791
+		try {
792
+			$this->_route_admin_request();
793
+		} catch (EE_Error $e) {
794
+			$e->get_error();
795
+		}
796
+	}
797
+
798
+
799
+
800
+	public function set_wp_page_slug($wp_page_slug)
801
+	{
802
+		$this->_wp_page_slug = $wp_page_slug;
803
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
804
+		if (is_network_admin()) {
805
+			$this->_wp_page_slug .= '-network';
806
+		}
807
+	}
808
+
809
+
810
+
811
+	/**
812
+	 * _verify_routes
813
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
814
+	 * we know if we need to drop out.
815
+	 *
816
+	 * @return bool
817
+	 * @throws EE_Error
818
+	 */
819
+	protected function _verify_routes()
820
+	{
821
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
822
+		if (! $this->_current_page && ! defined('DOING_AJAX')) {
823
+			return false;
824
+		}
825
+		$this->_route = false;
826
+		// check that the page_routes array is not empty
827
+		if (empty($this->_page_routes)) {
828
+			// user error msg
829
+			$error_msg = sprintf(
830
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
831
+				$this->_admin_page_title
832
+			);
833
+			// developer error msg
834
+			$error_msg .= '||' . $error_msg . esc_html__(
835
+				' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
836
+				'event_espresso'
837
+			);
838
+			throw new EE_Error($error_msg);
839
+		}
840
+		// and that the requested page route exists
841
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
842
+			$this->_route        = $this->_page_routes[$this->_req_action];
843
+			$this->_route_config = isset($this->_page_config[$this->_req_action])
844
+				? $this->_page_config[$this->_req_action] : array();
845
+		} else {
846
+			// user error msg
847
+			$error_msg = sprintf(
848
+				esc_html__(
849
+						'The requested page route does not exist for the %s admin page.',
850
+						'event_espresso'
851
+				),
852
+				$this->_admin_page_title
853
+			);
854
+			// developer error msg
855
+			$error_msg .= '||' . $error_msg . sprintf(
856
+					esc_html__(
857
+						' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
858
+						'event_espresso'
859
+					),
860
+					$this->_req_action
861
+				);
862
+			throw new EE_Error($error_msg);
863
+		}
864
+		// and that a default route exists
865
+		if (! array_key_exists('default', $this->_page_routes)) {
866
+			// user error msg
867
+			$error_msg = sprintf(
868
+				esc_html__(
869
+						'A default page route has not been set for the % admin page.',
870
+						'event_espresso'
871
+				),
872
+				$this->_admin_page_title
873
+			);
874
+			// developer error msg
875
+			$error_msg .= '||' . $error_msg . esc_html__(
876
+				' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
877
+				'event_espresso'
878
+			);
879
+			throw new EE_Error($error_msg);
880
+		}
881
+		//first lets' catch if the UI request has EVER been set.
882
+		if ($this->_is_UI_request === null) {
883
+			//lets set if this is a UI request or not.
884
+			$this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
885
+			//wait a minute... we might have a noheader in the route array
886
+			$this->_is_UI_request = is_array($this->_route)
887
+									&& isset($this->_route['noheader'])
888
+									&& $this->_route['noheader'] ? false : $this->_is_UI_request;
889
+		}
890
+		$this->_set_current_labels();
891
+		return true;
892
+	}
893
+
894
+
895
+
896
+	/**
897
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
898
+	 *
899
+	 * @param  string $route the route name we're verifying
900
+	 * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
901
+	 * @throws EE_Error
902
+	 */
903
+	protected function _verify_route($route)
904
+	{
905
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
906
+			return true;
907
+		}
908
+		// user error msg
909
+		$error_msg = sprintf(
910
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
911
+			$this->_admin_page_title
912
+		);
913
+		// developer error msg
914
+		$error_msg .= '||' . $error_msg . sprintf(
915
+				esc_html__(
916
+					' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
917
+					'event_espresso'
918
+				),
919
+				$route
920
+			);
921
+		throw new EE_Error($error_msg);
922
+	}
923
+
924
+
925
+
926
+	/**
927
+	 * perform nonce verification
928
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
929
+	 * using this method (and save retyping!)
930
+	 *
931
+	 * @param  string $nonce     The nonce sent
932
+	 * @param  string $nonce_ref The nonce reference string (name0)
933
+	 * @return void
934
+	 * @throws EE_Error
935
+	 */
936
+	protected function _verify_nonce($nonce, $nonce_ref)
937
+	{
938
+		// verify nonce against expected value
939
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
940
+			// these are not the droids you are looking for !!!
941
+			$msg = sprintf(
942
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
943
+				'<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
944
+				'</a>'
945
+			);
946
+			if (WP_DEBUG) {
947
+				$msg .= "\n  " . sprintf(
948
+						esc_html__(
949
+							'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
950
+							'event_espresso'
951
+						),
952
+						__CLASS__
953
+					);
954
+			}
955
+			if (! defined('DOING_AJAX')) {
956
+				wp_die($msg);
957
+			} else {
958
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
959
+				$this->_return_json();
960
+			}
961
+		}
962
+	}
963
+
964
+
965
+
966
+	/**
967
+	 * _route_admin_request()
968
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
969
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
970
+	 * in the page routes and then will try to load the corresponding method.
971
+	 *
972
+	 * @return void
973
+	 * @throws EE_Error
974
+	 * @throws InvalidArgumentException
975
+	 * @throws InvalidDataTypeException
976
+	 * @throws InvalidInterfaceException
977
+	 * @throws ReflectionException
978
+	 */
979
+	protected function _route_admin_request()
980
+	{
981
+		if (! $this->_is_UI_request) {
982
+			$this->_verify_routes();
983
+		}
984
+		$nonce_check = isset($this->_route_config['require_nonce'])
985
+			? $this->_route_config['require_nonce']
986
+			: true;
987
+		if ($this->_req_action !== 'default' && $nonce_check) {
988
+			// set nonce from post data
989
+			$nonce = isset($this->_req_data[$this->_req_nonce])
990
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
991
+				: '';
992
+			$this->_verify_nonce($nonce, $this->_req_nonce);
993
+		}
994
+		//set the nav_tabs array but ONLY if this is  UI_request
995
+		if ($this->_is_UI_request) {
996
+			$this->_set_nav_tabs();
997
+		}
998
+		// grab callback function
999
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
1000
+		// check if callback has args
1001
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1002
+		$error_msg = '';
1003
+		// action right before calling route
1004
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1005
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1006
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1007
+		}
1008
+		// right before calling the route, let's remove _wp_http_referer from the
1009
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1010
+		$_SERVER['REQUEST_URI'] = remove_query_arg(
1011
+				'_wp_http_referer',
1012
+				wp_unslash($_SERVER['REQUEST_URI'])
1013
+		);
1014
+		if (! empty($func)) {
1015
+			if (is_array($func)) {
1016
+				list($class, $method) = $func;
1017
+			} elseif (strpos($func, '::') !== false) {
1018
+				list($class, $method) = explode('::', $func);
1019
+			} else {
1020
+				$class  = $this;
1021
+				$method = $func;
1022
+			}
1023
+			if (! (is_object($class) && $class === $this)) {
1024
+				// send along this admin page object for access by addons.
1025
+				$args['admin_page_object'] = $this;
1026
+			}
1027
+			if (
1028
+				//is it a method on a class that doesn't work?
1029
+				(
1030
+					(
1031
+						method_exists($class, $method)
1032
+						&& call_user_func_array(array($class, $method), $args) === false
1033
+					)
1034
+					&& (
1035
+						//is it a standalone function that doesn't work?
1036
+						function_exists($method)
1037
+						&& call_user_func_array(
1038
+							$func,
1039
+							array_merge(array('admin_page_object' => $this), $args)
1040
+						   ) === false
1041
+					)
1042
+				)
1043
+				|| (
1044
+					//is it neither a class method NOR a standalone function?
1045
+					! method_exists($class, $method)
1046
+					&& ! function_exists($method)
1047
+				)
1048
+			) {
1049
+				// user error msg
1050
+				$error_msg = esc_html__(
1051
+					'An error occurred. The  requested page route could not be found.',
1052
+					'event_espresso'
1053
+				);
1054
+				// developer error msg
1055
+				$error_msg .= '||';
1056
+				$error_msg .= sprintf(
1057
+					esc_html__(
1058
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1059
+						'event_espresso'
1060
+					),
1061
+					$method
1062
+				);
1063
+			}
1064
+			if (! empty($error_msg)) {
1065
+				throw new EE_Error($error_msg);
1066
+			}
1067
+		}
1068
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1069
+		// then we need to reset the routing properties to the new route.
1070
+		//now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1071
+		if ($this->_is_UI_request === false
1072
+			&& is_array($this->_route)
1073
+			&& ! empty($this->_route['headers_sent_route'])
1074
+		) {
1075
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1076
+		}
1077
+	}
1078
+
1079
+
1080
+
1081
+	/**
1082
+	 * This method just allows the resetting of page properties in the case where a no headers
1083
+	 * route redirects to a headers route in its route config.
1084
+	 *
1085
+	 * @since   4.3.0
1086
+	 * @param  string $new_route New (non header) route to redirect to.
1087
+	 * @return   void
1088
+	 * @throws ReflectionException
1089
+	 * @throws InvalidArgumentException
1090
+	 * @throws InvalidInterfaceException
1091
+	 * @throws InvalidDataTypeException
1092
+	 * @throws EE_Error
1093
+	 */
1094
+	protected function _reset_routing_properties($new_route)
1095
+	{
1096
+		$this->_is_UI_request = true;
1097
+		//now we set the current route to whatever the headers_sent_route is set at
1098
+		$this->_req_data['action'] = $new_route;
1099
+		//rerun page setup
1100
+		$this->_page_setup();
1101
+	}
1102
+
1103
+
1104
+
1105
+	/**
1106
+	 * _add_query_arg
1107
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1108
+	 *(internally just uses EEH_URL's function with the same name)
1109
+	 *
1110
+	 * @param array  $args
1111
+	 * @param string $url
1112
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1113
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1114
+	 *                                        Example usage: If the current page is:
1115
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1116
+	 *                                        &action=default&event_id=20&month_range=March%202015
1117
+	 *                                        &_wpnonce=5467821
1118
+	 *                                        and you call:
1119
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1120
+	 *                                        array(
1121
+	 *                                        'action' => 'resend_something',
1122
+	 *                                        'page=>espresso_registrations'
1123
+	 *                                        ),
1124
+	 *                                        $some_url,
1125
+	 *                                        true
1126
+	 *                                        );
1127
+	 *                                        It will produce a url in this structure:
1128
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1129
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1130
+	 *                                        month_range]=March%202015
1131
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1132
+	 * @return string
1133
+	 */
1134
+	public static function add_query_args_and_nonce(
1135
+		$args = array(),
1136
+		$url = false,
1137
+		$sticky = false,
1138
+		$exclude_nonce = false
1139
+	) {
1140
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
1141
+		if ($sticky) {
1142
+			$request = $_REQUEST;
1143
+			unset($request['_wp_http_referer']);
1144
+			unset($request['wp_referer']);
1145
+			foreach ($request as $key => $value) {
1146
+				//do not add nonces
1147
+				if (strpos($key, 'nonce') !== false) {
1148
+					continue;
1149
+				}
1150
+				$args['wp_referer[' . $key . ']'] = $value;
1151
+			}
1152
+		}
1153
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1154
+	}
1155
+
1156
+
1157
+
1158
+	/**
1159
+	 * This returns a generated link that will load the related help tab.
1160
+	 *
1161
+	 * @param  string $help_tab_id the id for the connected help tab
1162
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1163
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1164
+	 * @uses EEH_Template::get_help_tab_link()
1165
+	 * @return string              generated link
1166
+	 */
1167
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1168
+	{
1169
+		return EEH_Template::get_help_tab_link(
1170
+			$help_tab_id,
1171
+			$this->page_slug,
1172
+			$this->_req_action,
1173
+			$icon_style,
1174
+			$help_text
1175
+		);
1176
+	}
1177
+
1178
+
1179
+
1180
+	/**
1181
+	 * _add_help_tabs
1182
+	 * Note child classes define their help tabs within the page_config array.
1183
+	 *
1184
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1185
+	 * @return void
1186
+	 * @throws DomainException
1187
+	 * @throws EE_Error
1188
+	 */
1189
+	protected function _add_help_tabs()
1190
+	{
1191
+		$tour_buttons = '';
1192
+		if (isset($this->_page_config[$this->_req_action])) {
1193
+			$config = $this->_page_config[$this->_req_action];
1194
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1195
+			if (isset($this->_help_tour[$this->_req_action])) {
1196
+				$tb           = array();
1197
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1198
+				foreach ($this->_help_tour['tours'] as $tour) {
1199
+					//if this is the end tour then we don't need to setup a button
1200
+					if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1201
+						continue;
1202
+					}
1203
+					$tb[] = '<button id="trigger-tour-'
1204
+							. $tour->get_slug()
1205
+							. '" class="button-primary trigger-ee-help-tour">'
1206
+							. $tour->get_label()
1207
+							. '</button>';
1208
+				}
1209
+				$tour_buttons .= implode('<br />', $tb);
1210
+				$tour_buttons .= '</div></div>';
1211
+			}
1212
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1213
+			if (is_array($config) && isset($config['help_sidebar'])) {
1214
+				//check that the callback given is valid
1215
+				if (! method_exists($this, $config['help_sidebar'])) {
1216
+					throw new EE_Error(
1217
+						sprintf(
1218
+							esc_html__(
1219
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1220
+								'event_espresso'
1221
+							),
1222
+							$config['help_sidebar'],
1223
+							get_class($this)
1224
+						)
1225
+					);
1226
+				}
1227
+				$content = apply_filters(
1228
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1229
+					$this->{$config['help_sidebar']}()
1230
+				);
1231
+				$content .= $tour_buttons; //add help tour buttons.
1232
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1233
+				$this->_current_screen->set_help_sidebar($content);
1234
+			}
1235
+			//if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1236
+			if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1237
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1238
+			}
1239
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1240
+			if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1241
+				$_ht['id']      = $this->page_slug;
1242
+				$_ht['title']   = esc_html__('Help Tours', 'event_espresso');
1243
+				$_ht['content'] = '<p>' . esc_html__(
1244
+						'The buttons to the right allow you to start/restart any help tours available for this page',
1245
+						'event_espresso'
1246
+					) . '</p>';
1247
+				$this->_current_screen->add_help_tab($_ht);
1248
+			}
1249
+			if (! isset($config['help_tabs'])) {
1250
+				return;
1251
+			} //no help tabs for this route
1252
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1253
+				//we're here so there ARE help tabs!
1254
+				//make sure we've got what we need
1255
+				if (! isset($cfg['title'])) {
1256
+					throw new EE_Error(
1257
+						esc_html__(
1258
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1259
+							'event_espresso'
1260
+						)
1261
+					);
1262
+				}
1263
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1264
+					throw new EE_Error(
1265
+						esc_html__(
1266
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1267
+							'event_espresso'
1268
+						)
1269
+					);
1270
+				}
1271
+				//first priority goes to content.
1272
+				if (! empty($cfg['content'])) {
1273
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1274
+					//second priority goes to filename
1275
+				} elseif (! empty($cfg['filename'])) {
1276
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1277
+					//it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1278
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1279
+															 . basename($this->_get_dir())
1280
+															 . '/help_tabs/'
1281
+															 . $cfg['filename']
1282
+															 . '.help_tab.php' : $file_path;
1283
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1284
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1285
+						EE_Error::add_error(
1286
+							sprintf(
1287
+								esc_html__(
1288
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1289
+									'event_espresso'
1290
+								),
1291
+								$tab_id,
1292
+								key($config),
1293
+								$file_path
1294
+							),
1295
+							__FILE__,
1296
+							__FUNCTION__,
1297
+							__LINE__
1298
+						);
1299
+						return;
1300
+					}
1301
+					$template_args['admin_page_obj'] = $this;
1302
+					$content = EEH_Template::display_template(
1303
+						$file_path,
1304
+						$template_args,
1305
+						true
1306
+					);
1307
+				} else {
1308
+					$content = '';
1309
+				}
1310
+				//check if callback is valid
1311
+				if (
1312
+					empty($content) && (
1313
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1314
+					)
1315
+				) {
1316
+					EE_Error::add_error(
1317
+						sprintf(
1318
+							esc_html__(
1319
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1320
+								'event_espresso'
1321
+							),
1322
+							$cfg['title']
1323
+						),
1324
+						__FILE__,
1325
+						__FUNCTION__,
1326
+						__LINE__
1327
+					);
1328
+					return;
1329
+				}
1330
+				//setup config array for help tab method
1331
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1332
+				$_ht = array(
1333
+					'id'       => $id,
1334
+					'title'    => $cfg['title'],
1335
+					'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1336
+					'content'  => $content,
1337
+				);
1338
+				$this->_current_screen->add_help_tab($_ht);
1339
+			}
1340
+		}
1341
+	}
1342
+
1343
+
1344
+
1345
+	/**
1346
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1347
+	 * an array with properties for setting up usage of the joyride plugin
1348
+	 *
1349
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1350
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1351
+	 *         _set_page_config() comments
1352
+	 * @return void
1353
+	 * @throws EE_Error
1354
+	 * @throws InvalidArgumentException
1355
+	 * @throws InvalidDataTypeException
1356
+	 * @throws InvalidInterfaceException
1357
+	 */
1358
+	protected function _add_help_tour()
1359
+	{
1360
+		$tours            = array();
1361
+		$this->_help_tour = array();
1362
+		//exit early if help tours are turned off globally
1363
+		if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1364
+			|| ! EE_Registry::instance()->CFG->admin->help_tour_activation
1365
+		) {
1366
+			return;
1367
+		}
1368
+		//loop through _page_config to find any help_tour defined
1369
+		foreach ($this->_page_config as $route => $config) {
1370
+			//we're only going to set things up for this route
1371
+			if ($route !== $this->_req_action) {
1372
+				continue;
1373
+			}
1374
+			if (isset($config['help_tour'])) {
1375
+				foreach ($config['help_tour'] as $tour) {
1376
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1377
+					// let's see if we can get that file...
1378
+					// if not its possible this is a decaf route not set in caffeinated
1379
+					// so lets try and get the caffeinated equivalent
1380
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1381
+															 . basename($this->_get_dir())
1382
+															 . '/help_tours/'
1383
+															 . $tour
1384
+															 . '.class.php' : $file_path;
1385
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1386
+					if (! is_readable($file_path)) {
1387
+						EE_Error::add_error(
1388
+							sprintf(
1389
+								esc_html__(
1390
+									'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1391
+									'event_espresso'
1392
+								),
1393
+								$file_path,
1394
+								$tour
1395
+							),
1396
+							__FILE__,
1397
+							__FUNCTION__,
1398
+							__LINE__
1399
+						);
1400
+						return;
1401
+					}
1402
+					require_once $file_path;
1403
+					if (! class_exists($tour)) {
1404
+						$error_msg[] = sprintf(
1405
+							esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1406
+							$tour
1407
+						);
1408
+						$error_msg[] = $error_msg[0] . "\r\n" . sprintf(
1409
+								esc_html__(
1410
+									'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1411
+									'event_espresso'
1412
+								),
1413
+								$tour,
1414
+								'<br />',
1415
+								$tour,
1416
+								$this->_req_action,
1417
+								get_class($this)
1418
+							);
1419
+						throw new EE_Error(implode('||', $error_msg));
1420
+					}
1421
+					$tour_obj                   = new $tour($this->_is_caf);
1422
+					$tours[]                    = $tour_obj;
1423
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1424
+				}
1425
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1426
+				$end_stop_tour              = new EE_Help_Tour_final_stop($this->_is_caf);
1427
+				$tours[]                    = $end_stop_tour;
1428
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1429
+			}
1430
+		}
1431
+		if (! empty($tours)) {
1432
+			$this->_help_tour['tours'] = $tours;
1433
+		}
1434
+		// that's it!  Now that the $_help_tours property is set (or not)
1435
+		// the scripts and html should be taken care of automatically.
1436
+	}
1437
+
1438
+
1439
+
1440
+	/**
1441
+	 * This simply sets up any qtips that have been defined in the page config
1442
+	 *
1443
+	 * @return void
1444
+	 */
1445
+	protected function _add_qtips()
1446
+	{
1447
+		if (isset($this->_route_config['qtips'])) {
1448
+			$qtips = (array)$this->_route_config['qtips'];
1449
+			//load qtip loader
1450
+			$path = array(
1451
+				$this->_get_dir() . '/qtips/',
1452
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1453
+			);
1454
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1455
+		}
1456
+	}
1457
+
1458
+
1459
+
1460
+	/**
1461
+	 * _set_nav_tabs
1462
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1463
+	 * wish to add additional tabs or modify accordingly.
1464
+	 *
1465
+	 * @return void
1466
+	 * @throws InvalidArgumentException
1467
+	 * @throws InvalidInterfaceException
1468
+	 * @throws InvalidDataTypeException
1469
+	 */
1470
+	protected function _set_nav_tabs()
1471
+	{
1472
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1473
+		$i = 0;
1474
+		foreach ($this->_page_config as $slug => $config) {
1475
+			if (
1476
+				! is_array($config)
1477
+				|| (
1478
+					is_array($config)
1479
+					&& (
1480
+						(isset($config['nav']) && ! $config['nav'])
1481
+						|| ! isset($config['nav'])
1482
+					)
1483
+				)
1484
+			) {
1485
+				continue;
1486
+			}
1487
+			//no nav tab for this config
1488
+			//check for persistent flag
1489
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1490
+				// nav tab is only to appear when route requested.
1491
+				continue;
1492
+			}
1493
+			if (! $this->check_user_access($slug, true)) {
1494
+				// no nav tab because current user does not have access.
1495
+				continue;
1496
+			}
1497
+			$css_class              = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1498
+			$this->_nav_tabs[$slug] = array(
1499
+				'url'       => isset($config['nav']['url'])
1500
+					? $config['nav']['url']
1501
+					: self::add_query_args_and_nonce(
1502
+						array('action' => $slug),
1503
+						$this->_admin_base_url
1504
+					),
1505
+				'link_text' => isset($config['nav']['label'])
1506
+					? $config['nav']['label']
1507
+					: ucwords(
1508
+						str_replace('_', ' ', $slug)
1509
+					),
1510
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1511
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1512
+			);
1513
+			$i++;
1514
+		}
1515
+		//if $this->_nav_tabs is empty then lets set the default
1516
+		if (empty($this->_nav_tabs)) {
1517
+			$this->_nav_tabs[$this->_default_nav_tab_name] = array(
1518
+				'url'       => $this->_admin_base_url,
1519
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1520
+				'css_class' => 'nav-tab-active',
1521
+				'order'     => 10,
1522
+			);
1523
+		}
1524
+		//now let's sort the tabs according to order
1525
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1526
+	}
1527
+
1528
+
1529
+
1530
+	/**
1531
+	 * _set_current_labels
1532
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1533
+	 * property array
1534
+	 *
1535
+	 * @return void
1536
+	 */
1537
+	private function _set_current_labels()
1538
+	{
1539
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1540
+			foreach ($this->_route_config['labels'] as $label => $text) {
1541
+				if (is_array($text)) {
1542
+					foreach ($text as $sublabel => $subtext) {
1543
+						$this->_labels[$label][$sublabel] = $subtext;
1544
+					}
1545
+				} else {
1546
+					$this->_labels[$label] = $text;
1547
+				}
1548
+			}
1549
+		}
1550
+	}
1551
+
1552
+
1553
+
1554
+	/**
1555
+	 *        verifies user access for this admin page
1556
+	 *
1557
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1558
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1559
+	 *                               return false if verify fail.
1560
+	 * @return bool
1561
+	 * @throws InvalidArgumentException
1562
+	 * @throws InvalidDataTypeException
1563
+	 * @throws InvalidInterfaceException
1564
+	 */
1565
+	public function check_user_access($route_to_check = '', $verify_only = false)
1566
+	{
1567
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1568
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1569
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1570
+						  && is_array(
1571
+							  $this->_page_routes[$route_to_check]
1572
+						  )
1573
+						  && ! empty($this->_page_routes[$route_to_check]['capability'])
1574
+			? $this->_page_routes[$route_to_check]['capability'] : null;
1575
+		if (empty($capability) && empty($route_to_check)) {
1576
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1577
+				: $this->_route['capability'];
1578
+		} else {
1579
+			$capability = empty($capability) ? 'manage_options' : $capability;
1580
+		}
1581
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1582
+		if (
1583
+			! defined('DOING_AJAX')
1584
+			&& (
1585
+				! function_exists('is_admin')
1586
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1587
+					$capability,
1588
+					$this->page_slug
1589
+					. '_'
1590
+					. $route_to_check,
1591
+					$id
1592
+				)
1593
+			)
1594
+		) {
1595
+			if ($verify_only) {
1596
+				return false;
1597
+			}
1598
+			if (is_user_logged_in()) {
1599
+				wp_die(__('You do not have access to this route.', 'event_espresso'));
1600
+			} else {
1601
+				return false;
1602
+			}
1603
+		}
1604
+		return true;
1605
+	}
1606
+
1607
+
1608
+
1609
+	/**
1610
+	 * admin_init_global
1611
+	 * This runs all the code that we want executed within the WP admin_init hook.
1612
+	 * This method executes for ALL EE Admin pages.
1613
+	 *
1614
+	 * @return void
1615
+	 */
1616
+	public function admin_init_global()
1617
+	{
1618
+	}
1619
+
1620
+
1621
+
1622
+	/**
1623
+	 * wp_loaded_global
1624
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1625
+	 * EE_Admin page and will execute on every EE Admin Page load
1626
+	 *
1627
+	 * @return void
1628
+	 */
1629
+	public function wp_loaded()
1630
+	{
1631
+	}
1632
+
1633
+
1634
+
1635
+	/**
1636
+	 * admin_notices
1637
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1638
+	 * ALL EE_Admin pages.
1639
+	 *
1640
+	 * @return void
1641
+	 */
1642
+	public function admin_notices_global()
1643
+	{
1644
+		$this->_display_no_javascript_warning();
1645
+		$this->_display_espresso_notices();
1646
+	}
1647
+
1648
+
1649
+
1650
+	public function network_admin_notices_global()
1651
+	{
1652
+		$this->_display_no_javascript_warning();
1653
+		$this->_display_espresso_notices();
1654
+	}
1655
+
1656
+
1657
+
1658
+	/**
1659
+	 * admin_footer_scripts_global
1660
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1661
+	 * will apply on ALL EE_Admin pages.
1662
+	 *
1663
+	 * @return void
1664
+	 */
1665
+	public function admin_footer_scripts_global()
1666
+	{
1667
+		$this->_add_admin_page_ajax_loading_img();
1668
+		$this->_add_admin_page_overlay();
1669
+		//if metaboxes are present we need to add the nonce field
1670
+		if (
1671
+			 isset($this->_route_config['metaboxes'])
1672
+			 || isset($this->_route_config['list_table'])
1673
+			 || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1674
+		) {
1675
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1676
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1677
+		}
1678
+	}
1679
+
1680
+
1681
+
1682
+	/**
1683
+	 * admin_footer_global
1684
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1685
+	 * ALL EE_Admin Pages.
1686
+	 *
1687
+	 * @return void
1688
+	 * @throws EE_Error
1689
+	 */
1690
+	public function admin_footer_global()
1691
+	{
1692
+		//dialog container for dialog helper
1693
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1694
+		$d_cont .= '<div class="ee-notices"></div>';
1695
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1696
+		$d_cont .= '</div>';
1697
+		echo $d_cont;
1698
+		//help tour stuff?
1699
+		if (isset($this->_help_tour[$this->_req_action])) {
1700
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1701
+		}
1702
+		//current set timezone for timezone js
1703
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1704
+	}
1705
+
1706
+
1707
+
1708
+	/**
1709
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1710
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1711
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1712
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1713
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1714
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1715
+	 * for the
1716
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1717
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1718
+	 *    'help_trigger_id' => array(
1719
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1720
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1721
+	 *    )
1722
+	 * );
1723
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1724
+	 *
1725
+	 * @param array $help_array
1726
+	 * @param bool  $display
1727
+	 * @return string content
1728
+	 * @throws DomainException
1729
+	 * @throws EE_Error
1730
+	 */
1731
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1732
+	{
1733
+		$content       = '';
1734
+		$help_array    = empty($help_array) ? $this->_get_help_content() : $help_array;
1735
+		//loop through the array and setup content
1736
+		foreach ($help_array as $trigger => $help) {
1737
+			//make sure the array is setup properly
1738
+			if (! isset($help['title']) || ! isset($help['content'])) {
1739
+				throw new EE_Error(
1740
+					esc_html__(
1741
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1742
+						'event_espresso'
1743
+					)
1744
+				);
1745
+			}
1746
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1747
+			$template_args = array(
1748
+				'help_popup_id'      => $trigger,
1749
+				'help_popup_title'   => $help['title'],
1750
+				'help_popup_content' => $help['content'],
1751
+			);
1752
+			$content       .= EEH_Template::display_template(
1753
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1754
+				$template_args,
1755
+				true
1756
+			);
1757
+		}
1758
+		if ($display) {
1759
+			echo $content;
1760
+			return '';
1761
+		}
1762
+		return $content;
1763
+	}
1764
+
1765
+
1766
+
1767
+	/**
1768
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1769
+	 *
1770
+	 * @return array properly formatted array for help popup content
1771
+	 * @throws EE_Error
1772
+	 */
1773
+	private function _get_help_content()
1774
+	{
1775
+		//what is the method we're looking for?
1776
+		$method_name = '_help_popup_content_' . $this->_req_action;
1777
+		//if method doesn't exist let's get out.
1778
+		if (! method_exists($this, $method_name)) {
1779
+			return array();
1780
+		}
1781
+		//k we're good to go let's retrieve the help array
1782
+		$help_array = call_user_func(array($this, $method_name));
1783
+		//make sure we've got an array!
1784
+		if (! is_array($help_array)) {
1785
+			throw new EE_Error(
1786
+				esc_html__(
1787
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1788
+					'event_espresso'
1789
+				)
1790
+			);
1791
+		}
1792
+		return $help_array;
1793
+	}
1794
+
1795
+
1796
+
1797
+	/**
1798
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1799
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1800
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1801
+	 *
1802
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1803
+	 * @param boolean $display    if false then we return the trigger string
1804
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1805
+	 * @return string
1806
+	 * @throws DomainException
1807
+	 * @throws EE_Error
1808
+	 */
1809
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1810
+	{
1811
+		if (defined('DOING_AJAX')) {
1812
+			return '';
1813
+		}
1814
+		//let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1815
+		$help_array   = $this->_get_help_content();
1816
+		$help_content = '';
1817
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1818
+			$help_array[$trigger_id] = array(
1819
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1820
+				'content' => esc_html__(
1821
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1822
+					'event_espresso'
1823
+				),
1824
+			);
1825
+			$help_content            = $this->_set_help_popup_content($help_array, false);
1826
+		}
1827
+		//let's setup the trigger
1828
+		$content = '<a class="ee-dialog" href="?height='
1829
+				   . $dimensions[0]
1830
+				   . '&width='
1831
+				   . $dimensions[1]
1832
+				   . '&inlineId='
1833
+				   . $trigger_id
1834
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1835
+		$content .= $help_content;
1836
+		if ($display) {
1837
+			echo $content;
1838
+			return  '';
1839
+		}
1840
+		return $content;
1841
+	}
1842
+
1843
+
1844
+
1845
+	/**
1846
+	 * _add_global_screen_options
1847
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1848
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1849
+	 *
1850
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1851
+	 *         see also WP_Screen object documents...
1852
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1853
+	 * @abstract
1854
+	 * @return void
1855
+	 */
1856
+	private function _add_global_screen_options()
1857
+	{
1858
+	}
1859
+
1860
+
1861
+
1862
+	/**
1863
+	 * _add_global_feature_pointers
1864
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1865
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1866
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1867
+	 *
1868
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1869
+	 *         extended) also see:
1870
+	 * @link   http://eamann.com/tech/wordpress-portland/
1871
+	 * @abstract
1872
+	 * @return void
1873
+	 */
1874
+	private function _add_global_feature_pointers()
1875
+	{
1876
+	}
1877
+
1878
+
1879
+
1880
+	/**
1881
+	 * load_global_scripts_styles
1882
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1883
+	 *
1884
+	 * @return void
1885
+	 * @throws EE_Error
1886
+	 */
1887
+	public function load_global_scripts_styles()
1888
+	{
1889
+		/** STYLES **/
1890
+		// add debugging styles
1891
+		if (WP_DEBUG) {
1892
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1893
+		}
1894
+		// register all styles
1895
+		wp_register_style(
1896
+			'espresso-ui-theme',
1897
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1898
+			array(),
1899
+			EVENT_ESPRESSO_VERSION
1900
+		);
1901
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1902
+		//helpers styles
1903
+		wp_register_style(
1904
+			'ee-text-links',
1905
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1906
+			array(),
1907
+			EVENT_ESPRESSO_VERSION
1908
+		);
1909
+		/** SCRIPTS **/
1910
+		//register all scripts
1911
+		wp_register_script(
1912
+			'ee-dialog',
1913
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1914
+			array('jquery', 'jquery-ui-draggable'),
1915
+			EVENT_ESPRESSO_VERSION,
1916
+			true
1917
+		);
1918
+		wp_register_script(
1919
+			'ee_admin_js',
1920
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1921
+			array('espresso_core', 'ee-parse-uri', 'ee-dialog'),
1922
+			EVENT_ESPRESSO_VERSION,
1923
+			true
1924
+		);
1925
+		wp_register_script(
1926
+			'jquery-ui-timepicker-addon',
1927
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1928
+			array('jquery-ui-datepicker', 'jquery-ui-slider'),
1929
+			EVENT_ESPRESSO_VERSION,
1930
+			true
1931
+		);
1932
+		add_filter('FHEE_load_joyride', '__return_true');
1933
+		//script for sorting tables
1934
+		wp_register_script(
1935
+			'espresso_ajax_table_sorting',
1936
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1937
+			array('ee_admin_js', 'jquery-ui-sortable'),
1938
+			EVENT_ESPRESSO_VERSION,
1939
+			true
1940
+		);
1941
+		//script for parsing uri's
1942
+		wp_register_script(
1943
+			'ee-parse-uri',
1944
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1945
+			array(),
1946
+			EVENT_ESPRESSO_VERSION,
1947
+			true
1948
+		);
1949
+		//and parsing associative serialized form elements
1950
+		wp_register_script(
1951
+			'ee-serialize-full-array',
1952
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1953
+			array('jquery'),
1954
+			EVENT_ESPRESSO_VERSION,
1955
+			true
1956
+		);
1957
+		//helpers scripts
1958
+		wp_register_script(
1959
+			'ee-text-links',
1960
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1961
+			array('jquery'),
1962
+			EVENT_ESPRESSO_VERSION,
1963
+			true
1964
+		);
1965
+		wp_register_script(
1966
+			'ee-moment-core',
1967
+			EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1968
+			array(),
1969
+			EVENT_ESPRESSO_VERSION,
1970
+			true
1971
+		);
1972
+		wp_register_script(
1973
+			'ee-moment',
1974
+			EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1975
+			array('ee-moment-core'),
1976
+			EVENT_ESPRESSO_VERSION,
1977
+			true
1978
+		);
1979
+		wp_register_script(
1980
+			'ee-datepicker',
1981
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1982
+			array('jquery-ui-timepicker-addon', 'ee-moment'),
1983
+			EVENT_ESPRESSO_VERSION,
1984
+			true
1985
+		);
1986
+		//google charts
1987
+		wp_register_script(
1988
+			'google-charts',
1989
+			'https://www.gstatic.com/charts/loader.js',
1990
+			array(),
1991
+			EVENT_ESPRESSO_VERSION,
1992
+			false
1993
+		);
1994
+		// ENQUEUE ALL BASICS BY DEFAULT
1995
+		wp_enqueue_style('ee-admin-css');
1996
+		wp_enqueue_script('ee_admin_js');
1997
+		wp_enqueue_script('ee-accounting');
1998
+		wp_enqueue_script('jquery-validate');
1999
+		//taking care of metaboxes
2000
+		if (
2001
+			empty($this->_cpt_route)
2002
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
2003
+		) {
2004
+			wp_enqueue_script('dashboard');
2005
+		}
2006
+		// LOCALIZED DATA
2007
+		//localize script for ajax lazy loading
2008
+		$lazy_loader_container_ids = apply_filters(
2009
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
2010
+			array('espresso_news_post_box_content')
2011
+		);
2012
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
2013
+		/**
2014
+		 * help tour stuff
2015
+		 */
2016
+		if (! empty($this->_help_tour)) {
2017
+			//register the js for kicking things off
2018
+			wp_enqueue_script(
2019
+				'ee-help-tour',
2020
+				EE_ADMIN_URL . 'assets/ee-help-tour.js',
2021
+				array('jquery-joyride'),
2022
+				EVENT_ESPRESSO_VERSION,
2023
+				true
2024
+			);
2025
+			$tours = array();
2026
+			//setup tours for the js tour object
2027
+			foreach ($this->_help_tour['tours'] as $tour) {
2028
+				if ($tour instanceof EE_Help_Tour) {
2029
+					$tours[] = array(
2030
+						'id'      => $tour->get_slug(),
2031
+						'options' => $tour->get_options(),
2032
+					);
2033
+				}
2034
+			}
2035
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2036
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2037
+		}
2038
+	}
2039
+
2040
+
2041
+
2042
+	/**
2043
+	 *        admin_footer_scripts_eei18n_js_strings
2044
+	 *
2045
+	 * @return        void
2046
+	 */
2047
+	public function admin_footer_scripts_eei18n_js_strings()
2048
+	{
2049
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
2050
+		EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2051
+			'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2052
+			'event_espresso'
2053
+		);
2054
+		EE_Registry::$i18n_js_strings['January']        = esc_html__('January', 'event_espresso');
2055
+		EE_Registry::$i18n_js_strings['February']       = esc_html__('February', 'event_espresso');
2056
+		EE_Registry::$i18n_js_strings['March']          = esc_html__('March', 'event_espresso');
2057
+		EE_Registry::$i18n_js_strings['April']          = esc_html__('April', 'event_espresso');
2058
+		EE_Registry::$i18n_js_strings['May']            = esc_html__('May', 'event_espresso');
2059
+		EE_Registry::$i18n_js_strings['June']           = esc_html__('June', 'event_espresso');
2060
+		EE_Registry::$i18n_js_strings['July']           = esc_html__('July', 'event_espresso');
2061
+		EE_Registry::$i18n_js_strings['August']         = esc_html__('August', 'event_espresso');
2062
+		EE_Registry::$i18n_js_strings['September']      = esc_html__('September', 'event_espresso');
2063
+		EE_Registry::$i18n_js_strings['October']        = esc_html__('October', 'event_espresso');
2064
+		EE_Registry::$i18n_js_strings['November']       = esc_html__('November', 'event_espresso');
2065
+		EE_Registry::$i18n_js_strings['December']       = esc_html__('December', 'event_espresso');
2066
+		EE_Registry::$i18n_js_strings['Jan']            = esc_html__('Jan', 'event_espresso');
2067
+		EE_Registry::$i18n_js_strings['Feb']            = esc_html__('Feb', 'event_espresso');
2068
+		EE_Registry::$i18n_js_strings['Mar']            = esc_html__('Mar', 'event_espresso');
2069
+		EE_Registry::$i18n_js_strings['Apr']            = esc_html__('Apr', 'event_espresso');
2070
+		EE_Registry::$i18n_js_strings['May']            = esc_html__('May', 'event_espresso');
2071
+		EE_Registry::$i18n_js_strings['Jun']            = esc_html__('Jun', 'event_espresso');
2072
+		EE_Registry::$i18n_js_strings['Jul']            = esc_html__('Jul', 'event_espresso');
2073
+		EE_Registry::$i18n_js_strings['Aug']            = esc_html__('Aug', 'event_espresso');
2074
+		EE_Registry::$i18n_js_strings['Sep']            = esc_html__('Sep', 'event_espresso');
2075
+		EE_Registry::$i18n_js_strings['Oct']            = esc_html__('Oct', 'event_espresso');
2076
+		EE_Registry::$i18n_js_strings['Nov']            = esc_html__('Nov', 'event_espresso');
2077
+		EE_Registry::$i18n_js_strings['Dec']            = esc_html__('Dec', 'event_espresso');
2078
+		EE_Registry::$i18n_js_strings['Sunday']         = esc_html__('Sunday', 'event_espresso');
2079
+		EE_Registry::$i18n_js_strings['Monday']         = esc_html__('Monday', 'event_espresso');
2080
+		EE_Registry::$i18n_js_strings['Tuesday']        = esc_html__('Tuesday', 'event_espresso');
2081
+		EE_Registry::$i18n_js_strings['Wednesday']      = esc_html__('Wednesday', 'event_espresso');
2082
+		EE_Registry::$i18n_js_strings['Thursday']       = esc_html__('Thursday', 'event_espresso');
2083
+		EE_Registry::$i18n_js_strings['Friday']         = esc_html__('Friday', 'event_espresso');
2084
+		EE_Registry::$i18n_js_strings['Saturday']       = esc_html__('Saturday', 'event_espresso');
2085
+		EE_Registry::$i18n_js_strings['Sun']            = esc_html__('Sun', 'event_espresso');
2086
+		EE_Registry::$i18n_js_strings['Mon']            = esc_html__('Mon', 'event_espresso');
2087
+		EE_Registry::$i18n_js_strings['Tue']            = esc_html__('Tue', 'event_espresso');
2088
+		EE_Registry::$i18n_js_strings['Wed']            = esc_html__('Wed', 'event_espresso');
2089
+		EE_Registry::$i18n_js_strings['Thu']            = esc_html__('Thu', 'event_espresso');
2090
+		EE_Registry::$i18n_js_strings['Fri']            = esc_html__('Fri', 'event_espresso');
2091
+		EE_Registry::$i18n_js_strings['Sat']            = esc_html__('Sat', 'event_espresso');
2092
+	}
2093
+
2094
+
2095
+
2096
+	/**
2097
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2098
+	 *
2099
+	 * @return        void
2100
+	 */
2101
+	public function add_xdebug_style()
2102
+	{
2103
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2104
+	}
2105
+
2106
+
2107
+	/************************/
2108
+	/** LIST TABLE METHODS **/
2109
+	/************************/
2110
+	/**
2111
+	 * this sets up the list table if the current view requires it.
2112
+	 *
2113
+	 * @return void
2114
+	 * @throws EE_Error
2115
+	 */
2116
+	protected function _set_list_table()
2117
+	{
2118
+		//first is this a list_table view?
2119
+		if (! isset($this->_route_config['list_table'])) {
2120
+			return;
2121
+		} //not a list_table view so get out.
2122
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2123
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2124
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2125
+			//user error msg
2126
+			$error_msg = esc_html__(
2127
+				'An error occurred. The requested list table views could not be found.',
2128
+				'event_espresso'
2129
+			);
2130
+			//developer error msg
2131
+			$error_msg .= '||' . sprintf(
2132
+					esc_html__(
2133
+						'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2134
+						'event_espresso'
2135
+					),
2136
+					$this->_req_action,
2137
+					$list_table_view
2138
+				);
2139
+			throw new EE_Error($error_msg);
2140
+		}
2141
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2142
+		$this->_views = apply_filters(
2143
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2144
+			$this->_views
2145
+		);
2146
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2147
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2148
+		$this->_set_list_table_view();
2149
+		$this->_set_list_table_object();
2150
+	}
2151
+
2152
+
2153
+
2154
+	/**
2155
+	 * set current view for List Table
2156
+	 *
2157
+	 * @return void
2158
+	 */
2159
+	protected function _set_list_table_view()
2160
+	{
2161
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2162
+		// looking at active items or dumpster diving ?
2163
+		if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2164
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2165
+		} else {
2166
+			$this->_view = sanitize_key($this->_req_data['status']);
2167
+		}
2168
+	}
2169
+
2170
+
2171
+
2172
+	/**
2173
+	 * _set_list_table_object
2174
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2175
+	 *
2176
+	 * @throws EE_Error
2177
+	 */
2178
+	protected function _set_list_table_object()
2179
+	{
2180
+		if (isset($this->_route_config['list_table'])) {
2181
+			if (! class_exists($this->_route_config['list_table'])) {
2182
+				throw new EE_Error(
2183
+					sprintf(
2184
+						esc_html__(
2185
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2186
+							'event_espresso'
2187
+						),
2188
+						$this->_route_config['list_table'],
2189
+						get_class($this)
2190
+					)
2191
+				);
2192
+			}
2193
+			$list_table               = $this->_route_config['list_table'];
2194
+			$this->_list_table_object = new $list_table($this);
2195
+		}
2196
+	}
2197
+
2198
+
2199
+
2200
+	/**
2201
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2202
+	 *
2203
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2204
+	 *                                                    urls.  The array should be indexed by the view it is being
2205
+	 *                                                    added to.
2206
+	 * @return array
2207
+	 */
2208
+	public function get_list_table_view_RLs($extra_query_args = array())
2209
+	{
2210
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2211
+		if (empty($this->_views)) {
2212
+			$this->_views = array();
2213
+		}
2214
+		// cycle thru views
2215
+		foreach ($this->_views as $key => $view) {
2216
+			$query_args = array();
2217
+			// check for current view
2218
+			$this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2219
+			$query_args['action']                      = $this->_req_action;
2220
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2221
+			$query_args['status']                      = $view['slug'];
2222
+			//merge any other arguments sent in.
2223
+			if (isset($extra_query_args[$view['slug']])) {
2224
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
2225
+			}
2226
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2227
+		}
2228
+		return $this->_views;
2229
+	}
2230
+
2231
+
2232
+
2233
+	/**
2234
+	 * _entries_per_page_dropdown
2235
+	 * generates a drop down box for selecting the number of visible rows in an admin page list table
2236
+	 *
2237
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2238
+	 *         WP does it.
2239
+	 * @param int $max_entries total number of rows in the table
2240
+	 * @return string
2241
+	 */
2242
+	protected function _entries_per_page_dropdown($max_entries = 0)
2243
+	{
2244
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2245
+		$values   = array(10, 25, 50, 100);
2246
+		$per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2247
+		if ($max_entries) {
2248
+			$values[] = $max_entries;
2249
+			sort($values);
2250
+		}
2251
+		$entries_per_page_dropdown = '
2252 2252
 			<div id="entries-per-page-dv" class="alignleft actions">
2253 2253
 				<label class="hide-if-no-js">
2254 2254
 					Show
2255 2255
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2256
-        foreach ($values as $value) {
2257
-            if ($value < $max_entries) {
2258
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2259
-                $entries_per_page_dropdown .= '
2256
+		foreach ($values as $value) {
2257
+			if ($value < $max_entries) {
2258
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2259
+				$entries_per_page_dropdown .= '
2260 2260
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2261
-            }
2262
-        }
2263
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2264
-        $entries_per_page_dropdown .= '
2261
+			}
2262
+		}
2263
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2264
+		$entries_per_page_dropdown .= '
2265 2265
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2266
-        $entries_per_page_dropdown .= '
2266
+		$entries_per_page_dropdown .= '
2267 2267
 					</select>
2268 2268
 					entries
2269 2269
 				</label>
2270 2270
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2271 2271
 			</div>
2272 2272
 		';
2273
-        return $entries_per_page_dropdown;
2274
-    }
2275
-
2276
-
2277
-
2278
-    /**
2279
-     *        _set_search_attributes
2280
-     *
2281
-     * @return        void
2282
-     */
2283
-    public function _set_search_attributes()
2284
-    {
2285
-        $this->_template_args['search']['btn_label'] = sprintf(
2286
-            esc_html__('Search %s', 'event_espresso'),
2287
-            empty($this->_search_btn_label) ? $this->page_label
2288
-                : $this->_search_btn_label
2289
-        );
2290
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2291
-    }
2292
-
2293
-
2294
-
2295
-    /*** END LIST TABLE METHODS **/
2296
-
2297
-
2298
-
2299
-    /**
2300
-     * _add_registered_metaboxes
2301
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2302
-     *
2303
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2304
-     * @return void
2305
-     * @throws EE_Error
2306
-     */
2307
-    private function _add_registered_meta_boxes()
2308
-    {
2309
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2310
-        //we only add meta boxes if the page_route calls for it
2311
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2312
-            && is_array(
2313
-                $this->_route_config['metaboxes']
2314
-            )
2315
-        ) {
2316
-            // this simply loops through the callbacks provided
2317
-            // and checks if there is a corresponding callback registered by the child
2318
-            // if there is then we go ahead and process the metabox loader.
2319
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2320
-                // first check for Closures
2321
-                if ($metabox_callback instanceof Closure) {
2322
-                    $result = $metabox_callback();
2323
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2324
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2325
-                } else {
2326
-                    $result = call_user_func(array($this, &$metabox_callback));
2327
-                }
2328
-                if ($result === false) {
2329
-                    // user error msg
2330
-                    $error_msg = esc_html__(
2331
-                            'An error occurred. The  requested metabox could not be found.',
2332
-                            'event_espresso'
2333
-                    );
2334
-                    // developer error msg
2335
-                    $error_msg .= '||' . sprintf(
2336
-                            esc_html__(
2337
-                                'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2338
-                                'event_espresso'
2339
-                            ),
2340
-                            $metabox_callback
2341
-                        );
2342
-                    throw new EE_Error($error_msg);
2343
-                }
2344
-            }
2345
-        }
2346
-    }
2347
-
2348
-
2349
-
2350
-    /**
2351
-     * _add_screen_columns
2352
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2353
-     * the dynamic column template and we'll setup the column options for the page.
2354
-     *
2355
-     * @return void
2356
-     */
2357
-    private function _add_screen_columns()
2358
-    {
2359
-        if (
2360
-            is_array($this->_route_config)
2361
-            && isset($this->_route_config['columns'])
2362
-            && is_array($this->_route_config['columns'])
2363
-            && count($this->_route_config['columns']) === 2
2364
-        ) {
2365
-            add_screen_option(
2366
-                'layout_columns',
2367
-                array(
2368
-                    'max'     => (int)$this->_route_config['columns'][0],
2369
-                    'default' => (int)$this->_route_config['columns'][1],
2370
-                )
2371
-            );
2372
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2373
-            $screen_id                                           = $this->_current_screen->id;
2374
-            $screen_columns                                      = (int)get_user_option("screen_layout_{$screen_id}");
2375
-            $total_columns                                       = ! empty($screen_columns)
2376
-                ? $screen_columns
2377
-                : $this->_route_config['columns'][1];
2378
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2379
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2380
-            $this->_template_args['screen']                      = $this->_current_screen;
2381
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2382
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2383
-            // finally if we don't have has_metaboxes set in the route config
2384
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2385
-            $this->_route_config['has_metaboxes'] = true;
2386
-        }
2387
-    }
2388
-
2389
-
2390
-
2391
-    /** GLOBALLY AVAILABLE METABOXES **/
2392
-
2393
-
2394
-    /**
2395
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2396
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2397
-     * these get loaded on.
2398
-     */
2399
-    private function _espresso_news_post_box()
2400
-    {
2401
-        $news_box_title = apply_filters(
2402
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2403
-            esc_html__('New @ Event Espresso', 'event_espresso')
2404
-        );
2405
-        add_meta_box(
2406
-            'espresso_news_post_box',
2407
-            $news_box_title,
2408
-            array(
2409
-                $this,
2410
-                'espresso_news_post_box',
2411
-            ),
2412
-            $this->_wp_page_slug,
2413
-            'side'
2414
-        );
2415
-    }
2416
-
2417
-
2418
-
2419
-    /**
2420
-     * Code for setting up espresso ratings request metabox.
2421
-     */
2422
-    protected function _espresso_ratings_request()
2423
-    {
2424
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2425
-            return;
2426
-        }
2427
-        $ratings_box_title = apply_filters(
2428
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2429
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2430
-        );
2431
-        add_meta_box(
2432
-            'espresso_ratings_request',
2433
-            $ratings_box_title,
2434
-            array(
2435
-                $this,
2436
-                'espresso_ratings_request',
2437
-            ),
2438
-            $this->_wp_page_slug,
2439
-            'side'
2440
-        );
2441
-    }
2442
-
2443
-
2444
-
2445
-    /**
2446
-     * Code for setting up espresso ratings request metabox content.
2447
-     *
2448
-     * @throws DomainException
2449
-     */
2450
-    public function espresso_ratings_request()
2451
-    {
2452
-        EEH_Template::display_template(
2453
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2454
-                array()
2455
-        );
2456
-    }
2457
-
2458
-
2459
-
2460
-    public static function cached_rss_display($rss_id, $url)
2461
-    {
2462
-        $loading    = '<p class="widget-loading hide-if-no-js">'
2463
-                      . __('Loading&#8230;')
2464
-                      . '</p><p class="hide-if-js">'
2465
-                      . esc_html__('This widget requires JavaScript.')
2466
-                      . '</p>';
2467
-        $pre        = '<div class="espresso-rss-display">' . "\n\t";
2468
-        $pre        .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2469
-        $post       = '</div>' . "\n";
2470
-        $cache_key  = 'ee_rss_' . md5($rss_id);
2471
-        $output = get_transient($cache_key);
2472
-        if ($output !== false) {
2473
-            echo $pre . $output . $post;
2474
-            return true;
2475
-        }
2476
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2477
-            echo $pre . $loading . $post;
2478
-            return false;
2479
-        }
2480
-        ob_start();
2481
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2482
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2483
-        return true;
2484
-    }
2485
-
2486
-
2487
-
2488
-    public function espresso_news_post_box()
2489
-    {
2490
-        ?>
2273
+		return $entries_per_page_dropdown;
2274
+	}
2275
+
2276
+
2277
+
2278
+	/**
2279
+	 *        _set_search_attributes
2280
+	 *
2281
+	 * @return        void
2282
+	 */
2283
+	public function _set_search_attributes()
2284
+	{
2285
+		$this->_template_args['search']['btn_label'] = sprintf(
2286
+			esc_html__('Search %s', 'event_espresso'),
2287
+			empty($this->_search_btn_label) ? $this->page_label
2288
+				: $this->_search_btn_label
2289
+		);
2290
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2291
+	}
2292
+
2293
+
2294
+
2295
+	/*** END LIST TABLE METHODS **/
2296
+
2297
+
2298
+
2299
+	/**
2300
+	 * _add_registered_metaboxes
2301
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2302
+	 *
2303
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2304
+	 * @return void
2305
+	 * @throws EE_Error
2306
+	 */
2307
+	private function _add_registered_meta_boxes()
2308
+	{
2309
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2310
+		//we only add meta boxes if the page_route calls for it
2311
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2312
+			&& is_array(
2313
+				$this->_route_config['metaboxes']
2314
+			)
2315
+		) {
2316
+			// this simply loops through the callbacks provided
2317
+			// and checks if there is a corresponding callback registered by the child
2318
+			// if there is then we go ahead and process the metabox loader.
2319
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2320
+				// first check for Closures
2321
+				if ($metabox_callback instanceof Closure) {
2322
+					$result = $metabox_callback();
2323
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2324
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2325
+				} else {
2326
+					$result = call_user_func(array($this, &$metabox_callback));
2327
+				}
2328
+				if ($result === false) {
2329
+					// user error msg
2330
+					$error_msg = esc_html__(
2331
+							'An error occurred. The  requested metabox could not be found.',
2332
+							'event_espresso'
2333
+					);
2334
+					// developer error msg
2335
+					$error_msg .= '||' . sprintf(
2336
+							esc_html__(
2337
+								'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2338
+								'event_espresso'
2339
+							),
2340
+							$metabox_callback
2341
+						);
2342
+					throw new EE_Error($error_msg);
2343
+				}
2344
+			}
2345
+		}
2346
+	}
2347
+
2348
+
2349
+
2350
+	/**
2351
+	 * _add_screen_columns
2352
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2353
+	 * the dynamic column template and we'll setup the column options for the page.
2354
+	 *
2355
+	 * @return void
2356
+	 */
2357
+	private function _add_screen_columns()
2358
+	{
2359
+		if (
2360
+			is_array($this->_route_config)
2361
+			&& isset($this->_route_config['columns'])
2362
+			&& is_array($this->_route_config['columns'])
2363
+			&& count($this->_route_config['columns']) === 2
2364
+		) {
2365
+			add_screen_option(
2366
+				'layout_columns',
2367
+				array(
2368
+					'max'     => (int)$this->_route_config['columns'][0],
2369
+					'default' => (int)$this->_route_config['columns'][1],
2370
+				)
2371
+			);
2372
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2373
+			$screen_id                                           = $this->_current_screen->id;
2374
+			$screen_columns                                      = (int)get_user_option("screen_layout_{$screen_id}");
2375
+			$total_columns                                       = ! empty($screen_columns)
2376
+				? $screen_columns
2377
+				: $this->_route_config['columns'][1];
2378
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2379
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2380
+			$this->_template_args['screen']                      = $this->_current_screen;
2381
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2382
+																   . 'admin_details_metabox_column_wrapper.template.php';
2383
+			// finally if we don't have has_metaboxes set in the route config
2384
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2385
+			$this->_route_config['has_metaboxes'] = true;
2386
+		}
2387
+	}
2388
+
2389
+
2390
+
2391
+	/** GLOBALLY AVAILABLE METABOXES **/
2392
+
2393
+
2394
+	/**
2395
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2396
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2397
+	 * these get loaded on.
2398
+	 */
2399
+	private function _espresso_news_post_box()
2400
+	{
2401
+		$news_box_title = apply_filters(
2402
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2403
+			esc_html__('New @ Event Espresso', 'event_espresso')
2404
+		);
2405
+		add_meta_box(
2406
+			'espresso_news_post_box',
2407
+			$news_box_title,
2408
+			array(
2409
+				$this,
2410
+				'espresso_news_post_box',
2411
+			),
2412
+			$this->_wp_page_slug,
2413
+			'side'
2414
+		);
2415
+	}
2416
+
2417
+
2418
+
2419
+	/**
2420
+	 * Code for setting up espresso ratings request metabox.
2421
+	 */
2422
+	protected function _espresso_ratings_request()
2423
+	{
2424
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2425
+			return;
2426
+		}
2427
+		$ratings_box_title = apply_filters(
2428
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2429
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2430
+		);
2431
+		add_meta_box(
2432
+			'espresso_ratings_request',
2433
+			$ratings_box_title,
2434
+			array(
2435
+				$this,
2436
+				'espresso_ratings_request',
2437
+			),
2438
+			$this->_wp_page_slug,
2439
+			'side'
2440
+		);
2441
+	}
2442
+
2443
+
2444
+
2445
+	/**
2446
+	 * Code for setting up espresso ratings request metabox content.
2447
+	 *
2448
+	 * @throws DomainException
2449
+	 */
2450
+	public function espresso_ratings_request()
2451
+	{
2452
+		EEH_Template::display_template(
2453
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2454
+				array()
2455
+		);
2456
+	}
2457
+
2458
+
2459
+
2460
+	public static function cached_rss_display($rss_id, $url)
2461
+	{
2462
+		$loading    = '<p class="widget-loading hide-if-no-js">'
2463
+					  . __('Loading&#8230;')
2464
+					  . '</p><p class="hide-if-js">'
2465
+					  . esc_html__('This widget requires JavaScript.')
2466
+					  . '</p>';
2467
+		$pre        = '<div class="espresso-rss-display">' . "\n\t";
2468
+		$pre        .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2469
+		$post       = '</div>' . "\n";
2470
+		$cache_key  = 'ee_rss_' . md5($rss_id);
2471
+		$output = get_transient($cache_key);
2472
+		if ($output !== false) {
2473
+			echo $pre . $output . $post;
2474
+			return true;
2475
+		}
2476
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2477
+			echo $pre . $loading . $post;
2478
+			return false;
2479
+		}
2480
+		ob_start();
2481
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2482
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2483
+		return true;
2484
+	}
2485
+
2486
+
2487
+
2488
+	public function espresso_news_post_box()
2489
+	{
2490
+		?>
2491 2491
         <div class="padding">
2492 2492
             <div id="espresso_news_post_box_content" class="infolinks">
2493 2493
                 <?php
2494
-                // Get RSS Feed(s)
2495
-                self::cached_rss_display(
2496
-                    'espresso_news_post_box_content',
2497
-                    urlencode(
2498
-                        apply_filters(
2499
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2500
-                            'http://eventespresso.com/feed/'
2501
-                        )
2502
-                    )
2503
-                );
2504
-                ?>
2494
+				// Get RSS Feed(s)
2495
+				self::cached_rss_display(
2496
+					'espresso_news_post_box_content',
2497
+					urlencode(
2498
+						apply_filters(
2499
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2500
+							'http://eventespresso.com/feed/'
2501
+						)
2502
+					)
2503
+				);
2504
+				?>
2505 2505
             </div>
2506 2506
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2507 2507
         </div>
2508 2508
         <?php
2509
-    }
2510
-
2511
-
2512
-
2513
-    private function _espresso_links_post_box()
2514
-    {
2515
-        //Hiding until we actually have content to put in here...
2516
-        //add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2517
-    }
2518
-
2519
-
2520
-
2521
-    public function espresso_links_post_box()
2522
-    {
2523
-        //Hiding until we actually have content to put in here...
2524
-        // EEH_Template::display_template(
2525
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2526
-        // );
2527
-    }
2528
-
2529
-
2530
-
2531
-    protected function _espresso_sponsors_post_box()
2532
-    {
2533
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2534
-            add_meta_box(
2535
-                'espresso_sponsors_post_box',
2536
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2537
-                array($this, 'espresso_sponsors_post_box'),
2538
-                $this->_wp_page_slug,
2539
-                'side'
2540
-            );
2541
-        }
2542
-    }
2543
-
2544
-
2545
-
2546
-    public function espresso_sponsors_post_box()
2547
-    {
2548
-        EEH_Template::display_template(
2549
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2550
-        );
2551
-    }
2552
-
2553
-
2554
-
2555
-    private function _publish_post_box()
2556
-    {
2557
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2558
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2559
-        // then we'll use that for the metabox label.
2560
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2561
-        if (! empty($this->_labels['publishbox'])) {
2562
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2563
-                : $this->_labels['publishbox'];
2564
-        } else {
2565
-            $box_label = esc_html__('Publish', 'event_espresso');
2566
-        }
2567
-        $box_label = apply_filters(
2568
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2569
-            $box_label,
2570
-            $this->_req_action,
2571
-            $this
2572
-        );
2573
-        add_meta_box(
2574
-            $meta_box_ref,
2575
-            $box_label,
2576
-            array($this, 'editor_overview'),
2577
-            $this->_current_screen->id,
2578
-            'side',
2579
-            'high'
2580
-        );
2581
-    }
2582
-
2583
-
2584
-
2585
-    public function editor_overview()
2586
-    {
2587
-        //if we have extra content set let's add it in if not make sure its empty
2588
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2589
-            ? $this->_template_args['publish_box_extra_content']
2590
-            : '';
2591
-        echo EEH_Template::display_template(
2592
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2593
-            $this->_template_args,
2594
-            true
2595
-        );
2596
-    }
2597
-
2598
-
2599
-    /** end of globally available metaboxes section **/
2600
-
2601
-
2602
-
2603
-    /**
2604
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2605
-     * protected method.
2606
-     *
2607
-     * @see   $this->_set_publish_post_box_vars for param details
2608
-     * @since 4.6.0
2609
-     * @param string $name
2610
-     * @param int    $id
2611
-     * @param bool   $delete
2612
-     * @param string $save_close_redirect_URL
2613
-     * @param bool   $both_btns
2614
-     * @throws EE_Error
2615
-     * @throws InvalidArgumentException
2616
-     * @throws InvalidDataTypeException
2617
-     * @throws InvalidInterfaceException
2618
-     */
2619
-    public function set_publish_post_box_vars(
2620
-        $name = '',
2621
-        $id = 0,
2622
-        $delete = false,
2623
-        $save_close_redirect_URL = '',
2624
-        $both_btns = true
2625
-    ) {
2626
-        $this->_set_publish_post_box_vars(
2627
-            $name,
2628
-            $id,
2629
-            $delete,
2630
-            $save_close_redirect_URL,
2631
-            $both_btns
2632
-        );
2633
-    }
2634
-
2635
-
2636
-
2637
-    /**
2638
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2639
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2640
-     * save, and save and close buttons to work properly, then you will want to include a
2641
-     * values for the name and id arguments.
2642
-     *
2643
-     * @todo  Add in validation for name/id arguments.
2644
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2645
-     * @param    int     $id                      id attached to the item published
2646
-     * @param    string  $delete                  page route callback for the delete action
2647
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2648
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2649
-     *                                            the Save button
2650
-     * @throws EE_Error
2651
-     * @throws InvalidArgumentException
2652
-     * @throws InvalidDataTypeException
2653
-     * @throws InvalidInterfaceException
2654
-     */
2655
-    protected function _set_publish_post_box_vars(
2656
-        $name = '',
2657
-        $id = 0,
2658
-        $delete = '',
2659
-        $save_close_redirect_URL = '',
2660
-        $both_btns = true
2661
-    ) {
2662
-        // if Save & Close, use a custom redirect URL or default to the main page?
2663
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2664
-            ? $save_close_redirect_URL
2665
-            : $this->_admin_base_url;
2666
-        // create the Save & Close and Save buttons
2667
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2668
-        //if we have extra content set let's add it in if not make sure its empty
2669
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2670
-            ? $this->_template_args['publish_box_extra_content']
2671
-            : '';
2672
-        if ($delete && ! empty($id)) {
2673
-            //make sure we have a default if just true is sent.
2674
-            $delete           = ! empty($delete) ? $delete : 'delete';
2675
-            $delete_link_args = array($name => $id);
2676
-            $delete           = $this->get_action_link_or_button(
2677
-                $delete,
2678
-                $delete,
2679
-                $delete_link_args,
2680
-                'submitdelete deletion',
2681
-                '',
2682
-                false
2683
-            );
2684
-        }
2685
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2686
-        if (! empty($name) && ! empty($id)) {
2687
-            $hidden_field_arr[$name] = array(
2688
-                'type'  => 'hidden',
2689
-                'value' => $id,
2690
-            );
2691
-            $hf                      = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2692
-        } else {
2693
-            $hf = '';
2694
-        }
2695
-        // add hidden field
2696
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2697
-            ? $hf[$name]['field']
2698
-            : $hf;
2699
-    }
2700
-
2701
-
2702
-
2703
-    /**
2704
-     * displays an error message to ppl who have javascript disabled
2705
-     *
2706
-     * @return void
2707
-     */
2708
-    private function _display_no_javascript_warning()
2709
-    {
2710
-        ?>
2509
+	}
2510
+
2511
+
2512
+
2513
+	private function _espresso_links_post_box()
2514
+	{
2515
+		//Hiding until we actually have content to put in here...
2516
+		//add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2517
+	}
2518
+
2519
+
2520
+
2521
+	public function espresso_links_post_box()
2522
+	{
2523
+		//Hiding until we actually have content to put in here...
2524
+		// EEH_Template::display_template(
2525
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2526
+		// );
2527
+	}
2528
+
2529
+
2530
+
2531
+	protected function _espresso_sponsors_post_box()
2532
+	{
2533
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2534
+			add_meta_box(
2535
+				'espresso_sponsors_post_box',
2536
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2537
+				array($this, 'espresso_sponsors_post_box'),
2538
+				$this->_wp_page_slug,
2539
+				'side'
2540
+			);
2541
+		}
2542
+	}
2543
+
2544
+
2545
+
2546
+	public function espresso_sponsors_post_box()
2547
+	{
2548
+		EEH_Template::display_template(
2549
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2550
+		);
2551
+	}
2552
+
2553
+
2554
+
2555
+	private function _publish_post_box()
2556
+	{
2557
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2558
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2559
+		// then we'll use that for the metabox label.
2560
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2561
+		if (! empty($this->_labels['publishbox'])) {
2562
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2563
+				: $this->_labels['publishbox'];
2564
+		} else {
2565
+			$box_label = esc_html__('Publish', 'event_espresso');
2566
+		}
2567
+		$box_label = apply_filters(
2568
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2569
+			$box_label,
2570
+			$this->_req_action,
2571
+			$this
2572
+		);
2573
+		add_meta_box(
2574
+			$meta_box_ref,
2575
+			$box_label,
2576
+			array($this, 'editor_overview'),
2577
+			$this->_current_screen->id,
2578
+			'side',
2579
+			'high'
2580
+		);
2581
+	}
2582
+
2583
+
2584
+
2585
+	public function editor_overview()
2586
+	{
2587
+		//if we have extra content set let's add it in if not make sure its empty
2588
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2589
+			? $this->_template_args['publish_box_extra_content']
2590
+			: '';
2591
+		echo EEH_Template::display_template(
2592
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2593
+			$this->_template_args,
2594
+			true
2595
+		);
2596
+	}
2597
+
2598
+
2599
+	/** end of globally available metaboxes section **/
2600
+
2601
+
2602
+
2603
+	/**
2604
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2605
+	 * protected method.
2606
+	 *
2607
+	 * @see   $this->_set_publish_post_box_vars for param details
2608
+	 * @since 4.6.0
2609
+	 * @param string $name
2610
+	 * @param int    $id
2611
+	 * @param bool   $delete
2612
+	 * @param string $save_close_redirect_URL
2613
+	 * @param bool   $both_btns
2614
+	 * @throws EE_Error
2615
+	 * @throws InvalidArgumentException
2616
+	 * @throws InvalidDataTypeException
2617
+	 * @throws InvalidInterfaceException
2618
+	 */
2619
+	public function set_publish_post_box_vars(
2620
+		$name = '',
2621
+		$id = 0,
2622
+		$delete = false,
2623
+		$save_close_redirect_URL = '',
2624
+		$both_btns = true
2625
+	) {
2626
+		$this->_set_publish_post_box_vars(
2627
+			$name,
2628
+			$id,
2629
+			$delete,
2630
+			$save_close_redirect_URL,
2631
+			$both_btns
2632
+		);
2633
+	}
2634
+
2635
+
2636
+
2637
+	/**
2638
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2639
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2640
+	 * save, and save and close buttons to work properly, then you will want to include a
2641
+	 * values for the name and id arguments.
2642
+	 *
2643
+	 * @todo  Add in validation for name/id arguments.
2644
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2645
+	 * @param    int     $id                      id attached to the item published
2646
+	 * @param    string  $delete                  page route callback for the delete action
2647
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2648
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2649
+	 *                                            the Save button
2650
+	 * @throws EE_Error
2651
+	 * @throws InvalidArgumentException
2652
+	 * @throws InvalidDataTypeException
2653
+	 * @throws InvalidInterfaceException
2654
+	 */
2655
+	protected function _set_publish_post_box_vars(
2656
+		$name = '',
2657
+		$id = 0,
2658
+		$delete = '',
2659
+		$save_close_redirect_URL = '',
2660
+		$both_btns = true
2661
+	) {
2662
+		// if Save & Close, use a custom redirect URL or default to the main page?
2663
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2664
+			? $save_close_redirect_URL
2665
+			: $this->_admin_base_url;
2666
+		// create the Save & Close and Save buttons
2667
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2668
+		//if we have extra content set let's add it in if not make sure its empty
2669
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2670
+			? $this->_template_args['publish_box_extra_content']
2671
+			: '';
2672
+		if ($delete && ! empty($id)) {
2673
+			//make sure we have a default if just true is sent.
2674
+			$delete           = ! empty($delete) ? $delete : 'delete';
2675
+			$delete_link_args = array($name => $id);
2676
+			$delete           = $this->get_action_link_or_button(
2677
+				$delete,
2678
+				$delete,
2679
+				$delete_link_args,
2680
+				'submitdelete deletion',
2681
+				'',
2682
+				false
2683
+			);
2684
+		}
2685
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2686
+		if (! empty($name) && ! empty($id)) {
2687
+			$hidden_field_arr[$name] = array(
2688
+				'type'  => 'hidden',
2689
+				'value' => $id,
2690
+			);
2691
+			$hf                      = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2692
+		} else {
2693
+			$hf = '';
2694
+		}
2695
+		// add hidden field
2696
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2697
+			? $hf[$name]['field']
2698
+			: $hf;
2699
+	}
2700
+
2701
+
2702
+
2703
+	/**
2704
+	 * displays an error message to ppl who have javascript disabled
2705
+	 *
2706
+	 * @return void
2707
+	 */
2708
+	private function _display_no_javascript_warning()
2709
+	{
2710
+		?>
2711 2711
         <noscript>
2712 2712
             <div id="no-js-message" class="error">
2713 2713
                 <p style="font-size:1.3em;">
2714 2714
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2715 2715
                     <?php esc_html_e(
2716
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2717
-                        'event_espresso'
2718
-                    ); ?>
2716
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2717
+						'event_espresso'
2718
+					); ?>
2719 2719
                 </p>
2720 2720
             </div>
2721 2721
         </noscript>
2722 2722
         <?php
2723
-    }
2723
+	}
2724 2724
 
2725 2725
 
2726 2726
 
2727
-    /**
2728
-     * displays espresso success and/or error notices
2729
-     *
2730
-     * @return void
2731
-     */
2732
-    private function _display_espresso_notices()
2733
-    {
2734
-        $notices = $this->_get_transient(true);
2735
-        echo stripslashes($notices);
2736
-    }
2727
+	/**
2728
+	 * displays espresso success and/or error notices
2729
+	 *
2730
+	 * @return void
2731
+	 */
2732
+	private function _display_espresso_notices()
2733
+	{
2734
+		$notices = $this->_get_transient(true);
2735
+		echo stripslashes($notices);
2736
+	}
2737 2737
 
2738 2738
 
2739 2739
 
2740
-    /**
2741
-     * spinny things pacify the masses
2742
-     *
2743
-     * @return void
2744
-     */
2745
-    protected function _add_admin_page_ajax_loading_img()
2746
-    {
2747
-        ?>
2740
+	/**
2741
+	 * spinny things pacify the masses
2742
+	 *
2743
+	 * @return void
2744
+	 */
2745
+	protected function _add_admin_page_ajax_loading_img()
2746
+	{
2747
+		?>
2748 2748
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2749 2749
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e(
2750
-                    'loading...',
2751
-                    'event_espresso'
2752
-                ); ?></span>
2750
+					'loading...',
2751
+					'event_espresso'
2752
+				); ?></span>
2753 2753
         </div>
2754 2754
         <?php
2755
-    }
2755
+	}
2756 2756
 
2757 2757
 
2758 2758
 
2759
-    /**
2760
-     * add admin page overlay for modal boxes
2761
-     *
2762
-     * @return void
2763
-     */
2764
-    protected function _add_admin_page_overlay()
2765
-    {
2766
-        ?>
2759
+	/**
2760
+	 * add admin page overlay for modal boxes
2761
+	 *
2762
+	 * @return void
2763
+	 */
2764
+	protected function _add_admin_page_overlay()
2765
+	{
2766
+		?>
2767 2767
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2768 2768
         <?php
2769
-    }
2770
-
2771
-
2772
-
2773
-    /**
2774
-     * facade for add_meta_box
2775
-     *
2776
-     * @param string  $action        where the metabox get's displayed
2777
-     * @param string  $title         Title of Metabox (output in metabox header)
2778
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2779
-     *                               instead of the one created in here.
2780
-     * @param array   $callback_args an array of args supplied for the metabox
2781
-     * @param string  $column        what metabox column
2782
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2783
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2784
-     *                               created but just set our own callback for wp's add_meta_box.
2785
-     * @throws \DomainException
2786
-     */
2787
-    public function _add_admin_page_meta_box(
2788
-        $action,
2789
-        $title,
2790
-        $callback,
2791
-        $callback_args,
2792
-        $column = 'normal',
2793
-        $priority = 'high',
2794
-        $create_func = true
2795
-    ) {
2796
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2797
-        //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2798
-        if (empty($callback_args) && $create_func) {
2799
-            $callback_args = array(
2800
-                'template_path' => $this->_template_path,
2801
-                'template_args' => $this->_template_args,
2802
-            );
2803
-        }
2804
-        //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2805
-        $call_back_func = $create_func
2806
-            ? function ($post, $metabox)
2807
-            {
2808
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2809
-                echo EEH_Template::display_template(
2810
-                    $metabox['args']['template_path'],
2811
-                    $metabox['args']['template_args'],
2812
-                    true
2813
-                );
2814
-            }
2815
-            : $callback;
2816
-        add_meta_box(
2817
-            str_replace('_', '-', $action) . '-mbox',
2818
-            $title,
2819
-            $call_back_func,
2820
-            $this->_wp_page_slug,
2821
-            $column,
2822
-            $priority,
2823
-            $callback_args
2824
-        );
2825
-    }
2826
-
2827
-
2828
-
2829
-    /**
2830
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2831
-     *
2832
-     * @throws DomainException
2833
-     * @throws EE_Error
2834
-     */
2835
-    public function display_admin_page_with_metabox_columns()
2836
-    {
2837
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2838
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2839
-            $this->_column_template_path,
2840
-            $this->_template_args,
2841
-            true
2842
-        );
2843
-        //the final wrapper
2844
-        $this->admin_page_wrapper();
2845
-    }
2846
-
2847
-
2848
-
2849
-    /**
2850
-     * generates  HTML wrapper for an admin details page
2851
-     *
2852
-     * @return void
2853
-     * @throws EE_Error
2854
-     * @throws DomainException
2855
-     */
2856
-    public function display_admin_page_with_sidebar()
2857
-    {
2858
-        $this->_display_admin_page(true);
2859
-    }
2860
-
2861
-
2862
-
2863
-    /**
2864
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2865
-     *
2866
-     * @return void
2867
-     * @throws EE_Error
2868
-     * @throws DomainException
2869
-     */
2870
-    public function display_admin_page_with_no_sidebar()
2871
-    {
2872
-        $this->_display_admin_page();
2873
-    }
2874
-
2875
-
2876
-
2877
-    /**
2878
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2879
-     *
2880
-     * @return void
2881
-     * @throws EE_Error
2882
-     * @throws DomainException
2883
-     */
2884
-    public function display_about_admin_page()
2885
-    {
2886
-        $this->_display_admin_page(false, true);
2887
-    }
2888
-
2889
-
2890
-
2891
-    /**
2892
-     * display_admin_page
2893
-     * contains the code for actually displaying an admin page
2894
-     *
2895
-     * @param  boolean $sidebar true with sidebar, false without
2896
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2897
-     * @return void
2898
-     * @throws DomainException
2899
-     * @throws EE_Error
2900
-     */
2901
-    private function _display_admin_page($sidebar = false, $about = false)
2902
-    {
2903
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2904
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2905
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2906
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2907
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2908
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2909
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2910
-            ? 'poststuff'
2911
-            : 'espresso-default-admin';
2912
-        $template_path                                     = $sidebar
2913
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2914
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2915
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2916
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2917
-        }
2918
-        $template_path                                     = ! empty($this->_column_template_path)
2919
-            ? $this->_column_template_path : $template_path;
2920
-        $this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2921
-            ? $this->_template_args['admin_page_content']
2922
-            : '';
2923
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2924
-            ? $this->_template_args['before_admin_page_content']
2925
-            : '';
2926
-        $this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2927
-            ? $this->_template_args['after_admin_page_content']
2928
-            : '';
2929
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2930
-            $template_path,
2931
-            $this->_template_args,
2932
-            true
2933
-        );
2934
-        // the final template wrapper
2935
-        $this->admin_page_wrapper($about);
2936
-    }
2937
-
2938
-
2939
-
2940
-    /**
2941
-     * This is used to display caf preview pages.
2942
-     *
2943
-     * @since 4.3.2
2944
-     * @param string $utm_campaign_source what is the key used for google analytics link
2945
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2946
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2947
-     * @return void
2948
-     * @throws DomainException
2949
-     * @throws EE_Error
2950
-     * @throws InvalidArgumentException
2951
-     * @throws InvalidDataTypeException
2952
-     * @throws InvalidInterfaceException
2953
-     */
2954
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2955
-    {
2956
-        //let's generate a default preview action button if there isn't one already present.
2957
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2958
-            'Upgrade to Event Espresso 4 Right Now',
2959
-            'event_espresso'
2960
-        );
2961
-        $buy_now_url                                   = add_query_arg(
2962
-            array(
2963
-                'ee_ver'       => 'ee4',
2964
-                'utm_source'   => 'ee4_plugin_admin',
2965
-                'utm_medium'   => 'link',
2966
-                'utm_campaign' => $utm_campaign_source,
2967
-                'utm_content'  => 'buy_now_button',
2968
-            ),
2969
-            'http://eventespresso.com/pricing/'
2970
-        );
2971
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2972
-            ? $this->get_action_link_or_button(
2973
-                '',
2974
-                'buy_now',
2975
-                array(),
2976
-                'button-primary button-large',
2977
-                $buy_now_url,
2978
-                true
2979
-            )
2980
-            : $this->_template_args['preview_action_button'];
2981
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2982
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2983
-            $this->_template_args,
2984
-            true
2985
-        );
2986
-        $this->_display_admin_page($display_sidebar);
2987
-    }
2988
-
2989
-
2990
-
2991
-    /**
2992
-     * display_admin_list_table_page_with_sidebar
2993
-     * generates HTML wrapper for an admin_page with list_table
2994
-     *
2995
-     * @return void
2996
-     * @throws EE_Error
2997
-     * @throws DomainException
2998
-     */
2999
-    public function display_admin_list_table_page_with_sidebar()
3000
-    {
3001
-        $this->_display_admin_list_table_page(true);
3002
-    }
3003
-
3004
-
3005
-
3006
-    /**
3007
-     * display_admin_list_table_page_with_no_sidebar
3008
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
3009
-     *
3010
-     * @return void
3011
-     * @throws EE_Error
3012
-     * @throws DomainException
3013
-     */
3014
-    public function display_admin_list_table_page_with_no_sidebar()
3015
-    {
3016
-        $this->_display_admin_list_table_page();
3017
-    }
3018
-
3019
-
3020
-
3021
-    /**
3022
-     * generates html wrapper for an admin_list_table page
3023
-     *
3024
-     * @param boolean $sidebar whether to display with sidebar or not.
3025
-     * @return void
3026
-     * @throws DomainException
3027
-     * @throws EE_Error
3028
-     */
3029
-    private function _display_admin_list_table_page($sidebar = false)
3030
-    {
3031
-        //setup search attributes
3032
-        $this->_set_search_attributes();
3033
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
3034
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3035
-        $this->_template_args['table_url']        = defined('DOING_AJAX')
3036
-            ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
3037
-            : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
3038
-        $this->_template_args['list_table']       = $this->_list_table_object;
3039
-        $this->_template_args['current_route']    = $this->_req_action;
3040
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3041
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
3042
-        if (! empty($ajax_sorting_callback)) {
3043
-            $sortable_list_table_form_fields = wp_nonce_field(
3044
-                $ajax_sorting_callback . '_nonce',
3045
-                $ajax_sorting_callback . '_nonce',
3046
-                false,
3047
-                false
3048
-            );
3049
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
3050
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
3051
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3052
-                                                . $this->page_slug
3053
-                                                . '" />';
3054
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3055
-                                                . $ajax_sorting_callback
3056
-                                                . '" />';
3057
-        } else {
3058
-            $sortable_list_table_form_fields = '';
3059
-        }
3060
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3061
-        $hidden_form_fields                                      = isset($this->_template_args['list_table_hidden_fields'])
3062
-            ? $this->_template_args['list_table_hidden_fields']
3063
-            : '';
3064
-        $nonce_ref                                               = $this->_req_action . '_nonce';
3065
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
3066
-                                                                    . $nonce_ref
3067
-                                                                    . '" value="'
3068
-                                                                    . wp_create_nonce($nonce_ref)
3069
-                                                                    . '">';
3070
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
3071
-        //display message about search results?
3072
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3073
-            ? '<p class="ee-search-results">' . sprintf(
3074
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3075
-                trim($this->_req_data['s'], '%')
3076
-            ) . '</p>'
3077
-            : '';
3078
-        // filter before_list_table template arg
3079
-        $this->_template_args['before_list_table'] = apply_filters(
3080
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3081
-            $this->_template_args['before_list_table'],
3082
-            $this->page_slug,
3083
-            $this->_req_data,
3084
-            $this->_req_action
3085
-        );
3086
-        // convert to array and filter again
3087
-        // arrays are easier to inject new items in a specific location,
3088
-        // but would not be backwards compatible, so we have to add a new filter
3089
-        $this->_template_args['before_list_table'] = implode(
3090
-            " \n",
3091
-            (array)apply_filters(
3092
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3093
-                (array)$this->_template_args['before_list_table'],
3094
-                $this->page_slug,
3095
-                $this->_req_data,
3096
-                $this->_req_action
3097
-            )
3098
-        );
3099
-        // filter after_list_table template arg
3100
-        $this->_template_args['after_list_table'] = apply_filters(
3101
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3102
-            $this->_template_args['after_list_table'],
3103
-            $this->page_slug,
3104
-            $this->_req_data,
3105
-            $this->_req_action
3106
-        );
3107
-        // convert to array and filter again
3108
-        // arrays are easier to inject new items in a specific location,
3109
-        // but would not be backwards compatible, so we have to add a new filter
3110
-        $this->_template_args['after_list_table']   = implode(
3111
-            " \n",
3112
-            (array)apply_filters(
3113
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3114
-                (array)$this->_template_args['after_list_table'],
3115
-                $this->page_slug,
3116
-                $this->_req_data,
3117
-                $this->_req_action
3118
-            )
3119
-        );
3120
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3121
-            $template_path,
3122
-            $this->_template_args,
3123
-            true
3124
-        );
3125
-        // the final template wrapper
3126
-        if ($sidebar) {
3127
-            $this->display_admin_page_with_sidebar();
3128
-        } else {
3129
-            $this->display_admin_page_with_no_sidebar();
3130
-        }
3131
-    }
3132
-
3133
-
3134
-
3135
-    /**
3136
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3137
-     * html string for the legend.
3138
-     * $items are expected in an array in the following format:
3139
-     * $legend_items = array(
3140
-     *        'item_id' => array(
3141
-     *            'icon' => 'http://url_to_icon_being_described.png',
3142
-     *            'desc' => esc_html__('localized description of item');
3143
-     *        )
3144
-     * );
3145
-     *
3146
-     * @param  array $items see above for format of array
3147
-     * @return string html string of legend
3148
-     * @throws DomainException
3149
-     */
3150
-    protected function _display_legend($items)
3151
-    {
3152
-        $this->_template_args['items'] = apply_filters(
3153
-            'FHEE__EE_Admin_Page___display_legend__items',
3154
-            (array)$items,
3155
-            $this
3156
-        );
3157
-        return EEH_Template::display_template(
3158
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3159
-            $this->_template_args,
3160
-            true
3161
-        );
3162
-    }
3163
-
3164
-
3165
-    /**
3166
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3167
-     * The returned json object is created from an array in the following format:
3168
-     * array(
3169
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3170
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3171
-     *  'notices' => '', // - contains any EE_Error formatted notices
3172
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3173
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3174
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3175
-     *  that might be included in here)
3176
-     * )
3177
-     * The json object is populated by whatever is set in the $_template_args property.
3178
-     *
3179
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3180
-     *                                 instead of displayed.
3181
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3182
-     * @return void
3183
-     * @throws EE_Error
3184
-     */
3185
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
3186
-    {
3187
-        //make sure any EE_Error notices have been handled.
3188
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3189
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3190
-        unset($this->_template_args['data']);
3191
-        $json = array(
3192
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3193
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3194
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3195
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3196
-            'notices'   => EE_Error::get_notices(),
3197
-            'content'   => isset($this->_template_args['admin_page_content'])
3198
-                ? $this->_template_args['admin_page_content'] : '',
3199
-            'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3200
-            'isEEajax'  => true
3201
-            //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3202
-        );
3203
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3204
-        if (null === error_get_last() || ! headers_sent()) {
3205
-            header('Content-Type: application/json; charset=UTF-8');
3206
-        }
3207
-        echo wp_json_encode($json);
3208
-        exit();
3209
-    }
3210
-
3211
-
3212
-
3213
-    /**
3214
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3215
-     *
3216
-     * @return void
3217
-     * @throws EE_Error
3218
-     */
3219
-    public function return_json()
3220
-    {
3221
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3222
-            $this->_return_json();
3223
-        } else {
3224
-            throw new EE_Error(
3225
-                sprintf(
3226
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3227
-                    __FUNCTION__
3228
-                )
3229
-            );
3230
-        }
3231
-    }
3232
-
3233
-
3234
-
3235
-    /**
3236
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3237
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3238
-     *
3239
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3240
-     */
3241
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3242
-    {
3243
-        $this->_hook_obj = $hook_obj;
3244
-    }
3245
-
3246
-
3247
-
3248
-    /**
3249
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3250
-     *
3251
-     * @param  boolean $about whether to use the special about page wrapper or default.
3252
-     * @return void
3253
-     * @throws DomainException
3254
-     * @throws EE_Error
3255
-     */
3256
-    public function admin_page_wrapper($about = false)
3257
-    {
3258
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3259
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3260
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3261
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3262
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3263
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3264
-            isset($this->_template_args['before_admin_page_content'])
3265
-                ? $this->_template_args['before_admin_page_content']
3266
-                : ''
3267
-        );
3268
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3269
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3270
-            isset($this->_template_args['after_admin_page_content'])
3271
-                ? $this->_template_args['after_admin_page_content']
3272
-                : ''
3273
-        );
3274
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3275
-        // load settings page wrapper template
3276
-        $template_path = ! defined('DOING_AJAX')
3277
-            ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3278
-            : EE_ADMIN_TEMPLATE
3279
-              . 'admin_wrapper_ajax.template.php';
3280
-        //about page?
3281
-        $template_path = $about
3282
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3283
-            : $template_path;
3284
-        if (defined('DOING_AJAX')) {
3285
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3286
-                $template_path,
3287
-                $this->_template_args,
3288
-                true
3289
-            );
3290
-            $this->_return_json();
3291
-        } else {
3292
-            EEH_Template::display_template($template_path, $this->_template_args);
3293
-        }
3294
-    }
3295
-
3296
-
3297
-
3298
-    /**
3299
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3300
-     *
3301
-     * @return string html
3302
-     * @throws EE_Error
3303
-     */
3304
-    protected function _get_main_nav_tabs()
3305
-    {
3306
-        // let's generate the html using the EEH_Tabbed_Content helper.
3307
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3308
-        // (rather than setting in the page_routes array)
3309
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3310
-    }
3311
-
3312
-
3313
-
3314
-    /**
3315
-     *        sort nav tabs
3316
-     *
3317
-     * @param $a
3318
-     * @param $b
3319
-     * @return int
3320
-     */
3321
-    private function _sort_nav_tabs($a, $b)
3322
-    {
3323
-        if ($a['order'] === $b['order']) {
3324
-            return 0;
3325
-        }
3326
-        return ($a['order'] < $b['order']) ? -1 : 1;
3327
-    }
3328
-
3329
-
3330
-
3331
-    /**
3332
-     *    generates HTML for the forms used on admin pages
3333
-     *
3334
-     * @param    array $input_vars - array of input field details
3335
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3336
-     *                             use)
3337
-     * @param bool     $id
3338
-     * @return string
3339
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3340
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3341
-     */
3342
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3343
-    {
3344
-        $content = $generator === 'string'
3345
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3346
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3347
-        return $content;
3348
-    }
3349
-
3350
-
3351
-
3352
-    /**
3353
-     * generates the "Save" and "Save & Close" buttons for edit forms
3354
-     *
3355
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3356
-     *                                   Close" button.
3357
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3358
-     *                                   'Save', [1] => 'save & close')
3359
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3360
-     *                                   via the "name" value in the button).  We can also use this to just dump
3361
-     *                                   default actions by submitting some other value.
3362
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3363
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3364
-     *                                   close (normal form handling).
3365
-     */
3366
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3367
-    {
3368
-        //make sure $text and $actions are in an array
3369
-        $text          = (array)$text;
3370
-        $actions       = (array)$actions;
3371
-        $referrer_url  = empty($referrer)
3372
-            ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3373
-              . $_SERVER['REQUEST_URI']
3374
-              . '" />'
3375
-            : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3376
-              . $referrer
3377
-              . '" />';
3378
-        $button_text   = ! empty($text)
3379
-            ? $text
3380
-            : array(
3381
-                esc_html__('Save', 'event_espresso'),
3382
-                esc_html__('Save and Close', 'event_espresso'),
3383
-            );
3384
-        $default_names = array('save', 'save_and_close');
3385
-        //add in a hidden index for the current page (so save and close redirects properly)
3386
-        $this->_template_args['save_buttons'] = $referrer_url;
3387
-        foreach ($button_text as $key => $button) {
3388
-            $ref                                  = $default_names[$key];
3389
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3390
-                                                     . $ref
3391
-                                                     . '" value="'
3392
-                                                     . $button
3393
-                                                     . '" name="'
3394
-                                                     . (! empty($actions) ? $actions[$key] : $ref)
3395
-                                                     . '" id="'
3396
-                                                     . $this->_current_view . '_' . $ref
3397
-                                                     . '" />';
3398
-            if (! $both) {
3399
-                break;
3400
-            }
3401
-        }
3402
-    }
3403
-
3404
-
3405
-
3406
-    /**
3407
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3408
-     *
3409
-     * @see   $this->_set_add_edit_form_tags() for details on params
3410
-     * @since 4.6.0
3411
-     * @param string $route
3412
-     * @param array  $additional_hidden_fields
3413
-     */
3414
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3415
-    {
3416
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3417
-    }
3418
-
3419
-
3420
-
3421
-    /**
3422
-     * set form open and close tags on add/edit pages.
3423
-     *
3424
-     * @param string $route                    the route you want the form to direct to
3425
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3426
-     * @return void
3427
-     */
3428
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3429
-    {
3430
-        if (empty($route)) {
3431
-            $user_msg = esc_html__(
3432
-                'An error occurred. No action was set for this page\'s form.',
3433
-                'event_espresso'
3434
-            );
3435
-            $dev_msg  = $user_msg . "\n" . sprintf(
3436
-                    esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3437
-                    __FUNCTION__,
3438
-                    __CLASS__
3439
-                );
3440
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3441
-        }
3442
-        // open form
3443
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3444
-                                                             . $this->_admin_base_url
3445
-                                                             . '" id="'
3446
-                                                             . $route
3447
-                                                             . '_event_form" >';
3448
-        // add nonce
3449
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3450
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
3451
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3452
-        // add REQUIRED form action
3453
-        $hidden_fields = array(
3454
-            'action' => array('type' => 'hidden', 'value' => $route),
3455
-        );
3456
-        // merge arrays
3457
-        $hidden_fields = is_array($additional_hidden_fields)
3458
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3459
-            : $hidden_fields;
3460
-        // generate form fields
3461
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3462
-        // add fields to form
3463
-        foreach ((array)$form_fields as $field_name => $form_field) {
3464
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3465
-        }
3466
-        // close form
3467
-        $this->_template_args['after_admin_page_content'] = '</form>';
3468
-    }
3469
-
3470
-
3471
-
3472
-    /**
3473
-     * Public Wrapper for _redirect_after_action() method since its
3474
-     * discovered it would be useful for external code to have access.
3475
-     *
3476
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3477
-     * @since 4.5.0
3478
-     * @param bool   $success
3479
-     * @param string $what
3480
-     * @param string $action_desc
3481
-     * @param array  $query_args
3482
-     * @param bool   $override_overwrite
3483
-     * @throws EE_Error
3484
-     */
3485
-    public function redirect_after_action(
3486
-        $success = false,
3487
-        $what = 'item',
3488
-        $action_desc = 'processed',
3489
-        $query_args = array(),
3490
-        $override_overwrite = false
3491
-    ) {
3492
-        $this->_redirect_after_action(
3493
-            $success,
3494
-            $what,
3495
-            $action_desc,
3496
-            $query_args,
3497
-            $override_overwrite
3498
-        );
3499
-    }
3500
-
3501
-
3502
-
3503
-    /**
3504
-     *    _redirect_after_action
3505
-     *
3506
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3507
-     * @param string $what               - what the action was performed on
3508
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3509
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3510
-     *                                   action is completed
3511
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3512
-     *                                   override this so that they show.
3513
-     * @return void
3514
-     * @throws EE_Error
3515
-     */
3516
-    protected function _redirect_after_action(
3517
-        $success = 0,
3518
-        $what = 'item',
3519
-        $action_desc = 'processed',
3520
-        $query_args = array(),
3521
-        $override_overwrite = false
3522
-    ) {
3523
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3524
-        //class name for actions/filters.
3525
-        $classname = get_class($this);
3526
-        // set redirect url.
3527
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3528
-        // otherwise we go with whatever is set as the _admin_base_url
3529
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3530
-        $notices      = EE_Error::get_notices(false);
3531
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3532
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3533
-            EE_Error::overwrite_success();
3534
-        }
3535
-        if (! empty($what) && ! empty($action_desc)  && empty($notices['errors'])) {
3536
-            // how many records affected ? more than one record ? or just one ?
3537
-            if ($success > 1) {
3538
-                // set plural msg
3539
-                EE_Error::add_success(
3540
-                    sprintf(
3541
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3542
-                        $what,
3543
-                        $action_desc
3544
-                    ),
3545
-                    __FILE__,
3546
-                    __FUNCTION__,
3547
-                    __LINE__
3548
-                );
3549
-            } elseif ($success === 1) {
3550
-                // set singular msg
3551
-                EE_Error::add_success(
3552
-                    sprintf(
3553
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3554
-                        $what,
3555
-                        $action_desc
3556
-                    ),
3557
-                    __FILE__,
3558
-                    __FUNCTION__,
3559
-                    __LINE__
3560
-                );
3561
-            }
3562
-        }
3563
-        // check that $query_args isn't something crazy
3564
-        if (! is_array($query_args)) {
3565
-            $query_args = array();
3566
-        }
3567
-        /**
3568
-         * Allow injecting actions before the query_args are modified for possible different
3569
-         * redirections on save and close actions
3570
-         *
3571
-         * @since 4.2.0
3572
-         * @param array $query_args       The original query_args array coming into the
3573
-         *                                method.
3574
-         */
3575
-        do_action(
3576
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3577
-            $query_args
3578
-        );
3579
-        //calculate where we're going (if we have a "save and close" button pushed)
3580
-        if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3581
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3582
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3583
-            // regenerate query args array from referrer URL
3584
-            parse_str($parsed_url['query'], $query_args);
3585
-            // correct page and action will be in the query args now
3586
-            $redirect_url = admin_url('admin.php');
3587
-        }
3588
-        //merge any default query_args set in _default_route_query_args property
3589
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3590
-            $args_to_merge = array();
3591
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3592
-                //is there a wp_referer array in our _default_route_query_args property?
3593
-                if ($query_param === 'wp_referer') {
3594
-                    $query_value = (array)$query_value;
3595
-                    foreach ($query_value as $reference => $value) {
3596
-                        if (strpos($reference, 'nonce') !== false) {
3597
-                            continue;
3598
-                        }
3599
-                        //finally we will override any arguments in the referer with
3600
-                        //what might be set on the _default_route_query_args array.
3601
-                        if (isset($this->_default_route_query_args[$reference])) {
3602
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3603
-                        } else {
3604
-                            $args_to_merge[$reference] = urlencode($value);
3605
-                        }
3606
-                    }
3607
-                    continue;
3608
-                }
3609
-                $args_to_merge[$query_param] = $query_value;
3610
-            }
3611
-            //now let's merge these arguments but override with what was specifically sent in to the
3612
-            //redirect.
3613
-            $query_args = array_merge($args_to_merge, $query_args);
3614
-        }
3615
-        $this->_process_notices($query_args);
3616
-        // generate redirect url
3617
-        // if redirecting to anything other than the main page, add a nonce
3618
-        if (isset($query_args['action'])) {
3619
-            // manually generate wp_nonce and merge that with the query vars
3620
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3621
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3622
-        }
3623
-        // we're adding some hooks and filters in here for processing any things just before redirects
3624
-        // (example: an admin page has done an insert or update and we want to run something after that).
3625
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3626
-        $redirect_url = apply_filters(
3627
-            'FHEE_redirect_' . $classname . $this->_req_action,
3628
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3629
-            $query_args
3630
-        );
3631
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3632
-        if (defined('DOING_AJAX')) {
3633
-            $default_data                    = array(
3634
-                'close'        => true,
3635
-                'redirect_url' => $redirect_url,
3636
-                'where'        => 'main',
3637
-                'what'         => 'append',
3638
-            );
3639
-            $this->_template_args['success'] = $success;
3640
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3641
-                $default_data,
3642
-                $this->_template_args['data']
3643
-            ) : $default_data;
3644
-            $this->_return_json();
3645
-        }
3646
-        wp_safe_redirect($redirect_url);
3647
-        exit();
3648
-    }
3649
-
3650
-
3651
-
3652
-    /**
3653
-     * process any notices before redirecting (or returning ajax request)
3654
-     * This method sets the $this->_template_args['notices'] attribute;
3655
-     *
3656
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
3657
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and
3658
-     *                                  page_routes haven't been defined yet.
3659
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we
3660
-     *                                  still save a transient for the notice.
3661
-     * @return void
3662
-     * @throws EE_Error
3663
-     */
3664
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3665
-    {
3666
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
3667
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3668
-            $notices = EE_Error::get_notices(false);
3669
-            if (empty($this->_template_args['success'])) {
3670
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3671
-            }
3672
-            if (empty($this->_template_args['errors'])) {
3673
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3674
-            }
3675
-            if (empty($this->_template_args['attention'])) {
3676
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3677
-            }
3678
-        }
3679
-        $this->_template_args['notices'] = EE_Error::get_notices();
3680
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3681
-        if (! defined('DOING_AJAX') || $sticky_notices) {
3682
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3683
-            $this->_add_transient(
3684
-                $route,
3685
-                $this->_template_args['notices'],
3686
-                true,
3687
-                $skip_route_verify
3688
-            );
3689
-        }
3690
-    }
3691
-
3692
-
3693
-
3694
-    /**
3695
-     * get_action_link_or_button
3696
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3697
-     *
3698
-     * @param string $action        use this to indicate which action the url is generated with.
3699
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3700
-     *                              property.
3701
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3702
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3703
-     * @param string $base_url      If this is not provided
3704
-     *                              the _admin_base_url will be used as the default for the button base_url.
3705
-     *                              Otherwise this value will be used.
3706
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3707
-     * @return string
3708
-     * @throws InvalidArgumentException
3709
-     * @throws InvalidInterfaceException
3710
-     * @throws InvalidDataTypeException
3711
-     * @throws EE_Error
3712
-     */
3713
-    public function get_action_link_or_button(
3714
-        $action,
3715
-        $type = 'add',
3716
-        $extra_request = array(),
3717
-        $class = 'button-primary',
3718
-        $base_url = '',
3719
-        $exclude_nonce = false
3720
-    ) {
3721
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3722
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3723
-            throw new EE_Error(
3724
-                sprintf(
3725
-                    esc_html__(
3726
-                        'There is no page route for given action for the button.  This action was given: %s',
3727
-                        'event_espresso'
3728
-                    ),
3729
-                    $action
3730
-                )
3731
-            );
3732
-        }
3733
-        if (! isset($this->_labels['buttons'][$type])) {
3734
-            throw new EE_Error(
3735
-                sprintf(
3736
-                    __(
3737
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3738
-                        'event_espresso'
3739
-                    ),
3740
-                    $type
3741
-                )
3742
-            );
3743
-        }
3744
-        //finally check user access for this button.
3745
-        $has_access = $this->check_user_access($action, true);
3746
-        if (! $has_access) {
3747
-            return '';
3748
-        }
3749
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3750
-        $query_args = array(
3751
-            'action' => $action,
3752
-        );
3753
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3754
-        if (! empty($extra_request)) {
3755
-            $query_args = array_merge($extra_request, $query_args);
3756
-        }
3757
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3758
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3759
-    }
3760
-
3761
-
3762
-
3763
-    /**
3764
-     * _per_page_screen_option
3765
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3766
-     *
3767
-     * @return void
3768
-     * @throws InvalidArgumentException
3769
-     * @throws InvalidInterfaceException
3770
-     * @throws InvalidDataTypeException
3771
-     */
3772
-    protected function _per_page_screen_option()
3773
-    {
3774
-        $option = 'per_page';
3775
-        $args   = array(
3776
-            'label'   => esc_html__(
3777
-                    apply_filters(
3778
-                        'FHEE__EE_Admin_Page___per_page_screen_options___label',
3779
-                        $this->_admin_page_title,
3780
-                        $this
3781
-                    )
3782
-            ),
3783
-            'default' => (int) apply_filters(
3784
-                    'FHEE__EE_Admin_Page___per_page_screen_options__default',
3785
-                    10
3786
-            ),
3787
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3788
-        );
3789
-        //ONLY add the screen option if the user has access to it.
3790
-        if ($this->check_user_access($this->_current_view, true)) {
3791
-            add_screen_option($option, $args);
3792
-        }
3793
-    }
3794
-
3795
-
3796
-
3797
-    /**
3798
-     * set_per_page_screen_option
3799
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3800
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3801
-     * admin_menu.
3802
-     *
3803
-     * @return void
3804
-     */
3805
-    private function _set_per_page_screen_options()
3806
-    {
3807
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3808
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3809
-            if (! $user = wp_get_current_user()) {
3810
-                return;
3811
-            }
3812
-            $option = $_POST['wp_screen_options']['option'];
3813
-            $value  = $_POST['wp_screen_options']['value'];
3814
-            if ($option != sanitize_key($option)) {
3815
-                return;
3816
-            }
3817
-            $map_option = $option;
3818
-            $option     = str_replace('-', '_', $option);
3819
-            switch ($map_option) {
3820
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3821
-                    $value = (int)$value;
3822
-                    $max_value = apply_filters(
3823
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3824
-                        999,
3825
-                        $this->_current_page,
3826
-                        $this->_current_view
3827
-                    );
3828
-                    if ($value < 1) {
3829
-                        return;
3830
-                    }
3831
-                    $value = min($value, $max_value);
3832
-                    break;
3833
-                default:
3834
-                    $value = apply_filters(
3835
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3836
-                        false,
3837
-                        $option,
3838
-                        $value
3839
-                    );
3840
-                    if (false === $value) {
3841
-                        return;
3842
-                    }
3843
-                    break;
3844
-            }
3845
-            update_user_meta($user->ID, $option, $value);
3846
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3847
-            exit;
3848
-        }
3849
-    }
3850
-
3851
-
3852
-
3853
-    /**
3854
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3855
-     *
3856
-     * @param array $data array that will be assigned to template args.
3857
-     */
3858
-    public function set_template_args($data)
3859
-    {
3860
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3861
-    }
3862
-
3863
-
3864
-
3865
-    /**
3866
-     * This makes available the WP transient system for temporarily moving data between routes
3867
-     *
3868
-     * @param string $route             the route that should receive the transient
3869
-     * @param array  $data              the data that gets sent
3870
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3871
-     *                                  normal route transient.
3872
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3873
-     *                                  when we are adding a transient before page_routes have been defined.
3874
-     * @return void
3875
-     * @throws EE_Error
3876
-     */
3877
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3878
-    {
3879
-        $user_id = get_current_user_id();
3880
-        if (! $skip_route_verify) {
3881
-            $this->_verify_route($route);
3882
-        }
3883
-        //now let's set the string for what kind of transient we're setting
3884
-        $transient = $notices
3885
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3886
-            : 'rte_tx_' . $route . '_' . $user_id;
3887
-        $data      = $notices ? array('notices' => $data) : $data;
3888
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3889
-        $existing = is_multisite() && is_network_admin()
3890
-            ? get_site_transient($transient)
3891
-            : get_transient($transient);
3892
-        if ($existing) {
3893
-            $data = array_merge((array)$data, (array)$existing);
3894
-        }
3895
-        if (is_multisite() && is_network_admin()) {
3896
-            set_site_transient($transient, $data, 8);
3897
-        } else {
3898
-            set_transient($transient, $data, 8);
3899
-        }
3900
-    }
3901
-
3902
-
3903
-
3904
-    /**
3905
-     * this retrieves the temporary transient that has been set for moving data between routes.
3906
-     *
3907
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3908
-     * @param string $route
3909
-     * @return mixed data
3910
-     */
3911
-    protected function _get_transient($notices = false, $route = '')
3912
-    {
3913
-        $user_id   = get_current_user_id();
3914
-        $route     = ! $route ? $this->_req_action : $route;
3915
-        $transient = $notices
3916
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3917
-            : 'rte_tx_' . $route . '_' . $user_id;
3918
-        $data      = is_multisite() && is_network_admin()
3919
-            ? get_site_transient($transient)
3920
-            : get_transient($transient);
3921
-        //delete transient after retrieval (just in case it hasn't expired);
3922
-        if (is_multisite() && is_network_admin()) {
3923
-            delete_site_transient($transient);
3924
-        } else {
3925
-            delete_transient($transient);
3926
-        }
3927
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3928
-    }
3929
-
3930
-
3931
-
3932
-    /**
3933
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3934
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3935
-     * default route callback on the EE_Admin page you want it run.)
3936
-     *
3937
-     * @return void
3938
-     */
3939
-    protected function _transient_garbage_collection()
3940
-    {
3941
-        global $wpdb;
3942
-        //retrieve all existing transients
3943
-        $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3944
-        if ($results = $wpdb->get_results($query)) {
3945
-            foreach ($results as $result) {
3946
-                $transient = str_replace('_transient_', '', $result->option_name);
3947
-                get_transient($transient);
3948
-                if (is_multisite() && is_network_admin()) {
3949
-                    get_site_transient($transient);
3950
-                }
3951
-            }
3952
-        }
3953
-    }
3954
-
3955
-
3956
-
3957
-    /**
3958
-     * get_view
3959
-     *
3960
-     * @return string content of _view property
3961
-     */
3962
-    public function get_view()
3963
-    {
3964
-        return $this->_view;
3965
-    }
3966
-
3967
-
3968
-
3969
-    /**
3970
-     * getter for the protected $_views property
3971
-     *
3972
-     * @return array
3973
-     */
3974
-    public function get_views()
3975
-    {
3976
-        return $this->_views;
3977
-    }
3978
-
3979
-
3980
-
3981
-    /**
3982
-     * get_current_page
3983
-     *
3984
-     * @return string _current_page property value
3985
-     */
3986
-    public function get_current_page()
3987
-    {
3988
-        return $this->_current_page;
3989
-    }
3990
-
3991
-
3992
-
3993
-    /**
3994
-     * get_current_view
3995
-     *
3996
-     * @return string _current_view property value
3997
-     */
3998
-    public function get_current_view()
3999
-    {
4000
-        return $this->_current_view;
4001
-    }
4002
-
4003
-
4004
-
4005
-    /**
4006
-     * get_current_screen
4007
-     *
4008
-     * @return object The current WP_Screen object
4009
-     */
4010
-    public function get_current_screen()
4011
-    {
4012
-        return $this->_current_screen;
4013
-    }
4014
-
4015
-
4016
-
4017
-    /**
4018
-     * get_current_page_view_url
4019
-     *
4020
-     * @return string This returns the url for the current_page_view.
4021
-     */
4022
-    public function get_current_page_view_url()
4023
-    {
4024
-        return $this->_current_page_view_url;
4025
-    }
4026
-
4027
-
4028
-
4029
-    /**
4030
-     * just returns the _req_data property
4031
-     *
4032
-     * @return array
4033
-     */
4034
-    public function get_request_data()
4035
-    {
4036
-        return $this->_req_data;
4037
-    }
4038
-
4039
-
4040
-
4041
-    /**
4042
-     * returns the _req_data protected property
4043
-     *
4044
-     * @return string
4045
-     */
4046
-    public function get_req_action()
4047
-    {
4048
-        return $this->_req_action;
4049
-    }
4050
-
4051
-
4052
-
4053
-    /**
4054
-     * @return bool  value of $_is_caf property
4055
-     */
4056
-    public function is_caf()
4057
-    {
4058
-        return $this->_is_caf;
4059
-    }
4060
-
4061
-
4062
-
4063
-    /**
4064
-     * @return mixed
4065
-     */
4066
-    public function default_espresso_metaboxes()
4067
-    {
4068
-        return $this->_default_espresso_metaboxes;
4069
-    }
4070
-
4071
-
4072
-
4073
-    /**
4074
-     * @return mixed
4075
-     */
4076
-    public function admin_base_url()
4077
-    {
4078
-        return $this->_admin_base_url;
4079
-    }
2769
+	}
2770
+
2771
+
2772
+
2773
+	/**
2774
+	 * facade for add_meta_box
2775
+	 *
2776
+	 * @param string  $action        where the metabox get's displayed
2777
+	 * @param string  $title         Title of Metabox (output in metabox header)
2778
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2779
+	 *                               instead of the one created in here.
2780
+	 * @param array   $callback_args an array of args supplied for the metabox
2781
+	 * @param string  $column        what metabox column
2782
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2783
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2784
+	 *                               created but just set our own callback for wp's add_meta_box.
2785
+	 * @throws \DomainException
2786
+	 */
2787
+	public function _add_admin_page_meta_box(
2788
+		$action,
2789
+		$title,
2790
+		$callback,
2791
+		$callback_args,
2792
+		$column = 'normal',
2793
+		$priority = 'high',
2794
+		$create_func = true
2795
+	) {
2796
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2797
+		//if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2798
+		if (empty($callback_args) && $create_func) {
2799
+			$callback_args = array(
2800
+				'template_path' => $this->_template_path,
2801
+				'template_args' => $this->_template_args,
2802
+			);
2803
+		}
2804
+		//if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2805
+		$call_back_func = $create_func
2806
+			? function ($post, $metabox)
2807
+			{
2808
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2809
+				echo EEH_Template::display_template(
2810
+					$metabox['args']['template_path'],
2811
+					$metabox['args']['template_args'],
2812
+					true
2813
+				);
2814
+			}
2815
+			: $callback;
2816
+		add_meta_box(
2817
+			str_replace('_', '-', $action) . '-mbox',
2818
+			$title,
2819
+			$call_back_func,
2820
+			$this->_wp_page_slug,
2821
+			$column,
2822
+			$priority,
2823
+			$callback_args
2824
+		);
2825
+	}
2826
+
2827
+
2828
+
2829
+	/**
2830
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2831
+	 *
2832
+	 * @throws DomainException
2833
+	 * @throws EE_Error
2834
+	 */
2835
+	public function display_admin_page_with_metabox_columns()
2836
+	{
2837
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2838
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2839
+			$this->_column_template_path,
2840
+			$this->_template_args,
2841
+			true
2842
+		);
2843
+		//the final wrapper
2844
+		$this->admin_page_wrapper();
2845
+	}
2846
+
2847
+
2848
+
2849
+	/**
2850
+	 * generates  HTML wrapper for an admin details page
2851
+	 *
2852
+	 * @return void
2853
+	 * @throws EE_Error
2854
+	 * @throws DomainException
2855
+	 */
2856
+	public function display_admin_page_with_sidebar()
2857
+	{
2858
+		$this->_display_admin_page(true);
2859
+	}
2860
+
2861
+
2862
+
2863
+	/**
2864
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2865
+	 *
2866
+	 * @return void
2867
+	 * @throws EE_Error
2868
+	 * @throws DomainException
2869
+	 */
2870
+	public function display_admin_page_with_no_sidebar()
2871
+	{
2872
+		$this->_display_admin_page();
2873
+	}
2874
+
2875
+
2876
+
2877
+	/**
2878
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2879
+	 *
2880
+	 * @return void
2881
+	 * @throws EE_Error
2882
+	 * @throws DomainException
2883
+	 */
2884
+	public function display_about_admin_page()
2885
+	{
2886
+		$this->_display_admin_page(false, true);
2887
+	}
2888
+
2889
+
2890
+
2891
+	/**
2892
+	 * display_admin_page
2893
+	 * contains the code for actually displaying an admin page
2894
+	 *
2895
+	 * @param  boolean $sidebar true with sidebar, false without
2896
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2897
+	 * @return void
2898
+	 * @throws DomainException
2899
+	 * @throws EE_Error
2900
+	 */
2901
+	private function _display_admin_page($sidebar = false, $about = false)
2902
+	{
2903
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2904
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2905
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2906
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2907
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2908
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2909
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2910
+			? 'poststuff'
2911
+			: 'espresso-default-admin';
2912
+		$template_path                                     = $sidebar
2913
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2914
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2915
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2916
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2917
+		}
2918
+		$template_path                                     = ! empty($this->_column_template_path)
2919
+			? $this->_column_template_path : $template_path;
2920
+		$this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2921
+			? $this->_template_args['admin_page_content']
2922
+			: '';
2923
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2924
+			? $this->_template_args['before_admin_page_content']
2925
+			: '';
2926
+		$this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2927
+			? $this->_template_args['after_admin_page_content']
2928
+			: '';
2929
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2930
+			$template_path,
2931
+			$this->_template_args,
2932
+			true
2933
+		);
2934
+		// the final template wrapper
2935
+		$this->admin_page_wrapper($about);
2936
+	}
2937
+
2938
+
2939
+
2940
+	/**
2941
+	 * This is used to display caf preview pages.
2942
+	 *
2943
+	 * @since 4.3.2
2944
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2945
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2946
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2947
+	 * @return void
2948
+	 * @throws DomainException
2949
+	 * @throws EE_Error
2950
+	 * @throws InvalidArgumentException
2951
+	 * @throws InvalidDataTypeException
2952
+	 * @throws InvalidInterfaceException
2953
+	 */
2954
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2955
+	{
2956
+		//let's generate a default preview action button if there isn't one already present.
2957
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2958
+			'Upgrade to Event Espresso 4 Right Now',
2959
+			'event_espresso'
2960
+		);
2961
+		$buy_now_url                                   = add_query_arg(
2962
+			array(
2963
+				'ee_ver'       => 'ee4',
2964
+				'utm_source'   => 'ee4_plugin_admin',
2965
+				'utm_medium'   => 'link',
2966
+				'utm_campaign' => $utm_campaign_source,
2967
+				'utm_content'  => 'buy_now_button',
2968
+			),
2969
+			'http://eventespresso.com/pricing/'
2970
+		);
2971
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2972
+			? $this->get_action_link_or_button(
2973
+				'',
2974
+				'buy_now',
2975
+				array(),
2976
+				'button-primary button-large',
2977
+				$buy_now_url,
2978
+				true
2979
+			)
2980
+			: $this->_template_args['preview_action_button'];
2981
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2982
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2983
+			$this->_template_args,
2984
+			true
2985
+		);
2986
+		$this->_display_admin_page($display_sidebar);
2987
+	}
2988
+
2989
+
2990
+
2991
+	/**
2992
+	 * display_admin_list_table_page_with_sidebar
2993
+	 * generates HTML wrapper for an admin_page with list_table
2994
+	 *
2995
+	 * @return void
2996
+	 * @throws EE_Error
2997
+	 * @throws DomainException
2998
+	 */
2999
+	public function display_admin_list_table_page_with_sidebar()
3000
+	{
3001
+		$this->_display_admin_list_table_page(true);
3002
+	}
3003
+
3004
+
3005
+
3006
+	/**
3007
+	 * display_admin_list_table_page_with_no_sidebar
3008
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
3009
+	 *
3010
+	 * @return void
3011
+	 * @throws EE_Error
3012
+	 * @throws DomainException
3013
+	 */
3014
+	public function display_admin_list_table_page_with_no_sidebar()
3015
+	{
3016
+		$this->_display_admin_list_table_page();
3017
+	}
3018
+
3019
+
3020
+
3021
+	/**
3022
+	 * generates html wrapper for an admin_list_table page
3023
+	 *
3024
+	 * @param boolean $sidebar whether to display with sidebar or not.
3025
+	 * @return void
3026
+	 * @throws DomainException
3027
+	 * @throws EE_Error
3028
+	 */
3029
+	private function _display_admin_list_table_page($sidebar = false)
3030
+	{
3031
+		//setup search attributes
3032
+		$this->_set_search_attributes();
3033
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
3034
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3035
+		$this->_template_args['table_url']        = defined('DOING_AJAX')
3036
+			? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
3037
+			: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
3038
+		$this->_template_args['list_table']       = $this->_list_table_object;
3039
+		$this->_template_args['current_route']    = $this->_req_action;
3040
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3041
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
3042
+		if (! empty($ajax_sorting_callback)) {
3043
+			$sortable_list_table_form_fields = wp_nonce_field(
3044
+				$ajax_sorting_callback . '_nonce',
3045
+				$ajax_sorting_callback . '_nonce',
3046
+				false,
3047
+				false
3048
+			);
3049
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
3050
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
3051
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3052
+												. $this->page_slug
3053
+												. '" />';
3054
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3055
+												. $ajax_sorting_callback
3056
+												. '" />';
3057
+		} else {
3058
+			$sortable_list_table_form_fields = '';
3059
+		}
3060
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3061
+		$hidden_form_fields                                      = isset($this->_template_args['list_table_hidden_fields'])
3062
+			? $this->_template_args['list_table_hidden_fields']
3063
+			: '';
3064
+		$nonce_ref                                               = $this->_req_action . '_nonce';
3065
+		$hidden_form_fields                                      .= '<input type="hidden" name="'
3066
+																	. $nonce_ref
3067
+																	. '" value="'
3068
+																	. wp_create_nonce($nonce_ref)
3069
+																	. '">';
3070
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
3071
+		//display message about search results?
3072
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3073
+			? '<p class="ee-search-results">' . sprintf(
3074
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3075
+				trim($this->_req_data['s'], '%')
3076
+			) . '</p>'
3077
+			: '';
3078
+		// filter before_list_table template arg
3079
+		$this->_template_args['before_list_table'] = apply_filters(
3080
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3081
+			$this->_template_args['before_list_table'],
3082
+			$this->page_slug,
3083
+			$this->_req_data,
3084
+			$this->_req_action
3085
+		);
3086
+		// convert to array and filter again
3087
+		// arrays are easier to inject new items in a specific location,
3088
+		// but would not be backwards compatible, so we have to add a new filter
3089
+		$this->_template_args['before_list_table'] = implode(
3090
+			" \n",
3091
+			(array)apply_filters(
3092
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3093
+				(array)$this->_template_args['before_list_table'],
3094
+				$this->page_slug,
3095
+				$this->_req_data,
3096
+				$this->_req_action
3097
+			)
3098
+		);
3099
+		// filter after_list_table template arg
3100
+		$this->_template_args['after_list_table'] = apply_filters(
3101
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3102
+			$this->_template_args['after_list_table'],
3103
+			$this->page_slug,
3104
+			$this->_req_data,
3105
+			$this->_req_action
3106
+		);
3107
+		// convert to array and filter again
3108
+		// arrays are easier to inject new items in a specific location,
3109
+		// but would not be backwards compatible, so we have to add a new filter
3110
+		$this->_template_args['after_list_table']   = implode(
3111
+			" \n",
3112
+			(array)apply_filters(
3113
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3114
+				(array)$this->_template_args['after_list_table'],
3115
+				$this->page_slug,
3116
+				$this->_req_data,
3117
+				$this->_req_action
3118
+			)
3119
+		);
3120
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3121
+			$template_path,
3122
+			$this->_template_args,
3123
+			true
3124
+		);
3125
+		// the final template wrapper
3126
+		if ($sidebar) {
3127
+			$this->display_admin_page_with_sidebar();
3128
+		} else {
3129
+			$this->display_admin_page_with_no_sidebar();
3130
+		}
3131
+	}
3132
+
3133
+
3134
+
3135
+	/**
3136
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3137
+	 * html string for the legend.
3138
+	 * $items are expected in an array in the following format:
3139
+	 * $legend_items = array(
3140
+	 *        'item_id' => array(
3141
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3142
+	 *            'desc' => esc_html__('localized description of item');
3143
+	 *        )
3144
+	 * );
3145
+	 *
3146
+	 * @param  array $items see above for format of array
3147
+	 * @return string html string of legend
3148
+	 * @throws DomainException
3149
+	 */
3150
+	protected function _display_legend($items)
3151
+	{
3152
+		$this->_template_args['items'] = apply_filters(
3153
+			'FHEE__EE_Admin_Page___display_legend__items',
3154
+			(array)$items,
3155
+			$this
3156
+		);
3157
+		return EEH_Template::display_template(
3158
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3159
+			$this->_template_args,
3160
+			true
3161
+		);
3162
+	}
3163
+
3164
+
3165
+	/**
3166
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3167
+	 * The returned json object is created from an array in the following format:
3168
+	 * array(
3169
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3170
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3171
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3172
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3173
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3174
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3175
+	 *  that might be included in here)
3176
+	 * )
3177
+	 * The json object is populated by whatever is set in the $_template_args property.
3178
+	 *
3179
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3180
+	 *                                 instead of displayed.
3181
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3182
+	 * @return void
3183
+	 * @throws EE_Error
3184
+	 */
3185
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
3186
+	{
3187
+		//make sure any EE_Error notices have been handled.
3188
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3189
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3190
+		unset($this->_template_args['data']);
3191
+		$json = array(
3192
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3193
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3194
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3195
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3196
+			'notices'   => EE_Error::get_notices(),
3197
+			'content'   => isset($this->_template_args['admin_page_content'])
3198
+				? $this->_template_args['admin_page_content'] : '',
3199
+			'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3200
+			'isEEajax'  => true
3201
+			//special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3202
+		);
3203
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3204
+		if (null === error_get_last() || ! headers_sent()) {
3205
+			header('Content-Type: application/json; charset=UTF-8');
3206
+		}
3207
+		echo wp_json_encode($json);
3208
+		exit();
3209
+	}
3210
+
3211
+
3212
+
3213
+	/**
3214
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3215
+	 *
3216
+	 * @return void
3217
+	 * @throws EE_Error
3218
+	 */
3219
+	public function return_json()
3220
+	{
3221
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3222
+			$this->_return_json();
3223
+		} else {
3224
+			throw new EE_Error(
3225
+				sprintf(
3226
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3227
+					__FUNCTION__
3228
+				)
3229
+			);
3230
+		}
3231
+	}
3232
+
3233
+
3234
+
3235
+	/**
3236
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3237
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3238
+	 *
3239
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3240
+	 */
3241
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3242
+	{
3243
+		$this->_hook_obj = $hook_obj;
3244
+	}
3245
+
3246
+
3247
+
3248
+	/**
3249
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3250
+	 *
3251
+	 * @param  boolean $about whether to use the special about page wrapper or default.
3252
+	 * @return void
3253
+	 * @throws DomainException
3254
+	 * @throws EE_Error
3255
+	 */
3256
+	public function admin_page_wrapper($about = false)
3257
+	{
3258
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3259
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3260
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3261
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3262
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3263
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3264
+			isset($this->_template_args['before_admin_page_content'])
3265
+				? $this->_template_args['before_admin_page_content']
3266
+				: ''
3267
+		);
3268
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3269
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3270
+			isset($this->_template_args['after_admin_page_content'])
3271
+				? $this->_template_args['after_admin_page_content']
3272
+				: ''
3273
+		);
3274
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3275
+		// load settings page wrapper template
3276
+		$template_path = ! defined('DOING_AJAX')
3277
+			? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3278
+			: EE_ADMIN_TEMPLATE
3279
+			  . 'admin_wrapper_ajax.template.php';
3280
+		//about page?
3281
+		$template_path = $about
3282
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3283
+			: $template_path;
3284
+		if (defined('DOING_AJAX')) {
3285
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3286
+				$template_path,
3287
+				$this->_template_args,
3288
+				true
3289
+			);
3290
+			$this->_return_json();
3291
+		} else {
3292
+			EEH_Template::display_template($template_path, $this->_template_args);
3293
+		}
3294
+	}
3295
+
3296
+
3297
+
3298
+	/**
3299
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3300
+	 *
3301
+	 * @return string html
3302
+	 * @throws EE_Error
3303
+	 */
3304
+	protected function _get_main_nav_tabs()
3305
+	{
3306
+		// let's generate the html using the EEH_Tabbed_Content helper.
3307
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3308
+		// (rather than setting in the page_routes array)
3309
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3310
+	}
3311
+
3312
+
3313
+
3314
+	/**
3315
+	 *        sort nav tabs
3316
+	 *
3317
+	 * @param $a
3318
+	 * @param $b
3319
+	 * @return int
3320
+	 */
3321
+	private function _sort_nav_tabs($a, $b)
3322
+	{
3323
+		if ($a['order'] === $b['order']) {
3324
+			return 0;
3325
+		}
3326
+		return ($a['order'] < $b['order']) ? -1 : 1;
3327
+	}
3328
+
3329
+
3330
+
3331
+	/**
3332
+	 *    generates HTML for the forms used on admin pages
3333
+	 *
3334
+	 * @param    array $input_vars - array of input field details
3335
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3336
+	 *                             use)
3337
+	 * @param bool     $id
3338
+	 * @return string
3339
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3340
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3341
+	 */
3342
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3343
+	{
3344
+		$content = $generator === 'string'
3345
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3346
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3347
+		return $content;
3348
+	}
3349
+
3350
+
3351
+
3352
+	/**
3353
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3354
+	 *
3355
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3356
+	 *                                   Close" button.
3357
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3358
+	 *                                   'Save', [1] => 'save & close')
3359
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3360
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3361
+	 *                                   default actions by submitting some other value.
3362
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3363
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3364
+	 *                                   close (normal form handling).
3365
+	 */
3366
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3367
+	{
3368
+		//make sure $text and $actions are in an array
3369
+		$text          = (array)$text;
3370
+		$actions       = (array)$actions;
3371
+		$referrer_url  = empty($referrer)
3372
+			? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3373
+			  . $_SERVER['REQUEST_URI']
3374
+			  . '" />'
3375
+			: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3376
+			  . $referrer
3377
+			  . '" />';
3378
+		$button_text   = ! empty($text)
3379
+			? $text
3380
+			: array(
3381
+				esc_html__('Save', 'event_espresso'),
3382
+				esc_html__('Save and Close', 'event_espresso'),
3383
+			);
3384
+		$default_names = array('save', 'save_and_close');
3385
+		//add in a hidden index for the current page (so save and close redirects properly)
3386
+		$this->_template_args['save_buttons'] = $referrer_url;
3387
+		foreach ($button_text as $key => $button) {
3388
+			$ref                                  = $default_names[$key];
3389
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3390
+													 . $ref
3391
+													 . '" value="'
3392
+													 . $button
3393
+													 . '" name="'
3394
+													 . (! empty($actions) ? $actions[$key] : $ref)
3395
+													 . '" id="'
3396
+													 . $this->_current_view . '_' . $ref
3397
+													 . '" />';
3398
+			if (! $both) {
3399
+				break;
3400
+			}
3401
+		}
3402
+	}
3403
+
3404
+
3405
+
3406
+	/**
3407
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3408
+	 *
3409
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3410
+	 * @since 4.6.0
3411
+	 * @param string $route
3412
+	 * @param array  $additional_hidden_fields
3413
+	 */
3414
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3415
+	{
3416
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3417
+	}
3418
+
3419
+
3420
+
3421
+	/**
3422
+	 * set form open and close tags on add/edit pages.
3423
+	 *
3424
+	 * @param string $route                    the route you want the form to direct to
3425
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3426
+	 * @return void
3427
+	 */
3428
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3429
+	{
3430
+		if (empty($route)) {
3431
+			$user_msg = esc_html__(
3432
+				'An error occurred. No action was set for this page\'s form.',
3433
+				'event_espresso'
3434
+			);
3435
+			$dev_msg  = $user_msg . "\n" . sprintf(
3436
+					esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3437
+					__FUNCTION__,
3438
+					__CLASS__
3439
+				);
3440
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3441
+		}
3442
+		// open form
3443
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3444
+															 . $this->_admin_base_url
3445
+															 . '" id="'
3446
+															 . $route
3447
+															 . '_event_form" >';
3448
+		// add nonce
3449
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3450
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
3451
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3452
+		// add REQUIRED form action
3453
+		$hidden_fields = array(
3454
+			'action' => array('type' => 'hidden', 'value' => $route),
3455
+		);
3456
+		// merge arrays
3457
+		$hidden_fields = is_array($additional_hidden_fields)
3458
+			? array_merge($hidden_fields, $additional_hidden_fields)
3459
+			: $hidden_fields;
3460
+		// generate form fields
3461
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3462
+		// add fields to form
3463
+		foreach ((array)$form_fields as $field_name => $form_field) {
3464
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3465
+		}
3466
+		// close form
3467
+		$this->_template_args['after_admin_page_content'] = '</form>';
3468
+	}
3469
+
3470
+
3471
+
3472
+	/**
3473
+	 * Public Wrapper for _redirect_after_action() method since its
3474
+	 * discovered it would be useful for external code to have access.
3475
+	 *
3476
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3477
+	 * @since 4.5.0
3478
+	 * @param bool   $success
3479
+	 * @param string $what
3480
+	 * @param string $action_desc
3481
+	 * @param array  $query_args
3482
+	 * @param bool   $override_overwrite
3483
+	 * @throws EE_Error
3484
+	 */
3485
+	public function redirect_after_action(
3486
+		$success = false,
3487
+		$what = 'item',
3488
+		$action_desc = 'processed',
3489
+		$query_args = array(),
3490
+		$override_overwrite = false
3491
+	) {
3492
+		$this->_redirect_after_action(
3493
+			$success,
3494
+			$what,
3495
+			$action_desc,
3496
+			$query_args,
3497
+			$override_overwrite
3498
+		);
3499
+	}
3500
+
3501
+
3502
+
3503
+	/**
3504
+	 *    _redirect_after_action
3505
+	 *
3506
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3507
+	 * @param string $what               - what the action was performed on
3508
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3509
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3510
+	 *                                   action is completed
3511
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3512
+	 *                                   override this so that they show.
3513
+	 * @return void
3514
+	 * @throws EE_Error
3515
+	 */
3516
+	protected function _redirect_after_action(
3517
+		$success = 0,
3518
+		$what = 'item',
3519
+		$action_desc = 'processed',
3520
+		$query_args = array(),
3521
+		$override_overwrite = false
3522
+	) {
3523
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3524
+		//class name for actions/filters.
3525
+		$classname = get_class($this);
3526
+		// set redirect url.
3527
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3528
+		// otherwise we go with whatever is set as the _admin_base_url
3529
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3530
+		$notices      = EE_Error::get_notices(false);
3531
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3532
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3533
+			EE_Error::overwrite_success();
3534
+		}
3535
+		if (! empty($what) && ! empty($action_desc)  && empty($notices['errors'])) {
3536
+			// how many records affected ? more than one record ? or just one ?
3537
+			if ($success > 1) {
3538
+				// set plural msg
3539
+				EE_Error::add_success(
3540
+					sprintf(
3541
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3542
+						$what,
3543
+						$action_desc
3544
+					),
3545
+					__FILE__,
3546
+					__FUNCTION__,
3547
+					__LINE__
3548
+				);
3549
+			} elseif ($success === 1) {
3550
+				// set singular msg
3551
+				EE_Error::add_success(
3552
+					sprintf(
3553
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3554
+						$what,
3555
+						$action_desc
3556
+					),
3557
+					__FILE__,
3558
+					__FUNCTION__,
3559
+					__LINE__
3560
+				);
3561
+			}
3562
+		}
3563
+		// check that $query_args isn't something crazy
3564
+		if (! is_array($query_args)) {
3565
+			$query_args = array();
3566
+		}
3567
+		/**
3568
+		 * Allow injecting actions before the query_args are modified for possible different
3569
+		 * redirections on save and close actions
3570
+		 *
3571
+		 * @since 4.2.0
3572
+		 * @param array $query_args       The original query_args array coming into the
3573
+		 *                                method.
3574
+		 */
3575
+		do_action(
3576
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3577
+			$query_args
3578
+		);
3579
+		//calculate where we're going (if we have a "save and close" button pushed)
3580
+		if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3581
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3582
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3583
+			// regenerate query args array from referrer URL
3584
+			parse_str($parsed_url['query'], $query_args);
3585
+			// correct page and action will be in the query args now
3586
+			$redirect_url = admin_url('admin.php');
3587
+		}
3588
+		//merge any default query_args set in _default_route_query_args property
3589
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3590
+			$args_to_merge = array();
3591
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3592
+				//is there a wp_referer array in our _default_route_query_args property?
3593
+				if ($query_param === 'wp_referer') {
3594
+					$query_value = (array)$query_value;
3595
+					foreach ($query_value as $reference => $value) {
3596
+						if (strpos($reference, 'nonce') !== false) {
3597
+							continue;
3598
+						}
3599
+						//finally we will override any arguments in the referer with
3600
+						//what might be set on the _default_route_query_args array.
3601
+						if (isset($this->_default_route_query_args[$reference])) {
3602
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3603
+						} else {
3604
+							$args_to_merge[$reference] = urlencode($value);
3605
+						}
3606
+					}
3607
+					continue;
3608
+				}
3609
+				$args_to_merge[$query_param] = $query_value;
3610
+			}
3611
+			//now let's merge these arguments but override with what was specifically sent in to the
3612
+			//redirect.
3613
+			$query_args = array_merge($args_to_merge, $query_args);
3614
+		}
3615
+		$this->_process_notices($query_args);
3616
+		// generate redirect url
3617
+		// if redirecting to anything other than the main page, add a nonce
3618
+		if (isset($query_args['action'])) {
3619
+			// manually generate wp_nonce and merge that with the query vars
3620
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3621
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3622
+		}
3623
+		// we're adding some hooks and filters in here for processing any things just before redirects
3624
+		// (example: an admin page has done an insert or update and we want to run something after that).
3625
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3626
+		$redirect_url = apply_filters(
3627
+			'FHEE_redirect_' . $classname . $this->_req_action,
3628
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3629
+			$query_args
3630
+		);
3631
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3632
+		if (defined('DOING_AJAX')) {
3633
+			$default_data                    = array(
3634
+				'close'        => true,
3635
+				'redirect_url' => $redirect_url,
3636
+				'where'        => 'main',
3637
+				'what'         => 'append',
3638
+			);
3639
+			$this->_template_args['success'] = $success;
3640
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3641
+				$default_data,
3642
+				$this->_template_args['data']
3643
+			) : $default_data;
3644
+			$this->_return_json();
3645
+		}
3646
+		wp_safe_redirect($redirect_url);
3647
+		exit();
3648
+	}
3649
+
3650
+
3651
+
3652
+	/**
3653
+	 * process any notices before redirecting (or returning ajax request)
3654
+	 * This method sets the $this->_template_args['notices'] attribute;
3655
+	 *
3656
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
3657
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and
3658
+	 *                                  page_routes haven't been defined yet.
3659
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we
3660
+	 *                                  still save a transient for the notice.
3661
+	 * @return void
3662
+	 * @throws EE_Error
3663
+	 */
3664
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3665
+	{
3666
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
3667
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3668
+			$notices = EE_Error::get_notices(false);
3669
+			if (empty($this->_template_args['success'])) {
3670
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3671
+			}
3672
+			if (empty($this->_template_args['errors'])) {
3673
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3674
+			}
3675
+			if (empty($this->_template_args['attention'])) {
3676
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3677
+			}
3678
+		}
3679
+		$this->_template_args['notices'] = EE_Error::get_notices();
3680
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3681
+		if (! defined('DOING_AJAX') || $sticky_notices) {
3682
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3683
+			$this->_add_transient(
3684
+				$route,
3685
+				$this->_template_args['notices'],
3686
+				true,
3687
+				$skip_route_verify
3688
+			);
3689
+		}
3690
+	}
3691
+
3692
+
3693
+
3694
+	/**
3695
+	 * get_action_link_or_button
3696
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3697
+	 *
3698
+	 * @param string $action        use this to indicate which action the url is generated with.
3699
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3700
+	 *                              property.
3701
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3702
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3703
+	 * @param string $base_url      If this is not provided
3704
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3705
+	 *                              Otherwise this value will be used.
3706
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3707
+	 * @return string
3708
+	 * @throws InvalidArgumentException
3709
+	 * @throws InvalidInterfaceException
3710
+	 * @throws InvalidDataTypeException
3711
+	 * @throws EE_Error
3712
+	 */
3713
+	public function get_action_link_or_button(
3714
+		$action,
3715
+		$type = 'add',
3716
+		$extra_request = array(),
3717
+		$class = 'button-primary',
3718
+		$base_url = '',
3719
+		$exclude_nonce = false
3720
+	) {
3721
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3722
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3723
+			throw new EE_Error(
3724
+				sprintf(
3725
+					esc_html__(
3726
+						'There is no page route for given action for the button.  This action was given: %s',
3727
+						'event_espresso'
3728
+					),
3729
+					$action
3730
+				)
3731
+			);
3732
+		}
3733
+		if (! isset($this->_labels['buttons'][$type])) {
3734
+			throw new EE_Error(
3735
+				sprintf(
3736
+					__(
3737
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3738
+						'event_espresso'
3739
+					),
3740
+					$type
3741
+				)
3742
+			);
3743
+		}
3744
+		//finally check user access for this button.
3745
+		$has_access = $this->check_user_access($action, true);
3746
+		if (! $has_access) {
3747
+			return '';
3748
+		}
3749
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3750
+		$query_args = array(
3751
+			'action' => $action,
3752
+		);
3753
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3754
+		if (! empty($extra_request)) {
3755
+			$query_args = array_merge($extra_request, $query_args);
3756
+		}
3757
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3758
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3759
+	}
3760
+
3761
+
3762
+
3763
+	/**
3764
+	 * _per_page_screen_option
3765
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3766
+	 *
3767
+	 * @return void
3768
+	 * @throws InvalidArgumentException
3769
+	 * @throws InvalidInterfaceException
3770
+	 * @throws InvalidDataTypeException
3771
+	 */
3772
+	protected function _per_page_screen_option()
3773
+	{
3774
+		$option = 'per_page';
3775
+		$args   = array(
3776
+			'label'   => esc_html__(
3777
+					apply_filters(
3778
+						'FHEE__EE_Admin_Page___per_page_screen_options___label',
3779
+						$this->_admin_page_title,
3780
+						$this
3781
+					)
3782
+			),
3783
+			'default' => (int) apply_filters(
3784
+					'FHEE__EE_Admin_Page___per_page_screen_options__default',
3785
+					10
3786
+			),
3787
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3788
+		);
3789
+		//ONLY add the screen option if the user has access to it.
3790
+		if ($this->check_user_access($this->_current_view, true)) {
3791
+			add_screen_option($option, $args);
3792
+		}
3793
+	}
3794
+
3795
+
3796
+
3797
+	/**
3798
+	 * set_per_page_screen_option
3799
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3800
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3801
+	 * admin_menu.
3802
+	 *
3803
+	 * @return void
3804
+	 */
3805
+	private function _set_per_page_screen_options()
3806
+	{
3807
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3808
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3809
+			if (! $user = wp_get_current_user()) {
3810
+				return;
3811
+			}
3812
+			$option = $_POST['wp_screen_options']['option'];
3813
+			$value  = $_POST['wp_screen_options']['value'];
3814
+			if ($option != sanitize_key($option)) {
3815
+				return;
3816
+			}
3817
+			$map_option = $option;
3818
+			$option     = str_replace('-', '_', $option);
3819
+			switch ($map_option) {
3820
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3821
+					$value = (int)$value;
3822
+					$max_value = apply_filters(
3823
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3824
+						999,
3825
+						$this->_current_page,
3826
+						$this->_current_view
3827
+					);
3828
+					if ($value < 1) {
3829
+						return;
3830
+					}
3831
+					$value = min($value, $max_value);
3832
+					break;
3833
+				default:
3834
+					$value = apply_filters(
3835
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3836
+						false,
3837
+						$option,
3838
+						$value
3839
+					);
3840
+					if (false === $value) {
3841
+						return;
3842
+					}
3843
+					break;
3844
+			}
3845
+			update_user_meta($user->ID, $option, $value);
3846
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3847
+			exit;
3848
+		}
3849
+	}
3850
+
3851
+
3852
+
3853
+	/**
3854
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3855
+	 *
3856
+	 * @param array $data array that will be assigned to template args.
3857
+	 */
3858
+	public function set_template_args($data)
3859
+	{
3860
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3861
+	}
3862
+
3863
+
3864
+
3865
+	/**
3866
+	 * This makes available the WP transient system for temporarily moving data between routes
3867
+	 *
3868
+	 * @param string $route             the route that should receive the transient
3869
+	 * @param array  $data              the data that gets sent
3870
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3871
+	 *                                  normal route transient.
3872
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3873
+	 *                                  when we are adding a transient before page_routes have been defined.
3874
+	 * @return void
3875
+	 * @throws EE_Error
3876
+	 */
3877
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3878
+	{
3879
+		$user_id = get_current_user_id();
3880
+		if (! $skip_route_verify) {
3881
+			$this->_verify_route($route);
3882
+		}
3883
+		//now let's set the string for what kind of transient we're setting
3884
+		$transient = $notices
3885
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3886
+			: 'rte_tx_' . $route . '_' . $user_id;
3887
+		$data      = $notices ? array('notices' => $data) : $data;
3888
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3889
+		$existing = is_multisite() && is_network_admin()
3890
+			? get_site_transient($transient)
3891
+			: get_transient($transient);
3892
+		if ($existing) {
3893
+			$data = array_merge((array)$data, (array)$existing);
3894
+		}
3895
+		if (is_multisite() && is_network_admin()) {
3896
+			set_site_transient($transient, $data, 8);
3897
+		} else {
3898
+			set_transient($transient, $data, 8);
3899
+		}
3900
+	}
3901
+
3902
+
3903
+
3904
+	/**
3905
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3906
+	 *
3907
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3908
+	 * @param string $route
3909
+	 * @return mixed data
3910
+	 */
3911
+	protected function _get_transient($notices = false, $route = '')
3912
+	{
3913
+		$user_id   = get_current_user_id();
3914
+		$route     = ! $route ? $this->_req_action : $route;
3915
+		$transient = $notices
3916
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3917
+			: 'rte_tx_' . $route . '_' . $user_id;
3918
+		$data      = is_multisite() && is_network_admin()
3919
+			? get_site_transient($transient)
3920
+			: get_transient($transient);
3921
+		//delete transient after retrieval (just in case it hasn't expired);
3922
+		if (is_multisite() && is_network_admin()) {
3923
+			delete_site_transient($transient);
3924
+		} else {
3925
+			delete_transient($transient);
3926
+		}
3927
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3928
+	}
3929
+
3930
+
3931
+
3932
+	/**
3933
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3934
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3935
+	 * default route callback on the EE_Admin page you want it run.)
3936
+	 *
3937
+	 * @return void
3938
+	 */
3939
+	protected function _transient_garbage_collection()
3940
+	{
3941
+		global $wpdb;
3942
+		//retrieve all existing transients
3943
+		$query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3944
+		if ($results = $wpdb->get_results($query)) {
3945
+			foreach ($results as $result) {
3946
+				$transient = str_replace('_transient_', '', $result->option_name);
3947
+				get_transient($transient);
3948
+				if (is_multisite() && is_network_admin()) {
3949
+					get_site_transient($transient);
3950
+				}
3951
+			}
3952
+		}
3953
+	}
3954
+
3955
+
3956
+
3957
+	/**
3958
+	 * get_view
3959
+	 *
3960
+	 * @return string content of _view property
3961
+	 */
3962
+	public function get_view()
3963
+	{
3964
+		return $this->_view;
3965
+	}
3966
+
3967
+
3968
+
3969
+	/**
3970
+	 * getter for the protected $_views property
3971
+	 *
3972
+	 * @return array
3973
+	 */
3974
+	public function get_views()
3975
+	{
3976
+		return $this->_views;
3977
+	}
3978
+
3979
+
3980
+
3981
+	/**
3982
+	 * get_current_page
3983
+	 *
3984
+	 * @return string _current_page property value
3985
+	 */
3986
+	public function get_current_page()
3987
+	{
3988
+		return $this->_current_page;
3989
+	}
3990
+
3991
+
3992
+
3993
+	/**
3994
+	 * get_current_view
3995
+	 *
3996
+	 * @return string _current_view property value
3997
+	 */
3998
+	public function get_current_view()
3999
+	{
4000
+		return $this->_current_view;
4001
+	}
4002
+
4003
+
4004
+
4005
+	/**
4006
+	 * get_current_screen
4007
+	 *
4008
+	 * @return object The current WP_Screen object
4009
+	 */
4010
+	public function get_current_screen()
4011
+	{
4012
+		return $this->_current_screen;
4013
+	}
4014
+
4015
+
4016
+
4017
+	/**
4018
+	 * get_current_page_view_url
4019
+	 *
4020
+	 * @return string This returns the url for the current_page_view.
4021
+	 */
4022
+	public function get_current_page_view_url()
4023
+	{
4024
+		return $this->_current_page_view_url;
4025
+	}
4026
+
4027
+
4028
+
4029
+	/**
4030
+	 * just returns the _req_data property
4031
+	 *
4032
+	 * @return array
4033
+	 */
4034
+	public function get_request_data()
4035
+	{
4036
+		return $this->_req_data;
4037
+	}
4038
+
4039
+
4040
+
4041
+	/**
4042
+	 * returns the _req_data protected property
4043
+	 *
4044
+	 * @return string
4045
+	 */
4046
+	public function get_req_action()
4047
+	{
4048
+		return $this->_req_action;
4049
+	}
4050
+
4051
+
4052
+
4053
+	/**
4054
+	 * @return bool  value of $_is_caf property
4055
+	 */
4056
+	public function is_caf()
4057
+	{
4058
+		return $this->_is_caf;
4059
+	}
4060
+
4061
+
4062
+
4063
+	/**
4064
+	 * @return mixed
4065
+	 */
4066
+	public function default_espresso_metaboxes()
4067
+	{
4068
+		return $this->_default_espresso_metaboxes;
4069
+	}
4070
+
4071
+
4072
+
4073
+	/**
4074
+	 * @return mixed
4075
+	 */
4076
+	public function admin_base_url()
4077
+	{
4078
+		return $this->_admin_base_url;
4079
+	}
4080 4080
 
4081 4081
 
4082 4082
 
4083
-    /**
4084
-     * @return mixed
4085
-     */
4086
-    public function wp_page_slug()
4087
-    {
4088
-        return $this->_wp_page_slug;
4089
-    }
4083
+	/**
4084
+	 * @return mixed
4085
+	 */
4086
+	public function wp_page_slug()
4087
+	{
4088
+		return $this->_wp_page_slug;
4089
+	}
4090 4090
 
4091 4091
 
4092
-
4093
-    /**
4094
-     * updates  espresso configuration settings
4095
-     *
4096
-     * @param string                   $tab
4097
-     * @param EE_Config_Base|EE_Config $config
4098
-     * @param string                   $file file where error occurred
4099
-     * @param string                   $func function  where error occurred
4100
-     * @param string                   $line line no where error occurred
4101
-     * @return boolean
4102
-     */
4103
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4104
-    {
4105
-        //remove any options that are NOT going to be saved with the config settings.
4106
-        if (isset($config->core->ee_ueip_optin)) {
4107
-            $config->core->ee_ueip_has_notified = true;
4108
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4109
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4110
-            update_option('ee_ueip_has_notified', true);
4111
-        }
4112
-        // and save it (note we're also doing the network save here)
4113
-        $net_saved    = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4114
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4115
-        if ($config_saved && $net_saved) {
4116
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4117
-            return true;
4118
-        }
4119
-        EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4120
-        return false;
4121
-    }
4122
-
4123
-
4124
-
4125
-    /**
4126
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4127
-     *
4128
-     * @return array
4129
-     */
4130
-    public function get_yes_no_values()
4131
-    {
4132
-        return $this->_yes_no_values;
4133
-    }
4134
-
4135
-
4136
-
4137
-    protected function _get_dir()
4138
-    {
4139
-        $reflector = new ReflectionClass(get_class($this));
4140
-        return dirname($reflector->getFileName());
4141
-    }
4142
-
4143
-
4144
-
4145
-    /**
4146
-     * A helper for getting a "next link".
4147
-     *
4148
-     * @param string $url   The url to link to
4149
-     * @param string $class The class to use.
4150
-     * @return string
4151
-     */
4152
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4153
-    {
4154
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4155
-    }
4156
-
4157
-
4158
-
4159
-    /**
4160
-     * A helper for getting a "previous link".
4161
-     *
4162
-     * @param string $url   The url to link to
4163
-     * @param string $class The class to use.
4164
-     * @return string
4165
-     */
4166
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4167
-    {
4168
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4169
-    }
4170
-
4171
-
4172
-
4173
-
4174
-
4175
-
4176
-
4177
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4178
-
4179
-
4180
-    /**
4181
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4182
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4183
-     * _req_data array.
4184
-     *
4185
-     * @return bool success/fail
4186
-     * @throws EE_Error
4187
-     * @throws InvalidArgumentException
4188
-     * @throws ReflectionException
4189
-     * @throws InvalidDataTypeException
4190
-     * @throws InvalidInterfaceException
4191
-     */
4192
-    protected function _process_resend_registration()
4193
-    {
4194
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4195
-        do_action(
4196
-            'AHEE__EE_Admin_Page___process_resend_registration',
4197
-            $this->_template_args['success'],
4198
-            $this->_req_data
4199
-        );
4200
-        return $this->_template_args['success'];
4201
-    }
4202
-
4203
-
4204
-
4205
-    /**
4206
-     * This automatically processes any payment message notifications when manual payment has been applied.
4207
-     *
4208
-     * @param \EE_Payment $payment
4209
-     * @return bool success/fail
4210
-     */
4211
-    protected function _process_payment_notification(EE_Payment $payment)
4212
-    {
4213
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4214
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4215
-        $this->_template_args['success'] = apply_filters(
4216
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4217
-            false,
4218
-            $payment
4219
-        );
4220
-        return $this->_template_args['success'];
4221
-    }
4092
+
4093
+	/**
4094
+	 * updates  espresso configuration settings
4095
+	 *
4096
+	 * @param string                   $tab
4097
+	 * @param EE_Config_Base|EE_Config $config
4098
+	 * @param string                   $file file where error occurred
4099
+	 * @param string                   $func function  where error occurred
4100
+	 * @param string                   $line line no where error occurred
4101
+	 * @return boolean
4102
+	 */
4103
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4104
+	{
4105
+		//remove any options that are NOT going to be saved with the config settings.
4106
+		if (isset($config->core->ee_ueip_optin)) {
4107
+			$config->core->ee_ueip_has_notified = true;
4108
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4109
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4110
+			update_option('ee_ueip_has_notified', true);
4111
+		}
4112
+		// and save it (note we're also doing the network save here)
4113
+		$net_saved    = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4114
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4115
+		if ($config_saved && $net_saved) {
4116
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4117
+			return true;
4118
+		}
4119
+		EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4120
+		return false;
4121
+	}
4122
+
4123
+
4124
+
4125
+	/**
4126
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4127
+	 *
4128
+	 * @return array
4129
+	 */
4130
+	public function get_yes_no_values()
4131
+	{
4132
+		return $this->_yes_no_values;
4133
+	}
4134
+
4135
+
4136
+
4137
+	protected function _get_dir()
4138
+	{
4139
+		$reflector = new ReflectionClass(get_class($this));
4140
+		return dirname($reflector->getFileName());
4141
+	}
4142
+
4143
+
4144
+
4145
+	/**
4146
+	 * A helper for getting a "next link".
4147
+	 *
4148
+	 * @param string $url   The url to link to
4149
+	 * @param string $class The class to use.
4150
+	 * @return string
4151
+	 */
4152
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4153
+	{
4154
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4155
+	}
4156
+
4157
+
4158
+
4159
+	/**
4160
+	 * A helper for getting a "previous link".
4161
+	 *
4162
+	 * @param string $url   The url to link to
4163
+	 * @param string $class The class to use.
4164
+	 * @return string
4165
+	 */
4166
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4167
+	{
4168
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4169
+	}
4170
+
4171
+
4172
+
4173
+
4174
+
4175
+
4176
+
4177
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4178
+
4179
+
4180
+	/**
4181
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4182
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4183
+	 * _req_data array.
4184
+	 *
4185
+	 * @return bool success/fail
4186
+	 * @throws EE_Error
4187
+	 * @throws InvalidArgumentException
4188
+	 * @throws ReflectionException
4189
+	 * @throws InvalidDataTypeException
4190
+	 * @throws InvalidInterfaceException
4191
+	 */
4192
+	protected function _process_resend_registration()
4193
+	{
4194
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4195
+		do_action(
4196
+			'AHEE__EE_Admin_Page___process_resend_registration',
4197
+			$this->_template_args['success'],
4198
+			$this->_req_data
4199
+		);
4200
+		return $this->_template_args['success'];
4201
+	}
4202
+
4203
+
4204
+
4205
+	/**
4206
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4207
+	 *
4208
+	 * @param \EE_Payment $payment
4209
+	 * @return bool success/fail
4210
+	 */
4211
+	protected function _process_payment_notification(EE_Payment $payment)
4212
+	{
4213
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4214
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4215
+		$this->_template_args['success'] = apply_filters(
4216
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4217
+			false,
4218
+			$payment
4219
+		);
4220
+		return $this->_template_args['success'];
4221
+	}
4222 4222
 
4223 4223
 
4224 4224
 }
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/EEG_Paypal_Express.gateway.php 1 patch
Indentation   +671 added lines, -671 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
 
@@ -16,680 +16,680 @@  discard block
 block discarded – undo
16 16
  */
17 17
 //Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
18 18
 if (! function_exists('mb_strcut')) {
19
-    /**
20
-     * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21
-     * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
22
-     * @param $string
23
-     * @param $start
24
-     * @param $length
25
-     * @return bool|string
26
-     */
27
-    function mb_strcut($string, $start, $length = null)
28
-    {
29
-        return mb_substr($string, $start, $length);
30
-    }
19
+	/**
20
+	 * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21
+	 * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
22
+	 * @param $string
23
+	 * @param $start
24
+	 * @param $length
25
+	 * @return bool|string
26
+	 */
27
+	function mb_strcut($string, $start, $length = null)
28
+	{
29
+		return mb_substr($string, $start, $length);
30
+	}
31 31
 }
32 32
 class EEG_Paypal_Express extends EE_Offsite_Gateway
33 33
 {
34 34
 
35
-    /**
36
-     * Merchant API Username.
37
-     *
38
-     * @var string
39
-     */
40
-    protected $_api_username;
41
-
42
-    /**
43
-     * Merchant API Password.
44
-     *
45
-     * @var string
46
-     */
47
-    protected $_api_password;
48
-
49
-    /**
50
-     * API Signature.
51
-     *
52
-     * @var string
53
-     */
54
-    protected $_api_signature;
55
-
56
-    /**
57
-     * Request Shipping address on PP checkout page.
58
-     *
59
-     * @var string
60
-     */
61
-    protected $_request_shipping_addr;
62
-
63
-    /**
64
-     * Business/personal logo.
65
-     *
66
-     * @var string
67
-     */
68
-    protected $_image_url;
69
-
70
-    /**
71
-     * gateway URL variable
72
-     *
73
-     * @var string
74
-     */
75
-    protected $_base_gateway_url = '';
76
-
77
-
78
-
79
-    /**
80
-     * EEG_Paypal_Express constructor.
81
-     */
82
-    public function __construct()
83
-    {
84
-        $this->_currencies_supported = array(
85
-            'USD',
86
-            'AUD',
87
-            'BRL',
88
-            'CAD',
89
-            'CZK',
90
-            'DKK',
91
-            'EUR',
92
-            'HKD',
93
-            'HUF',
94
-            'ILS',
95
-            'JPY',
96
-            'MYR',
97
-            'MXN',
98
-            'NOK',
99
-            'NZD',
100
-            'PHP',
101
-            'PLN',
102
-            'GBP',
103
-            'RUB',
104
-            'SGD',
105
-            'SEK',
106
-            'CHF',
107
-            'TWD',
108
-            'THB',
109
-            'TRY',
110
-        );
111
-        parent::__construct();
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * Sets the gateway URL variable based on whether debug mode is enabled or not.
118
-     *
119
-     * @param array $settings_array
120
-     */
121
-    public function set_settings($settings_array)
122
-    {
123
-        parent::set_settings($settings_array);
124
-        // Redirect URL.
125
-        $this->_base_gateway_url = $this->_debug_mode
126
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
127
-            : 'https://api-3t.paypal.com/nvp';
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @param EEI_Payment $payment
134
-     * @param array       $billing_info
135
-     * @param string      $return_url
136
-     * @param string      $notify_url
137
-     * @param string      $cancel_url
138
-     * @return \EE_Payment|\EEI_Payment
139
-     * @throws \EE_Error
140
-     */
141
-    public function set_redirection_info(
142
-        $payment,
143
-        $billing_info = array(),
144
-        $return_url = null,
145
-        $notify_url = null,
146
-        $cancel_url = null
147
-    ) {
148
-        if (! $payment instanceof EEI_Payment) {
149
-            $payment->set_gateway_response(
150
-                esc_html__(
151
-                    'Error. No associated payment was found.',
152
-                    'event_espresso'
153
-                )
154
-            );
155
-            $payment->set_status($this->_pay_model->failed_status());
156
-            return $payment;
157
-        }
158
-        $transaction = $payment->transaction();
159
-        if (! $transaction instanceof EEI_Transaction) {
160
-            $payment->set_gateway_response(
161
-                esc_html__(
162
-                    'Could not process this payment because it has no associated transaction.',
163
-                    'event_espresso'
164
-                )
165
-            );
166
-            $payment->set_status($this->_pay_model->failed_status());
167
-            return $payment;
168
-        }
169
-        $gateway_formatter = $this->_get_gateway_formatter();
170
-        $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127);
171
-        $primary_registration = $transaction->primary_registration();
172
-        $primary_attendee = $primary_registration instanceof EE_Registration
173
-            ? $primary_registration->attendee()
174
-            : false;
175
-        $locale = explode('-', get_bloginfo('language'));
176
-        // Gather request parameters.
177
-        $token_request_dtls = array(
178
-            'METHOD'                         => 'SetExpressCheckout',
179
-            'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
180
-            'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
181
-            'PAYMENTREQUEST_0_DESC'          => $order_description,
182
-            'RETURNURL'                      => $return_url,
183
-            'CANCELURL'                      => $cancel_url,
184
-            'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
185
-            // Buyer does not need to create a PayPal account to check out.
186
-            // This is referred to as PayPal Account Optional.
187
-            'SOLUTIONTYPE'                   => 'Sole',
188
-            //EE will blow up if you change this
189
-            'BUTTONSOURCE'                   => 'EventEspresso_SP',
190
-            // Locale of the pages displayed by PayPal during Express Checkout.
191
-            'LOCALECODE'                     => $locale[1]
192
-        );
193
-        // Show itemized list.
194
-        $itemized_list = $this->itemize_list($payment, $transaction);
195
-        $token_request_dtls = array_merge($token_request_dtls, $itemized_list);
196
-        // Automatically filling out shipping and contact information.
197
-        if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
198
-            // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
199
-            $token_request_dtls['NOSHIPPING'] = '2';
200
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
201
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
202
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
203
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
204
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
205
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
206
-            $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
207
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
208
-        } elseif (! $this->_request_shipping_addr) {
209
-            // Do not request shipping details on the PP Checkout page.
210
-            $token_request_dtls['NOSHIPPING'] = '1';
211
-            $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
212
-        }
213
-        // Used a business/personal logo on the PayPal page.
214
-        if (! empty($this->_image_url)) {
215
-            $token_request_dtls['LOGOIMG'] = $this->_image_url;
216
-        }
217
-        $token_request_dtls = apply_filters(
218
-            'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
219
-            $token_request_dtls,
220
-            $this
221
-        );
222
-        // Request PayPal token.
223
-        $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
224
-        $token_rstatus = $this->_ppExpress_check_response($token_request_response);
225
-        $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
226
-            ? $token_rstatus['args']
227
-            : array();
228
-        if ($token_rstatus['status']) {
229
-            // We got the Token so we may continue with the payment and redirect the client.
230
-            $payment->set_details($response_args);
231
-            $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
232
-            $payment->set_redirect_url(
233
-                $gateway_url
234
-                . '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
235
-                . $response_args['TOKEN']
236
-            );
237
-        } else {
238
-            if (isset($response_args['L_ERRORCODE'])) {
239
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
240
-            } else {
241
-                $payment->set_gateway_response(
242
-                    esc_html__(
243
-                        'Error occurred while trying to setup the Express Checkout.',
244
-                        'event_espresso'
245
-                    )
246
-                );
247
-            }
248
-            $payment->set_details($response_args);
249
-            $payment->set_status($this->_pay_model->failed_status());
250
-        }
251
-        return $payment;
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     * @param array           $update_info {
258
-     * @type string           $gateway_txn_id
259
-     * @type string status an EEMI_Payment status
260
-     *                                     }
261
-     * @param EEI_Transaction $transaction
262
-     * @return EEI_Payment
263
-     */
264
-    public function handle_payment_update($update_info, $transaction)
265
-    {
266
-        $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
267
-        if ($payment instanceof EEI_Payment) {
268
-            $this->log(array('Return from Authorization' => $update_info), $payment);
269
-            $transaction = $payment->transaction();
270
-            if (! $transaction instanceof EEI_Transaction) {
271
-                $payment->set_gateway_response(
272
-                    esc_html__(
273
-                        'Could not process this payment because it has no associated transaction.',
274
-                        'event_espresso'
275
-                    )
276
-                );
277
-                $payment->set_status($this->_pay_model->failed_status());
278
-                return $payment;
279
-            }
280
-            $primary_registrant = $transaction->primary_registration();
281
-            $payment_details = $payment->details();
282
-            // Check if we still have the token.
283
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
284
-                $payment->set_status($this->_pay_model->failed_status());
285
-                return $payment;
286
-            }
287
-            $cdetails_request_dtls = array(
288
-                'METHOD' => 'GetExpressCheckoutDetails',
289
-                'TOKEN'  => $payment_details['TOKEN'],
290
-            );
291
-            // Request Customer Details.
292
-            $cdetails_request_response = $this->_ppExpress_request(
293
-                $cdetails_request_dtls,
294
-                'Customer Details',
295
-                $payment
296
-            );
297
-            $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
298
-            $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
299
-                ? $cdetails_rstatus['args']
300
-                : array();
301
-            if ($cdetails_rstatus['status']) {
302
-                // We got the PayerID so now we can Complete the transaction.
303
-                $docheckout_request_dtls = array(
304
-                    'METHOD'                         => 'DoExpressCheckoutPayment',
305
-                    'PAYERID'                        => $cdata_response_args['PAYERID'],
306
-                    'TOKEN'                          => $payment_details['TOKEN'],
307
-                    'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
308
-                    'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
309
-                    'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
310
-                    //EE will blow up if you change this
311
-                    'BUTTONSOURCE'                   => 'EventEspresso_SP',
312
-                );
313
-                 // Include itemized list.
314
-                $itemized_list = $this->itemize_list(
315
-                    $payment,
316
-                    $transaction,
317
-                    $cdata_response_args
318
-                );
319
-                $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
320
-                // Payment Checkout/Capture.
321
-                $docheckout_request_response = $this->_ppExpress_request(
322
-                    $docheckout_request_dtls,
323
-                    'Do Payment',
324
-                    $payment
325
-                );
326
-                $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
327
-                $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
328
-                    ? $docheckout_rstatus['args']
329
-                    : array();
330
-                if ($docheckout_rstatus['status']) {
331
-                    // All is well, payment approved.
332
-                    $primary_registration_code = $primary_registrant instanceof EE_Registration ?
333
-                        $primary_registrant->reg_code()
334
-                        : '';
335
-                    $payment->set_extra_accntng($primary_registration_code);
336
-                    $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
337
-                        ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT']
338
-                        : 0);
339
-                    $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
340
-                        ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
341
-                        : null);
342
-                    $payment->set_details($cdata_response_args);
343
-                    $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
344
-                        ? $docheckout_response_args['PAYMENTINFO_0_ACK']
345
-                        : '');
346
-                    $payment->set_status($this->_pay_model->approved_status());
347
-                } else {
348
-                    if (isset($docheckout_response_args['L_ERRORCODE'])) {
349
-                        $payment->set_gateway_response(
350
-                            $docheckout_response_args['L_ERRORCODE']
351
-                            . '; '
352
-                            . $docheckout_response_args['L_SHORTMESSAGE']
353
-                        );
354
-                    } else {
355
-                        $payment->set_gateway_response(
356
-                            esc_html__(
357
-                                'Error occurred while trying to Capture the funds.',
358
-                                'event_espresso'
359
-                            )
360
-                        );
361
-                    }
362
-                    $payment->set_details($docheckout_response_args);
363
-                    $payment->set_status($this->_pay_model->declined_status());
364
-                }
365
-            } else {
366
-                if (isset($cdata_response_args['L_ERRORCODE'])) {
367
-                    $payment->set_gateway_response(
368
-                        $cdata_response_args['L_ERRORCODE']
369
-                        . '; '
370
-                        . $cdata_response_args['L_SHORTMESSAGE']
371
-                    );
372
-                } else {
373
-                    $payment->set_gateway_response(
374
-                        esc_html__(
375
-                            'Error occurred while trying to get payment Details from PayPal.',
376
-                            'event_espresso'
377
-                        )
378
-                    );
379
-                }
380
-                $payment->set_details($cdata_response_args);
381
-                $payment->set_status($this->_pay_model->failed_status());
382
-            }
383
-        } else {
384
-            $payment->set_gateway_response(
385
-                esc_html__(
386
-                    'Error occurred while trying to process the payment.',
387
-                    'event_espresso'
388
-                )
389
-            );
390
-            $payment->set_status($this->_pay_model->failed_status());
391
-        }
392
-        return $payment;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     *  Make a list of items that are in the giver transaction.
399
-     *
400
-     * @param EEI_Payment     $payment
401
-     * @param EEI_Transaction $transaction
402
-     * @param array           $request_response_args Data from a previous communication with PP.
403
-     * @return array
404
-     */
405
-    public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
406
-    {
407
-        $itemized_list = array();
408
-        $gateway_formatter = $this->_get_gateway_formatter();
409
-        // If we have data from a previous communication with PP (on this transaction) we may use that for our list...
410
-        if (
411
-            ! empty($request_response_args)
412
-            && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
413
-            && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
414
-        ) {
415
-            foreach ($request_response_args as $arg_key => $arg_val) {
416
-                if (
417
-                    strpos($arg_key, 'PAYMENTREQUEST_') !== false
418
-                    && strpos($arg_key, 'NOTIFYURL') === false
419
-                ) {
420
-                    $itemized_list[$arg_key] = $arg_val;
421
-                }
422
-            }
423
-            // If we got only a few Items then something is not right.
424
-            if (count($itemized_list) > 2) {
425
-                return $itemized_list;
426
-            } else {
427
-                if (WP_DEBUG) {
428
-                    throw new EE_Error(
429
-                        sprintf(
430
-                            esc_html__(
431
-                                // @codingStandardsIgnoreStart
432
-                                'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s',
433
-                                // @codingStandardsIgnoreEnd
434
-                                'event_espresso'
435
-                            ),
436
-                            wp_json_encode($itemized_list)
437
-                        )
438
-                    );
439
-                }
440
-                // Reset the list and log an error, maybe allow to try and generate a new list (below).
441
-                $itemized_list = array();
442
-                $this->log(
443
-                    array(
444
-                        esc_html__(
445
-                            'Could not generate a proper item list with:',
446
-                            'event_espresso'
447
-                        ) => $request_response_args
448
-                    ),
449
-                    $payment
450
-                );
451
-            }
452
-        }
453
-        // ...otherwise we generate a new list for this transaction.
454
-        if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
455
-            $item_num = 0;
456
-            $itemized_sum = 0;
457
-            $total_line_items = $transaction->total_line_item();
458
-            // Go through each item in the list.
459
-            foreach ($total_line_items->get_items() as $line_item) {
460
-                if ($line_item instanceof EE_Line_Item) {
461
-                    // PayPal doesn't like line items with 0.00 amount, so we may skip those.
462
-                    if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
463
-                        continue;
464
-                    }
465
-                    $unit_price = $line_item->unit_price();
466
-                    $line_item_quantity = $line_item->quantity();
467
-                    // This is a discount.
468
-                    if ($line_item->is_percent()) {
469
-                        $unit_price = $line_item->total();
470
-                        $line_item_quantity = 1;
471
-                    }
472
-                    // Item Name.
473
-                    $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
474
-                        $gateway_formatter->formatLineItemName($line_item, $payment),
475
-                        0,
476
-                        127
477
-                    );
478
-                    // Item description.
479
-                    $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut(
480
-                        $gateway_formatter->formatLineItemDesc($line_item, $payment),
481
-                        0,
482
-                        127
483
-                    );
484
-                    // Cost of individual item.
485
-                    $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $gateway_formatter->formatCurrency($unit_price);
486
-                    // Item Number.
487
-                    $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
488
-                    // Item quantity.
489
-                    $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity;
490
-                    // Digital item is sold.
491
-                    $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
492
-                    $itemized_sum += $line_item->total();
493
-                    ++$item_num;
494
-                }
495
-            }
496
-            // Item's sales S/H and tax amount.
497
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
498
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
499
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
500
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
501
-            $itemized_sum_diff_from_txn_total = round(
502
-                $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
503
-                2
504
-            );
505
-            // If we were not able to recognize some item like promotion, surcharge or cancellation,
506
-            // add the difference as an extra line item.
507
-            if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
508
-                // Item Name.
509
-                $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
510
-                    esc_html__(
511
-                        'Other (promotion/surcharge/cancellation)',
512
-                        'event_espresso'
513
-                    ),
514
-                    0,
515
-                    127
516
-                );
517
-                // Item description.
518
-                $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = '';
519
-                // Cost of individual item.
520
-                $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $gateway_formatter->formatCurrency(
521
-                    $itemized_sum_diff_from_txn_total
522
-                );
523
-                // Item Number.
524
-                $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
525
-                // Item quantity.
526
-                $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1;
527
-                // Digital item is sold.
528
-                $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
529
-                $item_num++;
530
-            }
531
-        } else {
532
-            // Just one Item.
533
-            // Item Name.
534
-            $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
535
-                $gateway_formatter->formatPartialPaymentLineItemName($payment),
536
-                0,
537
-                127
538
-            );
539
-            // Item description.
540
-            $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
541
-                $gateway_formatter->formatPartialPaymentLineItemDesc($payment),
542
-                0,
543
-                127
544
-            );
545
-            // Cost of individual item.
546
-            $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount());
547
-            // Item Number.
548
-            $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
549
-            // Item quantity.
550
-            $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
551
-            // Digital item is sold.
552
-            $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
553
-            // Item's sales S/H and tax amount.
554
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount());
555
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
556
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
557
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
558
-        }
559
-        return $itemized_list;
560
-    }
561
-
562
-
563
-
564
-    /**
565
-     *  Make the Express checkout request.
566
-     *
567
-     * @param array       $request_params
568
-     * @param string      $request_text
569
-     * @param EEI_Payment $payment
570
-     * @return mixed
571
-     */
572
-    public function _ppExpress_request($request_params, $request_text, $payment)
573
-    {
574
-        $request_dtls = array(
575
-            'VERSION'   => '204.0',
576
-            'USER'      => urlencode($this->_api_username),
577
-            'PWD'       => urlencode($this->_api_password),
578
-            'SIGNATURE' => urlencode($this->_api_signature),
579
-        );
580
-        $dtls = array_merge($request_dtls, $request_params);
581
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
582
-        // Request Customer Details.
583
-        $request_response = wp_remote_post(
584
-            $this->_base_gateway_url,
585
-            array(
586
-                'method'      => 'POST',
587
-                'timeout'     => 45,
588
-                'httpversion' => '1.1',
589
-                'cookies'     => array(),
590
-                'headers'     => array(),
591
-                'body'        => http_build_query($dtls, '', '&'),
592
-            )
593
-        );
594
-        // Log the response.
595
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
596
-        return $request_response;
597
-    }
598
-
599
-
600
-
601
-    /**
602
-     *  Check the response status.
603
-     *
604
-     * @param mixed $request_response
605
-     * @return array
606
-     */
607
-    public function _ppExpress_check_response($request_response)
608
-    {
609
-        if (is_wp_error($request_response) || empty($request_response['body'])) {
610
-            // If we got here then there was an error in this request.
611
-            return array('status' => false, 'args' => $request_response);
612
-        }
613
-        $response_args = array();
614
-        parse_str(urldecode($request_response['body']), $response_args);
615
-        if (! isset($response_args['ACK'])) {
616
-            return array('status' => false, 'args' => $request_response);
617
-        }
618
-        if (
619
-            (
620
-                isset($response_args['PAYERID'])
621
-                || isset($response_args['TOKEN'])
622
-                || isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
623
-                || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
624
-            )
625
-            && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
626
-        ) {
627
-            // Response status OK, return response parameters for further processing.
628
-            return array('status' => true, 'args' => $response_args);
629
-        }
630
-        $errors = $this->_get_errors($response_args);
631
-        return array('status' => false, 'args' => $errors);
632
-    }
633
-
634
-
635
-
636
-    /**
637
-     *  Log a "Cleared" request.
638
-     *
639
-     * @param array       $request
640
-     * @param EEI_Payment $payment
641
-     * @param string      $info
642
-     * @return void
643
-     */
644
-    private function _log_clean_request($request, $payment, $info)
645
-    {
646
-        $cleaned_request_data = $request;
647
-        unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
648
-        $this->log(array($info => $cleaned_request_data), $payment);
649
-    }
650
-
651
-
652
-
653
-    /**
654
-     *  Get error from the response data.
655
-     *
656
-     * @param array $data_array
657
-     * @return array
658
-     */
659
-    private function _get_errors($data_array)
660
-    {
661
-        $errors = array();
662
-        $n = 0;
663
-        while (isset($data_array["L_ERRORCODE{$n}"])) {
664
-            $l_error_code = isset($data_array["L_ERRORCODE{$n}"])
665
-                ? $data_array["L_ERRORCODE{$n}"]
666
-                : '';
667
-            $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
668
-                ? $data_array["L_SEVERITYCODE{$n}"]
669
-                : '';
670
-            $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
671
-                ? $data_array["L_SHORTMESSAGE{$n}"]
672
-                : '';
673
-            $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
674
-                ? $data_array["L_LONGMESSAGE{$n}"]
675
-                : '';
676
-            if ($n === 0) {
677
-                $errors = array(
678
-                    'L_ERRORCODE'    => $l_error_code,
679
-                    'L_SHORTMESSAGE' => $l_short_message,
680
-                    'L_LONGMESSAGE'  => $l_long_message,
681
-                    'L_SEVERITYCODE' => $l_severity_code,
682
-                );
683
-            } else {
684
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
685
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
686
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
687
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
688
-            }
689
-            $n++;
690
-        }
691
-        return $errors;
692
-    }
35
+	/**
36
+	 * Merchant API Username.
37
+	 *
38
+	 * @var string
39
+	 */
40
+	protected $_api_username;
41
+
42
+	/**
43
+	 * Merchant API Password.
44
+	 *
45
+	 * @var string
46
+	 */
47
+	protected $_api_password;
48
+
49
+	/**
50
+	 * API Signature.
51
+	 *
52
+	 * @var string
53
+	 */
54
+	protected $_api_signature;
55
+
56
+	/**
57
+	 * Request Shipping address on PP checkout page.
58
+	 *
59
+	 * @var string
60
+	 */
61
+	protected $_request_shipping_addr;
62
+
63
+	/**
64
+	 * Business/personal logo.
65
+	 *
66
+	 * @var string
67
+	 */
68
+	protected $_image_url;
69
+
70
+	/**
71
+	 * gateway URL variable
72
+	 *
73
+	 * @var string
74
+	 */
75
+	protected $_base_gateway_url = '';
76
+
77
+
78
+
79
+	/**
80
+	 * EEG_Paypal_Express constructor.
81
+	 */
82
+	public function __construct()
83
+	{
84
+		$this->_currencies_supported = array(
85
+			'USD',
86
+			'AUD',
87
+			'BRL',
88
+			'CAD',
89
+			'CZK',
90
+			'DKK',
91
+			'EUR',
92
+			'HKD',
93
+			'HUF',
94
+			'ILS',
95
+			'JPY',
96
+			'MYR',
97
+			'MXN',
98
+			'NOK',
99
+			'NZD',
100
+			'PHP',
101
+			'PLN',
102
+			'GBP',
103
+			'RUB',
104
+			'SGD',
105
+			'SEK',
106
+			'CHF',
107
+			'TWD',
108
+			'THB',
109
+			'TRY',
110
+		);
111
+		parent::__construct();
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
118
+	 *
119
+	 * @param array $settings_array
120
+	 */
121
+	public function set_settings($settings_array)
122
+	{
123
+		parent::set_settings($settings_array);
124
+		// Redirect URL.
125
+		$this->_base_gateway_url = $this->_debug_mode
126
+			? 'https://api-3t.sandbox.paypal.com/nvp'
127
+			: 'https://api-3t.paypal.com/nvp';
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @param EEI_Payment $payment
134
+	 * @param array       $billing_info
135
+	 * @param string      $return_url
136
+	 * @param string      $notify_url
137
+	 * @param string      $cancel_url
138
+	 * @return \EE_Payment|\EEI_Payment
139
+	 * @throws \EE_Error
140
+	 */
141
+	public function set_redirection_info(
142
+		$payment,
143
+		$billing_info = array(),
144
+		$return_url = null,
145
+		$notify_url = null,
146
+		$cancel_url = null
147
+	) {
148
+		if (! $payment instanceof EEI_Payment) {
149
+			$payment->set_gateway_response(
150
+				esc_html__(
151
+					'Error. No associated payment was found.',
152
+					'event_espresso'
153
+				)
154
+			);
155
+			$payment->set_status($this->_pay_model->failed_status());
156
+			return $payment;
157
+		}
158
+		$transaction = $payment->transaction();
159
+		if (! $transaction instanceof EEI_Transaction) {
160
+			$payment->set_gateway_response(
161
+				esc_html__(
162
+					'Could not process this payment because it has no associated transaction.',
163
+					'event_espresso'
164
+				)
165
+			);
166
+			$payment->set_status($this->_pay_model->failed_status());
167
+			return $payment;
168
+		}
169
+		$gateway_formatter = $this->_get_gateway_formatter();
170
+		$order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127);
171
+		$primary_registration = $transaction->primary_registration();
172
+		$primary_attendee = $primary_registration instanceof EE_Registration
173
+			? $primary_registration->attendee()
174
+			: false;
175
+		$locale = explode('-', get_bloginfo('language'));
176
+		// Gather request parameters.
177
+		$token_request_dtls = array(
178
+			'METHOD'                         => 'SetExpressCheckout',
179
+			'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
180
+			'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
181
+			'PAYMENTREQUEST_0_DESC'          => $order_description,
182
+			'RETURNURL'                      => $return_url,
183
+			'CANCELURL'                      => $cancel_url,
184
+			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
185
+			// Buyer does not need to create a PayPal account to check out.
186
+			// This is referred to as PayPal Account Optional.
187
+			'SOLUTIONTYPE'                   => 'Sole',
188
+			//EE will blow up if you change this
189
+			'BUTTONSOURCE'                   => 'EventEspresso_SP',
190
+			// Locale of the pages displayed by PayPal during Express Checkout.
191
+			'LOCALECODE'                     => $locale[1]
192
+		);
193
+		// Show itemized list.
194
+		$itemized_list = $this->itemize_list($payment, $transaction);
195
+		$token_request_dtls = array_merge($token_request_dtls, $itemized_list);
196
+		// Automatically filling out shipping and contact information.
197
+		if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
198
+			// If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
199
+			$token_request_dtls['NOSHIPPING'] = '2';
200
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
201
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
202
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
203
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
204
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
205
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
206
+			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
207
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
208
+		} elseif (! $this->_request_shipping_addr) {
209
+			// Do not request shipping details on the PP Checkout page.
210
+			$token_request_dtls['NOSHIPPING'] = '1';
211
+			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
212
+		}
213
+		// Used a business/personal logo on the PayPal page.
214
+		if (! empty($this->_image_url)) {
215
+			$token_request_dtls['LOGOIMG'] = $this->_image_url;
216
+		}
217
+		$token_request_dtls = apply_filters(
218
+			'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
219
+			$token_request_dtls,
220
+			$this
221
+		);
222
+		// Request PayPal token.
223
+		$token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
224
+		$token_rstatus = $this->_ppExpress_check_response($token_request_response);
225
+		$response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
226
+			? $token_rstatus['args']
227
+			: array();
228
+		if ($token_rstatus['status']) {
229
+			// We got the Token so we may continue with the payment and redirect the client.
230
+			$payment->set_details($response_args);
231
+			$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
232
+			$payment->set_redirect_url(
233
+				$gateway_url
234
+				. '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
235
+				. $response_args['TOKEN']
236
+			);
237
+		} else {
238
+			if (isset($response_args['L_ERRORCODE'])) {
239
+				$payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
240
+			} else {
241
+				$payment->set_gateway_response(
242
+					esc_html__(
243
+						'Error occurred while trying to setup the Express Checkout.',
244
+						'event_espresso'
245
+					)
246
+				);
247
+			}
248
+			$payment->set_details($response_args);
249
+			$payment->set_status($this->_pay_model->failed_status());
250
+		}
251
+		return $payment;
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 * @param array           $update_info {
258
+	 * @type string           $gateway_txn_id
259
+	 * @type string status an EEMI_Payment status
260
+	 *                                     }
261
+	 * @param EEI_Transaction $transaction
262
+	 * @return EEI_Payment
263
+	 */
264
+	public function handle_payment_update($update_info, $transaction)
265
+	{
266
+		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
267
+		if ($payment instanceof EEI_Payment) {
268
+			$this->log(array('Return from Authorization' => $update_info), $payment);
269
+			$transaction = $payment->transaction();
270
+			if (! $transaction instanceof EEI_Transaction) {
271
+				$payment->set_gateway_response(
272
+					esc_html__(
273
+						'Could not process this payment because it has no associated transaction.',
274
+						'event_espresso'
275
+					)
276
+				);
277
+				$payment->set_status($this->_pay_model->failed_status());
278
+				return $payment;
279
+			}
280
+			$primary_registrant = $transaction->primary_registration();
281
+			$payment_details = $payment->details();
282
+			// Check if we still have the token.
283
+			if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
284
+				$payment->set_status($this->_pay_model->failed_status());
285
+				return $payment;
286
+			}
287
+			$cdetails_request_dtls = array(
288
+				'METHOD' => 'GetExpressCheckoutDetails',
289
+				'TOKEN'  => $payment_details['TOKEN'],
290
+			);
291
+			// Request Customer Details.
292
+			$cdetails_request_response = $this->_ppExpress_request(
293
+				$cdetails_request_dtls,
294
+				'Customer Details',
295
+				$payment
296
+			);
297
+			$cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
298
+			$cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
299
+				? $cdetails_rstatus['args']
300
+				: array();
301
+			if ($cdetails_rstatus['status']) {
302
+				// We got the PayerID so now we can Complete the transaction.
303
+				$docheckout_request_dtls = array(
304
+					'METHOD'                         => 'DoExpressCheckoutPayment',
305
+					'PAYERID'                        => $cdata_response_args['PAYERID'],
306
+					'TOKEN'                          => $payment_details['TOKEN'],
307
+					'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
308
+					'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
309
+					'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
310
+					//EE will blow up if you change this
311
+					'BUTTONSOURCE'                   => 'EventEspresso_SP',
312
+				);
313
+				 // Include itemized list.
314
+				$itemized_list = $this->itemize_list(
315
+					$payment,
316
+					$transaction,
317
+					$cdata_response_args
318
+				);
319
+				$docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
320
+				// Payment Checkout/Capture.
321
+				$docheckout_request_response = $this->_ppExpress_request(
322
+					$docheckout_request_dtls,
323
+					'Do Payment',
324
+					$payment
325
+				);
326
+				$docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
327
+				$docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
328
+					? $docheckout_rstatus['args']
329
+					: array();
330
+				if ($docheckout_rstatus['status']) {
331
+					// All is well, payment approved.
332
+					$primary_registration_code = $primary_registrant instanceof EE_Registration ?
333
+						$primary_registrant->reg_code()
334
+						: '';
335
+					$payment->set_extra_accntng($primary_registration_code);
336
+					$payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
337
+						? (float)$docheckout_response_args['PAYMENTINFO_0_AMT']
338
+						: 0);
339
+					$payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
340
+						? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
341
+						: null);
342
+					$payment->set_details($cdata_response_args);
343
+					$payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
344
+						? $docheckout_response_args['PAYMENTINFO_0_ACK']
345
+						: '');
346
+					$payment->set_status($this->_pay_model->approved_status());
347
+				} else {
348
+					if (isset($docheckout_response_args['L_ERRORCODE'])) {
349
+						$payment->set_gateway_response(
350
+							$docheckout_response_args['L_ERRORCODE']
351
+							. '; '
352
+							. $docheckout_response_args['L_SHORTMESSAGE']
353
+						);
354
+					} else {
355
+						$payment->set_gateway_response(
356
+							esc_html__(
357
+								'Error occurred while trying to Capture the funds.',
358
+								'event_espresso'
359
+							)
360
+						);
361
+					}
362
+					$payment->set_details($docheckout_response_args);
363
+					$payment->set_status($this->_pay_model->declined_status());
364
+				}
365
+			} else {
366
+				if (isset($cdata_response_args['L_ERRORCODE'])) {
367
+					$payment->set_gateway_response(
368
+						$cdata_response_args['L_ERRORCODE']
369
+						. '; '
370
+						. $cdata_response_args['L_SHORTMESSAGE']
371
+					);
372
+				} else {
373
+					$payment->set_gateway_response(
374
+						esc_html__(
375
+							'Error occurred while trying to get payment Details from PayPal.',
376
+							'event_espresso'
377
+						)
378
+					);
379
+				}
380
+				$payment->set_details($cdata_response_args);
381
+				$payment->set_status($this->_pay_model->failed_status());
382
+			}
383
+		} else {
384
+			$payment->set_gateway_response(
385
+				esc_html__(
386
+					'Error occurred while trying to process the payment.',
387
+					'event_espresso'
388
+				)
389
+			);
390
+			$payment->set_status($this->_pay_model->failed_status());
391
+		}
392
+		return $payment;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 *  Make a list of items that are in the giver transaction.
399
+	 *
400
+	 * @param EEI_Payment     $payment
401
+	 * @param EEI_Transaction $transaction
402
+	 * @param array           $request_response_args Data from a previous communication with PP.
403
+	 * @return array
404
+	 */
405
+	public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
406
+	{
407
+		$itemized_list = array();
408
+		$gateway_formatter = $this->_get_gateway_formatter();
409
+		// If we have data from a previous communication with PP (on this transaction) we may use that for our list...
410
+		if (
411
+			! empty($request_response_args)
412
+			&& array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
413
+			&& array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
414
+		) {
415
+			foreach ($request_response_args as $arg_key => $arg_val) {
416
+				if (
417
+					strpos($arg_key, 'PAYMENTREQUEST_') !== false
418
+					&& strpos($arg_key, 'NOTIFYURL') === false
419
+				) {
420
+					$itemized_list[$arg_key] = $arg_val;
421
+				}
422
+			}
423
+			// If we got only a few Items then something is not right.
424
+			if (count($itemized_list) > 2) {
425
+				return $itemized_list;
426
+			} else {
427
+				if (WP_DEBUG) {
428
+					throw new EE_Error(
429
+						sprintf(
430
+							esc_html__(
431
+								// @codingStandardsIgnoreStart
432
+								'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s',
433
+								// @codingStandardsIgnoreEnd
434
+								'event_espresso'
435
+							),
436
+							wp_json_encode($itemized_list)
437
+						)
438
+					);
439
+				}
440
+				// Reset the list and log an error, maybe allow to try and generate a new list (below).
441
+				$itemized_list = array();
442
+				$this->log(
443
+					array(
444
+						esc_html__(
445
+							'Could not generate a proper item list with:',
446
+							'event_espresso'
447
+						) => $request_response_args
448
+					),
449
+					$payment
450
+				);
451
+			}
452
+		}
453
+		// ...otherwise we generate a new list for this transaction.
454
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
455
+			$item_num = 0;
456
+			$itemized_sum = 0;
457
+			$total_line_items = $transaction->total_line_item();
458
+			// Go through each item in the list.
459
+			foreach ($total_line_items->get_items() as $line_item) {
460
+				if ($line_item instanceof EE_Line_Item) {
461
+					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
462
+					if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
463
+						continue;
464
+					}
465
+					$unit_price = $line_item->unit_price();
466
+					$line_item_quantity = $line_item->quantity();
467
+					// This is a discount.
468
+					if ($line_item->is_percent()) {
469
+						$unit_price = $line_item->total();
470
+						$line_item_quantity = 1;
471
+					}
472
+					// Item Name.
473
+					$itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
474
+						$gateway_formatter->formatLineItemName($line_item, $payment),
475
+						0,
476
+						127
477
+					);
478
+					// Item description.
479
+					$itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut(
480
+						$gateway_formatter->formatLineItemDesc($line_item, $payment),
481
+						0,
482
+						127
483
+					);
484
+					// Cost of individual item.
485
+					$itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $gateway_formatter->formatCurrency($unit_price);
486
+					// Item Number.
487
+					$itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
488
+					// Item quantity.
489
+					$itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity;
490
+					// Digital item is sold.
491
+					$itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
492
+					$itemized_sum += $line_item->total();
493
+					++$item_num;
494
+				}
495
+			}
496
+			// Item's sales S/H and tax amount.
497
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
498
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
499
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
500
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
501
+			$itemized_sum_diff_from_txn_total = round(
502
+				$transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
503
+				2
504
+			);
505
+			// If we were not able to recognize some item like promotion, surcharge or cancellation,
506
+			// add the difference as an extra line item.
507
+			if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
508
+				// Item Name.
509
+				$itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
510
+					esc_html__(
511
+						'Other (promotion/surcharge/cancellation)',
512
+						'event_espresso'
513
+					),
514
+					0,
515
+					127
516
+				);
517
+				// Item description.
518
+				$itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = '';
519
+				// Cost of individual item.
520
+				$itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $gateway_formatter->formatCurrency(
521
+					$itemized_sum_diff_from_txn_total
522
+				);
523
+				// Item Number.
524
+				$itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
525
+				// Item quantity.
526
+				$itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1;
527
+				// Digital item is sold.
528
+				$itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
529
+				$item_num++;
530
+			}
531
+		} else {
532
+			// Just one Item.
533
+			// Item Name.
534
+			$itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
535
+				$gateway_formatter->formatPartialPaymentLineItemName($payment),
536
+				0,
537
+				127
538
+			);
539
+			// Item description.
540
+			$itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
541
+				$gateway_formatter->formatPartialPaymentLineItemDesc($payment),
542
+				0,
543
+				127
544
+			);
545
+			// Cost of individual item.
546
+			$itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount());
547
+			// Item Number.
548
+			$itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
549
+			// Item quantity.
550
+			$itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
551
+			// Digital item is sold.
552
+			$itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
553
+			// Item's sales S/H and tax amount.
554
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount());
555
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
556
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
557
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
558
+		}
559
+		return $itemized_list;
560
+	}
561
+
562
+
563
+
564
+	/**
565
+	 *  Make the Express checkout request.
566
+	 *
567
+	 * @param array       $request_params
568
+	 * @param string      $request_text
569
+	 * @param EEI_Payment $payment
570
+	 * @return mixed
571
+	 */
572
+	public function _ppExpress_request($request_params, $request_text, $payment)
573
+	{
574
+		$request_dtls = array(
575
+			'VERSION'   => '204.0',
576
+			'USER'      => urlencode($this->_api_username),
577
+			'PWD'       => urlencode($this->_api_password),
578
+			'SIGNATURE' => urlencode($this->_api_signature),
579
+		);
580
+		$dtls = array_merge($request_dtls, $request_params);
581
+		$this->_log_clean_request($dtls, $payment, $request_text . ' Request');
582
+		// Request Customer Details.
583
+		$request_response = wp_remote_post(
584
+			$this->_base_gateway_url,
585
+			array(
586
+				'method'      => 'POST',
587
+				'timeout'     => 45,
588
+				'httpversion' => '1.1',
589
+				'cookies'     => array(),
590
+				'headers'     => array(),
591
+				'body'        => http_build_query($dtls, '', '&'),
592
+			)
593
+		);
594
+		// Log the response.
595
+		$this->log(array($request_text . ' Response' => $request_response), $payment);
596
+		return $request_response;
597
+	}
598
+
599
+
600
+
601
+	/**
602
+	 *  Check the response status.
603
+	 *
604
+	 * @param mixed $request_response
605
+	 * @return array
606
+	 */
607
+	public function _ppExpress_check_response($request_response)
608
+	{
609
+		if (is_wp_error($request_response) || empty($request_response['body'])) {
610
+			// If we got here then there was an error in this request.
611
+			return array('status' => false, 'args' => $request_response);
612
+		}
613
+		$response_args = array();
614
+		parse_str(urldecode($request_response['body']), $response_args);
615
+		if (! isset($response_args['ACK'])) {
616
+			return array('status' => false, 'args' => $request_response);
617
+		}
618
+		if (
619
+			(
620
+				isset($response_args['PAYERID'])
621
+				|| isset($response_args['TOKEN'])
622
+				|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
623
+				|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
624
+			)
625
+			&& in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
626
+		) {
627
+			// Response status OK, return response parameters for further processing.
628
+			return array('status' => true, 'args' => $response_args);
629
+		}
630
+		$errors = $this->_get_errors($response_args);
631
+		return array('status' => false, 'args' => $errors);
632
+	}
633
+
634
+
635
+
636
+	/**
637
+	 *  Log a "Cleared" request.
638
+	 *
639
+	 * @param array       $request
640
+	 * @param EEI_Payment $payment
641
+	 * @param string      $info
642
+	 * @return void
643
+	 */
644
+	private function _log_clean_request($request, $payment, $info)
645
+	{
646
+		$cleaned_request_data = $request;
647
+		unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
648
+		$this->log(array($info => $cleaned_request_data), $payment);
649
+	}
650
+
651
+
652
+
653
+	/**
654
+	 *  Get error from the response data.
655
+	 *
656
+	 * @param array $data_array
657
+	 * @return array
658
+	 */
659
+	private function _get_errors($data_array)
660
+	{
661
+		$errors = array();
662
+		$n = 0;
663
+		while (isset($data_array["L_ERRORCODE{$n}"])) {
664
+			$l_error_code = isset($data_array["L_ERRORCODE{$n}"])
665
+				? $data_array["L_ERRORCODE{$n}"]
666
+				: '';
667
+			$l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
668
+				? $data_array["L_SEVERITYCODE{$n}"]
669
+				: '';
670
+			$l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
671
+				? $data_array["L_SHORTMESSAGE{$n}"]
672
+				: '';
673
+			$l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
674
+				? $data_array["L_LONGMESSAGE{$n}"]
675
+				: '';
676
+			if ($n === 0) {
677
+				$errors = array(
678
+					'L_ERRORCODE'    => $l_error_code,
679
+					'L_SHORTMESSAGE' => $l_short_message,
680
+					'L_LONGMESSAGE'  => $l_long_message,
681
+					'L_SEVERITYCODE' => $l_severity_code,
682
+				);
683
+			} else {
684
+				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
685
+				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
686
+				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
687
+				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
688
+			}
689
+			$n++;
690
+		}
691
+		return $errors;
692
+	}
693 693
 
694 694
 }
695 695
 // End of file EEG_Paypal_Express.gateway.php
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Indentation   +1276 added lines, -1276 removed lines patch added patch discarded remove patch
@@ -24,1282 +24,1282 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
-     */
31
-    const req_type_normal = 0;
32
-
33
-    /**
34
-     * Indicates this is a brand new installation of EE so we should install
35
-     * tables and default data etc
36
-     */
37
-    const req_type_new_activation = 1;
38
-
39
-    /**
40
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
-     * and we just exited maintenance mode). We MUST check the database is setup properly
42
-     * and that default data is setup too
43
-     */
44
-    const req_type_reactivation = 2;
45
-
46
-    /**
47
-     * indicates that EE has been upgraded since its previous request.
48
-     * We may have data migration scripts to call and will want to trigger maintenance mode
49
-     */
50
-    const req_type_upgrade = 3;
51
-
52
-    /**
53
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
-     */
55
-    const req_type_downgrade = 4;
56
-
57
-    /**
58
-     * @deprecated since version 4.6.0.dev.006
59
-     * Now whenever a new_activation is detected the request type is still just
60
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
-     * (Specifically, when the migration manager indicates migrations are finished
64
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
-     */
66
-    const req_type_activation_but_not_installed = 5;
67
-
68
-    /**
69
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
-     */
71
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
-
73
-
74
-    /**
75
-     * @var EE_System $_instance
76
-     */
77
-    private static $_instance;
78
-
79
-    /**
80
-     * @var EE_Registry $registry
81
-     */
82
-    private $registry;
83
-
84
-    /**
85
-     * @var LoaderInterface $loader
86
-     */
87
-    private $loader;
88
-
89
-    /**
90
-     * @var EE_Capabilities $capabilities
91
-     */
92
-    private $capabilities;
93
-
94
-    /**
95
-     * @var RequestInterface $request
96
-     */
97
-    private $request;
98
-
99
-    /**
100
-     * @var EE_Maintenance_Mode $maintenance_mode
101
-     */
102
-    private $maintenance_mode;
103
-
104
-    /**
105
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
-     *
108
-     * @var int $_req_type
109
-     */
110
-    private $_req_type;
111
-
112
-    /**
113
-     * Whether or not there was a non-micro version change in EE core version during this request
114
-     *
115
-     * @var boolean $_major_version_change
116
-     */
117
-    private $_major_version_change = false;
118
-
119
-    /**
120
-     * A Context DTO dedicated solely to identifying the current request type.
121
-     *
122
-     * @var RequestTypeContextCheckerInterface $request_type
123
-     */
124
-    private $request_type;
125
-
126
-
127
-
128
-    /**
129
-     * @singleton method used to instantiate class object
130
-     * @param EE_Registry|null         $registry
131
-     * @param LoaderInterface|null     $loader
132
-     * @param RequestInterface|null          $request
133
-     * @param EE_Maintenance_Mode|null $maintenance_mode
134
-     * @return EE_System
135
-     */
136
-    public static function instance(
137
-        EE_Registry $registry = null,
138
-        LoaderInterface $loader = null,
139
-        RequestInterface $request = null,
140
-        EE_Maintenance_Mode $maintenance_mode = null
141
-    ) {
142
-        // check if class object is instantiated
143
-        if (! self::$_instance instanceof EE_System) {
144
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
-        }
146
-        return self::$_instance;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * resets the instance and returns it
153
-     *
154
-     * @return EE_System
155
-     */
156
-    public static function reset()
157
-    {
158
-        self::$_instance->_req_type = null;
159
-        //make sure none of the old hooks are left hanging around
160
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
-        //we need to reset the migration manager in order for it to detect DMSs properly
162
-        EE_Data_Migration_Manager::reset();
163
-        self::instance()->detect_activations_or_upgrades();
164
-        self::instance()->perform_activations_upgrades_and_migrations();
165
-        return self::instance();
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * sets hooks for running rest of system
172
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
-     * starting EE Addons from any other point may lead to problems
174
-     *
175
-     * @param EE_Registry         $registry
176
-     * @param LoaderInterface     $loader
177
-     * @param RequestInterface          $request
178
-     * @param EE_Maintenance_Mode $maintenance_mode
179
-     */
180
-    private function __construct(
181
-        EE_Registry $registry,
182
-        LoaderInterface $loader,
183
-        RequestInterface $request,
184
-        EE_Maintenance_Mode $maintenance_mode
185
-    ) {
186
-        $this->registry         = $registry;
187
-        $this->loader           = $loader;
188
-        $this->request          = $request;
189
-        $this->maintenance_mode = $maintenance_mode;
190
-        do_action('AHEE__EE_System__construct__begin', $this);
191
-        add_action(
192
-            'AHEE__EE_Bootstrap__load_espresso_addons',
193
-            array($this, 'loadCapabilities'),
194
-            5
195
-        );
196
-        add_action(
197
-            'AHEE__EE_Bootstrap__load_espresso_addons',
198
-            array($this, 'loadCommandBus'),
199
-            7
200
-        );
201
-        add_action(
202
-            'AHEE__EE_Bootstrap__load_espresso_addons',
203
-            array($this, 'loadPluginApi'),
204
-            9
205
-        );
206
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
-        add_action(
208
-            'AHEE__EE_Bootstrap__load_espresso_addons',
209
-            array($this, 'load_espresso_addons')
210
-        );
211
-        // when an ee addon is activated, we want to call the core hook(s) again
212
-        // because the newly-activated addon didn't get a chance to run at all
213
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
-        // detect whether install or upgrade
215
-        add_action(
216
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
-            array($this, 'detect_activations_or_upgrades'),
218
-            3
219
-        );
220
-        // load EE_Config, EE_Textdomain, etc
221
-        add_action(
222
-            'AHEE__EE_Bootstrap__load_core_configuration',
223
-            array($this, 'load_core_configuration'),
224
-            5
225
-        );
226
-        // load EE_Config, EE_Textdomain, etc
227
-        add_action(
228
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
-            array($this, 'register_shortcodes_modules_and_widgets'),
230
-            7
231
-        );
232
-        // you wanna get going? I wanna get going... let's get going!
233
-        add_action(
234
-            'AHEE__EE_Bootstrap__brew_espresso',
235
-            array($this, 'brew_espresso'),
236
-            9
237
-        );
238
-        //other housekeeping
239
-        //exclude EE critical pages from wp_list_pages
240
-        add_filter(
241
-            'wp_list_pages_excludes',
242
-            array($this, 'remove_pages_from_wp_list_pages'),
243
-            10
244
-        );
245
-        // ALL EE Addons should use the following hook point to attach their initial setup too
246
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
-        do_action('AHEE__EE_System__construct__complete', $this);
248
-    }
249
-
250
-
251
-    /**
252
-     * load and setup EE_Capabilities
253
-     *
254
-     * @return void
255
-     * @throws EE_Error
256
-     */
257
-    public function loadCapabilities()
258
-    {
259
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
260
-        add_action(
261
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
262
-            function ()
263
-            {
264
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
-            }
266
-        );
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * create and cache the CommandBus, and also add middleware
273
-     * The CapChecker middleware requires the use of EE_Capabilities
274
-     * which is why we need to load the CommandBus after Caps are set up
275
-     *
276
-     * @return void
277
-     * @throws EE_Error
278
-     */
279
-    public function loadCommandBus()
280
-    {
281
-        $this->loader->getShared(
282
-            'CommandBusInterface',
283
-            array(
284
-                null,
285
-                apply_filters(
286
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
-                    array(
288
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
-                    )
291
-                ),
292
-            )
293
-        );
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * @return void
300
-     * @throws EE_Error
301
-     */
302
-    public function loadPluginApi()
303
-    {
304
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
305
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
306
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
-        $this->loader->getShared('EE_Request_Handler');
308
-    }
309
-
310
-
311
-    /**
312
-     * @param string $addon_name
313
-     * @param string $version_constant
314
-     * @param string $min_version_required
315
-     * @param string $load_callback
316
-     * @param string $plugin_file_constant
317
-     * @return void
318
-     */
319
-    private function deactivateIncompatibleAddon(
320
-        $addon_name,
321
-        $version_constant,
322
-        $min_version_required,
323
-        $load_callback,
324
-        $plugin_file_constant
325
-    ) {
326
-        if (! defined($version_constant)) {
327
-            return;
328
-        }
329
-        $addon_version = constant($version_constant);
330
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
-            if (! function_exists('deactivate_plugins')) {
333
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
-            }
335
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
-            EE_Error::add_error(
338
-                sprintf(
339
-                    esc_html__(
340
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
-                        'event_espresso'
342
-                    ),
343
-                    $addon_name,
344
-                    $min_version_required
345
-                ),
346
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
-            );
348
-            EE_Error::get_notices(false, true);
349
-        }
350
-    }
351
-
352
-
353
-    /**
354
-     * load_espresso_addons
355
-     * allow addons to load first so that they can set hooks for running DMS's, etc
356
-     * this is hooked into both:
357
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
358
-     *        which runs during the WP 'plugins_loaded' action at priority 5
359
-     *    and the WP 'activate_plugin' hook point
360
-     *
361
-     * @access public
362
-     * @return void
363
-     */
364
-    public function load_espresso_addons()
365
-    {
366
-        $this->deactivateIncompatibleAddon(
367
-            'Wait Lists',
368
-            'EE_WAIT_LISTS_VERSION',
369
-            '1.0.0.beta.074',
370
-            'load_espresso_wait_lists',
371
-            'EE_WAIT_LISTS_PLUGIN_FILE'
372
-        );
373
-        $this->deactivateIncompatibleAddon(
374
-            'Automated Upcoming Event Notifications',
375
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
-            '1.0.0.beta.091',
377
-            'load_espresso_automated_upcoming_event_notification',
378
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
-        );
380
-        do_action('AHEE__EE_System__load_espresso_addons');
381
-        //if the WP API basic auth plugin isn't already loaded, load it now.
382
-        //We want it for mobile apps. Just include the entire plugin
383
-        //also, don't load the basic auth when a plugin is getting activated, because
384
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
-        //and causes a fatal error
386
-        if (
387
-            $this->request->getRequestParam('activate') !== 'true'
388
-            && ! function_exists('json_basic_auth_handler')
389
-            && ! function_exists('json_basic_auth_error')
390
-            && ! in_array(
391
-                $this->request->getRequestParam('action'),
392
-                array('activate', 'activate-selected'),
393
-                true
394
-            )
395
-        ) {
396
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
-        }
398
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * detect_activations_or_upgrades
405
-     * Checks for activation or upgrade of core first;
406
-     * then also checks if any registered addons have been activated or upgraded
407
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
-     * which runs during the WP 'plugins_loaded' action at priority 3
409
-     *
410
-     * @access public
411
-     * @return void
412
-     */
413
-    public function detect_activations_or_upgrades()
414
-    {
415
-        //first off: let's make sure to handle core
416
-        $this->detect_if_activation_or_upgrade();
417
-        foreach ($this->registry->addons as $addon) {
418
-            if ($addon instanceof EE_Addon) {
419
-                //detect teh request type for that addon
420
-                $addon->detect_activation_or_upgrade();
421
-            }
422
-        }
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * detect_if_activation_or_upgrade
429
-     * Takes care of detecting whether this is a brand new install or code upgrade,
430
-     * and either setting up the DB or setting up maintenance mode etc.
431
-     *
432
-     * @access public
433
-     * @return void
434
-     */
435
-    public function detect_if_activation_or_upgrade()
436
-    {
437
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
-        // check if db has been updated, or if its a brand-new installation
439
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
-        $request_type       = $this->detect_req_type($espresso_db_update);
441
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
-        switch ($request_type) {
443
-            case EE_System::req_type_new_activation:
444
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
-                $this->_handle_core_version_change($espresso_db_update);
446
-                break;
447
-            case EE_System::req_type_reactivation:
448
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
-                $this->_handle_core_version_change($espresso_db_update);
450
-                break;
451
-            case EE_System::req_type_upgrade:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
-                //migrations may be required now that we've upgraded
454
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
455
-                $this->_handle_core_version_change($espresso_db_update);
456
-                //				echo "done upgrade";die;
457
-                break;
458
-            case EE_System::req_type_downgrade:
459
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
-                //its possible migrations are no longer required
461
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
462
-                $this->_handle_core_version_change($espresso_db_update);
463
-                break;
464
-            case EE_System::req_type_normal:
465
-            default:
466
-                break;
467
-        }
468
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
-    }
470
-
471
-
472
-
473
-    /**
474
-     * Updates the list of installed versions and sets hooks for
475
-     * initializing the database later during the request
476
-     *
477
-     * @param array $espresso_db_update
478
-     */
479
-    private function _handle_core_version_change($espresso_db_update)
480
-    {
481
-        $this->update_list_of_installed_versions($espresso_db_update);
482
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
-        add_action(
484
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
-            array($this, 'initialize_db_if_no_migrations_required')
486
-        );
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
-     * information about what versions of EE have been installed and activated,
494
-     * NOT necessarily the state of the database
495
-     *
496
-     * @param mixed $espresso_db_update           the value of the WordPress option.
497
-     *                                            If not supplied, fetches it from the options table
498
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
-     */
500
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
-    {
502
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
504
-            $espresso_db_update = get_option('espresso_db_update');
505
-        }
506
-        // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
508
-            // if option is FALSE, then it never existed
509
-            if ($espresso_db_update === false) {
510
-                // make $espresso_db_update an array and save option with autoload OFF
511
-                $espresso_db_update = array();
512
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
-            } else {
514
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
515
-                $espresso_db_update = array($espresso_db_update => array());
516
-                update_option('espresso_db_update', $espresso_db_update);
517
-            }
518
-        } else {
519
-            $corrected_db_update = array();
520
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
-                    //the key is an int, and the value IS NOT an array
524
-                    //so it must be numerically-indexed, where values are versions installed...
525
-                    //fix it!
526
-                    $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
528
-                } else {
529
-                    //ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
-                }
532
-            }
533
-            $espresso_db_update = $corrected_db_update;
534
-            update_option('espresso_db_update', $espresso_db_update);
535
-        }
536
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
-        return $espresso_db_update;
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * Does the traditional work of setting up the plugin's database and adding default data.
544
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
-     * so that it will be done when migrations are finished
548
-     *
549
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
-     *                                       This is a resource-intensive job
552
-     *                                       so we prefer to only do it when necessary
553
-     * @return void
554
-     * @throws EE_Error
555
-     */
556
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
-    {
558
-        $request_type = $this->detect_req_type();
559
-        //only initialize system if we're not in maintenance mode.
560
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
-            update_option('ee_flush_rewrite_rules', true);
562
-            if ($verify_schema) {
563
-                EEH_Activation::initialize_db_and_folders();
564
-            }
565
-            EEH_Activation::initialize_db_content();
566
-            EEH_Activation::system_initialization();
567
-            if ($initialize_addons_too) {
568
-                $this->initialize_addons();
569
-            }
570
-        } else {
571
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
-        }
573
-        if ($request_type === EE_System::req_type_new_activation
574
-            || $request_type === EE_System::req_type_reactivation
575
-            || (
576
-                $request_type === EE_System::req_type_upgrade
577
-                && $this->is_major_version_change()
578
-            )
579
-        ) {
580
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
-        }
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     * Initializes the db for all registered addons
588
-     *
589
-     * @throws EE_Error
590
-     */
591
-    public function initialize_addons()
592
-    {
593
-        //foreach registered addon, make sure its db is up-to-date too
594
-        foreach ($this->registry->addons as $addon) {
595
-            if ($addon instanceof EE_Addon) {
596
-                $addon->initialize_db_if_no_migrations_required();
597
-            }
598
-        }
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
-     *
606
-     * @param    array  $version_history
607
-     * @param    string $current_version_to_add version to be added to the version history
608
-     * @return    boolean success as to whether or not this option was changed
609
-     */
610
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
-    {
612
-        if (! $version_history) {
613
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
-        }
615
-        if ($current_version_to_add === null) {
616
-            $current_version_to_add = espresso_version();
617
-        }
618
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
-        // re-save
620
-        return update_option('espresso_db_update', $version_history);
621
-    }
622
-
623
-
624
-
625
-    /**
626
-     * Detects if the current version indicated in the has existed in the list of
627
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
-     *
629
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
-     *                                  If not supplied, fetches it from the options table.
631
-     *                                  Also, caches its result so later parts of the code can also know whether
632
-     *                                  there's been an update or not. This way we can add the current version to
633
-     *                                  espresso_db_update, but still know if this is a new install or not
634
-     * @return int one of the constants on EE_System::req_type_
635
-     */
636
-    public function detect_req_type($espresso_db_update = null)
637
-    {
638
-        if ($this->_req_type === null) {
639
-            $espresso_db_update          = ! empty($espresso_db_update)
640
-                ? $espresso_db_update
641
-                : $this->fix_espresso_db_upgrade_option();
642
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
-                $espresso_db_update,
644
-                'ee_espresso_activation', espresso_version()
645
-            );
646
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
-        }
649
-        return $this->_req_type;
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * Returns whether or not there was a non-micro version change (ie, change in either
656
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
-     *
659
-     * @param $activation_history
660
-     * @return bool
661
-     */
662
-    private function _detect_major_version_change($activation_history)
663
-    {
664
-        $previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
-        $previous_version_parts = explode('.', $previous_version);
666
-        $current_version_parts  = explode('.', espresso_version());
667
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
-               && ($previous_version_parts[0] !== $current_version_parts[0]
669
-                   || $previous_version_parts[1] !== $current_version_parts[1]
670
-               );
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * Returns true if either the major or minor version of EE changed during this request.
677
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
-     *
679
-     * @return bool
680
-     */
681
-    public function is_major_version_change()
682
-    {
683
-        return $this->_major_version_change;
684
-    }
685
-
686
-
687
-
688
-    /**
689
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
-     * just activated to (for core that will always be espresso_version())
693
-     *
694
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
-     *                                                 ee plugin. for core that's 'espresso_db_update'
696
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
-     *                                                 indicate that this plugin was just activated
698
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
-     *                                                 espresso_version())
700
-     * @return int one of the constants on EE_System::req_type_*
701
-     */
702
-    public static function detect_req_type_given_activation_history(
703
-        $activation_history_for_addon,
704
-        $activation_indicator_option_name,
705
-        $version_to_upgrade_to
706
-    ) {
707
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
-        if ($activation_history_for_addon) {
709
-            //it exists, so this isn't a completely new install
710
-            //check if this version already in that list of previously installed versions
711
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
-                //it a version we haven't seen before
713
-                if ($version_is_higher === 1) {
714
-                    $req_type = EE_System::req_type_upgrade;
715
-                } else {
716
-                    $req_type = EE_System::req_type_downgrade;
717
-                }
718
-                delete_option($activation_indicator_option_name);
719
-            } else {
720
-                // its not an update. maybe a reactivation?
721
-                if (get_option($activation_indicator_option_name, false)) {
722
-                    if ($version_is_higher === -1) {
723
-                        $req_type = EE_System::req_type_downgrade;
724
-                    } elseif ($version_is_higher === 0) {
725
-                        //we've seen this version before, but it's an activation. must be a reactivation
726
-                        $req_type = EE_System::req_type_reactivation;
727
-                    } else {//$version_is_higher === 1
728
-                        $req_type = EE_System::req_type_upgrade;
729
-                    }
730
-                    delete_option($activation_indicator_option_name);
731
-                } else {
732
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
733
-                    if ($version_is_higher === -1) {
734
-                        $req_type = EE_System::req_type_downgrade;
735
-                    } elseif ($version_is_higher === 0) {
736
-                        //we've seen this version before and it's not an activation. its normal request
737
-                        $req_type = EE_System::req_type_normal;
738
-                    } else {//$version_is_higher === 1
739
-                        $req_type = EE_System::req_type_upgrade;
740
-                    }
741
-                }
742
-            }
743
-        } else {
744
-            //brand new install
745
-            $req_type = EE_System::req_type_new_activation;
746
-            delete_option($activation_indicator_option_name);
747
-        }
748
-        return $req_type;
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
-     * the $activation_history_for_addon
756
-     *
757
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
-     *                                             sometimes containing 'unknown-date'
759
-     * @param string $version_to_upgrade_to        (current version)
760
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
-     */
765
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
-    {
767
-        //find the most recently-activated version
768
-        $most_recently_active_version =
769
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * Gets the most recently active version listed in the activation history,
777
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
-     *
779
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
-     *                                   sometimes containing 'unknown-date'
781
-     * @return string
782
-     */
783
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
-    {
785
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
786
-        $most_recently_active_version            = '0.0.0.dev.000';
787
-        if (is_array($activation_history)) {
788
-            foreach ($activation_history as $version => $times_activated) {
789
-                //check there is a record of when this version was activated. Otherwise,
790
-                //mark it as unknown
791
-                if (! $times_activated) {
792
-                    $times_activated = array('unknown-date');
793
-                }
794
-                if (is_string($times_activated)) {
795
-                    $times_activated = array($times_activated);
796
-                }
797
-                foreach ($times_activated as $an_activation) {
798
-                    if ($an_activation !== 'unknown-date'
799
-                        && $an_activation
800
-                           > $most_recently_active_version_activation) {
801
-                        $most_recently_active_version            = $version;
802
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
803
-                            ? '1970-01-01 00:00:00'
804
-                            : $an_activation;
805
-                    }
806
-                }
807
-            }
808
-        }
809
-        return $most_recently_active_version;
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * This redirects to the about EE page after activation
816
-     *
817
-     * @return void
818
-     */
819
-    public function redirect_to_about_ee()
820
-    {
821
-        $notices = EE_Error::get_notices(false);
822
-        //if current user is an admin and it's not an ajax or rest request
823
-        if (
824
-            ! isset($notices['errors'])
825
-            && $this->request->isAdmin()
826
-            && apply_filters(
827
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
-            )
830
-        ) {
831
-            $query_params = array('page' => 'espresso_about');
832
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
-                $query_params['new_activation'] = true;
834
-            }
835
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
-                $query_params['reactivation'] = true;
837
-            }
838
-            $url = add_query_arg($query_params, admin_url('admin.php'));
839
-            wp_safe_redirect($url);
840
-            exit();
841
-        }
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * load_core_configuration
848
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
-     * which runs during the WP 'plugins_loaded' action at priority 5
850
-     *
851
-     * @return void
852
-     * @throws ReflectionException
853
-     */
854
-    public function load_core_configuration()
855
-    {
856
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
-        $this->loader->getShared('EE_Load_Textdomain');
858
-        //load textdomain
859
-        EE_Load_Textdomain::load_textdomain();
860
-        // load and setup EE_Config and EE_Network_Config
861
-        $config = $this->loader->getShared('EE_Config');
862
-        $this->loader->getShared('EE_Network_Config');
863
-        // setup autoloaders
864
-        // enable logging?
865
-        if ($config->admin->use_full_logging) {
866
-            $this->loader->getShared('EE_Log');
867
-        }
868
-        // check for activation errors
869
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
870
-        if ($activation_errors) {
871
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
-            update_option('ee_plugin_activation_errors', false);
873
-        }
874
-        // get model names
875
-        $this->_parse_model_names();
876
-        //load caf stuff a chance to play during the activation process too.
877
-        $this->_maybe_brew_regular();
878
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
885
-     *
886
-     * @return void
887
-     * @throws ReflectionException
888
-     */
889
-    private function _parse_model_names()
890
-    {
891
-        //get all the files in the EE_MODELS folder that end in .model.php
892
-        $models                 = glob(EE_MODELS . '*.model.php');
893
-        $model_names            = array();
894
-        $non_abstract_db_models = array();
895
-        foreach ($models as $model) {
896
-            // get model classname
897
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
-            $short_name      = str_replace('EEM_', '', $classname);
899
-            $reflectionClass = new ReflectionClass($classname);
900
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
-                $non_abstract_db_models[ $short_name ] = $classname;
902
-            }
903
-            $model_names[ $short_name ] = $classname;
904
-        }
905
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
-        $this->registry->non_abstract_db_models = apply_filters(
907
-            'FHEE__EE_System__parse_implemented_model_names',
908
-            $non_abstract_db_models
909
-        );
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
-     * that need to be setup before our EE_System launches.
917
-     *
918
-     * @return void
919
-     */
920
-    private function _maybe_brew_regular()
921
-    {
922
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
924
-        }
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * register_shortcodes_modules_and_widgets
931
-     * generate lists of shortcodes and modules, then verify paths and classes
932
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
-     * which runs during the WP 'plugins_loaded' action at priority 7
934
-     *
935
-     * @access public
936
-     * @return void
937
-     * @throws Exception
938
-     */
939
-    public function register_shortcodes_modules_and_widgets()
940
-    {
941
-        try {
942
-            // load, register, and add shortcodes the new way
943
-            if ($this->request->isFrontend() || $this->request->isIframe()) {
944
-                $this->loader->getShared(
945
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
-                    array(
947
-                        // and the old way, but we'll put it under control of the new system
948
-                        EE_Config::getLegacyShortcodesManager(),
949
-                    )
950
-                );
951
-            }
952
-            if (function_exists('register_block_type')) {
953
-                $editor_block_collection = $this->loader->getShared(
954
-                    'EventEspresso\core\domain\entities\editor\EditorBlockCollection'
955
-                );
956
-                // or the even newer newer new way
957
-                if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
958
-                    $this->loader->getShared(
959
-                        'EventEspresso\core\services\editor\EditorBlockRegistrationManager',
960
-                        array($editor_block_collection, $this->request)
961
-                    );
962
-                }
963
-                if ($this->request->isAdmin()) {
964
-                    $this->loader->getShared(
965
-                        'EventEspresso\core\services\editor\EditorBlockAdminManager',
966
-                        array($editor_block_collection, $this->request)
967
-                    );
968
-                }
969
-            }
970
-        } catch (Exception $exception) {
971
-            new ExceptionStackTraceDisplay($exception);
972
-        }
973
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
974
-        // check for addons using old hook point
975
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
976
-            $this->_incompatible_addon_error();
977
-        }
978
-    }
979
-
980
-
981
-
982
-    /**
983
-     * _incompatible_addon_error
984
-     *
985
-     * @access public
986
-     * @return void
987
-     */
988
-    private function _incompatible_addon_error()
989
-    {
990
-        // get array of classes hooking into here
991
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
992
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
993
-        );
994
-        if (! empty($class_names)) {
995
-            $msg = __(
996
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
997
-                'event_espresso'
998
-            );
999
-            $msg .= '<ul>';
1000
-            foreach ($class_names as $class_name) {
1001
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
1002
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1003
-                        $class_name
1004
-                    ) . '</b></li>';
1005
-            }
1006
-            $msg .= '</ul>';
1007
-            $msg .= __(
1008
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1009
-                'event_espresso'
1010
-            );
1011
-            // save list of incompatible addons to wp-options for later use
1012
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1013
-            if (is_admin()) {
1014
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1015
-            }
1016
-        }
1017
-    }
1018
-
1019
-
1020
-
1021
-    /**
1022
-     * brew_espresso
1023
-     * begins the process of setting hooks for initializing EE in the correct order
1024
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1025
-     * which runs during the WP 'plugins_loaded' action at priority 9
1026
-     *
1027
-     * @return void
1028
-     */
1029
-    public function brew_espresso()
1030
-    {
1031
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1032
-        // load some final core systems
1033
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1034
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1035
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1036
-        add_action('init', array($this, 'load_controllers'), 7);
1037
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1038
-        add_action('init', array($this, 'initialize'), 10);
1039
-        add_action('init', array($this, 'initialize_last'), 100);
1040
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1041
-            // pew pew pew
1042
-            $this->loader->getShared('EE_PUE');
1043
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1044
-        }
1045
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1046
-    }
1047
-
1048
-
1049
-
1050
-    /**
1051
-     *    set_hooks_for_core
1052
-     *
1053
-     * @access public
1054
-     * @return    void
1055
-     * @throws EE_Error
1056
-     */
1057
-    public function set_hooks_for_core()
1058
-    {
1059
-        $this->_deactivate_incompatible_addons();
1060
-        do_action('AHEE__EE_System__set_hooks_for_core');
1061
-        //caps need to be initialized on every request so that capability maps are set.
1062
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1063
-        $this->registry->CAP->init_caps();
1064
-    }
1065
-
1066
-
1067
-
1068
-    /**
1069
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1070
-     * deactivates any addons considered incompatible with the current version of EE
1071
-     */
1072
-    private function _deactivate_incompatible_addons()
1073
-    {
1074
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1075
-        if (! empty($incompatible_addons)) {
1076
-            $active_plugins = get_option('active_plugins', array());
1077
-            foreach ($active_plugins as $active_plugin) {
1078
-                foreach ($incompatible_addons as $incompatible_addon) {
1079
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1080
-                        unset($_GET['activate']);
1081
-                        espresso_deactivate_plugin($active_plugin);
1082
-                    }
1083
-                }
1084
-            }
1085
-        }
1086
-    }
1087
-
1088
-
1089
-
1090
-    /**
1091
-     *    perform_activations_upgrades_and_migrations
1092
-     *
1093
-     * @access public
1094
-     * @return    void
1095
-     */
1096
-    public function perform_activations_upgrades_and_migrations()
1097
-    {
1098
-        //first check if we had previously attempted to setup EE's directories but failed
1099
-        if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1100
-            EEH_Activation::create_upload_directories();
1101
-        }
1102
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1103
-    }
1104
-
1105
-
1106
-
1107
-    /**
1108
-     *    load_CPTs_and_session
1109
-     *
1110
-     * @access public
1111
-     * @return    void
1112
-     */
1113
-    public function load_CPTs_and_session()
1114
-    {
1115
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1116
-        // register Custom Post Types
1117
-        $this->loader->getShared('EE_Register_CPTs');
1118
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1119
-    }
1120
-
1121
-
1122
-
1123
-    /**
1124
-     * load_controllers
1125
-     * this is the best place to load any additional controllers that needs access to EE core.
1126
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1127
-     * time
1128
-     *
1129
-     * @access public
1130
-     * @return void
1131
-     */
1132
-    public function load_controllers()
1133
-    {
1134
-        do_action('AHEE__EE_System__load_controllers__start');
1135
-        // let's get it started
1136
-        if (
1137
-            ! $this->maintenance_mode->level()
1138
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1139
-        ) {
1140
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1141
-            $this->loader->getShared('EE_Front_Controller');
1142
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1143
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1144
-            $this->loader->getShared('EE_Admin');
1145
-        }
1146
-        do_action('AHEE__EE_System__load_controllers__complete');
1147
-    }
1148
-
1149
-
1150
-
1151
-    /**
1152
-     * core_loaded_and_ready
1153
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1154
-     *
1155
-     * @access public
1156
-     * @return void
1157
-     */
1158
-    public function core_loaded_and_ready()
1159
-    {
1160
-        if (
1161
-            $this->request->isAdmin()
1162
-            || $this->request->isEeAjax()
1163
-            || $this->request->isFrontend()
1164
-        ) {
1165
-            $this->loader->getShared('EE_Session');
1166
-        }
1167
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1168
-        // load_espresso_template_tags
1169
-        if (
1170
-            is_readable(EE_PUBLIC . 'template_tags.php')
1171
-            && (
1172
-                $this->request->isFrontend()
1173
-                || $this->request->isAdmin()
1174
-                || $this->request->isIframe()
1175
-                || $this->request->isFeed()
1176
-            )
1177
-        ) {
1178
-            require_once EE_PUBLIC . 'template_tags.php';
1179
-        }
1180
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1181
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1182
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1183
-        }
1184
-    }
1185
-
1186
-
1187
-
1188
-    /**
1189
-     * initialize
1190
-     * this is the best place to begin initializing client code
1191
-     *
1192
-     * @access public
1193
-     * @return void
1194
-     */
1195
-    public function initialize()
1196
-    {
1197
-        do_action('AHEE__EE_System__initialize');
1198
-    }
1199
-
1200
-
1201
-
1202
-    /**
1203
-     * initialize_last
1204
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1205
-     * initialize has done so
1206
-     *
1207
-     * @access public
1208
-     * @return void
1209
-     */
1210
-    public function initialize_last()
1211
-    {
1212
-        do_action('AHEE__EE_System__initialize_last');
1213
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1214
-    }
1215
-
1216
-
1217
-
1218
-    /**
1219
-     * @return void
1220
-     * @throws EE_Error
1221
-     */
1222
-    public function addEspressoToolbar()
1223
-    {
1224
-        $this->loader->getShared(
1225
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1226
-            array($this->registry->CAP)
1227
-        );
1228
-    }
1229
-
1230
-
1231
-
1232
-    /**
1233
-     * do_not_cache
1234
-     * sets no cache headers and defines no cache constants for WP plugins
1235
-     *
1236
-     * @access public
1237
-     * @return void
1238
-     */
1239
-    public static function do_not_cache()
1240
-    {
1241
-        // set no cache constants
1242
-        if (! defined('DONOTCACHEPAGE')) {
1243
-            define('DONOTCACHEPAGE', true);
1244
-        }
1245
-        if (! defined('DONOTCACHCEOBJECT')) {
1246
-            define('DONOTCACHCEOBJECT', true);
1247
-        }
1248
-        if (! defined('DONOTCACHEDB')) {
1249
-            define('DONOTCACHEDB', true);
1250
-        }
1251
-        // add no cache headers
1252
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1253
-        // plus a little extra for nginx and Google Chrome
1254
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1255
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1256
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1257
-    }
1258
-
1259
-
1260
-
1261
-    /**
1262
-     *    extra_nocache_headers
1263
-     *
1264
-     * @access    public
1265
-     * @param $headers
1266
-     * @return    array
1267
-     */
1268
-    public static function extra_nocache_headers($headers)
1269
-    {
1270
-        // for NGINX
1271
-        $headers['X-Accel-Expires'] = 0;
1272
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1273
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1274
-        return $headers;
1275
-    }
1276
-
1277
-
1278
-
1279
-    /**
1280
-     *    nocache_headers
1281
-     *
1282
-     * @access    public
1283
-     * @return    void
1284
-     */
1285
-    public static function nocache_headers()
1286
-    {
1287
-        nocache_headers();
1288
-    }
1289
-
1290
-
1291
-
1292
-    /**
1293
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1294
-     * never returned with the function.
1295
-     *
1296
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1297
-     * @return array
1298
-     */
1299
-    public function remove_pages_from_wp_list_pages($exclude_array)
1300
-    {
1301
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1302
-    }
27
+	/**
28
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
+	 */
31
+	const req_type_normal = 0;
32
+
33
+	/**
34
+	 * Indicates this is a brand new installation of EE so we should install
35
+	 * tables and default data etc
36
+	 */
37
+	const req_type_new_activation = 1;
38
+
39
+	/**
40
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
42
+	 * and that default data is setup too
43
+	 */
44
+	const req_type_reactivation = 2;
45
+
46
+	/**
47
+	 * indicates that EE has been upgraded since its previous request.
48
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
49
+	 */
50
+	const req_type_upgrade = 3;
51
+
52
+	/**
53
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
+	 */
55
+	const req_type_downgrade = 4;
56
+
57
+	/**
58
+	 * @deprecated since version 4.6.0.dev.006
59
+	 * Now whenever a new_activation is detected the request type is still just
60
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
+	 * (Specifically, when the migration manager indicates migrations are finished
64
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
+	 */
66
+	const req_type_activation_but_not_installed = 5;
67
+
68
+	/**
69
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
+	 */
71
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
+
73
+
74
+	/**
75
+	 * @var EE_System $_instance
76
+	 */
77
+	private static $_instance;
78
+
79
+	/**
80
+	 * @var EE_Registry $registry
81
+	 */
82
+	private $registry;
83
+
84
+	/**
85
+	 * @var LoaderInterface $loader
86
+	 */
87
+	private $loader;
88
+
89
+	/**
90
+	 * @var EE_Capabilities $capabilities
91
+	 */
92
+	private $capabilities;
93
+
94
+	/**
95
+	 * @var RequestInterface $request
96
+	 */
97
+	private $request;
98
+
99
+	/**
100
+	 * @var EE_Maintenance_Mode $maintenance_mode
101
+	 */
102
+	private $maintenance_mode;
103
+
104
+	/**
105
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
+	 *
108
+	 * @var int $_req_type
109
+	 */
110
+	private $_req_type;
111
+
112
+	/**
113
+	 * Whether or not there was a non-micro version change in EE core version during this request
114
+	 *
115
+	 * @var boolean $_major_version_change
116
+	 */
117
+	private $_major_version_change = false;
118
+
119
+	/**
120
+	 * A Context DTO dedicated solely to identifying the current request type.
121
+	 *
122
+	 * @var RequestTypeContextCheckerInterface $request_type
123
+	 */
124
+	private $request_type;
125
+
126
+
127
+
128
+	/**
129
+	 * @singleton method used to instantiate class object
130
+	 * @param EE_Registry|null         $registry
131
+	 * @param LoaderInterface|null     $loader
132
+	 * @param RequestInterface|null          $request
133
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
134
+	 * @return EE_System
135
+	 */
136
+	public static function instance(
137
+		EE_Registry $registry = null,
138
+		LoaderInterface $loader = null,
139
+		RequestInterface $request = null,
140
+		EE_Maintenance_Mode $maintenance_mode = null
141
+	) {
142
+		// check if class object is instantiated
143
+		if (! self::$_instance instanceof EE_System) {
144
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
+		}
146
+		return self::$_instance;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * resets the instance and returns it
153
+	 *
154
+	 * @return EE_System
155
+	 */
156
+	public static function reset()
157
+	{
158
+		self::$_instance->_req_type = null;
159
+		//make sure none of the old hooks are left hanging around
160
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
+		//we need to reset the migration manager in order for it to detect DMSs properly
162
+		EE_Data_Migration_Manager::reset();
163
+		self::instance()->detect_activations_or_upgrades();
164
+		self::instance()->perform_activations_upgrades_and_migrations();
165
+		return self::instance();
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * sets hooks for running rest of system
172
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
+	 * starting EE Addons from any other point may lead to problems
174
+	 *
175
+	 * @param EE_Registry         $registry
176
+	 * @param LoaderInterface     $loader
177
+	 * @param RequestInterface          $request
178
+	 * @param EE_Maintenance_Mode $maintenance_mode
179
+	 */
180
+	private function __construct(
181
+		EE_Registry $registry,
182
+		LoaderInterface $loader,
183
+		RequestInterface $request,
184
+		EE_Maintenance_Mode $maintenance_mode
185
+	) {
186
+		$this->registry         = $registry;
187
+		$this->loader           = $loader;
188
+		$this->request          = $request;
189
+		$this->maintenance_mode = $maintenance_mode;
190
+		do_action('AHEE__EE_System__construct__begin', $this);
191
+		add_action(
192
+			'AHEE__EE_Bootstrap__load_espresso_addons',
193
+			array($this, 'loadCapabilities'),
194
+			5
195
+		);
196
+		add_action(
197
+			'AHEE__EE_Bootstrap__load_espresso_addons',
198
+			array($this, 'loadCommandBus'),
199
+			7
200
+		);
201
+		add_action(
202
+			'AHEE__EE_Bootstrap__load_espresso_addons',
203
+			array($this, 'loadPluginApi'),
204
+			9
205
+		);
206
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
+		add_action(
208
+			'AHEE__EE_Bootstrap__load_espresso_addons',
209
+			array($this, 'load_espresso_addons')
210
+		);
211
+		// when an ee addon is activated, we want to call the core hook(s) again
212
+		// because the newly-activated addon didn't get a chance to run at all
213
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
+		// detect whether install or upgrade
215
+		add_action(
216
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
+			array($this, 'detect_activations_or_upgrades'),
218
+			3
219
+		);
220
+		// load EE_Config, EE_Textdomain, etc
221
+		add_action(
222
+			'AHEE__EE_Bootstrap__load_core_configuration',
223
+			array($this, 'load_core_configuration'),
224
+			5
225
+		);
226
+		// load EE_Config, EE_Textdomain, etc
227
+		add_action(
228
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
+			array($this, 'register_shortcodes_modules_and_widgets'),
230
+			7
231
+		);
232
+		// you wanna get going? I wanna get going... let's get going!
233
+		add_action(
234
+			'AHEE__EE_Bootstrap__brew_espresso',
235
+			array($this, 'brew_espresso'),
236
+			9
237
+		);
238
+		//other housekeeping
239
+		//exclude EE critical pages from wp_list_pages
240
+		add_filter(
241
+			'wp_list_pages_excludes',
242
+			array($this, 'remove_pages_from_wp_list_pages'),
243
+			10
244
+		);
245
+		// ALL EE Addons should use the following hook point to attach their initial setup too
246
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
+		do_action('AHEE__EE_System__construct__complete', $this);
248
+	}
249
+
250
+
251
+	/**
252
+	 * load and setup EE_Capabilities
253
+	 *
254
+	 * @return void
255
+	 * @throws EE_Error
256
+	 */
257
+	public function loadCapabilities()
258
+	{
259
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
260
+		add_action(
261
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
262
+			function ()
263
+			{
264
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
+			}
266
+		);
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * create and cache the CommandBus, and also add middleware
273
+	 * The CapChecker middleware requires the use of EE_Capabilities
274
+	 * which is why we need to load the CommandBus after Caps are set up
275
+	 *
276
+	 * @return void
277
+	 * @throws EE_Error
278
+	 */
279
+	public function loadCommandBus()
280
+	{
281
+		$this->loader->getShared(
282
+			'CommandBusInterface',
283
+			array(
284
+				null,
285
+				apply_filters(
286
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
+					array(
288
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
+					)
291
+				),
292
+			)
293
+		);
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * @return void
300
+	 * @throws EE_Error
301
+	 */
302
+	public function loadPluginApi()
303
+	{
304
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
305
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
306
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
+		$this->loader->getShared('EE_Request_Handler');
308
+	}
309
+
310
+
311
+	/**
312
+	 * @param string $addon_name
313
+	 * @param string $version_constant
314
+	 * @param string $min_version_required
315
+	 * @param string $load_callback
316
+	 * @param string $plugin_file_constant
317
+	 * @return void
318
+	 */
319
+	private function deactivateIncompatibleAddon(
320
+		$addon_name,
321
+		$version_constant,
322
+		$min_version_required,
323
+		$load_callback,
324
+		$plugin_file_constant
325
+	) {
326
+		if (! defined($version_constant)) {
327
+			return;
328
+		}
329
+		$addon_version = constant($version_constant);
330
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
+			if (! function_exists('deactivate_plugins')) {
333
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
+			}
335
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
+			EE_Error::add_error(
338
+				sprintf(
339
+					esc_html__(
340
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
+						'event_espresso'
342
+					),
343
+					$addon_name,
344
+					$min_version_required
345
+				),
346
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
+			);
348
+			EE_Error::get_notices(false, true);
349
+		}
350
+	}
351
+
352
+
353
+	/**
354
+	 * load_espresso_addons
355
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
356
+	 * this is hooked into both:
357
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
358
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
359
+	 *    and the WP 'activate_plugin' hook point
360
+	 *
361
+	 * @access public
362
+	 * @return void
363
+	 */
364
+	public function load_espresso_addons()
365
+	{
366
+		$this->deactivateIncompatibleAddon(
367
+			'Wait Lists',
368
+			'EE_WAIT_LISTS_VERSION',
369
+			'1.0.0.beta.074',
370
+			'load_espresso_wait_lists',
371
+			'EE_WAIT_LISTS_PLUGIN_FILE'
372
+		);
373
+		$this->deactivateIncompatibleAddon(
374
+			'Automated Upcoming Event Notifications',
375
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
+			'1.0.0.beta.091',
377
+			'load_espresso_automated_upcoming_event_notification',
378
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
+		);
380
+		do_action('AHEE__EE_System__load_espresso_addons');
381
+		//if the WP API basic auth plugin isn't already loaded, load it now.
382
+		//We want it for mobile apps. Just include the entire plugin
383
+		//also, don't load the basic auth when a plugin is getting activated, because
384
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
+		//and causes a fatal error
386
+		if (
387
+			$this->request->getRequestParam('activate') !== 'true'
388
+			&& ! function_exists('json_basic_auth_handler')
389
+			&& ! function_exists('json_basic_auth_error')
390
+			&& ! in_array(
391
+				$this->request->getRequestParam('action'),
392
+				array('activate', 'activate-selected'),
393
+				true
394
+			)
395
+		) {
396
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
+		}
398
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * detect_activations_or_upgrades
405
+	 * Checks for activation or upgrade of core first;
406
+	 * then also checks if any registered addons have been activated or upgraded
407
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
+	 * which runs during the WP 'plugins_loaded' action at priority 3
409
+	 *
410
+	 * @access public
411
+	 * @return void
412
+	 */
413
+	public function detect_activations_or_upgrades()
414
+	{
415
+		//first off: let's make sure to handle core
416
+		$this->detect_if_activation_or_upgrade();
417
+		foreach ($this->registry->addons as $addon) {
418
+			if ($addon instanceof EE_Addon) {
419
+				//detect teh request type for that addon
420
+				$addon->detect_activation_or_upgrade();
421
+			}
422
+		}
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * detect_if_activation_or_upgrade
429
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
430
+	 * and either setting up the DB or setting up maintenance mode etc.
431
+	 *
432
+	 * @access public
433
+	 * @return void
434
+	 */
435
+	public function detect_if_activation_or_upgrade()
436
+	{
437
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
+		// check if db has been updated, or if its a brand-new installation
439
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
+		$request_type       = $this->detect_req_type($espresso_db_update);
441
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
+		switch ($request_type) {
443
+			case EE_System::req_type_new_activation:
444
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
+				$this->_handle_core_version_change($espresso_db_update);
446
+				break;
447
+			case EE_System::req_type_reactivation:
448
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
+				$this->_handle_core_version_change($espresso_db_update);
450
+				break;
451
+			case EE_System::req_type_upgrade:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
+				//migrations may be required now that we've upgraded
454
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
455
+				$this->_handle_core_version_change($espresso_db_update);
456
+				//				echo "done upgrade";die;
457
+				break;
458
+			case EE_System::req_type_downgrade:
459
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
+				//its possible migrations are no longer required
461
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
462
+				$this->_handle_core_version_change($espresso_db_update);
463
+				break;
464
+			case EE_System::req_type_normal:
465
+			default:
466
+				break;
467
+		}
468
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
+	}
470
+
471
+
472
+
473
+	/**
474
+	 * Updates the list of installed versions and sets hooks for
475
+	 * initializing the database later during the request
476
+	 *
477
+	 * @param array $espresso_db_update
478
+	 */
479
+	private function _handle_core_version_change($espresso_db_update)
480
+	{
481
+		$this->update_list_of_installed_versions($espresso_db_update);
482
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
+		add_action(
484
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
+			array($this, 'initialize_db_if_no_migrations_required')
486
+		);
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
+	 * information about what versions of EE have been installed and activated,
494
+	 * NOT necessarily the state of the database
495
+	 *
496
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
497
+	 *                                            If not supplied, fetches it from the options table
498
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
+	 */
500
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
+	{
502
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
+		if (! $espresso_db_update) {
504
+			$espresso_db_update = get_option('espresso_db_update');
505
+		}
506
+		// check that option is an array
507
+		if (! is_array($espresso_db_update)) {
508
+			// if option is FALSE, then it never existed
509
+			if ($espresso_db_update === false) {
510
+				// make $espresso_db_update an array and save option with autoload OFF
511
+				$espresso_db_update = array();
512
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
+			} else {
514
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
515
+				$espresso_db_update = array($espresso_db_update => array());
516
+				update_option('espresso_db_update', $espresso_db_update);
517
+			}
518
+		} else {
519
+			$corrected_db_update = array();
520
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
+					//the key is an int, and the value IS NOT an array
524
+					//so it must be numerically-indexed, where values are versions installed...
525
+					//fix it!
526
+					$version_string                         = $should_be_array;
527
+					$corrected_db_update[ $version_string ] = array('unknown-date');
528
+				} else {
529
+					//ok it checks out
530
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
+				}
532
+			}
533
+			$espresso_db_update = $corrected_db_update;
534
+			update_option('espresso_db_update', $espresso_db_update);
535
+		}
536
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
+		return $espresso_db_update;
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * Does the traditional work of setting up the plugin's database and adding default data.
544
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
+	 * so that it will be done when migrations are finished
548
+	 *
549
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
+	 *                                       This is a resource-intensive job
552
+	 *                                       so we prefer to only do it when necessary
553
+	 * @return void
554
+	 * @throws EE_Error
555
+	 */
556
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
+	{
558
+		$request_type = $this->detect_req_type();
559
+		//only initialize system if we're not in maintenance mode.
560
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
+			update_option('ee_flush_rewrite_rules', true);
562
+			if ($verify_schema) {
563
+				EEH_Activation::initialize_db_and_folders();
564
+			}
565
+			EEH_Activation::initialize_db_content();
566
+			EEH_Activation::system_initialization();
567
+			if ($initialize_addons_too) {
568
+				$this->initialize_addons();
569
+			}
570
+		} else {
571
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
+		}
573
+		if ($request_type === EE_System::req_type_new_activation
574
+			|| $request_type === EE_System::req_type_reactivation
575
+			|| (
576
+				$request_type === EE_System::req_type_upgrade
577
+				&& $this->is_major_version_change()
578
+			)
579
+		) {
580
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
+		}
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 * Initializes the db for all registered addons
588
+	 *
589
+	 * @throws EE_Error
590
+	 */
591
+	public function initialize_addons()
592
+	{
593
+		//foreach registered addon, make sure its db is up-to-date too
594
+		foreach ($this->registry->addons as $addon) {
595
+			if ($addon instanceof EE_Addon) {
596
+				$addon->initialize_db_if_no_migrations_required();
597
+			}
598
+		}
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
+	 *
606
+	 * @param    array  $version_history
607
+	 * @param    string $current_version_to_add version to be added to the version history
608
+	 * @return    boolean success as to whether or not this option was changed
609
+	 */
610
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
+	{
612
+		if (! $version_history) {
613
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
+		}
615
+		if ($current_version_to_add === null) {
616
+			$current_version_to_add = espresso_version();
617
+		}
618
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
+		// re-save
620
+		return update_option('espresso_db_update', $version_history);
621
+	}
622
+
623
+
624
+
625
+	/**
626
+	 * Detects if the current version indicated in the has existed in the list of
627
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
+	 *
629
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
+	 *                                  If not supplied, fetches it from the options table.
631
+	 *                                  Also, caches its result so later parts of the code can also know whether
632
+	 *                                  there's been an update or not. This way we can add the current version to
633
+	 *                                  espresso_db_update, but still know if this is a new install or not
634
+	 * @return int one of the constants on EE_System::req_type_
635
+	 */
636
+	public function detect_req_type($espresso_db_update = null)
637
+	{
638
+		if ($this->_req_type === null) {
639
+			$espresso_db_update          = ! empty($espresso_db_update)
640
+				? $espresso_db_update
641
+				: $this->fix_espresso_db_upgrade_option();
642
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
+				$espresso_db_update,
644
+				'ee_espresso_activation', espresso_version()
645
+			);
646
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
+		}
649
+		return $this->_req_type;
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * Returns whether or not there was a non-micro version change (ie, change in either
656
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
+	 *
659
+	 * @param $activation_history
660
+	 * @return bool
661
+	 */
662
+	private function _detect_major_version_change($activation_history)
663
+	{
664
+		$previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
+		$previous_version_parts = explode('.', $previous_version);
666
+		$current_version_parts  = explode('.', espresso_version());
667
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
669
+				   || $previous_version_parts[1] !== $current_version_parts[1]
670
+			   );
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * Returns true if either the major or minor version of EE changed during this request.
677
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
+	 *
679
+	 * @return bool
680
+	 */
681
+	public function is_major_version_change()
682
+	{
683
+		return $this->_major_version_change;
684
+	}
685
+
686
+
687
+
688
+	/**
689
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
+	 * just activated to (for core that will always be espresso_version())
693
+	 *
694
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
696
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
+	 *                                                 indicate that this plugin was just activated
698
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
+	 *                                                 espresso_version())
700
+	 * @return int one of the constants on EE_System::req_type_*
701
+	 */
702
+	public static function detect_req_type_given_activation_history(
703
+		$activation_history_for_addon,
704
+		$activation_indicator_option_name,
705
+		$version_to_upgrade_to
706
+	) {
707
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
+		if ($activation_history_for_addon) {
709
+			//it exists, so this isn't a completely new install
710
+			//check if this version already in that list of previously installed versions
711
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
+				//it a version we haven't seen before
713
+				if ($version_is_higher === 1) {
714
+					$req_type = EE_System::req_type_upgrade;
715
+				} else {
716
+					$req_type = EE_System::req_type_downgrade;
717
+				}
718
+				delete_option($activation_indicator_option_name);
719
+			} else {
720
+				// its not an update. maybe a reactivation?
721
+				if (get_option($activation_indicator_option_name, false)) {
722
+					if ($version_is_higher === -1) {
723
+						$req_type = EE_System::req_type_downgrade;
724
+					} elseif ($version_is_higher === 0) {
725
+						//we've seen this version before, but it's an activation. must be a reactivation
726
+						$req_type = EE_System::req_type_reactivation;
727
+					} else {//$version_is_higher === 1
728
+						$req_type = EE_System::req_type_upgrade;
729
+					}
730
+					delete_option($activation_indicator_option_name);
731
+				} else {
732
+					//we've seen this version before and the activation indicate doesn't show it was just activated
733
+					if ($version_is_higher === -1) {
734
+						$req_type = EE_System::req_type_downgrade;
735
+					} elseif ($version_is_higher === 0) {
736
+						//we've seen this version before and it's not an activation. its normal request
737
+						$req_type = EE_System::req_type_normal;
738
+					} else {//$version_is_higher === 1
739
+						$req_type = EE_System::req_type_upgrade;
740
+					}
741
+				}
742
+			}
743
+		} else {
744
+			//brand new install
745
+			$req_type = EE_System::req_type_new_activation;
746
+			delete_option($activation_indicator_option_name);
747
+		}
748
+		return $req_type;
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
+	 * the $activation_history_for_addon
756
+	 *
757
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
+	 *                                             sometimes containing 'unknown-date'
759
+	 * @param string $version_to_upgrade_to        (current version)
760
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
+	 */
765
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
+	{
767
+		//find the most recently-activated version
768
+		$most_recently_active_version =
769
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * Gets the most recently active version listed in the activation history,
777
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
+	 *
779
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
+	 *                                   sometimes containing 'unknown-date'
781
+	 * @return string
782
+	 */
783
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
+	{
785
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
786
+		$most_recently_active_version            = '0.0.0.dev.000';
787
+		if (is_array($activation_history)) {
788
+			foreach ($activation_history as $version => $times_activated) {
789
+				//check there is a record of when this version was activated. Otherwise,
790
+				//mark it as unknown
791
+				if (! $times_activated) {
792
+					$times_activated = array('unknown-date');
793
+				}
794
+				if (is_string($times_activated)) {
795
+					$times_activated = array($times_activated);
796
+				}
797
+				foreach ($times_activated as $an_activation) {
798
+					if ($an_activation !== 'unknown-date'
799
+						&& $an_activation
800
+						   > $most_recently_active_version_activation) {
801
+						$most_recently_active_version            = $version;
802
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
803
+							? '1970-01-01 00:00:00'
804
+							: $an_activation;
805
+					}
806
+				}
807
+			}
808
+		}
809
+		return $most_recently_active_version;
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * This redirects to the about EE page after activation
816
+	 *
817
+	 * @return void
818
+	 */
819
+	public function redirect_to_about_ee()
820
+	{
821
+		$notices = EE_Error::get_notices(false);
822
+		//if current user is an admin and it's not an ajax or rest request
823
+		if (
824
+			! isset($notices['errors'])
825
+			&& $this->request->isAdmin()
826
+			&& apply_filters(
827
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
+			)
830
+		) {
831
+			$query_params = array('page' => 'espresso_about');
832
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
+				$query_params['new_activation'] = true;
834
+			}
835
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
+				$query_params['reactivation'] = true;
837
+			}
838
+			$url = add_query_arg($query_params, admin_url('admin.php'));
839
+			wp_safe_redirect($url);
840
+			exit();
841
+		}
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * load_core_configuration
848
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
+	 * which runs during the WP 'plugins_loaded' action at priority 5
850
+	 *
851
+	 * @return void
852
+	 * @throws ReflectionException
853
+	 */
854
+	public function load_core_configuration()
855
+	{
856
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
+		$this->loader->getShared('EE_Load_Textdomain');
858
+		//load textdomain
859
+		EE_Load_Textdomain::load_textdomain();
860
+		// load and setup EE_Config and EE_Network_Config
861
+		$config = $this->loader->getShared('EE_Config');
862
+		$this->loader->getShared('EE_Network_Config');
863
+		// setup autoloaders
864
+		// enable logging?
865
+		if ($config->admin->use_full_logging) {
866
+			$this->loader->getShared('EE_Log');
867
+		}
868
+		// check for activation errors
869
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
870
+		if ($activation_errors) {
871
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
+			update_option('ee_plugin_activation_errors', false);
873
+		}
874
+		// get model names
875
+		$this->_parse_model_names();
876
+		//load caf stuff a chance to play during the activation process too.
877
+		$this->_maybe_brew_regular();
878
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
885
+	 *
886
+	 * @return void
887
+	 * @throws ReflectionException
888
+	 */
889
+	private function _parse_model_names()
890
+	{
891
+		//get all the files in the EE_MODELS folder that end in .model.php
892
+		$models                 = glob(EE_MODELS . '*.model.php');
893
+		$model_names            = array();
894
+		$non_abstract_db_models = array();
895
+		foreach ($models as $model) {
896
+			// get model classname
897
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
+			$short_name      = str_replace('EEM_', '', $classname);
899
+			$reflectionClass = new ReflectionClass($classname);
900
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
+				$non_abstract_db_models[ $short_name ] = $classname;
902
+			}
903
+			$model_names[ $short_name ] = $classname;
904
+		}
905
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
+		$this->registry->non_abstract_db_models = apply_filters(
907
+			'FHEE__EE_System__parse_implemented_model_names',
908
+			$non_abstract_db_models
909
+		);
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
+	 * that need to be setup before our EE_System launches.
917
+	 *
918
+	 * @return void
919
+	 */
920
+	private function _maybe_brew_regular()
921
+	{
922
+		if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
924
+		}
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * register_shortcodes_modules_and_widgets
931
+	 * generate lists of shortcodes and modules, then verify paths and classes
932
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
+	 * which runs during the WP 'plugins_loaded' action at priority 7
934
+	 *
935
+	 * @access public
936
+	 * @return void
937
+	 * @throws Exception
938
+	 */
939
+	public function register_shortcodes_modules_and_widgets()
940
+	{
941
+		try {
942
+			// load, register, and add shortcodes the new way
943
+			if ($this->request->isFrontend() || $this->request->isIframe()) {
944
+				$this->loader->getShared(
945
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
+					array(
947
+						// and the old way, but we'll put it under control of the new system
948
+						EE_Config::getLegacyShortcodesManager(),
949
+					)
950
+				);
951
+			}
952
+			if (function_exists('register_block_type')) {
953
+				$editor_block_collection = $this->loader->getShared(
954
+					'EventEspresso\core\domain\entities\editor\EditorBlockCollection'
955
+				);
956
+				// or the even newer newer new way
957
+				if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
958
+					$this->loader->getShared(
959
+						'EventEspresso\core\services\editor\EditorBlockRegistrationManager',
960
+						array($editor_block_collection, $this->request)
961
+					);
962
+				}
963
+				if ($this->request->isAdmin()) {
964
+					$this->loader->getShared(
965
+						'EventEspresso\core\services\editor\EditorBlockAdminManager',
966
+						array($editor_block_collection, $this->request)
967
+					);
968
+				}
969
+			}
970
+		} catch (Exception $exception) {
971
+			new ExceptionStackTraceDisplay($exception);
972
+		}
973
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
974
+		// check for addons using old hook point
975
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
976
+			$this->_incompatible_addon_error();
977
+		}
978
+	}
979
+
980
+
981
+
982
+	/**
983
+	 * _incompatible_addon_error
984
+	 *
985
+	 * @access public
986
+	 * @return void
987
+	 */
988
+	private function _incompatible_addon_error()
989
+	{
990
+		// get array of classes hooking into here
991
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
992
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
993
+		);
994
+		if (! empty($class_names)) {
995
+			$msg = __(
996
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
997
+				'event_espresso'
998
+			);
999
+			$msg .= '<ul>';
1000
+			foreach ($class_names as $class_name) {
1001
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
1002
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1003
+						$class_name
1004
+					) . '</b></li>';
1005
+			}
1006
+			$msg .= '</ul>';
1007
+			$msg .= __(
1008
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1009
+				'event_espresso'
1010
+			);
1011
+			// save list of incompatible addons to wp-options for later use
1012
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1013
+			if (is_admin()) {
1014
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1015
+			}
1016
+		}
1017
+	}
1018
+
1019
+
1020
+
1021
+	/**
1022
+	 * brew_espresso
1023
+	 * begins the process of setting hooks for initializing EE in the correct order
1024
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1025
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1026
+	 *
1027
+	 * @return void
1028
+	 */
1029
+	public function brew_espresso()
1030
+	{
1031
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1032
+		// load some final core systems
1033
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1034
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1035
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1036
+		add_action('init', array($this, 'load_controllers'), 7);
1037
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1038
+		add_action('init', array($this, 'initialize'), 10);
1039
+		add_action('init', array($this, 'initialize_last'), 100);
1040
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1041
+			// pew pew pew
1042
+			$this->loader->getShared('EE_PUE');
1043
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1044
+		}
1045
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1046
+	}
1047
+
1048
+
1049
+
1050
+	/**
1051
+	 *    set_hooks_for_core
1052
+	 *
1053
+	 * @access public
1054
+	 * @return    void
1055
+	 * @throws EE_Error
1056
+	 */
1057
+	public function set_hooks_for_core()
1058
+	{
1059
+		$this->_deactivate_incompatible_addons();
1060
+		do_action('AHEE__EE_System__set_hooks_for_core');
1061
+		//caps need to be initialized on every request so that capability maps are set.
1062
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1063
+		$this->registry->CAP->init_caps();
1064
+	}
1065
+
1066
+
1067
+
1068
+	/**
1069
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1070
+	 * deactivates any addons considered incompatible with the current version of EE
1071
+	 */
1072
+	private function _deactivate_incompatible_addons()
1073
+	{
1074
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1075
+		if (! empty($incompatible_addons)) {
1076
+			$active_plugins = get_option('active_plugins', array());
1077
+			foreach ($active_plugins as $active_plugin) {
1078
+				foreach ($incompatible_addons as $incompatible_addon) {
1079
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1080
+						unset($_GET['activate']);
1081
+						espresso_deactivate_plugin($active_plugin);
1082
+					}
1083
+				}
1084
+			}
1085
+		}
1086
+	}
1087
+
1088
+
1089
+
1090
+	/**
1091
+	 *    perform_activations_upgrades_and_migrations
1092
+	 *
1093
+	 * @access public
1094
+	 * @return    void
1095
+	 */
1096
+	public function perform_activations_upgrades_and_migrations()
1097
+	{
1098
+		//first check if we had previously attempted to setup EE's directories but failed
1099
+		if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1100
+			EEH_Activation::create_upload_directories();
1101
+		}
1102
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1103
+	}
1104
+
1105
+
1106
+
1107
+	/**
1108
+	 *    load_CPTs_and_session
1109
+	 *
1110
+	 * @access public
1111
+	 * @return    void
1112
+	 */
1113
+	public function load_CPTs_and_session()
1114
+	{
1115
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1116
+		// register Custom Post Types
1117
+		$this->loader->getShared('EE_Register_CPTs');
1118
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1119
+	}
1120
+
1121
+
1122
+
1123
+	/**
1124
+	 * load_controllers
1125
+	 * this is the best place to load any additional controllers that needs access to EE core.
1126
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1127
+	 * time
1128
+	 *
1129
+	 * @access public
1130
+	 * @return void
1131
+	 */
1132
+	public function load_controllers()
1133
+	{
1134
+		do_action('AHEE__EE_System__load_controllers__start');
1135
+		// let's get it started
1136
+		if (
1137
+			! $this->maintenance_mode->level()
1138
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1139
+		) {
1140
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1141
+			$this->loader->getShared('EE_Front_Controller');
1142
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1143
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1144
+			$this->loader->getShared('EE_Admin');
1145
+		}
1146
+		do_action('AHEE__EE_System__load_controllers__complete');
1147
+	}
1148
+
1149
+
1150
+
1151
+	/**
1152
+	 * core_loaded_and_ready
1153
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1154
+	 *
1155
+	 * @access public
1156
+	 * @return void
1157
+	 */
1158
+	public function core_loaded_and_ready()
1159
+	{
1160
+		if (
1161
+			$this->request->isAdmin()
1162
+			|| $this->request->isEeAjax()
1163
+			|| $this->request->isFrontend()
1164
+		) {
1165
+			$this->loader->getShared('EE_Session');
1166
+		}
1167
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1168
+		// load_espresso_template_tags
1169
+		if (
1170
+			is_readable(EE_PUBLIC . 'template_tags.php')
1171
+			&& (
1172
+				$this->request->isFrontend()
1173
+				|| $this->request->isAdmin()
1174
+				|| $this->request->isIframe()
1175
+				|| $this->request->isFeed()
1176
+			)
1177
+		) {
1178
+			require_once EE_PUBLIC . 'template_tags.php';
1179
+		}
1180
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1181
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1182
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1183
+		}
1184
+	}
1185
+
1186
+
1187
+
1188
+	/**
1189
+	 * initialize
1190
+	 * this is the best place to begin initializing client code
1191
+	 *
1192
+	 * @access public
1193
+	 * @return void
1194
+	 */
1195
+	public function initialize()
1196
+	{
1197
+		do_action('AHEE__EE_System__initialize');
1198
+	}
1199
+
1200
+
1201
+
1202
+	/**
1203
+	 * initialize_last
1204
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1205
+	 * initialize has done so
1206
+	 *
1207
+	 * @access public
1208
+	 * @return void
1209
+	 */
1210
+	public function initialize_last()
1211
+	{
1212
+		do_action('AHEE__EE_System__initialize_last');
1213
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1214
+	}
1215
+
1216
+
1217
+
1218
+	/**
1219
+	 * @return void
1220
+	 * @throws EE_Error
1221
+	 */
1222
+	public function addEspressoToolbar()
1223
+	{
1224
+		$this->loader->getShared(
1225
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1226
+			array($this->registry->CAP)
1227
+		);
1228
+	}
1229
+
1230
+
1231
+
1232
+	/**
1233
+	 * do_not_cache
1234
+	 * sets no cache headers and defines no cache constants for WP plugins
1235
+	 *
1236
+	 * @access public
1237
+	 * @return void
1238
+	 */
1239
+	public static function do_not_cache()
1240
+	{
1241
+		// set no cache constants
1242
+		if (! defined('DONOTCACHEPAGE')) {
1243
+			define('DONOTCACHEPAGE', true);
1244
+		}
1245
+		if (! defined('DONOTCACHCEOBJECT')) {
1246
+			define('DONOTCACHCEOBJECT', true);
1247
+		}
1248
+		if (! defined('DONOTCACHEDB')) {
1249
+			define('DONOTCACHEDB', true);
1250
+		}
1251
+		// add no cache headers
1252
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1253
+		// plus a little extra for nginx and Google Chrome
1254
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1255
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1256
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1257
+	}
1258
+
1259
+
1260
+
1261
+	/**
1262
+	 *    extra_nocache_headers
1263
+	 *
1264
+	 * @access    public
1265
+	 * @param $headers
1266
+	 * @return    array
1267
+	 */
1268
+	public static function extra_nocache_headers($headers)
1269
+	{
1270
+		// for NGINX
1271
+		$headers['X-Accel-Expires'] = 0;
1272
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1273
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1274
+		return $headers;
1275
+	}
1276
+
1277
+
1278
+
1279
+	/**
1280
+	 *    nocache_headers
1281
+	 *
1282
+	 * @access    public
1283
+	 * @return    void
1284
+	 */
1285
+	public static function nocache_headers()
1286
+	{
1287
+		nocache_headers();
1288
+	}
1289
+
1290
+
1291
+
1292
+	/**
1293
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1294
+	 * never returned with the function.
1295
+	 *
1296
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1297
+	 * @return array
1298
+	 */
1299
+	public function remove_pages_from_wp_list_pages($exclude_array)
1300
+	{
1301
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1302
+	}
1303 1303
 
1304 1304
 
1305 1305
 
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         EE_Maintenance_Mode $maintenance_mode = null
141 141
     ) {
142 142
         // check if class object is instantiated
143
-        if (! self::$_instance instanceof EE_System) {
143
+        if ( ! self::$_instance instanceof EE_System) {
144 144
             self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145 145
         }
146 146
         return self::$_instance;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         $this->capabilities = $this->loader->getShared('EE_Capabilities');
260 260
         add_action(
261 261
             'AHEE__EE_Capabilities__init_caps__before_initialization',
262
-            function ()
262
+            function()
263 263
             {
264 264
                 LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265 265
             }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     {
304 304
         // set autoloaders for all of the classes implementing EEI_Plugin_API
305 305
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
306
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
306
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
307 307
         $this->loader->getShared('EE_Request_Handler');
308 308
     }
309 309
 
@@ -323,14 +323,14 @@  discard block
 block discarded – undo
323 323
         $load_callback,
324 324
         $plugin_file_constant
325 325
     ) {
326
-        if (! defined($version_constant)) {
326
+        if ( ! defined($version_constant)) {
327 327
             return;
328 328
         }
329 329
         $addon_version = constant($version_constant);
330 330
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331 331
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
-            if (! function_exists('deactivate_plugins')) {
333
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
332
+            if ( ! function_exists('deactivate_plugins')) {
333
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
334 334
             }
335 335
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336 336
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
                     $addon_name,
344 344
                     $min_version_required
345 345
                 ),
346
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
346
+                __FILE__, __FUNCTION__."({$addon_name})", __LINE__
347 347
             );
348 348
             EE_Error::get_notices(false, true);
349 349
         }
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
                 true
394 394
             )
395 395
         ) {
396
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
396
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
397 397
         }
398 398
         do_action('AHEE__EE_System__load_espresso_addons__complete');
399 399
     }
@@ -500,11 +500,11 @@  discard block
 block discarded – undo
500 500
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501 501
     {
502 502
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
503
+        if ( ! $espresso_db_update) {
504 504
             $espresso_db_update = get_option('espresso_db_update');
505 505
         }
506 506
         // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
507
+        if ( ! is_array($espresso_db_update)) {
508 508
             // if option is FALSE, then it never existed
509 509
             if ($espresso_db_update === false) {
510 510
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
                     //so it must be numerically-indexed, where values are versions installed...
525 525
                     //fix it!
526 526
                     $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
527
+                    $corrected_db_update[$version_string] = array('unknown-date');
528 528
                 } else {
529 529
                     //ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
530
+                    $corrected_db_update[$should_be_version_string] = $should_be_array;
531 531
                 }
532 532
             }
533 533
             $espresso_db_update = $corrected_db_update;
@@ -609,13 +609,13 @@  discard block
 block discarded – undo
609 609
      */
610 610
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611 611
     {
612
-        if (! $version_history) {
612
+        if ( ! $version_history) {
613 613
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
614 614
         }
615 615
         if ($current_version_to_add === null) {
616 616
             $current_version_to_add = espresso_version();
617 617
         }
618
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
618
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
619 619
         // re-save
620 620
         return update_option('espresso_db_update', $version_history);
621 621
     }
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         if ($activation_history_for_addon) {
709 709
             //it exists, so this isn't a completely new install
710 710
             //check if this version already in that list of previously installed versions
711
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
711
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
712 712
                 //it a version we haven't seen before
713 713
                 if ($version_is_higher === 1) {
714 714
                     $req_type = EE_System::req_type_upgrade;
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
             foreach ($activation_history as $version => $times_activated) {
789 789
                 //check there is a record of when this version was activated. Otherwise,
790 790
                 //mark it as unknown
791
-                if (! $times_activated) {
791
+                if ( ! $times_activated) {
792 792
                     $times_activated = array('unknown-date');
793 793
                 }
794 794
                 if (is_string($times_activated)) {
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
     private function _parse_model_names()
890 890
     {
891 891
         //get all the files in the EE_MODELS folder that end in .model.php
892
-        $models                 = glob(EE_MODELS . '*.model.php');
892
+        $models                 = glob(EE_MODELS.'*.model.php');
893 893
         $model_names            = array();
894 894
         $non_abstract_db_models = array();
895 895
         foreach ($models as $model) {
@@ -898,9 +898,9 @@  discard block
 block discarded – undo
898 898
             $short_name      = str_replace('EEM_', '', $classname);
899 899
             $reflectionClass = new ReflectionClass($classname);
900 900
             if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
-                $non_abstract_db_models[ $short_name ] = $classname;
901
+                $non_abstract_db_models[$short_name] = $classname;
902 902
             }
903
-            $model_names[ $short_name ] = $classname;
903
+            $model_names[$short_name] = $classname;
904 904
         }
905 905
         $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906 906
         $this->registry->non_abstract_db_models = apply_filters(
@@ -919,8 +919,8 @@  discard block
 block discarded – undo
919 919
      */
920 920
     private function _maybe_brew_regular()
921 921
     {
922
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
922
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
923
+            require_once EE_CAFF_PATH.'brewing_regular.php';
924 924
         }
925 925
     }
926 926
 
@@ -991,17 +991,17 @@  discard block
 block discarded – undo
991 991
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
992 992
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
993 993
         );
994
-        if (! empty($class_names)) {
994
+        if ( ! empty($class_names)) {
995 995
             $msg = __(
996 996
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
997 997
                 'event_espresso'
998 998
             );
999 999
             $msg .= '<ul>';
1000 1000
             foreach ($class_names as $class_name) {
1001
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
1001
+                $msg .= '<li><b>Event Espresso - '.str_replace(
1002 1002
                         array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1003 1003
                         $class_name
1004
-                    ) . '</b></li>';
1004
+                    ).'</b></li>';
1005 1005
             }
1006 1006
             $msg .= '</ul>';
1007 1007
             $msg .= __(
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
     private function _deactivate_incompatible_addons()
1073 1073
     {
1074 1074
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1075
-        if (! empty($incompatible_addons)) {
1075
+        if ( ! empty($incompatible_addons)) {
1076 1076
             $active_plugins = get_option('active_plugins', array());
1077 1077
             foreach ($active_plugins as $active_plugin) {
1078 1078
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1167,7 +1167,7 @@  discard block
 block discarded – undo
1167 1167
         do_action('AHEE__EE_System__core_loaded_and_ready');
1168 1168
         // load_espresso_template_tags
1169 1169
         if (
1170
-            is_readable(EE_PUBLIC . 'template_tags.php')
1170
+            is_readable(EE_PUBLIC.'template_tags.php')
1171 1171
             && (
1172 1172
                 $this->request->isFrontend()
1173 1173
                 || $this->request->isAdmin()
@@ -1175,7 +1175,7 @@  discard block
 block discarded – undo
1175 1175
                 || $this->request->isFeed()
1176 1176
             )
1177 1177
         ) {
1178
-            require_once EE_PUBLIC . 'template_tags.php';
1178
+            require_once EE_PUBLIC.'template_tags.php';
1179 1179
         }
1180 1180
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1181 1181
         if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
@@ -1239,13 +1239,13 @@  discard block
 block discarded – undo
1239 1239
     public static function do_not_cache()
1240 1240
     {
1241 1241
         // set no cache constants
1242
-        if (! defined('DONOTCACHEPAGE')) {
1242
+        if ( ! defined('DONOTCACHEPAGE')) {
1243 1243
             define('DONOTCACHEPAGE', true);
1244 1244
         }
1245
-        if (! defined('DONOTCACHCEOBJECT')) {
1245
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1246 1246
             define('DONOTCACHCEOBJECT', true);
1247 1247
         }
1248
-        if (! defined('DONOTCACHEDB')) {
1248
+        if ( ! defined('DONOTCACHEDB')) {
1249 1249
             define('DONOTCACHEDB', true);
1250 1250
         }
1251 1251
         // add no cache headers
Please login to merge, or discard this patch.
core/helpers/EEH_Qtip_Loader.helper.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public static function instance() {
34 34
 		// check if class object is instantiated
35
-		if ( self::$_instance === NULL  or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) {
35
+		if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EEH_Qtip_Loader)) {
36 36
 			self::$_instance = new self();
37 37
 		}
38 38
 		return self::$_instance;
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 	 */
49 49
 	private function __construct() {
50 50
 		//let's just make sure this is instantiated in the right place.
51
-		if ( did_action( 'wp_print_styles' ) || did_action( 'admin_head' )) {
52
-			EE_Error::doing_it_wrong( 'EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso' ), '4.1' );
51
+		if (did_action('wp_print_styles') || did_action('admin_head')) {
52
+			EE_Error::doing_it_wrong('EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso'), '4.1');
53 53
 		}
54 54
 	}
55 55
 
@@ -61,25 +61,25 @@  discard block
 block discarded – undo
61 61
 	 * @return void
62 62
 	 */
63 63
 	public function register_and_enqueue() {
64
-		$qtips_js = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js';
65
-		$qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map';
66
-		$qtipcss = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css';
64
+		$qtips_js = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.js';
65
+		$qtip_map = EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.map';
66
+		$qtipcss = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.css';
67 67
 
68
-		wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE );
69
-		wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', TRUE );
70
-		wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS . 'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE );
68
+		wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE);
69
+		wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', TRUE);
70
+		wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS.'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE);
71 71
 
72
-		wp_register_style('qtip-css', $qtipcss, array(), '2.2' );
72
+		wp_register_style('qtip-css', $qtipcss, array(), '2.2');
73 73
 
74 74
 		//k now let's see if there are any registered qtips.  If there are, then we need to setup the localized script for ee-qtip-helper.js (and enqueue ee-qtip-helper.js of course!)
75
-		if ( !empty( $this->_qtips ) ) {
75
+		if ( ! empty($this->_qtips)) {
76 76
 			wp_enqueue_script('ee-qtip-helper');
77 77
 			wp_enqueue_style('qtip-css');
78 78
 			$qtips = array();
79
-			foreach ( $this->_qtips as $qtip ) {
79
+			foreach ($this->_qtips as $qtip) {
80 80
 				$qts = $qtip->get_tips();
81
-				foreach ( $qts as $qt ) {
82
-					if ( ! $qt instanceof EE_Qtip )
81
+				foreach ($qts as $qt) {
82
+					if ( ! $qt instanceof EE_Qtip)
83 83
 						continue;
84 84
 					$qtips[] = array(
85 85
 						'content_id' => $qt->content_id,
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
 						);
89 89
 				}
90 90
 			}
91
-			if ( !empty($qtips) )
92
-				wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ) );
91
+			if ( ! empty($qtips))
92
+				wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array('qtips' => $qtips));
93 93
 
94 94
 		} else {
95 95
 			//qtips has been requested without any registration (so assuming its just directly used in the admin).
@@ -111,24 +111,24 @@  discard block
 block discarded – undo
111 111
 	 * @param  string|array $configname name of the Qtip class (full class name is expected and will be used for looking for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array, then we loop through the array to instantiate and setup the qtips]
112 112
 	 * @return void
113 113
 	 */
114
-	public function register( $configname, $paths = array() ) {
114
+	public function register($configname, $paths = array()) {
115 115
 
116 116
 		//let's just make sure this is instantiated in the right place.
117
-		if ( did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts') ) {
118
-			EE_Error::doing_it_wrong( 'EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso' ), '4.1' );
117
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
118
+			EE_Error::doing_it_wrong('EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso'), '4.1');
119 119
 		}
120 120
 
121 121
 		$configname = (array) $configname; //typecast to array
122
-		foreach ( $configname as $config ) {
123
-			$this->_register( $config, $paths );
122
+		foreach ($configname as $config) {
123
+			$this->_register($config, $paths);
124 124
 		}
125 125
 
126 126
 		//hook into appropriate footer
127 127
 		$footer_action = is_admin() ? 'admin_footer' : 'wp_footer';
128
-		add_action($footer_action, array($this, 'setup_qtip'), 10 );
128
+		add_action($footer_action, array($this, 'setup_qtip'), 10);
129 129
 
130 130
 		//make sure we "turn on" qtip js.
131
-		add_filter('FHEE_load_qtip', '__return_true' );
131
+		add_filter('FHEE_load_qtip', '__return_true');
132 132
 	}
133 133
 
134 134
 
@@ -142,15 +142,15 @@  discard block
 block discarded – undo
142 142
 	 * @throws EE_Error
143 143
 	 * @return void
144 144
 	 */
145
-	private function _register( $config, $paths ) {
145
+	private function _register($config, $paths) {
146 146
 		//before doing anything we have to make sure that EE_Qtip_Config parent is required.
147
-		EE_Registry::instance()->load_lib( 'Qtip_Config', array(), TRUE );
147
+		EE_Registry::instance()->load_lib('Qtip_Config', array(), TRUE);
148 148
 
149
-		if ( !empty( $paths ) ) {
149
+		if ( ! empty($paths)) {
150 150
 			$paths = (array) $paths;
151
-			foreach ( $paths as $path ) {
152
-				$path = $path . $config . '.lib.php';
153
-				if ( !is_readable($path ) ) {
151
+			foreach ($paths as $path) {
152
+				$path = $path.$config.'.lib.php';
153
+				if ( ! is_readable($path)) {
154 154
 					continue;
155 155
 				} else {
156 156
 					require_once $path;
@@ -159,26 +159,26 @@  discard block
 block discarded – undo
159 159
 		}
160 160
 
161 161
 		//does class exist at this point?  If it does then let's instantiate.  If it doesn't then let's continue with other paths.
162
-		if ( !class_exists($config) ) {
163
-			$path = EE_LIBRARIES . 'qtips/' . $config . '.lib.php';
164
-			if ( !is_readable($path ) ) {
165
-				throw new EE_Error( sprintf( __('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable.  Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config ) );
162
+		if ( ! class_exists($config)) {
163
+			$path = EE_LIBRARIES.'qtips/'.$config.'.lib.php';
164
+			if ( ! is_readable($path)) {
165
+				throw new EE_Error(sprintf(__('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable.  Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config));
166 166
 			} else {
167 167
 				require_once $path;
168 168
 			}
169 169
 		}
170 170
 
171 171
 		//now we attempt a class_exists one more time.
172
-		if ( !class_exists( $config ) )
173
-			throw new EE_Error( sprintf( __('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config ) );
172
+		if ( ! class_exists($config))
173
+			throw new EE_Error(sprintf(__('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config));
174 174
 
175 175
 		//made it HERE?  FINALLY, let's get things setup.
176 176
 		$a = new ReflectionClass($config);
177 177
 		$qtip = $a->newInstance();
178 178
 
179 179
 		//verify that $qtip is a valid object
180
-		if ( ! $qtip instanceof EE_Qtip_Config )
181
-			throw new EE_Error( sprintf( esc_html__( 'The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>' ) );
180
+		if ( ! $qtip instanceof EE_Qtip_Config)
181
+			throw new EE_Error(sprintf(esc_html__('The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>'));
182 182
 
183 183
 		$this->_qtips[] = $a->newInstance();
184 184
 
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 	 * @return void
195 195
 	 */
196 196
 	public function setup_qtip() {
197
-		if ( empty( $this->_qtips ) )
197
+		if (empty($this->_qtips))
198 198
 			return; //no qtips!
199 199
 
200 200
 		$content = array();
201 201
 
202
-		foreach ( $this->_qtips as $qtip ) {
202
+		foreach ($this->_qtips as $qtip) {
203 203
 			$content[] = $this->_generate_content_container($qtip);
204 204
 		}
205 205
 
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
 	private function _generate_content_container($qtip) {
217 217
 		$qts = $qtip->get_tips();
218 218
 		$content = array();
219
-		foreach ( $qts as $qt ) {
220
-			if ( ! $qt instanceof EE_Qtip )
219
+		foreach ($qts as $qt) {
220
+			if ( ! $qt instanceof EE_Qtip)
221 221
 				continue;
222
-			$content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>';
222
+			$content[] = '<div class="ee-qtip-helper-content hidden" id="'.$qt->content_id.'">'.$qt->content.'</div>';
223 223
 		}
224 224
 
225 225
 		return implode('<br />', $content);
Please login to merge, or discard this patch.
core/domain/DomainInterface.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -15,49 +15,49 @@
 block discarded – undo
15 15
 interface DomainInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @return string
20
-     * @throws DomainException
21
-     */
22
-    public function pluginFile();
18
+	/**
19
+	 * @return string
20
+	 * @throws DomainException
21
+	 */
22
+	public function pluginFile();
23 23
 
24 24
 
25
-    /**
26
-     * @return string
27
-     * @throws DomainException
28
-     */
29
-    public function pluginBasename();
25
+	/**
26
+	 * @return string
27
+	 * @throws DomainException
28
+	 */
29
+	public function pluginBasename();
30 30
 
31 31
 
32
-    /**
33
-     * @return string
34
-     */
35
-    public function pluginPath();
32
+	/**
33
+	 * @return string
34
+	 */
35
+	public function pluginPath();
36 36
 
37 37
 
38
-    /**
39
-     * @return string
40
-     * @throws DomainException
41
-     */
42
-    public function pluginUrl();
38
+	/**
39
+	 * @return string
40
+	 * @throws DomainException
41
+	 */
42
+	public function pluginUrl();
43 43
 
44 44
 
45
-    /**
46
-     * @return string
47
-     * @throws DomainException
48
-     */
49
-    public function version();
45
+	/**
46
+	 * @return string
47
+	 * @throws DomainException
48
+	 */
49
+	public function version();
50 50
 
51 51
 
52
-    /**
53
-     * @return string
54
-     */
55
-    public function distributionAssetsPath();
52
+	/**
53
+	 * @return string
54
+	 */
55
+	public function distributionAssetsPath();
56 56
 
57 57
 
58
-    /**
59
-     * @return string
60
-     */
61
-    public function distributionAssetsUrl();
58
+	/**
59
+	 * @return string
60
+	 */
61
+	public function distributionAssetsUrl();
62 62
 
63 63
 }
Please login to merge, or discard this patch.
core/domain/entities/editor/blocks/TicketSelector.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -20,81 +20,81 @@
 block discarded – undo
20 20
 class TicketSelector extends EditorBlock
21 21
 {
22 22
 
23
-    const EDITOR_BLOCK_TYPE = 'ee-event-editor/ticket-editor-container';
24
-
25
-
26
-    /**
27
-     * Perform any early setup required by the block
28
-     * including setting the block type and supported post types
29
-     *
30
-     * @return void
31
-     */
32
-    public function initialize()
33
-    {
34
-        $this->setEditorBlockType(TicketSelector::EDITOR_BLOCK_TYPE);
35
-        $this->setSupportedPostTypes(array('espresso_events'));
36
-    }
37
-
38
-
39
-    /**
40
-     * Registers the Editor Block with WP core;
41
-     * Returns the registered block type on success, or false on failure.
42
-     *
43
-     * @return WP_Block_Type|false
44
-     */
45
-    public function registerBlock()
46
-    {
47
-        $wp_block_type = register_block_type(
48
-            new WP_Block_Type(
49
-                $this->editorBlockType(),
50
-                array(
51
-                    'editor_script' => 'ee-event-editor-blocks',
52
-                    'editor_style'  => 'ee-block-styles',
53
-                    'attributes'    => array(),
54
-                )
55
-            )
56
-        );
57
-        $this->setWpBlockType($wp_block_type);
58
-        return $wp_block_type;
59
-    }
60
-
61
-
62
-    /**
63
-     * @return array
64
-     */
65
-    public function getEditorContainer()
66
-    {
67
-        return array(
68
-            $this->editorBlockType(),
69
-            array()
70
-        );
71
-    }
72
-
73
-
74
-    /**
75
-     * @return  void
76
-     */
77
-    public function registerScripts()
78
-    {
79
-    }
80
-
81
-
82
-    /**
83
-     * @return void
84
-     */
85
-    public function registerStyles()
86
-    {
87
-    }
88
-
89
-
90
-    /**
91
-     * returns the rendered HTML for the block
92
-     *
93
-     * @param array $attributes
94
-     * @return string
95
-     */
96
-    public function renderBlock(array $attributes = array())
97
-    {
98
-        return '';
99
-    }
23
+	const EDITOR_BLOCK_TYPE = 'ee-event-editor/ticket-editor-container';
24
+
25
+
26
+	/**
27
+	 * Perform any early setup required by the block
28
+	 * including setting the block type and supported post types
29
+	 *
30
+	 * @return void
31
+	 */
32
+	public function initialize()
33
+	{
34
+		$this->setEditorBlockType(TicketSelector::EDITOR_BLOCK_TYPE);
35
+		$this->setSupportedPostTypes(array('espresso_events'));
36
+	}
37
+
38
+
39
+	/**
40
+	 * Registers the Editor Block with WP core;
41
+	 * Returns the registered block type on success, or false on failure.
42
+	 *
43
+	 * @return WP_Block_Type|false
44
+	 */
45
+	public function registerBlock()
46
+	{
47
+		$wp_block_type = register_block_type(
48
+			new WP_Block_Type(
49
+				$this->editorBlockType(),
50
+				array(
51
+					'editor_script' => 'ee-event-editor-blocks',
52
+					'editor_style'  => 'ee-block-styles',
53
+					'attributes'    => array(),
54
+				)
55
+			)
56
+		);
57
+		$this->setWpBlockType($wp_block_type);
58
+		return $wp_block_type;
59
+	}
60
+
61
+
62
+	/**
63
+	 * @return array
64
+	 */
65
+	public function getEditorContainer()
66
+	{
67
+		return array(
68
+			$this->editorBlockType(),
69
+			array()
70
+		);
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return  void
76
+	 */
77
+	public function registerScripts()
78
+	{
79
+	}
80
+
81
+
82
+	/**
83
+	 * @return void
84
+	 */
85
+	public function registerStyles()
86
+	{
87
+	}
88
+
89
+
90
+	/**
91
+	 * returns the rendered HTML for the block
92
+	 *
93
+	 * @param array $attributes
94
+	 * @return string
95
+	 */
96
+	public function renderBlock(array $attributes = array())
97
+	{
98
+		return '';
99
+	}
100 100
 }
Please login to merge, or discard this patch.