Completed
Branch BUG-10738-inconsistency-in-ses... (860590)
by
unknown
45:05 queued 33:37
created
core/EE_Deprecated.core.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -1047,11 +1047,11 @@  discard block
 block discarded – undo
1047 1047
 			'filter'
1048 1048
 		);
1049 1049
 		return apply_filters(
1050
-            'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1051
-            $existing_attendee, $registration, $attendee_data
1052
-        );
1050
+			'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1051
+			$existing_attendee, $registration, $attendee_data
1052
+		);
1053 1053
 	},
1054
-    10,3
1054
+	10,3
1055 1055
 );
1056 1056
 
1057 1057
 
@@ -1064,88 +1064,88 @@  discard block
 block discarded – undo
1064 1064
 class EE_Event_List_Query extends WP_Query
1065 1065
 {
1066 1066
 
1067
-    private $title;
1068
-
1069
-    private $css_class;
1070
-
1071
-    private $category_slug;
1072
-
1073
-    /**
1074
-     * EE_Event_List_Query constructor.
1075
-     *
1076
-     * @param array $args
1077
-     */
1078
-    public function __construct($args = array())
1079
-    {
1080
-        \EE_Error::doing_it_wrong(
1081
-            __METHOD__,
1082
-            __(
1083
-                'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1084
-                'event_espresso'
1085
-            ),
1086
-            '4.9.27',
1087
-            '5.0.0'
1088
-        );
1089
-        $this->title = isset($args['title']) ? $args['title'] : '';
1090
-        $this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1091
-        $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1092
-        $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1093
-        // the current "page" we are viewing
1094
-        $paged = max(1, get_query_var('paged'));
1095
-        // Force these args
1096
-        $args = array_merge(
1097
-            $args, array(
1098
-            'post_type'              => 'espresso_events',
1099
-            'posts_per_page'         => $limit,
1100
-            'update_post_term_cache' => false,
1101
-            'update_post_meta_cache' => false,
1102
-            'paged'                  => $paged,
1103
-            'offset'                 => ($paged - 1) * $limit
1104
-        )
1105
-        );
1106
-        // run the query
1107
-        parent::__construct($args);
1108
-    }
1109
-
1110
-
1111
-
1112
-    /**
1113
-     * event_list_title
1114
-     *
1115
-     * @param string $event_list_title
1116
-     * @return string
1117
-     */
1118
-    public function event_list_title($event_list_title = '')
1119
-    {
1120
-        if (! empty($this->title)) {
1121
-            return $this->title;
1122
-        }
1123
-        return $event_list_title;
1124
-    }
1125
-
1126
-
1127
-
1128
-    /**
1129
-     * event_list_css
1130
-     *
1131
-     * @param string $event_list_css
1132
-     * @return string
1133
-     */
1134
-    public function event_list_css($event_list_css = '')
1135
-    {
1136
-        $event_list_css .= ! empty($event_list_css)
1137
-            ? ' '
1138
-            : '';
1139
-        $event_list_css .= ! empty($this->css_class)
1140
-            ? $this->css_class
1141
-            : '';
1142
-        $event_list_css .= ! empty($event_list_css)
1143
-            ? ' '
1144
-            : '';
1145
-        $event_list_css .= ! empty($this->category_slug)
1146
-            ? $this->category_slug
1147
-            : '';
1148
-        return $event_list_css;
1149
-    }
1067
+	private $title;
1068
+
1069
+	private $css_class;
1070
+
1071
+	private $category_slug;
1072
+
1073
+	/**
1074
+	 * EE_Event_List_Query constructor.
1075
+	 *
1076
+	 * @param array $args
1077
+	 */
1078
+	public function __construct($args = array())
1079
+	{
1080
+		\EE_Error::doing_it_wrong(
1081
+			__METHOD__,
1082
+			__(
1083
+				'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1084
+				'event_espresso'
1085
+			),
1086
+			'4.9.27',
1087
+			'5.0.0'
1088
+		);
1089
+		$this->title = isset($args['title']) ? $args['title'] : '';
1090
+		$this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1091
+		$this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1092
+		$limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1093
+		// the current "page" we are viewing
1094
+		$paged = max(1, get_query_var('paged'));
1095
+		// Force these args
1096
+		$args = array_merge(
1097
+			$args, array(
1098
+			'post_type'              => 'espresso_events',
1099
+			'posts_per_page'         => $limit,
1100
+			'update_post_term_cache' => false,
1101
+			'update_post_meta_cache' => false,
1102
+			'paged'                  => $paged,
1103
+			'offset'                 => ($paged - 1) * $limit
1104
+		)
1105
+		);
1106
+		// run the query
1107
+		parent::__construct($args);
1108
+	}
1109
+
1110
+
1111
+
1112
+	/**
1113
+	 * event_list_title
1114
+	 *
1115
+	 * @param string $event_list_title
1116
+	 * @return string
1117
+	 */
1118
+	public function event_list_title($event_list_title = '')
1119
+	{
1120
+		if (! empty($this->title)) {
1121
+			return $this->title;
1122
+		}
1123
+		return $event_list_title;
1124
+	}
1125
+
1126
+
1127
+
1128
+	/**
1129
+	 * event_list_css
1130
+	 *
1131
+	 * @param string $event_list_css
1132
+	 * @return string
1133
+	 */
1134
+	public function event_list_css($event_list_css = '')
1135
+	{
1136
+		$event_list_css .= ! empty($event_list_css)
1137
+			? ' '
1138
+			: '';
1139
+		$event_list_css .= ! empty($this->css_class)
1140
+			? $this->css_class
1141
+			: '';
1142
+		$event_list_css .= ! empty($event_list_css)
1143
+			? ' '
1144
+			: '';
1145
+		$event_list_css .= ! empty($this->category_slug)
1146
+			? $this->category_slug
1147
+			: '';
1148
+		return $event_list_css;
1149
+	}
1150 1150
 
1151 1151
 }
Please login to merge, or discard this patch.
Spacing   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 /**
6 6
  * ************************************************************************
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	$action_or_filter = 'action'
44 44
 ) {
45 45
 	$action_or_filter = $action_or_filter === 'action'
46
-		? esc_html__( 'action', 'event_espresso' )
47
-		: esc_html__( 'filter', 'event_espresso' );
46
+		? esc_html__('action', 'event_espresso')
47
+		: esc_html__('filter', 'event_espresso');
48 48
 	EE_Error::doing_it_wrong(
49 49
 		$deprecated_filter,
50 50
 		sprintf(
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
  * @param \EE_Checkout $checkout
69 69
  * @return string
70 70
  */
71
-function ee_deprecated__registration_checkout__button_text( $submit_button_text, EE_Checkout $checkout ) {
71
+function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) {
72 72
 	// list of old filters
73 73
 	$deprecated_filters = array(
74 74
 		'update_registration_details' => true,
@@ -78,16 +78,16 @@  discard block
 block discarded – undo
78 78
 		'proceed_to' => true,
79 79
 	);
80 80
 	// loop thru and call doing_it_wrong() or remove any that aren't being used
81
-	foreach ( $deprecated_filters as $deprecated_filter => $on ) {
81
+	foreach ($deprecated_filters as $deprecated_filter => $on) {
82 82
 		// was this filter called ?
83
-		if ( has_action( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter )) {
83
+		if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) {
84 84
 			// only display doing_it_wrong() notice to Event Admins during non-AJAX requests
85
-			if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter' ) && ! defined( 'DOING_AJAX' ) ) {
85
+			if (EE_Registry::instance()->CAP->current_user_can('ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter') && ! defined('DOING_AJAX')) {
86 86
 				EE_Error::doing_it_wrong(
87
-					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
87
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
88 88
 					sprintf(
89
-						__( 'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso' ),
90
-						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
89
+						__('The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso'),
90
+						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
91 91
 						'<br />',
92 92
 						'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
93 93
 						'/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
@@ -96,24 +96,24 @@  discard block
 block discarded – undo
96 96
 				);
97 97
 			}
98 98
 		} else {
99
-			unset( $deprecated_filters[ $deprecated_filter ] );
99
+			unset($deprecated_filters[$deprecated_filter]);
100 100
 		}
101 101
 	}
102
-	if ( ! empty( $deprecated_filters )) {
103
-
104
-		if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset( $deprecated_filters[ 'update_registration_details' ] )) {
105
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text );
106
-		} else if ( $checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset( $deprecated_filters[ 'process_payment' ] ) ) {
107
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text );
108
-		} else if ( $checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset( $deprecated_filters[ 'finalize_registration' ] ) ) {
109
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text );
102
+	if ( ! empty($deprecated_filters)) {
103
+
104
+		if ($checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
105
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text);
106
+		} else if ($checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
107
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text);
108
+		} else if ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
109
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text);
110 110
 		}
111
-		if ( $checkout->next_step instanceof EE_SPCO_Reg_Step ) {
112
-			if ( $checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset( $deprecated_filters[ 'and_proceed_to_payment' ] ) ) {
113
-				$submit_button_text .= apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text );
111
+		if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
112
+			if ($checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
113
+				$submit_button_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text);
114 114
 			}
115
-			if ( $checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset( $deprecated_filters[ 'proceed_to' ] ) ) {
116
-				$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text ) . $checkout->next_step->name();
115
+			if ($checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
116
+				$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text).$checkout->next_step->name();
117 117
 			}
118 118
 		}
119 119
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	return $submit_button_text;
122 122
 
123 123
 }
124
-add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2 );
124
+add_filter('FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2);
125 125
 
126 126
 
127 127
 
@@ -132,16 +132,16 @@  discard block
 block discarded – undo
132 132
  * @param \EE_Checkout $checkout
133 133
  * @param boolean $status_updates
134 134
  */
135
-function ee_deprecated_finalize_transaction( EE_Checkout $checkout, $status_updates ) {
135
+function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) {
136 136
 	$action_ref = NULL;
137
-	$action_ref = has_action( 'AHEE__EE_Transaction__finalize__new_transaction' ) ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
138
-	$action_ref = has_action( 'AHEE__EE_Transaction__finalize__all_transaction' ) ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
139
-	if ( $action_ref ) {
137
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
138
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
139
+	if ($action_ref) {
140 140
 
141 141
 		EE_Error::doing_it_wrong(
142 142
 			$action_ref,
143 143
 			sprintf(
144
-				__( 'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso' ),
144
+				__('This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso'),
145 145
 				'<br />',
146 146
 				'/core/business/EE_Transaction_Processor.class.php',
147 147
 				'AHEE__EE_Transaction_Processor__finalize',
@@ -151,39 +151,39 @@  discard block
 block discarded – undo
151 151
 			),
152 152
 			'4.6.0'
153 153
 		);
154
-		switch ( $action_ref ) {
154
+		switch ($action_ref) {
155 155
 			case 'AHEE__EE_Transaction__finalize__new_transaction' :
156
-				do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request );
156
+				do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request);
157 157
 				break;
158 158
 			case 'AHEE__EE_Transaction__finalize__all_transaction' :
159
-				do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array( 'new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates ), $checkout->admin_request );
159
+				do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), $checkout->admin_request);
160 160
 				break;
161 161
 		}
162 162
 	}
163 163
 }
164
-add_action( 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2 );
164
+add_action('AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2);
165 165
 /**
166 166
  * ee_deprecated_finalize_registration
167 167
  *
168 168
  * @param EE_Registration $registration
169 169
  */
170
-function ee_deprecated_finalize_registration( EE_Registration $registration ) {
171
-	$action_ref = has_action( 'AHEE__EE_Registration__finalize__update_and_new_reg' ) ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL;
172
-	if ( $action_ref ) {
170
+function ee_deprecated_finalize_registration(EE_Registration $registration) {
171
+	$action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL;
172
+	if ($action_ref) {
173 173
 		EE_Error::doing_it_wrong(
174 174
 			$action_ref,
175 175
 			sprintf(
176
-				__( 'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso' ),
176
+				__('This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso'),
177 177
 				'<br />',
178 178
 				'/core/business/EE_Registration_Processor.class.php',
179 179
 				'AHEE__EE_Registration_Processor__trigger_registration_status_changed_hook'
180 180
 			),
181 181
 			'4.6.0'
182 182
 		);
183
-		do_action( 'AHEE__EE_Registration__finalize__update_and_new_reg', $registration, ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )));
183
+		do_action('AHEE__EE_Registration__finalize__update_and_new_reg', $registration, (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)));
184 184
 	}
185 185
 }
186
-add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1 );
186
+add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1);
187 187
 
188 188
 
189 189
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
  * Called after EED_Module::set_hooks() and EED_Module::set_admin_hooks() was called.
192 192
  * Checks if any deprecated hooks were hooked-into and provide doing_it_wrong messages appropriately.
193 193
  */
194
-function ee_deprecated_hooks(){
194
+function ee_deprecated_hooks() {
195 195
 	/**
196 196
 	 * @var $hooks array where keys are hook names, and their values are array{
197 197
 	 *			@type string $version  when deprecated
@@ -202,25 +202,25 @@  discard block
 block discarded – undo
202 202
 	$hooks = array(
203 203
 		'AHEE__EE_System___do_setup_validations' => array(
204 204
 			'version' => '4.6.0',
205
-			'alternative' => __( 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso' ),
205
+			'alternative' => __('Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso'),
206 206
 			'still_works' => FALSE
207 207
 		)
208 208
 	);
209
-	foreach( $hooks as $name => $deprecation_info ){
210
-		if( has_action( $name ) ){
209
+	foreach ($hooks as $name => $deprecation_info) {
210
+		if (has_action($name)) {
211 211
 			EE_Error::doing_it_wrong(
212 212
 				$name,
213 213
 				sprintf(
214
-					__('This filter is deprecated. %1$s%2$s','event_espresso'),
215
-					$deprecation_info[ 'still_works' ] ?  __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __( 'It has been completely removed.', 'event_espresso' ),
216
-					isset( $deprecation_info[ 'alternative' ] ) ? $deprecation_info[ 'alternative' ] : __( 'Please read the current EE4 documentation further or contact Support.', 'event_espresso' )
214
+					__('This filter is deprecated. %1$s%2$s', 'event_espresso'),
215
+					$deprecation_info['still_works'] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __('It has been completely removed.', 'event_espresso'),
216
+					isset($deprecation_info['alternative']) ? $deprecation_info['alternative'] : __('Please read the current EE4 documentation further or contact Support.', 'event_espresso')
217 217
 				),
218
-				isset( $deprecation_info[ 'version' ] ) ? $deprecation_info[ 'version' ] : __( 'recently', 'event_espresso' )
218
+				isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso')
219 219
 			);
220 220
 		}
221 221
 	}
222 222
 }
223
-add_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks' );
223
+add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks');
224 224
 
225 225
 
226 226
 
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
  * @return boolean
232 232
  */
233 233
 function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() {
234
-	$in_use =  has_filter( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns' )
235
-			|| has_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' );
236
-	if( $in_use ) {
234
+	$in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
235
+			|| has_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save');
236
+	if ($in_use) {
237 237
 		$msg = __(
238 238
 			'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
239 239
 			. 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
@@ -242,18 +242,18 @@  discard block
 block discarded – undo
242 242
 			'event_espresso' )
243 243
 		;
244 244
 		EE_Error::doing_it_wrong(
245
-			__CLASS__ . '::' . __FUNCTION__,
245
+			__CLASS__.'::'.__FUNCTION__,
246 246
 			$msg,
247 247
 			'4.8.32.rc.000'
248 248
 		);
249 249
 		//it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
250
-		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
251
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
250
+		if (is_admin() && ! defined('DOING_AJAX')) {
251
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
252 252
 		}
253 253
 	}
254 254
 	return $in_use;
255 255
 }
256
-add_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' );
256
+add_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks');
257 257
 
258 258
 /**
259 259
  * @deprecated since 4.8.32.rc.000 because it has issues on https://events.codebasehq.com/projects/event-espresso/tickets/9165
@@ -262,34 +262,34 @@  discard block
 block discarded – undo
262 262
  * @param EE_Admin_Page $admin_page
263 263
  * @return void
264 264
  */
265
-function ee_deprecated_update_attendee_registration_form_old( $admin_page ) {
265
+function ee_deprecated_update_attendee_registration_form_old($admin_page) {
266 266
 	//check if the old hooks are in use. If not, do the default
267
-	if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
268
-		|| ! $admin_page instanceof EE_Admin_Page ) {
267
+	if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
268
+		|| ! $admin_page instanceof EE_Admin_Page) {
269 269
 		return;
270 270
 	}
271 271
 	$req_data = $admin_page->get_request_data();
272
-	$qstns = isset( $req_data['qstn'] ) ? $req_data['qstn'] : FALSE;
273
-	$REG_ID = isset( $req_data['_REG_ID'] ) ? absint( $req_data['_REG_ID'] ) : FALSE;
274
-	$qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns );
275
-	if ( ! $REG_ID || ! $qstns ) {
276
-		EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
272
+	$qstns = isset($req_data['qstn']) ? $req_data['qstn'] : FALSE;
273
+	$REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : FALSE;
274
+	$qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
275
+	if ( ! $REG_ID || ! $qstns) {
276
+		EE_Error::add_error(__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
277 277
 	}
278 278
 	$success = TRUE;
279 279
 
280 280
 	// allow others to get in on this awesome fun   :D
281
-	do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns );
281
+	do_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns);
282 282
 	// loop thru questions... FINALLY!!!
283 283
 
284
-	foreach ( $qstns as $QST_ID => $qstn ) {
284
+	foreach ($qstns as $QST_ID => $qstn) {
285 285
 		//if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
286
-		if ( !is_array($qstn) ) {
287
-			$success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn);
286
+		if ( ! is_array($qstn)) {
287
+			$success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn);
288 288
 			continue;
289 289
 		}
290 290
 
291 291
 
292
-		foreach ( $qstn as $ANS_ID => $ANS_value ) {
292
+		foreach ($qstn as $ANS_ID => $ANS_value) {
293 293
 			//get answer
294 294
 			$query_params = array(
295 295
 				0 => array(
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 				);
301 301
 			$answer = EEM_Answer::instance()->get_one($query_params);
302 302
 			//this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
303
-			if ( ! $answer instanceof EE_Answer ) {
303
+			if ( ! $answer instanceof EE_Answer) {
304 304
 				$set_values = array(
305 305
 					'QST_ID' => $QST_ID,
306 306
 					'REG_ID' => $REG_ID,
@@ -315,11 +315,11 @@  discard block
 block discarded – undo
315 315
 		}
316 316
 	}
317 317
 	$what = __('Registration Form', 'event_espresso');
318
-	$route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' );
319
-	$admin_page->redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route );
318
+	$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
319
+	$admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
320 320
 	exit;
321 321
 }
322
-add_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1 );
322
+add_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1);
323 323
 /**
324 324
  * Render the registration admin page's custom questions area in the old fashion
325 325
  * and firing the old hooks. When this method is removed, we can probably also
@@ -332,31 +332,31 @@  discard block
 block discarded – undo
332 332
  * @return bool
333 333
  * @throws \EE_Error
334 334
  */
335
-function ee_deprecated_reg_questions_meta_box_old( $do_default_action, $admin_page, $registration ) {
335
+function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) {
336 336
 	//check if the old hooks are in use. If not, do the default
337
-	if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
338
-		|| ! $admin_page instanceof EE_Admin_Page ) {
337
+	if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
338
+		|| ! $admin_page instanceof EE_Admin_Page) {
339 339
 		return $do_default_action;
340 340
 	}
341
-	add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $admin_page, 'form_before_question_group' ), 10, 1 );
342
-	add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $admin_page, 'form_after_question_group' ), 10, 1 );
343
-	add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $admin_page, 'form_form_field_label_wrap' ), 10, 1 );
344
-	add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $admin_page, 'form_form_field_input__wrap' ), 10, 1 );
341
+	add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array($admin_page, 'form_before_question_group'), 10, 1);
342
+	add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array($admin_page, 'form_after_question_group'), 10, 1);
343
+	add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
344
+	add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
345 345
 
346
-	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $registration, $registration->get('EVT_ID') );
346
+	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options($registration, $registration->get('EVT_ID'));
347 347
 
348
-	EE_Registry::instance()->load_helper( 'Form_Fields' );
348
+	EE_Registry::instance()->load_helper('Form_Fields');
349 349
 	$template_args = array(
350
-		'att_questions' => EEH_Form_Fields::generate_question_groups_html( $question_groups ),
350
+		'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups),
351 351
 		'reg_questions_form_action' => 'edit_registration',
352 352
 		'REG_ID' => $registration->ID()
353 353
 	);
354
-	$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
355
-	echo EEH_Template::display_template( $template_path, $template_args, TRUE );
354
+	$template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
355
+	echo EEH_Template::display_template($template_path, $template_args, TRUE);
356 356
 	//indicate that we should not do the default admin page code
357 357
 	return false;
358 358
 }
359
-add_action( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3 );
359
+add_action('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3);
360 360
 
361 361
 
362 362
 
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 			'4.9.0'
398 398
 		);
399 399
 		/** @var EE_Message_Resource_Manager $message_resource_manager */
400
-		$message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
401
-		$messenger = $message_resource_manager->get_messenger( $messenger_name );
402
-		$message_type = $message_resource_manager->get_message_type( $message_type_name );
400
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
401
+		$messenger = $message_resource_manager->get_messenger($messenger_name);
402
+		$message_type = $message_resource_manager->get_message_type($message_type_name);
403 403
 		return EE_Registry::instance()->load_lib(
404 404
 			'Messages_Template_Defaults',
405 405
 			array(
@@ -464,15 +464,15 @@  discard block
 block discarded – undo
464 464
 	/**
465 465
 	 * @param string $method
466 466
 	 */
467
-	public function _class_is_deprecated( $method ) {
467
+	public function _class_is_deprecated($method) {
468 468
 		EE_Error::doing_it_wrong(
469
-			'EE_messages::' . $method,
470
-			__( 'EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.' ),
469
+			'EE_messages::'.$method,
470
+			__('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
471 471
 			'4.9.0',
472 472
 			'4.10.0.p'
473 473
 		);
474 474
 		// Please use EE_Message_Resource_Manager instead
475
-		$this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
475
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
476 476
 	}
477 477
 
478 478
 
@@ -482,10 +482,10 @@  discard block
 block discarded – undo
482 482
 	 * @param string $messenger_name
483 483
 	 * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
484 484
 	 */
485
-	public function ensure_messenger_is_active( $messenger_name ) {
485
+	public function ensure_messenger_is_active($messenger_name) {
486 486
 		// EE_messages has been deprecated
487
-		$this->_class_is_deprecated( __FUNCTION__ );
488
-		return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name );
487
+		$this->_class_is_deprecated(__FUNCTION__);
488
+		return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
489 489
 	}
490 490
 
491 491
 
@@ -497,10 +497,10 @@  discard block
 block discarded – undo
497 497
 	 * @return bool true if it got activated (or was active) and false if not.
498 498
 	 * @throws \EE_Error
499 499
 	 */
500
-	public function ensure_message_type_is_active( $message_type, $messenger ) {
500
+	public function ensure_message_type_is_active($message_type, $messenger) {
501 501
 		// EE_messages has been deprecated
502
-		$this->_class_is_deprecated( __FUNCTION__ );
503
-		return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger );
502
+		$this->_class_is_deprecated(__FUNCTION__);
503
+		return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
504 504
 	}
505 505
 
506 506
 
@@ -513,10 +513,10 @@  discard block
 block discarded – undo
513 513
 	 *                                            they are already setup.)
514 514
 	 * @return boolean an array of generated templates or false if nothing generated/activated.
515 515
 	 */
516
-	public function activate_messenger( $messenger_name, $mts_to_activate = array() ) {
516
+	public function activate_messenger($messenger_name, $mts_to_activate = array()) {
517 517
 		// EE_messages has been deprecated
518
-		$this->_class_is_deprecated( __FUNCTION__ );
519
-		return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate );
518
+		$this->_class_is_deprecated(__FUNCTION__);
519
+		return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
520 520
 	}
521 521
 
522 522
 
@@ -528,10 +528,10 @@  discard block
 block discarded – undo
528 528
 	 *
529 529
 	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
530 530
 	 */
531
-	public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) {
531
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) {
532 532
 		// EE_messages has been deprecated
533
-		$this->_class_is_deprecated( __FUNCTION__ );
534
-		return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type );
533
+		$this->_class_is_deprecated(__FUNCTION__);
534
+		return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
535 535
 	}
536 536
 
537 537
 
@@ -541,10 +541,10 @@  discard block
 block discarded – undo
541 541
 	 * @param string $messenger
542 542
 	 * @return EE_messenger | null
543 543
 	 */
544
-	public function get_messenger_if_active( $messenger ) {
544
+	public function get_messenger_if_active($messenger) {
545 545
 		// EE_messages has been deprecated
546
-		$this->_class_is_deprecated( __FUNCTION__ );
547
-		return $this->_message_resource_manager->get_active_messenger( $messenger );
546
+		$this->_class_is_deprecated(__FUNCTION__);
547
+		return $this->_message_resource_manager->get_active_messenger($messenger);
548 548
 	}
549 549
 
550 550
 
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
 	 *                  'message_type' => null
566 566
 	 *                  )
567 567
 	 */
568
-	public function validate_for_use( EE_Message $message ) {
568
+	public function validate_for_use(EE_Message $message) {
569 569
 		// EE_messages has been deprecated
570
-		$this->_class_is_deprecated( __FUNCTION__ );
570
+		$this->_class_is_deprecated(__FUNCTION__);
571 571
 		return array(
572 572
 			'messenger'    => $message->messenger_object(),
573 573
 			'message_type' => $message->message_type_object(),
@@ -595,41 +595,41 @@  discard block
 block discarded – undo
595 595
 		$send = true
596 596
 	) {
597 597
 		// EE_messages has been deprecated
598
-		$this->_class_is_deprecated( __FUNCTION__ );
598
+		$this->_class_is_deprecated(__FUNCTION__);
599 599
 		/** @type EE_Messages_Processor $processor */
600
-		$processor = EE_Registry::instance()->load_lib( 'Messages_Processor' );
600
+		$processor = EE_Registry::instance()->load_lib('Messages_Processor');
601 601
 		$error = false;
602 602
 		//try to intelligently determine what method we'll call based on the incoming data.
603 603
 		//if generating and sending are different then generate and send immediately.
604
-		if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) {
604
+		if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
605 605
 			//in the legacy system, when generating and sending were different, that means all the
606 606
 			//vars are already in the request object.  So let's just use that.
607 607
 			try {
608 608
 				/** @type EE_Message_To_Generate_From_Request $mtg */
609
-				$mtg = EE_Registry::instance()->load_lib( 'Message_To_Generate_From_Request' );
610
-				$processor->generate_and_send_now( $mtg );
611
-			} catch ( EE_Error $e ) {
609
+				$mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
610
+				$processor->generate_and_send_now($mtg);
611
+			} catch (EE_Error $e) {
612 612
 				$error_msg = __(
613 613
 					'Please note that a system message failed to send due to a technical issue.',
614 614
 					'event_espresso'
615 615
 				);
616 616
 				// add specific message for developers if WP_DEBUG in on
617
-				$error_msg .= '||' . $e->getMessage();
618
-				EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
617
+				$error_msg .= '||'.$e->getMessage();
618
+				EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
619 619
 				$error = true;
620 620
 			}
621 621
 		} else {
622
-			$processor->generate_for_all_active_messengers( $type, $vars, $send );
622
+			$processor->generate_for_all_active_messengers($type, $vars, $send);
623 623
 			//let's find out if there were any errors and how many successfully were queued.
624 624
 			$count_errors = $processor->get_queue()->count_STS_in_queue(
625
-				array( EEM_Message::status_failed, EEM_Message::status_debug_only )
625
+				array(EEM_Message::status_failed, EEM_Message::status_debug_only)
626 626
 			);
627
-			$count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete );
628
-			$count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry );
627
+			$count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
628
+			$count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
629 629
 			$count_errors = $count_errors + $count_retry;
630
-			if ( $count_errors > 0 ) {
630
+			if ($count_errors > 0) {
631 631
 				$error = true;
632
-				if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1 ) {
632
+				if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
633 633
 					$message = sprintf(
634 634
 						__(
635 635
 							'There were %d errors and %d messages successfully queued for generation and sending',
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 						$count_errors,
639 639
 						$count_queued
640 640
 					);
641
-				} elseif ( $count_errors > 1 && $count_queued === 1 ) {
641
+				} elseif ($count_errors > 1 && $count_queued === 1) {
642 642
 					$message = sprintf(
643 643
 						__(
644 644
 							'There were %d errors and %d message successfully queued for generation.',
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 						$count_errors,
648 648
 						$count_queued
649 649
 					);
650
-				} elseif ( $count_errors === 1 && $count_queued > 1 ) {
650
+				} elseif ($count_errors === 1 && $count_queued > 1) {
651 651
 					$message = sprintf(
652 652
 						__(
653 653
 							'There was %d error and %d messages successfully queued for generation.',
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
 						$count_errors
666 666
 					);
667 667
 				}
668
-				EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ );
668
+				EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
669 669
 			} else {
670
-				if ( $count_queued === 1 ) {
670
+				if ($count_queued === 1) {
671 671
 					$message = sprintf(
672 672
 						__(
673 673
 							'%d message successfully queued for generation.',
@@ -684,18 +684,18 @@  discard block
 block discarded – undo
684 684
 						$count_queued
685 685
 					);
686 686
 				}
687
-				EE_Error::add_success( $message );
687
+				EE_Error::add_success($message);
688 688
 			}
689 689
 		}
690 690
 		//if no error then return the generated message(s).
691
-		if ( ! $error && ! $send ) {
692
-			$generated_queue = $processor->generate_queue( false );
691
+		if ( ! $error && ! $send) {
692
+			$generated_queue = $processor->generate_queue(false);
693 693
 			//get message and return.
694 694
 			$generated_queue->get_message_repository()->rewind();
695 695
 			$messages = array();
696
-			while ( $generated_queue->get_message_repository()->valid() ) {
696
+			while ($generated_queue->get_message_repository()->valid()) {
697 697
 				$message = $generated_queue->get_message_repository()->current();
698
-				if ( $message instanceof EE_Message ) {
698
+				if ($message instanceof EE_Message) {
699 699
 					//set properties that might be expected by add-ons (backward compat)
700 700
 					$message->content = $message->content();
701 701
 					$message->template_pack = $message->get_template_pack();
@@ -720,10 +720,10 @@  discard block
 block discarded – undo
720 720
 	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular preview
721 721
 	 * @return string          The body of the message.
722 722
 	 */
723
-	public function preview_message( $type, $context, $messenger, $send = false ) {
723
+	public function preview_message($type, $context, $messenger, $send = false) {
724 724
 		// EE_messages has been deprecated
725
-		$this->_class_is_deprecated( __FUNCTION__ );
726
-		return EED_Messages::preview_message( $type, $context, $messenger, $send );
725
+		$this->_class_is_deprecated(__FUNCTION__);
726
+		return EED_Messages::preview_message($type, $context, $messenger, $send);
727 727
 	}
728 728
 
729 729
 
@@ -737,14 +737,14 @@  discard block
 block discarded – undo
737 737
 	 *
738 738
 	 * @return bool          success or fail.
739 739
 	 */
740
-	public function send_message_with_messenger_only( $messenger, $message_type, $message ) {
740
+	public function send_message_with_messenger_only($messenger, $message_type, $message) {
741 741
 		// EE_messages has been deprecated
742
-		$this->_class_is_deprecated( __FUNCTION__ );
742
+		$this->_class_is_deprecated(__FUNCTION__);
743 743
 		//setup for sending to new method.
744 744
 		/** @type EE_Messages_Queue $queue */
745
-		$queue = EE_Registry::instance()->load_lib( 'Messages_Queue' );
745
+		$queue = EE_Registry::instance()->load_lib('Messages_Queue');
746 746
 		//make sure we have a proper message object
747
-		if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) {
747
+		if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
748 748
 			$msg = EE_Message_Factory::create(
749 749
 				array(
750 750
 					'MSG_messenger'    => $messenger,
@@ -756,15 +756,15 @@  discard block
 block discarded – undo
756 756
 		} else {
757 757
 			$msg = $message;
758 758
 		}
759
-		if ( ! $msg instanceof EE_Message ) {
759
+		if ( ! $msg instanceof EE_Message) {
760 760
 			return false;
761 761
 		}
762 762
 		//make sure any content in a content property (if not empty) is set on the MSG_content.
763
-		if ( ! empty( $msg->content ) ) {
764
-			$msg->set( 'MSG_content', $msg->content );
763
+		if ( ! empty($msg->content)) {
764
+			$msg->set('MSG_content', $msg->content);
765 765
 		}
766
-		$queue->add( $msg );
767
-		return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue );
766
+		$queue->add($msg);
767
+		return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
768 768
 	}
769 769
 
770 770
 
@@ -778,11 +778,11 @@  discard block
 block discarded – undo
778 778
 	 * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned.
779 779
 	 * @throws \EE_Error
780 780
 	 */
781
-	public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) {
781
+	public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) {
782 782
 		// EE_messages has been deprecated
783
-		$this->_class_is_deprecated( __FUNCTION__ );
784
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
785
-		return EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $is_global );
783
+		$this->_class_is_deprecated(__FUNCTION__);
784
+		EE_Registry::instance()->load_helper('MSG_Template');
785
+		return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
786 786
 	}
787 787
 
788 788
 
@@ -793,11 +793,11 @@  discard block
 block discarded – undo
793 793
 	 * @param  string $message_type_name name of EE_message_type
794 794
 	 * @return array
795 795
 	 */
796
-	public function get_fields( $messenger_name, $message_type_name ) {
796
+	public function get_fields($messenger_name, $message_type_name) {
797 797
 		// EE_messages has been deprecated
798
-		$this->_class_is_deprecated( __FUNCTION__ );
799
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
800
-		return EEH_MSG_Template::get_fields( $messenger_name, $message_type_name );
798
+		$this->_class_is_deprecated(__FUNCTION__);
799
+		EE_Registry::instance()->load_helper('MSG_Template');
800
+		return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
801 801
 	}
802 802
 
803 803
 
@@ -811,13 +811,13 @@  discard block
 block discarded – undo
811 811
 	 * @return array                    multidimensional array of messenger and message_type objects
812 812
 	 *                                    (messengers index, and message_type index);
813 813
 	 */
814
-	public function get_installed( $type = 'all', $skip_cache = false ) {
814
+	public function get_installed($type = 'all', $skip_cache = false) {
815 815
 		// EE_messages has been deprecated
816
-		$this->_class_is_deprecated( __FUNCTION__ );
817
-		if ( $skip_cache ) {
816
+		$this->_class_is_deprecated(__FUNCTION__);
817
+		if ($skip_cache) {
818 818
 			$this->_message_resource_manager->reset_active_messengers_and_message_types();
819 819
 		}
820
-		switch ( $type ) {
820
+		switch ($type) {
821 821
 			case 'messengers' :
822 822
 				return array(
823 823
 					'messenger' => $this->_message_resource_manager->installed_messengers(),
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 	 */
847 847
 	public function get_active_messengers() {
848 848
 		// EE_messages has been deprecated
849
-		$this->_class_is_deprecated( __FUNCTION__ );
849
+		$this->_class_is_deprecated(__FUNCTION__);
850 850
 		return $this->_message_resource_manager->active_messengers();
851 851
 	}
852 852
 
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	public function get_active_message_types() {
860 860
 		// EE_messages has been deprecated
861
-		$this->_class_is_deprecated( __FUNCTION__ );
861
+		$this->_class_is_deprecated(__FUNCTION__);
862 862
 		return $this->_message_resource_manager->list_of_active_message_types();
863 863
 	}
864 864
 
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 	 */
871 871
 	public function get_active_message_type_objects() {
872 872
 		// EE_messages has been deprecated
873
-		$this->_class_is_deprecated( __FUNCTION__ );
873
+		$this->_class_is_deprecated(__FUNCTION__);
874 874
 		return $this->_message_resource_manager->get_active_message_type_objects();
875 875
 	}
876 876
 
@@ -882,10 +882,10 @@  discard block
 block discarded – undo
882 882
 	 * @param string $messenger The messenger being checked
883 883
 	 * @return EE_message_type[]    (or empty array if none present)
884 884
 	 */
885
-	public function get_active_message_types_per_messenger( $messenger ) {
885
+	public function get_active_message_types_per_messenger($messenger) {
886 886
 		// EE_messages has been deprecated
887
-		$this->_class_is_deprecated( __FUNCTION__ );
888
-		return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger );
887
+		$this->_class_is_deprecated(__FUNCTION__);
888
+		return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
889 889
 	}
890 890
 
891 891
 
@@ -896,10 +896,10 @@  discard block
 block discarded – undo
896 896
 	 * @param string $message_type The string should correspond to a message type.
897 897
 	 * @return EE_message_type|null
898 898
 	 */
899
-	public function get_active_message_type( $messenger, $message_type ) {
899
+	public function get_active_message_type($messenger, $message_type) {
900 900
 		// EE_messages has been deprecated
901
-		$this->_class_is_deprecated( __FUNCTION__ );
902
-		return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type );
901
+		$this->_class_is_deprecated(__FUNCTION__);
902
+		return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
903 903
 	}
904 904
 
905 905
 
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
 	 */
911 911
 	public function get_installed_message_types() {
912 912
 		// EE_messages has been deprecated
913
-		$this->_class_is_deprecated( __FUNCTION__ );
913
+		$this->_class_is_deprecated(__FUNCTION__);
914 914
 		return $this->_message_resource_manager->installed_message_types();
915 915
 	}
916 916
 
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
 	 */
923 923
 	public function get_installed_messengers() {
924 924
 		// EE_messages has been deprecated
925
-		$this->_class_is_deprecated( __FUNCTION__ );
925
+		$this->_class_is_deprecated(__FUNCTION__);
926 926
 		return $this->_message_resource_manager->installed_messengers();
927 927
 	}
928 928
 
@@ -933,10 +933,10 @@  discard block
 block discarded – undo
933 933
 	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by message type.
934 934
 	 * @return array
935 935
 	 */
936
-	public function get_all_contexts( $slugs_only = true ) {
936
+	public function get_all_contexts($slugs_only = true) {
937 937
 		// EE_messages has been deprecated
938
-		$this->_class_is_deprecated( __FUNCTION__ );
939
-		return $this->_message_resource_manager->get_all_contexts( $slugs_only );
938
+		$this->_class_is_deprecated(__FUNCTION__);
939
+		return $this->_message_resource_manager->get_all_contexts($slugs_only);
940 940
 	}
941 941
 
942 942
 
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
 add_filter(
996 996
 	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
997 997
 	function($event_list_iframe_css) {
998
-		if ( ! has_filter( 'FHEE__EventsArchiveIframe__event_list_iframe__css' )) {
998
+		if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
999 999
 			return $event_list_iframe_css;
1000 1000
 		}
1001 1001
 		deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
 add_filter(
1016 1016
 	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1017 1017
 	function($event_list_iframe_js) {
1018
-		if ( ! has_filter( 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js' )) {
1018
+		if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1019 1019
 			return $event_list_iframe_js;
1020 1020
 		}
1021 1021
 		deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
 add_filter(
1036 1036
 	'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1037 1037
 	function($existing_attendee, $registration, $attendee_data) {
1038
-		if ( ! has_filter( 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee' )) {
1038
+		if ( ! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) {
1039 1039
 			return $existing_attendee;
1040 1040
 		}
1041 1041
 		deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
             $existing_attendee, $registration, $attendee_data
1052 1052
         );
1053 1053
 	},
1054
-    10,3
1054
+    10, 3
1055 1055
 );
1056 1056
 
1057 1057
 
@@ -1117,7 +1117,7 @@  discard block
 block discarded – undo
1117 1117
      */
1118 1118
     public function event_list_title($event_list_title = '')
1119 1119
     {
1120
-        if (! empty($this->title)) {
1120
+        if ( ! empty($this->title)) {
1121 1121
             return $this->title;
1122 1122
         }
1123 1123
         return $event_list_title;
Please login to merge, or discard this patch.
core/db_classes/EE_Registration.class.php 1 patch
Indentation   +1685 added lines, -1685 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\EntityNotFoundException;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 /**
@@ -15,1690 +15,1690 @@  discard block
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Used to reference when a registration has never been checked in.
20
-     *
21
-     * @type int
22
-     */
23
-    const checkin_status_never = 2;
24
-
25
-    /**
26
-     * Used to reference when a registration has been checked in.
27
-     *
28
-     * @type int
29
-     */
30
-    const checkin_status_in = 1;
31
-
32
-
33
-    /**
34
-     * Used to reference when a registration has been checked out.
35
-     *
36
-     * @type int
37
-     */
38
-    const checkin_status_out = 0;
39
-
40
-
41
-    /**
42
-     * extra meta key for tracking reg status os trashed registrations
43
-     *
44
-     * @type string
45
-     */
46
-    const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
47
-
48
-
49
-    /**
50
-     * extra meta key for tracking if registration has reserved ticket
51
-     *
52
-     * @type string
53
-     */
54
-    const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
55
-
56
-
57
-    /**
58
-     * @param array  $props_n_values          incoming values
59
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
60
-     *                                        used.)
61
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
62
-     *                                        date_format and the second value is the time format
63
-     * @return EE_Registration
64
-     */
65
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
66
-    {
67
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
68
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
69
-    }
70
-
71
-
72
-    /**
73
-     * @param array  $props_n_values  incoming values from the database
74
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
75
-     *                                the website will be used.
76
-     * @return EE_Registration
77
-     */
78
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
79
-    {
80
-        return new self($props_n_values, true, $timezone);
81
-    }
82
-
83
-
84
-    /**
85
-     *        Set Event ID
86
-     *
87
-     * @param        int $EVT_ID Event ID
88
-     */
89
-    public function set_event($EVT_ID = 0)
90
-    {
91
-        $this->set('EVT_ID', $EVT_ID);
92
-    }
93
-
94
-
95
-    /**
96
-     * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
97
-     * be routed to internal methods
98
-     *
99
-     * @param string $field_name
100
-     * @param mixed  $field_value
101
-     * @param bool   $use_default
102
-     * @throws \EE_Error
103
-     * @throws \RuntimeException
104
-     */
105
-    public function set($field_name, $field_value, $use_default = false)
106
-    {
107
-        switch ($field_name) {
108
-            case 'REG_code' :
109
-                if (! empty($field_value) && $this->reg_code() === null) {
110
-                    $this->set_reg_code($field_value, $use_default);
111
-                }
112
-                break;
113
-            case 'STS_ID' :
114
-                $this->set_status($field_value, $use_default);
115
-                break;
116
-            default :
117
-                parent::set($field_name, $field_value, $use_default);
118
-        }
119
-    }
120
-
121
-
122
-    /**
123
-     * Set Status ID
124
-     * updates the registration status and ALSO...
125
-     * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
126
-     * calls release_registration_space() if the reg status changes FROM approved to any other reg status
127
-     *
128
-     * @param string  $new_STS_ID
129
-     * @param boolean $use_default
130
-     * @return bool
131
-     * @throws \RuntimeException
132
-     * @throws \EE_Error
133
-     */
134
-    public function set_status($new_STS_ID = null, $use_default = false)
135
-    {
136
-        // get current REG_Status
137
-        $old_STS_ID = $this->status_ID();
138
-        // if status has changed
139
-        if (
140
-            $old_STS_ID !== $new_STS_ID // and that status has actually changed
141
-            && ! empty($old_STS_ID) // and that old status is actually set
142
-            && ! empty($new_STS_ID) // as well as the new status
143
-            && $this->ID() // ensure registration is in the db
144
-        ) {
145
-            // TO approved
146
-            if ($new_STS_ID === EEM_Registration::status_id_approved) {
147
-                // reserve a space by incrementing ticket and datetime sold values
148
-                $this->_reserve_registration_space();
149
-                do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID);
150
-                // OR FROM  approved
151
-            } else if ($old_STS_ID === EEM_Registration::status_id_approved) {
152
-                // release a space by decrementing ticket and datetime sold values
153
-                $this->_release_registration_space();
154
-                do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID);
155
-            }
156
-            // update status
157
-            parent::set('STS_ID', $new_STS_ID, $use_default);
158
-            $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
159
-            /** @type EE_Transaction_Payments $transaction_payments */
160
-            $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
161
-            $transaction_payments->recalculate_transaction_total($this->transaction(), false);
162
-            $this->transaction()->update_status_based_on_total_paid(true);
163
-            do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID);
164
-            return true;
165
-        }
166
-        //even though the old value matches the new value, it's still good to
167
-        //allow the parent set method to have a say
168
-        parent::set('STS_ID', $new_STS_ID, $use_default);
169
-        return true;
170
-    }
171
-
172
-
173
-    /**
174
-     * update REGs and TXN when cancelled or declined registrations involved
175
-     *
176
-     * @param string $new_STS_ID
177
-     * @param string $old_STS_ID
178
-     * @throws \EE_Error
179
-     */
180
-    private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID)
181
-    {
182
-        // these reg statuses should not be considered in any calculations involving monies owing
183
-        $closed_reg_statuses = EEM_Registration::closed_reg_statuses();
184
-        // true if registration has been cancelled or declined
185
-        if (
186
-            in_array($new_STS_ID, $closed_reg_statuses, true)
187
-            && ! in_array($old_STS_ID, $closed_reg_statuses, true)
188
-        ) {
189
-            /** @type EE_Registration_Processor $registration_processor */
190
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
191
-            /** @type EE_Transaction_Processor $transaction_processor */
192
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
193
-            // cancelled or declined registration
194
-            $registration_processor->update_registration_after_being_canceled_or_declined(
195
-                $this,
196
-                $closed_reg_statuses
197
-            );
198
-            $transaction_processor->update_transaction_after_canceled_or_declined_registration(
199
-                $this,
200
-                $closed_reg_statuses,
201
-                false
202
-            );
203
-            do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID);
204
-            return;
205
-        }
206
-        // true if reinstating cancelled or declined registration
207
-        if (
208
-            in_array($old_STS_ID, $closed_reg_statuses, true)
209
-            && ! in_array($new_STS_ID, $closed_reg_statuses, true)
210
-        ) {
211
-            /** @type EE_Registration_Processor $registration_processor */
212
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
213
-            /** @type EE_Transaction_Processor $transaction_processor */
214
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
215
-            // reinstating cancelled or declined registration
216
-            $registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
217
-                $this,
218
-                $closed_reg_statuses
219
-            );
220
-            $transaction_processor->update_transaction_after_reinstating_canceled_registration(
221
-                $this,
222
-                $closed_reg_statuses,
223
-                false
224
-            );
225
-            do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID);
226
-        }
227
-    }
228
-
229
-
230
-    /**
231
-     *        get Status ID
232
-     */
233
-    public function status_ID()
234
-    {
235
-        return $this->get('STS_ID');
236
-    }
237
-
238
-
239
-    /**
240
-     * increments this registration's related ticket sold and corresponding datetime sold values
241
-     *
242
-     * @return void
243
-     * @throws \EE_Error
244
-     */
245
-    private function _reserve_registration_space()
246
-    {
247
-        // reserved ticket and datetime counts will be decremented as sold counts are incremented
248
-        // so stop tracking that this reg has a ticket reserved
249
-        $this->release_reserved_ticket();
250
-        $ticket = $this->ticket();
251
-        $ticket->increase_sold();
252
-        $ticket->save();
253
-        // possibly set event status to sold out
254
-        $this->event()->perform_sold_out_status_check();
255
-    }
256
-
257
-
258
-    /**
259
-     * Gets the ticket this registration is for
260
-     *
261
-     * @param boolean $include_archived whether to include archived tickets or not.
262
-     * @return EE_Ticket|EE_Base_Class
263
-     * @throws \EE_Error
264
-     */
265
-    public function ticket($include_archived = true)
266
-    {
267
-        $query_params = array();
268
-        if ($include_archived) {
269
-            $query_params['default_where_conditions'] = 'none';
270
-        }
271
-        return $this->get_first_related('Ticket', $query_params);
272
-    }
273
-
274
-
275
-    /**
276
-     * Gets the event this registration is for
277
-     *
278
-     * @return EE_Event
279
-     */
280
-    public function event()
281
-    {
282
-        $event = $this->get_first_related('Event');
283
-        if (! $event instanceof \EE_Event) {
284
-            throw new EntityNotFoundException('Event ID', $this->event_ID());
285
-        }
286
-        return $event;
287
-    }
288
-
289
-
290
-    /**
291
-     * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
292
-     * with the author of the event this registration is for.
293
-     *
294
-     * @since 4.5.0
295
-     * @return int
296
-     */
297
-    public function wp_user()
298
-    {
299
-        $event = $this->event();
300
-        if ($event instanceof EE_Event) {
301
-            return $event->wp_user();
302
-        }
303
-        return 0;
304
-    }
305
-
306
-
307
-    /**
308
-     * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
309
-     *
310
-     * @return void
311
-     * @throws \EE_Error
312
-     */
313
-    private function _release_registration_space()
314
-    {
315
-        $ticket = $this->ticket();
316
-        $ticket->decrease_sold();
317
-        $ticket->save();
318
-    }
319
-
320
-
321
-    /**
322
-     * tracks this registration's ticket reservation in extra meta
323
-     * and can increment related ticket reserved and corresponding datetime reserved values
324
-     *
325
-     * @param bool $update_ticket if true, will increment ticket and datetime reserved count
326
-     * @return void
327
-     * @throws \EE_Error
328
-     */
329
-    public function reserve_ticket($update_ticket = false)
330
-    {
331
-        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) {
332
-            // PLZ NOTE: although checking $update_ticket first would be more efficient,
333
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
334
-            if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) {
335
-                $ticket = $this->ticket();
336
-                $ticket->increase_reserved();
337
-                $ticket->save();
338
-            }
339
-        }
340
-    }
341
-
342
-
343
-    /**
344
-     * stops tracking this registration's ticket reservation in extra meta
345
-     * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
346
-     *
347
-     * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
348
-     * @return void
349
-     * @throws \EE_Error
350
-     */
351
-    public function release_reserved_ticket($update_ticket = false)
352
-    {
353
-        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) {
354
-            // PLZ NOTE: although checking $update_ticket first would be more efficient,
355
-            // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first
356
-            if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) {
357
-                $ticket = $this->ticket();
358
-                $ticket->decrease_reserved();
359
-                $ticket->save();
360
-            }
361
-        }
362
-    }
363
-
364
-
365
-    /**
366
-     * Set Attendee ID
367
-     *
368
-     * @param        int $ATT_ID Attendee ID
369
-     */
370
-    public function set_attendee_id($ATT_ID = 0)
371
-    {
372
-        $this->set('ATT_ID', $ATT_ID);
373
-    }
374
-
375
-
376
-    /**
377
-     *        Set Transaction ID
378
-     *
379
-     * @param        int $TXN_ID Transaction ID
380
-     */
381
-    public function set_transaction_id($TXN_ID = 0)
382
-    {
383
-        $this->set('TXN_ID', $TXN_ID);
384
-    }
385
-
386
-
387
-    /**
388
-     *        Set Session
389
-     *
390
-     * @param    string $REG_session PHP Session ID
391
-     */
392
-    public function set_session($REG_session = '')
393
-    {
394
-        $this->set('REG_session', $REG_session);
395
-    }
396
-
397
-
398
-    /**
399
-     *        Set Registration URL Link
400
-     *
401
-     * @param    string $REG_url_link Registration URL Link
402
-     */
403
-    public function set_reg_url_link($REG_url_link = '')
404
-    {
405
-        $this->set('REG_url_link', $REG_url_link);
406
-    }
407
-
408
-
409
-    /**
410
-     *        Set Attendee Counter
411
-     *
412
-     * @param        int $REG_count Primary Attendee
413
-     */
414
-    public function set_count($REG_count = 1)
415
-    {
416
-        $this->set('REG_count', $REG_count);
417
-    }
418
-
419
-
420
-    /**
421
-     *        Set Group Size
422
-     *
423
-     * @param        boolean $REG_group_size Group Registration
424
-     */
425
-    public function set_group_size($REG_group_size = false)
426
-    {
427
-        $this->set('REG_group_size', $REG_group_size);
428
-    }
429
-
430
-
431
-    /**
432
-     *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
433
-     *    EEM_Registration::status_id_not_approved
434
-     *
435
-     * @return        boolean
436
-     */
437
-    public function is_not_approved()
438
-    {
439
-        return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
440
-    }
441
-
442
-
443
-    /**
444
-     *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
445
-     *    EEM_Registration::status_id_pending_payment
446
-     *
447
-     * @return        boolean
448
-     */
449
-    public function is_pending_payment()
450
-    {
451
-        return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
452
-    }
453
-
454
-
455
-    /**
456
-     *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
457
-     *
458
-     * @return        boolean
459
-     */
460
-    public function is_approved()
461
-    {
462
-        return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
463
-    }
464
-
465
-
466
-    /**
467
-     *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
468
-     *
469
-     * @return        boolean
470
-     */
471
-    public function is_cancelled()
472
-    {
473
-        return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
474
-    }
475
-
476
-
477
-    /**
478
-     *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
479
-     *
480
-     * @return        boolean
481
-     */
482
-    public function is_declined()
483
-    {
484
-        return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
485
-    }
486
-
487
-
488
-    /**
489
-     *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
490
-     *    EEM_Registration::status_id_incomplete
491
-     *
492
-     * @return        boolean
493
-     */
494
-    public function is_incomplete()
495
-    {
496
-        return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
497
-    }
498
-
499
-
500
-    /**
501
-     *        Set Registration Date
502
-     *
503
-     * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
504
-     *                       Date
505
-     */
506
-    public function set_reg_date($REG_date = false)
507
-    {
508
-        $this->set('REG_date', $REG_date);
509
-    }
510
-
511
-
512
-    /**
513
-     *    Set final price owing for this registration after all ticket/price modifications
514
-     *
515
-     * @access    public
516
-     * @param    float $REG_final_price
517
-     */
518
-    public function set_final_price($REG_final_price = 0.00)
519
-    {
520
-        $this->set('REG_final_price', $REG_final_price);
521
-    }
522
-
523
-
524
-    /**
525
-     *    Set amount paid towards this registration's final price
526
-     *
527
-     * @access    public
528
-     * @param    float $REG_paid
529
-     */
530
-    public function set_paid($REG_paid = 0.00)
531
-    {
532
-        $this->set('REG_paid', $REG_paid);
533
-    }
534
-
535
-
536
-    /**
537
-     *        Attendee Is Going
538
-     *
539
-     * @param        boolean $REG_att_is_going Attendee Is Going
540
-     */
541
-    public function set_att_is_going($REG_att_is_going = false)
542
-    {
543
-        $this->set('REG_att_is_going', $REG_att_is_going);
544
-    }
545
-
546
-
547
-    /**
548
-     * Gets the related attendee
549
-     *
550
-     * @return EE_Attendee
551
-     */
552
-    public function attendee()
553
-    {
554
-        return $this->get_first_related('Attendee');
555
-    }
556
-
557
-
558
-    /**
559
-     *        get Event ID
560
-     */
561
-    public function event_ID()
562
-    {
563
-        return $this->get('EVT_ID');
564
-    }
565
-
566
-
567
-    /**
568
-     *        get Event ID
569
-     */
570
-    public function event_name()
571
-    {
572
-        $event = $this->event_obj();
573
-        if ($event) {
574
-            return $event->name();
575
-        } else {
576
-            return null;
577
-        }
578
-    }
579
-
580
-
581
-    /**
582
-     * Fetches the event this registration is for
583
-     *
584
-     * @return EE_Event
585
-     */
586
-    public function event_obj()
587
-    {
588
-        return $this->get_first_related('Event');
589
-    }
590
-
591
-
592
-    /**
593
-     *        get Attendee ID
594
-     */
595
-    public function attendee_ID()
596
-    {
597
-        return $this->get('ATT_ID');
598
-    }
599
-
600
-
601
-    /**
602
-     *        get PHP Session ID
603
-     */
604
-    public function session_ID()
605
-    {
606
-        return $this->get('REG_session');
607
-    }
608
-
609
-
610
-    /**
611
-     * Gets the string which represents the URL trigger for the receipt template in the message template system.
612
-     *
613
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
614
-     * @return string
615
-     */
616
-    public function receipt_url($messenger = 'html')
617
-    {
618
-
619
-        /**
620
-         * The below will be deprecated one version after this.  We check first if there is a custom receipt template already in use on old system.  If there is then we just return the standard url for it.
621
-         *
622
-         * @since 4.5.0
623
-         */
624
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
625
-        $has_custom             = EEH_Template::locate_template($template_relative_path, array(), true, true, true);
626
-
627
-        if ($has_custom) {
628
-            return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
629
-        }
630
-        return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
631
-    }
632
-
633
-
634
-    /**
635
-     * Gets the string which represents the URL trigger for the invoice template in the message template system.
636
-     *
637
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
638
-     * @return string
639
-     */
640
-    public function invoice_url($messenger = 'html')
641
-    {
642
-        /**
643
-         * The below will be deprecated one version after this.  We check first if there is a custom invoice template already in use on old system.  If there is then we just return the standard url for it.
644
-         *
645
-         * @since 4.5.0
646
-         */
647
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
648
-        $has_custom             = EEH_Template::locate_template($template_relative_path, array(), true, true, true);
649
-
650
-        if ($has_custom) {
651
-            if ($messenger == 'html') {
652
-                return $this->invoice_url('launch');
653
-            }
654
-            $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
655
-
656
-            $query_args = array('ee' => $route, 'id' => $this->reg_url_link());
657
-            if ($messenger == 'html') {
658
-                $query_args['html'] = true;
659
-            }
660
-            return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
661
-        }
662
-        return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
663
-    }
664
-
665
-
666
-    /**
667
-     * get Registration URL Link
668
-     *
669
-     * @access public
670
-     * @return string
671
-     * @throws \EE_Error
672
-     */
673
-    public function reg_url_link()
674
-    {
675
-        return (string)$this->get('REG_url_link');
676
-    }
677
-
678
-
679
-    /**
680
-     * Echoes out invoice_url()
681
-     *
682
-     * @param string $type 'download','launch', or 'html' (default is 'launch')
683
-     * @return void
684
-     */
685
-    public function e_invoice_url($type = 'launch')
686
-    {
687
-        echo $this->invoice_url($type);
688
-    }
689
-
690
-
691
-    /**
692
-     * Echoes out payment_overview_url
693
-     */
694
-    public function e_payment_overview_url()
695
-    {
696
-        echo $this->payment_overview_url();
697
-    }
698
-
699
-
700
-    /**
701
-     * Gets the URL of the thank you page with this registration REG_url_link added as
702
-     * a query parameter
703
-     *
704
-     * @return string
705
-     */
706
-    public function payment_overview_url()
707
-    {
708
-        return add_query_arg(array(
709
-            'e_reg_url_link' => $this->reg_url_link(),
710
-            'step'           => 'payment_options',
711
-            'revisit'        => true,
712
-        ), EE_Registry::instance()->CFG->core->reg_page_url());
713
-    }
714
-
715
-
716
-    /**
717
-     * Gets the URL of the thank you page with this registration REG_url_link added as
718
-     * a query parameter
719
-     *
720
-     * @return string
721
-     */
722
-    public function edit_attendee_information_url()
723
-    {
724
-        return add_query_arg(array(
725
-            'e_reg_url_link' => $this->reg_url_link(),
726
-            'step'           => 'attendee_information',
727
-            'revisit'        => true,
728
-        ), EE_Registry::instance()->CFG->core->reg_page_url());
729
-    }
730
-
731
-
732
-    /**
733
-     * Simply generates and returns the appropriate admin_url link to edit this registration
734
-     *
735
-     * @return string
736
-     */
737
-    public function get_admin_edit_url()
738
-    {
739
-        return EEH_URL::add_query_args_and_nonce(array(
740
-            'page'    => 'espresso_registrations',
741
-            'action'  => 'view_registration',
742
-            '_REG_ID' => $this->ID(),
743
-        ), admin_url('admin.php'));
744
-    }
745
-
746
-
747
-    /**
748
-     *    is_primary_registrant?
749
-     */
750
-    public function is_primary_registrant()
751
-    {
752
-        return $this->get('REG_count') == 1 ? true : false;
753
-    }
754
-
755
-
756
-    /**
757
-     * This returns the primary registration object for this registration group (which may be this object).
758
-     *
759
-     * @return EE_Registration
760
-     */
761
-    public function get_primary_registration()
762
-    {
763
-        if ($this->is_primary_registrant()) {
764
-            return $this;
765
-        }
766
-
767
-        //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
768
-        $primary_registrant = EEM_Registration::instance()->get_one(array(
769
-            array(
770
-                'TXN_ID'    => $this->transaction_ID(),
771
-                'REG_count' => 1,
772
-            ),
773
-        ));
774
-        return $primary_registrant;
775
-    }
776
-
777
-
778
-    /**
779
-     *        get  Attendee Number
780
-     *
781
-     * @access        public
782
-     */
783
-    public function count()
784
-    {
785
-        return $this->get('REG_count');
786
-    }
787
-
788
-
789
-    /**
790
-     *        get Group Size
791
-     */
792
-    public function group_size()
793
-    {
794
-        return $this->get('REG_group_size');
795
-    }
796
-
797
-
798
-    /**
799
-     *        get Registration Date
800
-     */
801
-    public function date()
802
-    {
803
-        return $this->get('REG_date');
804
-    }
805
-
806
-
807
-    /**
808
-     * gets a pretty date
809
-     *
810
-     * @param string $date_format
811
-     * @param string $time_format
812
-     * @return string
813
-     */
814
-    public function pretty_date($date_format = null, $time_format = null)
815
-    {
816
-        return $this->get_datetime('REG_date', $date_format, $time_format);
817
-    }
818
-
819
-
820
-    /**
821
-     * final_price
822
-     * the registration's share of the transaction total, so that the
823
-     * sum of all the transaction's REG_final_prices equal the transaction's total
824
-     *
825
-     * @return    float
826
-     */
827
-    public function final_price()
828
-    {
829
-        return $this->get('REG_final_price');
830
-    }
831
-
832
-
833
-    /**
834
-     * pretty_final_price
835
-     *  final price as formatted string, with correct decimal places and currency symbol
836
-     *
837
-     * @return string
838
-     */
839
-    public function pretty_final_price()
840
-    {
841
-        return $this->get_pretty('REG_final_price');
842
-    }
843
-
844
-
845
-    /**
846
-     * get paid (yeah)
847
-     *
848
-     * @return    float
849
-     */
850
-    public function paid()
851
-    {
852
-        return $this->get('REG_paid');
853
-    }
854
-
855
-
856
-    /**
857
-     * pretty_paid
858
-     *
859
-     * @return    float
860
-     */
861
-    public function pretty_paid()
862
-    {
863
-        return $this->get_pretty('REG_paid');
864
-    }
865
-
866
-
867
-    /**
868
-     * owes_monies_and_can_pay
869
-     * whether or not this registration has monies owing and it's' status allows payment
870
-     *
871
-     * @param array $requires_payment
872
-     * @return bool
873
-     */
874
-    public function owes_monies_and_can_pay($requires_payment = array())
875
-    {
876
-        // these reg statuses require payment (if event is not free)
877
-        $requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment();
878
-        if (
879
-            in_array($this->status_ID(), $requires_payment) &&
880
-            $this->final_price() != 0 &&
881
-            $this->final_price() != $this->paid()
882
-        ) {
883
-            return true;
884
-        } else {
885
-            return false;
886
-        }
887
-    }
888
-
889
-
890
-    /**
891
-     * Prints out the return value of $this->pretty_status()
892
-     *
893
-     * @param bool $show_icons
894
-     * @return void
895
-     */
896
-    public function e_pretty_status($show_icons = false)
897
-    {
898
-        echo $this->pretty_status($show_icons);
899
-    }
900
-
901
-
902
-    /**
903
-     * Returns a nice version of the status for displaying to customers
904
-     *
905
-     * @param bool $show_icons
906
-     * @return string
907
-     */
908
-    public function pretty_status($show_icons = false)
909
-    {
910
-        $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')),
911
-            false, 'sentence');
912
-        $icon   = '';
913
-        switch ($this->status_ID()) {
914
-            case EEM_Registration::status_id_approved:
915
-                $icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : '';
916
-                break;
917
-            case EEM_Registration::status_id_pending_payment:
918
-                $icon = $show_icons ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' : '';
919
-                break;
920
-            case EEM_Registration::status_id_not_approved:
921
-                $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' : '';
922
-                break;
923
-            case EEM_Registration::status_id_cancelled:
924
-                $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' : '';
925
-                break;
926
-            case EEM_Registration::status_id_incomplete:
927
-                $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' : '';
928
-                break;
929
-            case EEM_Registration::status_id_declined:
930
-                $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : '';
931
-                break;
932
-            case EEM_Registration::status_id_wait_list:
933
-                $icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : '';
934
-                break;
935
-        }
936
-        return $icon . $status[$this->status_ID()];
937
-    }
938
-
939
-
940
-    /**
941
-     *        get Attendee Is Going
942
-     */
943
-    public function att_is_going()
944
-    {
945
-        return $this->get('REG_att_is_going');
946
-    }
947
-
948
-
949
-    /**
950
-     * Gets related answers
951
-     *
952
-     * @param array $query_params like EEM_Base::get_all
953
-     * @return EE_Answer[]
954
-     */
955
-    public function answers($query_params = null)
956
-    {
957
-        return $this->get_many_related('Answer', $query_params);
958
-    }
959
-
960
-
961
-    /**
962
-     * Gets the registration's answer value to the specified question
963
-     * (either the question's ID or a question object)
964
-     *
965
-     * @param EE_Question|int $question
966
-     * @param bool            $pretty_value
967
-     * @return array|string if pretty_value= true, the result will always be a string
968
-     * (because the answer might be an array of answer values, so passing pretty_value=true
969
-     * will convert it into some kind of string)
970
-     */
971
-    public function answer_value_to_question($question, $pretty_value = true)
972
-    {
973
-        $question_id = EEM_Question::instance()->ensure_is_ID($question);
974
-        return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
975
-    }
976
-
977
-
978
-    /**
979
-     * question_groups
980
-     * returns an array of EE_Question_Group objects for this registration
981
-     *
982
-     * @return EE_Question_Group[]
983
-     */
984
-    public function question_groups()
985
-    {
986
-        $question_groups = array();
987
-        if ($this->event() instanceof EE_Event) {
988
-            $question_groups = $this->event()->question_groups(
989
-                array(
990
-                    array(
991
-                        'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
992
-                    ),
993
-                    'order_by' => array('QSG_order' => 'ASC'),
994
-                )
995
-            );
996
-        }
997
-        return $question_groups;
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * count_question_groups
1003
-     * returns a count of the number of EE_Question_Group objects for this registration
1004
-     *
1005
-     * @return int
1006
-     */
1007
-    public function count_question_groups()
1008
-    {
1009
-        $qg_count = 0;
1010
-        if ($this->event() instanceof EE_Event) {
1011
-            $qg_count = $this->event()->count_related(
1012
-                'Question_Group',
1013
-                array(
1014
-                    array(
1015
-                        'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
1016
-                    ),
1017
-                )
1018
-            );
1019
-        }
1020
-        return $qg_count;
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * Returns the registration date in the 'standard' string format
1026
-     * (function may be improved in the future to allow for different formats and timezones)
1027
-     *
1028
-     * @return string
1029
-     */
1030
-    public function reg_date()
1031
-    {
1032
-        return $this->get_datetime('REG_date');
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1038
-     * the ticket this registration purchased, or the datetime they have registered
1039
-     * to attend)
1040
-     *
1041
-     * @return EE_Datetime_Ticket
1042
-     */
1043
-    public function datetime_ticket()
1044
-    {
1045
-        return $this->get_first_related('Datetime_Ticket');
1046
-    }
1047
-
1048
-
1049
-    /**
1050
-     * Sets the registration's datetime_ticket.
1051
-     *
1052
-     * @param EE_Datetime_Ticket $datetime_ticket
1053
-     * @return EE_Datetime_Ticket
1054
-     */
1055
-    public function set_datetime_ticket($datetime_ticket)
1056
-    {
1057
-        return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1058
-    }
1059
-
1060
-    /**
1061
-     * Gets deleted
1062
-     *
1063
-     * @return boolean
1064
-     */
1065
-    public function deleted()
1066
-    {
1067
-        return $this->get('REG_deleted');
1068
-    }
1069
-
1070
-    /**
1071
-     * Sets deleted
1072
-     *
1073
-     * @param boolean $deleted
1074
-     * @return boolean
1075
-     */
1076
-    public function set_deleted($deleted)
1077
-    {
1078
-        if ($deleted) {
1079
-            $this->delete();
1080
-        } else {
1081
-            $this->restore();
1082
-        }
1083
-    }
1084
-
1085
-
1086
-    /**
1087
-     * Get the status object of this object
1088
-     *
1089
-     * @return EE_Status
1090
-     */
1091
-    public function status_obj()
1092
-    {
1093
-        return $this->get_first_related('Status');
1094
-    }
1095
-
1096
-
1097
-    /**
1098
-     * Returns the number of times this registration has checked into any of the datetimes
1099
-     * its available for
1100
-     *
1101
-     * @return int
1102
-     */
1103
-    public function count_checkins()
1104
-    {
1105
-        return $this->get_model()->count_related($this, 'Checkin');
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1111
-     * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1112
-     *
1113
-     * @return int
1114
-     */
1115
-    public function count_checkins_not_checkedout()
1116
-    {
1117
-        return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1123
-     *
1124
-     * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1125
-     * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1126
-     *                                          consider registration status as well as datetime access.
1127
-     * @return bool
1128
-     */
1129
-    public function can_checkin($DTT_OR_ID, $check_approved = true)
1130
-    {
1131
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1132
-
1133
-        //first check registration status
1134
-        if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1135
-            return false;
1136
-        }
1137
-        //is there a datetime ticket that matches this dtt_ID?
1138
-        if (! (EEM_Datetime_Ticket::instance()->exists(array(
1139
-            array(
1140
-                'TKT_ID' => $this->get('TKT_ID'),
1141
-                'DTT_ID' => $DTT_ID,
1142
-            ),
1143
-        )))
1144
-        ) {
1145
-            return false;
1146
-        }
1147
-
1148
-        //final check is against TKT_uses
1149
-        return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1150
-    }
1151
-
1152
-
1153
-    /**
1154
-     * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1155
-     * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1156
-     * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1157
-     * then return false.  Otherwise return true.
1158
-     *
1159
-     * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1160
-     * @return bool   true means can checkin.  false means cannot checkin.
1161
-     */
1162
-    public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1163
-    {
1164
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1165
-
1166
-        if (! $DTT_ID) {
1167
-            return false;
1168
-        }
1169
-
1170
-        $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1171
-
1172
-        // if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in
1173
-        // or not.
1174
-        if (! $max_uses || $max_uses === EE_INF) {
1175
-            return true;
1176
-        }
1177
-
1178
-        //does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1179
-        //go ahead and toggle.
1180
-        if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1181
-            return true;
1182
-        }
1183
-
1184
-        //made it here so the last check is whether the number of checkins per unique datetime on this registration
1185
-        //disallows further check-ins.
1186
-        $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(
1187
-            array(
1188
-                'REG_ID' => $this->ID(),
1189
-                'CHK_in' => true,
1190
-            ),
1191
-        ), 'DTT_ID', true);
1192
-        // checkins have already reached their max number of uses
1193
-        // so registrant can NOT checkin
1194
-        if ($count_unique_dtt_checkins >= $max_uses) {
1195
-            EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1196
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1197
-            return false;
1198
-        }
1199
-        return true;
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * toggle Check-in status for this registration
1205
-     * Check-ins are toggled in the following order:
1206
-     * never checked in -> checked in
1207
-     * checked in -> checked out
1208
-     * checked out -> checked in
1209
-     *
1210
-     * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1211
-     *                      If not included or null, then it is assumed latest datetime is being toggled.
1212
-     * @param bool $verify  If true then can_checkin() is used to verify whether the person
1213
-     *                      can be checked in or not.  Otherwise this forces change in checkin status.
1214
-     * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1215
-     * @throws EE_Error
1216
-     */
1217
-    public function toggle_checkin_status($DTT_ID = null, $verify = false)
1218
-    {
1219
-        if (empty($DTT_ID)) {
1220
-            $datetime = $this->get_latest_related_datetime();
1221
-            $DTT_ID   = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1222
-            // verify the registration can checkin for the given DTT_ID
1223
-        } elseif (! $this->can_checkin($DTT_ID, $verify)) {
1224
-            EE_Error::add_error(
1225
-                sprintf(
1226
-                    __('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1227
-                        'event_espresso'),
1228
-                    $this->ID(),
1229
-                    $DTT_ID
1230
-                ),
1231
-                __FILE__, __FUNCTION__, __LINE__
1232
-            );
1233
-            return false;
1234
-        }
1235
-        $status_paths = array(
1236
-            EE_Registration::checkin_status_never => EE_Registration::checkin_status_in,
1237
-            EE_Registration::checkin_status_in    => EE_Registration::checkin_status_out,
1238
-            EE_Registration::checkin_status_out   => EE_Registration::checkin_status_in,
1239
-        );
1240
-        //start by getting the current status so we know what status we'll be changing to.
1241
-        $cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1242
-        $status_to  = $status_paths[$cur_status];
1243
-        // database only records true for checked IN or false for checked OUT
1244
-        // no record ( null ) means checked in NEVER, but we obviously don't save that
1245
-        $new_status = $status_to === EE_Registration::checkin_status_in ? true : false;
1246
-        // add relation - note Check-ins are always creating new rows
1247
-        // because we are keeping track of Check-ins over time.
1248
-        // Eventually we'll probably want to show a list table
1249
-        // for the individual Check-ins so that they can be managed.
1250
-        $checkin = EE_Checkin::new_instance(array(
1251
-            'REG_ID' => $this->ID(),
1252
-            'DTT_ID' => $DTT_ID,
1253
-            'CHK_in' => $new_status,
1254
-        ));
1255
-        // if the record could not be saved then return false
1256
-        if ($checkin->save() === 0) {
1257
-            if (WP_DEBUG) {
1258
-                global $wpdb;
1259
-                $error = sprintf(
1260
-                    __('Registration check in update failed because of the following database error: %1$s%2$s',
1261
-                        'event_espresso'),
1262
-                    '<br />',
1263
-                    $wpdb->last_error
1264
-                );
1265
-            } else {
1266
-                $error = __('Registration check in update failed because of an unknown database error',
1267
-                    'event_espresso');
1268
-            }
1269
-            EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1270
-            return false;
1271
-        }
1272
-        return $status_to;
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1278
-     * "Latest" is defined by the `DTT_EVT_start` column.
1279
-     *
1280
-     * @return EE_Datetime|null
1281
-     * @throws \EE_Error
1282
-     */
1283
-    public function get_latest_related_datetime()
1284
-    {
1285
-        return EEM_Datetime::instance()->get_one(
1286
-            array(
1287
-                array(
1288
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1289
-                ),
1290
-                'order_by' => array('DTT_EVT_start' => 'DESC'),
1291
-            )
1292
-        );
1293
-    }
1294
-
1295
-
1296
-    /**
1297
-     * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1298
-     * "Earliest" is defined by the `DTT_EVT_start` column.
1299
-     *
1300
-     * @throws \EE_Error
1301
-     */
1302
-    public function get_earliest_related_datetime()
1303
-    {
1304
-        return EEM_Datetime::instance()->get_one(
1305
-            array(
1306
-                array(
1307
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1308
-                ),
1309
-                'order_by' => array('DTT_EVT_start' => 'ASC'),
1310
-            )
1311
-        );
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * This method simply returns the check-in status for this registration and the given datetime.
1317
-     * If neither the datetime nor the checkin values are provided as arguments,
1318
-     * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1319
-     *
1320
-     * @param  int       $DTT_ID  The ID of the datetime we're checking against
1321
-     *                            (if empty we'll get the primary datetime for
1322
-     *                            this registration (via event) and use it's ID);
1323
-     * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1324
-     * @return int                Integer representing Check-in status.
1325
-     * @throws \EE_Error
1326
-     */
1327
-    public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1328
-    {
1329
-        $checkin_query_params = array(
1330
-            'order_by' => array('CHK_timestamp' => 'DESC'),
1331
-        );
1332
-
1333
-        if ($DTT_ID > 0) {
1334
-            $checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1335
-        }
1336
-
1337
-        //get checkin object (if exists)
1338
-        $checkin = $checkin instanceof EE_Checkin
1339
-            ? $checkin
1340
-            : $this->get_first_related('Checkin', $checkin_query_params);
1341
-        if ($checkin instanceof EE_Checkin) {
1342
-            if ($checkin->get('CHK_in')) {
1343
-                return EE_Registration::checkin_status_in; //checked in
1344
-            }
1345
-            return EE_Registration::checkin_status_out; //had checked in but is now checked out.
1346
-        }
1347
-        return EE_Registration::checkin_status_never; //never been checked in
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * This method returns a localized message for the toggled Check-in message.
1353
-     *
1354
-     * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1355
-     *                     then it is assumed Check-in for primary datetime was toggled.
1356
-     * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1357
-     *                     message can be customized with the attendee name.
1358
-     * @return string         internationalized message
1359
-     */
1360
-    public function get_checkin_msg($DTT_ID, $error = false)
1361
-    {
1362
-        //let's get the attendee first so we can include the name of the attendee
1363
-        $attendee = $this->get_first_related('Attendee');
1364
-        if ($attendee instanceof EE_Attendee) {
1365
-            if ($error) {
1366
-                return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1367
-            }
1368
-            $cur_status = $this->check_in_status_for_datetime($DTT_ID);
1369
-            //what is the status message going to be?
1370
-            switch ($cur_status) {
1371
-                case EE_Registration::checkin_status_never :
1372
-                    return sprintf(__("%s has been removed from Check-in records", "event_espresso"),
1373
-                        $attendee->full_name());
1374
-                    break;
1375
-                case EE_Registration::checkin_status_in :
1376
-                    return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1377
-                    break;
1378
-                case EE_Registration::checkin_status_out :
1379
-                    return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1380
-                    break;
1381
-            }
1382
-        }
1383
-        return __("The check-in status could not be determined.", "event_espresso");
1384
-    }
1385
-
1386
-
1387
-    /**
1388
-     * Returns the related EE_Transaction to this registration
1389
-     *
1390
-     * @return EE_Transaction
1391
-     */
1392
-    public function transaction()
1393
-    {
1394
-        $transaction = $this->get_first_related('Transaction');
1395
-        if (! $transaction instanceof \EE_Transaction) {
1396
-            throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1397
-        }
1398
-        return $transaction;
1399
-    }
1400
-
1401
-
1402
-    /**
1403
-     *        get Registration Code
1404
-     */
1405
-    public function reg_code()
1406
-    {
1407
-        return $this->get('REG_code');
1408
-    }
1409
-
1410
-
1411
-    /**
1412
-     *        get Transaction ID
1413
-     */
1414
-    public function transaction_ID()
1415
-    {
1416
-        return $this->get('TXN_ID');
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     * @return int
1422
-     */
1423
-    public function ticket_ID()
1424
-    {
1425
-        return $this->get('TKT_ID');
1426
-    }
1427
-
1428
-
1429
-    /**
1430
-     *        Set Registration Code
1431
-     *
1432
-     * @access    public
1433
-     * @param    string  $REG_code Registration Code
1434
-     * @param    boolean $use_default
1435
-     */
1436
-    public function set_reg_code($REG_code, $use_default = false)
1437
-    {
1438
-        if (empty($REG_code)) {
1439
-            EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1440
-            return;
1441
-        }
1442
-        if (! $this->reg_code()) {
1443
-            parent::set('REG_code', $REG_code, $use_default);
1444
-        } else {
1445
-            EE_Error::doing_it_wrong(
1446
-                __CLASS__ . '::' . __FUNCTION__,
1447
-                __('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1448
-                '4.6.0'
1449
-            );
1450
-        }
1451
-    }
1452
-
1453
-
1454
-    /**
1455
-     * Returns all other registrations in the same group as this registrant who have the same ticket option.
1456
-     * Note, if you want to just get all registrations in the same transaction (group), use:
1457
-     *    $registration->transaction()->registrations();
1458
-     *
1459
-     * @since 4.5.0
1460
-     * @return EE_Registration[]  or empty array if this isn't a group registration.
1461
-     */
1462
-    public function get_all_other_registrations_in_group()
1463
-    {
1464
-        if ($this->group_size() < 2) {
1465
-            return array();
1466
-        }
1467
-
1468
-        $query[0] = array(
1469
-            'TXN_ID' => $this->transaction_ID(),
1470
-            'REG_ID' => array('!=', $this->ID()),
1471
-            'TKT_ID' => $this->ticket_ID(),
1472
-        );
1473
-
1474
-        $registrations = $this->get_model()->get_all($query);
1475
-        return $registrations;
1476
-    }
1477
-
1478
-    /**
1479
-     * Return the link to the admin details for the object.
1480
-     *
1481
-     * @return string
1482
-     */
1483
-    public function get_admin_details_link()
1484
-    {
1485
-        EE_Registry::instance()->load_helper('URL');
1486
-        return EEH_URL::add_query_args_and_nonce(
1487
-            array(
1488
-                'page'    => 'espresso_registrations',
1489
-                'action'  => 'view_registration',
1490
-                '_REG_ID' => $this->ID(),
1491
-            ),
1492
-            admin_url('admin.php')
1493
-        );
1494
-    }
1495
-
1496
-    /**
1497
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1498
-     *
1499
-     * @return string
1500
-     */
1501
-    public function get_admin_edit_link()
1502
-    {
1503
-        return $this->get_admin_details_link();
1504
-    }
1505
-
1506
-    /**
1507
-     * Returns the link to a settings page for the object.
1508
-     *
1509
-     * @return string
1510
-     */
1511
-    public function get_admin_settings_link()
1512
-    {
1513
-        return $this->get_admin_details_link();
1514
-    }
1515
-
1516
-    /**
1517
-     * Returns the link to the "overview" for the object (typically the "list table" view).
1518
-     *
1519
-     * @return string
1520
-     */
1521
-    public function get_admin_overview_link()
1522
-    {
1523
-        EE_Registry::instance()->load_helper('URL');
1524
-        return EEH_URL::add_query_args_and_nonce(
1525
-            array(
1526
-                'page' => 'espresso_registrations',
1527
-            ),
1528
-            admin_url('admin.php')
1529
-        );
1530
-    }
1531
-
1532
-
1533
-    /**
1534
-     * @param array $query_params
1535
-     * @return \EE_Registration[]
1536
-     * @throws \EE_Error
1537
-     */
1538
-    public function payments($query_params = array())
1539
-    {
1540
-        return $this->get_many_related('Payment', $query_params);
1541
-    }
1542
-
1543
-
1544
-    /**
1545
-     * @param array $query_params
1546
-     * @return \EE_Registration_Payment[]
1547
-     * @throws \EE_Error
1548
-     */
1549
-    public function registration_payments($query_params = array())
1550
-    {
1551
-        return $this->get_many_related('Registration_Payment', $query_params);
1552
-    }
1553
-
1554
-
1555
-    /**
1556
-     * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1557
-     * Note: if there are no payments on the registration there will be no payment method returned.
1558
-     *
1559
-     * @return EE_Payment_Method|null
1560
-     */
1561
-    public function payment_method()
1562
-    {
1563
-        return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1564
-    }
1565
-
1566
-
1567
-    /**
1568
-     * @return \EE_Line_Item
1569
-     * @throws EntityNotFoundException
1570
-     * @throws \EE_Error
1571
-     */
1572
-    public function ticket_line_item()
1573
-    {
1574
-        $ticket            = $this->ticket();
1575
-        $transaction       = $this->transaction();
1576
-        $line_item         = null;
1577
-        $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1578
-            $transaction->total_line_item(),
1579
-            'Ticket',
1580
-            array($ticket->ID())
1581
-        );
1582
-        foreach ($ticket_line_items as $ticket_line_item) {
1583
-            if (
1584
-                $ticket_line_item instanceof \EE_Line_Item
1585
-                && $ticket_line_item->OBJ_type() === 'Ticket'
1586
-                && $ticket_line_item->OBJ_ID() === $ticket->ID()
1587
-            ) {
1588
-                $line_item = $ticket_line_item;
1589
-                break;
1590
-            }
1591
-        }
1592
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1593
-            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1594
-        }
1595
-        return $line_item;
1596
-    }
1597
-
1598
-
1599
-    /**
1600
-     * Soft Deletes this model object.
1601
-     *
1602
-     * @return boolean | int
1603
-     * @throws \RuntimeException
1604
-     * @throws \EE_Error
1605
-     */
1606
-    public function delete()
1607
-    {
1608
-        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1609
-            $this->set_status(EEM_Registration::status_id_cancelled);
1610
-        }
1611
-        return parent::delete();
1612
-    }
1613
-
1614
-
1615
-    /**
1616
-     * Restores whatever the previous status was on a registration before it was trashed (if possible)
1617
-     *
1618
-     * @throws \EE_Error
1619
-     * @throws \RuntimeException
1620
-     */
1621
-    public function restore()
1622
-    {
1623
-        $previous_status = $this->get_extra_meta(
1624
-            EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1625
-            true,
1626
-            EEM_Registration::status_id_cancelled
1627
-        );
1628
-        if ($previous_status) {
1629
-            $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1630
-            $this->set_status($previous_status);
1631
-        }
1632
-        return parent::restore();
1633
-    }
1634
-
1635
-
1636
-
1637
-    /*************************** DEPRECATED ***************************/
1638
-
1639
-
1640
-    /**
1641
-     * @deprecated
1642
-     * @since     4.7.0
1643
-     * @access    public
1644
-     */
1645
-    public function price_paid()
1646
-    {
1647
-        EE_Error::doing_it_wrong('EE_Registration::price_paid()',
1648
-            __('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'),
1649
-            '4.7.0');
1650
-        return $this->final_price();
1651
-    }
1652
-
1653
-
1654
-    /**
1655
-     * @deprecated
1656
-     * @since     4.7.0
1657
-     * @access    public
1658
-     * @param    float $REG_final_price
1659
-     */
1660
-    public function set_price_paid($REG_final_price = 0.00)
1661
-    {
1662
-        EE_Error::doing_it_wrong('EE_Registration::set_price_paid()',
1663
-            __('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'),
1664
-            '4.7.0');
1665
-        $this->set_final_price($REG_final_price);
1666
-    }
1667
-
1668
-
1669
-    /**
1670
-     * @deprecated
1671
-     * @since 4.7.0
1672
-     * @return string
1673
-     */
1674
-    public function pretty_price_paid()
1675
-    {
1676
-        EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()',
1677
-            __('This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
1678
-                'event_espresso'), '4.7.0');
1679
-        return $this->pretty_final_price();
1680
-    }
1681
-
1682
-
1683
-    /**
1684
-     * Gets the primary datetime related to this registration via the related Event to this registration
1685
-     *
1686
-     * @deprecated 4.9.17
1687
-     * @return EE_Datetime
1688
-     */
1689
-    public function get_related_primary_datetime()
1690
-    {
1691
-        EE_Error::doing_it_wrong(
1692
-            __METHOD__,
1693
-            esc_html__(
1694
-                'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
1695
-                'event_espresso'
1696
-            ),
1697
-            '4.9.17',
1698
-            '5.0.0'
1699
-        );
1700
-        return $this->event()->primary_datetime();
1701
-    }
18
+	/**
19
+	 * Used to reference when a registration has never been checked in.
20
+	 *
21
+	 * @type int
22
+	 */
23
+	const checkin_status_never = 2;
24
+
25
+	/**
26
+	 * Used to reference when a registration has been checked in.
27
+	 *
28
+	 * @type int
29
+	 */
30
+	const checkin_status_in = 1;
31
+
32
+
33
+	/**
34
+	 * Used to reference when a registration has been checked out.
35
+	 *
36
+	 * @type int
37
+	 */
38
+	const checkin_status_out = 0;
39
+
40
+
41
+	/**
42
+	 * extra meta key for tracking reg status os trashed registrations
43
+	 *
44
+	 * @type string
45
+	 */
46
+	const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
47
+
48
+
49
+	/**
50
+	 * extra meta key for tracking if registration has reserved ticket
51
+	 *
52
+	 * @type string
53
+	 */
54
+	const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
55
+
56
+
57
+	/**
58
+	 * @param array  $props_n_values          incoming values
59
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
60
+	 *                                        used.)
61
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
62
+	 *                                        date_format and the second value is the time format
63
+	 * @return EE_Registration
64
+	 */
65
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
66
+	{
67
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
68
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param array  $props_n_values  incoming values from the database
74
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
75
+	 *                                the website will be used.
76
+	 * @return EE_Registration
77
+	 */
78
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
79
+	{
80
+		return new self($props_n_values, true, $timezone);
81
+	}
82
+
83
+
84
+	/**
85
+	 *        Set Event ID
86
+	 *
87
+	 * @param        int $EVT_ID Event ID
88
+	 */
89
+	public function set_event($EVT_ID = 0)
90
+	{
91
+		$this->set('EVT_ID', $EVT_ID);
92
+	}
93
+
94
+
95
+	/**
96
+	 * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
97
+	 * be routed to internal methods
98
+	 *
99
+	 * @param string $field_name
100
+	 * @param mixed  $field_value
101
+	 * @param bool   $use_default
102
+	 * @throws \EE_Error
103
+	 * @throws \RuntimeException
104
+	 */
105
+	public function set($field_name, $field_value, $use_default = false)
106
+	{
107
+		switch ($field_name) {
108
+			case 'REG_code' :
109
+				if (! empty($field_value) && $this->reg_code() === null) {
110
+					$this->set_reg_code($field_value, $use_default);
111
+				}
112
+				break;
113
+			case 'STS_ID' :
114
+				$this->set_status($field_value, $use_default);
115
+				break;
116
+			default :
117
+				parent::set($field_name, $field_value, $use_default);
118
+		}
119
+	}
120
+
121
+
122
+	/**
123
+	 * Set Status ID
124
+	 * updates the registration status and ALSO...
125
+	 * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
126
+	 * calls release_registration_space() if the reg status changes FROM approved to any other reg status
127
+	 *
128
+	 * @param string  $new_STS_ID
129
+	 * @param boolean $use_default
130
+	 * @return bool
131
+	 * @throws \RuntimeException
132
+	 * @throws \EE_Error
133
+	 */
134
+	public function set_status($new_STS_ID = null, $use_default = false)
135
+	{
136
+		// get current REG_Status
137
+		$old_STS_ID = $this->status_ID();
138
+		// if status has changed
139
+		if (
140
+			$old_STS_ID !== $new_STS_ID // and that status has actually changed
141
+			&& ! empty($old_STS_ID) // and that old status is actually set
142
+			&& ! empty($new_STS_ID) // as well as the new status
143
+			&& $this->ID() // ensure registration is in the db
144
+		) {
145
+			// TO approved
146
+			if ($new_STS_ID === EEM_Registration::status_id_approved) {
147
+				// reserve a space by incrementing ticket and datetime sold values
148
+				$this->_reserve_registration_space();
149
+				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID);
150
+				// OR FROM  approved
151
+			} else if ($old_STS_ID === EEM_Registration::status_id_approved) {
152
+				// release a space by decrementing ticket and datetime sold values
153
+				$this->_release_registration_space();
154
+				do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID);
155
+			}
156
+			// update status
157
+			parent::set('STS_ID', $new_STS_ID, $use_default);
158
+			$this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
159
+			/** @type EE_Transaction_Payments $transaction_payments */
160
+			$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
161
+			$transaction_payments->recalculate_transaction_total($this->transaction(), false);
162
+			$this->transaction()->update_status_based_on_total_paid(true);
163
+			do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID);
164
+			return true;
165
+		}
166
+		//even though the old value matches the new value, it's still good to
167
+		//allow the parent set method to have a say
168
+		parent::set('STS_ID', $new_STS_ID, $use_default);
169
+		return true;
170
+	}
171
+
172
+
173
+	/**
174
+	 * update REGs and TXN when cancelled or declined registrations involved
175
+	 *
176
+	 * @param string $new_STS_ID
177
+	 * @param string $old_STS_ID
178
+	 * @throws \EE_Error
179
+	 */
180
+	private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID)
181
+	{
182
+		// these reg statuses should not be considered in any calculations involving monies owing
183
+		$closed_reg_statuses = EEM_Registration::closed_reg_statuses();
184
+		// true if registration has been cancelled or declined
185
+		if (
186
+			in_array($new_STS_ID, $closed_reg_statuses, true)
187
+			&& ! in_array($old_STS_ID, $closed_reg_statuses, true)
188
+		) {
189
+			/** @type EE_Registration_Processor $registration_processor */
190
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
191
+			/** @type EE_Transaction_Processor $transaction_processor */
192
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
193
+			// cancelled or declined registration
194
+			$registration_processor->update_registration_after_being_canceled_or_declined(
195
+				$this,
196
+				$closed_reg_statuses
197
+			);
198
+			$transaction_processor->update_transaction_after_canceled_or_declined_registration(
199
+				$this,
200
+				$closed_reg_statuses,
201
+				false
202
+			);
203
+			do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID);
204
+			return;
205
+		}
206
+		// true if reinstating cancelled or declined registration
207
+		if (
208
+			in_array($old_STS_ID, $closed_reg_statuses, true)
209
+			&& ! in_array($new_STS_ID, $closed_reg_statuses, true)
210
+		) {
211
+			/** @type EE_Registration_Processor $registration_processor */
212
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
213
+			/** @type EE_Transaction_Processor $transaction_processor */
214
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
215
+			// reinstating cancelled or declined registration
216
+			$registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
217
+				$this,
218
+				$closed_reg_statuses
219
+			);
220
+			$transaction_processor->update_transaction_after_reinstating_canceled_registration(
221
+				$this,
222
+				$closed_reg_statuses,
223
+				false
224
+			);
225
+			do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID);
226
+		}
227
+	}
228
+
229
+
230
+	/**
231
+	 *        get Status ID
232
+	 */
233
+	public function status_ID()
234
+	{
235
+		return $this->get('STS_ID');
236
+	}
237
+
238
+
239
+	/**
240
+	 * increments this registration's related ticket sold and corresponding datetime sold values
241
+	 *
242
+	 * @return void
243
+	 * @throws \EE_Error
244
+	 */
245
+	private function _reserve_registration_space()
246
+	{
247
+		// reserved ticket and datetime counts will be decremented as sold counts are incremented
248
+		// so stop tracking that this reg has a ticket reserved
249
+		$this->release_reserved_ticket();
250
+		$ticket = $this->ticket();
251
+		$ticket->increase_sold();
252
+		$ticket->save();
253
+		// possibly set event status to sold out
254
+		$this->event()->perform_sold_out_status_check();
255
+	}
256
+
257
+
258
+	/**
259
+	 * Gets the ticket this registration is for
260
+	 *
261
+	 * @param boolean $include_archived whether to include archived tickets or not.
262
+	 * @return EE_Ticket|EE_Base_Class
263
+	 * @throws \EE_Error
264
+	 */
265
+	public function ticket($include_archived = true)
266
+	{
267
+		$query_params = array();
268
+		if ($include_archived) {
269
+			$query_params['default_where_conditions'] = 'none';
270
+		}
271
+		return $this->get_first_related('Ticket', $query_params);
272
+	}
273
+
274
+
275
+	/**
276
+	 * Gets the event this registration is for
277
+	 *
278
+	 * @return EE_Event
279
+	 */
280
+	public function event()
281
+	{
282
+		$event = $this->get_first_related('Event');
283
+		if (! $event instanceof \EE_Event) {
284
+			throw new EntityNotFoundException('Event ID', $this->event_ID());
285
+		}
286
+		return $event;
287
+	}
288
+
289
+
290
+	/**
291
+	 * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
292
+	 * with the author of the event this registration is for.
293
+	 *
294
+	 * @since 4.5.0
295
+	 * @return int
296
+	 */
297
+	public function wp_user()
298
+	{
299
+		$event = $this->event();
300
+		if ($event instanceof EE_Event) {
301
+			return $event->wp_user();
302
+		}
303
+		return 0;
304
+	}
305
+
306
+
307
+	/**
308
+	 * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
309
+	 *
310
+	 * @return void
311
+	 * @throws \EE_Error
312
+	 */
313
+	private function _release_registration_space()
314
+	{
315
+		$ticket = $this->ticket();
316
+		$ticket->decrease_sold();
317
+		$ticket->save();
318
+	}
319
+
320
+
321
+	/**
322
+	 * tracks this registration's ticket reservation in extra meta
323
+	 * and can increment related ticket reserved and corresponding datetime reserved values
324
+	 *
325
+	 * @param bool $update_ticket if true, will increment ticket and datetime reserved count
326
+	 * @return void
327
+	 * @throws \EE_Error
328
+	 */
329
+	public function reserve_ticket($update_ticket = false)
330
+	{
331
+		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) {
332
+			// PLZ NOTE: although checking $update_ticket first would be more efficient,
333
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
334
+			if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) {
335
+				$ticket = $this->ticket();
336
+				$ticket->increase_reserved();
337
+				$ticket->save();
338
+			}
339
+		}
340
+	}
341
+
342
+
343
+	/**
344
+	 * stops tracking this registration's ticket reservation in extra meta
345
+	 * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
346
+	 *
347
+	 * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
348
+	 * @return void
349
+	 * @throws \EE_Error
350
+	 */
351
+	public function release_reserved_ticket($update_ticket = false)
352
+	{
353
+		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) {
354
+			// PLZ NOTE: although checking $update_ticket first would be more efficient,
355
+			// we NEED to ALWAYS call delete_extra_meta(), which is why that is done first
356
+			if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) {
357
+				$ticket = $this->ticket();
358
+				$ticket->decrease_reserved();
359
+				$ticket->save();
360
+			}
361
+		}
362
+	}
363
+
364
+
365
+	/**
366
+	 * Set Attendee ID
367
+	 *
368
+	 * @param        int $ATT_ID Attendee ID
369
+	 */
370
+	public function set_attendee_id($ATT_ID = 0)
371
+	{
372
+		$this->set('ATT_ID', $ATT_ID);
373
+	}
374
+
375
+
376
+	/**
377
+	 *        Set Transaction ID
378
+	 *
379
+	 * @param        int $TXN_ID Transaction ID
380
+	 */
381
+	public function set_transaction_id($TXN_ID = 0)
382
+	{
383
+		$this->set('TXN_ID', $TXN_ID);
384
+	}
385
+
386
+
387
+	/**
388
+	 *        Set Session
389
+	 *
390
+	 * @param    string $REG_session PHP Session ID
391
+	 */
392
+	public function set_session($REG_session = '')
393
+	{
394
+		$this->set('REG_session', $REG_session);
395
+	}
396
+
397
+
398
+	/**
399
+	 *        Set Registration URL Link
400
+	 *
401
+	 * @param    string $REG_url_link Registration URL Link
402
+	 */
403
+	public function set_reg_url_link($REG_url_link = '')
404
+	{
405
+		$this->set('REG_url_link', $REG_url_link);
406
+	}
407
+
408
+
409
+	/**
410
+	 *        Set Attendee Counter
411
+	 *
412
+	 * @param        int $REG_count Primary Attendee
413
+	 */
414
+	public function set_count($REG_count = 1)
415
+	{
416
+		$this->set('REG_count', $REG_count);
417
+	}
418
+
419
+
420
+	/**
421
+	 *        Set Group Size
422
+	 *
423
+	 * @param        boolean $REG_group_size Group Registration
424
+	 */
425
+	public function set_group_size($REG_group_size = false)
426
+	{
427
+		$this->set('REG_group_size', $REG_group_size);
428
+	}
429
+
430
+
431
+	/**
432
+	 *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
433
+	 *    EEM_Registration::status_id_not_approved
434
+	 *
435
+	 * @return        boolean
436
+	 */
437
+	public function is_not_approved()
438
+	{
439
+		return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
440
+	}
441
+
442
+
443
+	/**
444
+	 *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
445
+	 *    EEM_Registration::status_id_pending_payment
446
+	 *
447
+	 * @return        boolean
448
+	 */
449
+	public function is_pending_payment()
450
+	{
451
+		return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
452
+	}
453
+
454
+
455
+	/**
456
+	 *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
457
+	 *
458
+	 * @return        boolean
459
+	 */
460
+	public function is_approved()
461
+	{
462
+		return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
463
+	}
464
+
465
+
466
+	/**
467
+	 *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
468
+	 *
469
+	 * @return        boolean
470
+	 */
471
+	public function is_cancelled()
472
+	{
473
+		return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
474
+	}
475
+
476
+
477
+	/**
478
+	 *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
479
+	 *
480
+	 * @return        boolean
481
+	 */
482
+	public function is_declined()
483
+	{
484
+		return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
485
+	}
486
+
487
+
488
+	/**
489
+	 *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
490
+	 *    EEM_Registration::status_id_incomplete
491
+	 *
492
+	 * @return        boolean
493
+	 */
494
+	public function is_incomplete()
495
+	{
496
+		return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
497
+	}
498
+
499
+
500
+	/**
501
+	 *        Set Registration Date
502
+	 *
503
+	 * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
504
+	 *                       Date
505
+	 */
506
+	public function set_reg_date($REG_date = false)
507
+	{
508
+		$this->set('REG_date', $REG_date);
509
+	}
510
+
511
+
512
+	/**
513
+	 *    Set final price owing for this registration after all ticket/price modifications
514
+	 *
515
+	 * @access    public
516
+	 * @param    float $REG_final_price
517
+	 */
518
+	public function set_final_price($REG_final_price = 0.00)
519
+	{
520
+		$this->set('REG_final_price', $REG_final_price);
521
+	}
522
+
523
+
524
+	/**
525
+	 *    Set amount paid towards this registration's final price
526
+	 *
527
+	 * @access    public
528
+	 * @param    float $REG_paid
529
+	 */
530
+	public function set_paid($REG_paid = 0.00)
531
+	{
532
+		$this->set('REG_paid', $REG_paid);
533
+	}
534
+
535
+
536
+	/**
537
+	 *        Attendee Is Going
538
+	 *
539
+	 * @param        boolean $REG_att_is_going Attendee Is Going
540
+	 */
541
+	public function set_att_is_going($REG_att_is_going = false)
542
+	{
543
+		$this->set('REG_att_is_going', $REG_att_is_going);
544
+	}
545
+
546
+
547
+	/**
548
+	 * Gets the related attendee
549
+	 *
550
+	 * @return EE_Attendee
551
+	 */
552
+	public function attendee()
553
+	{
554
+		return $this->get_first_related('Attendee');
555
+	}
556
+
557
+
558
+	/**
559
+	 *        get Event ID
560
+	 */
561
+	public function event_ID()
562
+	{
563
+		return $this->get('EVT_ID');
564
+	}
565
+
566
+
567
+	/**
568
+	 *        get Event ID
569
+	 */
570
+	public function event_name()
571
+	{
572
+		$event = $this->event_obj();
573
+		if ($event) {
574
+			return $event->name();
575
+		} else {
576
+			return null;
577
+		}
578
+	}
579
+
580
+
581
+	/**
582
+	 * Fetches the event this registration is for
583
+	 *
584
+	 * @return EE_Event
585
+	 */
586
+	public function event_obj()
587
+	{
588
+		return $this->get_first_related('Event');
589
+	}
590
+
591
+
592
+	/**
593
+	 *        get Attendee ID
594
+	 */
595
+	public function attendee_ID()
596
+	{
597
+		return $this->get('ATT_ID');
598
+	}
599
+
600
+
601
+	/**
602
+	 *        get PHP Session ID
603
+	 */
604
+	public function session_ID()
605
+	{
606
+		return $this->get('REG_session');
607
+	}
608
+
609
+
610
+	/**
611
+	 * Gets the string which represents the URL trigger for the receipt template in the message template system.
612
+	 *
613
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
614
+	 * @return string
615
+	 */
616
+	public function receipt_url($messenger = 'html')
617
+	{
618
+
619
+		/**
620
+		 * The below will be deprecated one version after this.  We check first if there is a custom receipt template already in use on old system.  If there is then we just return the standard url for it.
621
+		 *
622
+		 * @since 4.5.0
623
+		 */
624
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
625
+		$has_custom             = EEH_Template::locate_template($template_relative_path, array(), true, true, true);
626
+
627
+		if ($has_custom) {
628
+			return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
629
+		}
630
+		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
631
+	}
632
+
633
+
634
+	/**
635
+	 * Gets the string which represents the URL trigger for the invoice template in the message template system.
636
+	 *
637
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
638
+	 * @return string
639
+	 */
640
+	public function invoice_url($messenger = 'html')
641
+	{
642
+		/**
643
+		 * The below will be deprecated one version after this.  We check first if there is a custom invoice template already in use on old system.  If there is then we just return the standard url for it.
644
+		 *
645
+		 * @since 4.5.0
646
+		 */
647
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
648
+		$has_custom             = EEH_Template::locate_template($template_relative_path, array(), true, true, true);
649
+
650
+		if ($has_custom) {
651
+			if ($messenger == 'html') {
652
+				return $this->invoice_url('launch');
653
+			}
654
+			$route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
655
+
656
+			$query_args = array('ee' => $route, 'id' => $this->reg_url_link());
657
+			if ($messenger == 'html') {
658
+				$query_args['html'] = true;
659
+			}
660
+			return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
661
+		}
662
+		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
663
+	}
664
+
665
+
666
+	/**
667
+	 * get Registration URL Link
668
+	 *
669
+	 * @access public
670
+	 * @return string
671
+	 * @throws \EE_Error
672
+	 */
673
+	public function reg_url_link()
674
+	{
675
+		return (string)$this->get('REG_url_link');
676
+	}
677
+
678
+
679
+	/**
680
+	 * Echoes out invoice_url()
681
+	 *
682
+	 * @param string $type 'download','launch', or 'html' (default is 'launch')
683
+	 * @return void
684
+	 */
685
+	public function e_invoice_url($type = 'launch')
686
+	{
687
+		echo $this->invoice_url($type);
688
+	}
689
+
690
+
691
+	/**
692
+	 * Echoes out payment_overview_url
693
+	 */
694
+	public function e_payment_overview_url()
695
+	{
696
+		echo $this->payment_overview_url();
697
+	}
698
+
699
+
700
+	/**
701
+	 * Gets the URL of the thank you page with this registration REG_url_link added as
702
+	 * a query parameter
703
+	 *
704
+	 * @return string
705
+	 */
706
+	public function payment_overview_url()
707
+	{
708
+		return add_query_arg(array(
709
+			'e_reg_url_link' => $this->reg_url_link(),
710
+			'step'           => 'payment_options',
711
+			'revisit'        => true,
712
+		), EE_Registry::instance()->CFG->core->reg_page_url());
713
+	}
714
+
715
+
716
+	/**
717
+	 * Gets the URL of the thank you page with this registration REG_url_link added as
718
+	 * a query parameter
719
+	 *
720
+	 * @return string
721
+	 */
722
+	public function edit_attendee_information_url()
723
+	{
724
+		return add_query_arg(array(
725
+			'e_reg_url_link' => $this->reg_url_link(),
726
+			'step'           => 'attendee_information',
727
+			'revisit'        => true,
728
+		), EE_Registry::instance()->CFG->core->reg_page_url());
729
+	}
730
+
731
+
732
+	/**
733
+	 * Simply generates and returns the appropriate admin_url link to edit this registration
734
+	 *
735
+	 * @return string
736
+	 */
737
+	public function get_admin_edit_url()
738
+	{
739
+		return EEH_URL::add_query_args_and_nonce(array(
740
+			'page'    => 'espresso_registrations',
741
+			'action'  => 'view_registration',
742
+			'_REG_ID' => $this->ID(),
743
+		), admin_url('admin.php'));
744
+	}
745
+
746
+
747
+	/**
748
+	 *    is_primary_registrant?
749
+	 */
750
+	public function is_primary_registrant()
751
+	{
752
+		return $this->get('REG_count') == 1 ? true : false;
753
+	}
754
+
755
+
756
+	/**
757
+	 * This returns the primary registration object for this registration group (which may be this object).
758
+	 *
759
+	 * @return EE_Registration
760
+	 */
761
+	public function get_primary_registration()
762
+	{
763
+		if ($this->is_primary_registrant()) {
764
+			return $this;
765
+		}
766
+
767
+		//k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
768
+		$primary_registrant = EEM_Registration::instance()->get_one(array(
769
+			array(
770
+				'TXN_ID'    => $this->transaction_ID(),
771
+				'REG_count' => 1,
772
+			),
773
+		));
774
+		return $primary_registrant;
775
+	}
776
+
777
+
778
+	/**
779
+	 *        get  Attendee Number
780
+	 *
781
+	 * @access        public
782
+	 */
783
+	public function count()
784
+	{
785
+		return $this->get('REG_count');
786
+	}
787
+
788
+
789
+	/**
790
+	 *        get Group Size
791
+	 */
792
+	public function group_size()
793
+	{
794
+		return $this->get('REG_group_size');
795
+	}
796
+
797
+
798
+	/**
799
+	 *        get Registration Date
800
+	 */
801
+	public function date()
802
+	{
803
+		return $this->get('REG_date');
804
+	}
805
+
806
+
807
+	/**
808
+	 * gets a pretty date
809
+	 *
810
+	 * @param string $date_format
811
+	 * @param string $time_format
812
+	 * @return string
813
+	 */
814
+	public function pretty_date($date_format = null, $time_format = null)
815
+	{
816
+		return $this->get_datetime('REG_date', $date_format, $time_format);
817
+	}
818
+
819
+
820
+	/**
821
+	 * final_price
822
+	 * the registration's share of the transaction total, so that the
823
+	 * sum of all the transaction's REG_final_prices equal the transaction's total
824
+	 *
825
+	 * @return    float
826
+	 */
827
+	public function final_price()
828
+	{
829
+		return $this->get('REG_final_price');
830
+	}
831
+
832
+
833
+	/**
834
+	 * pretty_final_price
835
+	 *  final price as formatted string, with correct decimal places and currency symbol
836
+	 *
837
+	 * @return string
838
+	 */
839
+	public function pretty_final_price()
840
+	{
841
+		return $this->get_pretty('REG_final_price');
842
+	}
843
+
844
+
845
+	/**
846
+	 * get paid (yeah)
847
+	 *
848
+	 * @return    float
849
+	 */
850
+	public function paid()
851
+	{
852
+		return $this->get('REG_paid');
853
+	}
854
+
855
+
856
+	/**
857
+	 * pretty_paid
858
+	 *
859
+	 * @return    float
860
+	 */
861
+	public function pretty_paid()
862
+	{
863
+		return $this->get_pretty('REG_paid');
864
+	}
865
+
866
+
867
+	/**
868
+	 * owes_monies_and_can_pay
869
+	 * whether or not this registration has monies owing and it's' status allows payment
870
+	 *
871
+	 * @param array $requires_payment
872
+	 * @return bool
873
+	 */
874
+	public function owes_monies_and_can_pay($requires_payment = array())
875
+	{
876
+		// these reg statuses require payment (if event is not free)
877
+		$requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment();
878
+		if (
879
+			in_array($this->status_ID(), $requires_payment) &&
880
+			$this->final_price() != 0 &&
881
+			$this->final_price() != $this->paid()
882
+		) {
883
+			return true;
884
+		} else {
885
+			return false;
886
+		}
887
+	}
888
+
889
+
890
+	/**
891
+	 * Prints out the return value of $this->pretty_status()
892
+	 *
893
+	 * @param bool $show_icons
894
+	 * @return void
895
+	 */
896
+	public function e_pretty_status($show_icons = false)
897
+	{
898
+		echo $this->pretty_status($show_icons);
899
+	}
900
+
901
+
902
+	/**
903
+	 * Returns a nice version of the status for displaying to customers
904
+	 *
905
+	 * @param bool $show_icons
906
+	 * @return string
907
+	 */
908
+	public function pretty_status($show_icons = false)
909
+	{
910
+		$status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')),
911
+			false, 'sentence');
912
+		$icon   = '';
913
+		switch ($this->status_ID()) {
914
+			case EEM_Registration::status_id_approved:
915
+				$icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : '';
916
+				break;
917
+			case EEM_Registration::status_id_pending_payment:
918
+				$icon = $show_icons ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' : '';
919
+				break;
920
+			case EEM_Registration::status_id_not_approved:
921
+				$icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' : '';
922
+				break;
923
+			case EEM_Registration::status_id_cancelled:
924
+				$icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' : '';
925
+				break;
926
+			case EEM_Registration::status_id_incomplete:
927
+				$icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' : '';
928
+				break;
929
+			case EEM_Registration::status_id_declined:
930
+				$icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : '';
931
+				break;
932
+			case EEM_Registration::status_id_wait_list:
933
+				$icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : '';
934
+				break;
935
+		}
936
+		return $icon . $status[$this->status_ID()];
937
+	}
938
+
939
+
940
+	/**
941
+	 *        get Attendee Is Going
942
+	 */
943
+	public function att_is_going()
944
+	{
945
+		return $this->get('REG_att_is_going');
946
+	}
947
+
948
+
949
+	/**
950
+	 * Gets related answers
951
+	 *
952
+	 * @param array $query_params like EEM_Base::get_all
953
+	 * @return EE_Answer[]
954
+	 */
955
+	public function answers($query_params = null)
956
+	{
957
+		return $this->get_many_related('Answer', $query_params);
958
+	}
959
+
960
+
961
+	/**
962
+	 * Gets the registration's answer value to the specified question
963
+	 * (either the question's ID or a question object)
964
+	 *
965
+	 * @param EE_Question|int $question
966
+	 * @param bool            $pretty_value
967
+	 * @return array|string if pretty_value= true, the result will always be a string
968
+	 * (because the answer might be an array of answer values, so passing pretty_value=true
969
+	 * will convert it into some kind of string)
970
+	 */
971
+	public function answer_value_to_question($question, $pretty_value = true)
972
+	{
973
+		$question_id = EEM_Question::instance()->ensure_is_ID($question);
974
+		return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
975
+	}
976
+
977
+
978
+	/**
979
+	 * question_groups
980
+	 * returns an array of EE_Question_Group objects for this registration
981
+	 *
982
+	 * @return EE_Question_Group[]
983
+	 */
984
+	public function question_groups()
985
+	{
986
+		$question_groups = array();
987
+		if ($this->event() instanceof EE_Event) {
988
+			$question_groups = $this->event()->question_groups(
989
+				array(
990
+					array(
991
+						'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
992
+					),
993
+					'order_by' => array('QSG_order' => 'ASC'),
994
+				)
995
+			);
996
+		}
997
+		return $question_groups;
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * count_question_groups
1003
+	 * returns a count of the number of EE_Question_Group objects for this registration
1004
+	 *
1005
+	 * @return int
1006
+	 */
1007
+	public function count_question_groups()
1008
+	{
1009
+		$qg_count = 0;
1010
+		if ($this->event() instanceof EE_Event) {
1011
+			$qg_count = $this->event()->count_related(
1012
+				'Question_Group',
1013
+				array(
1014
+					array(
1015
+						'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
1016
+					),
1017
+				)
1018
+			);
1019
+		}
1020
+		return $qg_count;
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * Returns the registration date in the 'standard' string format
1026
+	 * (function may be improved in the future to allow for different formats and timezones)
1027
+	 *
1028
+	 * @return string
1029
+	 */
1030
+	public function reg_date()
1031
+	{
1032
+		return $this->get_datetime('REG_date');
1033
+	}
1034
+
1035
+
1036
+	/**
1037
+	 * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1038
+	 * the ticket this registration purchased, or the datetime they have registered
1039
+	 * to attend)
1040
+	 *
1041
+	 * @return EE_Datetime_Ticket
1042
+	 */
1043
+	public function datetime_ticket()
1044
+	{
1045
+		return $this->get_first_related('Datetime_Ticket');
1046
+	}
1047
+
1048
+
1049
+	/**
1050
+	 * Sets the registration's datetime_ticket.
1051
+	 *
1052
+	 * @param EE_Datetime_Ticket $datetime_ticket
1053
+	 * @return EE_Datetime_Ticket
1054
+	 */
1055
+	public function set_datetime_ticket($datetime_ticket)
1056
+	{
1057
+		return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1058
+	}
1059
+
1060
+	/**
1061
+	 * Gets deleted
1062
+	 *
1063
+	 * @return boolean
1064
+	 */
1065
+	public function deleted()
1066
+	{
1067
+		return $this->get('REG_deleted');
1068
+	}
1069
+
1070
+	/**
1071
+	 * Sets deleted
1072
+	 *
1073
+	 * @param boolean $deleted
1074
+	 * @return boolean
1075
+	 */
1076
+	public function set_deleted($deleted)
1077
+	{
1078
+		if ($deleted) {
1079
+			$this->delete();
1080
+		} else {
1081
+			$this->restore();
1082
+		}
1083
+	}
1084
+
1085
+
1086
+	/**
1087
+	 * Get the status object of this object
1088
+	 *
1089
+	 * @return EE_Status
1090
+	 */
1091
+	public function status_obj()
1092
+	{
1093
+		return $this->get_first_related('Status');
1094
+	}
1095
+
1096
+
1097
+	/**
1098
+	 * Returns the number of times this registration has checked into any of the datetimes
1099
+	 * its available for
1100
+	 *
1101
+	 * @return int
1102
+	 */
1103
+	public function count_checkins()
1104
+	{
1105
+		return $this->get_model()->count_related($this, 'Checkin');
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1111
+	 * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1112
+	 *
1113
+	 * @return int
1114
+	 */
1115
+	public function count_checkins_not_checkedout()
1116
+	{
1117
+		return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1123
+	 *
1124
+	 * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1125
+	 * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1126
+	 *                                          consider registration status as well as datetime access.
1127
+	 * @return bool
1128
+	 */
1129
+	public function can_checkin($DTT_OR_ID, $check_approved = true)
1130
+	{
1131
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1132
+
1133
+		//first check registration status
1134
+		if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1135
+			return false;
1136
+		}
1137
+		//is there a datetime ticket that matches this dtt_ID?
1138
+		if (! (EEM_Datetime_Ticket::instance()->exists(array(
1139
+			array(
1140
+				'TKT_ID' => $this->get('TKT_ID'),
1141
+				'DTT_ID' => $DTT_ID,
1142
+			),
1143
+		)))
1144
+		) {
1145
+			return false;
1146
+		}
1147
+
1148
+		//final check is against TKT_uses
1149
+		return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1150
+	}
1151
+
1152
+
1153
+	/**
1154
+	 * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1155
+	 * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1156
+	 * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1157
+	 * then return false.  Otherwise return true.
1158
+	 *
1159
+	 * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1160
+	 * @return bool   true means can checkin.  false means cannot checkin.
1161
+	 */
1162
+	public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1163
+	{
1164
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1165
+
1166
+		if (! $DTT_ID) {
1167
+			return false;
1168
+		}
1169
+
1170
+		$max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1171
+
1172
+		// if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in
1173
+		// or not.
1174
+		if (! $max_uses || $max_uses === EE_INF) {
1175
+			return true;
1176
+		}
1177
+
1178
+		//does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1179
+		//go ahead and toggle.
1180
+		if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1181
+			return true;
1182
+		}
1183
+
1184
+		//made it here so the last check is whether the number of checkins per unique datetime on this registration
1185
+		//disallows further check-ins.
1186
+		$count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(
1187
+			array(
1188
+				'REG_ID' => $this->ID(),
1189
+				'CHK_in' => true,
1190
+			),
1191
+		), 'DTT_ID', true);
1192
+		// checkins have already reached their max number of uses
1193
+		// so registrant can NOT checkin
1194
+		if ($count_unique_dtt_checkins >= $max_uses) {
1195
+			EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1196
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1197
+			return false;
1198
+		}
1199
+		return true;
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * toggle Check-in status for this registration
1205
+	 * Check-ins are toggled in the following order:
1206
+	 * never checked in -> checked in
1207
+	 * checked in -> checked out
1208
+	 * checked out -> checked in
1209
+	 *
1210
+	 * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1211
+	 *                      If not included or null, then it is assumed latest datetime is being toggled.
1212
+	 * @param bool $verify  If true then can_checkin() is used to verify whether the person
1213
+	 *                      can be checked in or not.  Otherwise this forces change in checkin status.
1214
+	 * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1215
+	 * @throws EE_Error
1216
+	 */
1217
+	public function toggle_checkin_status($DTT_ID = null, $verify = false)
1218
+	{
1219
+		if (empty($DTT_ID)) {
1220
+			$datetime = $this->get_latest_related_datetime();
1221
+			$DTT_ID   = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1222
+			// verify the registration can checkin for the given DTT_ID
1223
+		} elseif (! $this->can_checkin($DTT_ID, $verify)) {
1224
+			EE_Error::add_error(
1225
+				sprintf(
1226
+					__('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1227
+						'event_espresso'),
1228
+					$this->ID(),
1229
+					$DTT_ID
1230
+				),
1231
+				__FILE__, __FUNCTION__, __LINE__
1232
+			);
1233
+			return false;
1234
+		}
1235
+		$status_paths = array(
1236
+			EE_Registration::checkin_status_never => EE_Registration::checkin_status_in,
1237
+			EE_Registration::checkin_status_in    => EE_Registration::checkin_status_out,
1238
+			EE_Registration::checkin_status_out   => EE_Registration::checkin_status_in,
1239
+		);
1240
+		//start by getting the current status so we know what status we'll be changing to.
1241
+		$cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1242
+		$status_to  = $status_paths[$cur_status];
1243
+		// database only records true for checked IN or false for checked OUT
1244
+		// no record ( null ) means checked in NEVER, but we obviously don't save that
1245
+		$new_status = $status_to === EE_Registration::checkin_status_in ? true : false;
1246
+		// add relation - note Check-ins are always creating new rows
1247
+		// because we are keeping track of Check-ins over time.
1248
+		// Eventually we'll probably want to show a list table
1249
+		// for the individual Check-ins so that they can be managed.
1250
+		$checkin = EE_Checkin::new_instance(array(
1251
+			'REG_ID' => $this->ID(),
1252
+			'DTT_ID' => $DTT_ID,
1253
+			'CHK_in' => $new_status,
1254
+		));
1255
+		// if the record could not be saved then return false
1256
+		if ($checkin->save() === 0) {
1257
+			if (WP_DEBUG) {
1258
+				global $wpdb;
1259
+				$error = sprintf(
1260
+					__('Registration check in update failed because of the following database error: %1$s%2$s',
1261
+						'event_espresso'),
1262
+					'<br />',
1263
+					$wpdb->last_error
1264
+				);
1265
+			} else {
1266
+				$error = __('Registration check in update failed because of an unknown database error',
1267
+					'event_espresso');
1268
+			}
1269
+			EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1270
+			return false;
1271
+		}
1272
+		return $status_to;
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1278
+	 * "Latest" is defined by the `DTT_EVT_start` column.
1279
+	 *
1280
+	 * @return EE_Datetime|null
1281
+	 * @throws \EE_Error
1282
+	 */
1283
+	public function get_latest_related_datetime()
1284
+	{
1285
+		return EEM_Datetime::instance()->get_one(
1286
+			array(
1287
+				array(
1288
+					'Ticket.Registration.REG_ID' => $this->ID(),
1289
+				),
1290
+				'order_by' => array('DTT_EVT_start' => 'DESC'),
1291
+			)
1292
+		);
1293
+	}
1294
+
1295
+
1296
+	/**
1297
+	 * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1298
+	 * "Earliest" is defined by the `DTT_EVT_start` column.
1299
+	 *
1300
+	 * @throws \EE_Error
1301
+	 */
1302
+	public function get_earliest_related_datetime()
1303
+	{
1304
+		return EEM_Datetime::instance()->get_one(
1305
+			array(
1306
+				array(
1307
+					'Ticket.Registration.REG_ID' => $this->ID(),
1308
+				),
1309
+				'order_by' => array('DTT_EVT_start' => 'ASC'),
1310
+			)
1311
+		);
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * This method simply returns the check-in status for this registration and the given datetime.
1317
+	 * If neither the datetime nor the checkin values are provided as arguments,
1318
+	 * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1319
+	 *
1320
+	 * @param  int       $DTT_ID  The ID of the datetime we're checking against
1321
+	 *                            (if empty we'll get the primary datetime for
1322
+	 *                            this registration (via event) and use it's ID);
1323
+	 * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1324
+	 * @return int                Integer representing Check-in status.
1325
+	 * @throws \EE_Error
1326
+	 */
1327
+	public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1328
+	{
1329
+		$checkin_query_params = array(
1330
+			'order_by' => array('CHK_timestamp' => 'DESC'),
1331
+		);
1332
+
1333
+		if ($DTT_ID > 0) {
1334
+			$checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1335
+		}
1336
+
1337
+		//get checkin object (if exists)
1338
+		$checkin = $checkin instanceof EE_Checkin
1339
+			? $checkin
1340
+			: $this->get_first_related('Checkin', $checkin_query_params);
1341
+		if ($checkin instanceof EE_Checkin) {
1342
+			if ($checkin->get('CHK_in')) {
1343
+				return EE_Registration::checkin_status_in; //checked in
1344
+			}
1345
+			return EE_Registration::checkin_status_out; //had checked in but is now checked out.
1346
+		}
1347
+		return EE_Registration::checkin_status_never; //never been checked in
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * This method returns a localized message for the toggled Check-in message.
1353
+	 *
1354
+	 * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1355
+	 *                     then it is assumed Check-in for primary datetime was toggled.
1356
+	 * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1357
+	 *                     message can be customized with the attendee name.
1358
+	 * @return string         internationalized message
1359
+	 */
1360
+	public function get_checkin_msg($DTT_ID, $error = false)
1361
+	{
1362
+		//let's get the attendee first so we can include the name of the attendee
1363
+		$attendee = $this->get_first_related('Attendee');
1364
+		if ($attendee instanceof EE_Attendee) {
1365
+			if ($error) {
1366
+				return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1367
+			}
1368
+			$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1369
+			//what is the status message going to be?
1370
+			switch ($cur_status) {
1371
+				case EE_Registration::checkin_status_never :
1372
+					return sprintf(__("%s has been removed from Check-in records", "event_espresso"),
1373
+						$attendee->full_name());
1374
+					break;
1375
+				case EE_Registration::checkin_status_in :
1376
+					return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1377
+					break;
1378
+				case EE_Registration::checkin_status_out :
1379
+					return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1380
+					break;
1381
+			}
1382
+		}
1383
+		return __("The check-in status could not be determined.", "event_espresso");
1384
+	}
1385
+
1386
+
1387
+	/**
1388
+	 * Returns the related EE_Transaction to this registration
1389
+	 *
1390
+	 * @return EE_Transaction
1391
+	 */
1392
+	public function transaction()
1393
+	{
1394
+		$transaction = $this->get_first_related('Transaction');
1395
+		if (! $transaction instanceof \EE_Transaction) {
1396
+			throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1397
+		}
1398
+		return $transaction;
1399
+	}
1400
+
1401
+
1402
+	/**
1403
+	 *        get Registration Code
1404
+	 */
1405
+	public function reg_code()
1406
+	{
1407
+		return $this->get('REG_code');
1408
+	}
1409
+
1410
+
1411
+	/**
1412
+	 *        get Transaction ID
1413
+	 */
1414
+	public function transaction_ID()
1415
+	{
1416
+		return $this->get('TXN_ID');
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 * @return int
1422
+	 */
1423
+	public function ticket_ID()
1424
+	{
1425
+		return $this->get('TKT_ID');
1426
+	}
1427
+
1428
+
1429
+	/**
1430
+	 *        Set Registration Code
1431
+	 *
1432
+	 * @access    public
1433
+	 * @param    string  $REG_code Registration Code
1434
+	 * @param    boolean $use_default
1435
+	 */
1436
+	public function set_reg_code($REG_code, $use_default = false)
1437
+	{
1438
+		if (empty($REG_code)) {
1439
+			EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1440
+			return;
1441
+		}
1442
+		if (! $this->reg_code()) {
1443
+			parent::set('REG_code', $REG_code, $use_default);
1444
+		} else {
1445
+			EE_Error::doing_it_wrong(
1446
+				__CLASS__ . '::' . __FUNCTION__,
1447
+				__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1448
+				'4.6.0'
1449
+			);
1450
+		}
1451
+	}
1452
+
1453
+
1454
+	/**
1455
+	 * Returns all other registrations in the same group as this registrant who have the same ticket option.
1456
+	 * Note, if you want to just get all registrations in the same transaction (group), use:
1457
+	 *    $registration->transaction()->registrations();
1458
+	 *
1459
+	 * @since 4.5.0
1460
+	 * @return EE_Registration[]  or empty array if this isn't a group registration.
1461
+	 */
1462
+	public function get_all_other_registrations_in_group()
1463
+	{
1464
+		if ($this->group_size() < 2) {
1465
+			return array();
1466
+		}
1467
+
1468
+		$query[0] = array(
1469
+			'TXN_ID' => $this->transaction_ID(),
1470
+			'REG_ID' => array('!=', $this->ID()),
1471
+			'TKT_ID' => $this->ticket_ID(),
1472
+		);
1473
+
1474
+		$registrations = $this->get_model()->get_all($query);
1475
+		return $registrations;
1476
+	}
1477
+
1478
+	/**
1479
+	 * Return the link to the admin details for the object.
1480
+	 *
1481
+	 * @return string
1482
+	 */
1483
+	public function get_admin_details_link()
1484
+	{
1485
+		EE_Registry::instance()->load_helper('URL');
1486
+		return EEH_URL::add_query_args_and_nonce(
1487
+			array(
1488
+				'page'    => 'espresso_registrations',
1489
+				'action'  => 'view_registration',
1490
+				'_REG_ID' => $this->ID(),
1491
+			),
1492
+			admin_url('admin.php')
1493
+		);
1494
+	}
1495
+
1496
+	/**
1497
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1498
+	 *
1499
+	 * @return string
1500
+	 */
1501
+	public function get_admin_edit_link()
1502
+	{
1503
+		return $this->get_admin_details_link();
1504
+	}
1505
+
1506
+	/**
1507
+	 * Returns the link to a settings page for the object.
1508
+	 *
1509
+	 * @return string
1510
+	 */
1511
+	public function get_admin_settings_link()
1512
+	{
1513
+		return $this->get_admin_details_link();
1514
+	}
1515
+
1516
+	/**
1517
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
1518
+	 *
1519
+	 * @return string
1520
+	 */
1521
+	public function get_admin_overview_link()
1522
+	{
1523
+		EE_Registry::instance()->load_helper('URL');
1524
+		return EEH_URL::add_query_args_and_nonce(
1525
+			array(
1526
+				'page' => 'espresso_registrations',
1527
+			),
1528
+			admin_url('admin.php')
1529
+		);
1530
+	}
1531
+
1532
+
1533
+	/**
1534
+	 * @param array $query_params
1535
+	 * @return \EE_Registration[]
1536
+	 * @throws \EE_Error
1537
+	 */
1538
+	public function payments($query_params = array())
1539
+	{
1540
+		return $this->get_many_related('Payment', $query_params);
1541
+	}
1542
+
1543
+
1544
+	/**
1545
+	 * @param array $query_params
1546
+	 * @return \EE_Registration_Payment[]
1547
+	 * @throws \EE_Error
1548
+	 */
1549
+	public function registration_payments($query_params = array())
1550
+	{
1551
+		return $this->get_many_related('Registration_Payment', $query_params);
1552
+	}
1553
+
1554
+
1555
+	/**
1556
+	 * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1557
+	 * Note: if there are no payments on the registration there will be no payment method returned.
1558
+	 *
1559
+	 * @return EE_Payment_Method|null
1560
+	 */
1561
+	public function payment_method()
1562
+	{
1563
+		return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1564
+	}
1565
+
1566
+
1567
+	/**
1568
+	 * @return \EE_Line_Item
1569
+	 * @throws EntityNotFoundException
1570
+	 * @throws \EE_Error
1571
+	 */
1572
+	public function ticket_line_item()
1573
+	{
1574
+		$ticket            = $this->ticket();
1575
+		$transaction       = $this->transaction();
1576
+		$line_item         = null;
1577
+		$ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1578
+			$transaction->total_line_item(),
1579
+			'Ticket',
1580
+			array($ticket->ID())
1581
+		);
1582
+		foreach ($ticket_line_items as $ticket_line_item) {
1583
+			if (
1584
+				$ticket_line_item instanceof \EE_Line_Item
1585
+				&& $ticket_line_item->OBJ_type() === 'Ticket'
1586
+				&& $ticket_line_item->OBJ_ID() === $ticket->ID()
1587
+			) {
1588
+				$line_item = $ticket_line_item;
1589
+				break;
1590
+			}
1591
+		}
1592
+		if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1593
+			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1594
+		}
1595
+		return $line_item;
1596
+	}
1597
+
1598
+
1599
+	/**
1600
+	 * Soft Deletes this model object.
1601
+	 *
1602
+	 * @return boolean | int
1603
+	 * @throws \RuntimeException
1604
+	 * @throws \EE_Error
1605
+	 */
1606
+	public function delete()
1607
+	{
1608
+		if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1609
+			$this->set_status(EEM_Registration::status_id_cancelled);
1610
+		}
1611
+		return parent::delete();
1612
+	}
1613
+
1614
+
1615
+	/**
1616
+	 * Restores whatever the previous status was on a registration before it was trashed (if possible)
1617
+	 *
1618
+	 * @throws \EE_Error
1619
+	 * @throws \RuntimeException
1620
+	 */
1621
+	public function restore()
1622
+	{
1623
+		$previous_status = $this->get_extra_meta(
1624
+			EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1625
+			true,
1626
+			EEM_Registration::status_id_cancelled
1627
+		);
1628
+		if ($previous_status) {
1629
+			$this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1630
+			$this->set_status($previous_status);
1631
+		}
1632
+		return parent::restore();
1633
+	}
1634
+
1635
+
1636
+
1637
+	/*************************** DEPRECATED ***************************/
1638
+
1639
+
1640
+	/**
1641
+	 * @deprecated
1642
+	 * @since     4.7.0
1643
+	 * @access    public
1644
+	 */
1645
+	public function price_paid()
1646
+	{
1647
+		EE_Error::doing_it_wrong('EE_Registration::price_paid()',
1648
+			__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'),
1649
+			'4.7.0');
1650
+		return $this->final_price();
1651
+	}
1652
+
1653
+
1654
+	/**
1655
+	 * @deprecated
1656
+	 * @since     4.7.0
1657
+	 * @access    public
1658
+	 * @param    float $REG_final_price
1659
+	 */
1660
+	public function set_price_paid($REG_final_price = 0.00)
1661
+	{
1662
+		EE_Error::doing_it_wrong('EE_Registration::set_price_paid()',
1663
+			__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'),
1664
+			'4.7.0');
1665
+		$this->set_final_price($REG_final_price);
1666
+	}
1667
+
1668
+
1669
+	/**
1670
+	 * @deprecated
1671
+	 * @since 4.7.0
1672
+	 * @return string
1673
+	 */
1674
+	public function pretty_price_paid()
1675
+	{
1676
+		EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()',
1677
+			__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
1678
+				'event_espresso'), '4.7.0');
1679
+		return $this->pretty_final_price();
1680
+	}
1681
+
1682
+
1683
+	/**
1684
+	 * Gets the primary datetime related to this registration via the related Event to this registration
1685
+	 *
1686
+	 * @deprecated 4.9.17
1687
+	 * @return EE_Datetime
1688
+	 */
1689
+	public function get_related_primary_datetime()
1690
+	{
1691
+		EE_Error::doing_it_wrong(
1692
+			__METHOD__,
1693
+			esc_html__(
1694
+				'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
1695
+				'event_espresso'
1696
+			),
1697
+			'4.9.17',
1698
+			'5.0.0'
1699
+		);
1700
+		return $this->event()->primary_datetime();
1701
+	}
1702 1702
 
1703 1703
 
1704 1704
 }
Please login to merge, or discard this patch.
modules/ticket_selector/DisplayTicketSelector.php 1 patch
Indentation   +675 added lines, -675 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 use WP_Post;
17 17
 
18 18
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
19
-    exit( 'No direct script access allowed' );
19
+	exit( 'No direct script access allowed' );
20 20
 }
21 21
 
22 22
 
@@ -33,683 +33,683 @@  discard block
 block discarded – undo
33 33
 class DisplayTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * event that ticket selector is being generated for
38
-     *
39
-     * @access protected
40
-     * @var EE_Event $event
41
-     */
42
-    protected $event;
43
-
44
-    /**
45
-     * Used to flag when the ticket selector is being called from an external iframe.
46
-     *
47
-     * @var bool $iframe
48
-     */
49
-    protected $iframe = false;
50
-
51
-    /**
52
-     * max attendees that can register for event at one time
53
-     *
54
-     * @var int $max_attendees
55
-     */
56
-    private $max_attendees = EE_INF;
57
-
58
-    /**
59
-     *@var string $date_format
60
-     */
61
-    private $date_format;
62
-
63
-    /**
64
-     *@var string $time_format
65
-     */
66
-    private $time_format;
67
-
68
-
69
-
70
-    /**
71
-     * DisplayTicketSelector constructor.
72
-     */
73
-    public function __construct()
74
-    {
75
-        $this->date_format = apply_filters(
76
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
77
-            get_option('date_format')
78
-        );
79
-        $this->time_format = apply_filters(
80
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
81
-            get_option('time_format')
82
-        );
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * @param boolean $iframe
89
-     */
90
-    public function setIframe( $iframe = true )
91
-    {
92
-        $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
93
-    }
94
-
95
-
96
-    /**
97
-     * finds and sets the \EE_Event object for use throughout class
98
-     *
99
-     * @param mixed $event
100
-     * @return bool
101
-     * @throws EE_Error
102
-     */
103
-    protected function setEvent( $event = null )
104
-    {
105
-        if ( $event === null ) {
106
-            global $post;
107
-            $event = $post;
108
-        }
109
-        if ( $event instanceof EE_Event ) {
110
-            $this->event = $event;
111
-        } else if ( $event instanceof WP_Post ) {
112
-            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
113
-                $this->event = $event->EE_Event;
114
-            } else if ( $event->post_type === 'espresso_events' ) {
115
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
116
-                $this->event = $event->EE_Event;
117
-            }
118
-        } else {
119
-            $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
120
-            $dev_msg = $user_msg . __(
121
-                    'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
122
-                    'event_espresso'
123
-                );
124
-            EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
125
-            return false;
126
-        }
127
-        return true;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return int
134
-     */
135
-    public function getMaxAttendees()
136
-    {
137
-        return $this->max_attendees;
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * @param int $max_attendees
144
-     */
145
-    public function setMaxAttendees($max_attendees)
146
-    {
147
-        $this->max_attendees = absint(
148
-            apply_filters(
149
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
150
-                $max_attendees
151
-            )
152
-        );
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * creates buttons for selecting number of attendees for an event
159
-     *
160
-     * @param WP_Post|int $event
161
-     * @param bool         $view_details
162
-     * @return string
163
-     * @throws EE_Error
164
-     */
165
-    public function display( $event = null, $view_details = false )
166
-    {
167
-        // reset filter for displaying submit button
168
-        remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
169
-        // poke and prod incoming event till it tells us what it is
170
-        if ( ! $this->setEvent( $event ) ) {
171
-            return false;
172
-        }
173
-        // begin gathering template arguments by getting event status
174
-        $template_args = array( 'event_status' => $this->event->get_active_status() );
175
-        if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
176
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
177
-        }
178
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
179
-        $this->setMaxAttendees($this->event->additional_limit());
180
-        if ($this->getMaxAttendees() < 1) {
181
-            return $this->ticketSalesClosedMessage();
182
-        }
183
-        // is the event expired ?
184
-        $template_args['event_is_expired'] = $this->event->is_expired();
185
-        if ( $template_args[ 'event_is_expired' ] ) {
186
-            return $this->expiredEventMessage();
187
-        }
188
-        // get all tickets for this event ordered by the datetime
189
-        $tickets = $this->getTickets();
190
-        if (count($tickets) < 1) {
191
-            return $this->noTicketAvailableMessage();
192
-        }
193
-        if (EED_Events_Archive::is_iframe()){
194
-            $this->setIframe();
195
-        }
196
-        // redirecting to another site for registration ??
197
-        $external_url = (string) $this->event->external_url();
198
-        // if redirecting to another site for registration, then we don't load the TS
199
-        $ticket_selector = $external_url
200
-            ? $this->externalEventRegistration()
201
-            : $this->loadTicketSelector($tickets,$template_args);
202
-        // now set up the form (but not for the admin)
203
-        $ticket_selector = ! is_admin()
204
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
205
-            : $ticket_selector;
206
-        // submit button and form close tag
207
-        $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
208
-        return $ticket_selector;
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     * displayTicketSelector
215
-     * examines the event properties and determines whether a Ticket Selector should be displayed
216
-     *
217
-     * @param WP_Post|int $event
218
-     * @param string       $_event_active_status
219
-     * @param bool         $view_details
220
-     * @return bool
221
-     * @throws EE_Error
222
-     */
223
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
224
-    {
225
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
226
-        return ! is_admin()
227
-               && (
228
-                   ! $this->event->display_ticket_selector()
229
-                   || $view_details
230
-                   || post_password_required($event_post)
231
-                   || (
232
-                       $_event_active_status !== EE_Datetime::active
233
-                       && $_event_active_status !== EE_Datetime::upcoming
234
-                       && $_event_active_status !== EE_Datetime::sold_out
235
-                       && ! (
236
-                           $_event_active_status === EE_Datetime::inactive
237
-                           && is_user_logged_in()
238
-                       )
239
-                   )
240
-               );
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * noTicketAvailableMessage
247
-     * notice displayed if event is expired
248
-     *
249
-     * @return string
250
-     * @throws EE_Error
251
-     */
252
-    protected function expiredEventMessage()
253
-    {
254
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
255
-            'We\'re sorry, but all tickets sales have ended because the event is expired.',
256
-            'event_espresso'
257
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * noTicketAvailableMessage
264
-     * notice displayed if event has no more tickets available
265
-     *
266
-     * @return string
267
-     * @throws EE_Error
268
-     */
269
-    protected function noTicketAvailableMessage()
270
-    {
271
-        $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
272
-        if (current_user_can('edit_post', $this->event->ID())) {
273
-            $no_ticket_available_msg .= sprintf(
274
-                esc_html__(
275
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
276
-                    'event_espresso'
277
-                ),
278
-                '<div class="ee-attention" style="text-align: left;"><b>',
279
-                '</b><br />',
280
-                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
281
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
282
-            );
283
-        }
284
-        return '
36
+	/**
37
+	 * event that ticket selector is being generated for
38
+	 *
39
+	 * @access protected
40
+	 * @var EE_Event $event
41
+	 */
42
+	protected $event;
43
+
44
+	/**
45
+	 * Used to flag when the ticket selector is being called from an external iframe.
46
+	 *
47
+	 * @var bool $iframe
48
+	 */
49
+	protected $iframe = false;
50
+
51
+	/**
52
+	 * max attendees that can register for event at one time
53
+	 *
54
+	 * @var int $max_attendees
55
+	 */
56
+	private $max_attendees = EE_INF;
57
+
58
+	/**
59
+	 *@var string $date_format
60
+	 */
61
+	private $date_format;
62
+
63
+	/**
64
+	 *@var string $time_format
65
+	 */
66
+	private $time_format;
67
+
68
+
69
+
70
+	/**
71
+	 * DisplayTicketSelector constructor.
72
+	 */
73
+	public function __construct()
74
+	{
75
+		$this->date_format = apply_filters(
76
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
77
+			get_option('date_format')
78
+		);
79
+		$this->time_format = apply_filters(
80
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
81
+			get_option('time_format')
82
+		);
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * @param boolean $iframe
89
+	 */
90
+	public function setIframe( $iframe = true )
91
+	{
92
+		$this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
93
+	}
94
+
95
+
96
+	/**
97
+	 * finds and sets the \EE_Event object for use throughout class
98
+	 *
99
+	 * @param mixed $event
100
+	 * @return bool
101
+	 * @throws EE_Error
102
+	 */
103
+	protected function setEvent( $event = null )
104
+	{
105
+		if ( $event === null ) {
106
+			global $post;
107
+			$event = $post;
108
+		}
109
+		if ( $event instanceof EE_Event ) {
110
+			$this->event = $event;
111
+		} else if ( $event instanceof WP_Post ) {
112
+			if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
113
+				$this->event = $event->EE_Event;
114
+			} else if ( $event->post_type === 'espresso_events' ) {
115
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
116
+				$this->event = $event->EE_Event;
117
+			}
118
+		} else {
119
+			$user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
120
+			$dev_msg = $user_msg . __(
121
+					'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
122
+					'event_espresso'
123
+				);
124
+			EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
125
+			return false;
126
+		}
127
+		return true;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return int
134
+	 */
135
+	public function getMaxAttendees()
136
+	{
137
+		return $this->max_attendees;
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * @param int $max_attendees
144
+	 */
145
+	public function setMaxAttendees($max_attendees)
146
+	{
147
+		$this->max_attendees = absint(
148
+			apply_filters(
149
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
150
+				$max_attendees
151
+			)
152
+		);
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * creates buttons for selecting number of attendees for an event
159
+	 *
160
+	 * @param WP_Post|int $event
161
+	 * @param bool         $view_details
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 */
165
+	public function display( $event = null, $view_details = false )
166
+	{
167
+		// reset filter for displaying submit button
168
+		remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
169
+		// poke and prod incoming event till it tells us what it is
170
+		if ( ! $this->setEvent( $event ) ) {
171
+			return false;
172
+		}
173
+		// begin gathering template arguments by getting event status
174
+		$template_args = array( 'event_status' => $this->event->get_active_status() );
175
+		if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
176
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
177
+		}
178
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
179
+		$this->setMaxAttendees($this->event->additional_limit());
180
+		if ($this->getMaxAttendees() < 1) {
181
+			return $this->ticketSalesClosedMessage();
182
+		}
183
+		// is the event expired ?
184
+		$template_args['event_is_expired'] = $this->event->is_expired();
185
+		if ( $template_args[ 'event_is_expired' ] ) {
186
+			return $this->expiredEventMessage();
187
+		}
188
+		// get all tickets for this event ordered by the datetime
189
+		$tickets = $this->getTickets();
190
+		if (count($tickets) < 1) {
191
+			return $this->noTicketAvailableMessage();
192
+		}
193
+		if (EED_Events_Archive::is_iframe()){
194
+			$this->setIframe();
195
+		}
196
+		// redirecting to another site for registration ??
197
+		$external_url = (string) $this->event->external_url();
198
+		// if redirecting to another site for registration, then we don't load the TS
199
+		$ticket_selector = $external_url
200
+			? $this->externalEventRegistration()
201
+			: $this->loadTicketSelector($tickets,$template_args);
202
+		// now set up the form (but not for the admin)
203
+		$ticket_selector = ! is_admin()
204
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
205
+			: $ticket_selector;
206
+		// submit button and form close tag
207
+		$ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
208
+		return $ticket_selector;
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 * displayTicketSelector
215
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
216
+	 *
217
+	 * @param WP_Post|int $event
218
+	 * @param string       $_event_active_status
219
+	 * @param bool         $view_details
220
+	 * @return bool
221
+	 * @throws EE_Error
222
+	 */
223
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
224
+	{
225
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
226
+		return ! is_admin()
227
+			   && (
228
+				   ! $this->event->display_ticket_selector()
229
+				   || $view_details
230
+				   || post_password_required($event_post)
231
+				   || (
232
+					   $_event_active_status !== EE_Datetime::active
233
+					   && $_event_active_status !== EE_Datetime::upcoming
234
+					   && $_event_active_status !== EE_Datetime::sold_out
235
+					   && ! (
236
+						   $_event_active_status === EE_Datetime::inactive
237
+						   && is_user_logged_in()
238
+					   )
239
+				   )
240
+			   );
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * noTicketAvailableMessage
247
+	 * notice displayed if event is expired
248
+	 *
249
+	 * @return string
250
+	 * @throws EE_Error
251
+	 */
252
+	protected function expiredEventMessage()
253
+	{
254
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
255
+			'We\'re sorry, but all tickets sales have ended because the event is expired.',
256
+			'event_espresso'
257
+		) . '</span></div><!-- .ee-event-expired-notice -->';
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * noTicketAvailableMessage
264
+	 * notice displayed if event has no more tickets available
265
+	 *
266
+	 * @return string
267
+	 * @throws EE_Error
268
+	 */
269
+	protected function noTicketAvailableMessage()
270
+	{
271
+		$no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
272
+		if (current_user_can('edit_post', $this->event->ID())) {
273
+			$no_ticket_available_msg .= sprintf(
274
+				esc_html__(
275
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
276
+					'event_espresso'
277
+				),
278
+				'<div class="ee-attention" style="text-align: left;"><b>',
279
+				'</b><br />',
280
+				'<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
281
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
282
+			);
283
+		}
284
+		return '
285 285
             <div class="ee-event-expired-notice">
286 286
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
287 287
             </div><!-- .ee-event-expired-notice -->';
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * ticketSalesClosed
294
-     * notice displayed if event ticket sales are turned off
295
-     *
296
-     * @return string
297
-     * @throws EE_Error
298
-     */
299
-    protected function ticketSalesClosedMessage()
300
-    {
301
-        $sales_closed_msg = esc_html__(
302
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
303
-            'event_espresso'
304
-        );
305
-        if (current_user_can('edit_post', $this->event->ID())) {
306
-            $sales_closed_msg .= sprintf(
307
-                esc_html__(
308
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
309
-                    'event_espresso'
310
-                ),
311
-                '<div class="ee-attention" style="text-align: left;"><b>',
312
-                '</b><br />',
313
-                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
314
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
315
-            );
316
-        }
317
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * getTickets
324
-     *
325
-     * @return \EE_Base_Class[]|\EE_Ticket[]
326
-     * @throws EE_Error
327
-     */
328
-    protected function getTickets()
329
-    {
330
-        $ticket_query_args = array(
331
-            array('Datetime.EVT_ID' => $this->event->ID()),
332
-            'order_by' => array(
333
-                'TKT_order'              => 'ASC',
334
-                'TKT_required'           => 'DESC',
335
-                'TKT_start_date'         => 'ASC',
336
-                'TKT_end_date'           => 'ASC',
337
-                'Datetime.DTT_EVT_start' => 'DESC',
338
-            ),
339
-        );
340
-        if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
341
-            //use the correct applicable time query depending on what version of core is being run.
342
-            $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
343
-                ? time()
344
-                : current_time('timestamp');
345
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
346
-        }
347
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * loadTicketSelector
354
-     * begins to assemble template arguments
355
-     * and decides whether to load a "simple" ticket selector, or the standard
356
-     *
357
-     * @param \EE_Ticket[] $tickets
358
-     * @param array $template_args
359
-     * @return string
360
-     * @throws EE_Error
361
-     */
362
-    protected function loadTicketSelector(array $tickets, array $template_args)
363
-    {
364
-        $template_args['event'] = $this->event;
365
-        $template_args['EVT_ID'] = $this->event->ID();
366
-        $template_args['event_is_expired'] = $this->event->is_expired();
367
-        $template_args['max_atndz'] = $this->getMaxAttendees();
368
-        $template_args['date_format'] = $this->date_format;
369
-        $template_args['time_format'] = $this->time_format;
370
-        /**
371
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
372
-         *
373
-         * @since 4.9.13
374
-         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
375
-         * @param int $EVT_ID The Event ID
376
-         */
377
-        $template_args['anchor_id'] = apply_filters(
378
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
379
-            '#tkt-slctr-tbl-' . $this->event->ID(),
380
-            $this->event->ID()
381
-        );
382
-        $template_args['tickets'] = $tickets;
383
-        $template_args['ticket_count'] = count($tickets);
384
-        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
385
-        return $ticket_selector instanceof TicketSelectorSimple
386
-            ? $ticket_selector
387
-            : new TicketSelectorStandard(
388
-                $this->event,
389
-                $tickets,
390
-                $this->getMaxAttendees(),
391
-                $template_args,
392
-                $this->date_format,
393
-                $this->time_format
394
-            );
395
-    }
396
-
397
-
398
-
399
-    /**
400
-     * simpleTicketSelector
401
-     * there's one ticket, and max attendees is set to one,
402
-     * so if the event is free, then this is a "simple" ticket selector
403
-     * a.k.a. "Dude Where's my Ticket Selector?"
404
-     *
405
-     * @param \EE_Ticket[] $tickets
406
-     * @param array  $template_args
407
-     * @return string
408
-     * @throws EE_Error
409
-     */
410
-    protected function simpleTicketSelector($tickets, array $template_args)
411
-    {
412
-        // if there is only ONE ticket with a max qty of ONE
413
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
414
-            return '';
415
-        }
416
-        /** @var \EE_Ticket $ticket */
417
-        $ticket = reset($tickets);
418
-        // if the ticket is free... then not much need for the ticket selector
419
-        if (
420
-            apply_filters(
421
-                'FHEE__ticket_selector_chart_template__hide_ticket_selector',
422
-                $ticket->is_free(),
423
-                $this->event->ID()
424
-            )
425
-        ) {
426
-            return new TicketSelectorSimple(
427
-                $this->event,
428
-                $ticket,
429
-                $this->getMaxAttendees(),
430
-                $template_args
431
-            );
432
-        }
433
-        return '';
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     * externalEventRegistration
440
-     *
441
-     * @return string
442
-     */
443
-    public function externalEventRegistration()
444
-    {
445
-        // if not we still need to trigger the display of the submit button
446
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
447
-        //display notice to admin that registration is external
448
-        return is_admin()
449
-            ? esc_html__(
450
-                'Registration is at an external URL for this event.',
451
-                'event_espresso'
452
-            )
453
-            : '';
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     * formOpen
460
-     *
461
-     * @param        int    $ID
462
-     * @param        string $external_url
463
-     * @return        string
464
-     */
465
-    public function formOpen( $ID = 0, $external_url = '' )
466
-    {
467
-        // if redirecting, we don't need any anything else
468
-        if ( $external_url ) {
469
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
470
-            // open link in new window ?
471
-            $html .= apply_filters(
472
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
473
-                EED_Events_Archive::is_iframe()
474
-            )
475
-                ? ' target="_blank"'
476
-                : '';
477
-            $html .= '>';
478
-            $query_args = EEH_URL::get_query_string( $external_url );
479
-            foreach ( (array)$query_args as $query_arg => $value ) {
480
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
481
-            }
482
-            return $html;
483
-        }
484
-        // if there is no submit button, then don't start building a form
485
-        // because the "View Details" button will build its own form
486
-        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
487
-            return '';
488
-        }
489
-        $checkout_url = EEH_Event_View::event_link_url( $ID );
490
-        if ( ! $checkout_url ) {
491
-            EE_Error::add_error(
492
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
493
-                __FILE__,
494
-                __FUNCTION__,
495
-                __LINE__
496
-            );
497
-        }
498
-        // set no cache headers and constants
499
-        EE_System::do_not_cache();
500
-        $extra_params = $this->iframe ? ' target="_blank"' : '';
501
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
502
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
503
-        $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
504
-        return $html;
505
-    }
506
-
507
-
508
-
509
-    /**
510
-     * displaySubmitButton
511
-     *
512
-     * @param  string $external_url
513
-     * @return string
514
-     * @throws EE_Error
515
-     */
516
-    public function displaySubmitButton($external_url = '')
517
-    {
518
-        $html = '';
519
-        if ( ! is_admin()) {
520
-            // standard TS displayed with submit button, ie: "Register Now"
521
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
522
-                $html .= $this->displayRegisterNowButton();
523
-                $html .= empty($external_url)
524
-                    ? $this->ticketSelectorEndDiv()
525
-                    : $this->clearTicketSelector();
526
-                $html .= '<br/>' . $this->formClose();
527
-            } else if ($this->getMaxAttendees() === 1) {
528
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
529
-                if ($this->event->is_sold_out()) {
530
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
531
-                    $html .= apply_filters(
532
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
533
-                        sprintf(
534
-                            __(
535
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
536
-                                'event_espresso'
537
-                            ),
538
-                            '<p class="no-ticket-selector-msg clear-float">',
539
-                            $this->event->name(),
540
-                            '</p>',
541
-                            '<br />'
542
-                        ),
543
-                        $this->event
544
-                    );
545
-                    if (
546
-                        apply_filters(
547
-                            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
548
-                            false,
549
-                            $this->event
550
-                        )
551
-                    ) {
552
-                        $html .= $this->displayRegisterNowButton();
553
-                    }
554
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
555
-                    $html .=  $this->ticketSelectorEndDiv();
556
-                } else if (
557
-                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
558
-                    && ! is_single()
559
-                ) {
560
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
561
-                    // but no tickets are available, so display event's "View Details" button.
562
-                    // it is being viewed via somewhere other than a single post
563
-                    $html .= $this->displayViewDetailsButton(true);
564
-                } else {
565
-                    $html .= $this->ticketSelectorEndDiv();
566
-                }
567
-            } else if (is_archive()) {
568
-                // event list, no tickets available so display event's "View Details" button
569
-                $html .= $this->ticketSelectorEndDiv();
570
-                $html .= $this->displayViewDetailsButton();
571
-            } else {
572
-                if (
573
-                    apply_filters(
574
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
575
-                        false,
576
-                        $this->event
577
-                    )
578
-                ) {
579
-                    $html .= $this->displayRegisterNowButton();
580
-                }
581
-                // no submit or view details button, and no additional content
582
-                $html .= $this->ticketSelectorEndDiv();
583
-            }
584
-            if ( ! $this->iframe && ! is_archive()) {
585
-                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
586
-            }
587
-        }
588
-	    return apply_filters(
589
-		    'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
590
-		    $html,
591
-		    $this->event
592
-	    );
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * @return string
599
-     * @throws EE_Error
600
-     */
601
-    public function displayRegisterNowButton()
602
-    {
603
-        $btn_text = apply_filters(
604
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
605
-            __('Register Now', 'event_espresso'),
606
-            $this->event
607
-        );
608
-        $external_url = $this->event->external_url();
609
-        $html = EEH_HTML::div(
610
-            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
611
-        );
612
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
613
-        $html .= ' class="ticket-selector-submit-btn ';
614
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
615
-        $html .= ' type="submit" value="' . $btn_text . '" />';
616
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
617
-        $html .= apply_filters(
618
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
619
-            '',
620
-            $this->event
621
-        );
622
-        return $html;
623
-    }
624
-
625
-
626
-    /**
627
-     * displayViewDetailsButton
628
-     *
629
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
630
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
631
-     *                    either because they are sold out, expired, or not yet on sale.
632
-     *                    In this case, we need to close the form BEFORE adding any closing divs
633
-     * @return string
634
-     * @throws EE_Error
635
-     */
636
-    public function displayViewDetailsButton( $DWMTS = false )
637
-    {
638
-        if ( ! $this->event->get_permalink() ) {
639
-            EE_Error::add_error(
640
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
641
-                __FILE__, __FUNCTION__, __LINE__
642
-            );
643
-        }
644
-        $view_details_btn = '<form method="POST" action="';
645
-        $view_details_btn .= apply_filters(
646
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
647
-            $this->event->get_permalink(),
648
-            $this->event
649
-        );
650
-        $view_details_btn .= '"';
651
-        // open link in new window ?
652
-        $view_details_btn .= apply_filters(
653
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
654
-            EED_Events_Archive::is_iframe()
655
-        )
656
-            ? ' target="_blank"'
657
-            : '';
658
-        $view_details_btn .='>';
659
-        $btn_text = apply_filters(
660
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
661
-            esc_html__('View Details', 'event_espresso'),
662
-            $this->event
663
-        );
664
-        $view_details_btn .= '<input id="ticket-selector-submit-'
665
-                             . $this->event->ID()
666
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
667
-                             . $btn_text
668
-                             . '" />';
669
-        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
670
-        if ($DWMTS) {
671
-            $view_details_btn .= $this->formClose();
672
-            $view_details_btn .= $this->ticketSelectorEndDiv();
673
-            $view_details_btn .= '<br/>';
674
-        } else {
675
-            $view_details_btn .= $this->clearTicketSelector();
676
-            $view_details_btn .= '<br/>';
677
-            $view_details_btn .= $this->formClose();
678
-        }
679
-        return $view_details_btn;
680
-    }
681
-
682
-
683
-
684
-    /**
685
-     * @return string
686
-     */
687
-    public function ticketSelectorEndDiv()
688
-    {
689
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     * @return string
696
-     */
697
-    public function clearTicketSelector()
698
-    {
699
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
700
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
701
-    }
702
-
703
-
704
-
705
-    /**
706
-     * @access        public
707
-     * @return        string
708
-     */
709
-    public function formClose()
710
-    {
711
-        return '</form>';
712
-    }
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * ticketSalesClosed
294
+	 * notice displayed if event ticket sales are turned off
295
+	 *
296
+	 * @return string
297
+	 * @throws EE_Error
298
+	 */
299
+	protected function ticketSalesClosedMessage()
300
+	{
301
+		$sales_closed_msg = esc_html__(
302
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
303
+			'event_espresso'
304
+		);
305
+		if (current_user_can('edit_post', $this->event->ID())) {
306
+			$sales_closed_msg .= sprintf(
307
+				esc_html__(
308
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
309
+					'event_espresso'
310
+				),
311
+				'<div class="ee-attention" style="text-align: left;"><b>',
312
+				'</b><br />',
313
+				'<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
314
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
315
+			);
316
+		}
317
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * getTickets
324
+	 *
325
+	 * @return \EE_Base_Class[]|\EE_Ticket[]
326
+	 * @throws EE_Error
327
+	 */
328
+	protected function getTickets()
329
+	{
330
+		$ticket_query_args = array(
331
+			array('Datetime.EVT_ID' => $this->event->ID()),
332
+			'order_by' => array(
333
+				'TKT_order'              => 'ASC',
334
+				'TKT_required'           => 'DESC',
335
+				'TKT_start_date'         => 'ASC',
336
+				'TKT_end_date'           => 'ASC',
337
+				'Datetime.DTT_EVT_start' => 'DESC',
338
+			),
339
+		);
340
+		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
341
+			//use the correct applicable time query depending on what version of core is being run.
342
+			$current_time = method_exists('EEM_Datetime', 'current_time_for_query')
343
+				? time()
344
+				: current_time('timestamp');
345
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
346
+		}
347
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * loadTicketSelector
354
+	 * begins to assemble template arguments
355
+	 * and decides whether to load a "simple" ticket selector, or the standard
356
+	 *
357
+	 * @param \EE_Ticket[] $tickets
358
+	 * @param array $template_args
359
+	 * @return string
360
+	 * @throws EE_Error
361
+	 */
362
+	protected function loadTicketSelector(array $tickets, array $template_args)
363
+	{
364
+		$template_args['event'] = $this->event;
365
+		$template_args['EVT_ID'] = $this->event->ID();
366
+		$template_args['event_is_expired'] = $this->event->is_expired();
367
+		$template_args['max_atndz'] = $this->getMaxAttendees();
368
+		$template_args['date_format'] = $this->date_format;
369
+		$template_args['time_format'] = $this->time_format;
370
+		/**
371
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
372
+		 *
373
+		 * @since 4.9.13
374
+		 * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
375
+		 * @param int $EVT_ID The Event ID
376
+		 */
377
+		$template_args['anchor_id'] = apply_filters(
378
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
379
+			'#tkt-slctr-tbl-' . $this->event->ID(),
380
+			$this->event->ID()
381
+		);
382
+		$template_args['tickets'] = $tickets;
383
+		$template_args['ticket_count'] = count($tickets);
384
+		$ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
385
+		return $ticket_selector instanceof TicketSelectorSimple
386
+			? $ticket_selector
387
+			: new TicketSelectorStandard(
388
+				$this->event,
389
+				$tickets,
390
+				$this->getMaxAttendees(),
391
+				$template_args,
392
+				$this->date_format,
393
+				$this->time_format
394
+			);
395
+	}
396
+
397
+
398
+
399
+	/**
400
+	 * simpleTicketSelector
401
+	 * there's one ticket, and max attendees is set to one,
402
+	 * so if the event is free, then this is a "simple" ticket selector
403
+	 * a.k.a. "Dude Where's my Ticket Selector?"
404
+	 *
405
+	 * @param \EE_Ticket[] $tickets
406
+	 * @param array  $template_args
407
+	 * @return string
408
+	 * @throws EE_Error
409
+	 */
410
+	protected function simpleTicketSelector($tickets, array $template_args)
411
+	{
412
+		// if there is only ONE ticket with a max qty of ONE
413
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
414
+			return '';
415
+		}
416
+		/** @var \EE_Ticket $ticket */
417
+		$ticket = reset($tickets);
418
+		// if the ticket is free... then not much need for the ticket selector
419
+		if (
420
+			apply_filters(
421
+				'FHEE__ticket_selector_chart_template__hide_ticket_selector',
422
+				$ticket->is_free(),
423
+				$this->event->ID()
424
+			)
425
+		) {
426
+			return new TicketSelectorSimple(
427
+				$this->event,
428
+				$ticket,
429
+				$this->getMaxAttendees(),
430
+				$template_args
431
+			);
432
+		}
433
+		return '';
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 * externalEventRegistration
440
+	 *
441
+	 * @return string
442
+	 */
443
+	public function externalEventRegistration()
444
+	{
445
+		// if not we still need to trigger the display of the submit button
446
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
447
+		//display notice to admin that registration is external
448
+		return is_admin()
449
+			? esc_html__(
450
+				'Registration is at an external URL for this event.',
451
+				'event_espresso'
452
+			)
453
+			: '';
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 * formOpen
460
+	 *
461
+	 * @param        int    $ID
462
+	 * @param        string $external_url
463
+	 * @return        string
464
+	 */
465
+	public function formOpen( $ID = 0, $external_url = '' )
466
+	{
467
+		// if redirecting, we don't need any anything else
468
+		if ( $external_url ) {
469
+			$html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
470
+			// open link in new window ?
471
+			$html .= apply_filters(
472
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
473
+				EED_Events_Archive::is_iframe()
474
+			)
475
+				? ' target="_blank"'
476
+				: '';
477
+			$html .= '>';
478
+			$query_args = EEH_URL::get_query_string( $external_url );
479
+			foreach ( (array)$query_args as $query_arg => $value ) {
480
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
481
+			}
482
+			return $html;
483
+		}
484
+		// if there is no submit button, then don't start building a form
485
+		// because the "View Details" button will build its own form
486
+		if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
487
+			return '';
488
+		}
489
+		$checkout_url = EEH_Event_View::event_link_url( $ID );
490
+		if ( ! $checkout_url ) {
491
+			EE_Error::add_error(
492
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
493
+				__FILE__,
494
+				__FUNCTION__,
495
+				__LINE__
496
+			);
497
+		}
498
+		// set no cache headers and constants
499
+		EE_System::do_not_cache();
500
+		$extra_params = $this->iframe ? ' target="_blank"' : '';
501
+		$html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
502
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
503
+		$html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
504
+		return $html;
505
+	}
506
+
507
+
508
+
509
+	/**
510
+	 * displaySubmitButton
511
+	 *
512
+	 * @param  string $external_url
513
+	 * @return string
514
+	 * @throws EE_Error
515
+	 */
516
+	public function displaySubmitButton($external_url = '')
517
+	{
518
+		$html = '';
519
+		if ( ! is_admin()) {
520
+			// standard TS displayed with submit button, ie: "Register Now"
521
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
522
+				$html .= $this->displayRegisterNowButton();
523
+				$html .= empty($external_url)
524
+					? $this->ticketSelectorEndDiv()
525
+					: $this->clearTicketSelector();
526
+				$html .= '<br/>' . $this->formClose();
527
+			} else if ($this->getMaxAttendees() === 1) {
528
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
529
+				if ($this->event->is_sold_out()) {
530
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
531
+					$html .= apply_filters(
532
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
533
+						sprintf(
534
+							__(
535
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
536
+								'event_espresso'
537
+							),
538
+							'<p class="no-ticket-selector-msg clear-float">',
539
+							$this->event->name(),
540
+							'</p>',
541
+							'<br />'
542
+						),
543
+						$this->event
544
+					);
545
+					if (
546
+						apply_filters(
547
+							'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
548
+							false,
549
+							$this->event
550
+						)
551
+					) {
552
+						$html .= $this->displayRegisterNowButton();
553
+					}
554
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
555
+					$html .=  $this->ticketSelectorEndDiv();
556
+				} else if (
557
+					apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
558
+					&& ! is_single()
559
+				) {
560
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
561
+					// but no tickets are available, so display event's "View Details" button.
562
+					// it is being viewed via somewhere other than a single post
563
+					$html .= $this->displayViewDetailsButton(true);
564
+				} else {
565
+					$html .= $this->ticketSelectorEndDiv();
566
+				}
567
+			} else if (is_archive()) {
568
+				// event list, no tickets available so display event's "View Details" button
569
+				$html .= $this->ticketSelectorEndDiv();
570
+				$html .= $this->displayViewDetailsButton();
571
+			} else {
572
+				if (
573
+					apply_filters(
574
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
575
+						false,
576
+						$this->event
577
+					)
578
+				) {
579
+					$html .= $this->displayRegisterNowButton();
580
+				}
581
+				// no submit or view details button, and no additional content
582
+				$html .= $this->ticketSelectorEndDiv();
583
+			}
584
+			if ( ! $this->iframe && ! is_archive()) {
585
+				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
586
+			}
587
+		}
588
+		return apply_filters(
589
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
590
+			$html,
591
+			$this->event
592
+		);
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * @return string
599
+	 * @throws EE_Error
600
+	 */
601
+	public function displayRegisterNowButton()
602
+	{
603
+		$btn_text = apply_filters(
604
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
605
+			__('Register Now', 'event_espresso'),
606
+			$this->event
607
+		);
608
+		$external_url = $this->event->external_url();
609
+		$html = EEH_HTML::div(
610
+			'', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
611
+		);
612
+		$html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
613
+		$html .= ' class="ticket-selector-submit-btn ';
614
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
615
+		$html .= ' type="submit" value="' . $btn_text . '" />';
616
+		$html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
617
+		$html .= apply_filters(
618
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
619
+			'',
620
+			$this->event
621
+		);
622
+		return $html;
623
+	}
624
+
625
+
626
+	/**
627
+	 * displayViewDetailsButton
628
+	 *
629
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
630
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
631
+	 *                    either because they are sold out, expired, or not yet on sale.
632
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
633
+	 * @return string
634
+	 * @throws EE_Error
635
+	 */
636
+	public function displayViewDetailsButton( $DWMTS = false )
637
+	{
638
+		if ( ! $this->event->get_permalink() ) {
639
+			EE_Error::add_error(
640
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
641
+				__FILE__, __FUNCTION__, __LINE__
642
+			);
643
+		}
644
+		$view_details_btn = '<form method="POST" action="';
645
+		$view_details_btn .= apply_filters(
646
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
647
+			$this->event->get_permalink(),
648
+			$this->event
649
+		);
650
+		$view_details_btn .= '"';
651
+		// open link in new window ?
652
+		$view_details_btn .= apply_filters(
653
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
654
+			EED_Events_Archive::is_iframe()
655
+		)
656
+			? ' target="_blank"'
657
+			: '';
658
+		$view_details_btn .='>';
659
+		$btn_text = apply_filters(
660
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
661
+			esc_html__('View Details', 'event_espresso'),
662
+			$this->event
663
+		);
664
+		$view_details_btn .= '<input id="ticket-selector-submit-'
665
+							 . $this->event->ID()
666
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
667
+							 . $btn_text
668
+							 . '" />';
669
+		$view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
670
+		if ($DWMTS) {
671
+			$view_details_btn .= $this->formClose();
672
+			$view_details_btn .= $this->ticketSelectorEndDiv();
673
+			$view_details_btn .= '<br/>';
674
+		} else {
675
+			$view_details_btn .= $this->clearTicketSelector();
676
+			$view_details_btn .= '<br/>';
677
+			$view_details_btn .= $this->formClose();
678
+		}
679
+		return $view_details_btn;
680
+	}
681
+
682
+
683
+
684
+	/**
685
+	 * @return string
686
+	 */
687
+	public function ticketSelectorEndDiv()
688
+	{
689
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 * @return string
696
+	 */
697
+	public function clearTicketSelector()
698
+	{
699
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
700
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
701
+	}
702
+
703
+
704
+
705
+	/**
706
+	 * @access        public
707
+	 * @return        string
708
+	 */
709
+	public function formClose()
710
+	{
711
+		return '</form>';
712
+	}
713 713
 
714 714
 
715 715
 
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2687 added lines, -2687 removed lines patch added patch discarded remove patch
@@ -15,2694 +15,2694 @@
 block discarded – undo
15 15
 class Events_Admin_Page extends EE_Admin_Page_CPT
16 16
 {
17 17
 
18
-    /**
19
-     * This will hold the event object for event_details screen.
20
-     *
21
-     * @access protected
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-
44
-    /**
45
-     * @var EE_Event
46
-     */
47
-    protected $_cpt_model_obj = false;
48
-
49
-
50
-    /**
51
-     * Initialize page props for this admin page group.
52
-     */
53
-    protected function _init_page_props()
54
-    {
55
-        $this->page_slug = EVENTS_PG_SLUG;
56
-        $this->page_label = EVENTS_LABEL;
57
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
58
-        $this->_admin_base_path = EVENTS_ADMIN;
59
-        $this->_cpt_model_names = array(
60
-            'create_new' => 'EEM_Event',
61
-            'edit'       => 'EEM_Event',
62
-        );
63
-        $this->_cpt_edit_routes = array(
64
-            'espresso_events' => 'edit',
65
-        );
66
-        add_action(
67
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
-            array($this, 'verify_event_edit'), 10, 2
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     * Sets the ajax hooks used for this admin page group.
75
-     */
76
-    protected function _ajax_hooks()
77
-    {
78
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
79
-    }
80
-
81
-
82
-    /**
83
-     * Sets the page properties for this admin page group.
84
-     */
85
-    protected function _define_page_props()
86
-    {
87
-        $this->_admin_page_title = EVENTS_LABEL;
88
-        $this->_labels = array(
89
-            'buttons'      => array(
90
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
91
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
92
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
93
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
94
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
95
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
96
-            ),
97
-            'editor_title' => array(
98
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
99
-            ),
100
-            'publishbox'   => array(
101
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
102
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
103
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
104
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
105
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
106
-            ),
107
-        );
108
-    }
109
-
110
-
111
-    /**
112
-     * Sets the page routes property for this admin page group.
113
-     */
114
-    protected function _set_page_routes()
115
-    {
116
-        //load formatter helper
117
-        //load field generator helper
118
-        //is there a evt_id in the request?
119
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
120
-            ? $this->_req_data['EVT_ID']
121
-            : 0;
122
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
123
-        $this->_page_routes = array(
124
-            'default'                       => array(
125
-                'func'       => '_events_overview_list_table',
126
-                'capability' => 'ee_read_events',
127
-            ),
128
-            'create_new'                    => array(
129
-                'func'       => '_create_new_cpt_item',
130
-                'capability' => 'ee_edit_events',
131
-            ),
132
-            'edit'                          => array(
133
-                'func'       => '_edit_cpt_item',
134
-                'capability' => 'ee_edit_event',
135
-                'obj_id'     => $evt_id,
136
-            ),
137
-            'copy_event'                    => array(
138
-                'func'       => '_copy_events',
139
-                'capability' => 'ee_edit_event',
140
-                'obj_id'     => $evt_id,
141
-                'noheader'   => true,
142
-            ),
143
-            'trash_event'                   => array(
144
-                'func'       => '_trash_or_restore_event',
145
-                'args'       => array('event_status' => 'trash'),
146
-                'capability' => 'ee_delete_event',
147
-                'obj_id'     => $evt_id,
148
-                'noheader'   => true,
149
-            ),
150
-            'trash_events'                  => array(
151
-                'func'       => '_trash_or_restore_events',
152
-                'args'       => array('event_status' => 'trash'),
153
-                'capability' => 'ee_delete_events',
154
-                'noheader'   => true,
155
-            ),
156
-            'restore_event'                 => array(
157
-                'func'       => '_trash_or_restore_event',
158
-                'args'       => array('event_status' => 'draft'),
159
-                'capability' => 'ee_delete_event',
160
-                'obj_id'     => $evt_id,
161
-                'noheader'   => true,
162
-            ),
163
-            'restore_events'                => array(
164
-                'func'       => '_trash_or_restore_events',
165
-                'args'       => array('event_status' => 'draft'),
166
-                'capability' => 'ee_delete_events',
167
-                'noheader'   => true,
168
-            ),
169
-            'delete_event'                  => array(
170
-                'func'       => '_delete_event',
171
-                'capability' => 'ee_delete_event',
172
-                'obj_id'     => $evt_id,
173
-                'noheader'   => true,
174
-            ),
175
-            'delete_events'                 => array(
176
-                'func'       => '_delete_events',
177
-                'capability' => 'ee_delete_events',
178
-                'noheader'   => true,
179
-            ),
180
-            'view_report'                   => array(
181
-                'func'      => '_view_report',
182
-                'capablity' => 'ee_edit_events',
183
-            ),
184
-            'default_event_settings'        => array(
185
-                'func'       => '_default_event_settings',
186
-                'capability' => 'manage_options',
187
-            ),
188
-            'update_default_event_settings' => array(
189
-                'func'       => '_update_default_event_settings',
190
-                'capability' => 'manage_options',
191
-                'noheader'   => true,
192
-            ),
193
-            'template_settings'             => array(
194
-                'func'       => '_template_settings',
195
-                'capability' => 'manage_options',
196
-            ),
197
-            //event category tab related
198
-            'add_category'                  => array(
199
-                'func'       => '_category_details',
200
-                'capability' => 'ee_edit_event_category',
201
-                'args'       => array('add'),
202
-            ),
203
-            'edit_category'                 => array(
204
-                'func'       => '_category_details',
205
-                'capability' => 'ee_edit_event_category',
206
-                'args'       => array('edit'),
207
-            ),
208
-            'delete_categories'             => array(
209
-                'func'       => '_delete_categories',
210
-                'capability' => 'ee_delete_event_category',
211
-                'noheader'   => true,
212
-            ),
213
-            'delete_category'               => array(
214
-                'func'       => '_delete_categories',
215
-                'capability' => 'ee_delete_event_category',
216
-                'noheader'   => true,
217
-            ),
218
-            'insert_category'               => array(
219
-                'func'       => '_insert_or_update_category',
220
-                'args'       => array('new_category' => true),
221
-                'capability' => 'ee_edit_event_category',
222
-                'noheader'   => true,
223
-            ),
224
-            'update_category'               => array(
225
-                'func'       => '_insert_or_update_category',
226
-                'args'       => array('new_category' => false),
227
-                'capability' => 'ee_edit_event_category',
228
-                'noheader'   => true,
229
-            ),
230
-            'category_list'                 => array(
231
-                'func'       => '_category_list_table',
232
-                'capability' => 'ee_manage_event_categories',
233
-            ),
234
-        );
235
-    }
236
-
237
-
238
-    /**
239
-     * Set the _page_config property for this admin page group.
240
-     */
241
-    protected function _set_page_config()
242
-    {
243
-        $this->_page_config = array(
244
-            'default'                => array(
245
-                'nav'           => array(
246
-                    'label' => esc_html__('Overview', 'event_espresso'),
247
-                    'order' => 10,
248
-                ),
249
-                'list_table'    => 'Events_Admin_List_Table',
250
-                'help_tabs'     => array(
251
-                    'events_overview_help_tab'                       => array(
252
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
253
-                        'filename' => 'events_overview',
254
-                    ),
255
-                    'events_overview_table_column_headings_help_tab' => array(
256
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
257
-                        'filename' => 'events_overview_table_column_headings',
258
-                    ),
259
-                    'events_overview_filters_help_tab'               => array(
260
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
261
-                        'filename' => 'events_overview_filters',
262
-                    ),
263
-                    'events_overview_view_help_tab'                  => array(
264
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
265
-                        'filename' => 'events_overview_views',
266
-                    ),
267
-                    'events_overview_other_help_tab'                 => array(
268
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
269
-                        'filename' => 'events_overview_other',
270
-                    ),
271
-                ),
272
-                'help_tour'     => array(
273
-                    'Event_Overview_Help_Tour',
274
-                    //'New_Features_Test_Help_Tour' for testing multiple help tour
275
-                ),
276
-                'qtips'         => array(
277
-                    'EE_Event_List_Table_Tips',
278
-                ),
279
-                'require_nonce' => false,
280
-            ),
281
-            'create_new'             => array(
282
-                'nav'           => array(
283
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
284
-                    'order'      => 5,
285
-                    'persistent' => false,
286
-                ),
287
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
288
-                'help_tabs'     => array(
289
-                    'event_editor_help_tab'                            => array(
290
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
291
-                        'filename' => 'event_editor',
292
-                    ),
293
-                    'event_editor_title_richtexteditor_help_tab'       => array(
294
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
295
-                        'filename' => 'event_editor_title_richtexteditor',
296
-                    ),
297
-                    'event_editor_venue_details_help_tab'              => array(
298
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
299
-                        'filename' => 'event_editor_venue_details',
300
-                    ),
301
-                    'event_editor_event_datetimes_help_tab'            => array(
302
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
303
-                        'filename' => 'event_editor_event_datetimes',
304
-                    ),
305
-                    'event_editor_event_tickets_help_tab'              => array(
306
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
307
-                        'filename' => 'event_editor_event_tickets',
308
-                    ),
309
-                    'event_editor_event_registration_options_help_tab' => array(
310
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
311
-                        'filename' => 'event_editor_event_registration_options',
312
-                    ),
313
-                    'event_editor_tags_categories_help_tab'            => array(
314
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
315
-                        'filename' => 'event_editor_tags_categories',
316
-                    ),
317
-                    'event_editor_questions_registrants_help_tab'      => array(
318
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
319
-                        'filename' => 'event_editor_questions_registrants',
320
-                    ),
321
-                    'event_editor_save_new_event_help_tab'             => array(
322
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
323
-                        'filename' => 'event_editor_save_new_event',
324
-                    ),
325
-                    'event_editor_other_help_tab'                      => array(
326
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
327
-                        'filename' => 'event_editor_other',
328
-                    ),
329
-                ),
330
-                'help_tour'     => array(
331
-                    'Event_Editor_Help_Tour',
332
-                ),
333
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
334
-                'require_nonce' => false,
335
-            ),
336
-            'edit'                   => array(
337
-                'nav'           => array(
338
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
339
-                    'order'      => 5,
340
-                    'persistent' => false,
341
-                    'url'        => isset($this->_req_data['post'])
342
-                        ? EE_Admin_Page::add_query_args_and_nonce(
343
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
344
-                            $this->_current_page_view_url
345
-                        )
346
-                        : $this->_admin_base_url,
347
-                ),
348
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
349
-                'help_tabs'     => array(
350
-                    'event_editor_help_tab'                            => array(
351
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
352
-                        'filename' => 'event_editor',
353
-                    ),
354
-                    'event_editor_title_richtexteditor_help_tab'       => array(
355
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
356
-                        'filename' => 'event_editor_title_richtexteditor',
357
-                    ),
358
-                    'event_editor_venue_details_help_tab'              => array(
359
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
360
-                        'filename' => 'event_editor_venue_details',
361
-                    ),
362
-                    'event_editor_event_datetimes_help_tab'            => array(
363
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
364
-                        'filename' => 'event_editor_event_datetimes',
365
-                    ),
366
-                    'event_editor_event_tickets_help_tab'              => array(
367
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
368
-                        'filename' => 'event_editor_event_tickets',
369
-                    ),
370
-                    'event_editor_event_registration_options_help_tab' => array(
371
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
372
-                        'filename' => 'event_editor_event_registration_options',
373
-                    ),
374
-                    'event_editor_tags_categories_help_tab'            => array(
375
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
376
-                        'filename' => 'event_editor_tags_categories',
377
-                    ),
378
-                    'event_editor_questions_registrants_help_tab'      => array(
379
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
380
-                        'filename' => 'event_editor_questions_registrants',
381
-                    ),
382
-                    'event_editor_save_new_event_help_tab'             => array(
383
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
384
-                        'filename' => 'event_editor_save_new_event',
385
-                    ),
386
-                    'event_editor_other_help_tab'                      => array(
387
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
388
-                        'filename' => 'event_editor_other',
389
-                    ),
390
-                ),
391
-                /*'help_tour' => array(
18
+	/**
19
+	 * This will hold the event object for event_details screen.
20
+	 *
21
+	 * @access protected
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+
44
+	/**
45
+	 * @var EE_Event
46
+	 */
47
+	protected $_cpt_model_obj = false;
48
+
49
+
50
+	/**
51
+	 * Initialize page props for this admin page group.
52
+	 */
53
+	protected function _init_page_props()
54
+	{
55
+		$this->page_slug = EVENTS_PG_SLUG;
56
+		$this->page_label = EVENTS_LABEL;
57
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
58
+		$this->_admin_base_path = EVENTS_ADMIN;
59
+		$this->_cpt_model_names = array(
60
+			'create_new' => 'EEM_Event',
61
+			'edit'       => 'EEM_Event',
62
+		);
63
+		$this->_cpt_edit_routes = array(
64
+			'espresso_events' => 'edit',
65
+		);
66
+		add_action(
67
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
+			array($this, 'verify_event_edit'), 10, 2
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 * Sets the ajax hooks used for this admin page group.
75
+	 */
76
+	protected function _ajax_hooks()
77
+	{
78
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
79
+	}
80
+
81
+
82
+	/**
83
+	 * Sets the page properties for this admin page group.
84
+	 */
85
+	protected function _define_page_props()
86
+	{
87
+		$this->_admin_page_title = EVENTS_LABEL;
88
+		$this->_labels = array(
89
+			'buttons'      => array(
90
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
91
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
92
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
93
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
94
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
95
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
96
+			),
97
+			'editor_title' => array(
98
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
99
+			),
100
+			'publishbox'   => array(
101
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
102
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
103
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
104
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
105
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
106
+			),
107
+		);
108
+	}
109
+
110
+
111
+	/**
112
+	 * Sets the page routes property for this admin page group.
113
+	 */
114
+	protected function _set_page_routes()
115
+	{
116
+		//load formatter helper
117
+		//load field generator helper
118
+		//is there a evt_id in the request?
119
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
120
+			? $this->_req_data['EVT_ID']
121
+			: 0;
122
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
123
+		$this->_page_routes = array(
124
+			'default'                       => array(
125
+				'func'       => '_events_overview_list_table',
126
+				'capability' => 'ee_read_events',
127
+			),
128
+			'create_new'                    => array(
129
+				'func'       => '_create_new_cpt_item',
130
+				'capability' => 'ee_edit_events',
131
+			),
132
+			'edit'                          => array(
133
+				'func'       => '_edit_cpt_item',
134
+				'capability' => 'ee_edit_event',
135
+				'obj_id'     => $evt_id,
136
+			),
137
+			'copy_event'                    => array(
138
+				'func'       => '_copy_events',
139
+				'capability' => 'ee_edit_event',
140
+				'obj_id'     => $evt_id,
141
+				'noheader'   => true,
142
+			),
143
+			'trash_event'                   => array(
144
+				'func'       => '_trash_or_restore_event',
145
+				'args'       => array('event_status' => 'trash'),
146
+				'capability' => 'ee_delete_event',
147
+				'obj_id'     => $evt_id,
148
+				'noheader'   => true,
149
+			),
150
+			'trash_events'                  => array(
151
+				'func'       => '_trash_or_restore_events',
152
+				'args'       => array('event_status' => 'trash'),
153
+				'capability' => 'ee_delete_events',
154
+				'noheader'   => true,
155
+			),
156
+			'restore_event'                 => array(
157
+				'func'       => '_trash_or_restore_event',
158
+				'args'       => array('event_status' => 'draft'),
159
+				'capability' => 'ee_delete_event',
160
+				'obj_id'     => $evt_id,
161
+				'noheader'   => true,
162
+			),
163
+			'restore_events'                => array(
164
+				'func'       => '_trash_or_restore_events',
165
+				'args'       => array('event_status' => 'draft'),
166
+				'capability' => 'ee_delete_events',
167
+				'noheader'   => true,
168
+			),
169
+			'delete_event'                  => array(
170
+				'func'       => '_delete_event',
171
+				'capability' => 'ee_delete_event',
172
+				'obj_id'     => $evt_id,
173
+				'noheader'   => true,
174
+			),
175
+			'delete_events'                 => array(
176
+				'func'       => '_delete_events',
177
+				'capability' => 'ee_delete_events',
178
+				'noheader'   => true,
179
+			),
180
+			'view_report'                   => array(
181
+				'func'      => '_view_report',
182
+				'capablity' => 'ee_edit_events',
183
+			),
184
+			'default_event_settings'        => array(
185
+				'func'       => '_default_event_settings',
186
+				'capability' => 'manage_options',
187
+			),
188
+			'update_default_event_settings' => array(
189
+				'func'       => '_update_default_event_settings',
190
+				'capability' => 'manage_options',
191
+				'noheader'   => true,
192
+			),
193
+			'template_settings'             => array(
194
+				'func'       => '_template_settings',
195
+				'capability' => 'manage_options',
196
+			),
197
+			//event category tab related
198
+			'add_category'                  => array(
199
+				'func'       => '_category_details',
200
+				'capability' => 'ee_edit_event_category',
201
+				'args'       => array('add'),
202
+			),
203
+			'edit_category'                 => array(
204
+				'func'       => '_category_details',
205
+				'capability' => 'ee_edit_event_category',
206
+				'args'       => array('edit'),
207
+			),
208
+			'delete_categories'             => array(
209
+				'func'       => '_delete_categories',
210
+				'capability' => 'ee_delete_event_category',
211
+				'noheader'   => true,
212
+			),
213
+			'delete_category'               => array(
214
+				'func'       => '_delete_categories',
215
+				'capability' => 'ee_delete_event_category',
216
+				'noheader'   => true,
217
+			),
218
+			'insert_category'               => array(
219
+				'func'       => '_insert_or_update_category',
220
+				'args'       => array('new_category' => true),
221
+				'capability' => 'ee_edit_event_category',
222
+				'noheader'   => true,
223
+			),
224
+			'update_category'               => array(
225
+				'func'       => '_insert_or_update_category',
226
+				'args'       => array('new_category' => false),
227
+				'capability' => 'ee_edit_event_category',
228
+				'noheader'   => true,
229
+			),
230
+			'category_list'                 => array(
231
+				'func'       => '_category_list_table',
232
+				'capability' => 'ee_manage_event_categories',
233
+			),
234
+		);
235
+	}
236
+
237
+
238
+	/**
239
+	 * Set the _page_config property for this admin page group.
240
+	 */
241
+	protected function _set_page_config()
242
+	{
243
+		$this->_page_config = array(
244
+			'default'                => array(
245
+				'nav'           => array(
246
+					'label' => esc_html__('Overview', 'event_espresso'),
247
+					'order' => 10,
248
+				),
249
+				'list_table'    => 'Events_Admin_List_Table',
250
+				'help_tabs'     => array(
251
+					'events_overview_help_tab'                       => array(
252
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
253
+						'filename' => 'events_overview',
254
+					),
255
+					'events_overview_table_column_headings_help_tab' => array(
256
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
257
+						'filename' => 'events_overview_table_column_headings',
258
+					),
259
+					'events_overview_filters_help_tab'               => array(
260
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
261
+						'filename' => 'events_overview_filters',
262
+					),
263
+					'events_overview_view_help_tab'                  => array(
264
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
265
+						'filename' => 'events_overview_views',
266
+					),
267
+					'events_overview_other_help_tab'                 => array(
268
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
269
+						'filename' => 'events_overview_other',
270
+					),
271
+				),
272
+				'help_tour'     => array(
273
+					'Event_Overview_Help_Tour',
274
+					//'New_Features_Test_Help_Tour' for testing multiple help tour
275
+				),
276
+				'qtips'         => array(
277
+					'EE_Event_List_Table_Tips',
278
+				),
279
+				'require_nonce' => false,
280
+			),
281
+			'create_new'             => array(
282
+				'nav'           => array(
283
+					'label'      => esc_html__('Add Event', 'event_espresso'),
284
+					'order'      => 5,
285
+					'persistent' => false,
286
+				),
287
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
288
+				'help_tabs'     => array(
289
+					'event_editor_help_tab'                            => array(
290
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
291
+						'filename' => 'event_editor',
292
+					),
293
+					'event_editor_title_richtexteditor_help_tab'       => array(
294
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
295
+						'filename' => 'event_editor_title_richtexteditor',
296
+					),
297
+					'event_editor_venue_details_help_tab'              => array(
298
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
299
+						'filename' => 'event_editor_venue_details',
300
+					),
301
+					'event_editor_event_datetimes_help_tab'            => array(
302
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
303
+						'filename' => 'event_editor_event_datetimes',
304
+					),
305
+					'event_editor_event_tickets_help_tab'              => array(
306
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
307
+						'filename' => 'event_editor_event_tickets',
308
+					),
309
+					'event_editor_event_registration_options_help_tab' => array(
310
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
311
+						'filename' => 'event_editor_event_registration_options',
312
+					),
313
+					'event_editor_tags_categories_help_tab'            => array(
314
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
315
+						'filename' => 'event_editor_tags_categories',
316
+					),
317
+					'event_editor_questions_registrants_help_tab'      => array(
318
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
319
+						'filename' => 'event_editor_questions_registrants',
320
+					),
321
+					'event_editor_save_new_event_help_tab'             => array(
322
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
323
+						'filename' => 'event_editor_save_new_event',
324
+					),
325
+					'event_editor_other_help_tab'                      => array(
326
+						'title'    => esc_html__('Event Other', 'event_espresso'),
327
+						'filename' => 'event_editor_other',
328
+					),
329
+				),
330
+				'help_tour'     => array(
331
+					'Event_Editor_Help_Tour',
332
+				),
333
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
334
+				'require_nonce' => false,
335
+			),
336
+			'edit'                   => array(
337
+				'nav'           => array(
338
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
339
+					'order'      => 5,
340
+					'persistent' => false,
341
+					'url'        => isset($this->_req_data['post'])
342
+						? EE_Admin_Page::add_query_args_and_nonce(
343
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
344
+							$this->_current_page_view_url
345
+						)
346
+						: $this->_admin_base_url,
347
+				),
348
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
349
+				'help_tabs'     => array(
350
+					'event_editor_help_tab'                            => array(
351
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
352
+						'filename' => 'event_editor',
353
+					),
354
+					'event_editor_title_richtexteditor_help_tab'       => array(
355
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
356
+						'filename' => 'event_editor_title_richtexteditor',
357
+					),
358
+					'event_editor_venue_details_help_tab'              => array(
359
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
360
+						'filename' => 'event_editor_venue_details',
361
+					),
362
+					'event_editor_event_datetimes_help_tab'            => array(
363
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
364
+						'filename' => 'event_editor_event_datetimes',
365
+					),
366
+					'event_editor_event_tickets_help_tab'              => array(
367
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
368
+						'filename' => 'event_editor_event_tickets',
369
+					),
370
+					'event_editor_event_registration_options_help_tab' => array(
371
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
372
+						'filename' => 'event_editor_event_registration_options',
373
+					),
374
+					'event_editor_tags_categories_help_tab'            => array(
375
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
376
+						'filename' => 'event_editor_tags_categories',
377
+					),
378
+					'event_editor_questions_registrants_help_tab'      => array(
379
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
380
+						'filename' => 'event_editor_questions_registrants',
381
+					),
382
+					'event_editor_save_new_event_help_tab'             => array(
383
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
384
+						'filename' => 'event_editor_save_new_event',
385
+					),
386
+					'event_editor_other_help_tab'                      => array(
387
+						'title'    => esc_html__('Event Other', 'event_espresso'),
388
+						'filename' => 'event_editor_other',
389
+					),
390
+				),
391
+				/*'help_tour' => array(
392 392
 					'Event_Edit_Help_Tour'
393 393
 				),*/
394
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
395
-                'require_nonce' => false,
396
-            ),
397
-            'default_event_settings' => array(
398
-                'nav'           => array(
399
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
400
-                    'order' => 40,
401
-                ),
402
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
403
-                'labels'        => array(
404
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
405
-                ),
406
-                'help_tabs'     => array(
407
-                    'default_settings_help_tab'        => array(
408
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
409
-                        'filename' => 'events_default_settings',
410
-                    ),
411
-                    'default_settings_status_help_tab' => array(
412
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
413
-                        'filename' => 'events_default_settings_status',
414
-                    ),
415
-                    'default_maximum_tickets_help_tab' => array(
416
-                        'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
417
-                        'filename' => 'events_default_settings_max_tickets',
418
-                    )
419
-                ),
420
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
421
-                'require_nonce' => false,
422
-            ),
423
-            //template settings
424
-            'template_settings'      => array(
425
-                'nav'           => array(
426
-                    'label' => esc_html__('Templates', 'event_espresso'),
427
-                    'order' => 30,
428
-                ),
429
-                'metaboxes'     => $this->_default_espresso_metaboxes,
430
-                'help_tabs'     => array(
431
-                    'general_settings_templates_help_tab' => array(
432
-                        'title'    => esc_html__('Templates', 'event_espresso'),
433
-                        'filename' => 'general_settings_templates',
434
-                    ),
435
-                ),
436
-                'help_tour'     => array('Templates_Help_Tour'),
437
-                'require_nonce' => false,
438
-            ),
439
-            //event category stuff
440
-            'add_category'           => array(
441
-                'nav'           => array(
442
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
443
-                    'order'      => 15,
444
-                    'persistent' => false,
445
-                ),
446
-                'help_tabs'     => array(
447
-                    'add_category_help_tab' => array(
448
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
449
-                        'filename' => 'events_add_category',
450
-                    ),
451
-                ),
452
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
453
-                'metaboxes'     => array('_publish_post_box'),
454
-                'require_nonce' => false,
455
-            ),
456
-            'edit_category'          => array(
457
-                'nav'           => array(
458
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
459
-                    'order'      => 15,
460
-                    'persistent' => false,
461
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
462
-                        ? add_query_arg(
463
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
464
-                            $this->_current_page_view_url
465
-                        )
466
-                        : $this->_admin_base_url,
467
-                ),
468
-                'help_tabs'     => array(
469
-                    'edit_category_help_tab' => array(
470
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
471
-                        'filename' => 'events_edit_category',
472
-                    ),
473
-                ),
474
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
475
-                'metaboxes'     => array('_publish_post_box'),
476
-                'require_nonce' => false,
477
-            ),
478
-            'category_list'          => array(
479
-                'nav'           => array(
480
-                    'label' => esc_html__('Categories', 'event_espresso'),
481
-                    'order' => 20,
482
-                ),
483
-                'list_table'    => 'Event_Categories_Admin_List_Table',
484
-                'help_tabs'     => array(
485
-                    'events_categories_help_tab'                       => array(
486
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
487
-                        'filename' => 'events_categories',
488
-                    ),
489
-                    'events_categories_table_column_headings_help_tab' => array(
490
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
491
-                        'filename' => 'events_categories_table_column_headings',
492
-                    ),
493
-                    'events_categories_view_help_tab'                  => array(
494
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
495
-                        'filename' => 'events_categories_views',
496
-                    ),
497
-                    'events_categories_other_help_tab'                 => array(
498
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
499
-                        'filename' => 'events_categories_other',
500
-                    ),
501
-                ),
502
-                'help_tour'     => array(
503
-                    'Event_Categories_Help_Tour',
504
-                ),
505
-                'metaboxes'     => $this->_default_espresso_metaboxes,
506
-                'require_nonce' => false,
507
-            ),
508
-        );
509
-    }
510
-
511
-
512
-    /**
513
-     * Used to register any global screen options if necessary for every route in this admin page group.
514
-     */
515
-    protected function _add_screen_options()
516
-    {
517
-    }
518
-
519
-
520
-    /**
521
-     * Implementing the screen options for the 'default' route.
522
-     */
523
-    protected function _add_screen_options_default()
524
-    {
525
-        $this->_per_page_screen_option();
526
-    }
527
-
528
-
529
-    /**
530
-     * Implementing screen options for the category list route.
531
-     */
532
-    protected function _add_screen_options_category_list()
533
-    {
534
-        $page_title = $this->_admin_page_title;
535
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
536
-        $this->_per_page_screen_option();
537
-        $this->_admin_page_title = $page_title;
538
-    }
539
-
540
-
541
-    /**
542
-     * Used to register any global feature pointers for the admin page group.
543
-     */
544
-    protected function _add_feature_pointers()
545
-    {
546
-    }
547
-
548
-
549
-    /**
550
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
551
-     */
552
-    public function load_scripts_styles()
553
-    {
554
-        wp_register_style(
555
-            'events-admin-css',
556
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
557
-            array(),
558
-            EVENT_ESPRESSO_VERSION
559
-        );
560
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
561
-        wp_enqueue_style('events-admin-css');
562
-        wp_enqueue_style('ee-cat-admin');
563
-        //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
564
-        //registers for all views
565
-        //scripts
566
-        wp_register_script(
567
-            'event_editor_js',
568
-            EVENTS_ASSETS_URL . 'event_editor.js',
569
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
570
-            EVENT_ESPRESSO_VERSION,
571
-            true
572
-        );
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * Enqueuing scripts and styles specific to this view
579
-     */
580
-    public function load_scripts_styles_create_new()
581
-    {
582
-        $this->load_scripts_styles_edit();
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     * Enqueuing scripts and styles specific to this view
589
-     */
590
-    public function load_scripts_styles_edit()
591
-    {
592
-        //styles
593
-        wp_enqueue_style('espresso-ui-theme');
594
-        wp_register_style(
595
-            'event-editor-css',
596
-            EVENTS_ASSETS_URL . 'event-editor.css',
597
-            array('ee-admin-css'),
598
-            EVENT_ESPRESSO_VERSION
599
-        );
600
-        wp_enqueue_style('event-editor-css');
601
-        //scripts
602
-        wp_register_script(
603
-            'event-datetime-metabox',
604
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
605
-            array('event_editor_js', 'ee-datepicker'),
606
-            EVENT_ESPRESSO_VERSION
607
-        );
608
-        wp_enqueue_script('event-datetime-metabox');
609
-    }
610
-
611
-
612
-    /**
613
-     * Populating the _views property for the category list table view.
614
-     */
615
-    protected function _set_list_table_views_category_list()
616
-    {
617
-        $this->_views = array(
618
-            'all' => array(
619
-                'slug'        => 'all',
620
-                'label'       => esc_html__('All', 'event_espresso'),
621
-                'count'       => 0,
622
-                'bulk_action' => array(
623
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
624
-                ),
625
-            ),
626
-        );
627
-    }
628
-
629
-
630
-    /**
631
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
632
-     */
633
-    public function admin_init()
634
-    {
635
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
636
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
637
-            'event_espresso'
638
-        );
639
-    }
640
-
641
-
642
-    /**
643
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page group.
644
-     */
645
-    public function admin_notices()
646
-    {
647
-    }
648
-
649
-
650
-    /**
651
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
652
-     * this admin page group.
653
-     */
654
-    public function admin_footer_scripts()
655
-    {
656
-    }
657
-
658
-
659
-
660
-    /**
661
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
662
-     * warning (via EE_Error::add_error());
663
-     *
664
-     * @param  EE_Event $event Event object
665
-     * @param string    $req_type
666
-     * @return void
667
-     * @throws EE_Error
668
-     * @access public
669
-     */
670
-    public function verify_event_edit($event = null, $req_type = '')
671
-    {
672
-        // don't need to do this when processing
673
-        if(!empty($req_type)) {
674
-            return;
675
-        }
676
-        // no event?
677
-        if (empty($event)) {
678
-            // set event
679
-            $event = $this->_cpt_model_obj;
680
-        }
681
-        // STILL no event?
682
-        if (! $event instanceof EE_Event) {
683
-            return;
684
-        }
685
-        $orig_status = $event->status();
686
-        // first check if event is active.
687
-        if (
688
-            $orig_status === EEM_Event::cancelled
689
-            || $orig_status === EEM_Event::postponed
690
-            || $event->is_expired()
691
-            || $event->is_inactive()
692
-        ) {
693
-            return;
694
-        }
695
-        //made it here so it IS active... next check that any of the tickets are sold.
696
-        if ($event->is_sold_out(true)) {
697
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
698
-                EE_Error::add_attention(
699
-                    sprintf(
700
-                        esc_html__(
701
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
702
-                            'event_espresso'
703
-                        ),
704
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
705
-                    )
706
-                );
707
-            }
708
-            return;
709
-        } else if ($orig_status === EEM_Event::sold_out) {
710
-            EE_Error::add_attention(
711
-                sprintf(
712
-                    esc_html__(
713
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
714
-                        'event_espresso'
715
-                    ),
716
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
717
-                )
718
-            );
719
-        }
720
-        //now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
721
-        if ( ! $event->tickets_on_sale()) {
722
-            return;
723
-        }
724
-        //made it here so show warning
725
-        $this->_edit_event_warning();
726
-    }
727
-
728
-
729
-
730
-    /**
731
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
732
-     * When needed, hook this into a EE_Error::add_error() notice.
733
-     *
734
-     * @access protected
735
-     * @return void
736
-     */
737
-    protected function _edit_event_warning()
738
-    {
739
-        // we don't want to add warnings during these requests
740
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
741
-            return;
742
-        }
743
-        EE_Error::add_attention(
744
-            esc_html__(
745
-                'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
746
-                'event_espresso'
747
-            )
748
-        );
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * When a user is creating a new event, notify them if they haven't set their timezone.
755
-     * Otherwise, do the normal logic
756
-     *
757
-     * @return string
758
-     * @throws \EE_Error
759
-     */
760
-    protected function _create_new_cpt_item()
761
-    {
762
-        $has_timezone_string = get_option('timezone_string');
763
-        //only nag them about setting their timezone if it's their first event, and they haven't already done it
764
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
765
-            EE_Error::add_attention(
766
-                sprintf(
767
-                    __(
768
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
769
-                        'event_espresso'
770
-                    ),
771
-                    '<br>',
772
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
773
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
774
-                    . '</select>',
775
-                    '<button class="button button-secondary timezone-submit">',
776
-                    '</button><span class="spinner"></span>'
777
-                ),
778
-                __FILE__,
779
-                __FUNCTION__,
780
-                __LINE__
781
-            );
782
-        }
783
-        return parent::_create_new_cpt_item();
784
-    }
785
-
786
-
787
-    /**
788
-     * Sets the _views property for the default route in this admin page group.
789
-     */
790
-    protected function _set_list_table_views_default()
791
-    {
792
-        $this->_views = array(
793
-            'all'   => array(
794
-                'slug'        => 'all',
795
-                'label'       => esc_html__('View All Events', 'event_espresso'),
796
-                'count'       => 0,
797
-                'bulk_action' => array(
798
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
799
-                ),
800
-            ),
801
-            'draft' => array(
802
-                'slug'        => 'draft',
803
-                'label'       => esc_html__('Draft', 'event_espresso'),
804
-                'count'       => 0,
805
-                'bulk_action' => array(
806
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
807
-                ),
808
-            ),
809
-        );
810
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
811
-            $this->_views['trash'] = array(
812
-                'slug'        => 'trash',
813
-                'label'       => esc_html__('Trash', 'event_espresso'),
814
-                'count'       => 0,
815
-                'bulk_action' => array(
816
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
817
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
818
-                ),
819
-            );
820
-        }
821
-    }
822
-
823
-
824
-
825
-    /**
826
-     * Provides the legend item array for the default list table view.
827
-     * @return array
828
-     */
829
-    protected function _event_legend_items()
830
-    {
831
-        $items = array(
832
-            'view_details'   => array(
833
-                'class' => 'dashicons dashicons-search',
834
-                'desc'  => esc_html__('View Event', 'event_espresso'),
835
-            ),
836
-            'edit_event'     => array(
837
-                'class' => 'ee-icon ee-icon-calendar-edit',
838
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
839
-            ),
840
-            'view_attendees' => array(
841
-                'class' => 'dashicons dashicons-groups',
842
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
843
-            ),
844
-        );
845
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
846
-        $statuses = array(
847
-            'sold_out_status'  => array(
848
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
849
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
850
-            ),
851
-            'active_status'    => array(
852
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
853
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
854
-            ),
855
-            'upcoming_status'  => array(
856
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
857
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
858
-            ),
859
-            'postponed_status' => array(
860
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
861
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
862
-            ),
863
-            'cancelled_status' => array(
864
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
865
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
866
-            ),
867
-            'expired_status'   => array(
868
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
869
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
870
-            ),
871
-            'inactive_status'  => array(
872
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
873
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
874
-            ),
875
-        );
876
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
877
-        return array_merge($items, $statuses);
878
-    }
879
-
880
-
881
-
882
-    /**
883
-     * @return EEM_Event
884
-     */
885
-    private function _event_model()
886
-    {
887
-        if ( ! $this->_event_model instanceof EEM_Event) {
888
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
889
-        }
890
-        return $this->_event_model;
891
-    }
892
-
893
-
894
-
895
-    /**
896
-     * Adds extra buttons to the WP CPT permalink field row.
897
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
898
-     *
899
-     * @param  string $return    the current html
900
-     * @param  int    $id        the post id for the page
901
-     * @param  string $new_title What the title is
902
-     * @param  string $new_slug  what the slug is
903
-     * @return string            The new html string for the permalink area
904
-     */
905
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
906
-    {
907
-        //make sure this is only when editing
908
-        if ( ! empty($id)) {
909
-            $post = get_post($id);
910
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
911
-                       . esc_html__('Shortcode', 'event_espresso')
912
-                       . '</a> ';
913
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
914
-                       . $post->ID
915
-                       . ']">';
916
-        }
917
-        return $return;
918
-    }
919
-
920
-
921
-
922
-    /**
923
-     * _events_overview_list_table
924
-     * This contains the logic for showing the events_overview list
925
-     *
926
-     * @access protected
927
-     * @return void
928
-     * @throws \EE_Error
929
-     */
930
-    protected function _events_overview_list_table()
931
-    {
932
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
933
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
934
-            ? (array)$this->_template_args['after_list_table']
935
-            : array();
936
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
937
-                                                                              . EEH_Template::get_button_or_link(
938
-                get_post_type_archive_link('espresso_events'),
939
-                esc_html__("View Event Archive Page", "event_espresso"),
940
-                'button'
941
-            );
942
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
943
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
944
-                'create_new',
945
-                'add',
946
-                array(),
947
-                'add-new-h2'
948
-            );
949
-        $this->display_admin_list_table_page_with_no_sidebar();
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * this allows for extra misc actions in the default WP publish box
956
-     *
957
-     * @return void
958
-     */
959
-    public function extra_misc_actions_publish_box()
960
-    {
961
-        $this->_generate_publish_box_extra_content();
962
-    }
963
-
964
-
965
-
966
-    /**
967
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been saved.
968
-     * Typically you would use this to save any additional data.
969
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
970
-     * ALSO very important.  When a post transitions from scheduled to published,
971
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from other meta saves.
972
-     * So MAKE sure that you handle this accordingly.
973
-     *
974
-     * @access protected
975
-     * @abstract
976
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
977
-     * @param  object $post    The post object of the cpt that was saved.
978
-     * @return void
979
-     * @throws \EE_Error
980
-     */
981
-    protected function _insert_update_cpt_item($post_id, $post)
982
-    {
983
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
984
-            //get out we're not processing an event save.
985
-            return;
986
-        }
987
-        $event_values = array(
988
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
989
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
990
-            'EVT_additional_limit'            => min(
991
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
992
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
993
-            ),
994
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
995
-                ? $this->_req_data['EVT_default_registration_status']
996
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
997
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
998
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
999
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1000
-                ? $this->_req_data['timezone_string'] : null,
1001
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1002
-                ? $this->_req_data['externalURL'] : null,
1003
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1004
-                ? $this->_req_data['event_phone'] : null,
1005
-        );
1006
-        //update event
1007
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1008
-        //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1009
-        $get_one_where = array(
1010
-            $this->_event_model()->primary_key_name() => $post_id,
1011
-            'OR' => array(
1012
-                'status' => $post->post_status,
1013
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1014
-                // but the returned object here has a status of "publish", so use the original post status as well
1015
-                'status*1' => $this->_req_data['original_post_status'],
1016
-            )
1017
-        );
1018
-        $event = $this->_event_model()->get_one(array($get_one_where));
1019
-        //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1020
-        $event_update_callbacks = apply_filters(
1021
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1022
-            array(
1023
-                array($this, '_default_venue_update'),
1024
-                array($this, '_default_tickets_update')
1025
-            )
1026
-        );
1027
-        $att_success = true;
1028
-        foreach ($event_update_callbacks as $e_callback) {
1029
-            $_success = $e_callback($event, $this->_req_data);
1030
-            //if ANY of these updates fail then we want the appropriate global error message
1031
-            $att_success = ! $att_success ? $att_success : $_success;
1032
-        }
1033
-        //any errors?
1034
-        if ($success && false === $att_success) {
1035
-            EE_Error::add_error(
1036
-                esc_html__(
1037
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1038
-                    'event_espresso'
1039
-                ),
1040
-                __FILE__,
1041
-                __FUNCTION__,
1042
-                __LINE__
1043
-            );
1044
-        } else if ($success === false) {
1045
-            EE_Error::add_error(
1046
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1047
-                __FILE__,
1048
-                __FUNCTION__,
1049
-                __LINE__
1050
-            );
1051
-        }
1052
-    }
1053
-
1054
-
1055
-
1056
-    /**
1057
-     * @see parent::restore_item()
1058
-     * @param int $post_id
1059
-     * @param int $revision_id
1060
-     */
1061
-    protected function _restore_cpt_item($post_id, $revision_id)
1062
-    {
1063
-        //copy existing event meta to new post
1064
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1065
-        if ($post_evt instanceof EE_Event) {
1066
-            //meta revision restore
1067
-            $post_evt->restore_revision($revision_id);
1068
-            //related objs restore
1069
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1070
-        }
1071
-    }
1072
-
1073
-
1074
-
1075
-    /**
1076
-     * Attach the venue to the Event
1077
-     *
1078
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1079
-     * @param  array     $data   The request data from the form
1080
-     * @return bool           Success or fail.
1081
-     */
1082
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1083
-    {
1084
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1085
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1086
-        $rows_affected = null;
1087
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1088
-        // very important.  If we don't have a venue name...
1089
-        // then we'll get out because not necessary to create empty venue
1090
-        if (empty($data['venue_title'])) {
1091
-            return false;
1092
-        }
1093
-        $venue_array = array(
1094
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1095
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1096
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1097
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1098
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1099
-                : null,
1100
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1101
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1102
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1103
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1104
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1105
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1106
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1107
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1108
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1109
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1110
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1111
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1112
-            'status'              => 'publish',
1113
-        );
1114
-        //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1115
-        if ( ! empty($venue_id)) {
1116
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1117
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1118
-            //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1119
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1120
-            return $rows_affected > 0 ? true : false;
1121
-        } else {
1122
-            //we insert the venue
1123
-            $venue_id = $venue_model->insert($venue_array);
1124
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1125
-            return ! empty($venue_id) ? true : false;
1126
-        }
1127
-        //when we have the ancestor come in it's already been handled by the revision save.
1128
-    }
1129
-
1130
-
1131
-
1132
-    /**
1133
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1134
-     *
1135
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1136
-     * @param  array    $data   The request data from the form
1137
-     * @return array
1138
-     */
1139
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1140
-    {
1141
-        $success = true;
1142
-        $saved_dtt = null;
1143
-        $saved_tickets = array();
1144
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1145
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1146
-            //trim all values to ensure any excess whitespace is removed.
1147
-            $dtt = array_map('trim', $dtt);
1148
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1149
-                : $dtt['DTT_EVT_start'];
1150
-            $datetime_values = array(
1151
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1152
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1153
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1154
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1155
-                'DTT_order'     => $row,
1156
-            );
1157
-            //if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1158
-            if ( ! empty($dtt['DTT_ID'])) {
1159
-                $DTM = EE_Registry::instance()
1160
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1161
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1162
-                $DTM->set_date_format($incoming_date_formats[0]);
1163
-                $DTM->set_time_format($incoming_date_formats[1]);
1164
-                foreach ($datetime_values as $field => $value) {
1165
-                    $DTM->set($field, $value);
1166
-                }
1167
-                //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1168
-                $saved_dtts[$DTM->ID()] = $DTM;
1169
-            } else {
1170
-                $DTM = EE_Registry::instance()->load_class(
1171
-                    'Datetime',
1172
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1173
-                    false,
1174
-                    false
1175
-                );
1176
-                foreach ($datetime_values as $field => $value) {
1177
-                    $DTM->set($field, $value);
1178
-                }
1179
-            }
1180
-            $DTM->save();
1181
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1182
-            //load DTT helper
1183
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1184
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1185
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1186
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1187
-                $DTT->save();
1188
-            }
1189
-            //now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1190
-            $saved_dtt = $DTT;
1191
-            $success = ! $success ? $success : $DTT;
1192
-            //if ANY of these updates fail then we want the appropriate global error message.
1193
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1194
-        }
1195
-        //no dtts get deleted so we don't do any of that logic here.
1196
-        //update tickets next
1197
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1198
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1199
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1200
-            $update_prices = false;
1201
-            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1202
-                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1203
-            // trim inputs to ensure any excess whitespace is removed.
1204
-            $tkt = array_map('trim', $tkt);
1205
-            if (empty($tkt['TKT_start_date'])) {
1206
-                //let's use now in the set timezone.
1207
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1208
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1209
-            }
1210
-            if (empty($tkt['TKT_end_date'])) {
1211
-                //use the start date of the first datetime
1212
-                $dtt = $evtobj->first_datetime();
1213
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1214
-                    $incoming_date_formats[0],
1215
-                    $incoming_date_formats[1]
1216
-                );
1217
-            }
1218
-            $TKT_values = array(
1219
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1220
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1221
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1222
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1223
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1224
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1225
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1226
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1227
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1228
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1229
-                'TKT_row'         => $row,
1230
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1231
-                'TKT_price'       => $ticket_price,
1232
-            );
1233
-            //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1234
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1235
-                $TKT_values['TKT_ID'] = 0;
1236
-                $TKT_values['TKT_is_default'] = 0;
1237
-                $TKT_values['TKT_price'] = $ticket_price;
1238
-                $update_prices = true;
1239
-            }
1240
-            //if we have a TKT_ID then we need to get that existing TKT_obj and update it
1241
-            //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1242
-            //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1243
-            if ( ! empty($tkt['TKT_ID'])) {
1244
-                $TKT = EE_Registry::instance()
1245
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1246
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1247
-                if ($TKT instanceof EE_Ticket) {
1248
-                    $ticket_sold = $TKT->count_related(
1249
-                        'Registration',
1250
-                        array(
1251
-                            array(
1252
-                                'STS_ID' => array(
1253
-                                    'NOT IN',
1254
-                                    array(EEM_Registration::status_id_incomplete),
1255
-                                ),
1256
-                            ),
1257
-                        )
1258
-                    ) > 0 ? true : false;
1259
-                    //let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1260
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1261
-                                      && ! $TKT->get(
1262
-                        'TKT_deleted'
1263
-                    ) ? true : false;
1264
-                    $TKT->set_date_format($incoming_date_formats[0]);
1265
-                    $TKT->set_time_format($incoming_date_formats[1]);
1266
-                    //set new values
1267
-                    foreach ($TKT_values as $field => $value) {
1268
-                        if ($field == 'TKT_qty') {
1269
-                            $TKT->set_qty($value);
1270
-                        } else {
1271
-                            $TKT->set($field, $value);
1272
-                        }
1273
-                    }
1274
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1275
-                    if ($create_new_TKT) {
1276
-                        //archive the old ticket first
1277
-                        $TKT->set('TKT_deleted', 1);
1278
-                        $TKT->save();
1279
-                        //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1280
-                        $saved_tickets[$TKT->ID()] = $TKT;
1281
-                        //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1282
-                        $TKT = clone $TKT;
1283
-                        $TKT->set('TKT_ID', 0);
1284
-                        $TKT->set('TKT_deleted', 0);
1285
-                        $TKT->set('TKT_price', $ticket_price);
1286
-                        $TKT->set('TKT_sold', 0);
1287
-                        //now we need to make sure that $new prices are created as well and attached to new ticket.
1288
-                        $update_prices = true;
1289
-                    }
1290
-                    //make sure price is set if it hasn't been already
1291
-                    $TKT->set('TKT_price', $ticket_price);
1292
-                }
1293
-            } else {
1294
-                //no TKT_id so a new TKT
1295
-                $TKT_values['TKT_price'] = $ticket_price;
1296
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1297
-                if ($TKT instanceof EE_Ticket) {
1298
-                    //need to reset values to properly account for the date formats
1299
-                    $TKT->set_date_format($incoming_date_formats[0]);
1300
-                    $TKT->set_time_format($incoming_date_formats[1]);
1301
-                    $TKT->set_timezone($evtobj->get_timezone());
1302
-                    //set new values
1303
-                    foreach ($TKT_values as $field => $value) {
1304
-                        if ($field == 'TKT_qty') {
1305
-                            $TKT->set_qty($value);
1306
-                        } else {
1307
-                            $TKT->set($field, $value);
1308
-                        }
1309
-                    }
1310
-                    $update_prices = true;
1311
-                }
1312
-            }
1313
-            // cap ticket qty by datetime reg limits
1314
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1315
-            //update ticket.
1316
-            $TKT->save();
1317
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1318
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1319
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1320
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1321
-                $TKT->save();
1322
-            }
1323
-            //initially let's add the ticket to the dtt
1324
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1325
-            $saved_tickets[$TKT->ID()] = $TKT;
1326
-            //add prices to ticket
1327
-            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1328
-        }
1329
-        //however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1330
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1331
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1332
-        foreach ($tickets_removed as $id) {
1333
-            $id = absint($id);
1334
-            //get the ticket for this id
1335
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1336
-            //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1337
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1338
-            foreach ($dtts as $dtt) {
1339
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1340
-            }
1341
-            //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1342
-            $tkt_to_remove->delete_related_permanently('Price');
1343
-            //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1344
-            $tkt_to_remove->delete_permanently();
1345
-        }
1346
-        return array($saved_dtt, $saved_tickets);
1347
-    }
1348
-
1349
-
1350
-
1351
-    /**
1352
-     * This attaches a list of given prices to a ticket.
1353
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1354
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1355
-     * price info and prices are automatically "archived" via the ticket.
1356
-     *
1357
-     * @access  private
1358
-     * @param array     $prices     Array of prices from the form.
1359
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1360
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1361
-     * @return  void
1362
-     */
1363
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1364
-    {
1365
-        foreach ($prices as $row => $prc) {
1366
-            $PRC_values = array(
1367
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1368
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1369
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1370
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1371
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1372
-                'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1373
-                'PRC_order'      => $row,
1374
-            );
1375
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1376
-                $PRC_values['PRC_ID'] = 0;
1377
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1378
-            } else {
1379
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1380
-                //update this price with new values
1381
-                foreach ($PRC_values as $field => $newprc) {
1382
-                    $PRC->set($field, $newprc);
1383
-                }
1384
-                $PRC->save();
1385
-            }
1386
-            $ticket->_add_relation_to($PRC, 'Price');
1387
-        }
1388
-    }
1389
-
1390
-
1391
-
1392
-    /**
1393
-     * Add in our autosave ajax handlers
1394
-     *
1395
-     */
1396
-    protected function _ee_autosave_create_new()
1397
-    {
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     * More autosave handlers.
1403
-     */
1404
-    protected function _ee_autosave_edit()
1405
-    {
1406
-        return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1407
-    }
1408
-
1409
-
1410
-
1411
-    /**
1412
-     *    _generate_publish_box_extra_content
1413
-     */
1414
-    private function _generate_publish_box_extra_content()
1415
-    {
1416
-        //load formatter helper
1417
-        //args for getting related registrations
1418
-        $approved_query_args = array(
1419
-            array(
1420
-                'REG_deleted' => 0,
1421
-                'STS_ID'      => EEM_Registration::status_id_approved,
1422
-            ),
1423
-        );
1424
-        $not_approved_query_args = array(
1425
-            array(
1426
-                'REG_deleted' => 0,
1427
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1428
-            ),
1429
-        );
1430
-        $pending_payment_query_args = array(
1431
-            array(
1432
-                'REG_deleted' => 0,
1433
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1434
-            ),
1435
-        );
1436
-        // publish box
1437
-        $publish_box_extra_args = array(
1438
-            'view_approved_reg_url'        => add_query_arg(
1439
-                array(
1440
-                    'action'      => 'default',
1441
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1442
-                    '_reg_status' => EEM_Registration::status_id_approved,
1443
-                ),
1444
-                REG_ADMIN_URL
1445
-            ),
1446
-            'view_not_approved_reg_url'    => add_query_arg(
1447
-                array(
1448
-                    'action'      => 'default',
1449
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1450
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1451
-                ),
1452
-                REG_ADMIN_URL
1453
-            ),
1454
-            'view_pending_payment_reg_url' => add_query_arg(
1455
-                array(
1456
-                    'action'      => 'default',
1457
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1458
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1459
-                ),
1460
-                REG_ADMIN_URL
1461
-            ),
1462
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1463
-                'Registration',
1464
-                $approved_query_args
1465
-            ),
1466
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1467
-                'Registration',
1468
-                $not_approved_query_args
1469
-            ),
1470
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1471
-                'Registration',
1472
-                $pending_payment_query_args
1473
-            ),
1474
-            'misc_pub_section_class'       => apply_filters(
1475
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1476
-                'misc-pub-section'
1477
-            ),
1478
-        );
1479
-        ob_start();
1480
-        do_action(
1481
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1482
-            $this->_cpt_model_obj
1483
-        );
1484
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1485
-        // load template
1486
-        EEH_Template::display_template(
1487
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1488
-            $publish_box_extra_args
1489
-        );
1490
-    }
1491
-
1492
-
1493
-
1494
-    /**
1495
-     * @return EE_Event
1496
-     */
1497
-    public function get_event_object()
1498
-    {
1499
-        return $this->_cpt_model_obj;
1500
-    }
1501
-
1502
-
1503
-
1504
-
1505
-    /** METABOXES * */
1506
-    /**
1507
-     * _register_event_editor_meta_boxes
1508
-     * add all metaboxes related to the event_editor
1509
-     *
1510
-     * @return void
1511
-     */
1512
-    protected function _register_event_editor_meta_boxes()
1513
-    {
1514
-        $this->verify_cpt_object();
1515
-        add_meta_box(
1516
-            'espresso_event_editor_tickets',
1517
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1518
-            array($this, 'ticket_metabox'),
1519
-            $this->page_slug,
1520
-            'normal',
1521
-            'high'
1522
-        );
1523
-        add_meta_box(
1524
-            'espresso_event_editor_event_options',
1525
-            esc_html__('Event Registration Options', 'event_espresso'),
1526
-            array($this, 'registration_options_meta_box'),
1527
-            $this->page_slug,
1528
-            'side',
1529
-            'default'
1530
-        );
1531
-        // NOTE: if you're looking for other metaboxes in here,
1532
-        // where a metabox has a related management page in the admin
1533
-        // you will find it setup in the related management page's "_Hooks" file.
1534
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1535
-    }
1536
-
1537
-
1538
-    /**
1539
-     * @throws DomainException
1540
-     * @throws EE_Error
1541
-     */
1542
-    public function ticket_metabox()
1543
-    {
1544
-        $existing_datetime_ids = $existing_ticket_ids = array();
1545
-        //defaults for template args
1546
-        $template_args = array(
1547
-            'existing_datetime_ids'    => '',
1548
-            'event_datetime_help_link' => '',
1549
-            'ticket_options_help_link' => '',
1550
-            'time'                     => null,
1551
-            'ticket_rows'              => '',
1552
-            'existing_ticket_ids'      => '',
1553
-            'total_ticket_rows'        => 1,
1554
-            'ticket_js_structure'      => '',
1555
-            'trash_icon'               => 'ee-lock-icon',
1556
-            'disabled'                 => '',
1557
-        );
1558
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1559
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1560
-        /**
1561
-         * 1. Start with retrieving Datetimes
1562
-         * 2. Fore each datetime get related tickets
1563
-         * 3. For each ticket get related prices
1564
-         */
1565
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1566
-        /** @type EE_Datetime $first_datetime */
1567
-        $first_datetime = reset($times);
1568
-        //do we get related tickets?
1569
-        if ($first_datetime instanceof EE_Datetime
1570
-            && $first_datetime->ID() !== 0
1571
-        ) {
1572
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1573
-            $template_args['time'] = $first_datetime;
1574
-            $related_tickets = $first_datetime->tickets(
1575
-                array(
1576
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1577
-                    'default_where_conditions' => 'none',
1578
-                )
1579
-            );
1580
-            if ( ! empty($related_tickets)) {
1581
-                $template_args['total_ticket_rows'] = count($related_tickets);
1582
-                $row = 0;
1583
-                foreach ($related_tickets as $ticket) {
1584
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1585
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1586
-                    $row++;
1587
-                }
1588
-            } else {
1589
-                $template_args['total_ticket_rows'] = 1;
1590
-                /** @type EE_Ticket $ticket */
1591
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1592
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1593
-            }
1594
-        } else {
1595
-            $template_args['time'] = $times[0];
1596
-            /** @type EE_Ticket $ticket */
1597
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1598
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1599
-            // NOTE: we're just sending the first default row
1600
-            // (decaf can't manage default tickets so this should be sufficient);
1601
-        }
1602
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1603
-            'event_editor_event_datetimes_help_tab'
1604
-        );
1605
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1606
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1607
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1608
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1609
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1610
-            true
1611
-        );
1612
-        $template = apply_filters(
1613
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1614
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1615
-        );
1616
-        EEH_Template::display_template($template, $template_args);
1617
-    }
1618
-
1619
-
1620
-
1621
-    /**
1622
-     * Setup an individual ticket form for the decaf event editor page
1623
-     *
1624
-     * @access private
1625
-     * @param  EE_Ticket $ticket   the ticket object
1626
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1627
-     * @param int        $row
1628
-     * @return string generated html for the ticket row.
1629
-     */
1630
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1631
-    {
1632
-        $template_args = array(
1633
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1634
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1635
-                : '',
1636
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1637
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1638
-            'TKT_name'            => $ticket->get('TKT_name'),
1639
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1640
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1641
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1642
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1643
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1644
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1645
-            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1646
-                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1647
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1648
-            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1649
-                : ' disabled=disabled',
1650
-        );
1651
-        $price = $ticket->ID() !== 0
1652
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1653
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1654
-        $price_args = array(
1655
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1656
-            'PRC_amount'            => $price->get('PRC_amount'),
1657
-            'PRT_ID'                => $price->get('PRT_ID'),
1658
-            'PRC_ID'                => $price->get('PRC_ID'),
1659
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1660
-        );
1661
-        //make sure we have default start and end dates if skeleton
1662
-        //handle rows that should NOT be empty
1663
-        if (empty($template_args['TKT_start_date'])) {
1664
-            //if empty then the start date will be now.
1665
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1666
-        }
1667
-        if (empty($template_args['TKT_end_date'])) {
1668
-            //get the earliest datetime (if present);
1669
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1670
-                ? $this->_cpt_model_obj->get_first_related(
1671
-                    'Datetime',
1672
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1673
-                )
1674
-                : null;
1675
-            if ( ! empty($earliest_dtt)) {
1676
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1677
-            } else {
1678
-                $template_args['TKT_end_date'] = date(
1679
-                    'Y-m-d h:i a',
1680
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1681
-                );
1682
-            }
1683
-        }
1684
-        $template_args = array_merge($template_args, $price_args);
1685
-        $template = apply_filters(
1686
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1687
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1688
-            $ticket
1689
-        );
1690
-        return EEH_Template::display_template($template, $template_args, true);
1691
-    }
1692
-
1693
-
1694
-    /**
1695
-     * @throws DomainException
1696
-     */
1697
-    public function registration_options_meta_box()
1698
-    {
1699
-        $yes_no_values = array(
1700
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1701
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1702
-        );
1703
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1704
-            array(
1705
-                EEM_Registration::status_id_cancelled,
1706
-                EEM_Registration::status_id_declined,
1707
-                EEM_Registration::status_id_incomplete,
1708
-            ),
1709
-            true
1710
-        );
1711
-        //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1712
-        $template_args['_event'] = $this->_cpt_model_obj;
1713
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1714
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1715
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1716
-            'default_reg_status',
1717
-            $default_reg_status_values,
1718
-            $this->_cpt_model_obj->default_registration_status()
1719
-        );
1720
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1721
-            'display_desc',
1722
-            $yes_no_values,
1723
-            $this->_cpt_model_obj->display_description()
1724
-        );
1725
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1726
-            'display_ticket_selector',
1727
-            $yes_no_values,
1728
-            $this->_cpt_model_obj->display_ticket_selector(),
1729
-            '',
1730
-            '',
1731
-            false
1732
-        );
1733
-        $template_args['additional_registration_options'] = apply_filters(
1734
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1735
-            '',
1736
-            $template_args,
1737
-            $yes_no_values,
1738
-            $default_reg_status_values
1739
-        );
1740
-        EEH_Template::display_template(
1741
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1742
-            $template_args
1743
-        );
1744
-    }
1745
-
1746
-
1747
-
1748
-    /**
1749
-     * _get_events()
1750
-     * This method simply returns all the events (for the given _view and paging)
1751
-     *
1752
-     * @access public
1753
-     * @param int  $per_page     count of items per page (20 default);
1754
-     * @param int  $current_page what is the current page being viewed.
1755
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1756
-     *                           If FALSE then we return an array of event objects
1757
-     *                           that match the given _view and paging parameters.
1758
-     * @return array an array of event objects.
1759
-     */
1760
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1761
-    {
1762
-        $EEME = $this->_event_model();
1763
-        $offset = ($current_page - 1) * $per_page;
1764
-        $limit = $count ? null : $offset . ',' . $per_page;
1765
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1766
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1767
-        if (isset($this->_req_data['month_range'])) {
1768
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1769
-            //simulate the FIRST day of the month, that fixes issues for months like February
1770
-            //where PHP doesn't know what to assume for date.
1771
-            //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1772
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1773
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1774
-        }
1775
-        $where = array();
1776
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1777
-        //determine what post_status our condition will have for the query.
1778
-        switch ($status) {
1779
-            case 'month' :
1780
-            case 'today' :
1781
-            case null :
1782
-            case 'all' :
1783
-                break;
1784
-            case 'draft' :
1785
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1786
-                break;
1787
-            default :
1788
-                $where['status'] = $status;
1789
-        }
1790
-        //categories?
1791
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1792
-            ? $this->_req_data['EVT_CAT'] : null;
1793
-        if ( ! empty ($category)) {
1794
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1795
-            $where['Term_Taxonomy.term_id'] = $category;
1796
-        }
1797
-        //date where conditions
1798
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1799
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1800
-            $DateTime = new DateTime(
1801
-                $year_r . '-' . $month_r . '-01 00:00:00',
1802
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1803
-            );
1804
-            $start = $DateTime->format(implode(' ', $start_formats));
1805
-            $end = $DateTime->setDate($year_r, $month_r, $DateTime
1806
-                ->format('t'))->setTime(23, 59, 59)
1807
-                            ->format(implode(' ', $start_formats));
1808
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1809
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1810
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1811
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1812
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1813
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1814
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1815
-            $now = date('Y-m-01');
1816
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1817
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1818
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1819
-                            ->setTime(23, 59, 59)
1820
-                            ->format(implode(' ', $start_formats));
1821
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1822
-        }
1823
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1824
-            $where['EVT_wp_user'] = get_current_user_id();
1825
-        } else {
1826
-            if ( ! isset($where['status'])) {
1827
-                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1828
-                    $where['OR'] = array(
1829
-                        'status*restrict_private' => array('!=', 'private'),
1830
-                        'AND'                     => array(
1831
-                            'status*inclusive' => array('=', 'private'),
1832
-                            'EVT_wp_user'      => get_current_user_id(),
1833
-                        ),
1834
-                    );
1835
-                }
1836
-            }
1837
-        }
1838
-        if (isset($this->_req_data['EVT_wp_user'])) {
1839
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1840
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1841
-            ) {
1842
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1843
-            }
1844
-        }
1845
-        //search query handling
1846
-        if (isset($this->_req_data['s'])) {
1847
-            $search_string = '%' . $this->_req_data['s'] . '%';
1848
-            $where['OR'] = array(
1849
-                'EVT_name'       => array('LIKE', $search_string),
1850
-                'EVT_desc'       => array('LIKE', $search_string),
1851
-                'EVT_short_desc' => array('LIKE', $search_string),
1852
-            );
1853
-        }
1854
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1855
-        $query_params = apply_filters(
1856
-            'FHEE__Events_Admin_Page__get_events__query_params',
1857
-            array(
1858
-                $where,
1859
-                'limit'    => $limit,
1860
-                'order_by' => $orderby,
1861
-                'order'    => $order,
1862
-                'group_by' => 'EVT_ID',
1863
-            ),
1864
-            $this->_req_data
1865
-        );
1866
-        //let's first check if we have special requests coming in.
1867
-        if (isset($this->_req_data['active_status'])) {
1868
-            switch ($this->_req_data['active_status']) {
1869
-                case 'upcoming' :
1870
-                    return $EEME->get_upcoming_events($query_params, $count);
1871
-                    break;
1872
-                case 'expired' :
1873
-                    return $EEME->get_expired_events($query_params, $count);
1874
-                    break;
1875
-                case 'active' :
1876
-                    return $EEME->get_active_events($query_params, $count);
1877
-                    break;
1878
-                case 'inactive' :
1879
-                    return $EEME->get_inactive_events($query_params, $count);
1880
-                    break;
1881
-            }
1882
-        }
1883
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1884
-        return $events;
1885
-    }
1886
-
1887
-
1888
-
1889
-    /**
1890
-     * handling for WordPress CPT actions (trash, restore, delete)
1891
-     *
1892
-     * @param string $post_id
1893
-     */
1894
-    public function trash_cpt_item($post_id)
1895
-    {
1896
-        $this->_req_data['EVT_ID'] = $post_id;
1897
-        $this->_trash_or_restore_event('trash', false);
1898
-    }
1899
-
1900
-
1901
-
1902
-    /**
1903
-     * @param string $post_id
1904
-     */
1905
-    public function restore_cpt_item($post_id)
1906
-    {
1907
-        $this->_req_data['EVT_ID'] = $post_id;
1908
-        $this->_trash_or_restore_event('draft', false);
1909
-    }
1910
-
1911
-
1912
-
1913
-    /**
1914
-     * @param string $post_id
1915
-     */
1916
-    public function delete_cpt_item($post_id)
1917
-    {
1918
-        $this->_req_data['EVT_ID'] = $post_id;
1919
-        $this->_delete_event(false);
1920
-    }
1921
-
1922
-
1923
-
1924
-    /**
1925
-     * _trash_or_restore_event
1926
-     *
1927
-     * @access protected
1928
-     * @param  string $event_status
1929
-     * @param bool    $redirect_after
1930
-     */
1931
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1932
-    {
1933
-        //determine the event id and set to array.
1934
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1935
-        // loop thru events
1936
-        if ($EVT_ID) {
1937
-            // clean status
1938
-            $event_status = sanitize_key($event_status);
1939
-            // grab status
1940
-            if ( ! empty($event_status)) {
1941
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1942
-            } else {
1943
-                $success = false;
1944
-                $msg = esc_html__(
1945
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1946
-                    'event_espresso'
1947
-                );
1948
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1949
-            }
1950
-        } else {
1951
-            $success = false;
1952
-            $msg = esc_html__(
1953
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1954
-                'event_espresso'
1955
-            );
1956
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1957
-        }
1958
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1959
-        if ($redirect_after) {
1960
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1961
-        }
1962
-    }
1963
-
1964
-
1965
-
1966
-    /**
1967
-     * _trash_or_restore_events
1968
-     *
1969
-     * @access protected
1970
-     * @param  string $event_status
1971
-     * @return void
1972
-     */
1973
-    protected function _trash_or_restore_events($event_status = 'trash')
1974
-    {
1975
-        // clean status
1976
-        $event_status = sanitize_key($event_status);
1977
-        // grab status
1978
-        if ( ! empty($event_status)) {
1979
-            $success = true;
1980
-            //determine the event id and set to array.
1981
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1982
-            // loop thru events
1983
-            foreach ($EVT_IDs as $EVT_ID) {
1984
-                if ($EVT_ID = absint($EVT_ID)) {
1985
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1986
-                    $success = $results !== false ? $success : false;
1987
-                } else {
1988
-                    $msg = sprintf(
1989
-                        esc_html__(
1990
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1991
-                            'event_espresso'
1992
-                        ),
1993
-                        $EVT_ID
1994
-                    );
1995
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1996
-                    $success = false;
1997
-                }
1998
-            }
1999
-        } else {
2000
-            $success = false;
2001
-            $msg = esc_html__(
2002
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2003
-                'event_espresso'
2004
-            );
2005
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2006
-        }
2007
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2008
-        $success = $success ? 2 : false;
2009
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2010
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2011
-    }
2012
-
2013
-
2014
-
2015
-    /**
2016
-     * _trash_or_restore_events
2017
-     *
2018
-     * @access  private
2019
-     * @param  int    $EVT_ID
2020
-     * @param  string $event_status
2021
-     * @return bool
2022
-     */
2023
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2024
-    {
2025
-        // grab event id
2026
-        if ( ! $EVT_ID) {
2027
-            $msg = esc_html__(
2028
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2029
-                'event_espresso'
2030
-            );
2031
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2032
-            return false;
2033
-        }
2034
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2035
-        // clean status
2036
-        $event_status = sanitize_key($event_status);
2037
-        // grab status
2038
-        if (empty($event_status)) {
2039
-            $msg = esc_html__(
2040
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2041
-                'event_espresso'
2042
-            );
2043
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2044
-            return false;
2045
-        }
2046
-        // was event trashed or restored ?
2047
-        switch ($event_status) {
2048
-            case 'draft' :
2049
-                $action = 'restored from the trash';
2050
-                $hook = 'AHEE_event_restored_from_trash';
2051
-                break;
2052
-            case 'trash' :
2053
-                $action = 'moved to the trash';
2054
-                $hook = 'AHEE_event_moved_to_trash';
2055
-                break;
2056
-            default :
2057
-                $action = 'updated';
2058
-                $hook = false;
2059
-        }
2060
-        //use class to change status
2061
-        $this->_cpt_model_obj->set_status($event_status);
2062
-        $success = $this->_cpt_model_obj->save();
2063
-        if ($success === false) {
2064
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2065
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2066
-            return false;
2067
-        }
2068
-        if ($hook) {
2069
-            do_action($hook);
2070
-        }
2071
-        return true;
2072
-    }
2073
-
2074
-
2075
-
2076
-    /**
2077
-     * _delete_event
2078
-     *
2079
-     * @access protected
2080
-     * @param bool $redirect_after
2081
-     */
2082
-    protected function _delete_event($redirect_after = true)
2083
-    {
2084
-        //determine the event id and set to array.
2085
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2086
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2087
-        // loop thru events
2088
-        if ($EVT_ID) {
2089
-            $success = $this->_permanently_delete_event($EVT_ID);
2090
-            // get list of events with no prices
2091
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2092
-            // remove this event from the list of events with no prices
2093
-            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2094
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2095
-            }
2096
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2097
-        } else {
2098
-            $success = false;
2099
-            $msg = esc_html__(
2100
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2101
-                'event_espresso'
2102
-            );
2103
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2104
-        }
2105
-        if ($redirect_after) {
2106
-            $this->_redirect_after_action(
2107
-                $success,
2108
-                'Event',
2109
-                'deleted',
2110
-                array('action' => 'default', 'status' => 'trash')
2111
-            );
2112
-        }
2113
-    }
2114
-
2115
-
2116
-
2117
-    /**
2118
-     * _delete_events
2119
-     *
2120
-     * @access protected
2121
-     * @return void
2122
-     */
2123
-    protected function _delete_events()
2124
-    {
2125
-        $success = true;
2126
-        // get list of events with no prices
2127
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2128
-        //determine the event id and set to array.
2129
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2130
-        // loop thru events
2131
-        foreach ($EVT_IDs as $EVT_ID) {
2132
-            $EVT_ID = absint($EVT_ID);
2133
-            if ($EVT_ID) {
2134
-                $results = $this->_permanently_delete_event($EVT_ID);
2135
-                $success = $results !== false ? $success : false;
2136
-                // remove this event from the list of events with no prices
2137
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2138
-            } else {
2139
-                $success = false;
2140
-                $msg = esc_html__(
2141
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2142
-                    'event_espresso'
2143
-                );
2144
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2145
-            }
2146
-        }
2147
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2148
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2149
-        $success = $success ? 2 : false;
2150
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2151
-    }
2152
-
2153
-
2154
-
2155
-    /**
2156
-     * _permanently_delete_event
2157
-     *
2158
-     * @access  private
2159
-     * @param  int $EVT_ID
2160
-     * @return bool
2161
-     */
2162
-    private function _permanently_delete_event($EVT_ID = 0)
2163
-    {
2164
-        // grab event id
2165
-        if ( ! $EVT_ID) {
2166
-            $msg = esc_html__(
2167
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2168
-                'event_espresso'
2169
-            );
2170
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
-            return false;
2172
-        }
2173
-        if (
2174
-            ! $this->_cpt_model_obj instanceof EE_Event
2175
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2176
-        ) {
2177
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2178
-        }
2179
-        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2180
-            return false;
2181
-        }
2182
-        //need to delete related tickets and prices first.
2183
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2184
-        foreach ($datetimes as $datetime) {
2185
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2186
-            $tickets = $datetime->get_many_related('Ticket');
2187
-            foreach ($tickets as $ticket) {
2188
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2189
-                $ticket->delete_related_permanently('Price');
2190
-                $ticket->delete_permanently();
2191
-            }
2192
-            $datetime->delete();
2193
-        }
2194
-        //what about related venues or terms?
2195
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2196
-        foreach ($venues as $venue) {
2197
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2198
-        }
2199
-        //any attached question groups?
2200
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2201
-        if ( ! empty($question_groups)) {
2202
-            foreach ($question_groups as $question_group) {
2203
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2204
-            }
2205
-        }
2206
-        //Message Template Groups
2207
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2208
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2209
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2210
-        foreach ($term_taxonomies as $term_taxonomy) {
2211
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2212
-        }
2213
-        $success = $this->_cpt_model_obj->delete_permanently();
2214
-        // did it all go as planned ?
2215
-        if ($success) {
2216
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2217
-            EE_Error::add_success($msg);
2218
-        } else {
2219
-            $msg = sprintf(
2220
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2221
-                $EVT_ID
2222
-            );
2223
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2224
-            return false;
2225
-        }
2226
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2227
-        return true;
2228
-    }
2229
-
2230
-
2231
-
2232
-    /**
2233
-     * get total number of events
2234
-     *
2235
-     * @access public
2236
-     * @return int
2237
-     */
2238
-    public function total_events()
2239
-    {
2240
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2241
-        return $count;
2242
-    }
2243
-
2244
-
2245
-
2246
-    /**
2247
-     * get total number of draft events
2248
-     *
2249
-     * @access public
2250
-     * @return int
2251
-     */
2252
-    public function total_events_draft()
2253
-    {
2254
-        $where = array(
2255
-            'status' => array('IN', array('draft', 'auto-draft')),
2256
-        );
2257
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2258
-        return $count;
2259
-    }
2260
-
2261
-
2262
-
2263
-    /**
2264
-     * get total number of trashed events
2265
-     *
2266
-     * @access public
2267
-     * @return int
2268
-     */
2269
-    public function total_trashed_events()
2270
-    {
2271
-        $where = array(
2272
-            'status' => 'trash',
2273
-        );
2274
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2275
-        return $count;
2276
-    }
2277
-
2278
-
2279
-    /**
2280
-     *    _default_event_settings
2281
-     *    This generates the Default Settings Tab
2282
-     *
2283
-     * @return void
2284
-     * @throws EE_Error
2285
-     */
2286
-    protected function _default_event_settings()
2287
-    {
2288
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2289
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2290
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2291
-        $this->display_admin_page_with_sidebar();
2292
-    }
2293
-
2294
-
2295
-    /**
2296
-     * Return the form for event settings.
2297
-     * @return EE_Form_Section_Proper
2298
-     */
2299
-    protected function _default_event_settings_form()
2300
-    {
2301
-        $registration_config = EE_Registry::instance()->CFG->registration;
2302
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2303
-        //exclude
2304
-            array(
2305
-                EEM_Registration::status_id_cancelled,
2306
-                EEM_Registration::status_id_declined,
2307
-                EEM_Registration::status_id_incomplete,
2308
-                EEM_Registration::status_id_wait_list,
2309
-            ),
2310
-            true
2311
-        );
2312
-        return new EE_Form_Section_Proper(
2313
-            array(
2314
-                'name' => 'update_default_event_settings',
2315
-                'html_id' => 'update_default_event_settings',
2316
-                'html_class' => 'form-table',
2317
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2318
-                'subsections' => apply_filters(
2319
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2320
-                    array(
2321
-                        'default_reg_status' => new EE_Select_Input(
2322
-                            $registration_stati_for_selection,
2323
-                            array(
2324
-                                'default' => isset($registration_config->default_STS_ID)
2325
-                                             && array_key_exists(
2326
-                                                $registration_config->default_STS_ID,
2327
-                                                $registration_stati_for_selection
2328
-                                             )
2329
-                                            ? sanitize_text_field($registration_config->default_STS_ID)
2330
-                                            : EEM_Registration::status_id_pending_payment,
2331
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2332
-                                                    . EEH_Template::get_help_tab_link(
2333
-                                                        'default_settings_status_help_tab'
2334
-                                                    ),
2335
-                                'html_help_text' => esc_html__(
2336
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2337
-                                    'event_espresso'
2338
-                                )
2339
-                            )
2340
-                        ),
2341
-                        'default_max_tickets' => new EE_Integer_Input(
2342
-                            array(
2343
-                                'default' => isset($registration_config->default_maximum_number_of_tickets)
2344
-                                    ? $registration_config->default_maximum_number_of_tickets
2345
-                                    : EEM_Event::get_default_additional_limit(),
2346
-                                'html_label_text' => esc_html__(
2347
-                                    'Default Maximum Tickets Allowed Per Order:',
2348
-                                    'event_espresso'
2349
-                                ) . EEH_Template::get_help_tab_link(
2350
-                                    'default_maximum_tickets_help_tab"'
2351
-                                    ),
2352
-                                'html_help_text' => esc_html__(
2353
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2354
-                                    'event_espresso'
2355
-                                )
2356
-                            )
2357
-                        )
2358
-                    )
2359
-                )
2360
-            )
2361
-        );
2362
-    }
2363
-
2364
-
2365
-    /**
2366
-     * _update_default_event_settings
2367
-     *
2368
-     * @access protected
2369
-     * @return void
2370
-     * @throws EE_Error
2371
-     */
2372
-    protected function _update_default_event_settings()
2373
-    {
2374
-        $registration_config = EE_Registry::instance()->CFG->registration;
2375
-        $form = $this->_default_event_settings_form();
2376
-        if ($form->was_submitted()) {
2377
-            $form->receive_form_submission();
2378
-            if ($form->is_valid()) {
2379
-                $valid_data = $form->valid_data();
2380
-                if (isset($valid_data['default_reg_status'])) {
2381
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2382
-                }
2383
-                if (isset($valid_data['default_max_tickets'])) {
2384
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2385
-                }
2386
-                //update because data was valid!
2387
-                EE_Registry::instance()->CFG->update_espresso_config();
2388
-                EE_Error::overwrite_success();
2389
-                EE_Error::add_success(
2390
-                    __('Default Event Settings were updated', 'event_espresso')
2391
-                );
2392
-            }
2393
-        }
2394
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2395
-    }
2396
-
2397
-
2398
-
2399
-    /*************        Templates        *************/
2400
-    protected function _template_settings()
2401
-    {
2402
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2403
-        $this->_template_args['preview_img'] = '<img src="'
2404
-                                               . EVENTS_ASSETS_URL
2405
-                                               . DS
2406
-                                               . 'images'
2407
-                                               . DS
2408
-                                               . 'caffeinated_template_features.jpg" alt="'
2409
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2410
-                                               . '" />';
2411
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2412
-                'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2413
-                'event_espresso'
2414
-            ) . '</strong>';
2415
-        $this->display_admin_caf_preview_page('template_settings_tab');
2416
-    }
2417
-
2418
-
2419
-    /** Event Category Stuff **/
2420
-    /**
2421
-     * set the _category property with the category object for the loaded page.
2422
-     *
2423
-     * @access private
2424
-     * @return void
2425
-     */
2426
-    private function _set_category_object()
2427
-    {
2428
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2429
-            return;
2430
-        } //already have the category object so get out.
2431
-        //set default category object
2432
-        $this->_set_empty_category_object();
2433
-        //only set if we've got an id
2434
-        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2435
-            return;
2436
-        }
2437
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2438
-        $term = get_term($category_id, 'espresso_event_categories');
2439
-        if ( ! empty($term)) {
2440
-            $this->_category->category_name = $term->name;
2441
-            $this->_category->category_identifier = $term->slug;
2442
-            $this->_category->category_desc = $term->description;
2443
-            $this->_category->id = $term->term_id;
2444
-            $this->_category->parent = $term->parent;
2445
-        }
2446
-    }
2447
-
2448
-
2449
-    /**
2450
-     * Clears out category properties.
2451
-     */
2452
-    private function _set_empty_category_object()
2453
-    {
2454
-        $this->_category = new stdClass();
2455
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2456
-        $this->_category->id = $this->_category->parent = 0;
2457
-    }
2458
-
2459
-
2460
-    /**
2461
-     * @throws EE_Error
2462
-     */
2463
-    protected function _category_list_table()
2464
-    {
2465
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2466
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2467
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2468
-                'add_category',
2469
-                'add_category',
2470
-                array(),
2471
-                'add-new-h2'
2472
-            );
2473
-        $this->display_admin_list_table_page_with_sidebar();
2474
-    }
2475
-
2476
-
2477
-
2478
-    /**
2479
-     * Output category details view.
2480
-     */
2481
-    protected function _category_details($view)
2482
-    {
2483
-        //load formatter helper
2484
-        //load field generator helper
2485
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2486
-        $this->_set_add_edit_form_tags($route);
2487
-        $this->_set_category_object();
2488
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2489
-        $delete_action = 'delete_category';
2490
-        //custom redirect
2491
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2492
-            array('action' => 'category_list'),
2493
-            $this->_admin_base_url
2494
-        );
2495
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2496
-        //take care of contents
2497
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2498
-        $this->display_admin_page_with_sidebar();
2499
-    }
2500
-
2501
-
2502
-
2503
-    /**
2504
-     * Output category details content.
2505
-     */
2506
-    protected function _category_details_content()
2507
-    {
2508
-        $editor_args['category_desc'] = array(
2509
-            'type'          => 'wp_editor',
2510
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2511
-            'class'         => 'my_editor_custom',
2512
-            'wpeditor_args' => array('media_buttons' => false),
2513
-        );
2514
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2515
-        $all_terms = get_terms(
2516
-            array('espresso_event_categories'),
2517
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2518
-        );
2519
-        //setup category select for term parents.
2520
-        $category_select_values[] = array(
2521
-            'text' => esc_html__('No Parent', 'event_espresso'),
2522
-            'id'   => 0,
2523
-        );
2524
-        foreach ($all_terms as $term) {
2525
-            $category_select_values[] = array(
2526
-                'text' => $term->name,
2527
-                'id'   => $term->term_id,
2528
-            );
2529
-        }
2530
-        $category_select = EEH_Form_Fields::select_input(
2531
-            'category_parent',
2532
-            $category_select_values,
2533
-            $this->_category->parent
2534
-        );
2535
-        $template_args = array(
2536
-            'category'                 => $this->_category,
2537
-            'category_select'          => $category_select,
2538
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2539
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2540
-            'disable'                  => '',
2541
-            'disabled_message'         => false,
2542
-        );
2543
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2544
-        return EEH_Template::display_template($template, $template_args, true);
2545
-    }
2546
-
2547
-
2548
-    /**
2549
-     * Handles deleting categories.
2550
-     */
2551
-    protected function _delete_categories()
2552
-    {
2553
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2554
-            : (array)$this->_req_data['category_id'];
2555
-        foreach ($cat_ids as $cat_id) {
2556
-            $this->_delete_category($cat_id);
2557
-        }
2558
-        //doesn't matter what page we're coming from... we're going to the same place after delete.
2559
-        $query_args = array(
2560
-            'action' => 'category_list',
2561
-        );
2562
-        $this->_redirect_after_action(0, '', '', $query_args);
2563
-    }
2564
-
2565
-
2566
-
2567
-    /**
2568
-     * Handles deleting specific category.
2569
-     * @param int $cat_id
2570
-     */
2571
-    protected function _delete_category($cat_id)
2572
-    {
2573
-        $cat_id = absint($cat_id);
2574
-        wp_delete_term($cat_id, 'espresso_event_categories');
2575
-    }
2576
-
2577
-
2578
-
2579
-    /**
2580
-     * Handles triggering the update or insertion of a new category.
2581
-     * @param bool $new_category  true means we're triggering the insert of a new category.
2582
-     */
2583
-    protected function _insert_or_update_category($new_category)
2584
-    {
2585
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2586
-        $success = 0; //we already have a success message so lets not send another.
2587
-        if ($cat_id) {
2588
-            $query_args = array(
2589
-                'action'     => 'edit_category',
2590
-                'EVT_CAT_ID' => $cat_id,
2591
-            );
2592
-        } else {
2593
-            $query_args = array('action' => 'add_category');
2594
-        }
2595
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2596
-    }
2597
-
2598
-
2599
-
2600
-    /**
2601
-     * Inserts or updates category
2602
-     * @param bool $update (true indicates we're updating a category).
2603
-     * @return bool|mixed|string
2604
-     */
2605
-    private function _insert_category($update = false)
2606
-    {
2607
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2608
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2609
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2610
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2611
-        if (empty($category_name)) {
2612
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2613
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2614
-            return false;
2615
-        }
2616
-        $term_args = array(
2617
-            'name'        => $category_name,
2618
-            'description' => $category_desc,
2619
-            'parent'      => $category_parent,
2620
-        );
2621
-        //was the category_identifier input disabled?
2622
-        if (isset($this->_req_data['category_identifier'])) {
2623
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2624
-        }
2625
-        $insert_ids = $update
2626
-            ? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2627
-            : wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2628
-        if ( ! is_array($insert_ids)) {
2629
-            $msg = esc_html__(
2630
-                'An error occurred and the category has not been saved to the database.',
2631
-                'event_espresso'
2632
-            );
2633
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2634
-        } else {
2635
-            $cat_id = $insert_ids['term_id'];
2636
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2637
-            EE_Error::add_success($msg);
2638
-        }
2639
-        return $cat_id;
2640
-    }
2641
-
2642
-
2643
-
2644
-    /**
2645
-     * Gets categories or count of categories matching the arguments in the request.
2646
-     * @param int  $per_page
2647
-     * @param int  $current_page
2648
-     * @param bool $count
2649
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2650
-     */
2651
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2652
-    {
2653
-        //testing term stuff
2654
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2655
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2656
-        $limit = ($current_page - 1) * $per_page;
2657
-        $where = array('taxonomy' => 'espresso_event_categories');
2658
-        if (isset($this->_req_data['s'])) {
2659
-            $sstr = '%' . $this->_req_data['s'] . '%';
2660
-            $where['OR'] = array(
2661
-                'Term.name'   => array('LIKE', $sstr),
2662
-                'description' => array('LIKE', $sstr),
2663
-            );
2664
-        }
2665
-        $query_params = array(
2666
-            $where,
2667
-            'order_by'   => array($orderby => $order),
2668
-            'limit'      => $limit . ',' . $per_page,
2669
-            'force_join' => array('Term'),
2670
-        );
2671
-        $categories = $count
2672
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2673
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2674
-        return $categories;
2675
-    }
2676
-
2677
-    /* end category stuff */
2678
-    /**************/
2679
-
2680
-
2681
-    /**
2682
-     * Callback for the `ee_save_timezone_setting` ajax action.
2683
-     * @throws EE_Error
2684
-     */
2685
-    public function save_timezonestring_setting()
2686
-    {
2687
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2688
-            ? $this->_req_data['timezone_selected']
2689
-            : '';
2690
-        if  (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2691
-        {
2692
-            EE_Error::add_error(
2693
-                esc_html('An invalid timezone string submitted.', 'event_espresso'),
2694
-                __FILE__, __FUNCTION__, __LINE__
2695
-            );
2696
-            $this->_template_args['error'] = true;
2697
-            $this->_return_json();
2698
-        }
2699
-
2700
-        update_option('timezone_string', $timezone_string);
2701
-        EE_Error::add_success(
2702
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2703
-        );
2704
-        $this->_template_args['success'] = true;
2705
-        $this->_return_json(true, array('action' => 'create_new'));
2706
-    }
394
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
395
+				'require_nonce' => false,
396
+			),
397
+			'default_event_settings' => array(
398
+				'nav'           => array(
399
+					'label' => esc_html__('Default Settings', 'event_espresso'),
400
+					'order' => 40,
401
+				),
402
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
403
+				'labels'        => array(
404
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
405
+				),
406
+				'help_tabs'     => array(
407
+					'default_settings_help_tab'        => array(
408
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
409
+						'filename' => 'events_default_settings',
410
+					),
411
+					'default_settings_status_help_tab' => array(
412
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
413
+						'filename' => 'events_default_settings_status',
414
+					),
415
+					'default_maximum_tickets_help_tab' => array(
416
+						'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
417
+						'filename' => 'events_default_settings_max_tickets',
418
+					)
419
+				),
420
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
421
+				'require_nonce' => false,
422
+			),
423
+			//template settings
424
+			'template_settings'      => array(
425
+				'nav'           => array(
426
+					'label' => esc_html__('Templates', 'event_espresso'),
427
+					'order' => 30,
428
+				),
429
+				'metaboxes'     => $this->_default_espresso_metaboxes,
430
+				'help_tabs'     => array(
431
+					'general_settings_templates_help_tab' => array(
432
+						'title'    => esc_html__('Templates', 'event_espresso'),
433
+						'filename' => 'general_settings_templates',
434
+					),
435
+				),
436
+				'help_tour'     => array('Templates_Help_Tour'),
437
+				'require_nonce' => false,
438
+			),
439
+			//event category stuff
440
+			'add_category'           => array(
441
+				'nav'           => array(
442
+					'label'      => esc_html__('Add Category', 'event_espresso'),
443
+					'order'      => 15,
444
+					'persistent' => false,
445
+				),
446
+				'help_tabs'     => array(
447
+					'add_category_help_tab' => array(
448
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
449
+						'filename' => 'events_add_category',
450
+					),
451
+				),
452
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
453
+				'metaboxes'     => array('_publish_post_box'),
454
+				'require_nonce' => false,
455
+			),
456
+			'edit_category'          => array(
457
+				'nav'           => array(
458
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
459
+					'order'      => 15,
460
+					'persistent' => false,
461
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
462
+						? add_query_arg(
463
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
464
+							$this->_current_page_view_url
465
+						)
466
+						: $this->_admin_base_url,
467
+				),
468
+				'help_tabs'     => array(
469
+					'edit_category_help_tab' => array(
470
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
471
+						'filename' => 'events_edit_category',
472
+					),
473
+				),
474
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
475
+				'metaboxes'     => array('_publish_post_box'),
476
+				'require_nonce' => false,
477
+			),
478
+			'category_list'          => array(
479
+				'nav'           => array(
480
+					'label' => esc_html__('Categories', 'event_espresso'),
481
+					'order' => 20,
482
+				),
483
+				'list_table'    => 'Event_Categories_Admin_List_Table',
484
+				'help_tabs'     => array(
485
+					'events_categories_help_tab'                       => array(
486
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
487
+						'filename' => 'events_categories',
488
+					),
489
+					'events_categories_table_column_headings_help_tab' => array(
490
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
491
+						'filename' => 'events_categories_table_column_headings',
492
+					),
493
+					'events_categories_view_help_tab'                  => array(
494
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
495
+						'filename' => 'events_categories_views',
496
+					),
497
+					'events_categories_other_help_tab'                 => array(
498
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
499
+						'filename' => 'events_categories_other',
500
+					),
501
+				),
502
+				'help_tour'     => array(
503
+					'Event_Categories_Help_Tour',
504
+				),
505
+				'metaboxes'     => $this->_default_espresso_metaboxes,
506
+				'require_nonce' => false,
507
+			),
508
+		);
509
+	}
510
+
511
+
512
+	/**
513
+	 * Used to register any global screen options if necessary for every route in this admin page group.
514
+	 */
515
+	protected function _add_screen_options()
516
+	{
517
+	}
518
+
519
+
520
+	/**
521
+	 * Implementing the screen options for the 'default' route.
522
+	 */
523
+	protected function _add_screen_options_default()
524
+	{
525
+		$this->_per_page_screen_option();
526
+	}
527
+
528
+
529
+	/**
530
+	 * Implementing screen options for the category list route.
531
+	 */
532
+	protected function _add_screen_options_category_list()
533
+	{
534
+		$page_title = $this->_admin_page_title;
535
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
536
+		$this->_per_page_screen_option();
537
+		$this->_admin_page_title = $page_title;
538
+	}
539
+
540
+
541
+	/**
542
+	 * Used to register any global feature pointers for the admin page group.
543
+	 */
544
+	protected function _add_feature_pointers()
545
+	{
546
+	}
547
+
548
+
549
+	/**
550
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
551
+	 */
552
+	public function load_scripts_styles()
553
+	{
554
+		wp_register_style(
555
+			'events-admin-css',
556
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
557
+			array(),
558
+			EVENT_ESPRESSO_VERSION
559
+		);
560
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
561
+		wp_enqueue_style('events-admin-css');
562
+		wp_enqueue_style('ee-cat-admin');
563
+		//todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
564
+		//registers for all views
565
+		//scripts
566
+		wp_register_script(
567
+			'event_editor_js',
568
+			EVENTS_ASSETS_URL . 'event_editor.js',
569
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
570
+			EVENT_ESPRESSO_VERSION,
571
+			true
572
+		);
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * Enqueuing scripts and styles specific to this view
579
+	 */
580
+	public function load_scripts_styles_create_new()
581
+	{
582
+		$this->load_scripts_styles_edit();
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 * Enqueuing scripts and styles specific to this view
589
+	 */
590
+	public function load_scripts_styles_edit()
591
+	{
592
+		//styles
593
+		wp_enqueue_style('espresso-ui-theme');
594
+		wp_register_style(
595
+			'event-editor-css',
596
+			EVENTS_ASSETS_URL . 'event-editor.css',
597
+			array('ee-admin-css'),
598
+			EVENT_ESPRESSO_VERSION
599
+		);
600
+		wp_enqueue_style('event-editor-css');
601
+		//scripts
602
+		wp_register_script(
603
+			'event-datetime-metabox',
604
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
605
+			array('event_editor_js', 'ee-datepicker'),
606
+			EVENT_ESPRESSO_VERSION
607
+		);
608
+		wp_enqueue_script('event-datetime-metabox');
609
+	}
610
+
611
+
612
+	/**
613
+	 * Populating the _views property for the category list table view.
614
+	 */
615
+	protected function _set_list_table_views_category_list()
616
+	{
617
+		$this->_views = array(
618
+			'all' => array(
619
+				'slug'        => 'all',
620
+				'label'       => esc_html__('All', 'event_espresso'),
621
+				'count'       => 0,
622
+				'bulk_action' => array(
623
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
624
+				),
625
+			),
626
+		);
627
+	}
628
+
629
+
630
+	/**
631
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
632
+	 */
633
+	public function admin_init()
634
+	{
635
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
636
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
637
+			'event_espresso'
638
+		);
639
+	}
640
+
641
+
642
+	/**
643
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page group.
644
+	 */
645
+	public function admin_notices()
646
+	{
647
+	}
648
+
649
+
650
+	/**
651
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
652
+	 * this admin page group.
653
+	 */
654
+	public function admin_footer_scripts()
655
+	{
656
+	}
657
+
658
+
659
+
660
+	/**
661
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
662
+	 * warning (via EE_Error::add_error());
663
+	 *
664
+	 * @param  EE_Event $event Event object
665
+	 * @param string    $req_type
666
+	 * @return void
667
+	 * @throws EE_Error
668
+	 * @access public
669
+	 */
670
+	public function verify_event_edit($event = null, $req_type = '')
671
+	{
672
+		// don't need to do this when processing
673
+		if(!empty($req_type)) {
674
+			return;
675
+		}
676
+		// no event?
677
+		if (empty($event)) {
678
+			// set event
679
+			$event = $this->_cpt_model_obj;
680
+		}
681
+		// STILL no event?
682
+		if (! $event instanceof EE_Event) {
683
+			return;
684
+		}
685
+		$orig_status = $event->status();
686
+		// first check if event is active.
687
+		if (
688
+			$orig_status === EEM_Event::cancelled
689
+			|| $orig_status === EEM_Event::postponed
690
+			|| $event->is_expired()
691
+			|| $event->is_inactive()
692
+		) {
693
+			return;
694
+		}
695
+		//made it here so it IS active... next check that any of the tickets are sold.
696
+		if ($event->is_sold_out(true)) {
697
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
698
+				EE_Error::add_attention(
699
+					sprintf(
700
+						esc_html__(
701
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
702
+							'event_espresso'
703
+						),
704
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
705
+					)
706
+				);
707
+			}
708
+			return;
709
+		} else if ($orig_status === EEM_Event::sold_out) {
710
+			EE_Error::add_attention(
711
+				sprintf(
712
+					esc_html__(
713
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
714
+						'event_espresso'
715
+					),
716
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
717
+				)
718
+			);
719
+		}
720
+		//now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
721
+		if ( ! $event->tickets_on_sale()) {
722
+			return;
723
+		}
724
+		//made it here so show warning
725
+		$this->_edit_event_warning();
726
+	}
727
+
728
+
729
+
730
+	/**
731
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
732
+	 * When needed, hook this into a EE_Error::add_error() notice.
733
+	 *
734
+	 * @access protected
735
+	 * @return void
736
+	 */
737
+	protected function _edit_event_warning()
738
+	{
739
+		// we don't want to add warnings during these requests
740
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
741
+			return;
742
+		}
743
+		EE_Error::add_attention(
744
+			esc_html__(
745
+				'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
746
+				'event_espresso'
747
+			)
748
+		);
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
755
+	 * Otherwise, do the normal logic
756
+	 *
757
+	 * @return string
758
+	 * @throws \EE_Error
759
+	 */
760
+	protected function _create_new_cpt_item()
761
+	{
762
+		$has_timezone_string = get_option('timezone_string');
763
+		//only nag them about setting their timezone if it's their first event, and they haven't already done it
764
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
765
+			EE_Error::add_attention(
766
+				sprintf(
767
+					__(
768
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
769
+						'event_espresso'
770
+					),
771
+					'<br>',
772
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
773
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
774
+					. '</select>',
775
+					'<button class="button button-secondary timezone-submit">',
776
+					'</button><span class="spinner"></span>'
777
+				),
778
+				__FILE__,
779
+				__FUNCTION__,
780
+				__LINE__
781
+			);
782
+		}
783
+		return parent::_create_new_cpt_item();
784
+	}
785
+
786
+
787
+	/**
788
+	 * Sets the _views property for the default route in this admin page group.
789
+	 */
790
+	protected function _set_list_table_views_default()
791
+	{
792
+		$this->_views = array(
793
+			'all'   => array(
794
+				'slug'        => 'all',
795
+				'label'       => esc_html__('View All Events', 'event_espresso'),
796
+				'count'       => 0,
797
+				'bulk_action' => array(
798
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
799
+				),
800
+			),
801
+			'draft' => array(
802
+				'slug'        => 'draft',
803
+				'label'       => esc_html__('Draft', 'event_espresso'),
804
+				'count'       => 0,
805
+				'bulk_action' => array(
806
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
807
+				),
808
+			),
809
+		);
810
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
811
+			$this->_views['trash'] = array(
812
+				'slug'        => 'trash',
813
+				'label'       => esc_html__('Trash', 'event_espresso'),
814
+				'count'       => 0,
815
+				'bulk_action' => array(
816
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
817
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
818
+				),
819
+			);
820
+		}
821
+	}
822
+
823
+
824
+
825
+	/**
826
+	 * Provides the legend item array for the default list table view.
827
+	 * @return array
828
+	 */
829
+	protected function _event_legend_items()
830
+	{
831
+		$items = array(
832
+			'view_details'   => array(
833
+				'class' => 'dashicons dashicons-search',
834
+				'desc'  => esc_html__('View Event', 'event_espresso'),
835
+			),
836
+			'edit_event'     => array(
837
+				'class' => 'ee-icon ee-icon-calendar-edit',
838
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
839
+			),
840
+			'view_attendees' => array(
841
+				'class' => 'dashicons dashicons-groups',
842
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
843
+			),
844
+		);
845
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
846
+		$statuses = array(
847
+			'sold_out_status'  => array(
848
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
849
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
850
+			),
851
+			'active_status'    => array(
852
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
853
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
854
+			),
855
+			'upcoming_status'  => array(
856
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
857
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
858
+			),
859
+			'postponed_status' => array(
860
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
861
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
862
+			),
863
+			'cancelled_status' => array(
864
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
865
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
866
+			),
867
+			'expired_status'   => array(
868
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
869
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
870
+			),
871
+			'inactive_status'  => array(
872
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
873
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
874
+			),
875
+		);
876
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
877
+		return array_merge($items, $statuses);
878
+	}
879
+
880
+
881
+
882
+	/**
883
+	 * @return EEM_Event
884
+	 */
885
+	private function _event_model()
886
+	{
887
+		if ( ! $this->_event_model instanceof EEM_Event) {
888
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
889
+		}
890
+		return $this->_event_model;
891
+	}
892
+
893
+
894
+
895
+	/**
896
+	 * Adds extra buttons to the WP CPT permalink field row.
897
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
898
+	 *
899
+	 * @param  string $return    the current html
900
+	 * @param  int    $id        the post id for the page
901
+	 * @param  string $new_title What the title is
902
+	 * @param  string $new_slug  what the slug is
903
+	 * @return string            The new html string for the permalink area
904
+	 */
905
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
906
+	{
907
+		//make sure this is only when editing
908
+		if ( ! empty($id)) {
909
+			$post = get_post($id);
910
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
911
+					   . esc_html__('Shortcode', 'event_espresso')
912
+					   . '</a> ';
913
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
914
+					   . $post->ID
915
+					   . ']">';
916
+		}
917
+		return $return;
918
+	}
919
+
920
+
921
+
922
+	/**
923
+	 * _events_overview_list_table
924
+	 * This contains the logic for showing the events_overview list
925
+	 *
926
+	 * @access protected
927
+	 * @return void
928
+	 * @throws \EE_Error
929
+	 */
930
+	protected function _events_overview_list_table()
931
+	{
932
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
933
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
934
+			? (array)$this->_template_args['after_list_table']
935
+			: array();
936
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
937
+																			  . EEH_Template::get_button_or_link(
938
+				get_post_type_archive_link('espresso_events'),
939
+				esc_html__("View Event Archive Page", "event_espresso"),
940
+				'button'
941
+			);
942
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
943
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
944
+				'create_new',
945
+				'add',
946
+				array(),
947
+				'add-new-h2'
948
+			);
949
+		$this->display_admin_list_table_page_with_no_sidebar();
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * this allows for extra misc actions in the default WP publish box
956
+	 *
957
+	 * @return void
958
+	 */
959
+	public function extra_misc_actions_publish_box()
960
+	{
961
+		$this->_generate_publish_box_extra_content();
962
+	}
963
+
964
+
965
+
966
+	/**
967
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been saved.
968
+	 * Typically you would use this to save any additional data.
969
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
970
+	 * ALSO very important.  When a post transitions from scheduled to published,
971
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from other meta saves.
972
+	 * So MAKE sure that you handle this accordingly.
973
+	 *
974
+	 * @access protected
975
+	 * @abstract
976
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
977
+	 * @param  object $post    The post object of the cpt that was saved.
978
+	 * @return void
979
+	 * @throws \EE_Error
980
+	 */
981
+	protected function _insert_update_cpt_item($post_id, $post)
982
+	{
983
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
984
+			//get out we're not processing an event save.
985
+			return;
986
+		}
987
+		$event_values = array(
988
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
989
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
990
+			'EVT_additional_limit'            => min(
991
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
992
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
993
+			),
994
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
995
+				? $this->_req_data['EVT_default_registration_status']
996
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
997
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
998
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
999
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1000
+				? $this->_req_data['timezone_string'] : null,
1001
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1002
+				? $this->_req_data['externalURL'] : null,
1003
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1004
+				? $this->_req_data['event_phone'] : null,
1005
+		);
1006
+		//update event
1007
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1008
+		//get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1009
+		$get_one_where = array(
1010
+			$this->_event_model()->primary_key_name() => $post_id,
1011
+			'OR' => array(
1012
+				'status' => $post->post_status,
1013
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1014
+				// but the returned object here has a status of "publish", so use the original post status as well
1015
+				'status*1' => $this->_req_data['original_post_status'],
1016
+			)
1017
+		);
1018
+		$event = $this->_event_model()->get_one(array($get_one_where));
1019
+		//the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1020
+		$event_update_callbacks = apply_filters(
1021
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1022
+			array(
1023
+				array($this, '_default_venue_update'),
1024
+				array($this, '_default_tickets_update')
1025
+			)
1026
+		);
1027
+		$att_success = true;
1028
+		foreach ($event_update_callbacks as $e_callback) {
1029
+			$_success = $e_callback($event, $this->_req_data);
1030
+			//if ANY of these updates fail then we want the appropriate global error message
1031
+			$att_success = ! $att_success ? $att_success : $_success;
1032
+		}
1033
+		//any errors?
1034
+		if ($success && false === $att_success) {
1035
+			EE_Error::add_error(
1036
+				esc_html__(
1037
+					'Event Details saved successfully but something went wrong with saving attachments.',
1038
+					'event_espresso'
1039
+				),
1040
+				__FILE__,
1041
+				__FUNCTION__,
1042
+				__LINE__
1043
+			);
1044
+		} else if ($success === false) {
1045
+			EE_Error::add_error(
1046
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1047
+				__FILE__,
1048
+				__FUNCTION__,
1049
+				__LINE__
1050
+			);
1051
+		}
1052
+	}
1053
+
1054
+
1055
+
1056
+	/**
1057
+	 * @see parent::restore_item()
1058
+	 * @param int $post_id
1059
+	 * @param int $revision_id
1060
+	 */
1061
+	protected function _restore_cpt_item($post_id, $revision_id)
1062
+	{
1063
+		//copy existing event meta to new post
1064
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1065
+		if ($post_evt instanceof EE_Event) {
1066
+			//meta revision restore
1067
+			$post_evt->restore_revision($revision_id);
1068
+			//related objs restore
1069
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1070
+		}
1071
+	}
1072
+
1073
+
1074
+
1075
+	/**
1076
+	 * Attach the venue to the Event
1077
+	 *
1078
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1079
+	 * @param  array     $data   The request data from the form
1080
+	 * @return bool           Success or fail.
1081
+	 */
1082
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1083
+	{
1084
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1085
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1086
+		$rows_affected = null;
1087
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1088
+		// very important.  If we don't have a venue name...
1089
+		// then we'll get out because not necessary to create empty venue
1090
+		if (empty($data['venue_title'])) {
1091
+			return false;
1092
+		}
1093
+		$venue_array = array(
1094
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1095
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1096
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1097
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1098
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1099
+				: null,
1100
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1101
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1102
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1103
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1104
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1105
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1106
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1107
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1108
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1109
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1110
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1111
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1112
+			'status'              => 'publish',
1113
+		);
1114
+		//if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1115
+		if ( ! empty($venue_id)) {
1116
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1117
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1118
+			//we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1119
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1120
+			return $rows_affected > 0 ? true : false;
1121
+		} else {
1122
+			//we insert the venue
1123
+			$venue_id = $venue_model->insert($venue_array);
1124
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1125
+			return ! empty($venue_id) ? true : false;
1126
+		}
1127
+		//when we have the ancestor come in it's already been handled by the revision save.
1128
+	}
1129
+
1130
+
1131
+
1132
+	/**
1133
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1134
+	 *
1135
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1136
+	 * @param  array    $data   The request data from the form
1137
+	 * @return array
1138
+	 */
1139
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1140
+	{
1141
+		$success = true;
1142
+		$saved_dtt = null;
1143
+		$saved_tickets = array();
1144
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1145
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1146
+			//trim all values to ensure any excess whitespace is removed.
1147
+			$dtt = array_map('trim', $dtt);
1148
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1149
+				: $dtt['DTT_EVT_start'];
1150
+			$datetime_values = array(
1151
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1152
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1153
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1154
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1155
+				'DTT_order'     => $row,
1156
+			);
1157
+			//if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1158
+			if ( ! empty($dtt['DTT_ID'])) {
1159
+				$DTM = EE_Registry::instance()
1160
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1161
+								  ->get_one_by_ID($dtt['DTT_ID']);
1162
+				$DTM->set_date_format($incoming_date_formats[0]);
1163
+				$DTM->set_time_format($incoming_date_formats[1]);
1164
+				foreach ($datetime_values as $field => $value) {
1165
+					$DTM->set($field, $value);
1166
+				}
1167
+				//make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1168
+				$saved_dtts[$DTM->ID()] = $DTM;
1169
+			} else {
1170
+				$DTM = EE_Registry::instance()->load_class(
1171
+					'Datetime',
1172
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1173
+					false,
1174
+					false
1175
+				);
1176
+				foreach ($datetime_values as $field => $value) {
1177
+					$DTM->set($field, $value);
1178
+				}
1179
+			}
1180
+			$DTM->save();
1181
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1182
+			//load DTT helper
1183
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1184
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1185
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1186
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1187
+				$DTT->save();
1188
+			}
1189
+			//now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1190
+			$saved_dtt = $DTT;
1191
+			$success = ! $success ? $success : $DTT;
1192
+			//if ANY of these updates fail then we want the appropriate global error message.
1193
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1194
+		}
1195
+		//no dtts get deleted so we don't do any of that logic here.
1196
+		//update tickets next
1197
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1198
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1199
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1200
+			$update_prices = false;
1201
+			$ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1202
+				? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1203
+			// trim inputs to ensure any excess whitespace is removed.
1204
+			$tkt = array_map('trim', $tkt);
1205
+			if (empty($tkt['TKT_start_date'])) {
1206
+				//let's use now in the set timezone.
1207
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1208
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1209
+			}
1210
+			if (empty($tkt['TKT_end_date'])) {
1211
+				//use the start date of the first datetime
1212
+				$dtt = $evtobj->first_datetime();
1213
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1214
+					$incoming_date_formats[0],
1215
+					$incoming_date_formats[1]
1216
+				);
1217
+			}
1218
+			$TKT_values = array(
1219
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1220
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1221
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1222
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1223
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1224
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1225
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1226
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1227
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1228
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1229
+				'TKT_row'         => $row,
1230
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1231
+				'TKT_price'       => $ticket_price,
1232
+			);
1233
+			//if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1234
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1235
+				$TKT_values['TKT_ID'] = 0;
1236
+				$TKT_values['TKT_is_default'] = 0;
1237
+				$TKT_values['TKT_price'] = $ticket_price;
1238
+				$update_prices = true;
1239
+			}
1240
+			//if we have a TKT_ID then we need to get that existing TKT_obj and update it
1241
+			//we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1242
+			//keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1243
+			if ( ! empty($tkt['TKT_ID'])) {
1244
+				$TKT = EE_Registry::instance()
1245
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1246
+								  ->get_one_by_ID($tkt['TKT_ID']);
1247
+				if ($TKT instanceof EE_Ticket) {
1248
+					$ticket_sold = $TKT->count_related(
1249
+						'Registration',
1250
+						array(
1251
+							array(
1252
+								'STS_ID' => array(
1253
+									'NOT IN',
1254
+									array(EEM_Registration::status_id_incomplete),
1255
+								),
1256
+							),
1257
+						)
1258
+					) > 0 ? true : false;
1259
+					//let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1260
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1261
+									  && ! $TKT->get(
1262
+						'TKT_deleted'
1263
+					) ? true : false;
1264
+					$TKT->set_date_format($incoming_date_formats[0]);
1265
+					$TKT->set_time_format($incoming_date_formats[1]);
1266
+					//set new values
1267
+					foreach ($TKT_values as $field => $value) {
1268
+						if ($field == 'TKT_qty') {
1269
+							$TKT->set_qty($value);
1270
+						} else {
1271
+							$TKT->set($field, $value);
1272
+						}
1273
+					}
1274
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1275
+					if ($create_new_TKT) {
1276
+						//archive the old ticket first
1277
+						$TKT->set('TKT_deleted', 1);
1278
+						$TKT->save();
1279
+						//make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1280
+						$saved_tickets[$TKT->ID()] = $TKT;
1281
+						//create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1282
+						$TKT = clone $TKT;
1283
+						$TKT->set('TKT_ID', 0);
1284
+						$TKT->set('TKT_deleted', 0);
1285
+						$TKT->set('TKT_price', $ticket_price);
1286
+						$TKT->set('TKT_sold', 0);
1287
+						//now we need to make sure that $new prices are created as well and attached to new ticket.
1288
+						$update_prices = true;
1289
+					}
1290
+					//make sure price is set if it hasn't been already
1291
+					$TKT->set('TKT_price', $ticket_price);
1292
+				}
1293
+			} else {
1294
+				//no TKT_id so a new TKT
1295
+				$TKT_values['TKT_price'] = $ticket_price;
1296
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1297
+				if ($TKT instanceof EE_Ticket) {
1298
+					//need to reset values to properly account for the date formats
1299
+					$TKT->set_date_format($incoming_date_formats[0]);
1300
+					$TKT->set_time_format($incoming_date_formats[1]);
1301
+					$TKT->set_timezone($evtobj->get_timezone());
1302
+					//set new values
1303
+					foreach ($TKT_values as $field => $value) {
1304
+						if ($field == 'TKT_qty') {
1305
+							$TKT->set_qty($value);
1306
+						} else {
1307
+							$TKT->set($field, $value);
1308
+						}
1309
+					}
1310
+					$update_prices = true;
1311
+				}
1312
+			}
1313
+			// cap ticket qty by datetime reg limits
1314
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1315
+			//update ticket.
1316
+			$TKT->save();
1317
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1318
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1319
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1320
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1321
+				$TKT->save();
1322
+			}
1323
+			//initially let's add the ticket to the dtt
1324
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1325
+			$saved_tickets[$TKT->ID()] = $TKT;
1326
+			//add prices to ticket
1327
+			$this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1328
+		}
1329
+		//however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1330
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1331
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1332
+		foreach ($tickets_removed as $id) {
1333
+			$id = absint($id);
1334
+			//get the ticket for this id
1335
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1336
+			//need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1337
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1338
+			foreach ($dtts as $dtt) {
1339
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1340
+			}
1341
+			//need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1342
+			$tkt_to_remove->delete_related_permanently('Price');
1343
+			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1344
+			$tkt_to_remove->delete_permanently();
1345
+		}
1346
+		return array($saved_dtt, $saved_tickets);
1347
+	}
1348
+
1349
+
1350
+
1351
+	/**
1352
+	 * This attaches a list of given prices to a ticket.
1353
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1354
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1355
+	 * price info and prices are automatically "archived" via the ticket.
1356
+	 *
1357
+	 * @access  private
1358
+	 * @param array     $prices     Array of prices from the form.
1359
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1360
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1361
+	 * @return  void
1362
+	 */
1363
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1364
+	{
1365
+		foreach ($prices as $row => $prc) {
1366
+			$PRC_values = array(
1367
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1368
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1369
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1370
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1371
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1372
+				'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1373
+				'PRC_order'      => $row,
1374
+			);
1375
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1376
+				$PRC_values['PRC_ID'] = 0;
1377
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1378
+			} else {
1379
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1380
+				//update this price with new values
1381
+				foreach ($PRC_values as $field => $newprc) {
1382
+					$PRC->set($field, $newprc);
1383
+				}
1384
+				$PRC->save();
1385
+			}
1386
+			$ticket->_add_relation_to($PRC, 'Price');
1387
+		}
1388
+	}
1389
+
1390
+
1391
+
1392
+	/**
1393
+	 * Add in our autosave ajax handlers
1394
+	 *
1395
+	 */
1396
+	protected function _ee_autosave_create_new()
1397
+	{
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 * More autosave handlers.
1403
+	 */
1404
+	protected function _ee_autosave_edit()
1405
+	{
1406
+		return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1407
+	}
1408
+
1409
+
1410
+
1411
+	/**
1412
+	 *    _generate_publish_box_extra_content
1413
+	 */
1414
+	private function _generate_publish_box_extra_content()
1415
+	{
1416
+		//load formatter helper
1417
+		//args for getting related registrations
1418
+		$approved_query_args = array(
1419
+			array(
1420
+				'REG_deleted' => 0,
1421
+				'STS_ID'      => EEM_Registration::status_id_approved,
1422
+			),
1423
+		);
1424
+		$not_approved_query_args = array(
1425
+			array(
1426
+				'REG_deleted' => 0,
1427
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1428
+			),
1429
+		);
1430
+		$pending_payment_query_args = array(
1431
+			array(
1432
+				'REG_deleted' => 0,
1433
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1434
+			),
1435
+		);
1436
+		// publish box
1437
+		$publish_box_extra_args = array(
1438
+			'view_approved_reg_url'        => add_query_arg(
1439
+				array(
1440
+					'action'      => 'default',
1441
+					'event_id'    => $this->_cpt_model_obj->ID(),
1442
+					'_reg_status' => EEM_Registration::status_id_approved,
1443
+				),
1444
+				REG_ADMIN_URL
1445
+			),
1446
+			'view_not_approved_reg_url'    => add_query_arg(
1447
+				array(
1448
+					'action'      => 'default',
1449
+					'event_id'    => $this->_cpt_model_obj->ID(),
1450
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1451
+				),
1452
+				REG_ADMIN_URL
1453
+			),
1454
+			'view_pending_payment_reg_url' => add_query_arg(
1455
+				array(
1456
+					'action'      => 'default',
1457
+					'event_id'    => $this->_cpt_model_obj->ID(),
1458
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1459
+				),
1460
+				REG_ADMIN_URL
1461
+			),
1462
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1463
+				'Registration',
1464
+				$approved_query_args
1465
+			),
1466
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1467
+				'Registration',
1468
+				$not_approved_query_args
1469
+			),
1470
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1471
+				'Registration',
1472
+				$pending_payment_query_args
1473
+			),
1474
+			'misc_pub_section_class'       => apply_filters(
1475
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1476
+				'misc-pub-section'
1477
+			),
1478
+		);
1479
+		ob_start();
1480
+		do_action(
1481
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1482
+			$this->_cpt_model_obj
1483
+		);
1484
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1485
+		// load template
1486
+		EEH_Template::display_template(
1487
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1488
+			$publish_box_extra_args
1489
+		);
1490
+	}
1491
+
1492
+
1493
+
1494
+	/**
1495
+	 * @return EE_Event
1496
+	 */
1497
+	public function get_event_object()
1498
+	{
1499
+		return $this->_cpt_model_obj;
1500
+	}
1501
+
1502
+
1503
+
1504
+
1505
+	/** METABOXES * */
1506
+	/**
1507
+	 * _register_event_editor_meta_boxes
1508
+	 * add all metaboxes related to the event_editor
1509
+	 *
1510
+	 * @return void
1511
+	 */
1512
+	protected function _register_event_editor_meta_boxes()
1513
+	{
1514
+		$this->verify_cpt_object();
1515
+		add_meta_box(
1516
+			'espresso_event_editor_tickets',
1517
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1518
+			array($this, 'ticket_metabox'),
1519
+			$this->page_slug,
1520
+			'normal',
1521
+			'high'
1522
+		);
1523
+		add_meta_box(
1524
+			'espresso_event_editor_event_options',
1525
+			esc_html__('Event Registration Options', 'event_espresso'),
1526
+			array($this, 'registration_options_meta_box'),
1527
+			$this->page_slug,
1528
+			'side',
1529
+			'default'
1530
+		);
1531
+		// NOTE: if you're looking for other metaboxes in here,
1532
+		// where a metabox has a related management page in the admin
1533
+		// you will find it setup in the related management page's "_Hooks" file.
1534
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1535
+	}
1536
+
1537
+
1538
+	/**
1539
+	 * @throws DomainException
1540
+	 * @throws EE_Error
1541
+	 */
1542
+	public function ticket_metabox()
1543
+	{
1544
+		$existing_datetime_ids = $existing_ticket_ids = array();
1545
+		//defaults for template args
1546
+		$template_args = array(
1547
+			'existing_datetime_ids'    => '',
1548
+			'event_datetime_help_link' => '',
1549
+			'ticket_options_help_link' => '',
1550
+			'time'                     => null,
1551
+			'ticket_rows'              => '',
1552
+			'existing_ticket_ids'      => '',
1553
+			'total_ticket_rows'        => 1,
1554
+			'ticket_js_structure'      => '',
1555
+			'trash_icon'               => 'ee-lock-icon',
1556
+			'disabled'                 => '',
1557
+		);
1558
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1559
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1560
+		/**
1561
+		 * 1. Start with retrieving Datetimes
1562
+		 * 2. Fore each datetime get related tickets
1563
+		 * 3. For each ticket get related prices
1564
+		 */
1565
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1566
+		/** @type EE_Datetime $first_datetime */
1567
+		$first_datetime = reset($times);
1568
+		//do we get related tickets?
1569
+		if ($first_datetime instanceof EE_Datetime
1570
+			&& $first_datetime->ID() !== 0
1571
+		) {
1572
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1573
+			$template_args['time'] = $first_datetime;
1574
+			$related_tickets = $first_datetime->tickets(
1575
+				array(
1576
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1577
+					'default_where_conditions' => 'none',
1578
+				)
1579
+			);
1580
+			if ( ! empty($related_tickets)) {
1581
+				$template_args['total_ticket_rows'] = count($related_tickets);
1582
+				$row = 0;
1583
+				foreach ($related_tickets as $ticket) {
1584
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1585
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1586
+					$row++;
1587
+				}
1588
+			} else {
1589
+				$template_args['total_ticket_rows'] = 1;
1590
+				/** @type EE_Ticket $ticket */
1591
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1592
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1593
+			}
1594
+		} else {
1595
+			$template_args['time'] = $times[0];
1596
+			/** @type EE_Ticket $ticket */
1597
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1598
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1599
+			// NOTE: we're just sending the first default row
1600
+			// (decaf can't manage default tickets so this should be sufficient);
1601
+		}
1602
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1603
+			'event_editor_event_datetimes_help_tab'
1604
+		);
1605
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1606
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1607
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1608
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1609
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1610
+			true
1611
+		);
1612
+		$template = apply_filters(
1613
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1614
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1615
+		);
1616
+		EEH_Template::display_template($template, $template_args);
1617
+	}
1618
+
1619
+
1620
+
1621
+	/**
1622
+	 * Setup an individual ticket form for the decaf event editor page
1623
+	 *
1624
+	 * @access private
1625
+	 * @param  EE_Ticket $ticket   the ticket object
1626
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1627
+	 * @param int        $row
1628
+	 * @return string generated html for the ticket row.
1629
+	 */
1630
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1631
+	{
1632
+		$template_args = array(
1633
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1634
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1635
+				: '',
1636
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1637
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1638
+			'TKT_name'            => $ticket->get('TKT_name'),
1639
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1640
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1641
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1642
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1643
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1644
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1645
+			'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1646
+									 && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1647
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1648
+			'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1649
+				: ' disabled=disabled',
1650
+		);
1651
+		$price = $ticket->ID() !== 0
1652
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1653
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1654
+		$price_args = array(
1655
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1656
+			'PRC_amount'            => $price->get('PRC_amount'),
1657
+			'PRT_ID'                => $price->get('PRT_ID'),
1658
+			'PRC_ID'                => $price->get('PRC_ID'),
1659
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1660
+		);
1661
+		//make sure we have default start and end dates if skeleton
1662
+		//handle rows that should NOT be empty
1663
+		if (empty($template_args['TKT_start_date'])) {
1664
+			//if empty then the start date will be now.
1665
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1666
+		}
1667
+		if (empty($template_args['TKT_end_date'])) {
1668
+			//get the earliest datetime (if present);
1669
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1670
+				? $this->_cpt_model_obj->get_first_related(
1671
+					'Datetime',
1672
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1673
+				)
1674
+				: null;
1675
+			if ( ! empty($earliest_dtt)) {
1676
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1677
+			} else {
1678
+				$template_args['TKT_end_date'] = date(
1679
+					'Y-m-d h:i a',
1680
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1681
+				);
1682
+			}
1683
+		}
1684
+		$template_args = array_merge($template_args, $price_args);
1685
+		$template = apply_filters(
1686
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1687
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1688
+			$ticket
1689
+		);
1690
+		return EEH_Template::display_template($template, $template_args, true);
1691
+	}
1692
+
1693
+
1694
+	/**
1695
+	 * @throws DomainException
1696
+	 */
1697
+	public function registration_options_meta_box()
1698
+	{
1699
+		$yes_no_values = array(
1700
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1701
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1702
+		);
1703
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1704
+			array(
1705
+				EEM_Registration::status_id_cancelled,
1706
+				EEM_Registration::status_id_declined,
1707
+				EEM_Registration::status_id_incomplete,
1708
+			),
1709
+			true
1710
+		);
1711
+		//$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1712
+		$template_args['_event'] = $this->_cpt_model_obj;
1713
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1714
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1715
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1716
+			'default_reg_status',
1717
+			$default_reg_status_values,
1718
+			$this->_cpt_model_obj->default_registration_status()
1719
+		);
1720
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1721
+			'display_desc',
1722
+			$yes_no_values,
1723
+			$this->_cpt_model_obj->display_description()
1724
+		);
1725
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1726
+			'display_ticket_selector',
1727
+			$yes_no_values,
1728
+			$this->_cpt_model_obj->display_ticket_selector(),
1729
+			'',
1730
+			'',
1731
+			false
1732
+		);
1733
+		$template_args['additional_registration_options'] = apply_filters(
1734
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1735
+			'',
1736
+			$template_args,
1737
+			$yes_no_values,
1738
+			$default_reg_status_values
1739
+		);
1740
+		EEH_Template::display_template(
1741
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1742
+			$template_args
1743
+		);
1744
+	}
1745
+
1746
+
1747
+
1748
+	/**
1749
+	 * _get_events()
1750
+	 * This method simply returns all the events (for the given _view and paging)
1751
+	 *
1752
+	 * @access public
1753
+	 * @param int  $per_page     count of items per page (20 default);
1754
+	 * @param int  $current_page what is the current page being viewed.
1755
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1756
+	 *                           If FALSE then we return an array of event objects
1757
+	 *                           that match the given _view and paging parameters.
1758
+	 * @return array an array of event objects.
1759
+	 */
1760
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1761
+	{
1762
+		$EEME = $this->_event_model();
1763
+		$offset = ($current_page - 1) * $per_page;
1764
+		$limit = $count ? null : $offset . ',' . $per_page;
1765
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1766
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1767
+		if (isset($this->_req_data['month_range'])) {
1768
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1769
+			//simulate the FIRST day of the month, that fixes issues for months like February
1770
+			//where PHP doesn't know what to assume for date.
1771
+			//@see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1772
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1773
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1774
+		}
1775
+		$where = array();
1776
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1777
+		//determine what post_status our condition will have for the query.
1778
+		switch ($status) {
1779
+			case 'month' :
1780
+			case 'today' :
1781
+			case null :
1782
+			case 'all' :
1783
+				break;
1784
+			case 'draft' :
1785
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1786
+				break;
1787
+			default :
1788
+				$where['status'] = $status;
1789
+		}
1790
+		//categories?
1791
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1792
+			? $this->_req_data['EVT_CAT'] : null;
1793
+		if ( ! empty ($category)) {
1794
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1795
+			$where['Term_Taxonomy.term_id'] = $category;
1796
+		}
1797
+		//date where conditions
1798
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1799
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1800
+			$DateTime = new DateTime(
1801
+				$year_r . '-' . $month_r . '-01 00:00:00',
1802
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1803
+			);
1804
+			$start = $DateTime->format(implode(' ', $start_formats));
1805
+			$end = $DateTime->setDate($year_r, $month_r, $DateTime
1806
+				->format('t'))->setTime(23, 59, 59)
1807
+							->format(implode(' ', $start_formats));
1808
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1809
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1810
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1811
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1812
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1813
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1814
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1815
+			$now = date('Y-m-01');
1816
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1817
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1818
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1819
+							->setTime(23, 59, 59)
1820
+							->format(implode(' ', $start_formats));
1821
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1822
+		}
1823
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1824
+			$where['EVT_wp_user'] = get_current_user_id();
1825
+		} else {
1826
+			if ( ! isset($where['status'])) {
1827
+				if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1828
+					$where['OR'] = array(
1829
+						'status*restrict_private' => array('!=', 'private'),
1830
+						'AND'                     => array(
1831
+							'status*inclusive' => array('=', 'private'),
1832
+							'EVT_wp_user'      => get_current_user_id(),
1833
+						),
1834
+					);
1835
+				}
1836
+			}
1837
+		}
1838
+		if (isset($this->_req_data['EVT_wp_user'])) {
1839
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1840
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1841
+			) {
1842
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1843
+			}
1844
+		}
1845
+		//search query handling
1846
+		if (isset($this->_req_data['s'])) {
1847
+			$search_string = '%' . $this->_req_data['s'] . '%';
1848
+			$where['OR'] = array(
1849
+				'EVT_name'       => array('LIKE', $search_string),
1850
+				'EVT_desc'       => array('LIKE', $search_string),
1851
+				'EVT_short_desc' => array('LIKE', $search_string),
1852
+			);
1853
+		}
1854
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1855
+		$query_params = apply_filters(
1856
+			'FHEE__Events_Admin_Page__get_events__query_params',
1857
+			array(
1858
+				$where,
1859
+				'limit'    => $limit,
1860
+				'order_by' => $orderby,
1861
+				'order'    => $order,
1862
+				'group_by' => 'EVT_ID',
1863
+			),
1864
+			$this->_req_data
1865
+		);
1866
+		//let's first check if we have special requests coming in.
1867
+		if (isset($this->_req_data['active_status'])) {
1868
+			switch ($this->_req_data['active_status']) {
1869
+				case 'upcoming' :
1870
+					return $EEME->get_upcoming_events($query_params, $count);
1871
+					break;
1872
+				case 'expired' :
1873
+					return $EEME->get_expired_events($query_params, $count);
1874
+					break;
1875
+				case 'active' :
1876
+					return $EEME->get_active_events($query_params, $count);
1877
+					break;
1878
+				case 'inactive' :
1879
+					return $EEME->get_inactive_events($query_params, $count);
1880
+					break;
1881
+			}
1882
+		}
1883
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1884
+		return $events;
1885
+	}
1886
+
1887
+
1888
+
1889
+	/**
1890
+	 * handling for WordPress CPT actions (trash, restore, delete)
1891
+	 *
1892
+	 * @param string $post_id
1893
+	 */
1894
+	public function trash_cpt_item($post_id)
1895
+	{
1896
+		$this->_req_data['EVT_ID'] = $post_id;
1897
+		$this->_trash_or_restore_event('trash', false);
1898
+	}
1899
+
1900
+
1901
+
1902
+	/**
1903
+	 * @param string $post_id
1904
+	 */
1905
+	public function restore_cpt_item($post_id)
1906
+	{
1907
+		$this->_req_data['EVT_ID'] = $post_id;
1908
+		$this->_trash_or_restore_event('draft', false);
1909
+	}
1910
+
1911
+
1912
+
1913
+	/**
1914
+	 * @param string $post_id
1915
+	 */
1916
+	public function delete_cpt_item($post_id)
1917
+	{
1918
+		$this->_req_data['EVT_ID'] = $post_id;
1919
+		$this->_delete_event(false);
1920
+	}
1921
+
1922
+
1923
+
1924
+	/**
1925
+	 * _trash_or_restore_event
1926
+	 *
1927
+	 * @access protected
1928
+	 * @param  string $event_status
1929
+	 * @param bool    $redirect_after
1930
+	 */
1931
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1932
+	{
1933
+		//determine the event id and set to array.
1934
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1935
+		// loop thru events
1936
+		if ($EVT_ID) {
1937
+			// clean status
1938
+			$event_status = sanitize_key($event_status);
1939
+			// grab status
1940
+			if ( ! empty($event_status)) {
1941
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1942
+			} else {
1943
+				$success = false;
1944
+				$msg = esc_html__(
1945
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1946
+					'event_espresso'
1947
+				);
1948
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1949
+			}
1950
+		} else {
1951
+			$success = false;
1952
+			$msg = esc_html__(
1953
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1954
+				'event_espresso'
1955
+			);
1956
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1957
+		}
1958
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1959
+		if ($redirect_after) {
1960
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1961
+		}
1962
+	}
1963
+
1964
+
1965
+
1966
+	/**
1967
+	 * _trash_or_restore_events
1968
+	 *
1969
+	 * @access protected
1970
+	 * @param  string $event_status
1971
+	 * @return void
1972
+	 */
1973
+	protected function _trash_or_restore_events($event_status = 'trash')
1974
+	{
1975
+		// clean status
1976
+		$event_status = sanitize_key($event_status);
1977
+		// grab status
1978
+		if ( ! empty($event_status)) {
1979
+			$success = true;
1980
+			//determine the event id and set to array.
1981
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1982
+			// loop thru events
1983
+			foreach ($EVT_IDs as $EVT_ID) {
1984
+				if ($EVT_ID = absint($EVT_ID)) {
1985
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1986
+					$success = $results !== false ? $success : false;
1987
+				} else {
1988
+					$msg = sprintf(
1989
+						esc_html__(
1990
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1991
+							'event_espresso'
1992
+						),
1993
+						$EVT_ID
1994
+					);
1995
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1996
+					$success = false;
1997
+				}
1998
+			}
1999
+		} else {
2000
+			$success = false;
2001
+			$msg = esc_html__(
2002
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2003
+				'event_espresso'
2004
+			);
2005
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2006
+		}
2007
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2008
+		$success = $success ? 2 : false;
2009
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2010
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2011
+	}
2012
+
2013
+
2014
+
2015
+	/**
2016
+	 * _trash_or_restore_events
2017
+	 *
2018
+	 * @access  private
2019
+	 * @param  int    $EVT_ID
2020
+	 * @param  string $event_status
2021
+	 * @return bool
2022
+	 */
2023
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2024
+	{
2025
+		// grab event id
2026
+		if ( ! $EVT_ID) {
2027
+			$msg = esc_html__(
2028
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2029
+				'event_espresso'
2030
+			);
2031
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2032
+			return false;
2033
+		}
2034
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2035
+		// clean status
2036
+		$event_status = sanitize_key($event_status);
2037
+		// grab status
2038
+		if (empty($event_status)) {
2039
+			$msg = esc_html__(
2040
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2041
+				'event_espresso'
2042
+			);
2043
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2044
+			return false;
2045
+		}
2046
+		// was event trashed or restored ?
2047
+		switch ($event_status) {
2048
+			case 'draft' :
2049
+				$action = 'restored from the trash';
2050
+				$hook = 'AHEE_event_restored_from_trash';
2051
+				break;
2052
+			case 'trash' :
2053
+				$action = 'moved to the trash';
2054
+				$hook = 'AHEE_event_moved_to_trash';
2055
+				break;
2056
+			default :
2057
+				$action = 'updated';
2058
+				$hook = false;
2059
+		}
2060
+		//use class to change status
2061
+		$this->_cpt_model_obj->set_status($event_status);
2062
+		$success = $this->_cpt_model_obj->save();
2063
+		if ($success === false) {
2064
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2065
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2066
+			return false;
2067
+		}
2068
+		if ($hook) {
2069
+			do_action($hook);
2070
+		}
2071
+		return true;
2072
+	}
2073
+
2074
+
2075
+
2076
+	/**
2077
+	 * _delete_event
2078
+	 *
2079
+	 * @access protected
2080
+	 * @param bool $redirect_after
2081
+	 */
2082
+	protected function _delete_event($redirect_after = true)
2083
+	{
2084
+		//determine the event id and set to array.
2085
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2086
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2087
+		// loop thru events
2088
+		if ($EVT_ID) {
2089
+			$success = $this->_permanently_delete_event($EVT_ID);
2090
+			// get list of events with no prices
2091
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2092
+			// remove this event from the list of events with no prices
2093
+			if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2094
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2095
+			}
2096
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2097
+		} else {
2098
+			$success = false;
2099
+			$msg = esc_html__(
2100
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2101
+				'event_espresso'
2102
+			);
2103
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2104
+		}
2105
+		if ($redirect_after) {
2106
+			$this->_redirect_after_action(
2107
+				$success,
2108
+				'Event',
2109
+				'deleted',
2110
+				array('action' => 'default', 'status' => 'trash')
2111
+			);
2112
+		}
2113
+	}
2114
+
2115
+
2116
+
2117
+	/**
2118
+	 * _delete_events
2119
+	 *
2120
+	 * @access protected
2121
+	 * @return void
2122
+	 */
2123
+	protected function _delete_events()
2124
+	{
2125
+		$success = true;
2126
+		// get list of events with no prices
2127
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2128
+		//determine the event id and set to array.
2129
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2130
+		// loop thru events
2131
+		foreach ($EVT_IDs as $EVT_ID) {
2132
+			$EVT_ID = absint($EVT_ID);
2133
+			if ($EVT_ID) {
2134
+				$results = $this->_permanently_delete_event($EVT_ID);
2135
+				$success = $results !== false ? $success : false;
2136
+				// remove this event from the list of events with no prices
2137
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2138
+			} else {
2139
+				$success = false;
2140
+				$msg = esc_html__(
2141
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2142
+					'event_espresso'
2143
+				);
2144
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2145
+			}
2146
+		}
2147
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2148
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2149
+		$success = $success ? 2 : false;
2150
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2151
+	}
2152
+
2153
+
2154
+
2155
+	/**
2156
+	 * _permanently_delete_event
2157
+	 *
2158
+	 * @access  private
2159
+	 * @param  int $EVT_ID
2160
+	 * @return bool
2161
+	 */
2162
+	private function _permanently_delete_event($EVT_ID = 0)
2163
+	{
2164
+		// grab event id
2165
+		if ( ! $EVT_ID) {
2166
+			$msg = esc_html__(
2167
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2168
+				'event_espresso'
2169
+			);
2170
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
+			return false;
2172
+		}
2173
+		if (
2174
+			! $this->_cpt_model_obj instanceof EE_Event
2175
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2176
+		) {
2177
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2178
+		}
2179
+		if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2180
+			return false;
2181
+		}
2182
+		//need to delete related tickets and prices first.
2183
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2184
+		foreach ($datetimes as $datetime) {
2185
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2186
+			$tickets = $datetime->get_many_related('Ticket');
2187
+			foreach ($tickets as $ticket) {
2188
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2189
+				$ticket->delete_related_permanently('Price');
2190
+				$ticket->delete_permanently();
2191
+			}
2192
+			$datetime->delete();
2193
+		}
2194
+		//what about related venues or terms?
2195
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2196
+		foreach ($venues as $venue) {
2197
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2198
+		}
2199
+		//any attached question groups?
2200
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2201
+		if ( ! empty($question_groups)) {
2202
+			foreach ($question_groups as $question_group) {
2203
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2204
+			}
2205
+		}
2206
+		//Message Template Groups
2207
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2208
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2209
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2210
+		foreach ($term_taxonomies as $term_taxonomy) {
2211
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2212
+		}
2213
+		$success = $this->_cpt_model_obj->delete_permanently();
2214
+		// did it all go as planned ?
2215
+		if ($success) {
2216
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2217
+			EE_Error::add_success($msg);
2218
+		} else {
2219
+			$msg = sprintf(
2220
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2221
+				$EVT_ID
2222
+			);
2223
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2224
+			return false;
2225
+		}
2226
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2227
+		return true;
2228
+	}
2229
+
2230
+
2231
+
2232
+	/**
2233
+	 * get total number of events
2234
+	 *
2235
+	 * @access public
2236
+	 * @return int
2237
+	 */
2238
+	public function total_events()
2239
+	{
2240
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2241
+		return $count;
2242
+	}
2243
+
2244
+
2245
+
2246
+	/**
2247
+	 * get total number of draft events
2248
+	 *
2249
+	 * @access public
2250
+	 * @return int
2251
+	 */
2252
+	public function total_events_draft()
2253
+	{
2254
+		$where = array(
2255
+			'status' => array('IN', array('draft', 'auto-draft')),
2256
+		);
2257
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2258
+		return $count;
2259
+	}
2260
+
2261
+
2262
+
2263
+	/**
2264
+	 * get total number of trashed events
2265
+	 *
2266
+	 * @access public
2267
+	 * @return int
2268
+	 */
2269
+	public function total_trashed_events()
2270
+	{
2271
+		$where = array(
2272
+			'status' => 'trash',
2273
+		);
2274
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2275
+		return $count;
2276
+	}
2277
+
2278
+
2279
+	/**
2280
+	 *    _default_event_settings
2281
+	 *    This generates the Default Settings Tab
2282
+	 *
2283
+	 * @return void
2284
+	 * @throws EE_Error
2285
+	 */
2286
+	protected function _default_event_settings()
2287
+	{
2288
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2289
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2290
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2291
+		$this->display_admin_page_with_sidebar();
2292
+	}
2293
+
2294
+
2295
+	/**
2296
+	 * Return the form for event settings.
2297
+	 * @return EE_Form_Section_Proper
2298
+	 */
2299
+	protected function _default_event_settings_form()
2300
+	{
2301
+		$registration_config = EE_Registry::instance()->CFG->registration;
2302
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2303
+		//exclude
2304
+			array(
2305
+				EEM_Registration::status_id_cancelled,
2306
+				EEM_Registration::status_id_declined,
2307
+				EEM_Registration::status_id_incomplete,
2308
+				EEM_Registration::status_id_wait_list,
2309
+			),
2310
+			true
2311
+		);
2312
+		return new EE_Form_Section_Proper(
2313
+			array(
2314
+				'name' => 'update_default_event_settings',
2315
+				'html_id' => 'update_default_event_settings',
2316
+				'html_class' => 'form-table',
2317
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2318
+				'subsections' => apply_filters(
2319
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2320
+					array(
2321
+						'default_reg_status' => new EE_Select_Input(
2322
+							$registration_stati_for_selection,
2323
+							array(
2324
+								'default' => isset($registration_config->default_STS_ID)
2325
+											 && array_key_exists(
2326
+												$registration_config->default_STS_ID,
2327
+												$registration_stati_for_selection
2328
+											 )
2329
+											? sanitize_text_field($registration_config->default_STS_ID)
2330
+											: EEM_Registration::status_id_pending_payment,
2331
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2332
+													. EEH_Template::get_help_tab_link(
2333
+														'default_settings_status_help_tab'
2334
+													),
2335
+								'html_help_text' => esc_html__(
2336
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2337
+									'event_espresso'
2338
+								)
2339
+							)
2340
+						),
2341
+						'default_max_tickets' => new EE_Integer_Input(
2342
+							array(
2343
+								'default' => isset($registration_config->default_maximum_number_of_tickets)
2344
+									? $registration_config->default_maximum_number_of_tickets
2345
+									: EEM_Event::get_default_additional_limit(),
2346
+								'html_label_text' => esc_html__(
2347
+									'Default Maximum Tickets Allowed Per Order:',
2348
+									'event_espresso'
2349
+								) . EEH_Template::get_help_tab_link(
2350
+									'default_maximum_tickets_help_tab"'
2351
+									),
2352
+								'html_help_text' => esc_html__(
2353
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2354
+									'event_espresso'
2355
+								)
2356
+							)
2357
+						)
2358
+					)
2359
+				)
2360
+			)
2361
+		);
2362
+	}
2363
+
2364
+
2365
+	/**
2366
+	 * _update_default_event_settings
2367
+	 *
2368
+	 * @access protected
2369
+	 * @return void
2370
+	 * @throws EE_Error
2371
+	 */
2372
+	protected function _update_default_event_settings()
2373
+	{
2374
+		$registration_config = EE_Registry::instance()->CFG->registration;
2375
+		$form = $this->_default_event_settings_form();
2376
+		if ($form->was_submitted()) {
2377
+			$form->receive_form_submission();
2378
+			if ($form->is_valid()) {
2379
+				$valid_data = $form->valid_data();
2380
+				if (isset($valid_data['default_reg_status'])) {
2381
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2382
+				}
2383
+				if (isset($valid_data['default_max_tickets'])) {
2384
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2385
+				}
2386
+				//update because data was valid!
2387
+				EE_Registry::instance()->CFG->update_espresso_config();
2388
+				EE_Error::overwrite_success();
2389
+				EE_Error::add_success(
2390
+					__('Default Event Settings were updated', 'event_espresso')
2391
+				);
2392
+			}
2393
+		}
2394
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2395
+	}
2396
+
2397
+
2398
+
2399
+	/*************        Templates        *************/
2400
+	protected function _template_settings()
2401
+	{
2402
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2403
+		$this->_template_args['preview_img'] = '<img src="'
2404
+											   . EVENTS_ASSETS_URL
2405
+											   . DS
2406
+											   . 'images'
2407
+											   . DS
2408
+											   . 'caffeinated_template_features.jpg" alt="'
2409
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2410
+											   . '" />';
2411
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__(
2412
+				'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2413
+				'event_espresso'
2414
+			) . '</strong>';
2415
+		$this->display_admin_caf_preview_page('template_settings_tab');
2416
+	}
2417
+
2418
+
2419
+	/** Event Category Stuff **/
2420
+	/**
2421
+	 * set the _category property with the category object for the loaded page.
2422
+	 *
2423
+	 * @access private
2424
+	 * @return void
2425
+	 */
2426
+	private function _set_category_object()
2427
+	{
2428
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2429
+			return;
2430
+		} //already have the category object so get out.
2431
+		//set default category object
2432
+		$this->_set_empty_category_object();
2433
+		//only set if we've got an id
2434
+		if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2435
+			return;
2436
+		}
2437
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2438
+		$term = get_term($category_id, 'espresso_event_categories');
2439
+		if ( ! empty($term)) {
2440
+			$this->_category->category_name = $term->name;
2441
+			$this->_category->category_identifier = $term->slug;
2442
+			$this->_category->category_desc = $term->description;
2443
+			$this->_category->id = $term->term_id;
2444
+			$this->_category->parent = $term->parent;
2445
+		}
2446
+	}
2447
+
2448
+
2449
+	/**
2450
+	 * Clears out category properties.
2451
+	 */
2452
+	private function _set_empty_category_object()
2453
+	{
2454
+		$this->_category = new stdClass();
2455
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2456
+		$this->_category->id = $this->_category->parent = 0;
2457
+	}
2458
+
2459
+
2460
+	/**
2461
+	 * @throws EE_Error
2462
+	 */
2463
+	protected function _category_list_table()
2464
+	{
2465
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2466
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2467
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2468
+				'add_category',
2469
+				'add_category',
2470
+				array(),
2471
+				'add-new-h2'
2472
+			);
2473
+		$this->display_admin_list_table_page_with_sidebar();
2474
+	}
2475
+
2476
+
2477
+
2478
+	/**
2479
+	 * Output category details view.
2480
+	 */
2481
+	protected function _category_details($view)
2482
+	{
2483
+		//load formatter helper
2484
+		//load field generator helper
2485
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2486
+		$this->_set_add_edit_form_tags($route);
2487
+		$this->_set_category_object();
2488
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2489
+		$delete_action = 'delete_category';
2490
+		//custom redirect
2491
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2492
+			array('action' => 'category_list'),
2493
+			$this->_admin_base_url
2494
+		);
2495
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2496
+		//take care of contents
2497
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2498
+		$this->display_admin_page_with_sidebar();
2499
+	}
2500
+
2501
+
2502
+
2503
+	/**
2504
+	 * Output category details content.
2505
+	 */
2506
+	protected function _category_details_content()
2507
+	{
2508
+		$editor_args['category_desc'] = array(
2509
+			'type'          => 'wp_editor',
2510
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2511
+			'class'         => 'my_editor_custom',
2512
+			'wpeditor_args' => array('media_buttons' => false),
2513
+		);
2514
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2515
+		$all_terms = get_terms(
2516
+			array('espresso_event_categories'),
2517
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2518
+		);
2519
+		//setup category select for term parents.
2520
+		$category_select_values[] = array(
2521
+			'text' => esc_html__('No Parent', 'event_espresso'),
2522
+			'id'   => 0,
2523
+		);
2524
+		foreach ($all_terms as $term) {
2525
+			$category_select_values[] = array(
2526
+				'text' => $term->name,
2527
+				'id'   => $term->term_id,
2528
+			);
2529
+		}
2530
+		$category_select = EEH_Form_Fields::select_input(
2531
+			'category_parent',
2532
+			$category_select_values,
2533
+			$this->_category->parent
2534
+		);
2535
+		$template_args = array(
2536
+			'category'                 => $this->_category,
2537
+			'category_select'          => $category_select,
2538
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2539
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2540
+			'disable'                  => '',
2541
+			'disabled_message'         => false,
2542
+		);
2543
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2544
+		return EEH_Template::display_template($template, $template_args, true);
2545
+	}
2546
+
2547
+
2548
+	/**
2549
+	 * Handles deleting categories.
2550
+	 */
2551
+	protected function _delete_categories()
2552
+	{
2553
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2554
+			: (array)$this->_req_data['category_id'];
2555
+		foreach ($cat_ids as $cat_id) {
2556
+			$this->_delete_category($cat_id);
2557
+		}
2558
+		//doesn't matter what page we're coming from... we're going to the same place after delete.
2559
+		$query_args = array(
2560
+			'action' => 'category_list',
2561
+		);
2562
+		$this->_redirect_after_action(0, '', '', $query_args);
2563
+	}
2564
+
2565
+
2566
+
2567
+	/**
2568
+	 * Handles deleting specific category.
2569
+	 * @param int $cat_id
2570
+	 */
2571
+	protected function _delete_category($cat_id)
2572
+	{
2573
+		$cat_id = absint($cat_id);
2574
+		wp_delete_term($cat_id, 'espresso_event_categories');
2575
+	}
2576
+
2577
+
2578
+
2579
+	/**
2580
+	 * Handles triggering the update or insertion of a new category.
2581
+	 * @param bool $new_category  true means we're triggering the insert of a new category.
2582
+	 */
2583
+	protected function _insert_or_update_category($new_category)
2584
+	{
2585
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2586
+		$success = 0; //we already have a success message so lets not send another.
2587
+		if ($cat_id) {
2588
+			$query_args = array(
2589
+				'action'     => 'edit_category',
2590
+				'EVT_CAT_ID' => $cat_id,
2591
+			);
2592
+		} else {
2593
+			$query_args = array('action' => 'add_category');
2594
+		}
2595
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2596
+	}
2597
+
2598
+
2599
+
2600
+	/**
2601
+	 * Inserts or updates category
2602
+	 * @param bool $update (true indicates we're updating a category).
2603
+	 * @return bool|mixed|string
2604
+	 */
2605
+	private function _insert_category($update = false)
2606
+	{
2607
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2608
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2609
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2610
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2611
+		if (empty($category_name)) {
2612
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2613
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2614
+			return false;
2615
+		}
2616
+		$term_args = array(
2617
+			'name'        => $category_name,
2618
+			'description' => $category_desc,
2619
+			'parent'      => $category_parent,
2620
+		);
2621
+		//was the category_identifier input disabled?
2622
+		if (isset($this->_req_data['category_identifier'])) {
2623
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2624
+		}
2625
+		$insert_ids = $update
2626
+			? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2627
+			: wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2628
+		if ( ! is_array($insert_ids)) {
2629
+			$msg = esc_html__(
2630
+				'An error occurred and the category has not been saved to the database.',
2631
+				'event_espresso'
2632
+			);
2633
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2634
+		} else {
2635
+			$cat_id = $insert_ids['term_id'];
2636
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2637
+			EE_Error::add_success($msg);
2638
+		}
2639
+		return $cat_id;
2640
+	}
2641
+
2642
+
2643
+
2644
+	/**
2645
+	 * Gets categories or count of categories matching the arguments in the request.
2646
+	 * @param int  $per_page
2647
+	 * @param int  $current_page
2648
+	 * @param bool $count
2649
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2650
+	 */
2651
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2652
+	{
2653
+		//testing term stuff
2654
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2655
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2656
+		$limit = ($current_page - 1) * $per_page;
2657
+		$where = array('taxonomy' => 'espresso_event_categories');
2658
+		if (isset($this->_req_data['s'])) {
2659
+			$sstr = '%' . $this->_req_data['s'] . '%';
2660
+			$where['OR'] = array(
2661
+				'Term.name'   => array('LIKE', $sstr),
2662
+				'description' => array('LIKE', $sstr),
2663
+			);
2664
+		}
2665
+		$query_params = array(
2666
+			$where,
2667
+			'order_by'   => array($orderby => $order),
2668
+			'limit'      => $limit . ',' . $per_page,
2669
+			'force_join' => array('Term'),
2670
+		);
2671
+		$categories = $count
2672
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2673
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2674
+		return $categories;
2675
+	}
2676
+
2677
+	/* end category stuff */
2678
+	/**************/
2679
+
2680
+
2681
+	/**
2682
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2683
+	 * @throws EE_Error
2684
+	 */
2685
+	public function save_timezonestring_setting()
2686
+	{
2687
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2688
+			? $this->_req_data['timezone_selected']
2689
+			: '';
2690
+		if  (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2691
+		{
2692
+			EE_Error::add_error(
2693
+				esc_html('An invalid timezone string submitted.', 'event_espresso'),
2694
+				__FILE__, __FUNCTION__, __LINE__
2695
+			);
2696
+			$this->_template_args['error'] = true;
2697
+			$this->_return_json();
2698
+		}
2699
+
2700
+		update_option('timezone_string', $timezone_string);
2701
+		EE_Error::add_success(
2702
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2703
+		);
2704
+		$this->_template_args['success'] = true;
2705
+		$this->_return_json(true, array('action' => 'create_new'));
2706
+	}
2707 2707
 }
2708 2708
 //end class Events_Admin_Page
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -553,11 +553,11 @@  discard block
 block discarded – undo
553 553
     {
554 554
         wp_register_style(
555 555
             'events-admin-css',
556
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
556
+            EVENTS_ASSETS_URL.'events-admin-page.css',
557 557
             array(),
558 558
             EVENT_ESPRESSO_VERSION
559 559
         );
560
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
560
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
561 561
         wp_enqueue_style('events-admin-css');
562 562
         wp_enqueue_style('ee-cat-admin');
563 563
         //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
         //scripts
566 566
         wp_register_script(
567 567
             'event_editor_js',
568
-            EVENTS_ASSETS_URL . 'event_editor.js',
568
+            EVENTS_ASSETS_URL.'event_editor.js',
569 569
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
570 570
             EVENT_ESPRESSO_VERSION,
571 571
             true
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
         wp_enqueue_style('espresso-ui-theme');
594 594
         wp_register_style(
595 595
             'event-editor-css',
596
-            EVENTS_ASSETS_URL . 'event-editor.css',
596
+            EVENTS_ASSETS_URL.'event-editor.css',
597 597
             array('ee-admin-css'),
598 598
             EVENT_ESPRESSO_VERSION
599 599
         );
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
         //scripts
602 602
         wp_register_script(
603 603
             'event-datetime-metabox',
604
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
604
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
605 605
             array('event_editor_js', 'ee-datepicker'),
606 606
             EVENT_ESPRESSO_VERSION
607 607
         );
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
     public function verify_event_edit($event = null, $req_type = '')
671 671
     {
672 672
         // don't need to do this when processing
673
-        if(!empty($req_type)) {
673
+        if ( ! empty($req_type)) {
674 674
             return;
675 675
         }
676 676
         // no event?
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
             $event = $this->_cpt_model_obj;
680 680
         }
681 681
         // STILL no event?
682
-        if (! $event instanceof EE_Event) {
682
+        if ( ! $event instanceof EE_Event) {
683 683
             return;
684 684
         }
685 685
         $orig_status = $event->status();
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
     {
762 762
         $has_timezone_string = get_option('timezone_string');
763 763
         //only nag them about setting their timezone if it's their first event, and they haven't already done it
764
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
764
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
765 765
             EE_Error::add_attention(
766 766
                 sprintf(
767 767
                     __(
@@ -845,31 +845,31 @@  discard block
 block discarded – undo
845 845
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
846 846
         $statuses = array(
847 847
             'sold_out_status'  => array(
848
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
848
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
849 849
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
850 850
             ),
851 851
             'active_status'    => array(
852
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
852
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
853 853
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
854 854
             ),
855 855
             'upcoming_status'  => array(
856
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
856
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
857 857
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
858 858
             ),
859 859
             'postponed_status' => array(
860
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
860
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
861 861
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
862 862
             ),
863 863
             'cancelled_status' => array(
864
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
864
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
865 865
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
866 866
             ),
867 867
             'expired_status'   => array(
868
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
868
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
869 869
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
870 870
             ),
871 871
             'inactive_status'  => array(
872
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
872
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
873 873
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
874 874
             ),
875 875
         );
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
     {
932 932
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
933 933
         $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
934
-            ? (array)$this->_template_args['after_list_table']
934
+            ? (array) $this->_template_args['after_list_table']
935 935
             : array();
936 936
         $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
937 937
                                                                               . EEH_Template::get_button_or_link(
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
                 'button'
941 941
             );
942 942
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
943
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
943
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
944 944
                 'create_new',
945 945
                 'add',
946 946
                 array(),
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
      */
1082 1082
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1083 1083
     {
1084
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1084
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1085 1085
         $venue_model = EE_Registry::instance()->load_model('Venue');
1086 1086
         $rows_affected = null;
1087 1087
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1205,7 +1205,7 @@  discard block
 block discarded – undo
1205 1205
             if (empty($tkt['TKT_start_date'])) {
1206 1206
                 //let's use now in the set timezone.
1207 1207
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1208
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1208
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1209 1209
             }
1210 1210
             if (empty($tkt['TKT_end_date'])) {
1211 1211
                 //use the start date of the first datetime
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1485 1485
         // load template
1486 1486
         EEH_Template::display_template(
1487
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1487
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1488 1488
             $publish_box_extra_args
1489 1489
         );
1490 1490
     }
@@ -1611,7 +1611,7 @@  discard block
 block discarded – undo
1611 1611
         );
1612 1612
         $template = apply_filters(
1613 1613
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1614
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1614
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1615 1615
         );
1616 1616
         EEH_Template::display_template($template, $template_args);
1617 1617
     }
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1631 1631
     {
1632 1632
         $template_args = array(
1633
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1633
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1634 1634
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1635 1635
                 : '',
1636 1636
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1684,7 +1684,7 @@  discard block
 block discarded – undo
1684 1684
         $template_args = array_merge($template_args, $price_args);
1685 1685
         $template = apply_filters(
1686 1686
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1687
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1687
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1688 1688
             $ticket
1689 1689
         );
1690 1690
         return EEH_Template::display_template($template, $template_args, true);
@@ -1738,7 +1738,7 @@  discard block
 block discarded – undo
1738 1738
             $default_reg_status_values
1739 1739
         );
1740 1740
         EEH_Template::display_template(
1741
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1741
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1742 1742
             $template_args
1743 1743
         );
1744 1744
     }
@@ -1761,7 +1761,7 @@  discard block
 block discarded – undo
1761 1761
     {
1762 1762
         $EEME = $this->_event_model();
1763 1763
         $offset = ($current_page - 1) * $per_page;
1764
-        $limit = $count ? null : $offset . ',' . $per_page;
1764
+        $limit = $count ? null : $offset.','.$per_page;
1765 1765
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1766 1766
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1767 1767
         if (isset($this->_req_data['month_range'])) {
@@ -1798,7 +1798,7 @@  discard block
 block discarded – undo
1798 1798
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1799 1799
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1800 1800
             $DateTime = new DateTime(
1801
-                $year_r . '-' . $month_r . '-01 00:00:00',
1801
+                $year_r.'-'.$month_r.'-01 00:00:00',
1802 1802
                 new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1803 1803
             );
1804 1804
             $start = $DateTime->format(implode(' ', $start_formats));
@@ -1844,7 +1844,7 @@  discard block
 block discarded – undo
1844 1844
         }
1845 1845
         //search query handling
1846 1846
         if (isset($this->_req_data['s'])) {
1847
-            $search_string = '%' . $this->_req_data['s'] . '%';
1847
+            $search_string = '%'.$this->_req_data['s'].'%';
1848 1848
             $where['OR'] = array(
1849 1849
                 'EVT_name'       => array('LIKE', $search_string),
1850 1850
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1978,7 +1978,7 @@  discard block
 block discarded – undo
1978 1978
         if ( ! empty($event_status)) {
1979 1979
             $success = true;
1980 1980
             //determine the event id and set to array.
1981
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1981
+            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1982 1982
             // loop thru events
1983 1983
             foreach ($EVT_IDs as $EVT_ID) {
1984 1984
                 if ($EVT_ID = absint($EVT_ID)) {
@@ -2126,7 +2126,7 @@  discard block
 block discarded – undo
2126 2126
         // get list of events with no prices
2127 2127
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2128 2128
         //determine the event id and set to array.
2129
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2129
+        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2130 2130
         // loop thru events
2131 2131
         foreach ($EVT_IDs as $EVT_ID) {
2132 2132
             $EVT_ID = absint($EVT_ID);
@@ -2346,7 +2346,7 @@  discard block
 block discarded – undo
2346 2346
                                 'html_label_text' => esc_html__(
2347 2347
                                     'Default Maximum Tickets Allowed Per Order:',
2348 2348
                                     'event_espresso'
2349
-                                ) . EEH_Template::get_help_tab_link(
2349
+                                ).EEH_Template::get_help_tab_link(
2350 2350
                                     'default_maximum_tickets_help_tab"'
2351 2351
                                     ),
2352 2352
                                 'html_help_text' => esc_html__(
@@ -2408,10 +2408,10 @@  discard block
 block discarded – undo
2408 2408
                                                . 'caffeinated_template_features.jpg" alt="'
2409 2409
                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2410 2410
                                                . '" />';
2411
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2411
+        $this->_template_args['preview_text'] = '<strong>'.esc_html__(
2412 2412
                 'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2413 2413
                 'event_espresso'
2414
-            ) . '</strong>';
2414
+            ).'</strong>';
2415 2415
         $this->display_admin_caf_preview_page('template_settings_tab');
2416 2416
     }
2417 2417
 
@@ -2464,7 +2464,7 @@  discard block
 block discarded – undo
2464 2464
     {
2465 2465
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2466 2466
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2467
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2467
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2468 2468
                 'add_category',
2469 2469
                 'add_category',
2470 2470
                 array(),
@@ -2540,7 +2540,7 @@  discard block
 block discarded – undo
2540 2540
             'disable'                  => '',
2541 2541
             'disabled_message'         => false,
2542 2542
         );
2543
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2543
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2544 2544
         return EEH_Template::display_template($template, $template_args, true);
2545 2545
     }
2546 2546
 
@@ -2550,8 +2550,8 @@  discard block
 block discarded – undo
2550 2550
      */
2551 2551
     protected function _delete_categories()
2552 2552
     {
2553
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2554
-            : (array)$this->_req_data['category_id'];
2553
+        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2554
+            : (array) $this->_req_data['category_id'];
2555 2555
         foreach ($cat_ids as $cat_id) {
2556 2556
             $this->_delete_category($cat_id);
2557 2557
         }
@@ -2656,7 +2656,7 @@  discard block
 block discarded – undo
2656 2656
         $limit = ($current_page - 1) * $per_page;
2657 2657
         $where = array('taxonomy' => 'espresso_event_categories');
2658 2658
         if (isset($this->_req_data['s'])) {
2659
-            $sstr = '%' . $this->_req_data['s'] . '%';
2659
+            $sstr = '%'.$this->_req_data['s'].'%';
2660 2660
             $where['OR'] = array(
2661 2661
                 'Term.name'   => array('LIKE', $sstr),
2662 2662
                 'description' => array('LIKE', $sstr),
@@ -2665,7 +2665,7 @@  discard block
 block discarded – undo
2665 2665
         $query_params = array(
2666 2666
             $where,
2667 2667
             'order_by'   => array($orderby => $order),
2668
-            'limit'      => $limit . ',' . $per_page,
2668
+            'limit'      => $limit.','.$per_page,
2669 2669
             'force_join' => array('Term'),
2670 2670
         );
2671 2671
         $categories = $count
@@ -2687,7 +2687,7 @@  discard block
 block discarded – undo
2687 2687
         $timezone_string = isset($this->_req_data['timezone_selected'])
2688 2688
             ? $this->_req_data['timezone_selected']
2689 2689
             : '';
2690
-        if  (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2690
+        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2691 2691
         {
2692 2692
             EE_Error::add_error(
2693 2693
                 esc_html('An invalid timezone string submitted.', 'event_espresso'),
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3427 added lines, -3427 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
 
@@ -23,2113 +23,2113 @@  discard block
 block discarded – undo
23 23
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registration
28
-     */
29
-    private $_registration;
30
-
31
-    /**
32
-     * @var EE_Event
33
-     */
34
-    private $_reg_event;
35
-
36
-    /**
37
-     * @var EE_Session
38
-     */
39
-    private $_session;
40
-
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-
52
-    /**
53
-     *        constructor
54
-     *
55
-     * @Constructor
56
-     * @access public
57
-     * @param bool $routing
58
-     * @return Registrations_Admin_Page
59
-     */
60
-    public function __construct($routing = true)
61
-    {
62
-        parent::__construct($routing);
63
-        add_action('wp_loaded', array($this, 'wp_loaded'));
64
-    }
65
-
66
-
67
-    public function wp_loaded()
68
-    {
69
-        // when adding a new registration...
70
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
-            EE_System::do_not_cache();
72
-            if (! isset($this->_req_data['processing_registration'])
73
-                 || absint($this->_req_data['processing_registration']) !== 1
74
-            ) {
75
-                // and it's NOT the attendee information reg step
76
-                // force cookie expiration by setting time to last week
77
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
-                // and update the global
79
-                $_COOKIE['ee_registration_added'] = 0;
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-    protected function _init_page_props()
86
-    {
87
-        $this->page_slug        = REG_PG_SLUG;
88
-        $this->_admin_base_url  = REG_ADMIN_URL;
89
-        $this->_admin_base_path = REG_ADMIN;
90
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
91
-        $this->_cpt_routes      = array(
92
-            'add_new_attendee' => 'espresso_attendees',
93
-            'edit_attendee'    => 'espresso_attendees',
94
-            'insert_attendee'  => 'espresso_attendees',
95
-            'update_attendee'  => 'espresso_attendees',
96
-        );
97
-        $this->_cpt_model_names = array(
98
-            'add_new_attendee' => 'EEM_Attendee',
99
-            'edit_attendee'    => 'EEM_Attendee',
100
-        );
101
-        $this->_cpt_edit_routes = array(
102
-            'espresso_attendees' => 'edit_attendee',
103
-        );
104
-        $this->_pagenow_map     = array(
105
-            'add_new_attendee' => 'post-new.php',
106
-            'edit_attendee'    => 'post.php',
107
-            'trash'            => 'post.php',
108
-        );
109
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
-        //add filters so that the comment urls don't take users to a confusing 404 page
111
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
-    }
113
-
114
-
115
-    public function clear_comment_link($link, $comment, $args)
116
-    {
117
-        //gotta make sure this only happens on this route
118
-        $post_type = get_post_type($comment->comment_post_ID);
119
-        if ($post_type === 'espresso_attendees') {
120
-            return '#commentsdiv';
121
-        }
122
-        return $link;
123
-    }
124
-
125
-
126
-    protected function _ajax_hooks()
127
-    {
128
-        //todo: all hooks for registrations ajax goes in here
129
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
-    }
131
-
132
-
133
-    protected function _define_page_props()
134
-    {
135
-        $this->_admin_page_title = $this->page_label;
136
-        $this->_labels           = array(
137
-            'buttons'                      => array(
138
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
-            ),
147
-            'publishbox'                   => array(
148
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
-            ),
151
-            'hide_add_button_on_cpt_route' => array(
152
-                'edit_attendee' => true,
153
-            ),
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *        grab url requests and route them
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    public function _set_page_routes()
165
-    {
166
-        $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
-            ? $this->_req_data['_REG_ID'] : 0;
169
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
-            ? $this->_req_data['ATT_ID'] : 0;
171
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
172
-            ? $this->_req_data['post']
173
-            : $att_id;
174
-        $this->_page_routes = array(
175
-            'default'                            => array(
176
-                'func'       => '_registrations_overview_list_table',
177
-                'capability' => 'ee_read_registrations',
178
-            ),
179
-            'view_registration'                  => array(
180
-                'func'       => '_registration_details',
181
-                'capability' => 'ee_read_registration',
182
-                'obj_id'     => $reg_id,
183
-            ),
184
-            'edit_registration'                  => array(
185
-                'func'               => '_update_attendee_registration_form',
186
-                'noheader'           => true,
187
-                'headers_sent_route' => 'view_registration',
188
-                'capability'         => 'ee_edit_registration',
189
-                'obj_id'             => $reg_id,
190
-                '_REG_ID'            => $reg_id,
191
-            ),
192
-            'trash_registrations'                => array(
193
-                'func'       => '_trash_or_restore_registrations',
194
-                'args'       => array('trash' => true),
195
-                'noheader'   => true,
196
-                'capability' => 'ee_delete_registrations',
197
-            ),
198
-            'restore_registrations'              => array(
199
-                'func'       => '_trash_or_restore_registrations',
200
-                'args'       => array('trash' => false),
201
-                'noheader'   => true,
202
-                'capability' => 'ee_delete_registrations',
203
-            ),
204
-            'delete_registrations'               => array(
205
-                'func'       => '_delete_registrations',
206
-                'noheader'   => true,
207
-                'capability' => 'ee_delete_registrations',
208
-            ),
209
-            'new_registration'                   => array(
210
-                'func'       => 'new_registration',
211
-                'capability' => 'ee_edit_registrations',
212
-            ),
213
-            'process_reg_step'                   => array(
214
-                'func'       => 'process_reg_step',
215
-                'noheader'   => true,
216
-                'capability' => 'ee_edit_registrations',
217
-            ),
218
-            'redirect_to_txn'                    => array(
219
-                'func'       => 'redirect_to_txn',
220
-                'noheader'   => true,
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'change_reg_status'                  => array(
224
-                'func'       => '_change_reg_status',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registration',
227
-                'obj_id'     => $reg_id,
228
-            ),
229
-            'approve_registration'               => array(
230
-                'func'       => 'approve_registration',
231
-                'noheader'   => true,
232
-                'capability' => 'ee_edit_registration',
233
-                'obj_id'     => $reg_id,
234
-            ),
235
-            'approve_and_notify_registration'    => array(
236
-                'func'       => 'approve_registration',
237
-                'noheader'   => true,
238
-                'args'       => array(true),
239
-                'capability' => 'ee_edit_registration',
240
-                'obj_id'     => $reg_id,
241
-            ),
242
-            'decline_registration'               => array(
243
-                'func'       => 'decline_registration',
244
-                'noheader'   => true,
245
-                'capability' => 'ee_edit_registration',
246
-                'obj_id'     => $reg_id,
247
-            ),
248
-            'decline_and_notify_registration'    => array(
249
-                'func'       => 'decline_registration',
250
-                'noheader'   => true,
251
-                'args'       => array(true),
252
-                'capability' => 'ee_edit_registration',
253
-                'obj_id'     => $reg_id,
254
-            ),
255
-            'pending_registration'               => array(
256
-                'func'       => 'pending_registration',
257
-                'noheader'   => true,
258
-                'capability' => 'ee_edit_registration',
259
-                'obj_id'     => $reg_id,
260
-            ),
261
-            'pending_and_notify_registration'    => array(
262
-                'func'       => 'pending_registration',
263
-                'noheader'   => true,
264
-                'args'       => array(true),
265
-                'capability' => 'ee_edit_registration',
266
-                'obj_id'     => $reg_id,
267
-            ),
268
-            'no_approve_registration'            => array(
269
-                'func'       => 'not_approve_registration',
270
-                'noheader'   => true,
271
-                'capability' => 'ee_edit_registration',
272
-                'obj_id'     => $reg_id,
273
-            ),
274
-            'no_approve_and_notify_registration' => array(
275
-                'func'       => 'not_approve_registration',
276
-                'noheader'   => true,
277
-                'args'       => array(true),
278
-                'capability' => 'ee_edit_registration',
279
-                'obj_id'     => $reg_id,
280
-            ),
281
-            'cancel_registration'                => array(
282
-                'func'       => 'cancel_registration',
283
-                'noheader'   => true,
284
-                'capability' => 'ee_edit_registration',
285
-                'obj_id'     => $reg_id,
286
-            ),
287
-            'cancel_and_notify_registration'     => array(
288
-                'func'       => 'cancel_registration',
289
-                'noheader'   => true,
290
-                'args'       => array(true),
291
-                'capability' => 'ee_edit_registration',
292
-                'obj_id'     => $reg_id,
293
-            ),
294
-            'wait_list_registration' => array(
295
-                'func'       => 'wait_list_registration',
296
-                'noheader'   => true,
297
-                'capability' => 'ee_edit_registration',
298
-                'obj_id'     => $reg_id,
299
-            ),
300
-            'contact_list'                       => array(
301
-                'func'       => '_attendee_contact_list_table',
302
-                'capability' => 'ee_read_contacts',
303
-            ),
304
-            'add_new_attendee'                   => array(
305
-                'func' => '_create_new_cpt_item',
306
-                'args' => array(
307
-                    'new_attendee' => true,
308
-                    'capability'   => 'ee_edit_contacts',
309
-                ),
310
-            ),
311
-            'edit_attendee'                      => array(
312
-                'func'       => '_edit_cpt_item',
313
-                'capability' => 'ee_edit_contacts',
314
-                'obj_id'     => $att_id,
315
-            ),
316
-            'duplicate_attendee'                 => array(
317
-                'func'       => '_duplicate_attendee',
318
-                'noheader'   => true,
319
-                'capability' => 'ee_edit_contacts',
320
-                'obj_id'     => $att_id,
321
-            ),
322
-            'insert_attendee'                    => array(
323
-                'func'       => '_insert_or_update_attendee',
324
-                'args'       => array(
325
-                    'new_attendee' => true,
326
-                ),
327
-                'noheader'   => true,
328
-                'capability' => 'ee_edit_contacts',
329
-            ),
330
-            'update_attendee'                    => array(
331
-                'func'       => '_insert_or_update_attendee',
332
-                'args'       => array(
333
-                    'new_attendee' => false,
334
-                ),
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_contacts',
337
-                'obj_id'     => $att_id,
338
-            ),
339
-            'trash_attendee'                    => array(
340
-                'func'       => '_trash_or_restore_attendees',
341
-                'args'       => array(
342
-                    'trash' => true,
343
-                ),
344
-                'noheader'   => true,
345
-                'capability' => 'ee_delete_contacts',
346
-                'obj_id'     => $att_id,
347
-            ),
348
-            'restore_attendees'                  => array(
349
-                'func'       => '_trash_or_restore_attendees',
350
-                'args'       => array(
351
-                    'trash' => false,
352
-                ),
353
-                'noheader'   => true,
354
-                'capability' => 'ee_delete_contacts',
355
-                'obj_id'     => $att_id,
356
-            ),
357
-            'resend_registration'                => array(
358
-                'func'       => '_resend_registration',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_send_message',
361
-            ),
362
-            'registrations_report'               => array(
363
-                'func'       => '_registrations_report',
364
-                'noheader'   => true,
365
-                'capability' => 'ee_read_registrations',
366
-            ),
367
-            'contact_list_export'                => array(
368
-                'func'       => '_contact_list_export',
369
-                'noheader'   => true,
370
-                'capability' => 'export',
371
-            ),
372
-            'contact_list_report'                => array(
373
-                'func'       => '_contact_list_report',
374
-                'noheader'   => true,
375
-                'capability' => 'ee_read_contacts',
376
-            ),
377
-        );
378
-    }
379
-
380
-
381
-    protected function _set_page_config()
382
-    {
383
-        $this->_page_config = array(
384
-            'default'           => array(
385
-                'nav'           => array(
386
-                    'label' => esc_html__('Overview', 'event_espresso'),
387
-                    'order' => 5,
388
-                ),
389
-                'help_tabs'     => array(
390
-                    'registrations_overview_help_tab'                       => array(
391
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
392
-                        'filename' => 'registrations_overview',
393
-                    ),
394
-                    'registrations_overview_table_column_headings_help_tab' => array(
395
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
396
-                        'filename' => 'registrations_overview_table_column_headings',
397
-                    ),
398
-                    'registrations_overview_filters_help_tab'               => array(
399
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
400
-                        'filename' => 'registrations_overview_filters',
401
-                    ),
402
-                    'registrations_overview_views_help_tab'                 => array(
403
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
404
-                        'filename' => 'registrations_overview_views',
405
-                    ),
406
-                    'registrations_regoverview_other_help_tab'              => array(
407
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
408
-                        'filename' => 'registrations_overview_other',
409
-                    ),
410
-                ),
411
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
412
-                'qtips'         => array('Registration_List_Table_Tips'),
413
-                'list_table'    => 'EE_Registrations_List_Table',
414
-                'require_nonce' => false,
415
-            ),
416
-            'view_registration' => array(
417
-                'nav'           => array(
418
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
419
-                    'order'      => 15,
420
-                    'url'        => isset($this->_req_data['_REG_ID'])
421
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
422
-                        : $this->_admin_base_url,
423
-                    'persistent' => false,
424
-                ),
425
-                'help_tabs'     => array(
426
-                    'registrations_details_help_tab'                    => array(
427
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
428
-                        'filename' => 'registrations_details',
429
-                    ),
430
-                    'registrations_details_table_help_tab'              => array(
431
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
432
-                        'filename' => 'registrations_details_table',
433
-                    ),
434
-                    'registrations_details_form_answers_help_tab'       => array(
435
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
436
-                        'filename' => 'registrations_details_form_answers',
437
-                    ),
438
-                    'registrations_details_registrant_details_help_tab' => array(
439
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
440
-                        'filename' => 'registrations_details_registrant_details',
441
-                    ),
442
-                ),
443
-                'help_tour'     => array('Registration_Details_Help_Tour'),
444
-                'metaboxes'     => array_merge(
445
-                    $this->_default_espresso_metaboxes,
446
-                    array('_registration_details_metaboxes')
447
-                ),
448
-                'require_nonce' => false,
449
-            ),
450
-            'new_registration'  => array(
451
-                'nav'           => array(
452
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
453
-                    'url'        => '#',
454
-                    'order'      => 15,
455
-                    'persistent' => false,
456
-                ),
457
-                'metaboxes'     => $this->_default_espresso_metaboxes,
458
-                'labels'        => array(
459
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
460
-                ),
461
-                'require_nonce' => false,
462
-            ),
463
-            'add_new_attendee'  => array(
464
-                'nav'           => array(
465
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
466
-                    'order'      => 15,
467
-                    'persistent' => false,
468
-                ),
469
-                'metaboxes'     => array_merge(
470
-                    $this->_default_espresso_metaboxes,
471
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
472
-                ),
473
-                'require_nonce' => false,
474
-            ),
475
-            'edit_attendee'     => array(
476
-                'nav'           => array(
477
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
478
-                    'order'      => 15,
479
-                    'persistent' => false,
480
-                    'url'        => isset($this->_req_data['ATT_ID'])
481
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
482
-                        : $this->_admin_base_url,
483
-                ),
484
-                'metaboxes'     => array('attendee_editor_metaboxes'),
485
-                'require_nonce' => false,
486
-            ),
487
-            'contact_list'      => array(
488
-                'nav'           => array(
489
-                    'label' => esc_html__('Contact List', 'event_espresso'),
490
-                    'order' => 20,
491
-                ),
492
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
493
-                'help_tabs'     => array(
494
-                    'registrations_contact_list_help_tab'                       => array(
495
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
496
-                        'filename' => 'registrations_contact_list',
497
-                    ),
498
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
499
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
500
-                        'filename' => 'registrations_contact_list_table_column_headings',
501
-                    ),
502
-                    'registrations_contact_list_views_help_tab'                 => array(
503
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
504
-                        'filename' => 'registrations_contact_list_views',
505
-                    ),
506
-                    'registrations_contact_list_other_help_tab'                 => array(
507
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
508
-                        'filename' => 'registrations_contact_list_other',
509
-                    ),
510
-                ),
511
-                'help_tour'     => array('Contact_List_Help_Tour'),
512
-                'metaboxes'     => array(),
513
-                'require_nonce' => false,
514
-            ),
515
-            //override default cpt routes
516
-            'create_new'        => '',
517
-            'edit'              => '',
518
-        );
519
-    }
520
-
521
-
522
-    /**
523
-     * The below methods aren't used by this class currently
524
-     */
525
-    protected function _add_screen_options()
526
-    {
527
-    }
528
-
529
-
530
-    protected function _add_feature_pointers()
531
-    {
532
-    }
533
-
534
-
535
-    public function admin_init()
536
-    {
537
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
538
-            'click "Update Registration Questions" to save your changes',
539
-            'event_espresso'
540
-        );
541
-    }
542
-
543
-
544
-    public function admin_notices()
545
-    {
546
-    }
547
-
548
-
549
-    public function admin_footer_scripts()
550
-    {
551
-    }
552
-
553
-
554
-    /**
555
-     *        get list of registration statuses
556
-     *
557
-     * @access private
558
-     * @return void
559
-     */
560
-    private function _get_registration_status_array()
561
-    {
562
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
563
-    }
564
-
565
-
566
-    protected function _add_screen_options_default()
567
-    {
568
-        $this->_per_page_screen_option();
569
-    }
570
-
571
-
572
-    protected function _add_screen_options_contact_list()
573
-    {
574
-        $page_title              = $this->_admin_page_title;
575
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
576
-        $this->_per_page_screen_option();
577
-        $this->_admin_page_title = $page_title;
578
-    }
579
-
580
-
581
-    public function load_scripts_styles()
582
-    {
583
-        //style
584
-        wp_register_style(
585
-            'espresso_reg',
586
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
587
-            array('ee-admin-css'),
588
-            EVENT_ESPRESSO_VERSION
589
-        );
590
-        wp_enqueue_style('espresso_reg');
591
-        //script
592
-        wp_register_script(
593
-            'espresso_reg',
594
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
595
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
596
-            EVENT_ESPRESSO_VERSION,
597
-            true
598
-        );
599
-        wp_enqueue_script('espresso_reg');
600
-    }
601
-
602
-
603
-    public function load_scripts_styles_edit_attendee()
604
-    {
605
-        //stuff to only show up on our attendee edit details page.
606
-        $attendee_details_translations = array(
607
-            'att_publish_text' => sprintf(
608
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
609
-                $this->_cpt_model_obj->get_datetime('ATT_created')
610
-            ),
611
-        );
612
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
613
-        wp_enqueue_script('jquery-validate');
614
-    }
615
-
616
-
617
-    public function load_scripts_styles_view_registration()
618
-    {
619
-        //styles
620
-        wp_enqueue_style('espresso-ui-theme');
621
-        //scripts
622
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
623
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
624
-    }
625
-
626
-
627
-    public function load_scripts_styles_contact_list()
628
-    {
629
-        wp_deregister_style('espresso_reg');
630
-        wp_register_style(
631
-            'espresso_att',
632
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
633
-            array('ee-admin-css'),
634
-            EVENT_ESPRESSO_VERSION
635
-        );
636
-        wp_enqueue_style('espresso_att');
637
-    }
638
-
639
-
640
-    public function load_scripts_styles_new_registration()
641
-    {
642
-        wp_register_script(
643
-            'ee-spco-for-admin',
644
-            REG_ASSETS_URL . 'spco_for_admin.js',
645
-            array('underscore', 'jquery'),
646
-            EVENT_ESPRESSO_VERSION,
647
-            true
648
-        );
649
-        wp_enqueue_script('ee-spco-for-admin');
650
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
651
-        EE_Form_Section_Proper::wp_enqueue_scripts();
652
-        EED_Ticket_Selector::load_tckt_slctr_assets();
653
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
654
-    }
655
-
656
-
657
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
658
-    {
659
-        add_filter('FHEE_load_EE_messages', '__return_true');
660
-    }
661
-
662
-
663
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
664
-    {
665
-        add_filter('FHEE_load_EE_messages', '__return_true');
666
-    }
667
-
668
-
669
-    protected function _set_list_table_views_default()
670
-    {
671
-        //for notification related bulk actions we need to make sure only active messengers have an option.
672
-        EED_Messages::set_autoloaders();
673
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
674
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
675
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
676
-        //key= bulk_action_slug, value= message type.
677
-        $match_array = array(
678
-            'approve_registration'    => 'registration',
679
-            'decline_registration'    => 'declined_registration',
680
-            'pending_registration'    => 'pending_approval',
681
-            'no_approve_registration' => 'not_approved_registration',
682
-            'cancel_registration'     => 'cancelled_registration',
683
-        );
684
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
685
-            'ee_send_message',
686
-            'batch_send_messages'
687
-        );
688
-        /** setup reg status bulk actions **/
689
-        $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
690
-        if ($can_send && in_array($match_array['approve_registration'], $active_mts, true)) {
691
-                $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
692
-                    'event_espresso');
693
-        }
694
-        $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
695
-        if ($can_send && in_array($match_array['decline_registration'], $active_mts, true)) {
696
-                $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
697
-                    'event_espresso');
698
-        }
699
-        $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
700
-        if ($can_send && in_array($match_array['pending_registration'], $active_mts, true)) {
701
-                $def_reg_status_actions['pending_and_notify_registration'] = __(
702
-                    'Set Registrations to Pending Payment and Notify',
703
-                    'event_espresso'
704
-                );
705
-        }
706
-        $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
707
-        if ($can_send && in_array($match_array['no_approve_registration'], $active_mts, true)) {
708
-                $def_reg_status_actions['no_approve_and_notify_registration'] = __(
709
-                    'Set Registrations to Not Approved and Notify',
710
-                    'event_espresso'
711
-                );
712
-        }
713
-        $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
714
-        if ($can_send && in_array($match_array['cancel_registration'], $active_mts, true)) {
715
-                $def_reg_status_actions['cancel_and_notify_registration'] = __(
716
-                    'Cancel Registrations and Notify',
717
-                    'event_espresso'
718
-                );
719
-        }
720
-        $def_reg_status_actions = apply_filters(
721
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
722
-            $def_reg_status_actions,
723
-            $active_mts
724
-        );
725
-
726
-        $this->_views = array(
727
-            'all'   => array(
728
-                'slug'        => 'all',
729
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
730
-                'count'       => 0,
731
-                'bulk_action' => array_merge($def_reg_status_actions, array(
732
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
733
-                )),
734
-            ),
735
-            'month' => array(
736
-                'slug'        => 'month',
737
-                'label'       => esc_html__('This Month', 'event_espresso'),
738
-                'count'       => 0,
739
-                'bulk_action' => array_merge($def_reg_status_actions, array(
740
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
741
-                )),
742
-            ),
743
-            'today' => array(
744
-                'slug'        => 'today',
745
-                'label'       => sprintf(
746
-                    esc_html__('Today - %s', 'event_espresso'),
747
-                    date('M d, Y', current_time('timestamp'))
748
-                ),
749
-                'count'       => 0,
750
-                'bulk_action' => array_merge($def_reg_status_actions, array(
751
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
752
-                )),
753
-            ),
754
-        );
755
-        if (EE_Registry::instance()->CAP->current_user_can(
756
-            'ee_delete_registrations',
757
-            'espresso_registrations_delete_registration'
758
-        )) {
759
-            $this->_views['incomplete'] = array(
760
-                'slug'        => 'incomplete',
761
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
762
-                'count'       => 0,
763
-                'bulk_action' => array(
764
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
765
-                ),
766
-            );
767
-            $this->_views['trash']      = array(
768
-                'slug'        => 'trash',
769
-                'label'       => esc_html__('Trash', 'event_espresso'),
770
-                'count'       => 0,
771
-                'bulk_action' => array(
772
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
773
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
774
-                ),
775
-            );
776
-        }
777
-    }
778
-
779
-
780
-    protected function _set_list_table_views_contact_list()
781
-    {
782
-        $this->_views = array(
783
-            'in_use' => array(
784
-                'slug'        => 'in_use',
785
-                'label'       => esc_html__('In Use', 'event_espresso'),
786
-                'count'       => 0,
787
-                'bulk_action' => array(
788
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
789
-                ),
790
-            ),
791
-        );
792
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
793
-            'espresso_registrations_trash_attendees')
794
-        ) {
795
-            $this->_views['trash'] = array(
796
-                'slug'        => 'trash',
797
-                'label'       => esc_html__('Trash', 'event_espresso'),
798
-                'count'       => 0,
799
-                'bulk_action' => array(
800
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
801
-                ),
802
-            );
803
-        }
804
-    }
805
-
806
-
807
-    protected function _registration_legend_items()
808
-    {
809
-        $fc_items = array(
810
-            'star-icon'        => array(
811
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
812
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
813
-            ),
814
-            'view_details'     => array(
815
-                'class' => 'dashicons dashicons-clipboard',
816
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
817
-            ),
818
-            'edit_attendee'    => array(
819
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
820
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
821
-            ),
822
-            'view_transaction' => array(
823
-                'class' => 'dashicons dashicons-cart',
824
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
825
-            ),
826
-            'view_invoice'     => array(
827
-                'class' => 'dashicons dashicons-media-spreadsheet',
828
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
829
-            ),
830
-        );
831
-        if (EE_Registry::instance()->CAP->current_user_can(
832
-            'ee_send_message',
833
-            'espresso_registrations_resend_registration'
834
-        )) {
835
-            $fc_items['resend_registration'] = array(
836
-                'class' => 'dashicons dashicons-email-alt',
837
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
838
-            );
839
-        } else {
840
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
841
-        }
842
-        if (EE_Registry::instance()->CAP->current_user_can(
843
-            'ee_read_global_messages',
844
-            'view_filtered_messages'
845
-        )) {
846
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
847
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
848
-                $fc_items['view_related_messages'] = array(
849
-                    'class' => $related_for_icon['css_class'],
850
-                    'desc'  => $related_for_icon['label'],
851
-                );
852
-            }
853
-        }
854
-        $sc_items = array(
855
-            'approved_status'   => array(
856
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
857
-                'desc'  => EEH_Template::pretty_status(
858
-                    EEM_Registration::status_id_approved,
859
-                    false,
860
-                    'sentence'
861
-                ),
862
-            ),
863
-            'pending_status'    => array(
864
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
865
-                'desc'  => EEH_Template::pretty_status(
866
-                    EEM_Registration::status_id_pending_payment,
867
-                    false,
868
-                    'sentence'
869
-                ),
870
-            ),
871
-            'wait_list'         => array(
872
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
873
-                'desc'  => EEH_Template::pretty_status(
874
-                    EEM_Registration::status_id_wait_list,
875
-                    false,
876
-                    'sentence'
877
-                ),
878
-            ),
879
-            'incomplete_status' => array(
880
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
881
-                'desc'  => EEH_Template::pretty_status(
882
-                    EEM_Registration::status_id_incomplete,
883
-                    false,
884
-                    'sentence'
885
-                ),
886
-            ),
887
-            'not_approved'      => array(
888
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
889
-                'desc'  => EEH_Template::pretty_status(
890
-                    EEM_Registration::status_id_not_approved,
891
-                    false,
892
-                    'sentence'
893
-                ),
894
-            ),
895
-            'declined_status'   => array(
896
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
897
-                'desc'  => EEH_Template::pretty_status(
898
-                    EEM_Registration::status_id_declined,
899
-                    false,
900
-                    'sentence'
901
-                ),
902
-            ),
903
-            'cancelled_status'  => array(
904
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
905
-                'desc'  => EEH_Template::pretty_status(
906
-                    EEM_Registration::status_id_cancelled,
907
-                    false,
908
-                    'sentence'
909
-                ),
910
-            ),
911
-        );
912
-        return array_merge($fc_items, $sc_items);
913
-    }
914
-
915
-
916
-
917
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
918
-    /**
919
-     * @throws \EE_Error
920
-     */
921
-    protected function _registrations_overview_list_table()
922
-    {
923
-        $this->_template_args['admin_page_header'] = '';
924
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
925
-            ? absint($this->_req_data['event_id'])
926
-            : 0;
927
-        if ($EVT_ID) {
928
-            if (EE_Registry::instance()->CAP->current_user_can(
929
-                'ee_edit_registrations',
930
-                'espresso_registrations_new_registration',
931
-                $EVT_ID
932
-            )) {
933
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
934
-                    'new_registration',
935
-                    'add-registrant',
936
-                    array('event_id' => $EVT_ID),
937
-                    'add-new-h2'
938
-                );
939
-            }
940
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
941
-            if ($event instanceof EE_Event) {
942
-                $this->_template_args['admin_page_header'] = sprintf(
943
-                    esc_html__(
944
-                        '%s Viewing registrations for the event: %s%s',
945
-                        'event_espresso'
946
-                    ),
947
-                    '<h3 style="line-height:1.5em;">',
948
-                    '<br /><a href="'
949
-                        . EE_Admin_Page::add_query_args_and_nonce(
950
-                            array(
951
-                                'action' => 'edit',
952
-                                'post'   => $event->ID(),
953
-                            ),
954
-                            EVENTS_ADMIN_URL
955
-                        )
956
-                        . '">&nbsp;'
957
-                        . $event->get('EVT_name')
958
-                        . '&nbsp;</a>&nbsp;',
959
-                    '</h3>'
960
-                );
961
-            }
962
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
963
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
964
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
965
-                $this->_template_args['admin_page_header'] = substr(
966
-                    $this->_template_args['admin_page_header'],
967
-                    0,
968
-                    -5
969
-                );
970
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
971
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
972
-                $this->_template_args['admin_page_header'] .= $datetime->name();
973
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
974
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
975
-            }
976
-        }
977
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
978
-        $this->display_admin_list_table_page_with_no_sidebar();
979
-    }
980
-
981
-
982
-    /**
983
-     * This sets the _registration property for the registration details screen
984
-     *
985
-     * @access private
986
-     * @return bool
987
-     */
988
-    private function _set_registration_object()
989
-    {
990
-        //get out if we've already set the object
991
-        if (is_object($this->_registration)) {
992
-            return true;
993
-        }
994
-        $REG    = EEM_Registration::instance();
995
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
996
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
997
-            return true;
998
-        } else {
999
-            $error_msg = sprintf(
1000
-                esc_html__(
1001
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1002
-                    'event_espresso'
1003
-                ),
1004
-                $REG_ID
1005
-            );
1006
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1007
-            $this->_registration = null;
1008
-            return false;
1009
-        }
1010
-    }
1011
-
1012
-
1013
-    /**
1014
-     * Used to retrieve registrations for the list table.
1015
-     *
1016
-     * @param int  $per_page
1017
-     * @param bool $count
1018
-     * @param bool $this_month
1019
-     * @param bool $today
1020
-     * @return EE_Registration[]|int
1021
-     * @throws EE_Error
1022
-     */
1023
-    public function get_registrations(
1024
-        $per_page = 10,
1025
-        $count = false,
1026
-        $this_month = false,
1027
-        $today = false
1028
-    ) {
1029
-        if ($this_month) {
1030
-            $this->_req_data['status'] = 'month';
1031
-        }
1032
-        if ($today) {
1033
-            $this->_req_data['status'] = 'today';
1034
-        }
1035
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1036
-        /**
1037
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1038
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1039
-         * @see EEM_Base::get_all()
1040
-         */
1041
-        $query_params['group_by'] = '';
1042
-
1043
-        return $count
1044
-            ? EEM_Registration::instance()->count($query_params)
1045
-            /** @type EE_Registration[] */
1046
-            : EEM_Registration::instance()->get_all($query_params);
1047
-    }
1048
-
1049
-
1050
-
1051
-    /**
1052
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1053
-     * Note: this listens to values on the request for some of the query parameters.
1054
-     *
1055
-     * @param array $request
1056
-     * @param int    $per_page
1057
-     * @param bool   $count
1058
-     * @return array
1059
-     */
1060
-    protected function _get_registration_query_parameters(
1061
-        $request = array(),
1062
-        $per_page = 10,
1063
-        $count = false
1064
-    ) {
1065
-
1066
-        $query_params = array(
1067
-            0                          => $this->_get_where_conditions_for_registrations_query(
1068
-                $request
1069
-            ),
1070
-            'caps'                     => EEM_Registration::caps_read_admin,
1071
-            'default_where_conditions' => 'this_model_only',
1072
-        );
1073
-        if (! $count) {
1074
-            $query_params = array_merge(
1075
-                $query_params,
1076
-                $this->_get_orderby_for_registrations_query(),
1077
-                $this->_get_limit($per_page)
1078
-            );
1079
-        }
1080
-
1081
-        return $query_params;
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1087
-     *
1088
-     * @param array $request usually the same as $this->_req_data but not necessarily
1089
-     * @return array
1090
-     */
1091
-    protected function _add_event_id_to_where_conditions(array $request)
1092
-    {
1093
-        $where = array();
1094
-        if (! empty($request['event_id'])) {
1095
-            $where['EVT_ID'] = absint($request['event_id']);
1096
-        }
1097
-        return $where;
1098
-    }
1099
-
1100
-
1101
-    /**
1102
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1103
-     *
1104
-     * @param array $request usually the same as $this->_req_data but not necessarily
1105
-     * @return array
1106
-     */
1107
-    protected function _add_category_id_to_where_conditions(array $request)
1108
-    {
1109
-        $where = array();
1110
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1111
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1112
-        }
1113
-        return $where;
1114
-    }
1115
-
1116
-
1117
-    /**
1118
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1119
-     *
1120
-     * @param array $request usually the same as $this->_req_data but not necessarily
1121
-     * @return array
1122
-     */
1123
-    protected function _add_datetime_id_to_where_conditions(array $request)
1124
-    {
1125
-        $where = array();
1126
-        if (! empty($request['datetime_id'])) {
1127
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1128
-        }
1129
-        if (! empty($request['DTT_ID'])) {
1130
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1131
-        }
1132
-        return $where;
1133
-    }
1134
-
1135
-
1136
-    /**
1137
-     * Adds the correct registration status to the where conditions for the registrations query.
1138
-     *
1139
-     * @param array $request usually the same as $this->_req_data but not necessarily
1140
-     * @return array
1141
-     */
1142
-    protected function _add_registration_status_to_where_conditions(array $request)
1143
-    {
1144
-        $where = array();
1145
-        $view = EEH_Array::is_set($request, 'status', '');
1146
-        $registration_status = ! empty($request['_reg_status'])
1147
-            ? sanitize_text_field($request['_reg_status'])
1148
-            : '';
1149
-
1150
-        /*
26
+	/**
27
+	 * @var EE_Registration
28
+	 */
29
+	private $_registration;
30
+
31
+	/**
32
+	 * @var EE_Event
33
+	 */
34
+	private $_reg_event;
35
+
36
+	/**
37
+	 * @var EE_Session
38
+	 */
39
+	private $_session;
40
+
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+
52
+	/**
53
+	 *        constructor
54
+	 *
55
+	 * @Constructor
56
+	 * @access public
57
+	 * @param bool $routing
58
+	 * @return Registrations_Admin_Page
59
+	 */
60
+	public function __construct($routing = true)
61
+	{
62
+		parent::__construct($routing);
63
+		add_action('wp_loaded', array($this, 'wp_loaded'));
64
+	}
65
+
66
+
67
+	public function wp_loaded()
68
+	{
69
+		// when adding a new registration...
70
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
+			EE_System::do_not_cache();
72
+			if (! isset($this->_req_data['processing_registration'])
73
+				 || absint($this->_req_data['processing_registration']) !== 1
74
+			) {
75
+				// and it's NOT the attendee information reg step
76
+				// force cookie expiration by setting time to last week
77
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
+				// and update the global
79
+				$_COOKIE['ee_registration_added'] = 0;
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+	protected function _init_page_props()
86
+	{
87
+		$this->page_slug        = REG_PG_SLUG;
88
+		$this->_admin_base_url  = REG_ADMIN_URL;
89
+		$this->_admin_base_path = REG_ADMIN;
90
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
91
+		$this->_cpt_routes      = array(
92
+			'add_new_attendee' => 'espresso_attendees',
93
+			'edit_attendee'    => 'espresso_attendees',
94
+			'insert_attendee'  => 'espresso_attendees',
95
+			'update_attendee'  => 'espresso_attendees',
96
+		);
97
+		$this->_cpt_model_names = array(
98
+			'add_new_attendee' => 'EEM_Attendee',
99
+			'edit_attendee'    => 'EEM_Attendee',
100
+		);
101
+		$this->_cpt_edit_routes = array(
102
+			'espresso_attendees' => 'edit_attendee',
103
+		);
104
+		$this->_pagenow_map     = array(
105
+			'add_new_attendee' => 'post-new.php',
106
+			'edit_attendee'    => 'post.php',
107
+			'trash'            => 'post.php',
108
+		);
109
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
+		//add filters so that the comment urls don't take users to a confusing 404 page
111
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
+	}
113
+
114
+
115
+	public function clear_comment_link($link, $comment, $args)
116
+	{
117
+		//gotta make sure this only happens on this route
118
+		$post_type = get_post_type($comment->comment_post_ID);
119
+		if ($post_type === 'espresso_attendees') {
120
+			return '#commentsdiv';
121
+		}
122
+		return $link;
123
+	}
124
+
125
+
126
+	protected function _ajax_hooks()
127
+	{
128
+		//todo: all hooks for registrations ajax goes in here
129
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
+	}
131
+
132
+
133
+	protected function _define_page_props()
134
+	{
135
+		$this->_admin_page_title = $this->page_label;
136
+		$this->_labels           = array(
137
+			'buttons'                      => array(
138
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
+			),
147
+			'publishbox'                   => array(
148
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
+			),
151
+			'hide_add_button_on_cpt_route' => array(
152
+				'edit_attendee' => true,
153
+			),
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *        grab url requests and route them
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	public function _set_page_routes()
165
+	{
166
+		$this->_get_registration_status_array();
167
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
+			? $this->_req_data['_REG_ID'] : 0;
169
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
+			? $this->_req_data['ATT_ID'] : 0;
171
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
172
+			? $this->_req_data['post']
173
+			: $att_id;
174
+		$this->_page_routes = array(
175
+			'default'                            => array(
176
+				'func'       => '_registrations_overview_list_table',
177
+				'capability' => 'ee_read_registrations',
178
+			),
179
+			'view_registration'                  => array(
180
+				'func'       => '_registration_details',
181
+				'capability' => 'ee_read_registration',
182
+				'obj_id'     => $reg_id,
183
+			),
184
+			'edit_registration'                  => array(
185
+				'func'               => '_update_attendee_registration_form',
186
+				'noheader'           => true,
187
+				'headers_sent_route' => 'view_registration',
188
+				'capability'         => 'ee_edit_registration',
189
+				'obj_id'             => $reg_id,
190
+				'_REG_ID'            => $reg_id,
191
+			),
192
+			'trash_registrations'                => array(
193
+				'func'       => '_trash_or_restore_registrations',
194
+				'args'       => array('trash' => true),
195
+				'noheader'   => true,
196
+				'capability' => 'ee_delete_registrations',
197
+			),
198
+			'restore_registrations'              => array(
199
+				'func'       => '_trash_or_restore_registrations',
200
+				'args'       => array('trash' => false),
201
+				'noheader'   => true,
202
+				'capability' => 'ee_delete_registrations',
203
+			),
204
+			'delete_registrations'               => array(
205
+				'func'       => '_delete_registrations',
206
+				'noheader'   => true,
207
+				'capability' => 'ee_delete_registrations',
208
+			),
209
+			'new_registration'                   => array(
210
+				'func'       => 'new_registration',
211
+				'capability' => 'ee_edit_registrations',
212
+			),
213
+			'process_reg_step'                   => array(
214
+				'func'       => 'process_reg_step',
215
+				'noheader'   => true,
216
+				'capability' => 'ee_edit_registrations',
217
+			),
218
+			'redirect_to_txn'                    => array(
219
+				'func'       => 'redirect_to_txn',
220
+				'noheader'   => true,
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'change_reg_status'                  => array(
224
+				'func'       => '_change_reg_status',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registration',
227
+				'obj_id'     => $reg_id,
228
+			),
229
+			'approve_registration'               => array(
230
+				'func'       => 'approve_registration',
231
+				'noheader'   => true,
232
+				'capability' => 'ee_edit_registration',
233
+				'obj_id'     => $reg_id,
234
+			),
235
+			'approve_and_notify_registration'    => array(
236
+				'func'       => 'approve_registration',
237
+				'noheader'   => true,
238
+				'args'       => array(true),
239
+				'capability' => 'ee_edit_registration',
240
+				'obj_id'     => $reg_id,
241
+			),
242
+			'decline_registration'               => array(
243
+				'func'       => 'decline_registration',
244
+				'noheader'   => true,
245
+				'capability' => 'ee_edit_registration',
246
+				'obj_id'     => $reg_id,
247
+			),
248
+			'decline_and_notify_registration'    => array(
249
+				'func'       => 'decline_registration',
250
+				'noheader'   => true,
251
+				'args'       => array(true),
252
+				'capability' => 'ee_edit_registration',
253
+				'obj_id'     => $reg_id,
254
+			),
255
+			'pending_registration'               => array(
256
+				'func'       => 'pending_registration',
257
+				'noheader'   => true,
258
+				'capability' => 'ee_edit_registration',
259
+				'obj_id'     => $reg_id,
260
+			),
261
+			'pending_and_notify_registration'    => array(
262
+				'func'       => 'pending_registration',
263
+				'noheader'   => true,
264
+				'args'       => array(true),
265
+				'capability' => 'ee_edit_registration',
266
+				'obj_id'     => $reg_id,
267
+			),
268
+			'no_approve_registration'            => array(
269
+				'func'       => 'not_approve_registration',
270
+				'noheader'   => true,
271
+				'capability' => 'ee_edit_registration',
272
+				'obj_id'     => $reg_id,
273
+			),
274
+			'no_approve_and_notify_registration' => array(
275
+				'func'       => 'not_approve_registration',
276
+				'noheader'   => true,
277
+				'args'       => array(true),
278
+				'capability' => 'ee_edit_registration',
279
+				'obj_id'     => $reg_id,
280
+			),
281
+			'cancel_registration'                => array(
282
+				'func'       => 'cancel_registration',
283
+				'noheader'   => true,
284
+				'capability' => 'ee_edit_registration',
285
+				'obj_id'     => $reg_id,
286
+			),
287
+			'cancel_and_notify_registration'     => array(
288
+				'func'       => 'cancel_registration',
289
+				'noheader'   => true,
290
+				'args'       => array(true),
291
+				'capability' => 'ee_edit_registration',
292
+				'obj_id'     => $reg_id,
293
+			),
294
+			'wait_list_registration' => array(
295
+				'func'       => 'wait_list_registration',
296
+				'noheader'   => true,
297
+				'capability' => 'ee_edit_registration',
298
+				'obj_id'     => $reg_id,
299
+			),
300
+			'contact_list'                       => array(
301
+				'func'       => '_attendee_contact_list_table',
302
+				'capability' => 'ee_read_contacts',
303
+			),
304
+			'add_new_attendee'                   => array(
305
+				'func' => '_create_new_cpt_item',
306
+				'args' => array(
307
+					'new_attendee' => true,
308
+					'capability'   => 'ee_edit_contacts',
309
+				),
310
+			),
311
+			'edit_attendee'                      => array(
312
+				'func'       => '_edit_cpt_item',
313
+				'capability' => 'ee_edit_contacts',
314
+				'obj_id'     => $att_id,
315
+			),
316
+			'duplicate_attendee'                 => array(
317
+				'func'       => '_duplicate_attendee',
318
+				'noheader'   => true,
319
+				'capability' => 'ee_edit_contacts',
320
+				'obj_id'     => $att_id,
321
+			),
322
+			'insert_attendee'                    => array(
323
+				'func'       => '_insert_or_update_attendee',
324
+				'args'       => array(
325
+					'new_attendee' => true,
326
+				),
327
+				'noheader'   => true,
328
+				'capability' => 'ee_edit_contacts',
329
+			),
330
+			'update_attendee'                    => array(
331
+				'func'       => '_insert_or_update_attendee',
332
+				'args'       => array(
333
+					'new_attendee' => false,
334
+				),
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_contacts',
337
+				'obj_id'     => $att_id,
338
+			),
339
+			'trash_attendee'                    => array(
340
+				'func'       => '_trash_or_restore_attendees',
341
+				'args'       => array(
342
+					'trash' => true,
343
+				),
344
+				'noheader'   => true,
345
+				'capability' => 'ee_delete_contacts',
346
+				'obj_id'     => $att_id,
347
+			),
348
+			'restore_attendees'                  => array(
349
+				'func'       => '_trash_or_restore_attendees',
350
+				'args'       => array(
351
+					'trash' => false,
352
+				),
353
+				'noheader'   => true,
354
+				'capability' => 'ee_delete_contacts',
355
+				'obj_id'     => $att_id,
356
+			),
357
+			'resend_registration'                => array(
358
+				'func'       => '_resend_registration',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_send_message',
361
+			),
362
+			'registrations_report'               => array(
363
+				'func'       => '_registrations_report',
364
+				'noheader'   => true,
365
+				'capability' => 'ee_read_registrations',
366
+			),
367
+			'contact_list_export'                => array(
368
+				'func'       => '_contact_list_export',
369
+				'noheader'   => true,
370
+				'capability' => 'export',
371
+			),
372
+			'contact_list_report'                => array(
373
+				'func'       => '_contact_list_report',
374
+				'noheader'   => true,
375
+				'capability' => 'ee_read_contacts',
376
+			),
377
+		);
378
+	}
379
+
380
+
381
+	protected function _set_page_config()
382
+	{
383
+		$this->_page_config = array(
384
+			'default'           => array(
385
+				'nav'           => array(
386
+					'label' => esc_html__('Overview', 'event_espresso'),
387
+					'order' => 5,
388
+				),
389
+				'help_tabs'     => array(
390
+					'registrations_overview_help_tab'                       => array(
391
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
392
+						'filename' => 'registrations_overview',
393
+					),
394
+					'registrations_overview_table_column_headings_help_tab' => array(
395
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
396
+						'filename' => 'registrations_overview_table_column_headings',
397
+					),
398
+					'registrations_overview_filters_help_tab'               => array(
399
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
400
+						'filename' => 'registrations_overview_filters',
401
+					),
402
+					'registrations_overview_views_help_tab'                 => array(
403
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
404
+						'filename' => 'registrations_overview_views',
405
+					),
406
+					'registrations_regoverview_other_help_tab'              => array(
407
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
408
+						'filename' => 'registrations_overview_other',
409
+					),
410
+				),
411
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
412
+				'qtips'         => array('Registration_List_Table_Tips'),
413
+				'list_table'    => 'EE_Registrations_List_Table',
414
+				'require_nonce' => false,
415
+			),
416
+			'view_registration' => array(
417
+				'nav'           => array(
418
+					'label'      => esc_html__('REG Details', 'event_espresso'),
419
+					'order'      => 15,
420
+					'url'        => isset($this->_req_data['_REG_ID'])
421
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
422
+						: $this->_admin_base_url,
423
+					'persistent' => false,
424
+				),
425
+				'help_tabs'     => array(
426
+					'registrations_details_help_tab'                    => array(
427
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
428
+						'filename' => 'registrations_details',
429
+					),
430
+					'registrations_details_table_help_tab'              => array(
431
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
432
+						'filename' => 'registrations_details_table',
433
+					),
434
+					'registrations_details_form_answers_help_tab'       => array(
435
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
436
+						'filename' => 'registrations_details_form_answers',
437
+					),
438
+					'registrations_details_registrant_details_help_tab' => array(
439
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
440
+						'filename' => 'registrations_details_registrant_details',
441
+					),
442
+				),
443
+				'help_tour'     => array('Registration_Details_Help_Tour'),
444
+				'metaboxes'     => array_merge(
445
+					$this->_default_espresso_metaboxes,
446
+					array('_registration_details_metaboxes')
447
+				),
448
+				'require_nonce' => false,
449
+			),
450
+			'new_registration'  => array(
451
+				'nav'           => array(
452
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
453
+					'url'        => '#',
454
+					'order'      => 15,
455
+					'persistent' => false,
456
+				),
457
+				'metaboxes'     => $this->_default_espresso_metaboxes,
458
+				'labels'        => array(
459
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
460
+				),
461
+				'require_nonce' => false,
462
+			),
463
+			'add_new_attendee'  => array(
464
+				'nav'           => array(
465
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
466
+					'order'      => 15,
467
+					'persistent' => false,
468
+				),
469
+				'metaboxes'     => array_merge(
470
+					$this->_default_espresso_metaboxes,
471
+					array('_publish_post_box', 'attendee_editor_metaboxes')
472
+				),
473
+				'require_nonce' => false,
474
+			),
475
+			'edit_attendee'     => array(
476
+				'nav'           => array(
477
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
478
+					'order'      => 15,
479
+					'persistent' => false,
480
+					'url'        => isset($this->_req_data['ATT_ID'])
481
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
482
+						: $this->_admin_base_url,
483
+				),
484
+				'metaboxes'     => array('attendee_editor_metaboxes'),
485
+				'require_nonce' => false,
486
+			),
487
+			'contact_list'      => array(
488
+				'nav'           => array(
489
+					'label' => esc_html__('Contact List', 'event_espresso'),
490
+					'order' => 20,
491
+				),
492
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
493
+				'help_tabs'     => array(
494
+					'registrations_contact_list_help_tab'                       => array(
495
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
496
+						'filename' => 'registrations_contact_list',
497
+					),
498
+					'registrations_contact-list_table_column_headings_help_tab' => array(
499
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
500
+						'filename' => 'registrations_contact_list_table_column_headings',
501
+					),
502
+					'registrations_contact_list_views_help_tab'                 => array(
503
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
504
+						'filename' => 'registrations_contact_list_views',
505
+					),
506
+					'registrations_contact_list_other_help_tab'                 => array(
507
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
508
+						'filename' => 'registrations_contact_list_other',
509
+					),
510
+				),
511
+				'help_tour'     => array('Contact_List_Help_Tour'),
512
+				'metaboxes'     => array(),
513
+				'require_nonce' => false,
514
+			),
515
+			//override default cpt routes
516
+			'create_new'        => '',
517
+			'edit'              => '',
518
+		);
519
+	}
520
+
521
+
522
+	/**
523
+	 * The below methods aren't used by this class currently
524
+	 */
525
+	protected function _add_screen_options()
526
+	{
527
+	}
528
+
529
+
530
+	protected function _add_feature_pointers()
531
+	{
532
+	}
533
+
534
+
535
+	public function admin_init()
536
+	{
537
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
538
+			'click "Update Registration Questions" to save your changes',
539
+			'event_espresso'
540
+		);
541
+	}
542
+
543
+
544
+	public function admin_notices()
545
+	{
546
+	}
547
+
548
+
549
+	public function admin_footer_scripts()
550
+	{
551
+	}
552
+
553
+
554
+	/**
555
+	 *        get list of registration statuses
556
+	 *
557
+	 * @access private
558
+	 * @return void
559
+	 */
560
+	private function _get_registration_status_array()
561
+	{
562
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
563
+	}
564
+
565
+
566
+	protected function _add_screen_options_default()
567
+	{
568
+		$this->_per_page_screen_option();
569
+	}
570
+
571
+
572
+	protected function _add_screen_options_contact_list()
573
+	{
574
+		$page_title              = $this->_admin_page_title;
575
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
576
+		$this->_per_page_screen_option();
577
+		$this->_admin_page_title = $page_title;
578
+	}
579
+
580
+
581
+	public function load_scripts_styles()
582
+	{
583
+		//style
584
+		wp_register_style(
585
+			'espresso_reg',
586
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
587
+			array('ee-admin-css'),
588
+			EVENT_ESPRESSO_VERSION
589
+		);
590
+		wp_enqueue_style('espresso_reg');
591
+		//script
592
+		wp_register_script(
593
+			'espresso_reg',
594
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
595
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
596
+			EVENT_ESPRESSO_VERSION,
597
+			true
598
+		);
599
+		wp_enqueue_script('espresso_reg');
600
+	}
601
+
602
+
603
+	public function load_scripts_styles_edit_attendee()
604
+	{
605
+		//stuff to only show up on our attendee edit details page.
606
+		$attendee_details_translations = array(
607
+			'att_publish_text' => sprintf(
608
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
609
+				$this->_cpt_model_obj->get_datetime('ATT_created')
610
+			),
611
+		);
612
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
613
+		wp_enqueue_script('jquery-validate');
614
+	}
615
+
616
+
617
+	public function load_scripts_styles_view_registration()
618
+	{
619
+		//styles
620
+		wp_enqueue_style('espresso-ui-theme');
621
+		//scripts
622
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
623
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
624
+	}
625
+
626
+
627
+	public function load_scripts_styles_contact_list()
628
+	{
629
+		wp_deregister_style('espresso_reg');
630
+		wp_register_style(
631
+			'espresso_att',
632
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
633
+			array('ee-admin-css'),
634
+			EVENT_ESPRESSO_VERSION
635
+		);
636
+		wp_enqueue_style('espresso_att');
637
+	}
638
+
639
+
640
+	public function load_scripts_styles_new_registration()
641
+	{
642
+		wp_register_script(
643
+			'ee-spco-for-admin',
644
+			REG_ASSETS_URL . 'spco_for_admin.js',
645
+			array('underscore', 'jquery'),
646
+			EVENT_ESPRESSO_VERSION,
647
+			true
648
+		);
649
+		wp_enqueue_script('ee-spco-for-admin');
650
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
651
+		EE_Form_Section_Proper::wp_enqueue_scripts();
652
+		EED_Ticket_Selector::load_tckt_slctr_assets();
653
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
654
+	}
655
+
656
+
657
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
658
+	{
659
+		add_filter('FHEE_load_EE_messages', '__return_true');
660
+	}
661
+
662
+
663
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
664
+	{
665
+		add_filter('FHEE_load_EE_messages', '__return_true');
666
+	}
667
+
668
+
669
+	protected function _set_list_table_views_default()
670
+	{
671
+		//for notification related bulk actions we need to make sure only active messengers have an option.
672
+		EED_Messages::set_autoloaders();
673
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
674
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
675
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
676
+		//key= bulk_action_slug, value= message type.
677
+		$match_array = array(
678
+			'approve_registration'    => 'registration',
679
+			'decline_registration'    => 'declined_registration',
680
+			'pending_registration'    => 'pending_approval',
681
+			'no_approve_registration' => 'not_approved_registration',
682
+			'cancel_registration'     => 'cancelled_registration',
683
+		);
684
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
685
+			'ee_send_message',
686
+			'batch_send_messages'
687
+		);
688
+		/** setup reg status bulk actions **/
689
+		$def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
690
+		if ($can_send && in_array($match_array['approve_registration'], $active_mts, true)) {
691
+				$def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
692
+					'event_espresso');
693
+		}
694
+		$def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
695
+		if ($can_send && in_array($match_array['decline_registration'], $active_mts, true)) {
696
+				$def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
697
+					'event_espresso');
698
+		}
699
+		$def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
700
+		if ($can_send && in_array($match_array['pending_registration'], $active_mts, true)) {
701
+				$def_reg_status_actions['pending_and_notify_registration'] = __(
702
+					'Set Registrations to Pending Payment and Notify',
703
+					'event_espresso'
704
+				);
705
+		}
706
+		$def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
707
+		if ($can_send && in_array($match_array['no_approve_registration'], $active_mts, true)) {
708
+				$def_reg_status_actions['no_approve_and_notify_registration'] = __(
709
+					'Set Registrations to Not Approved and Notify',
710
+					'event_espresso'
711
+				);
712
+		}
713
+		$def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
714
+		if ($can_send && in_array($match_array['cancel_registration'], $active_mts, true)) {
715
+				$def_reg_status_actions['cancel_and_notify_registration'] = __(
716
+					'Cancel Registrations and Notify',
717
+					'event_espresso'
718
+				);
719
+		}
720
+		$def_reg_status_actions = apply_filters(
721
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
722
+			$def_reg_status_actions,
723
+			$active_mts
724
+		);
725
+
726
+		$this->_views = array(
727
+			'all'   => array(
728
+				'slug'        => 'all',
729
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
730
+				'count'       => 0,
731
+				'bulk_action' => array_merge($def_reg_status_actions, array(
732
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
733
+				)),
734
+			),
735
+			'month' => array(
736
+				'slug'        => 'month',
737
+				'label'       => esc_html__('This Month', 'event_espresso'),
738
+				'count'       => 0,
739
+				'bulk_action' => array_merge($def_reg_status_actions, array(
740
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
741
+				)),
742
+			),
743
+			'today' => array(
744
+				'slug'        => 'today',
745
+				'label'       => sprintf(
746
+					esc_html__('Today - %s', 'event_espresso'),
747
+					date('M d, Y', current_time('timestamp'))
748
+				),
749
+				'count'       => 0,
750
+				'bulk_action' => array_merge($def_reg_status_actions, array(
751
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
752
+				)),
753
+			),
754
+		);
755
+		if (EE_Registry::instance()->CAP->current_user_can(
756
+			'ee_delete_registrations',
757
+			'espresso_registrations_delete_registration'
758
+		)) {
759
+			$this->_views['incomplete'] = array(
760
+				'slug'        => 'incomplete',
761
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
762
+				'count'       => 0,
763
+				'bulk_action' => array(
764
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
765
+				),
766
+			);
767
+			$this->_views['trash']      = array(
768
+				'slug'        => 'trash',
769
+				'label'       => esc_html__('Trash', 'event_espresso'),
770
+				'count'       => 0,
771
+				'bulk_action' => array(
772
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
773
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
774
+				),
775
+			);
776
+		}
777
+	}
778
+
779
+
780
+	protected function _set_list_table_views_contact_list()
781
+	{
782
+		$this->_views = array(
783
+			'in_use' => array(
784
+				'slug'        => 'in_use',
785
+				'label'       => esc_html__('In Use', 'event_espresso'),
786
+				'count'       => 0,
787
+				'bulk_action' => array(
788
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
789
+				),
790
+			),
791
+		);
792
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
793
+			'espresso_registrations_trash_attendees')
794
+		) {
795
+			$this->_views['trash'] = array(
796
+				'slug'        => 'trash',
797
+				'label'       => esc_html__('Trash', 'event_espresso'),
798
+				'count'       => 0,
799
+				'bulk_action' => array(
800
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
801
+				),
802
+			);
803
+		}
804
+	}
805
+
806
+
807
+	protected function _registration_legend_items()
808
+	{
809
+		$fc_items = array(
810
+			'star-icon'        => array(
811
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
812
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
813
+			),
814
+			'view_details'     => array(
815
+				'class' => 'dashicons dashicons-clipboard',
816
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
817
+			),
818
+			'edit_attendee'    => array(
819
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
820
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
821
+			),
822
+			'view_transaction' => array(
823
+				'class' => 'dashicons dashicons-cart',
824
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
825
+			),
826
+			'view_invoice'     => array(
827
+				'class' => 'dashicons dashicons-media-spreadsheet',
828
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
829
+			),
830
+		);
831
+		if (EE_Registry::instance()->CAP->current_user_can(
832
+			'ee_send_message',
833
+			'espresso_registrations_resend_registration'
834
+		)) {
835
+			$fc_items['resend_registration'] = array(
836
+				'class' => 'dashicons dashicons-email-alt',
837
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
838
+			);
839
+		} else {
840
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
841
+		}
842
+		if (EE_Registry::instance()->CAP->current_user_can(
843
+			'ee_read_global_messages',
844
+			'view_filtered_messages'
845
+		)) {
846
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
847
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
848
+				$fc_items['view_related_messages'] = array(
849
+					'class' => $related_for_icon['css_class'],
850
+					'desc'  => $related_for_icon['label'],
851
+				);
852
+			}
853
+		}
854
+		$sc_items = array(
855
+			'approved_status'   => array(
856
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
857
+				'desc'  => EEH_Template::pretty_status(
858
+					EEM_Registration::status_id_approved,
859
+					false,
860
+					'sentence'
861
+				),
862
+			),
863
+			'pending_status'    => array(
864
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
865
+				'desc'  => EEH_Template::pretty_status(
866
+					EEM_Registration::status_id_pending_payment,
867
+					false,
868
+					'sentence'
869
+				),
870
+			),
871
+			'wait_list'         => array(
872
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
873
+				'desc'  => EEH_Template::pretty_status(
874
+					EEM_Registration::status_id_wait_list,
875
+					false,
876
+					'sentence'
877
+				),
878
+			),
879
+			'incomplete_status' => array(
880
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
881
+				'desc'  => EEH_Template::pretty_status(
882
+					EEM_Registration::status_id_incomplete,
883
+					false,
884
+					'sentence'
885
+				),
886
+			),
887
+			'not_approved'      => array(
888
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
889
+				'desc'  => EEH_Template::pretty_status(
890
+					EEM_Registration::status_id_not_approved,
891
+					false,
892
+					'sentence'
893
+				),
894
+			),
895
+			'declined_status'   => array(
896
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
897
+				'desc'  => EEH_Template::pretty_status(
898
+					EEM_Registration::status_id_declined,
899
+					false,
900
+					'sentence'
901
+				),
902
+			),
903
+			'cancelled_status'  => array(
904
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
905
+				'desc'  => EEH_Template::pretty_status(
906
+					EEM_Registration::status_id_cancelled,
907
+					false,
908
+					'sentence'
909
+				),
910
+			),
911
+		);
912
+		return array_merge($fc_items, $sc_items);
913
+	}
914
+
915
+
916
+
917
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
918
+	/**
919
+	 * @throws \EE_Error
920
+	 */
921
+	protected function _registrations_overview_list_table()
922
+	{
923
+		$this->_template_args['admin_page_header'] = '';
924
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
925
+			? absint($this->_req_data['event_id'])
926
+			: 0;
927
+		if ($EVT_ID) {
928
+			if (EE_Registry::instance()->CAP->current_user_can(
929
+				'ee_edit_registrations',
930
+				'espresso_registrations_new_registration',
931
+				$EVT_ID
932
+			)) {
933
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
934
+					'new_registration',
935
+					'add-registrant',
936
+					array('event_id' => $EVT_ID),
937
+					'add-new-h2'
938
+				);
939
+			}
940
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
941
+			if ($event instanceof EE_Event) {
942
+				$this->_template_args['admin_page_header'] = sprintf(
943
+					esc_html__(
944
+						'%s Viewing registrations for the event: %s%s',
945
+						'event_espresso'
946
+					),
947
+					'<h3 style="line-height:1.5em;">',
948
+					'<br /><a href="'
949
+						. EE_Admin_Page::add_query_args_and_nonce(
950
+							array(
951
+								'action' => 'edit',
952
+								'post'   => $event->ID(),
953
+							),
954
+							EVENTS_ADMIN_URL
955
+						)
956
+						. '">&nbsp;'
957
+						. $event->get('EVT_name')
958
+						. '&nbsp;</a>&nbsp;',
959
+					'</h3>'
960
+				);
961
+			}
962
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
963
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
964
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
965
+				$this->_template_args['admin_page_header'] = substr(
966
+					$this->_template_args['admin_page_header'],
967
+					0,
968
+					-5
969
+				);
970
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
971
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
972
+				$this->_template_args['admin_page_header'] .= $datetime->name();
973
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
974
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
975
+			}
976
+		}
977
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
978
+		$this->display_admin_list_table_page_with_no_sidebar();
979
+	}
980
+
981
+
982
+	/**
983
+	 * This sets the _registration property for the registration details screen
984
+	 *
985
+	 * @access private
986
+	 * @return bool
987
+	 */
988
+	private function _set_registration_object()
989
+	{
990
+		//get out if we've already set the object
991
+		if (is_object($this->_registration)) {
992
+			return true;
993
+		}
994
+		$REG    = EEM_Registration::instance();
995
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
996
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
997
+			return true;
998
+		} else {
999
+			$error_msg = sprintf(
1000
+				esc_html__(
1001
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1002
+					'event_espresso'
1003
+				),
1004
+				$REG_ID
1005
+			);
1006
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1007
+			$this->_registration = null;
1008
+			return false;
1009
+		}
1010
+	}
1011
+
1012
+
1013
+	/**
1014
+	 * Used to retrieve registrations for the list table.
1015
+	 *
1016
+	 * @param int  $per_page
1017
+	 * @param bool $count
1018
+	 * @param bool $this_month
1019
+	 * @param bool $today
1020
+	 * @return EE_Registration[]|int
1021
+	 * @throws EE_Error
1022
+	 */
1023
+	public function get_registrations(
1024
+		$per_page = 10,
1025
+		$count = false,
1026
+		$this_month = false,
1027
+		$today = false
1028
+	) {
1029
+		if ($this_month) {
1030
+			$this->_req_data['status'] = 'month';
1031
+		}
1032
+		if ($today) {
1033
+			$this->_req_data['status'] = 'today';
1034
+		}
1035
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1036
+		/**
1037
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1038
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1039
+		 * @see EEM_Base::get_all()
1040
+		 */
1041
+		$query_params['group_by'] = '';
1042
+
1043
+		return $count
1044
+			? EEM_Registration::instance()->count($query_params)
1045
+			/** @type EE_Registration[] */
1046
+			: EEM_Registration::instance()->get_all($query_params);
1047
+	}
1048
+
1049
+
1050
+
1051
+	/**
1052
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1053
+	 * Note: this listens to values on the request for some of the query parameters.
1054
+	 *
1055
+	 * @param array $request
1056
+	 * @param int    $per_page
1057
+	 * @param bool   $count
1058
+	 * @return array
1059
+	 */
1060
+	protected function _get_registration_query_parameters(
1061
+		$request = array(),
1062
+		$per_page = 10,
1063
+		$count = false
1064
+	) {
1065
+
1066
+		$query_params = array(
1067
+			0                          => $this->_get_where_conditions_for_registrations_query(
1068
+				$request
1069
+			),
1070
+			'caps'                     => EEM_Registration::caps_read_admin,
1071
+			'default_where_conditions' => 'this_model_only',
1072
+		);
1073
+		if (! $count) {
1074
+			$query_params = array_merge(
1075
+				$query_params,
1076
+				$this->_get_orderby_for_registrations_query(),
1077
+				$this->_get_limit($per_page)
1078
+			);
1079
+		}
1080
+
1081
+		return $query_params;
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1087
+	 *
1088
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1089
+	 * @return array
1090
+	 */
1091
+	protected function _add_event_id_to_where_conditions(array $request)
1092
+	{
1093
+		$where = array();
1094
+		if (! empty($request['event_id'])) {
1095
+			$where['EVT_ID'] = absint($request['event_id']);
1096
+		}
1097
+		return $where;
1098
+	}
1099
+
1100
+
1101
+	/**
1102
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1103
+	 *
1104
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1105
+	 * @return array
1106
+	 */
1107
+	protected function _add_category_id_to_where_conditions(array $request)
1108
+	{
1109
+		$where = array();
1110
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1111
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1112
+		}
1113
+		return $where;
1114
+	}
1115
+
1116
+
1117
+	/**
1118
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1119
+	 *
1120
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1121
+	 * @return array
1122
+	 */
1123
+	protected function _add_datetime_id_to_where_conditions(array $request)
1124
+	{
1125
+		$where = array();
1126
+		if (! empty($request['datetime_id'])) {
1127
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1128
+		}
1129
+		if (! empty($request['DTT_ID'])) {
1130
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1131
+		}
1132
+		return $where;
1133
+	}
1134
+
1135
+
1136
+	/**
1137
+	 * Adds the correct registration status to the where conditions for the registrations query.
1138
+	 *
1139
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1140
+	 * @return array
1141
+	 */
1142
+	protected function _add_registration_status_to_where_conditions(array $request)
1143
+	{
1144
+		$where = array();
1145
+		$view = EEH_Array::is_set($request, 'status', '');
1146
+		$registration_status = ! empty($request['_reg_status'])
1147
+			? sanitize_text_field($request['_reg_status'])
1148
+			: '';
1149
+
1150
+		/*
1151 1151
          * If filtering by registration status, then we show registrations matching that status.
1152 1152
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1153 1153
          * UNLESS viewing trashed registrations.
1154 1154
          */
1155
-        if (! empty($registration_status)) {
1156
-            $where['STS_ID'] = $registration_status;
1157
-        } else {
1158
-            //make sure we exclude incomplete registrations, but only if not trashed.
1159
-            if ($view === 'trash') {
1160
-                $where['REG_deleted'] = true;
1161
-            } elseif ($view === 'incomplete') {
1162
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1163
-            } else {
1164
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1165
-            }
1166
-        }
1167
-        return $where;
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * Adds any provided date restraints to the where conditions for the registrations query.
1173
-     *
1174
-     * @param array $request usually the same as $this->_req_data but not necessarily
1175
-     * @return array
1176
-     * @throws EE_Error
1177
-     */
1178
-    protected function _add_date_to_where_conditions(array $request)
1179
-    {
1180
-        $where = array();
1181
-        $view = EEH_Array::is_set($request, 'status', '');
1182
-        $month_range             = ! empty($request['month_range'])
1183
-            ? sanitize_text_field($request['month_range'])
1184
-            : '';
1185
-        $retrieve_for_today      = $view === 'today';
1186
-        $retrieve_for_this_month = $view === 'month';
1187
-
1188
-        if ($retrieve_for_today) {
1189
-            $now               = date('Y-m-d', current_time('timestamp'));
1190
-            $where['REG_date'] = array(
1191
-                'BETWEEN',
1192
-                array(
1193
-                    EEM_Registration::instance()->convert_datetime_for_query(
1194
-                        'REG_date',
1195
-                        $now . ' 00:00:00',
1196
-                        'Y-m-d H:i:s'
1197
-                    ),
1198
-                    EEM_Registration::instance()->convert_datetime_for_query(
1199
-                        'REG_date',
1200
-                        $now . ' 23:59:59',
1201
-                        'Y-m-d H:i:s'
1202
-                    ),
1203
-                ),
1204
-            );
1205
-        } elseif ($retrieve_for_this_month) {
1206
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1207
-            $days_this_month        = date('t', current_time('timestamp'));
1208
-            $where['REG_date']      = array(
1209
-                'BETWEEN',
1210
-                array(
1211
-                    EEM_Registration::instance()->convert_datetime_for_query(
1212
-                        'REG_date',
1213
-                        $current_year_and_month . '-01 00:00:00',
1214
-                        'Y-m-d H:i:s'
1215
-                    ),
1216
-                    EEM_Registration::instance()->convert_datetime_for_query(
1217
-                        'REG_date',
1218
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1219
-                        'Y-m-d H:i:s'
1220
-                    ),
1221
-                ),
1222
-            );
1223
-        } elseif ($month_range) {
1224
-            $pieces          = explode(' ', $month_range, 3);
1225
-            $month_requested = ! empty($pieces[0])
1226
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1227
-                : '';
1228
-            $year_requested  = ! empty($pieces[1])
1229
-                ? $pieces[1]
1230
-                : '';
1231
-            //if there is not a month or year then we can't go further
1232
-            if ($month_requested && $year_requested) {
1233
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1234
-                $where['REG_date'] = array(
1235
-                    'BETWEEN',
1236
-                    array(
1237
-                        EEM_Registration::instance()->convert_datetime_for_query(
1238
-                            'REG_date',
1239
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1240
-                            'Y-m-d H:i:s'
1241
-                        ),
1242
-                        EEM_Registration::instance()->convert_datetime_for_query(
1243
-                            'REG_date',
1244
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1245
-                            'Y-m-d H:i:s'
1246
-                        ),
1247
-                    ),
1248
-                );
1249
-            }
1250
-        }
1251
-        return $where;
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     * Adds any provided search restraints to the where conditions for the registrations query
1257
-     *
1258
-     * @param array $request usually the same as $this->_req_data but not necessarily
1259
-     * @return array
1260
-     */
1261
-    protected function _add_search_to_where_conditions(array $request)
1262
-    {
1263
-        $where = array();
1264
-        if (! empty($request['s'])) {
1265
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1266
-            $where['OR*search_conditions'] = array(
1267
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1268
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1269
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1270
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1271
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1272
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1273
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1274
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1275
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1276
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1277
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1278
-                'REG_final_price'                         => array('LIKE', $search_string),
1279
-                'REG_code'                                => array('LIKE', $search_string),
1280
-                'REG_count'                               => array('LIKE', $search_string),
1281
-                'REG_group_size'                          => array('LIKE', $search_string),
1282
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1283
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1284
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1285
-            );
1286
-        }
1287
-        return $where;
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * Sets up the where conditions for the registrations query.
1293
-     *
1294
-     * @param array $request
1295
-     * @return array
1296
-     * @throws EE_Error
1297
-     */
1298
-    protected function _get_where_conditions_for_registrations_query($request)
1299
-    {
1300
-        return apply_filters(
1301
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1302
-            array_merge(
1303
-                $this->_add_event_id_to_where_conditions($request),
1304
-                $this->_add_category_id_to_where_conditions($request),
1305
-                $this->_add_datetime_id_to_where_conditions($request),
1306
-                $this->_add_registration_status_to_where_conditions($request),
1307
-                $this->_add_date_to_where_conditions($request),
1308
-                $this->_add_search_to_where_conditions($request)
1309
-            ),
1310
-            $request
1311
-        );
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * Sets up the orderby for the registrations query.
1317
-     *
1318
-     * @return array
1319
-     */
1320
-    protected function _get_orderby_for_registrations_query()
1321
-    {
1322
-        $orderby_field = ! empty($this->_req_data['orderby'])
1323
-            ? sanitize_text_field($this->_req_data['orderby'])
1324
-            : '';
1325
-        switch ($orderby_field) {
1326
-            case '_REG_ID':
1327
-                $orderby_field = 'REG_ID';
1328
-                break;
1329
-            case '_Reg_status':
1330
-                $orderby_field = 'STS_ID';
1331
-                break;
1332
-            case 'ATT_fname':
1333
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1334
-                break;
1335
-            case 'ATT_lname':
1336
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1337
-                break;
1338
-            case 'event_name':
1339
-                $orderby_field = 'Event.EVT_name';
1340
-                break;
1341
-            case 'DTT_EVT_start':
1342
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1343
-                break;
1344
-            default: //'REG_date'
1345
-                $orderby_field = 'REG_date';
1346
-        }
1347
-
1348
-        //order
1349
-        $order = ! empty($this->_req_data['order'])
1350
-            ? sanitize_text_field($this->_req_data['order'])
1351
-            : 'DESC';
1352
-
1353
-        //mutate orderby_field
1354
-        $orderby_field = array_combine(
1355
-            (array) $orderby_field,
1356
-            array_fill(0, count($orderby_field), $order)
1357
-        );
1358
-        return array('order_by' => $orderby_field);
1359
-    }
1360
-
1361
-
1362
-    /**
1363
-     * Sets up the limit for the registrations query.
1364
-     *
1365
-     * @param $per_page
1366
-     * @return array
1367
-     */
1368
-    protected function _get_limit($per_page)
1369
-    {
1370
-        $current_page = ! empty($this->_req_data['paged'])
1371
-            ? absint($this->_req_data['paged'])
1372
-            : 1;
1373
-        $per_page     = ! empty($this->_req_data['perpage'])
1374
-            ? $this->_req_data['perpage']
1375
-            : $per_page;
1376
-
1377
-        //-1 means return all results so get out if that's set.
1378
-        if ((int)$per_page === -1) {
1379
-            return array();
1380
-        }
1381
-        $per_page = absint($per_page);
1382
-        $offset   = ($current_page - 1) * $per_page;
1383
-        return array('limit' => array($offset, $per_page));
1384
-    }
1385
-
1386
-
1387
-    public function get_registration_status_array()
1388
-    {
1389
-        return self::$_reg_status;
1390
-    }
1391
-
1392
-
1393
-
1394
-
1395
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1396
-    /**
1397
-     *        generates HTML for the View Registration Details Admin page
1398
-     *
1399
-     * @access protected
1400
-     * @return void
1401
-     * @throws DomainException
1402
-     * @throws EE_Error
1403
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1404
-     */
1405
-    protected function _registration_details()
1406
-    {
1407
-        $this->_template_args = array();
1408
-        $this->_set_registration_object();
1409
-        if (is_object($this->_registration)) {
1410
-            $transaction                                   = $this->_registration->transaction()
1411
-                ? $this->_registration->transaction()
1412
-                : EE_Transaction::new_instance();
1413
-            $this->_session                                = $transaction->session_data();
1414
-            $event_id                                      = $this->_registration->event_ID();
1415
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1416
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1417
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1418
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1419
-            $this->_template_args['grand_total']           = $transaction->total();
1420
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1421
-            // link back to overview
1422
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1423
-            $this->_template_args['registration']                = $this->_registration;
1424
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1425
-                array(
1426
-                    'action'   => 'default',
1427
-                    'event_id' => $event_id,
1428
-                ),
1429
-                REG_ADMIN_URL
1430
-            );
1431
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1432
-                array(
1433
-                    'action' => 'default',
1434
-                    'EVT_ID' => $event_id,
1435
-                    'page'   => 'espresso_transactions',
1436
-                ),
1437
-                admin_url('admin.php')
1438
-            );
1439
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1440
-                array(
1441
-                    'page'   => 'espresso_events',
1442
-                    'action' => 'edit',
1443
-                    'post'   => $event_id,
1444
-                ),
1445
-                admin_url('admin.php')
1446
-            );
1447
-            //next and previous links
1448
-            $next_reg                                      = $this->_registration->next(
1449
-                null,
1450
-                array(),
1451
-                'REG_ID'
1452
-            );
1453
-            $this->_template_args['next_registration']     = $next_reg
1454
-                ? $this->_next_link(
1455
-                    EE_Admin_Page::add_query_args_and_nonce(
1456
-                        array(
1457
-                            'action'  => 'view_registration',
1458
-                            '_REG_ID' => $next_reg['REG_ID'],
1459
-                        ),
1460
-                        REG_ADMIN_URL
1461
-                    ),
1462
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1463
-                )
1464
-                : '';
1465
-            $previous_reg                                  = $this->_registration->previous(
1466
-                null,
1467
-                array(),
1468
-                'REG_ID'
1469
-            );
1470
-            $this->_template_args['previous_registration'] = $previous_reg
1471
-                ? $this->_previous_link(
1472
-                    EE_Admin_Page::add_query_args_and_nonce(
1473
-                        array(
1474
-                            'action'  => 'view_registration',
1475
-                            '_REG_ID' => $previous_reg['REG_ID'],
1476
-                        ),
1477
-                        REG_ADMIN_URL
1478
-                    ),
1479
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1480
-                )
1481
-                : '';
1482
-            // grab header
1483
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1484
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1485
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1486
-                $template_path,
1487
-                $this->_template_args,
1488
-                true
1489
-            );
1490
-        } else {
1491
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1492
-        }
1493
-        // the details template wrapper
1494
-        $this->display_admin_page_with_sidebar();
1495
-    }
1496
-
1497
-
1498
-    protected function _registration_details_metaboxes()
1499
-    {
1500
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1501
-        $this->_set_registration_object();
1502
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1503
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1504
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1505
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1506
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1507
-        if ($attendee instanceof EE_Attendee
1508
-            && EE_Registry::instance()->CAP->current_user_can(
1509
-                'ee_edit_registration',
1510
-                'edit-reg-questions-mbox'
1511
-            )
1512
-        ) {
1513
-            add_meta_box(
1514
-                'edit-reg-questions-mbox',
1515
-                esc_html__('Registration Form Answers', 'event_espresso'),
1516
-                array($this, '_reg_questions_meta_box'),
1517
-                $this->wp_page_slug,
1518
-                'normal',
1519
-                'high'
1520
-            );
1521
-        }
1522
-        add_meta_box(
1523
-            'edit-reg-registrant-mbox',
1524
-            esc_html__('Contact Details', 'event_espresso'),
1525
-            array($this, '_reg_registrant_side_meta_box'),
1526
-            $this->wp_page_slug,
1527
-            'side',
1528
-            'high'
1529
-        );
1530
-        if ($this->_registration->group_size() > 1) {
1531
-            add_meta_box(
1532
-                'edit-reg-attendees-mbox',
1533
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1534
-                array($this, '_reg_attendees_meta_box'),
1535
-                $this->wp_page_slug,
1536
-                'normal',
1537
-                'high'
1538
-            );
1539
-        }
1540
-    }
1541
-
1542
-
1543
-    /**
1544
-     * set_reg_status_buttons_metabox
1545
-     *
1546
-     * @access protected
1547
-     * @return string
1548
-     * @throws \EE_Error
1549
-     */
1550
-    public function set_reg_status_buttons_metabox()
1551
-    {
1552
-        $this->_set_registration_object();
1553
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1554
-        echo $change_reg_status_form->form_open(
1555
-            self::add_query_args_and_nonce(
1556
-                array(
1557
-                    'action' => 'change_reg_status',
1558
-                ),
1559
-                REG_ADMIN_URL
1560
-            )
1561
-        );
1562
-        echo $change_reg_status_form->get_html();
1563
-        echo $change_reg_status_form->form_close();
1564
-    }
1565
-
1566
-
1567
-
1568
-    /**
1569
-     * @return EE_Form_Section_Proper
1570
-     * @throws EE_Error
1571
-     */
1572
-    protected function _generate_reg_status_change_form()
1573
-    {
1574
-        return new EE_Form_Section_Proper(array(
1575
-            'name'            => 'reg_status_change_form',
1576
-            'html_id'         => 'reg-status-change-form',
1577
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1578
-            'subsections'     => array(
1579
-                'return'             => new EE_Hidden_Input(array(
1580
-                    'name'    => 'return',
1581
-                    'default' => 'view_registration',
1582
-                )),
1583
-                'REG_ID'             => new EE_Hidden_Input(array(
1584
-                    'name'    => 'REG_ID',
1585
-                    'default' => $this->_registration->ID(),
1586
-                )),
1587
-                'current_status'     => new EE_Form_Section_HTML(
1588
-                    EEH_HTML::tr(
1589
-                        EEH_HTML::th(
1590
-                            EEH_HTML::label(
1591
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1592
-                                )
1593
-                            )
1594
-                        )
1595
-                        . EEH_HTML::td(
1596
-                            EEH_HTML::strong(
1597
-                                $this->_registration->pretty_status(),
1598
-                                '',
1599
-                                'status-' . $this->_registration->status_ID(),
1600
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1601
-                            )
1602
-                        )
1603
-                    )
1604
-                ),
1605
-                'reg_status'         => new EE_Select_Input(
1606
-                    $this->_get_reg_statuses(),
1607
-                    array(
1608
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1609
-                        'default'         => $this->_registration->status_ID(),
1610
-                    )
1611
-                ),
1612
-                'send_notifications' => new EE_Yes_No_Input(
1613
-                    array(
1614
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1615
-                        'default'         => false,
1616
-                        'html_help_text'  => esc_html__(
1617
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1618
-                            'event_espresso'
1619
-                        ),
1620
-                    )
1621
-                ),
1622
-                'submit'             => new EE_Submit_Input(
1623
-                    array(
1624
-                        'html_class'      => 'button-primary',
1625
-                        'html_label_text' => '&nbsp;',
1626
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1627
-                    )
1628
-                ),
1629
-            ),
1630
-        ));
1631
-    }
1632
-
1633
-
1634
-    /**
1635
-     * Returns an array of all the buttons for the various statuses and switch status actions
1636
-     *
1637
-     * @return array
1638
-     * @throws EE_Error
1639
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1640
-     */
1641
-    protected function _get_reg_statuses()
1642
-    {
1643
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1644
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1645
-        // get current reg status
1646
-        $current_status = $this->_registration->status_ID();
1647
-        // is registration for free event? This will determine whether to display the pending payment option
1648
-        if (
1649
-            $current_status !== EEM_Registration::status_id_pending_payment
1650
-            && $this->_registration->transaction()->is_free()
1651
-        ) {
1652
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1653
-        }
1654
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1655
-    }
1656
-
1657
-
1658
-
1659
-    /**
1660
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1661
-     *
1662
-     * @param bool $status REG status given for changing registrations to.
1663
-     * @param bool $notify Whether to send messages notifications or not.
1664
-     * @return array  (array with reg_id(s) updated and whether update was successful.
1665
-     * @throws \EE_Error
1666
-     */
1667
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1668
-    {
1669
-        if (isset($this->_req_data['reg_status_change_form'])) {
1670
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1671
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1672
-        } else {
1673
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1674
-        }
1675
-        $success = $this->_set_registration_status($REG_IDs, $status);
1676
-        //notify?
1677
-        if ($success
1678
-            && $notify
1679
-            && EE_Registry::instance()->CAP->current_user_can(
1680
-                'ee_send_message',
1681
-                'espresso_registrations_resend_registration'
1682
-            )
1683
-        ) {
1684
-            $this->_process_resend_registration();
1685
-        }
1686
-        return $success;
1687
-    }
1688
-
1689
-
1690
-
1691
-    /**
1692
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1693
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1694
-     *
1695
-     * @param array $REG_IDs
1696
-     * @param bool  $status
1697
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
-     * @throws \RuntimeException
1699
-     * @throws \EE_Error
1700
-     *               the array of updated registrations).
1701
-     * @throws EE_Error
1702
-     * @throws RuntimeException
1703
-     */
1704
-    protected function _set_registration_status($REG_IDs = array(), $status = false)
1705
-    {
1706
-        $success = false;
1707
-        // typecast $REG_IDs
1708
-        $REG_IDs = (array)$REG_IDs;
1709
-        if ( ! empty($REG_IDs)) {
1710
-            $success = true;
1711
-            // set default status if none is passed
1712
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1713
-            // sanitize $REG_IDs
1714
-            $REG_IDs = array_filter($REG_IDs, 'absint');
1715
-            //loop through REG_ID's and change status
1716
-            foreach ($REG_IDs as $REG_ID) {
1717
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1718
-                if ($registration instanceof EE_Registration) {
1719
-                    $registration->set_status($status);
1720
-                    $result = $registration->save();
1721
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1722
-                    $success = $result !== false ? $success : false;
1723
-                }
1724
-            }
1725
-        }
1726
-        //reset _req_data['_REG_ID'] for any potential future messages notifications
1727
-        $this->_req_data['_REG_ID'] = $REG_IDs;
1728
-        //return $success and processed registrations
1729
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1730
-    }
1731
-
1732
-
1733
-    /**
1734
-     * Common logic for setting up success message and redirecting to appropriate route
1735
-     *
1736
-     * @param  string $STS_ID status id for the registration changed to
1737
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1738
-     * @return void
1739
-     */
1740
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1741
-    {
1742
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1743
-            : array('success' => false);
1744
-        $success = isset($result['success']) && $result['success'];
1745
-        //setup success message
1746
-        if ($success) {
1747
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1748
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1749
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1750
-            } else {
1751
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1752
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1753
-            }
1754
-            EE_Error::add_success($msg);
1755
-        } else {
1756
-            EE_Error::add_error(
1757
-                esc_html__(
1758
-                    'Something went wrong, and the status was not changed',
1759
-                    'event_espresso'
1760
-                ), __FILE__, __LINE__, __FUNCTION__
1761
-            );
1762
-        }
1763
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1764
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1765
-        } else {
1766
-            $route = array('action' => 'default');
1767
-        }
1768
-        //unset nonces
1769
-        foreach ($this->_req_data as $ref => $value) {
1770
-            if (strpos($ref, 'nonce') !== false) {
1771
-                unset($this->_req_data[$ref]);
1772
-                continue;
1773
-            }
1774
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1775
-            $this->_req_data[$ref] = $value;
1776
-        }
1777
-        //merge request vars so that the reloaded list table contains any existing filter query params
1778
-        $route = array_merge($this->_req_data, $route);
1779
-        $this->_redirect_after_action($success, '', '', $route, true);
1780
-    }
1781
-
1782
-
1783
-    /**
1784
-     * incoming reg status change from reg details page.
1785
-     *
1786
-     * @return void
1787
-     */
1788
-    protected function _change_reg_status()
1789
-    {
1790
-        $this->_req_data['return'] = 'view_registration';
1791
-        //set notify based on whether the send notifications toggle is set or not
1792
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1793
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1794
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1795
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1796
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1797
-            case EEM_Registration::status_id_approved :
1798
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1799
-                $this->approve_registration($notify);
1800
-                break;
1801
-            case EEM_Registration::status_id_pending_payment :
1802
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1803
-                $this->pending_registration($notify);
1804
-                break;
1805
-            case EEM_Registration::status_id_not_approved :
1806
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1807
-                $this->not_approve_registration($notify);
1808
-                break;
1809
-            case EEM_Registration::status_id_declined :
1810
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1811
-                $this->decline_registration($notify);
1812
-                break;
1813
-            case EEM_Registration::status_id_cancelled :
1814
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1815
-                $this->cancel_registration($notify);
1816
-                break;
1817
-            case EEM_Registration::status_id_wait_list :
1818
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1819
-                $this->wait_list_registration($notify);
1820
-                break;
1821
-            case EEM_Registration::status_id_incomplete :
1822
-            default :
1823
-                $result['success'] = false;
1824
-                unset($this->_req_data['return']);
1825
-                $this->_reg_status_change_return('', false);
1826
-                break;
1827
-        }
1828
-    }
1829
-
1830
-
1831
-    /**
1832
-     * approve_registration
1833
-     *
1834
-     * @access protected
1835
-     * @param bool $notify whether or not to notify the registrant about their approval.
1836
-     * @return void
1837
-     */
1838
-    protected function approve_registration($notify = false)
1839
-    {
1840
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1841
-    }
1842
-
1843
-
1844
-    /**
1845
-     *        decline_registration
1846
-     *
1847
-     * @access protected
1848
-     * @param bool $notify whether or not to notify the registrant about their status change.
1849
-     * @return void
1850
-     */
1851
-    protected function decline_registration($notify = false)
1852
-    {
1853
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1854
-    }
1855
-
1856
-
1857
-    /**
1858
-     *        cancel_registration
1859
-     *
1860
-     * @access protected
1861
-     * @param bool $notify whether or not to notify the registrant about their status change.
1862
-     * @return void
1863
-     */
1864
-    protected function cancel_registration($notify = false)
1865
-    {
1866
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1867
-    }
1868
-
1869
-
1870
-    /**
1871
-     *        not_approve_registration
1872
-     *
1873
-     * @access protected
1874
-     * @param bool $notify whether or not to notify the registrant about their status change.
1875
-     * @return void
1876
-     */
1877
-    protected function not_approve_registration($notify = false)
1878
-    {
1879
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1880
-    }
1881
-
1882
-
1883
-    /**
1884
-     *        decline_registration
1885
-     *
1886
-     * @access protected
1887
-     * @param bool $notify whether or not to notify the registrant about their status change.
1888
-     * @return void
1889
-     */
1890
-    protected function pending_registration($notify = false)
1891
-    {
1892
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1893
-    }
1894
-
1895
-
1896
-    /**
1897
-     * waitlist_registration
1898
-     *
1899
-     * @access protected
1900
-     * @param bool $notify whether or not to notify the registrant about their status change.
1901
-     * @return void
1902
-     */
1903
-    protected function wait_list_registration($notify = false)
1904
-    {
1905
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1906
-    }
1907
-
1908
-
1909
-    /**
1910
-     *        generates HTML for the Registration main meta box
1911
-     *
1912
-     * @access public
1913
-     * @return void
1914
-     * @throws DomainException
1915
-     * @throws EE_Error
1916
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1917
-     */
1918
-    public function _reg_details_meta_box()
1919
-    {
1920
-        EEH_Autoloader::register_line_item_display_autoloaders();
1921
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1922
-        EE_Registry::instance()->load_helper('Line_Item');
1923
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1924
-            : EE_Transaction::new_instance();
1925
-        $this->_session = $transaction->session_data();
1926
-        $filters        = new EE_Line_Item_Filter_Collection();
1927
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1928
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1929
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1930
-            $transaction->total_line_item());
1931
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
1932
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1933
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1934
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
1935
-            $filtered_line_item_tree,
1936
-            array('EE_Registration' => $this->_registration)
1937
-        );
1938
-        $attendee                                = $this->_registration->attendee();
1939
-        if (EE_Registry::instance()->CAP->current_user_can(
1940
-            'ee_read_transaction',
1941
-            'espresso_transactions_view_transaction'
1942
-        )) {
1943
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
1944
-                EE_Admin_Page::add_query_args_and_nonce(
1945
-                    array(
1946
-                        'action' => 'view_transaction',
1947
-                        'TXN_ID' => $transaction->ID(),
1948
-                    ),
1949
-                    TXN_ADMIN_URL
1950
-                ),
1951
-                esc_html__(' View Transaction', 'event_espresso'),
1952
-                'button secondary-button right',
1953
-                'dashicons dashicons-cart'
1954
-            );
1955
-        } else {
1956
-            $this->_template_args['view_transaction_button'] = '';
1957
-        }
1958
-        if ($attendee instanceof EE_Attendee
1959
-            && EE_Registry::instance()->CAP->current_user_can(
1960
-                'ee_send_message',
1961
-                'espresso_registrations_resend_registration'
1962
-            )
1963
-        ) {
1964
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
1965
-                EE_Admin_Page::add_query_args_and_nonce(
1966
-                    array(
1967
-                        'action'      => 'resend_registration',
1968
-                        '_REG_ID'     => $this->_registration->ID(),
1969
-                        'redirect_to' => 'view_registration',
1970
-                    ),
1971
-                    REG_ADMIN_URL
1972
-                ),
1973
-                esc_html__(' Resend Registration', 'event_espresso'),
1974
-                'button secondary-button right',
1975
-                'dashicons dashicons-email-alt'
1976
-            );
1977
-        } else {
1978
-            $this->_template_args['resend_registration_button'] = '';
1979
-        }
1980
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1981
-        $payment                               = $transaction->get_first_related('Payment');
1982
-        $payment                               = ! $payment instanceof EE_Payment
1983
-            ? EE_Payment::new_instance()
1984
-            : $payment;
1985
-        $payment_method                        = $payment->get_first_related('Payment_Method');
1986
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
1987
-            ? EE_Payment_Method::new_instance()
1988
-            : $payment_method;
1989
-        $reg_details                           = array(
1990
-            'payment_method'       => $payment_method->name(),
1991
-            'response_msg'         => $payment->gateway_response(),
1992
-            'registration_id'      => $this->_registration->get('REG_code'),
1993
-            'registration_session' => $this->_registration->session_ID(),
1994
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1995
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1996
-        );
1997
-        if (isset($reg_details['registration_id'])) {
1998
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1999
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2000
-                'Registration ID',
2001
-                'event_espresso'
2002
-            );
2003
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2004
-        }
2005
-        if (isset($reg_details['payment_method'])) {
2006
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2007
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2008
-                'Most Recent Payment Method',
2009
-                'event_espresso'
2010
-            );
2011
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2012
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2013
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2014
-                'Payment method response',
2015
-                'event_espresso'
2016
-            );
2017
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2018
-        }
2019
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2020
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2021
-            'Registration Session',
2022
-            'event_espresso'
2023
-        );
2024
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2025
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2026
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2027
-            'Registration placed from IP',
2028
-            'event_espresso'
2029
-        );
2030
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2031
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2032
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2033
-            'event_espresso');
2034
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2035
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2036
-            array(
2037
-                'action'   => 'default',
2038
-                'event_id' => $this->_registration->event_ID(),
2039
-            ),
2040
-            REG_ADMIN_URL
2041
-        );
2042
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2043
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2044
-        $template_path                                                        =
2045
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2046
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2047
-    }
2048
-
2049
-
2050
-    /**
2051
-     * generates HTML for the Registration Questions meta box.
2052
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2053
-     * otherwise uses new forms system
2054
-     *
2055
-     * @access public
2056
-     * @return void
2057
-     * @throws DomainException
2058
-     * @throws EE_Error
2059
-     */
2060
-    public function _reg_questions_meta_box()
2061
-    {
2062
-        //allow someone to override this method entirely
2063
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2064
-            $this->_registration)) {
2065
-            $form                                              = $this->_get_reg_custom_questions_form(
2066
-                $this->_registration->ID()
2067
-            );
2068
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2069
-                ? $form->get_html_and_js()
2070
-                : '';
2071
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2072
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2073
-            $template_path                                     =
2074
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2075
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2076
-        }
2077
-    }
2078
-
2079
-
2080
-    /**
2081
-     * form_before_question_group
2082
-     *
2083
-     * @deprecated    as of 4.8.32.rc.000
2084
-     * @access        public
2085
-     * @param        string $output
2086
-     * @return        string
2087
-     */
2088
-    public function form_before_question_group($output)
2089
-    {
2090
-        EE_Error::doing_it_wrong(
2091
-            __CLASS__ . '::' . __FUNCTION__,
2092
-            esc_html__(
2093
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2094
-                'event_espresso'
2095
-            ),
2096
-            '4.8.32.rc.000'
2097
-        );
2098
-        return '
1155
+		if (! empty($registration_status)) {
1156
+			$where['STS_ID'] = $registration_status;
1157
+		} else {
1158
+			//make sure we exclude incomplete registrations, but only if not trashed.
1159
+			if ($view === 'trash') {
1160
+				$where['REG_deleted'] = true;
1161
+			} elseif ($view === 'incomplete') {
1162
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1163
+			} else {
1164
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1165
+			}
1166
+		}
1167
+		return $where;
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1173
+	 *
1174
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1175
+	 * @return array
1176
+	 * @throws EE_Error
1177
+	 */
1178
+	protected function _add_date_to_where_conditions(array $request)
1179
+	{
1180
+		$where = array();
1181
+		$view = EEH_Array::is_set($request, 'status', '');
1182
+		$month_range             = ! empty($request['month_range'])
1183
+			? sanitize_text_field($request['month_range'])
1184
+			: '';
1185
+		$retrieve_for_today      = $view === 'today';
1186
+		$retrieve_for_this_month = $view === 'month';
1187
+
1188
+		if ($retrieve_for_today) {
1189
+			$now               = date('Y-m-d', current_time('timestamp'));
1190
+			$where['REG_date'] = array(
1191
+				'BETWEEN',
1192
+				array(
1193
+					EEM_Registration::instance()->convert_datetime_for_query(
1194
+						'REG_date',
1195
+						$now . ' 00:00:00',
1196
+						'Y-m-d H:i:s'
1197
+					),
1198
+					EEM_Registration::instance()->convert_datetime_for_query(
1199
+						'REG_date',
1200
+						$now . ' 23:59:59',
1201
+						'Y-m-d H:i:s'
1202
+					),
1203
+				),
1204
+			);
1205
+		} elseif ($retrieve_for_this_month) {
1206
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1207
+			$days_this_month        = date('t', current_time('timestamp'));
1208
+			$where['REG_date']      = array(
1209
+				'BETWEEN',
1210
+				array(
1211
+					EEM_Registration::instance()->convert_datetime_for_query(
1212
+						'REG_date',
1213
+						$current_year_and_month . '-01 00:00:00',
1214
+						'Y-m-d H:i:s'
1215
+					),
1216
+					EEM_Registration::instance()->convert_datetime_for_query(
1217
+						'REG_date',
1218
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1219
+						'Y-m-d H:i:s'
1220
+					),
1221
+				),
1222
+			);
1223
+		} elseif ($month_range) {
1224
+			$pieces          = explode(' ', $month_range, 3);
1225
+			$month_requested = ! empty($pieces[0])
1226
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1227
+				: '';
1228
+			$year_requested  = ! empty($pieces[1])
1229
+				? $pieces[1]
1230
+				: '';
1231
+			//if there is not a month or year then we can't go further
1232
+			if ($month_requested && $year_requested) {
1233
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1234
+				$where['REG_date'] = array(
1235
+					'BETWEEN',
1236
+					array(
1237
+						EEM_Registration::instance()->convert_datetime_for_query(
1238
+							'REG_date',
1239
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1240
+							'Y-m-d H:i:s'
1241
+						),
1242
+						EEM_Registration::instance()->convert_datetime_for_query(
1243
+							'REG_date',
1244
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1245
+							'Y-m-d H:i:s'
1246
+						),
1247
+					),
1248
+				);
1249
+			}
1250
+		}
1251
+		return $where;
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 * Adds any provided search restraints to the where conditions for the registrations query
1257
+	 *
1258
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1259
+	 * @return array
1260
+	 */
1261
+	protected function _add_search_to_where_conditions(array $request)
1262
+	{
1263
+		$where = array();
1264
+		if (! empty($request['s'])) {
1265
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1266
+			$where['OR*search_conditions'] = array(
1267
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1268
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1269
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1270
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1271
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1272
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1273
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1274
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1275
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1276
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1277
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1278
+				'REG_final_price'                         => array('LIKE', $search_string),
1279
+				'REG_code'                                => array('LIKE', $search_string),
1280
+				'REG_count'                               => array('LIKE', $search_string),
1281
+				'REG_group_size'                          => array('LIKE', $search_string),
1282
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1283
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1284
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1285
+			);
1286
+		}
1287
+		return $where;
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * Sets up the where conditions for the registrations query.
1293
+	 *
1294
+	 * @param array $request
1295
+	 * @return array
1296
+	 * @throws EE_Error
1297
+	 */
1298
+	protected function _get_where_conditions_for_registrations_query($request)
1299
+	{
1300
+		return apply_filters(
1301
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1302
+			array_merge(
1303
+				$this->_add_event_id_to_where_conditions($request),
1304
+				$this->_add_category_id_to_where_conditions($request),
1305
+				$this->_add_datetime_id_to_where_conditions($request),
1306
+				$this->_add_registration_status_to_where_conditions($request),
1307
+				$this->_add_date_to_where_conditions($request),
1308
+				$this->_add_search_to_where_conditions($request)
1309
+			),
1310
+			$request
1311
+		);
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * Sets up the orderby for the registrations query.
1317
+	 *
1318
+	 * @return array
1319
+	 */
1320
+	protected function _get_orderby_for_registrations_query()
1321
+	{
1322
+		$orderby_field = ! empty($this->_req_data['orderby'])
1323
+			? sanitize_text_field($this->_req_data['orderby'])
1324
+			: '';
1325
+		switch ($orderby_field) {
1326
+			case '_REG_ID':
1327
+				$orderby_field = 'REG_ID';
1328
+				break;
1329
+			case '_Reg_status':
1330
+				$orderby_field = 'STS_ID';
1331
+				break;
1332
+			case 'ATT_fname':
1333
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1334
+				break;
1335
+			case 'ATT_lname':
1336
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1337
+				break;
1338
+			case 'event_name':
1339
+				$orderby_field = 'Event.EVT_name';
1340
+				break;
1341
+			case 'DTT_EVT_start':
1342
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1343
+				break;
1344
+			default: //'REG_date'
1345
+				$orderby_field = 'REG_date';
1346
+		}
1347
+
1348
+		//order
1349
+		$order = ! empty($this->_req_data['order'])
1350
+			? sanitize_text_field($this->_req_data['order'])
1351
+			: 'DESC';
1352
+
1353
+		//mutate orderby_field
1354
+		$orderby_field = array_combine(
1355
+			(array) $orderby_field,
1356
+			array_fill(0, count($orderby_field), $order)
1357
+		);
1358
+		return array('order_by' => $orderby_field);
1359
+	}
1360
+
1361
+
1362
+	/**
1363
+	 * Sets up the limit for the registrations query.
1364
+	 *
1365
+	 * @param $per_page
1366
+	 * @return array
1367
+	 */
1368
+	protected function _get_limit($per_page)
1369
+	{
1370
+		$current_page = ! empty($this->_req_data['paged'])
1371
+			? absint($this->_req_data['paged'])
1372
+			: 1;
1373
+		$per_page     = ! empty($this->_req_data['perpage'])
1374
+			? $this->_req_data['perpage']
1375
+			: $per_page;
1376
+
1377
+		//-1 means return all results so get out if that's set.
1378
+		if ((int)$per_page === -1) {
1379
+			return array();
1380
+		}
1381
+		$per_page = absint($per_page);
1382
+		$offset   = ($current_page - 1) * $per_page;
1383
+		return array('limit' => array($offset, $per_page));
1384
+	}
1385
+
1386
+
1387
+	public function get_registration_status_array()
1388
+	{
1389
+		return self::$_reg_status;
1390
+	}
1391
+
1392
+
1393
+
1394
+
1395
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1396
+	/**
1397
+	 *        generates HTML for the View Registration Details Admin page
1398
+	 *
1399
+	 * @access protected
1400
+	 * @return void
1401
+	 * @throws DomainException
1402
+	 * @throws EE_Error
1403
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1404
+	 */
1405
+	protected function _registration_details()
1406
+	{
1407
+		$this->_template_args = array();
1408
+		$this->_set_registration_object();
1409
+		if (is_object($this->_registration)) {
1410
+			$transaction                                   = $this->_registration->transaction()
1411
+				? $this->_registration->transaction()
1412
+				: EE_Transaction::new_instance();
1413
+			$this->_session                                = $transaction->session_data();
1414
+			$event_id                                      = $this->_registration->event_ID();
1415
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1416
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1417
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1418
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1419
+			$this->_template_args['grand_total']           = $transaction->total();
1420
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1421
+			// link back to overview
1422
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1423
+			$this->_template_args['registration']                = $this->_registration;
1424
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1425
+				array(
1426
+					'action'   => 'default',
1427
+					'event_id' => $event_id,
1428
+				),
1429
+				REG_ADMIN_URL
1430
+			);
1431
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1432
+				array(
1433
+					'action' => 'default',
1434
+					'EVT_ID' => $event_id,
1435
+					'page'   => 'espresso_transactions',
1436
+				),
1437
+				admin_url('admin.php')
1438
+			);
1439
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1440
+				array(
1441
+					'page'   => 'espresso_events',
1442
+					'action' => 'edit',
1443
+					'post'   => $event_id,
1444
+				),
1445
+				admin_url('admin.php')
1446
+			);
1447
+			//next and previous links
1448
+			$next_reg                                      = $this->_registration->next(
1449
+				null,
1450
+				array(),
1451
+				'REG_ID'
1452
+			);
1453
+			$this->_template_args['next_registration']     = $next_reg
1454
+				? $this->_next_link(
1455
+					EE_Admin_Page::add_query_args_and_nonce(
1456
+						array(
1457
+							'action'  => 'view_registration',
1458
+							'_REG_ID' => $next_reg['REG_ID'],
1459
+						),
1460
+						REG_ADMIN_URL
1461
+					),
1462
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1463
+				)
1464
+				: '';
1465
+			$previous_reg                                  = $this->_registration->previous(
1466
+				null,
1467
+				array(),
1468
+				'REG_ID'
1469
+			);
1470
+			$this->_template_args['previous_registration'] = $previous_reg
1471
+				? $this->_previous_link(
1472
+					EE_Admin_Page::add_query_args_and_nonce(
1473
+						array(
1474
+							'action'  => 'view_registration',
1475
+							'_REG_ID' => $previous_reg['REG_ID'],
1476
+						),
1477
+						REG_ADMIN_URL
1478
+					),
1479
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1480
+				)
1481
+				: '';
1482
+			// grab header
1483
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1484
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1485
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1486
+				$template_path,
1487
+				$this->_template_args,
1488
+				true
1489
+			);
1490
+		} else {
1491
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1492
+		}
1493
+		// the details template wrapper
1494
+		$this->display_admin_page_with_sidebar();
1495
+	}
1496
+
1497
+
1498
+	protected function _registration_details_metaboxes()
1499
+	{
1500
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1501
+		$this->_set_registration_object();
1502
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1503
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1504
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1505
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1506
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1507
+		if ($attendee instanceof EE_Attendee
1508
+			&& EE_Registry::instance()->CAP->current_user_can(
1509
+				'ee_edit_registration',
1510
+				'edit-reg-questions-mbox'
1511
+			)
1512
+		) {
1513
+			add_meta_box(
1514
+				'edit-reg-questions-mbox',
1515
+				esc_html__('Registration Form Answers', 'event_espresso'),
1516
+				array($this, '_reg_questions_meta_box'),
1517
+				$this->wp_page_slug,
1518
+				'normal',
1519
+				'high'
1520
+			);
1521
+		}
1522
+		add_meta_box(
1523
+			'edit-reg-registrant-mbox',
1524
+			esc_html__('Contact Details', 'event_espresso'),
1525
+			array($this, '_reg_registrant_side_meta_box'),
1526
+			$this->wp_page_slug,
1527
+			'side',
1528
+			'high'
1529
+		);
1530
+		if ($this->_registration->group_size() > 1) {
1531
+			add_meta_box(
1532
+				'edit-reg-attendees-mbox',
1533
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1534
+				array($this, '_reg_attendees_meta_box'),
1535
+				$this->wp_page_slug,
1536
+				'normal',
1537
+				'high'
1538
+			);
1539
+		}
1540
+	}
1541
+
1542
+
1543
+	/**
1544
+	 * set_reg_status_buttons_metabox
1545
+	 *
1546
+	 * @access protected
1547
+	 * @return string
1548
+	 * @throws \EE_Error
1549
+	 */
1550
+	public function set_reg_status_buttons_metabox()
1551
+	{
1552
+		$this->_set_registration_object();
1553
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1554
+		echo $change_reg_status_form->form_open(
1555
+			self::add_query_args_and_nonce(
1556
+				array(
1557
+					'action' => 'change_reg_status',
1558
+				),
1559
+				REG_ADMIN_URL
1560
+			)
1561
+		);
1562
+		echo $change_reg_status_form->get_html();
1563
+		echo $change_reg_status_form->form_close();
1564
+	}
1565
+
1566
+
1567
+
1568
+	/**
1569
+	 * @return EE_Form_Section_Proper
1570
+	 * @throws EE_Error
1571
+	 */
1572
+	protected function _generate_reg_status_change_form()
1573
+	{
1574
+		return new EE_Form_Section_Proper(array(
1575
+			'name'            => 'reg_status_change_form',
1576
+			'html_id'         => 'reg-status-change-form',
1577
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1578
+			'subsections'     => array(
1579
+				'return'             => new EE_Hidden_Input(array(
1580
+					'name'    => 'return',
1581
+					'default' => 'view_registration',
1582
+				)),
1583
+				'REG_ID'             => new EE_Hidden_Input(array(
1584
+					'name'    => 'REG_ID',
1585
+					'default' => $this->_registration->ID(),
1586
+				)),
1587
+				'current_status'     => new EE_Form_Section_HTML(
1588
+					EEH_HTML::tr(
1589
+						EEH_HTML::th(
1590
+							EEH_HTML::label(
1591
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1592
+								)
1593
+							)
1594
+						)
1595
+						. EEH_HTML::td(
1596
+							EEH_HTML::strong(
1597
+								$this->_registration->pretty_status(),
1598
+								'',
1599
+								'status-' . $this->_registration->status_ID(),
1600
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1601
+							)
1602
+						)
1603
+					)
1604
+				),
1605
+				'reg_status'         => new EE_Select_Input(
1606
+					$this->_get_reg_statuses(),
1607
+					array(
1608
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1609
+						'default'         => $this->_registration->status_ID(),
1610
+					)
1611
+				),
1612
+				'send_notifications' => new EE_Yes_No_Input(
1613
+					array(
1614
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1615
+						'default'         => false,
1616
+						'html_help_text'  => esc_html__(
1617
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1618
+							'event_espresso'
1619
+						),
1620
+					)
1621
+				),
1622
+				'submit'             => new EE_Submit_Input(
1623
+					array(
1624
+						'html_class'      => 'button-primary',
1625
+						'html_label_text' => '&nbsp;',
1626
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1627
+					)
1628
+				),
1629
+			),
1630
+		));
1631
+	}
1632
+
1633
+
1634
+	/**
1635
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1636
+	 *
1637
+	 * @return array
1638
+	 * @throws EE_Error
1639
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1640
+	 */
1641
+	protected function _get_reg_statuses()
1642
+	{
1643
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1644
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1645
+		// get current reg status
1646
+		$current_status = $this->_registration->status_ID();
1647
+		// is registration for free event? This will determine whether to display the pending payment option
1648
+		if (
1649
+			$current_status !== EEM_Registration::status_id_pending_payment
1650
+			&& $this->_registration->transaction()->is_free()
1651
+		) {
1652
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1653
+		}
1654
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1655
+	}
1656
+
1657
+
1658
+
1659
+	/**
1660
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1661
+	 *
1662
+	 * @param bool $status REG status given for changing registrations to.
1663
+	 * @param bool $notify Whether to send messages notifications or not.
1664
+	 * @return array  (array with reg_id(s) updated and whether update was successful.
1665
+	 * @throws \EE_Error
1666
+	 */
1667
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1668
+	{
1669
+		if (isset($this->_req_data['reg_status_change_form'])) {
1670
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1671
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1672
+		} else {
1673
+			$REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1674
+		}
1675
+		$success = $this->_set_registration_status($REG_IDs, $status);
1676
+		//notify?
1677
+		if ($success
1678
+			&& $notify
1679
+			&& EE_Registry::instance()->CAP->current_user_can(
1680
+				'ee_send_message',
1681
+				'espresso_registrations_resend_registration'
1682
+			)
1683
+		) {
1684
+			$this->_process_resend_registration();
1685
+		}
1686
+		return $success;
1687
+	}
1688
+
1689
+
1690
+
1691
+	/**
1692
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1693
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1694
+	 *
1695
+	 * @param array $REG_IDs
1696
+	 * @param bool  $status
1697
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
+	 * @throws \RuntimeException
1699
+	 * @throws \EE_Error
1700
+	 *               the array of updated registrations).
1701
+	 * @throws EE_Error
1702
+	 * @throws RuntimeException
1703
+	 */
1704
+	protected function _set_registration_status($REG_IDs = array(), $status = false)
1705
+	{
1706
+		$success = false;
1707
+		// typecast $REG_IDs
1708
+		$REG_IDs = (array)$REG_IDs;
1709
+		if ( ! empty($REG_IDs)) {
1710
+			$success = true;
1711
+			// set default status if none is passed
1712
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1713
+			// sanitize $REG_IDs
1714
+			$REG_IDs = array_filter($REG_IDs, 'absint');
1715
+			//loop through REG_ID's and change status
1716
+			foreach ($REG_IDs as $REG_ID) {
1717
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1718
+				if ($registration instanceof EE_Registration) {
1719
+					$registration->set_status($status);
1720
+					$result = $registration->save();
1721
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1722
+					$success = $result !== false ? $success : false;
1723
+				}
1724
+			}
1725
+		}
1726
+		//reset _req_data['_REG_ID'] for any potential future messages notifications
1727
+		$this->_req_data['_REG_ID'] = $REG_IDs;
1728
+		//return $success and processed registrations
1729
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1730
+	}
1731
+
1732
+
1733
+	/**
1734
+	 * Common logic for setting up success message and redirecting to appropriate route
1735
+	 *
1736
+	 * @param  string $STS_ID status id for the registration changed to
1737
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1738
+	 * @return void
1739
+	 */
1740
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1741
+	{
1742
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1743
+			: array('success' => false);
1744
+		$success = isset($result['success']) && $result['success'];
1745
+		//setup success message
1746
+		if ($success) {
1747
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1748
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1749
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1750
+			} else {
1751
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1752
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1753
+			}
1754
+			EE_Error::add_success($msg);
1755
+		} else {
1756
+			EE_Error::add_error(
1757
+				esc_html__(
1758
+					'Something went wrong, and the status was not changed',
1759
+					'event_espresso'
1760
+				), __FILE__, __LINE__, __FUNCTION__
1761
+			);
1762
+		}
1763
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1764
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1765
+		} else {
1766
+			$route = array('action' => 'default');
1767
+		}
1768
+		//unset nonces
1769
+		foreach ($this->_req_data as $ref => $value) {
1770
+			if (strpos($ref, 'nonce') !== false) {
1771
+				unset($this->_req_data[$ref]);
1772
+				continue;
1773
+			}
1774
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1775
+			$this->_req_data[$ref] = $value;
1776
+		}
1777
+		//merge request vars so that the reloaded list table contains any existing filter query params
1778
+		$route = array_merge($this->_req_data, $route);
1779
+		$this->_redirect_after_action($success, '', '', $route, true);
1780
+	}
1781
+
1782
+
1783
+	/**
1784
+	 * incoming reg status change from reg details page.
1785
+	 *
1786
+	 * @return void
1787
+	 */
1788
+	protected function _change_reg_status()
1789
+	{
1790
+		$this->_req_data['return'] = 'view_registration';
1791
+		//set notify based on whether the send notifications toggle is set or not
1792
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1793
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1794
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1795
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1796
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1797
+			case EEM_Registration::status_id_approved :
1798
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1799
+				$this->approve_registration($notify);
1800
+				break;
1801
+			case EEM_Registration::status_id_pending_payment :
1802
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1803
+				$this->pending_registration($notify);
1804
+				break;
1805
+			case EEM_Registration::status_id_not_approved :
1806
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1807
+				$this->not_approve_registration($notify);
1808
+				break;
1809
+			case EEM_Registration::status_id_declined :
1810
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1811
+				$this->decline_registration($notify);
1812
+				break;
1813
+			case EEM_Registration::status_id_cancelled :
1814
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1815
+				$this->cancel_registration($notify);
1816
+				break;
1817
+			case EEM_Registration::status_id_wait_list :
1818
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1819
+				$this->wait_list_registration($notify);
1820
+				break;
1821
+			case EEM_Registration::status_id_incomplete :
1822
+			default :
1823
+				$result['success'] = false;
1824
+				unset($this->_req_data['return']);
1825
+				$this->_reg_status_change_return('', false);
1826
+				break;
1827
+		}
1828
+	}
1829
+
1830
+
1831
+	/**
1832
+	 * approve_registration
1833
+	 *
1834
+	 * @access protected
1835
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1836
+	 * @return void
1837
+	 */
1838
+	protected function approve_registration($notify = false)
1839
+	{
1840
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1841
+	}
1842
+
1843
+
1844
+	/**
1845
+	 *        decline_registration
1846
+	 *
1847
+	 * @access protected
1848
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1849
+	 * @return void
1850
+	 */
1851
+	protected function decline_registration($notify = false)
1852
+	{
1853
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1854
+	}
1855
+
1856
+
1857
+	/**
1858
+	 *        cancel_registration
1859
+	 *
1860
+	 * @access protected
1861
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1862
+	 * @return void
1863
+	 */
1864
+	protected function cancel_registration($notify = false)
1865
+	{
1866
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1867
+	}
1868
+
1869
+
1870
+	/**
1871
+	 *        not_approve_registration
1872
+	 *
1873
+	 * @access protected
1874
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1875
+	 * @return void
1876
+	 */
1877
+	protected function not_approve_registration($notify = false)
1878
+	{
1879
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1880
+	}
1881
+
1882
+
1883
+	/**
1884
+	 *        decline_registration
1885
+	 *
1886
+	 * @access protected
1887
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1888
+	 * @return void
1889
+	 */
1890
+	protected function pending_registration($notify = false)
1891
+	{
1892
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1893
+	}
1894
+
1895
+
1896
+	/**
1897
+	 * waitlist_registration
1898
+	 *
1899
+	 * @access protected
1900
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1901
+	 * @return void
1902
+	 */
1903
+	protected function wait_list_registration($notify = false)
1904
+	{
1905
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1906
+	}
1907
+
1908
+
1909
+	/**
1910
+	 *        generates HTML for the Registration main meta box
1911
+	 *
1912
+	 * @access public
1913
+	 * @return void
1914
+	 * @throws DomainException
1915
+	 * @throws EE_Error
1916
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1917
+	 */
1918
+	public function _reg_details_meta_box()
1919
+	{
1920
+		EEH_Autoloader::register_line_item_display_autoloaders();
1921
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1922
+		EE_Registry::instance()->load_helper('Line_Item');
1923
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1924
+			: EE_Transaction::new_instance();
1925
+		$this->_session = $transaction->session_data();
1926
+		$filters        = new EE_Line_Item_Filter_Collection();
1927
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1928
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1929
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1930
+			$transaction->total_line_item());
1931
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
1932
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1933
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1934
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
1935
+			$filtered_line_item_tree,
1936
+			array('EE_Registration' => $this->_registration)
1937
+		);
1938
+		$attendee                                = $this->_registration->attendee();
1939
+		if (EE_Registry::instance()->CAP->current_user_can(
1940
+			'ee_read_transaction',
1941
+			'espresso_transactions_view_transaction'
1942
+		)) {
1943
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
1944
+				EE_Admin_Page::add_query_args_and_nonce(
1945
+					array(
1946
+						'action' => 'view_transaction',
1947
+						'TXN_ID' => $transaction->ID(),
1948
+					),
1949
+					TXN_ADMIN_URL
1950
+				),
1951
+				esc_html__(' View Transaction', 'event_espresso'),
1952
+				'button secondary-button right',
1953
+				'dashicons dashicons-cart'
1954
+			);
1955
+		} else {
1956
+			$this->_template_args['view_transaction_button'] = '';
1957
+		}
1958
+		if ($attendee instanceof EE_Attendee
1959
+			&& EE_Registry::instance()->CAP->current_user_can(
1960
+				'ee_send_message',
1961
+				'espresso_registrations_resend_registration'
1962
+			)
1963
+		) {
1964
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
1965
+				EE_Admin_Page::add_query_args_and_nonce(
1966
+					array(
1967
+						'action'      => 'resend_registration',
1968
+						'_REG_ID'     => $this->_registration->ID(),
1969
+						'redirect_to' => 'view_registration',
1970
+					),
1971
+					REG_ADMIN_URL
1972
+				),
1973
+				esc_html__(' Resend Registration', 'event_espresso'),
1974
+				'button secondary-button right',
1975
+				'dashicons dashicons-email-alt'
1976
+			);
1977
+		} else {
1978
+			$this->_template_args['resend_registration_button'] = '';
1979
+		}
1980
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1981
+		$payment                               = $transaction->get_first_related('Payment');
1982
+		$payment                               = ! $payment instanceof EE_Payment
1983
+			? EE_Payment::new_instance()
1984
+			: $payment;
1985
+		$payment_method                        = $payment->get_first_related('Payment_Method');
1986
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
1987
+			? EE_Payment_Method::new_instance()
1988
+			: $payment_method;
1989
+		$reg_details                           = array(
1990
+			'payment_method'       => $payment_method->name(),
1991
+			'response_msg'         => $payment->gateway_response(),
1992
+			'registration_id'      => $this->_registration->get('REG_code'),
1993
+			'registration_session' => $this->_registration->session_ID(),
1994
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1995
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1996
+		);
1997
+		if (isset($reg_details['registration_id'])) {
1998
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1999
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2000
+				'Registration ID',
2001
+				'event_espresso'
2002
+			);
2003
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2004
+		}
2005
+		if (isset($reg_details['payment_method'])) {
2006
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2007
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2008
+				'Most Recent Payment Method',
2009
+				'event_espresso'
2010
+			);
2011
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2012
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2013
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2014
+				'Payment method response',
2015
+				'event_espresso'
2016
+			);
2017
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2018
+		}
2019
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2020
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2021
+			'Registration Session',
2022
+			'event_espresso'
2023
+		);
2024
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2025
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2026
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2027
+			'Registration placed from IP',
2028
+			'event_espresso'
2029
+		);
2030
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2031
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2032
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2033
+			'event_espresso');
2034
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2035
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2036
+			array(
2037
+				'action'   => 'default',
2038
+				'event_id' => $this->_registration->event_ID(),
2039
+			),
2040
+			REG_ADMIN_URL
2041
+		);
2042
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2043
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2044
+		$template_path                                                        =
2045
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2046
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2047
+	}
2048
+
2049
+
2050
+	/**
2051
+	 * generates HTML for the Registration Questions meta box.
2052
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2053
+	 * otherwise uses new forms system
2054
+	 *
2055
+	 * @access public
2056
+	 * @return void
2057
+	 * @throws DomainException
2058
+	 * @throws EE_Error
2059
+	 */
2060
+	public function _reg_questions_meta_box()
2061
+	{
2062
+		//allow someone to override this method entirely
2063
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2064
+			$this->_registration)) {
2065
+			$form                                              = $this->_get_reg_custom_questions_form(
2066
+				$this->_registration->ID()
2067
+			);
2068
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2069
+				? $form->get_html_and_js()
2070
+				: '';
2071
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2072
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2073
+			$template_path                                     =
2074
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2075
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2076
+		}
2077
+	}
2078
+
2079
+
2080
+	/**
2081
+	 * form_before_question_group
2082
+	 *
2083
+	 * @deprecated    as of 4.8.32.rc.000
2084
+	 * @access        public
2085
+	 * @param        string $output
2086
+	 * @return        string
2087
+	 */
2088
+	public function form_before_question_group($output)
2089
+	{
2090
+		EE_Error::doing_it_wrong(
2091
+			__CLASS__ . '::' . __FUNCTION__,
2092
+			esc_html__(
2093
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2094
+				'event_espresso'
2095
+			),
2096
+			'4.8.32.rc.000'
2097
+		);
2098
+		return '
2099 2099
 	<table class="form-table ee-width-100">
2100 2100
 		<tbody>
2101 2101
 			';
2102
-    }
2103
-
2104
-
2105
-    /**
2106
-     * form_after_question_group
2107
-     *
2108
-     * @deprecated    as of 4.8.32.rc.000
2109
-     * @access        public
2110
-     * @param        string $output
2111
-     * @return        string
2112
-     */
2113
-    public function form_after_question_group($output)
2114
-    {
2115
-        EE_Error::doing_it_wrong(
2116
-            __CLASS__ . '::' . __FUNCTION__,
2117
-            esc_html__(
2118
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2119
-                'event_espresso'
2120
-            ),
2121
-            '4.8.32.rc.000'
2122
-        );
2123
-        return '
2102
+	}
2103
+
2104
+
2105
+	/**
2106
+	 * form_after_question_group
2107
+	 *
2108
+	 * @deprecated    as of 4.8.32.rc.000
2109
+	 * @access        public
2110
+	 * @param        string $output
2111
+	 * @return        string
2112
+	 */
2113
+	public function form_after_question_group($output)
2114
+	{
2115
+		EE_Error::doing_it_wrong(
2116
+			__CLASS__ . '::' . __FUNCTION__,
2117
+			esc_html__(
2118
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2119
+				'event_espresso'
2120
+			),
2121
+			'4.8.32.rc.000'
2122
+		);
2123
+		return '
2124 2124
 			<tr class="hide-if-no-js">
2125 2125
 				<th> </th>
2126 2126
 				<td class="reg-admin-edit-attendee-question-td">
2127 2127
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2128
-               . esc_attr__('click to edit question', 'event_espresso')
2129
-               . '">
2128
+			   . esc_attr__('click to edit question', 'event_espresso')
2129
+			   . '">
2130 2130
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2131
-               . esc_html__('edit the above question group', 'event_espresso')
2132
-               . '</span>
2131
+			   . esc_html__('edit the above question group', 'event_espresso')
2132
+			   . '</span>
2133 2133
 						<div class="dashicons dashicons-edit"></div>
2134 2134
 					</a>
2135 2135
 				</td>
@@ -2137,558 +2137,558 @@  discard block
 block discarded – undo
2137 2137
 		</tbody>
2138 2138
 	</table>
2139 2139
 ';
2140
-    }
2141
-
2142
-
2143
-    /**
2144
-     * form_form_field_label_wrap
2145
-     *
2146
-     * @deprecated    as of 4.8.32.rc.000
2147
-     * @access        public
2148
-     * @param        string $label
2149
-     * @return        string
2150
-     */
2151
-    public function form_form_field_label_wrap($label)
2152
-    {
2153
-        EE_Error::doing_it_wrong(
2154
-            __CLASS__ . '::' . __FUNCTION__,
2155
-            esc_html__(
2156
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2157
-                'event_espresso'
2158
-            ),
2159
-            '4.8.32.rc.000'
2160
-        );
2161
-        return '
2140
+	}
2141
+
2142
+
2143
+	/**
2144
+	 * form_form_field_label_wrap
2145
+	 *
2146
+	 * @deprecated    as of 4.8.32.rc.000
2147
+	 * @access        public
2148
+	 * @param        string $label
2149
+	 * @return        string
2150
+	 */
2151
+	public function form_form_field_label_wrap($label)
2152
+	{
2153
+		EE_Error::doing_it_wrong(
2154
+			__CLASS__ . '::' . __FUNCTION__,
2155
+			esc_html__(
2156
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2157
+				'event_espresso'
2158
+			),
2159
+			'4.8.32.rc.000'
2160
+		);
2161
+		return '
2162 2162
 			<tr>
2163 2163
 				<th>
2164 2164
 					' . $label . '
2165 2165
 				</th>';
2166
-    }
2167
-
2168
-
2169
-    /**
2170
-     * form_form_field_input__wrap
2171
-     *
2172
-     * @deprecated    as of 4.8.32.rc.000
2173
-     * @access        public
2174
-     * @param        string $input
2175
-     * @return        string
2176
-     */
2177
-    public function form_form_field_input__wrap($input)
2178
-    {
2179
-        EE_Error::doing_it_wrong(
2180
-            __CLASS__ . '::' . __FUNCTION__,
2181
-            esc_html__(
2182
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2183
-                'event_espresso'
2184
-            ),
2185
-            '4.8.32.rc.000'
2186
-        );
2187
-        return '
2166
+	}
2167
+
2168
+
2169
+	/**
2170
+	 * form_form_field_input__wrap
2171
+	 *
2172
+	 * @deprecated    as of 4.8.32.rc.000
2173
+	 * @access        public
2174
+	 * @param        string $input
2175
+	 * @return        string
2176
+	 */
2177
+	public function form_form_field_input__wrap($input)
2178
+	{
2179
+		EE_Error::doing_it_wrong(
2180
+			__CLASS__ . '::' . __FUNCTION__,
2181
+			esc_html__(
2182
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2183
+				'event_espresso'
2184
+			),
2185
+			'4.8.32.rc.000'
2186
+		);
2187
+		return '
2188 2188
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2189 2189
 					' . $input . '
2190 2190
 				</td>
2191 2191
 			</tr>';
2192
-    }
2193
-
2194
-
2195
-    /**
2196
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2197
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2198
-     * to display the page
2199
-     *
2200
-     * @access protected
2201
-     * @return void
2202
-     * @throws EE_Error
2203
-     */
2204
-    protected function _update_attendee_registration_form()
2205
-    {
2206
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2207
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2208
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2209
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2210
-            if ($success) {
2211
-                $what  = esc_html__('Registration Form', 'event_espresso');
2212
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2213
-                    : array('action' => 'default');
2214
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2215
-            }
2216
-        }
2217
-    }
2218
-
2219
-
2220
-    /**
2221
-     * Gets the form for saving registrations custom questions (if done
2222
-     * previously retrieves the cached form object, which may have validation errors in it)
2223
-     *
2224
-     * @param int $REG_ID
2225
-     * @return EE_Registration_Custom_Questions_Form
2226
-     * @throws EE_Error
2227
-     */
2228
-    protected function _get_reg_custom_questions_form($REG_ID)
2229
-    {
2230
-        if ( ! $this->_reg_custom_questions_form) {
2231
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2232
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2233
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2234
-            );
2235
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2236
-        }
2237
-        return $this->_reg_custom_questions_form;
2238
-    }
2239
-
2240
-
2241
-    /**
2242
-     * Saves
2243
-     *
2244
-     * @access private
2245
-     * @param bool $REG_ID
2246
-     * @return bool
2247
-     * @throws EE_Error
2248
-     */
2249
-    private function _save_reg_custom_questions_form($REG_ID = false)
2250
-    {
2251
-        if ( ! $REG_ID) {
2252
-            EE_Error::add_error(
2253
-                esc_html__(
2254
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2255
-                __FILE__, __FUNCTION__, __LINE__
2256
-            );
2257
-        }
2258
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2259
-        $form->receive_form_submission($this->_req_data);
2260
-        $success = false;
2261
-        if ($form->is_valid()) {
2262
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2263
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2264
-                    $where_conditions    = array(
2265
-                        'QST_ID' => $question_id,
2266
-                        'REG_ID' => $REG_ID,
2267
-                    );
2268
-                    $possibly_new_values = array(
2269
-                        'ANS_value' => $input->normalized_value(),
2270
-                    );
2271
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2272
-                    if ($answer instanceof EE_Answer) {
2273
-                        $success = $answer->save($possibly_new_values);
2274
-                    } else {
2275
-                        //insert it then
2276
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2277
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2278
-                        $success     = $answer->save();
2279
-                    }
2280
-                }
2281
-            }
2282
-        } else {
2283
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2284
-        }
2285
-        return $success;
2286
-    }
2287
-
2288
-
2289
-    /**
2290
-     *        generates HTML for the Registration main meta box
2291
-     *
2292
-     * @access public
2293
-     * @return void
2294
-     * @throws DomainException
2295
-     * @throws EE_Error
2296
-     */
2297
-    public function _reg_attendees_meta_box()
2298
-    {
2299
-        $REG = EEM_Registration::instance();
2300
-        //get all other registrations on this transaction, and cache
2301
-        //the attendees for them so we don't have to run another query using force_join
2302
-        $registrations                           = $REG->get_all(array(
2303
-            array(
2304
-                'TXN_ID' => $this->_registration->transaction_ID(),
2305
-                'REG_ID' => array('!=', $this->_registration->ID()),
2306
-            ),
2307
-            'force_join' => array('Attendee'),
2308
-        ));
2309
-        $this->_template_args['attendees']       = array();
2310
-        $this->_template_args['attendee_notice'] = '';
2311
-        if (empty($registrations)
2312
-            || (is_array($registrations)
2313
-                && ! EEH_Array::get_one_item_from_array($registrations))
2314
-        ) {
2315
-            EE_Error::add_error(
2316
-                esc_html__(
2317
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2318
-                    'event_espresso'
2319
-                ), __FILE__, __FUNCTION__, __LINE__
2320
-            );
2321
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2322
-        } else {
2323
-            $att_nmbr = 1;
2324
-            foreach ($registrations as $registration) {
2325
-                /* @var $registration EE_Registration */
2326
-                $attendee                                                    = $registration->attendee()
2327
-                    ? $registration->attendee()
2328
-                    : EEM_Attendee::instance()
2329
-                                  ->create_default_object();
2330
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2331
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2332
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2333
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2334
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2335
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2336
-                    ', ',
2337
-                    $attendee->full_address_as_array()
2338
-                );
2339
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2340
-                    array(
2341
-                        'action' => 'edit_attendee',
2342
-                        'post'   => $attendee->ID(),
2343
-                    ),
2344
-                    REG_ADMIN_URL
2345
-                );
2346
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2347
-                $att_nmbr++;
2348
-            }
2349
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2350
-        }
2351
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2352
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2353
-    }
2354
-
2355
-
2356
-    /**
2357
-     *        generates HTML for the Edit Registration side meta box
2358
-     *
2359
-     * @access public
2360
-     * @return void
2361
-     * @throws DomainException
2362
-     * @throws EE_Error
2363
-     */
2364
-    public function _reg_registrant_side_meta_box()
2365
-    {
2366
-        /*@var $attendee EE_Attendee */
2367
-        $att_check = $this->_registration->attendee();
2368
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2369
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2370
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2371
-        //primary registration object (that way we know if we need to show create button or not)
2372
-        if ( ! $this->_registration->is_primary_registrant()) {
2373
-            $primary_registration = $this->_registration->get_primary_registration();
2374
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2375
-                : null;
2376
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2377
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2378
-                //custom attendee object so let's not worry about the primary reg.
2379
-                $primary_registration = null;
2380
-            }
2381
-        } else {
2382
-            $primary_registration = null;
2383
-        }
2384
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2385
-        $this->_template_args['fname']             = $attendee->fname();
2386
-        $this->_template_args['lname']             = $attendee->lname();
2387
-        $this->_template_args['email']             = $attendee->email();
2388
-        $this->_template_args['phone']             = $attendee->phone();
2389
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2390
-        //edit link
2391
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2392
-            'action' => 'edit_attendee',
2393
-            'post'   => $attendee->ID(),
2394
-        ), REG_ADMIN_URL);
2395
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2396
-        //create link
2397
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2398
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2399
-                'action'  => 'duplicate_attendee',
2400
-                '_REG_ID' => $this->_registration->ID(),
2401
-            ), REG_ADMIN_URL) : '';
2402
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2403
-        $this->_template_args['att_check']    = $att_check;
2404
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2405
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2406
-    }
2407
-
2408
-
2409
-    /**
2410
-     * trash or restore registrations
2411
-     *
2412
-     * @param  boolean $trash whether to archive or restore
2413
-     * @return void
2414
-     * @throws EE_Error
2415
-     * @throws RuntimeException
2416
-     * @access protected
2417
-     */
2418
-    protected function _trash_or_restore_registrations($trash = true)
2419
-    {
2420
-        //if empty _REG_ID then get out because there's nothing to do
2421
-        if (empty($this->_req_data['_REG_ID'])) {
2422
-            EE_Error::add_error(
2423
-                sprintf(
2424
-                    esc_html__(
2425
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2426
-                        'event_espresso'
2427
-                    ),
2428
-                    $trash ? 'trash' : 'restore'
2429
-                ),
2430
-                __FILE__, __LINE__, __FUNCTION__
2431
-            );
2432
-            $this->_redirect_after_action(false, '', '', array(), true);
2433
-        }
2434
-        $success = 0;
2435
-        $overwrite_msgs = false;
2436
-        //Checkboxes
2437
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2438
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2439
-        }
2440
-        $reg_count = count($this->_req_data['_REG_ID']);
2441
-        // cycle thru checkboxes
2442
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2443
-            /** @var EE_Registration $REG */
2444
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2445
-            $payments = $REG->registration_payments();
2446
-            if (! empty($payments)) {
2447
-                $name = $REG->attendee() instanceof EE_Attendee
2448
-                    ? $REG->attendee()->full_name()
2449
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2450
-                $overwrite_msgs = true;
2451
-                EE_Error::add_error(
2452
-                    sprintf(
2453
-                        esc_html__(
2454
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2455
-                            'event_espresso'
2456
-                        ),
2457
-                        $name
2458
-                    ),
2459
-                    __FILE__, __FUNCTION__, __LINE__
2460
-                );
2461
-                //can't trash this registration because it has payments.
2462
-                continue;
2463
-            }
2464
-            $updated = $trash ? $REG->delete() : $REG->restore();
2465
-            if ($updated) {
2466
-                $success++;
2467
-            }
2468
-        }
2469
-        $this->_redirect_after_action(
2470
-            $success === $reg_count, // were ALL registrations affected?
2471
-            $success > 1
2472
-                ? esc_html__('Registrations', 'event_espresso')
2473
-                : esc_html__('Registration', 'event_espresso'),
2474
-            $trash
2475
-                ? esc_html__('moved to the trash', 'event_espresso')
2476
-                : esc_html__('restored', 'event_espresso'),
2477
-            array('action' => 'default'),
2478
-            $overwrite_msgs
2479
-        );
2480
-    }
2481
-
2482
-
2483
-    /**
2484
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2485
-     * registration but also.
2486
-     * 1. Removing relations to EE_Attendee
2487
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2488
-     * ALSO trashed.
2489
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2490
-     * 4. Removing relationships between all tickets and the related registrations
2491
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2492
-     * 6. Deleting permanently any related Checkins.
2493
-     *
2494
-     * @return void
2495
-     * @throws EE_Error
2496
-     */
2497
-    protected function _delete_registrations()
2498
-    {
2499
-        $REG_MDL = EEM_Registration::instance();
2500
-        $success = 1;
2501
-        //Checkboxes
2502
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2503
-            // if array has more than one element than success message should be plural
2504
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2505
-            // cycle thru checkboxes
2506
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2507
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2508
-                if ( ! $REG instanceof EE_Registration) {
2509
-                    continue;
2510
-                }
2511
-                $deleted = $this->_delete_registration($REG);
2512
-                if ( ! $deleted) {
2513
-                    $success = 0;
2514
-                }
2515
-            }
2516
-        } else {
2517
-            // grab single id and delete
2518
-            $REG_ID  = $this->_req_data['_REG_ID'];
2519
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2520
-            $deleted = $this->_delete_registration($REG);
2521
-            if ( ! $deleted) {
2522
-                $success = 0;
2523
-            }
2524
-        }
2525
-        $what        = $success > 1
2526
-            ? esc_html__('Registrations', 'event_espresso')
2527
-            : esc_html__('Registration', 'event_espresso');
2528
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2529
-        $this->_redirect_after_action(
2530
-            $success,
2531
-            $what,
2532
-            $action_desc,
2533
-            array('action' => 'default'),
2534
-            true
2535
-        );
2536
-    }
2537
-
2538
-
2539
-    /**
2540
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2541
-     * models get affected.
2542
-     *
2543
-     * @param  EE_Registration $REG registration to be deleted permenantly
2544
-     * @return bool true = successful deletion, false = fail.
2545
-     * @throws EE_Error
2546
-     */
2547
-    protected function _delete_registration(EE_Registration $REG)
2548
-    {
2549
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2550
-        //registrations on the transaction that are NOT trashed.
2551
-        $TXN         = $REG->get_first_related('Transaction');
2552
-        $REGS        = $TXN->get_many_related('Registration');
2553
-        $all_trashed = true;
2554
-        foreach ($REGS as $registration) {
2555
-            if ( ! $registration->get('REG_deleted')) {
2556
-                $all_trashed = false;
2557
-            }
2558
-        }
2559
-        if ( ! $all_trashed) {
2560
-            EE_Error::add_error(
2561
-                esc_html__(
2562
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2563
-                    'event_espresso'
2564
-                ),
2565
-                __FILE__, __FUNCTION__, __LINE__
2566
-            );
2567
-            return false;
2568
-        }
2569
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2570
-        //separately from THIS one).
2571
-        foreach ($REGS as $registration) {
2572
-            //delete related answers
2573
-            $registration->delete_related_permanently('Answer');
2574
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2575
-            $attendee = $registration->get_first_related('Attendee');
2576
-            if ($attendee instanceof EE_Attendee) {
2577
-                $registration->_remove_relation_to($attendee, 'Attendee');
2578
-            }
2579
-            //now remove relationships to tickets on this registration.
2580
-            $registration->_remove_relations('Ticket');
2581
-            //now delete permanently the checkins related to this registration.
2582
-            $registration->delete_related_permanently('Checkin');
2583
-            if ($registration->ID() === $REG->ID()) {
2584
-                continue;
2585
-            } //we don't want to delete permanently the existing registration just yet.
2586
-            //remove relation to transaction for these registrations if NOT the existing registrations
2587
-            $registration->_remove_relations('Transaction');
2588
-            //delete permanently any related messages.
2589
-            $registration->delete_related_permanently('Message');
2590
-            //now delete this registration permanently
2591
-            $registration->delete_permanently();
2592
-        }
2593
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2594
-        // (the transaction and line items should be all that's left).
2595
-        // delete the line items related to the transaction for this registration.
2596
-        $TXN->delete_related_permanently('Line_Item');
2597
-        //we need to remove all the relationships on the transaction
2598
-        $TXN->delete_related_permanently('Payment');
2599
-        $TXN->delete_related_permanently('Extra_Meta');
2600
-        $TXN->delete_related_permanently('Message');
2601
-        //now we can delete this REG permanently (and the transaction of course)
2602
-        $REG->delete_related_permanently('Transaction');
2603
-        return $REG->delete_permanently();
2604
-    }
2605
-
2606
-
2607
-    /**
2608
-     *    generates HTML for the Register New Attendee Admin page
2609
-     *
2610
-     * @access private
2611
-     * @throws DomainException
2612
-     * @throws EE_Error
2613
-     */
2614
-    public function new_registration()
2615
-    {
2616
-        if ( ! $this->_set_reg_event()) {
2617
-            throw new EE_Error(
2618
-                esc_html__(
2619
-                    'Unable to continue with registering because there is no Event ID in the request',
2620
-                    'event_espresso'
2621
-                )
2622
-            );
2623
-        }
2624
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2625
-        // gotta start with a clean slate if we're not coming here via ajax
2626
-        if ( ! defined('DOING_AJAX')
2627
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2628
-        ) {
2629
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2630
-        }
2631
-        $this->_template_args['event_name'] = '';
2632
-        // event name
2633
-        if ($this->_reg_event) {
2634
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2635
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2636
-                'action' => 'edit',
2637
-                'post'   => $this->_reg_event->ID(),
2638
-            ), EVENTS_ADMIN_URL);
2639
-            $edit_event_lnk                     = '<a href="'
2640
-                                                  . $edit_event_url
2641
-                                                  . '" title="'
2642
-                                                  . esc_attr__('Edit ', 'event_espresso')
2643
-                                                  . $this->_reg_event->name()
2644
-                                                  . '">'
2645
-                                                  . esc_html__('Edit Event', 'event_espresso')
2646
-                                                  . '</a>';
2647
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2648
-                                                   . $edit_event_lnk
2649
-                                                   . '</span>';
2650
-        }
2651
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2652
-        if (defined('DOING_AJAX')) {
2653
-            $this->_return_json();
2654
-        }
2655
-        // grab header
2656
-        $template_path                              =
2657
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2658
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2659
-            $this->_template_args, true);
2660
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2661
-        // the details template wrapper
2662
-        $this->display_admin_page_with_sidebar();
2663
-    }
2664
-
2665
-
2666
-    /**
2667
-     * This returns the content for a registration step
2668
-     *
2669
-     * @access protected
2670
-     * @return string html
2671
-     * @throws DomainException
2672
-     * @throws EE_Error
2673
-     */
2674
-    protected function _get_registration_step_content()
2675
-    {
2676
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2677
-            $warning_msg = sprintf(
2678
-                esc_html__(
2679
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2680
-                    'event_espresso'
2681
-                ),
2682
-                '<br />',
2683
-                '<h3 class="important-notice">',
2684
-                '</h3>',
2685
-                '<div class="float-right">',
2686
-                '<span id="redirect_timer" class="important-notice">30</span>',
2687
-                '</div>',
2688
-                '<b>',
2689
-                '</b>'
2690
-            );
2691
-            return '
2192
+	}
2193
+
2194
+
2195
+	/**
2196
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2197
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2198
+	 * to display the page
2199
+	 *
2200
+	 * @access protected
2201
+	 * @return void
2202
+	 * @throws EE_Error
2203
+	 */
2204
+	protected function _update_attendee_registration_form()
2205
+	{
2206
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2207
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2208
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2209
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2210
+			if ($success) {
2211
+				$what  = esc_html__('Registration Form', 'event_espresso');
2212
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2213
+					: array('action' => 'default');
2214
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2215
+			}
2216
+		}
2217
+	}
2218
+
2219
+
2220
+	/**
2221
+	 * Gets the form for saving registrations custom questions (if done
2222
+	 * previously retrieves the cached form object, which may have validation errors in it)
2223
+	 *
2224
+	 * @param int $REG_ID
2225
+	 * @return EE_Registration_Custom_Questions_Form
2226
+	 * @throws EE_Error
2227
+	 */
2228
+	protected function _get_reg_custom_questions_form($REG_ID)
2229
+	{
2230
+		if ( ! $this->_reg_custom_questions_form) {
2231
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2232
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2233
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2234
+			);
2235
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2236
+		}
2237
+		return $this->_reg_custom_questions_form;
2238
+	}
2239
+
2240
+
2241
+	/**
2242
+	 * Saves
2243
+	 *
2244
+	 * @access private
2245
+	 * @param bool $REG_ID
2246
+	 * @return bool
2247
+	 * @throws EE_Error
2248
+	 */
2249
+	private function _save_reg_custom_questions_form($REG_ID = false)
2250
+	{
2251
+		if ( ! $REG_ID) {
2252
+			EE_Error::add_error(
2253
+				esc_html__(
2254
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2255
+				__FILE__, __FUNCTION__, __LINE__
2256
+			);
2257
+		}
2258
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2259
+		$form->receive_form_submission($this->_req_data);
2260
+		$success = false;
2261
+		if ($form->is_valid()) {
2262
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2263
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2264
+					$where_conditions    = array(
2265
+						'QST_ID' => $question_id,
2266
+						'REG_ID' => $REG_ID,
2267
+					);
2268
+					$possibly_new_values = array(
2269
+						'ANS_value' => $input->normalized_value(),
2270
+					);
2271
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2272
+					if ($answer instanceof EE_Answer) {
2273
+						$success = $answer->save($possibly_new_values);
2274
+					} else {
2275
+						//insert it then
2276
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2277
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2278
+						$success     = $answer->save();
2279
+					}
2280
+				}
2281
+			}
2282
+		} else {
2283
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2284
+		}
2285
+		return $success;
2286
+	}
2287
+
2288
+
2289
+	/**
2290
+	 *        generates HTML for the Registration main meta box
2291
+	 *
2292
+	 * @access public
2293
+	 * @return void
2294
+	 * @throws DomainException
2295
+	 * @throws EE_Error
2296
+	 */
2297
+	public function _reg_attendees_meta_box()
2298
+	{
2299
+		$REG = EEM_Registration::instance();
2300
+		//get all other registrations on this transaction, and cache
2301
+		//the attendees for them so we don't have to run another query using force_join
2302
+		$registrations                           = $REG->get_all(array(
2303
+			array(
2304
+				'TXN_ID' => $this->_registration->transaction_ID(),
2305
+				'REG_ID' => array('!=', $this->_registration->ID()),
2306
+			),
2307
+			'force_join' => array('Attendee'),
2308
+		));
2309
+		$this->_template_args['attendees']       = array();
2310
+		$this->_template_args['attendee_notice'] = '';
2311
+		if (empty($registrations)
2312
+			|| (is_array($registrations)
2313
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2314
+		) {
2315
+			EE_Error::add_error(
2316
+				esc_html__(
2317
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2318
+					'event_espresso'
2319
+				), __FILE__, __FUNCTION__, __LINE__
2320
+			);
2321
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2322
+		} else {
2323
+			$att_nmbr = 1;
2324
+			foreach ($registrations as $registration) {
2325
+				/* @var $registration EE_Registration */
2326
+				$attendee                                                    = $registration->attendee()
2327
+					? $registration->attendee()
2328
+					: EEM_Attendee::instance()
2329
+								  ->create_default_object();
2330
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2331
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2332
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2333
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2334
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2335
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2336
+					', ',
2337
+					$attendee->full_address_as_array()
2338
+				);
2339
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2340
+					array(
2341
+						'action' => 'edit_attendee',
2342
+						'post'   => $attendee->ID(),
2343
+					),
2344
+					REG_ADMIN_URL
2345
+				);
2346
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2347
+				$att_nmbr++;
2348
+			}
2349
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2350
+		}
2351
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2352
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2353
+	}
2354
+
2355
+
2356
+	/**
2357
+	 *        generates HTML for the Edit Registration side meta box
2358
+	 *
2359
+	 * @access public
2360
+	 * @return void
2361
+	 * @throws DomainException
2362
+	 * @throws EE_Error
2363
+	 */
2364
+	public function _reg_registrant_side_meta_box()
2365
+	{
2366
+		/*@var $attendee EE_Attendee */
2367
+		$att_check = $this->_registration->attendee();
2368
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2369
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2370
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2371
+		//primary registration object (that way we know if we need to show create button or not)
2372
+		if ( ! $this->_registration->is_primary_registrant()) {
2373
+			$primary_registration = $this->_registration->get_primary_registration();
2374
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2375
+				: null;
2376
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2377
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2378
+				//custom attendee object so let's not worry about the primary reg.
2379
+				$primary_registration = null;
2380
+			}
2381
+		} else {
2382
+			$primary_registration = null;
2383
+		}
2384
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2385
+		$this->_template_args['fname']             = $attendee->fname();
2386
+		$this->_template_args['lname']             = $attendee->lname();
2387
+		$this->_template_args['email']             = $attendee->email();
2388
+		$this->_template_args['phone']             = $attendee->phone();
2389
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2390
+		//edit link
2391
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2392
+			'action' => 'edit_attendee',
2393
+			'post'   => $attendee->ID(),
2394
+		), REG_ADMIN_URL);
2395
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2396
+		//create link
2397
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2398
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2399
+				'action'  => 'duplicate_attendee',
2400
+				'_REG_ID' => $this->_registration->ID(),
2401
+			), REG_ADMIN_URL) : '';
2402
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2403
+		$this->_template_args['att_check']    = $att_check;
2404
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2405
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2406
+	}
2407
+
2408
+
2409
+	/**
2410
+	 * trash or restore registrations
2411
+	 *
2412
+	 * @param  boolean $trash whether to archive or restore
2413
+	 * @return void
2414
+	 * @throws EE_Error
2415
+	 * @throws RuntimeException
2416
+	 * @access protected
2417
+	 */
2418
+	protected function _trash_or_restore_registrations($trash = true)
2419
+	{
2420
+		//if empty _REG_ID then get out because there's nothing to do
2421
+		if (empty($this->_req_data['_REG_ID'])) {
2422
+			EE_Error::add_error(
2423
+				sprintf(
2424
+					esc_html__(
2425
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2426
+						'event_espresso'
2427
+					),
2428
+					$trash ? 'trash' : 'restore'
2429
+				),
2430
+				__FILE__, __LINE__, __FUNCTION__
2431
+			);
2432
+			$this->_redirect_after_action(false, '', '', array(), true);
2433
+		}
2434
+		$success = 0;
2435
+		$overwrite_msgs = false;
2436
+		//Checkboxes
2437
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2438
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2439
+		}
2440
+		$reg_count = count($this->_req_data['_REG_ID']);
2441
+		// cycle thru checkboxes
2442
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2443
+			/** @var EE_Registration $REG */
2444
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2445
+			$payments = $REG->registration_payments();
2446
+			if (! empty($payments)) {
2447
+				$name = $REG->attendee() instanceof EE_Attendee
2448
+					? $REG->attendee()->full_name()
2449
+					: esc_html__('Unknown Attendee', 'event_espresso');
2450
+				$overwrite_msgs = true;
2451
+				EE_Error::add_error(
2452
+					sprintf(
2453
+						esc_html__(
2454
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2455
+							'event_espresso'
2456
+						),
2457
+						$name
2458
+					),
2459
+					__FILE__, __FUNCTION__, __LINE__
2460
+				);
2461
+				//can't trash this registration because it has payments.
2462
+				continue;
2463
+			}
2464
+			$updated = $trash ? $REG->delete() : $REG->restore();
2465
+			if ($updated) {
2466
+				$success++;
2467
+			}
2468
+		}
2469
+		$this->_redirect_after_action(
2470
+			$success === $reg_count, // were ALL registrations affected?
2471
+			$success > 1
2472
+				? esc_html__('Registrations', 'event_espresso')
2473
+				: esc_html__('Registration', 'event_espresso'),
2474
+			$trash
2475
+				? esc_html__('moved to the trash', 'event_espresso')
2476
+				: esc_html__('restored', 'event_espresso'),
2477
+			array('action' => 'default'),
2478
+			$overwrite_msgs
2479
+		);
2480
+	}
2481
+
2482
+
2483
+	/**
2484
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2485
+	 * registration but also.
2486
+	 * 1. Removing relations to EE_Attendee
2487
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2488
+	 * ALSO trashed.
2489
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2490
+	 * 4. Removing relationships between all tickets and the related registrations
2491
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2492
+	 * 6. Deleting permanently any related Checkins.
2493
+	 *
2494
+	 * @return void
2495
+	 * @throws EE_Error
2496
+	 */
2497
+	protected function _delete_registrations()
2498
+	{
2499
+		$REG_MDL = EEM_Registration::instance();
2500
+		$success = 1;
2501
+		//Checkboxes
2502
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2503
+			// if array has more than one element than success message should be plural
2504
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2505
+			// cycle thru checkboxes
2506
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2507
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2508
+				if ( ! $REG instanceof EE_Registration) {
2509
+					continue;
2510
+				}
2511
+				$deleted = $this->_delete_registration($REG);
2512
+				if ( ! $deleted) {
2513
+					$success = 0;
2514
+				}
2515
+			}
2516
+		} else {
2517
+			// grab single id and delete
2518
+			$REG_ID  = $this->_req_data['_REG_ID'];
2519
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2520
+			$deleted = $this->_delete_registration($REG);
2521
+			if ( ! $deleted) {
2522
+				$success = 0;
2523
+			}
2524
+		}
2525
+		$what        = $success > 1
2526
+			? esc_html__('Registrations', 'event_espresso')
2527
+			: esc_html__('Registration', 'event_espresso');
2528
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2529
+		$this->_redirect_after_action(
2530
+			$success,
2531
+			$what,
2532
+			$action_desc,
2533
+			array('action' => 'default'),
2534
+			true
2535
+		);
2536
+	}
2537
+
2538
+
2539
+	/**
2540
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2541
+	 * models get affected.
2542
+	 *
2543
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2544
+	 * @return bool true = successful deletion, false = fail.
2545
+	 * @throws EE_Error
2546
+	 */
2547
+	protected function _delete_registration(EE_Registration $REG)
2548
+	{
2549
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2550
+		//registrations on the transaction that are NOT trashed.
2551
+		$TXN         = $REG->get_first_related('Transaction');
2552
+		$REGS        = $TXN->get_many_related('Registration');
2553
+		$all_trashed = true;
2554
+		foreach ($REGS as $registration) {
2555
+			if ( ! $registration->get('REG_deleted')) {
2556
+				$all_trashed = false;
2557
+			}
2558
+		}
2559
+		if ( ! $all_trashed) {
2560
+			EE_Error::add_error(
2561
+				esc_html__(
2562
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2563
+					'event_espresso'
2564
+				),
2565
+				__FILE__, __FUNCTION__, __LINE__
2566
+			);
2567
+			return false;
2568
+		}
2569
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2570
+		//separately from THIS one).
2571
+		foreach ($REGS as $registration) {
2572
+			//delete related answers
2573
+			$registration->delete_related_permanently('Answer');
2574
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2575
+			$attendee = $registration->get_first_related('Attendee');
2576
+			if ($attendee instanceof EE_Attendee) {
2577
+				$registration->_remove_relation_to($attendee, 'Attendee');
2578
+			}
2579
+			//now remove relationships to tickets on this registration.
2580
+			$registration->_remove_relations('Ticket');
2581
+			//now delete permanently the checkins related to this registration.
2582
+			$registration->delete_related_permanently('Checkin');
2583
+			if ($registration->ID() === $REG->ID()) {
2584
+				continue;
2585
+			} //we don't want to delete permanently the existing registration just yet.
2586
+			//remove relation to transaction for these registrations if NOT the existing registrations
2587
+			$registration->_remove_relations('Transaction');
2588
+			//delete permanently any related messages.
2589
+			$registration->delete_related_permanently('Message');
2590
+			//now delete this registration permanently
2591
+			$registration->delete_permanently();
2592
+		}
2593
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2594
+		// (the transaction and line items should be all that's left).
2595
+		// delete the line items related to the transaction for this registration.
2596
+		$TXN->delete_related_permanently('Line_Item');
2597
+		//we need to remove all the relationships on the transaction
2598
+		$TXN->delete_related_permanently('Payment');
2599
+		$TXN->delete_related_permanently('Extra_Meta');
2600
+		$TXN->delete_related_permanently('Message');
2601
+		//now we can delete this REG permanently (and the transaction of course)
2602
+		$REG->delete_related_permanently('Transaction');
2603
+		return $REG->delete_permanently();
2604
+	}
2605
+
2606
+
2607
+	/**
2608
+	 *    generates HTML for the Register New Attendee Admin page
2609
+	 *
2610
+	 * @access private
2611
+	 * @throws DomainException
2612
+	 * @throws EE_Error
2613
+	 */
2614
+	public function new_registration()
2615
+	{
2616
+		if ( ! $this->_set_reg_event()) {
2617
+			throw new EE_Error(
2618
+				esc_html__(
2619
+					'Unable to continue with registering because there is no Event ID in the request',
2620
+					'event_espresso'
2621
+				)
2622
+			);
2623
+		}
2624
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2625
+		// gotta start with a clean slate if we're not coming here via ajax
2626
+		if ( ! defined('DOING_AJAX')
2627
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2628
+		) {
2629
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2630
+		}
2631
+		$this->_template_args['event_name'] = '';
2632
+		// event name
2633
+		if ($this->_reg_event) {
2634
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2635
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2636
+				'action' => 'edit',
2637
+				'post'   => $this->_reg_event->ID(),
2638
+			), EVENTS_ADMIN_URL);
2639
+			$edit_event_lnk                     = '<a href="'
2640
+												  . $edit_event_url
2641
+												  . '" title="'
2642
+												  . esc_attr__('Edit ', 'event_espresso')
2643
+												  . $this->_reg_event->name()
2644
+												  . '">'
2645
+												  . esc_html__('Edit Event', 'event_espresso')
2646
+												  . '</a>';
2647
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2648
+												   . $edit_event_lnk
2649
+												   . '</span>';
2650
+		}
2651
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2652
+		if (defined('DOING_AJAX')) {
2653
+			$this->_return_json();
2654
+		}
2655
+		// grab header
2656
+		$template_path                              =
2657
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2658
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2659
+			$this->_template_args, true);
2660
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2661
+		// the details template wrapper
2662
+		$this->display_admin_page_with_sidebar();
2663
+	}
2664
+
2665
+
2666
+	/**
2667
+	 * This returns the content for a registration step
2668
+	 *
2669
+	 * @access protected
2670
+	 * @return string html
2671
+	 * @throws DomainException
2672
+	 * @throws EE_Error
2673
+	 */
2674
+	protected function _get_registration_step_content()
2675
+	{
2676
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2677
+			$warning_msg = sprintf(
2678
+				esc_html__(
2679
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2680
+					'event_espresso'
2681
+				),
2682
+				'<br />',
2683
+				'<h3 class="important-notice">',
2684
+				'</h3>',
2685
+				'<div class="float-right">',
2686
+				'<span id="redirect_timer" class="important-notice">30</span>',
2687
+				'</div>',
2688
+				'<b>',
2689
+				'</b>'
2690
+			);
2691
+			return '
2692 2692
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2693 2693
 	<script >
2694 2694
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2701,792 +2701,792 @@  discard block
 block discarded – undo
2701 2701
 	        }
2702 2702
 	    }, 800 );
2703 2703
 	</script >';
2704
-        }
2705
-        $template_args = array(
2706
-            'title'                    => '',
2707
-            'content'                  => '',
2708
-            'step_button_text'         => '',
2709
-            'show_notification_toggle' => false,
2710
-        );
2711
-        //to indicate we're processing a new registration
2712
-        $hidden_fields = array(
2713
-            'processing_registration' => array(
2714
-                'type'  => 'hidden',
2715
-                'value' => 0,
2716
-            ),
2717
-            'event_id'                => array(
2718
-                'type'  => 'hidden',
2719
-                'value' => $this->_reg_event->ID(),
2720
-            ),
2721
-        );
2722
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2723
-        $cart = EE_Registry::instance()->SSN->cart();
2724
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2725
-        switch ($step) {
2726
-            case 'ticket' :
2727
-                $hidden_fields['processing_registration']['value'] = 1;
2728
-                $template_args['title']                            = esc_html__(
2729
-                    'Step One: Select the Ticket for this registration',
2730
-                    'event_espresso'
2731
-                );
2732
-                $template_args['content']                          =
2733
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2734
-                $template_args['step_button_text']                 = esc_html__(
2735
-                    'Add Tickets and Continue to Registrant Details',
2736
-                    'event_espresso'
2737
-                );
2738
-                $template_args['show_notification_toggle']         = false;
2739
-                break;
2740
-            case 'questions' :
2741
-                $hidden_fields['processing_registration']['value'] = 2;
2742
-                $template_args['title']                            = esc_html__(
2743
-                    'Step Two: Add Registrant Details for this Registration',
2744
-                    'event_espresso'
2745
-                );
2746
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2747
-                // properly by the first process_reg_step run.
2748
-                $template_args['content']                  =
2749
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2750
-                $template_args['step_button_text']         = esc_html__(
2751
-                    'Save Registration and Continue to Details',
2752
-                    'event_espresso'
2753
-                );
2754
-                $template_args['show_notification_toggle'] = true;
2755
-                break;
2756
-        }
2757
-        //we come back to the process_registration_step route.
2758
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2759
-        return EEH_Template::display_template(
2760
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2761
-            $template_args,
2762
-            true
2763
-        );
2764
-    }
2765
-
2766
-
2767
-    /**
2768
-     *        set_reg_event
2769
-     *
2770
-     * @access private
2771
-     * @return bool
2772
-     * @throws EE_Error
2773
-     */
2774
-    private function _set_reg_event()
2775
-    {
2776
-        if (is_object($this->_reg_event)) {
2777
-            return true;
2778
-        }
2779
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2780
-        if ( ! $EVT_ID) {
2781
-            return false;
2782
-        }
2783
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2784
-        return true;
2785
-    }
2786
-
2787
-
2788
-    /**
2789
-     * process_reg_step
2790
-     *
2791
-     * @access        public
2792
-     * @return string
2793
-     * @throws DomainException
2794
-     * @throws EE_Error
2795
-     * @throws RuntimeException
2796
-     */
2797
-    public function process_reg_step()
2798
-    {
2799
-        EE_System::do_not_cache();
2800
-        $this->_set_reg_event();
2801
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2802
-        EE_Registry::instance()->REQ->set('uts', time());
2803
-        //what step are we on?
2804
-        $cart = EE_Registry::instance()->SSN->cart();
2805
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2806
-        //if doing ajax then we need to verify the nonce
2807
-        if (defined('DOING_AJAX')) {
2808
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2809
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2810
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2811
-        }
2812
-        switch ($step) {
2813
-            case 'ticket' :
2814
-                //process ticket selection
2815
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2816
-                if ($success) {
2817
-                    EE_Error::add_success(
2818
-                        esc_html__(
2819
-                            'Tickets Selected. Now complete the registration.',
2820
-                            'event_espresso'
2821
-                        )
2822
-                    );
2823
-                } else {
2824
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2825
-                }
2826
-                if (defined('DOING_AJAX')) {
2827
-                    $this->new_registration(); //display next step
2828
-                } else {
2829
-                    $query_args = array(
2830
-                        'action'                  => 'new_registration',
2831
-                        'processing_registration' => 1,
2832
-                        'event_id'                => $this->_reg_event->ID(),
2833
-                        'uts'                     => time(),
2834
-                    );
2835
-                    $this->_redirect_after_action(
2836
-                        false,
2837
-                        '',
2838
-                        '',
2839
-                        $query_args,
2840
-                        true
2841
-                    );
2842
-                }
2843
-                break;
2844
-            case 'questions' :
2845
-                if (! isset(
2846
-                    $this->_req_data['txn_reg_status_change'],
2847
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
2848
-                ) {
2849
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2850
-                }
2851
-                //process registration
2852
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2853
-                if ($cart instanceof EE_Cart) {
2854
-                    $grand_total = $cart->get_cart_grand_total();
2855
-                    if ($grand_total instanceof EE_Line_Item) {
2856
-                        $grand_total->save_this_and_descendants_to_txn();
2857
-                    }
2858
-                }
2859
-                if ( ! $transaction instanceof EE_Transaction) {
2860
-                    $query_args = array(
2861
-                        'action'                  => 'new_registration',
2862
-                        'processing_registration' => 2,
2863
-                        'event_id'                => $this->_reg_event->ID(),
2864
-                        'uts'                     => time(),
2865
-                    );
2866
-                    if (defined('DOING_AJAX')) {
2867
-                        //display registration form again because there are errors (maybe validation?)
2868
-                        $this->new_registration();
2869
-                        return;
2870
-                    } else {
2871
-                        $this->_redirect_after_action(
2872
-                            false,
2873
-                            '',
2874
-                            '',
2875
-                            $query_args,
2876
-                            true
2877
-                        );
2878
-                        return;
2879
-                    }
2880
-                }
2881
-                // maybe update status, and make sure to save transaction if not done already
2882
-                if ( ! $transaction->update_status_based_on_total_paid()) {
2883
-                    $transaction->save();
2884
-                }
2885
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2886
-                $this->_req_data = array();
2887
-                $query_args      = array(
2888
-                    'action'        => 'redirect_to_txn',
2889
-                    'TXN_ID'        => $transaction->ID(),
2890
-                    'EVT_ID'        => $this->_reg_event->ID(),
2891
-                    'event_name'    => urlencode($this->_reg_event->name()),
2892
-                    'redirect_from' => 'new_registration',
2893
-                );
2894
-                $this->_redirect_after_action(false, '', '', $query_args, true);
2895
-                break;
2896
-        }
2897
-        //what are you looking here for?  Should be nothing to do at this point.
2898
-    }
2899
-
2900
-
2901
-    /**
2902
-     * redirect_to_txn
2903
-     *
2904
-     * @access public
2905
-     * @return void
2906
-     * @throws EE_Error
2907
-     */
2908
-    public function redirect_to_txn()
2909
-    {
2910
-        EE_System::do_not_cache();
2911
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2912
-        $query_args = array(
2913
-            'action' => 'view_transaction',
2914
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2915
-            'page'   => 'espresso_transactions',
2916
-        );
2917
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2918
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2919
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
2920
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
2921
-        }
2922
-        EE_Error::add_success(
2923
-            esc_html__(
2924
-                'Registration Created.  Please review the transaction and add any payments as necessary',
2925
-                'event_espresso'
2926
-            )
2927
-        );
2928
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2929
-    }
2930
-
2931
-
2932
-    /**
2933
-     *        generates HTML for the Attendee Contact List
2934
-     *
2935
-     * @access protected
2936
-     * @return void
2937
-     */
2938
-    protected function _attendee_contact_list_table()
2939
-    {
2940
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2941
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
2942
-        $this->display_admin_list_table_page_with_no_sidebar();
2943
-    }
2944
-
2945
-
2946
-    /**
2947
-     *        get_attendees
2948
-     *
2949
-     * @param      $per_page
2950
-     * @param bool $count whether to return count or data.
2951
-     * @param bool $trash
2952
-     * @return array
2953
-     * @throws EE_Error
2954
-     * @access public
2955
-     */
2956
-    public function get_attendees($per_page, $count = false, $trash = false)
2957
-    {
2958
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2959
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2960
-        $ATT_MDL                    = EEM_Attendee::instance();
2961
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2962
-        switch ($this->_req_data['orderby']) {
2963
-            case 'ATT_ID':
2964
-                $orderby = 'ATT_ID';
2965
-                break;
2966
-            case 'ATT_fname':
2967
-                $orderby = 'ATT_fname';
2968
-                break;
2969
-            case 'ATT_email':
2970
-                $orderby = 'ATT_email';
2971
-                break;
2972
-            case 'ATT_city':
2973
-                $orderby = 'ATT_city';
2974
-                break;
2975
-            case 'STA_ID':
2976
-                $orderby = 'STA_ID';
2977
-                break;
2978
-            case 'CNT_ID':
2979
-                $orderby = 'CNT_ID';
2980
-                break;
2981
-            default:
2982
-                $orderby = 'ATT_lname';
2983
-        }
2984
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
2985
-            ? $this->_req_data['order']
2986
-            : 'ASC';
2987
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2988
-            ? $this->_req_data['paged']
2989
-            : 1;
2990
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2991
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2992
-            ? $this->_req_data['perpage']
2993
-            : $per_page;
2994
-        $_where       = array();
2995
-        if ( ! empty($this->_req_data['s'])) {
2996
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2997
-            $_where['OR'] = array(
2998
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2999
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3000
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3001
-                'ATT_fname'                         => array('LIKE', $sstr),
3002
-                'ATT_lname'                         => array('LIKE', $sstr),
3003
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3004
-                'ATT_email'                         => array('LIKE', $sstr),
3005
-                'ATT_address'                       => array('LIKE', $sstr),
3006
-                'ATT_address2'                      => array('LIKE', $sstr),
3007
-                'ATT_city'                          => array('LIKE', $sstr),
3008
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3009
-                'State.STA_name'                    => array('LIKE', $sstr),
3010
-                'ATT_phone'                         => array('LIKE', $sstr),
3011
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3012
-                'Registration.REG_code'             => array('LIKE', $sstr),
3013
-                'Registration.REG_count'            => array('LIKE', $sstr),
3014
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3015
-            );
3016
-        }
3017
-        $offset = ($current_page - 1) * $per_page;
3018
-        $limit  = $count ? null : array($offset, $per_page);
3019
-        if ($trash) {
3020
-            $_where['status'] = array('!=', 'publish');
3021
-            $all_attendees    = $count
3022
-                ? $ATT_MDL->count(array(
3023
-                    $_where,
3024
-                    'order_by' => array($orderby => $sort),
3025
-                    'limit'    => $limit,
3026
-                ), 'ATT_ID', true)
3027
-                : $ATT_MDL->get_all(array(
3028
-                    $_where,
3029
-                    'order_by' => array($orderby => $sort),
3030
-                    'limit'    => $limit,
3031
-                ));
3032
-        } else {
3033
-            $_where['status'] = array('IN', array('publish'));
3034
-            $all_attendees    = $count
3035
-                ? $ATT_MDL->count(array(
3036
-                    $_where,
3037
-                    'order_by' => array($orderby => $sort),
3038
-                    'limit'    => $limit,
3039
-                ), 'ATT_ID', true)
3040
-                : $ATT_MDL->get_all(array(
3041
-                    $_where,
3042
-                    'order_by' => array($orderby => $sort),
3043
-                    'limit'    => $limit,
3044
-                ));
3045
-        }
3046
-        return $all_attendees;
3047
-    }
3048
-
3049
-
3050
-    /**
3051
-     * This is just taking care of resending the registration confirmation
3052
-     *
3053
-     * @access protected
3054
-     * @return void
3055
-     */
3056
-    protected function _resend_registration()
3057
-    {
3058
-        $this->_process_resend_registration();
3059
-        $query_args = isset($this->_req_data['redirect_to'])
3060
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3061
-            : array('action' => 'default');
3062
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3063
-    }
3064
-
3065
-    /**
3066
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3067
-     * to use when selecting registrations
3068
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3069
-     *                                                     the query parameters from the request
3070
-     * @return void ends the request with a redirect or download
3071
-     */
3072
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3073
-    {
3074
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3075
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3076
-                array(
3077
-                    'page'        => 'espresso_batch',
3078
-                    'batch'       => 'file',
3079
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3080
-                    'filters'     => urlencode(
3081
-                        serialize(
3082
-                            call_user_func(
3083
-                                array( $this, $method_name_for_getting_query_params ),
3084
-                                EEH_Array::is_set(
3085
-                                    $this->_req_data,
3086
-                                    'filters',
3087
-                                    array()
3088
-                                )
3089
-                            )
3090
-                        )
3091
-                ),
3092
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3093
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3094
-                'return_url'  => urlencode($this->_req_data['return_url']),
3095
-            )));
3096
-        } else {
3097
-            $new_request_args = array(
3098
-                'export' => 'report',
3099
-                'action' => 'registrations_report_for_event',
3100
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3101
-            );
3102
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3103
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3104
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3105
-                $EE_Export = EE_Export::instance($this->_req_data);
3106
-                $EE_Export->export();
3107
-            }
3108
-        }
3109
-    }
3110
-
3111
-
3112
-
3113
-    /**
3114
-     * Creates a registration report using only query parameters in the request
3115
-     * @return void
3116
-     */
3117
-    public function _registrations_report()
3118
-    {
3119
-        $this->_registrations_report_base('_get_registration_query_parameters');
3120
-    }
3121
-
3122
-
3123
-    public function _contact_list_export()
3124
-    {
3125
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3126
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3127
-            $EE_Export = EE_Export::instance($this->_req_data);
3128
-            $EE_Export->export_attendees();
3129
-        }
3130
-    }
3131
-
3132
-
3133
-    public function _contact_list_report()
3134
-    {
3135
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3136
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3137
-                'page'        => 'espresso_batch',
3138
-                'batch'       => 'file',
3139
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3140
-                'return_url'  => urlencode($this->_req_data['return_url']),
3141
-            )));
3142
-        } else {
3143
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3144
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3145
-                $EE_Export = EE_Export::instance($this->_req_data);
3146
-                $EE_Export->report_attendees();
3147
-            }
3148
-        }
3149
-    }
3150
-
3151
-
3152
-
3153
-
3154
-
3155
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3156
-    /**
3157
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3158
-     *
3159
-     * @return void
3160
-     * @throws EE_Error
3161
-     */
3162
-    protected function _duplicate_attendee()
3163
-    {
3164
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3165
-        //verify we have necessary info
3166
-        if (empty($this->_req_data['_REG_ID'])) {
3167
-            EE_Error::add_error(
3168
-                esc_html__(
3169
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3170
-                    'event_espresso'
3171
-                ), __FILE__, __LINE__, __FUNCTION__
3172
-            );
3173
-            $query_args = array('action' => $action);
3174
-            $this->_redirect_after_action('', '', '', $query_args, true);
3175
-        }
3176
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3177
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3178
-        $attendee     = $registration->attendee();
3179
-        //remove relation of existing attendee on registration
3180
-        $registration->_remove_relation_to($attendee, 'Attendee');
3181
-        //new attendee
3182
-        $new_attendee = clone $attendee;
3183
-        $new_attendee->set('ATT_ID', 0);
3184
-        $new_attendee->save();
3185
-        //add new attendee to reg
3186
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3187
-        EE_Error::add_success(
3188
-            esc_html__(
3189
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3190
-                'event_espresso'
3191
-            )
3192
-        );
3193
-        //redirect to edit page for attendee
3194
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3195
-        $this->_redirect_after_action('', '', '', $query_args, true);
3196
-    }
3197
-
3198
-
3199
-    //related to cpt routes
3200
-    protected function _insert_update_cpt_item($post_id, $post)
3201
-    {
3202
-        $success  = true;
3203
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3204
-        //for attendee updates
3205
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3206
-            //note we should only be UPDATING attendees at this point.
3207
-            $updated_fields = array(
3208
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3209
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3210
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3211
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3212
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3213
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3214
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3215
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3216
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3217
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3218
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3219
-            );
3220
-            foreach ($updated_fields as $field => $value) {
3221
-                $attendee->set($field, $value);
3222
-            }
3223
-            $success                   = $attendee->save();
3224
-            $attendee_update_callbacks = apply_filters(
3225
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3226
-                array()
3227
-            );
3228
-            foreach ($attendee_update_callbacks as $a_callback) {
3229
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3230
-                    throw new EE_Error(
3231
-                        sprintf(
3232
-                            esc_html__(
3233
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3234
-                                'event_espresso'
3235
-                            ),
3236
-                            $a_callback
3237
-                        )
3238
-                    );
3239
-                }
3240
-            }
3241
-        }
3242
-        if ($success === false) {
3243
-            EE_Error::add_error(
3244
-                esc_html__(
3245
-                    'Something went wrong with updating the meta table data for the registration.',
3246
-                    'event_espresso'
3247
-                ),
3248
-                __FILE__, __FUNCTION__, __LINE__
3249
-            );
3250
-        }
3251
-    }
3252
-
3253
-
3254
-    public function trash_cpt_item($post_id)
3255
-    {
3256
-    }
3257
-
3258
-
3259
-    public function delete_cpt_item($post_id)
3260
-    {
3261
-    }
3262
-
3263
-
3264
-    public function restore_cpt_item($post_id)
3265
-    {
3266
-    }
3267
-
3268
-
3269
-    protected function _restore_cpt_item($post_id, $revision_id)
3270
-    {
3271
-    }
3272
-
3273
-
3274
-    public function attendee_editor_metaboxes()
3275
-    {
3276
-        $this->verify_cpt_object();
3277
-        remove_meta_box(
3278
-            'postexcerpt',
3279
-            esc_html__('Excerpt', 'event_espresso'),
3280
-            'post_excerpt_meta_box',
3281
-            $this->_cpt_routes[$this->_req_action],
3282
-            'normal',
3283
-            'core'
3284
-        );
3285
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3286
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3287
-            add_meta_box(
3288
-                'postexcerpt',
3289
-                esc_html__('Short Biography', 'event_espresso'),
3290
-                'post_excerpt_meta_box',
3291
-                $this->_cpt_routes[$this->_req_action],
3292
-                'normal'
3293
-            );
3294
-        }
3295
-        if (post_type_supports('espresso_attendees', 'comments')) {
3296
-            add_meta_box(
3297
-                'commentsdiv',
3298
-                esc_html__('Notes on the Contact', 'event_espresso'),
3299
-                'post_comment_meta_box',
3300
-                $this->_cpt_routes[$this->_req_action],
3301
-                'normal',
3302
-                'core'
3303
-            );
3304
-        }
3305
-        add_meta_box(
3306
-            'attendee_contact_info',
3307
-            esc_html__('Contact Info', 'event_espresso'),
3308
-            array($this, 'attendee_contact_info'),
3309
-            $this->_cpt_routes[$this->_req_action],
3310
-            'side',
3311
-            'core'
3312
-        );
3313
-        add_meta_box(
3314
-            'attendee_details_address',
3315
-            esc_html__('Address Details', 'event_espresso'),
3316
-            array($this, 'attendee_address_details'),
3317
-            $this->_cpt_routes[$this->_req_action],
3318
-            'normal',
3319
-            'core'
3320
-        );
3321
-        add_meta_box(
3322
-            'attendee_registrations',
3323
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3324
-            array($this, 'attendee_registrations_meta_box'),
3325
-            $this->_cpt_routes[$this->_req_action],
3326
-            'normal',
3327
-            'high'
3328
-        );
3329
-    }
3330
-
3331
-
3332
-    /**
3333
-     * Metabox for attendee contact info
3334
-     *
3335
-     * @param  WP_Post $post wp post object
3336
-     * @return string attendee contact info ( and form )
3337
-     * @throws DomainException
3338
-     */
3339
-    public function attendee_contact_info($post)
3340
-    {
3341
-        //get attendee object ( should already have it )
3342
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3343
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3344
-        EEH_Template::display_template($template, $this->_template_args);
3345
-    }
3346
-
3347
-
3348
-    /**
3349
-     * Metabox for attendee details
3350
-     *
3351
-     * @param  WP_Post $post wp post object
3352
-     * @return string attendee address details (and form)
3353
-     * @throws DomainException
3354
-     */
3355
-    public function attendee_address_details($post)
3356
-    {
3357
-        //get attendee object (should already have it)
3358
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3359
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3360
-            new EE_Question_Form_Input(
3361
-                EE_Question::new_instance(
3362
-                    array(
3363
-                        'QST_ID'           => 0,
3364
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3365
-                        'QST_system'       => 'admin-state',
3366
-                    )
3367
-                ),
3368
-                EE_Answer::new_instance(
3369
-                    array(
3370
-                        'ANS_ID'    => 0,
3371
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3372
-                    )
3373
-                ),
3374
-                array(
3375
-                    'input_id'       => 'STA_ID',
3376
-                    'input_name'     => 'STA_ID',
3377
-                    'input_prefix'   => '',
3378
-                    'append_qstn_id' => false,
3379
-                )
3380
-            )
3381
-        );
3382
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3383
-            new EE_Question_Form_Input(
3384
-                EE_Question::new_instance(
3385
-                    array(
3386
-                        'QST_ID'           => 0,
3387
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3388
-                        'QST_system'       => 'admin-country',
3389
-                    )
3390
-                ),
3391
-                EE_Answer::new_instance(
3392
-                    array(
3393
-                        'ANS_ID'    => 0,
3394
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3395
-                    )
3396
-                ),
3397
-                array(
3398
-                    'input_id'       => 'CNT_ISO',
3399
-                    'input_name'     => 'CNT_ISO',
3400
-                    'input_prefix'   => '',
3401
-                    'append_qstn_id' => false,
3402
-                )
3403
-            )
3404
-        );
3405
-        $template                             =
3406
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3407
-        EEH_Template::display_template($template, $this->_template_args);
3408
-    }
3409
-
3410
-
3411
-    /**
3412
-     *        _attendee_details
3413
-     *
3414
-     * @access protected
3415
-     * @param $post
3416
-     * @return void
3417
-     * @throws DomainException
3418
-     * @throws EE_Error
3419
-     */
3420
-    public function attendee_registrations_meta_box($post)
3421
-    {
3422
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3423
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3424
-        $template                              =
3425
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3426
-        EEH_Template::display_template($template, $this->_template_args);
3427
-    }
3428
-
3429
-
3430
-    /**
3431
-     * add in the form fields for the attendee edit
3432
-     *
3433
-     * @param  WP_Post $post wp post object
3434
-     * @return string html for new form.
3435
-     * @throws DomainException
3436
-     */
3437
-    public function after_title_form_fields($post)
3438
-    {
3439
-        if ($post->post_type == 'espresso_attendees') {
3440
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3441
-            $template_args['attendee'] = $this->_cpt_model_obj;
3442
-            EEH_Template::display_template($template, $template_args);
3443
-        }
3444
-    }
3445
-
3446
-
3447
-    /**
3448
-     *        _trash_or_restore_attendee
3449
-     *
3450
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3451
-     * @return void
3452
-     * @throws EE_Error
3453
-     * @access protected
3454
-     */
3455
-    protected function _trash_or_restore_attendees($trash = true)
3456
-    {
3457
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3458
-        $ATT_MDL = EEM_Attendee::instance();
3459
-        $success = 1;
3460
-        //Checkboxes
3461
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3462
-            // if array has more than one element than success message should be plural
3463
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3464
-            // cycle thru checkboxes
3465
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3466
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3467
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3468
-                if ( ! $updated) {
3469
-                    $success = 0;
3470
-                }
3471
-            }
3472
-        } else {
3473
-            // grab single id and delete
3474
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3475
-            //get attendee
3476
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3477
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3478
-            $updated = $att->save();
3479
-            if ( ! $updated) {
3480
-                $success = 0;
3481
-            }
3482
-        }
3483
-        $what        = $success > 1
3484
-            ? esc_html__('Contacts', 'event_espresso')
3485
-            : esc_html__('Contact', 'event_espresso');
3486
-        $action_desc = $trash
3487
-            ? esc_html__('moved to the trash', 'event_espresso')
3488
-            : esc_html__('restored', 'event_espresso');
3489
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3490
-    }
2704
+		}
2705
+		$template_args = array(
2706
+			'title'                    => '',
2707
+			'content'                  => '',
2708
+			'step_button_text'         => '',
2709
+			'show_notification_toggle' => false,
2710
+		);
2711
+		//to indicate we're processing a new registration
2712
+		$hidden_fields = array(
2713
+			'processing_registration' => array(
2714
+				'type'  => 'hidden',
2715
+				'value' => 0,
2716
+			),
2717
+			'event_id'                => array(
2718
+				'type'  => 'hidden',
2719
+				'value' => $this->_reg_event->ID(),
2720
+			),
2721
+		);
2722
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2723
+		$cart = EE_Registry::instance()->SSN->cart();
2724
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2725
+		switch ($step) {
2726
+			case 'ticket' :
2727
+				$hidden_fields['processing_registration']['value'] = 1;
2728
+				$template_args['title']                            = esc_html__(
2729
+					'Step One: Select the Ticket for this registration',
2730
+					'event_espresso'
2731
+				);
2732
+				$template_args['content']                          =
2733
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2734
+				$template_args['step_button_text']                 = esc_html__(
2735
+					'Add Tickets and Continue to Registrant Details',
2736
+					'event_espresso'
2737
+				);
2738
+				$template_args['show_notification_toggle']         = false;
2739
+				break;
2740
+			case 'questions' :
2741
+				$hidden_fields['processing_registration']['value'] = 2;
2742
+				$template_args['title']                            = esc_html__(
2743
+					'Step Two: Add Registrant Details for this Registration',
2744
+					'event_espresso'
2745
+				);
2746
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2747
+				// properly by the first process_reg_step run.
2748
+				$template_args['content']                  =
2749
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2750
+				$template_args['step_button_text']         = esc_html__(
2751
+					'Save Registration and Continue to Details',
2752
+					'event_espresso'
2753
+				);
2754
+				$template_args['show_notification_toggle'] = true;
2755
+				break;
2756
+		}
2757
+		//we come back to the process_registration_step route.
2758
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2759
+		return EEH_Template::display_template(
2760
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2761
+			$template_args,
2762
+			true
2763
+		);
2764
+	}
2765
+
2766
+
2767
+	/**
2768
+	 *        set_reg_event
2769
+	 *
2770
+	 * @access private
2771
+	 * @return bool
2772
+	 * @throws EE_Error
2773
+	 */
2774
+	private function _set_reg_event()
2775
+	{
2776
+		if (is_object($this->_reg_event)) {
2777
+			return true;
2778
+		}
2779
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2780
+		if ( ! $EVT_ID) {
2781
+			return false;
2782
+		}
2783
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2784
+		return true;
2785
+	}
2786
+
2787
+
2788
+	/**
2789
+	 * process_reg_step
2790
+	 *
2791
+	 * @access        public
2792
+	 * @return string
2793
+	 * @throws DomainException
2794
+	 * @throws EE_Error
2795
+	 * @throws RuntimeException
2796
+	 */
2797
+	public function process_reg_step()
2798
+	{
2799
+		EE_System::do_not_cache();
2800
+		$this->_set_reg_event();
2801
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2802
+		EE_Registry::instance()->REQ->set('uts', time());
2803
+		//what step are we on?
2804
+		$cart = EE_Registry::instance()->SSN->cart();
2805
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2806
+		//if doing ajax then we need to verify the nonce
2807
+		if (defined('DOING_AJAX')) {
2808
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2809
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2810
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2811
+		}
2812
+		switch ($step) {
2813
+			case 'ticket' :
2814
+				//process ticket selection
2815
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2816
+				if ($success) {
2817
+					EE_Error::add_success(
2818
+						esc_html__(
2819
+							'Tickets Selected. Now complete the registration.',
2820
+							'event_espresso'
2821
+						)
2822
+					);
2823
+				} else {
2824
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2825
+				}
2826
+				if (defined('DOING_AJAX')) {
2827
+					$this->new_registration(); //display next step
2828
+				} else {
2829
+					$query_args = array(
2830
+						'action'                  => 'new_registration',
2831
+						'processing_registration' => 1,
2832
+						'event_id'                => $this->_reg_event->ID(),
2833
+						'uts'                     => time(),
2834
+					);
2835
+					$this->_redirect_after_action(
2836
+						false,
2837
+						'',
2838
+						'',
2839
+						$query_args,
2840
+						true
2841
+					);
2842
+				}
2843
+				break;
2844
+			case 'questions' :
2845
+				if (! isset(
2846
+					$this->_req_data['txn_reg_status_change'],
2847
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
2848
+				) {
2849
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2850
+				}
2851
+				//process registration
2852
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2853
+				if ($cart instanceof EE_Cart) {
2854
+					$grand_total = $cart->get_cart_grand_total();
2855
+					if ($grand_total instanceof EE_Line_Item) {
2856
+						$grand_total->save_this_and_descendants_to_txn();
2857
+					}
2858
+				}
2859
+				if ( ! $transaction instanceof EE_Transaction) {
2860
+					$query_args = array(
2861
+						'action'                  => 'new_registration',
2862
+						'processing_registration' => 2,
2863
+						'event_id'                => $this->_reg_event->ID(),
2864
+						'uts'                     => time(),
2865
+					);
2866
+					if (defined('DOING_AJAX')) {
2867
+						//display registration form again because there are errors (maybe validation?)
2868
+						$this->new_registration();
2869
+						return;
2870
+					} else {
2871
+						$this->_redirect_after_action(
2872
+							false,
2873
+							'',
2874
+							'',
2875
+							$query_args,
2876
+							true
2877
+						);
2878
+						return;
2879
+					}
2880
+				}
2881
+				// maybe update status, and make sure to save transaction if not done already
2882
+				if ( ! $transaction->update_status_based_on_total_paid()) {
2883
+					$transaction->save();
2884
+				}
2885
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2886
+				$this->_req_data = array();
2887
+				$query_args      = array(
2888
+					'action'        => 'redirect_to_txn',
2889
+					'TXN_ID'        => $transaction->ID(),
2890
+					'EVT_ID'        => $this->_reg_event->ID(),
2891
+					'event_name'    => urlencode($this->_reg_event->name()),
2892
+					'redirect_from' => 'new_registration',
2893
+				);
2894
+				$this->_redirect_after_action(false, '', '', $query_args, true);
2895
+				break;
2896
+		}
2897
+		//what are you looking here for?  Should be nothing to do at this point.
2898
+	}
2899
+
2900
+
2901
+	/**
2902
+	 * redirect_to_txn
2903
+	 *
2904
+	 * @access public
2905
+	 * @return void
2906
+	 * @throws EE_Error
2907
+	 */
2908
+	public function redirect_to_txn()
2909
+	{
2910
+		EE_System::do_not_cache();
2911
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2912
+		$query_args = array(
2913
+			'action' => 'view_transaction',
2914
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2915
+			'page'   => 'espresso_transactions',
2916
+		);
2917
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2918
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2919
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
2920
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
2921
+		}
2922
+		EE_Error::add_success(
2923
+			esc_html__(
2924
+				'Registration Created.  Please review the transaction and add any payments as necessary',
2925
+				'event_espresso'
2926
+			)
2927
+		);
2928
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2929
+	}
2930
+
2931
+
2932
+	/**
2933
+	 *        generates HTML for the Attendee Contact List
2934
+	 *
2935
+	 * @access protected
2936
+	 * @return void
2937
+	 */
2938
+	protected function _attendee_contact_list_table()
2939
+	{
2940
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2941
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
2942
+		$this->display_admin_list_table_page_with_no_sidebar();
2943
+	}
2944
+
2945
+
2946
+	/**
2947
+	 *        get_attendees
2948
+	 *
2949
+	 * @param      $per_page
2950
+	 * @param bool $count whether to return count or data.
2951
+	 * @param bool $trash
2952
+	 * @return array
2953
+	 * @throws EE_Error
2954
+	 * @access public
2955
+	 */
2956
+	public function get_attendees($per_page, $count = false, $trash = false)
2957
+	{
2958
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2959
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2960
+		$ATT_MDL                    = EEM_Attendee::instance();
2961
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2962
+		switch ($this->_req_data['orderby']) {
2963
+			case 'ATT_ID':
2964
+				$orderby = 'ATT_ID';
2965
+				break;
2966
+			case 'ATT_fname':
2967
+				$orderby = 'ATT_fname';
2968
+				break;
2969
+			case 'ATT_email':
2970
+				$orderby = 'ATT_email';
2971
+				break;
2972
+			case 'ATT_city':
2973
+				$orderby = 'ATT_city';
2974
+				break;
2975
+			case 'STA_ID':
2976
+				$orderby = 'STA_ID';
2977
+				break;
2978
+			case 'CNT_ID':
2979
+				$orderby = 'CNT_ID';
2980
+				break;
2981
+			default:
2982
+				$orderby = 'ATT_lname';
2983
+		}
2984
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
2985
+			? $this->_req_data['order']
2986
+			: 'ASC';
2987
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2988
+			? $this->_req_data['paged']
2989
+			: 1;
2990
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2991
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2992
+			? $this->_req_data['perpage']
2993
+			: $per_page;
2994
+		$_where       = array();
2995
+		if ( ! empty($this->_req_data['s'])) {
2996
+			$sstr         = '%' . $this->_req_data['s'] . '%';
2997
+			$_where['OR'] = array(
2998
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2999
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3000
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3001
+				'ATT_fname'                         => array('LIKE', $sstr),
3002
+				'ATT_lname'                         => array('LIKE', $sstr),
3003
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3004
+				'ATT_email'                         => array('LIKE', $sstr),
3005
+				'ATT_address'                       => array('LIKE', $sstr),
3006
+				'ATT_address2'                      => array('LIKE', $sstr),
3007
+				'ATT_city'                          => array('LIKE', $sstr),
3008
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3009
+				'State.STA_name'                    => array('LIKE', $sstr),
3010
+				'ATT_phone'                         => array('LIKE', $sstr),
3011
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3012
+				'Registration.REG_code'             => array('LIKE', $sstr),
3013
+				'Registration.REG_count'            => array('LIKE', $sstr),
3014
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3015
+			);
3016
+		}
3017
+		$offset = ($current_page - 1) * $per_page;
3018
+		$limit  = $count ? null : array($offset, $per_page);
3019
+		if ($trash) {
3020
+			$_where['status'] = array('!=', 'publish');
3021
+			$all_attendees    = $count
3022
+				? $ATT_MDL->count(array(
3023
+					$_where,
3024
+					'order_by' => array($orderby => $sort),
3025
+					'limit'    => $limit,
3026
+				), 'ATT_ID', true)
3027
+				: $ATT_MDL->get_all(array(
3028
+					$_where,
3029
+					'order_by' => array($orderby => $sort),
3030
+					'limit'    => $limit,
3031
+				));
3032
+		} else {
3033
+			$_where['status'] = array('IN', array('publish'));
3034
+			$all_attendees    = $count
3035
+				? $ATT_MDL->count(array(
3036
+					$_where,
3037
+					'order_by' => array($orderby => $sort),
3038
+					'limit'    => $limit,
3039
+				), 'ATT_ID', true)
3040
+				: $ATT_MDL->get_all(array(
3041
+					$_where,
3042
+					'order_by' => array($orderby => $sort),
3043
+					'limit'    => $limit,
3044
+				));
3045
+		}
3046
+		return $all_attendees;
3047
+	}
3048
+
3049
+
3050
+	/**
3051
+	 * This is just taking care of resending the registration confirmation
3052
+	 *
3053
+	 * @access protected
3054
+	 * @return void
3055
+	 */
3056
+	protected function _resend_registration()
3057
+	{
3058
+		$this->_process_resend_registration();
3059
+		$query_args = isset($this->_req_data['redirect_to'])
3060
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3061
+			: array('action' => 'default');
3062
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3063
+	}
3064
+
3065
+	/**
3066
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3067
+	 * to use when selecting registrations
3068
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3069
+	 *                                                     the query parameters from the request
3070
+	 * @return void ends the request with a redirect or download
3071
+	 */
3072
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3073
+	{
3074
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3075
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3076
+				array(
3077
+					'page'        => 'espresso_batch',
3078
+					'batch'       => 'file',
3079
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3080
+					'filters'     => urlencode(
3081
+						serialize(
3082
+							call_user_func(
3083
+								array( $this, $method_name_for_getting_query_params ),
3084
+								EEH_Array::is_set(
3085
+									$this->_req_data,
3086
+									'filters',
3087
+									array()
3088
+								)
3089
+							)
3090
+						)
3091
+				),
3092
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3093
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3094
+				'return_url'  => urlencode($this->_req_data['return_url']),
3095
+			)));
3096
+		} else {
3097
+			$new_request_args = array(
3098
+				'export' => 'report',
3099
+				'action' => 'registrations_report_for_event',
3100
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3101
+			);
3102
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3103
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3104
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3105
+				$EE_Export = EE_Export::instance($this->_req_data);
3106
+				$EE_Export->export();
3107
+			}
3108
+		}
3109
+	}
3110
+
3111
+
3112
+
3113
+	/**
3114
+	 * Creates a registration report using only query parameters in the request
3115
+	 * @return void
3116
+	 */
3117
+	public function _registrations_report()
3118
+	{
3119
+		$this->_registrations_report_base('_get_registration_query_parameters');
3120
+	}
3121
+
3122
+
3123
+	public function _contact_list_export()
3124
+	{
3125
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3126
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3127
+			$EE_Export = EE_Export::instance($this->_req_data);
3128
+			$EE_Export->export_attendees();
3129
+		}
3130
+	}
3131
+
3132
+
3133
+	public function _contact_list_report()
3134
+	{
3135
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3136
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3137
+				'page'        => 'espresso_batch',
3138
+				'batch'       => 'file',
3139
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3140
+				'return_url'  => urlencode($this->_req_data['return_url']),
3141
+			)));
3142
+		} else {
3143
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3144
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3145
+				$EE_Export = EE_Export::instance($this->_req_data);
3146
+				$EE_Export->report_attendees();
3147
+			}
3148
+		}
3149
+	}
3150
+
3151
+
3152
+
3153
+
3154
+
3155
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3156
+	/**
3157
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3158
+	 *
3159
+	 * @return void
3160
+	 * @throws EE_Error
3161
+	 */
3162
+	protected function _duplicate_attendee()
3163
+	{
3164
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3165
+		//verify we have necessary info
3166
+		if (empty($this->_req_data['_REG_ID'])) {
3167
+			EE_Error::add_error(
3168
+				esc_html__(
3169
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3170
+					'event_espresso'
3171
+				), __FILE__, __LINE__, __FUNCTION__
3172
+			);
3173
+			$query_args = array('action' => $action);
3174
+			$this->_redirect_after_action('', '', '', $query_args, true);
3175
+		}
3176
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3177
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3178
+		$attendee     = $registration->attendee();
3179
+		//remove relation of existing attendee on registration
3180
+		$registration->_remove_relation_to($attendee, 'Attendee');
3181
+		//new attendee
3182
+		$new_attendee = clone $attendee;
3183
+		$new_attendee->set('ATT_ID', 0);
3184
+		$new_attendee->save();
3185
+		//add new attendee to reg
3186
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3187
+		EE_Error::add_success(
3188
+			esc_html__(
3189
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3190
+				'event_espresso'
3191
+			)
3192
+		);
3193
+		//redirect to edit page for attendee
3194
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3195
+		$this->_redirect_after_action('', '', '', $query_args, true);
3196
+	}
3197
+
3198
+
3199
+	//related to cpt routes
3200
+	protected function _insert_update_cpt_item($post_id, $post)
3201
+	{
3202
+		$success  = true;
3203
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3204
+		//for attendee updates
3205
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3206
+			//note we should only be UPDATING attendees at this point.
3207
+			$updated_fields = array(
3208
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3209
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3210
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3211
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3212
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3213
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3214
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3215
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3216
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3217
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3218
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3219
+			);
3220
+			foreach ($updated_fields as $field => $value) {
3221
+				$attendee->set($field, $value);
3222
+			}
3223
+			$success                   = $attendee->save();
3224
+			$attendee_update_callbacks = apply_filters(
3225
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3226
+				array()
3227
+			);
3228
+			foreach ($attendee_update_callbacks as $a_callback) {
3229
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3230
+					throw new EE_Error(
3231
+						sprintf(
3232
+							esc_html__(
3233
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3234
+								'event_espresso'
3235
+							),
3236
+							$a_callback
3237
+						)
3238
+					);
3239
+				}
3240
+			}
3241
+		}
3242
+		if ($success === false) {
3243
+			EE_Error::add_error(
3244
+				esc_html__(
3245
+					'Something went wrong with updating the meta table data for the registration.',
3246
+					'event_espresso'
3247
+				),
3248
+				__FILE__, __FUNCTION__, __LINE__
3249
+			);
3250
+		}
3251
+	}
3252
+
3253
+
3254
+	public function trash_cpt_item($post_id)
3255
+	{
3256
+	}
3257
+
3258
+
3259
+	public function delete_cpt_item($post_id)
3260
+	{
3261
+	}
3262
+
3263
+
3264
+	public function restore_cpt_item($post_id)
3265
+	{
3266
+	}
3267
+
3268
+
3269
+	protected function _restore_cpt_item($post_id, $revision_id)
3270
+	{
3271
+	}
3272
+
3273
+
3274
+	public function attendee_editor_metaboxes()
3275
+	{
3276
+		$this->verify_cpt_object();
3277
+		remove_meta_box(
3278
+			'postexcerpt',
3279
+			esc_html__('Excerpt', 'event_espresso'),
3280
+			'post_excerpt_meta_box',
3281
+			$this->_cpt_routes[$this->_req_action],
3282
+			'normal',
3283
+			'core'
3284
+		);
3285
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3286
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3287
+			add_meta_box(
3288
+				'postexcerpt',
3289
+				esc_html__('Short Biography', 'event_espresso'),
3290
+				'post_excerpt_meta_box',
3291
+				$this->_cpt_routes[$this->_req_action],
3292
+				'normal'
3293
+			);
3294
+		}
3295
+		if (post_type_supports('espresso_attendees', 'comments')) {
3296
+			add_meta_box(
3297
+				'commentsdiv',
3298
+				esc_html__('Notes on the Contact', 'event_espresso'),
3299
+				'post_comment_meta_box',
3300
+				$this->_cpt_routes[$this->_req_action],
3301
+				'normal',
3302
+				'core'
3303
+			);
3304
+		}
3305
+		add_meta_box(
3306
+			'attendee_contact_info',
3307
+			esc_html__('Contact Info', 'event_espresso'),
3308
+			array($this, 'attendee_contact_info'),
3309
+			$this->_cpt_routes[$this->_req_action],
3310
+			'side',
3311
+			'core'
3312
+		);
3313
+		add_meta_box(
3314
+			'attendee_details_address',
3315
+			esc_html__('Address Details', 'event_espresso'),
3316
+			array($this, 'attendee_address_details'),
3317
+			$this->_cpt_routes[$this->_req_action],
3318
+			'normal',
3319
+			'core'
3320
+		);
3321
+		add_meta_box(
3322
+			'attendee_registrations',
3323
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3324
+			array($this, 'attendee_registrations_meta_box'),
3325
+			$this->_cpt_routes[$this->_req_action],
3326
+			'normal',
3327
+			'high'
3328
+		);
3329
+	}
3330
+
3331
+
3332
+	/**
3333
+	 * Metabox for attendee contact info
3334
+	 *
3335
+	 * @param  WP_Post $post wp post object
3336
+	 * @return string attendee contact info ( and form )
3337
+	 * @throws DomainException
3338
+	 */
3339
+	public function attendee_contact_info($post)
3340
+	{
3341
+		//get attendee object ( should already have it )
3342
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3343
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3344
+		EEH_Template::display_template($template, $this->_template_args);
3345
+	}
3346
+
3347
+
3348
+	/**
3349
+	 * Metabox for attendee details
3350
+	 *
3351
+	 * @param  WP_Post $post wp post object
3352
+	 * @return string attendee address details (and form)
3353
+	 * @throws DomainException
3354
+	 */
3355
+	public function attendee_address_details($post)
3356
+	{
3357
+		//get attendee object (should already have it)
3358
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3359
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3360
+			new EE_Question_Form_Input(
3361
+				EE_Question::new_instance(
3362
+					array(
3363
+						'QST_ID'           => 0,
3364
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3365
+						'QST_system'       => 'admin-state',
3366
+					)
3367
+				),
3368
+				EE_Answer::new_instance(
3369
+					array(
3370
+						'ANS_ID'    => 0,
3371
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3372
+					)
3373
+				),
3374
+				array(
3375
+					'input_id'       => 'STA_ID',
3376
+					'input_name'     => 'STA_ID',
3377
+					'input_prefix'   => '',
3378
+					'append_qstn_id' => false,
3379
+				)
3380
+			)
3381
+		);
3382
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3383
+			new EE_Question_Form_Input(
3384
+				EE_Question::new_instance(
3385
+					array(
3386
+						'QST_ID'           => 0,
3387
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3388
+						'QST_system'       => 'admin-country',
3389
+					)
3390
+				),
3391
+				EE_Answer::new_instance(
3392
+					array(
3393
+						'ANS_ID'    => 0,
3394
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3395
+					)
3396
+				),
3397
+				array(
3398
+					'input_id'       => 'CNT_ISO',
3399
+					'input_name'     => 'CNT_ISO',
3400
+					'input_prefix'   => '',
3401
+					'append_qstn_id' => false,
3402
+				)
3403
+			)
3404
+		);
3405
+		$template                             =
3406
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3407
+		EEH_Template::display_template($template, $this->_template_args);
3408
+	}
3409
+
3410
+
3411
+	/**
3412
+	 *        _attendee_details
3413
+	 *
3414
+	 * @access protected
3415
+	 * @param $post
3416
+	 * @return void
3417
+	 * @throws DomainException
3418
+	 * @throws EE_Error
3419
+	 */
3420
+	public function attendee_registrations_meta_box($post)
3421
+	{
3422
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3423
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3424
+		$template                              =
3425
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3426
+		EEH_Template::display_template($template, $this->_template_args);
3427
+	}
3428
+
3429
+
3430
+	/**
3431
+	 * add in the form fields for the attendee edit
3432
+	 *
3433
+	 * @param  WP_Post $post wp post object
3434
+	 * @return string html for new form.
3435
+	 * @throws DomainException
3436
+	 */
3437
+	public function after_title_form_fields($post)
3438
+	{
3439
+		if ($post->post_type == 'espresso_attendees') {
3440
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3441
+			$template_args['attendee'] = $this->_cpt_model_obj;
3442
+			EEH_Template::display_template($template, $template_args);
3443
+		}
3444
+	}
3445
+
3446
+
3447
+	/**
3448
+	 *        _trash_or_restore_attendee
3449
+	 *
3450
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3451
+	 * @return void
3452
+	 * @throws EE_Error
3453
+	 * @access protected
3454
+	 */
3455
+	protected function _trash_or_restore_attendees($trash = true)
3456
+	{
3457
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3458
+		$ATT_MDL = EEM_Attendee::instance();
3459
+		$success = 1;
3460
+		//Checkboxes
3461
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3462
+			// if array has more than one element than success message should be plural
3463
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3464
+			// cycle thru checkboxes
3465
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3466
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3467
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3468
+				if ( ! $updated) {
3469
+					$success = 0;
3470
+				}
3471
+			}
3472
+		} else {
3473
+			// grab single id and delete
3474
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3475
+			//get attendee
3476
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3477
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3478
+			$updated = $att->save();
3479
+			if ( ! $updated) {
3480
+				$success = 0;
3481
+			}
3482
+		}
3483
+		$what        = $success > 1
3484
+			? esc_html__('Contacts', 'event_espresso')
3485
+			: esc_html__('Contact', 'event_espresso');
3486
+		$action_desc = $trash
3487
+			? esc_html__('moved to the trash', 'event_espresso')
3488
+			: esc_html__('restored', 'event_espresso');
3489
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3490
+	}
3491 3491
 
3492 3492
 }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Pdf_messenger.class.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Event Espresso
7 7
  * @subpackage messages
8 8
  */
9
-if (!defined('EVENT_ESPRESSO_VERSION') )
9
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
10 10
 	exit('NO direct script access allowed');
11 11
 
12 12
 /**
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @subpackage		messages
21 21
  * @author			Darren Ethier
22 22
  */
23
-class EE_Pdf_messenger extends EE_messenger  {
23
+class EE_Pdf_messenger extends EE_messenger {
24 24
 
25 25
 
26 26
 	/**
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @see abstract declaration in EE_messenger for details.
94 94
 	 */
95 95
 	protected function _set_admin_pages() {
96
-		$this->admin_registered_pages = array( 'events_edit' => false );
96
+		$this->admin_registered_pages = array('events_edit' => false);
97 97
 	}
98 98
 
99 99
 
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
 	protected function _set_validator_config() {
114 114
 		$this->_validator_config = array(
115 115
 			'subject' => array(
116
-				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email','event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
116
+				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
117 117
 				),
118 118
 			'content' => array(
119
-				'shortcodes' => array( 'recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email','event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
119
+				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
120 120
 				),
121 121
 			'attendee_list' => array(
122 122
 				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 				'required' => array('[EVENT_LIST]')
128 128
 				),
129 129
 			'ticket_list' => array(
130
-				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list','primary_registration_details', 'recipient_details'),
130
+				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'),
131 131
 				'required' => array('[TICKET_LIST]')
132 132
 				),
133 133
 			'datetime_list' => array(
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 */
148 148
 	public  function enqueue_scripts_styles() {
149 149
 		parent::enqueue_scripts_styles();
150
-		do_action( 'AHEE__EE_Pdf_messenger__enqueue_scripts_styles');
150
+		do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles');
151 151
 	}
152 152
 
153 153
 
@@ -273,18 +273,18 @@  discard block
 block discarded – undo
273 273
 	 */
274 274
 	protected function _send_message() {
275 275
 		$this->_template_args = array(
276
-			'page_title' => html_entity_decode( stripslashes( $this->_subject ), ENT_QUOTES, "UTF-8"),
277
-			'base_css' => $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'base', $this->_variation ),
278
-			'print_css' => $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'print', $this->_variation ),
279
-			'main_css' => $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'main', $this->_variation ),
280
-			'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css',
281
-			'main_body' => apply_filters( 'FHEE__EE_Pdf_messenger___send_message__main_body', wpautop(stripslashes_deep( html_entity_decode($this->_content,  ENT_QUOTES,"UTF-8" ) )), $this->_content )
276
+			'page_title' => html_entity_decode(stripslashes($this->_subject), ENT_QUOTES, "UTF-8"),
277
+			'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'base', $this->_variation),
278
+			'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'print', $this->_variation),
279
+			'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'main', $this->_variation),
280
+			'extra_css' => EE_LIBRARIES_URL.'messages/defaults/default/variations/pdf_base_default.css',
281
+			'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))), $this->_content)
282 282
 			);
283 283
 		$this->_deregister_wp_hooks();
284
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts_styles' ) );
284
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
285 285
 		$content = $this->_get_main_template();
286 286
 //		die( $content );
287
-		$this->_do_pdf( $content );
287
+		$this->_do_pdf($content);
288 288
 		exit(0);
289 289
 	}
290 290
 
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
 
309 309
 		//just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
310 310
 		add_action('wp_head', 'wp_enqueue_scripts');
311
-		add_action( 'wp_footer', 'wp_print_footer_scripts' );
312
-		add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' );
311
+		add_action('wp_footer', 'wp_print_footer_scripts');
312
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
313 313
 	}
314 314
 
315 315
 
@@ -322,11 +322,11 @@  discard block
 block discarded – undo
322 322
 	 * @param bool $preview
323 323
 	 * @return string
324 324
 	 */
325
-	protected function _get_main_template( $preview = FALSE ) {
326
-		$wrapper_template = $this->_tmp_pack->get_wrapper( 'html', 'main' );
325
+	protected function _get_main_template($preview = FALSE) {
326
+		$wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main');
327 327
 		//add message type to template_args
328 328
 		$this->_template_args['message_type'] = $this->_incoming_message_type;
329
-		return EEH_Template::display_template( $wrapper_template, $this->_template_args, TRUE );
329
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE);
330 330
 	}
331 331
 
332 332
 
@@ -339,15 +339,15 @@  discard block
 block discarded – undo
339 339
 	 *
340 340
 	 * @return void
341 341
 	 */
342
-	protected function _do_pdf( $content = '' ) {
343
-		$invoice_name = html_entity_decode( $this->_subject, ENT_QUOTES, "UTF-8");
342
+	protected function _do_pdf($content = '') {
343
+		$invoice_name = html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8");
344 344
 
345 345
 		//only load dompdf if nobody else has yet...
346
-		if( ! defined('DOMPDF_DIR')){
346
+		if ( ! defined('DOMPDF_DIR')) {
347 347
 			define('DOMPDF_ENABLE_REMOTE', TRUE);
348 348
 			define('DOMPDF_ENABLE_JAVASCRIPT', FALSE);
349 349
 			define('DOMPDF_ENABLE_CSS_FLOAT', TRUE);
350
-			require_once(EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php');
350
+			require_once(EE_THIRD_PARTY.'dompdf/dompdf_config.inc.php');
351 351
 		}
352 352
 		$dompdf = new DOMPDF();
353 353
 		if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) {
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		$dompdf->load_html($content);
357 357
 		$dompdf->render();
358 358
 		//forcing the browser to open a download dialog.
359
-		$dompdf->stream($invoice_name . ".pdf", array( 'Attachment' => TRUE ));
359
+		$dompdf->stream($invoice_name.".pdf", array('Attachment' => TRUE));
360 360
 	}
361 361
 
362 362
 
Please login to merge, or discard this patch.
core/admin/EE_Admin_List_Table.core.php 2 patches
Indentation   +834 added lines, -834 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed.');
4 4
 
5 5
 if (! class_exists('WP_List_Table')) {
6
-    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 
@@ -22,847 +22,847 @@  discard block
 block discarded – undo
22 22
 abstract class EE_Admin_List_Table extends WP_List_Table
23 23
 {
24 24
 
25
-    /**
26
-     * holds the data that will be processed for the table
27
-     *
28
-     * @var array $_data
29
-     */
30
-    protected $_data;
31
-
32
-
33
-    /**
34
-     * This holds the value of all the data available for the given view (for all pages).
35
-     *
36
-     * @var int $_all_data_count
37
-     */
38
-    protected $_all_data_count;
39
-
40
-
41
-    /**
42
-     * Will contain the count of trashed items for the view label.
43
-     *
44
-     * @var int $_trashed_count
45
-     */
46
-    protected $_trashed_count;
47
-
48
-
49
-    /**
50
-     * This is what will be referenced as the slug for the current screen
51
-     *
52
-     * @var string $_screen
53
-     */
54
-    protected $_screen;
55
-
56
-
57
-    /**
58
-     * this is the EE_Admin_Page object
59
-     *
60
-     * @var EE_Admin_Page $_admin_page
61
-     */
62
-    protected $_admin_page;
63
-
64
-
65
-    /**
66
-     * The current view
67
-     *
68
-     * @var string $_view
69
-     */
70
-    protected $_view;
71
-
72
-
73
-    /**
74
-     * array of possible views for this table
75
-     *
76
-     * @var array $_views
77
-     */
78
-    protected $_views;
79
-
80
-
81
-    /**
82
-     * An array of key => value pairs containing information about the current table
83
-     * array(
84
-     *        'plural' => 'plural label',
85
-     *        'singular' => 'singular label',
86
-     *        'ajax' => false, //whether to use ajax or not
87
-     *        'screen' => null, //string used to reference what screen this is
88
-     *        (WP_List_table converts to screen object)
89
-     * )
90
-     *
91
-     * @var array $_wp_list_args
92
-     */
93
-    protected $_wp_list_args;
94
-
95
-    /**
96
-     * an array of column names
97
-     * array(
98
-     *    'internal-name' => 'Title'
99
-     * )
100
-     *
101
-     * @var array $_columns
102
-     */
103
-    protected $_columns;
104
-
105
-    /**
106
-     * An array of sortable columns
107
-     * array(
108
-     *    'internal-name' => 'orderby' //or
109
-     *    'internal-name' => array( 'orderby', true )
110
-     * )
111
-     *
112
-     * @var array $_sortable_columns
113
-     */
114
-    protected $_sortable_columns;
115
-
116
-    /**
117
-     * callback method used to perform AJAX row reordering
118
-     *
119
-     * @var string $_ajax_sorting_callback
120
-     */
121
-    protected $_ajax_sorting_callback;
122
-
123
-    /**
124
-     * An array of hidden columns (if needed)
125
-     * array('internal-name', 'internal-name')
126
-     *
127
-     * @var array $_hidden_columns
128
-     */
129
-    protected $_hidden_columns;
130
-
131
-    /**
132
-     * holds the per_page value
133
-     *
134
-     * @var int $_per_page
135
-     */
136
-    protected $_per_page;
137
-
138
-    /**
139
-     * holds what page number is currently being viewed
140
-     *
141
-     * @var int $_current_page
142
-     */
143
-    protected $_current_page;
144
-
145
-    /**
146
-     * the reference string for the nonce_action
147
-     *
148
-     * @var string $_nonce_action_ref
149
-     */
150
-    protected $_nonce_action_ref;
151
-
152
-    /**
153
-     * property to hold incoming request data (as set by the admin_page_core)
154
-     *
155
-     * @var array $_req_data
156
-     */
157
-    protected $_req_data;
158
-
159
-
160
-    /**
161
-     * yes / no array for admin form fields
162
-     *
163
-     * @var array $_yes_no
164
-     */
165
-    protected $_yes_no = array();
166
-
167
-    /**
168
-     * Array describing buttons that should appear at the bottom of the page
169
-     * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
170
-     * and the values are another array with the following keys
171
-     * array(
172
-     *    'route' => 'page_route',
173
-     *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
174
-     * )
175
-     *
176
-     * @var array $_bottom_buttons
177
-     */
178
-    protected $_bottom_buttons = array();
179
-
180
-
181
-    /**
182
-     * Used to indicate what should be the primary column for the list table.
183
-     * If not present then falls back to what WP calculates
184
-     * as the primary column.
185
-     *
186
-     * @type string $_primary_column
187
-     */
188
-    protected $_primary_column = '';
189
-
190
-
191
-    /**
192
-     * Used to indicate whether the table has a checkbox column or not.
193
-     *
194
-     * @type bool $_has_checkbox_column
195
-     */
196
-    protected $_has_checkbox_column = false;
197
-
198
-
199
-    /**
200
-     * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
201
-     */
202
-    public function __construct(EE_Admin_Page $admin_page)
203
-    {
204
-        $this->_admin_page   = $admin_page;
205
-        $this->_req_data     = $this->_admin_page->get_request_data();
206
-        $this->_view         = $this->_admin_page->get_view();
207
-        $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208
-        $this->_current_page = $this->get_pagenum();
209
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
210
-        $this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211
-
212
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
213
-
214
-        $this->_setup_data();
215
-        $this->_add_view_counts();
216
-
217
-        $this->_nonce_action_ref = $this->_view;
218
-
219
-        $this->_set_properties();
220
-
221
-        //set primary column
222
-        add_filter('list_table_primary_column', array($this, 'set_primary_column'));
223
-
224
-        //set parent defaults
225
-        parent::__construct($this->_wp_list_args);
226
-
227
-        $this->prepare_items();
228
-    }
229
-
230
-
231
-    /**
232
-     * _setup_data
233
-     * this method is used to setup the $_data, $_all_data_count, and _per_page properties
234
-     *
235
-     * @uses $this->_admin_page
236
-     * @return void
237
-     */
238
-    abstract protected function _setup_data();
239
-
240
-
241
-    /**
242
-     * set the properties that this class needs to be able to execute wp_list_table properly
243
-     * properties set:
244
-     * _wp_list_args = what the arguments required for the parent _wp_list_table.
245
-     * _columns = set the columns in an array.
246
-     * _sortable_columns = columns that are sortable (array).
247
-     * _hidden_columns = columns that are hidden (array)
248
-     * _default_orderby = the default orderby for sorting.
249
-     *
250
-     * @abstract
251
-     * @access protected
252
-     * @return void
253
-     */
254
-    abstract protected function _set_properties();
255
-
256
-
257
-    /**
258
-     * _get_table_filters
259
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
260
-     * get's shown in the table.
261
-     *
262
-     * @abstract
263
-     * @access protected
264
-     * @return string
265
-     */
266
-    abstract protected function _get_table_filters();
267
-
268
-
269
-    /**
270
-     * this is a method that child class will do to add counts to the views array so when views are displayed the
271
-     * counts of the views is accurate.
272
-     *
273
-     * @abstract
274
-     * @access protected
275
-     * @return void
276
-     */
277
-    abstract protected function _add_view_counts();
278
-
279
-
280
-    /**
281
-     * _get_hidden_fields
282
-     * returns a html string of hidden fields so if any table filters are used the current view will be respected.
283
-     *
284
-     * @return string
285
-     */
286
-    protected function _get_hidden_fields()
287
-    {
288
-        $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
289
-        $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290
-        //if action is STILL empty, then we set it to default
291
-        $action = empty($action) ? 'default' : $action;
292
-        $field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
-        $field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
-        $field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
295
-
296
-        $bulk_actions = $this->_get_bulk_actions();
297
-        foreach ($bulk_actions as $bulk_action => $label) {
298
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
299
-                . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
300
-        }
301
-
302
-        return $field;
303
-    }
304
-
305
-
306
-    /**
307
-     * _set_column_info
308
-     * we're using this to set the column headers property.
309
-     *
310
-     * @access protected
311
-     * @return void
312
-     */
313
-    protected function _set_column_info()
314
-    {
315
-        $columns   = $this->get_columns();
316
-        $hidden    = $this->get_hidden_columns();
317
-        $_sortable = $this->get_sortable_columns();
318
-
319
-        /**
320
-         * Dynamic hook allowing for adding sortable columns in this list table.
321
-         * Note that $this->screen->id is in the format
322
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
323
-         * table it is: event-espresso_page_espresso_messages.
324
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
325
-         * hook prefix ("event-espresso") will be different.
326
-         *
327
-         * @var array
328
-         */
329
-        $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
330
-
331
-        $sortable = array();
332
-        foreach ($_sortable as $id => $data) {
333
-            if (empty($data)) {
334
-                continue;
335
-            }
336
-            //fix for offset errors with WP_List_Table default get_columninfo()
337
-            if (is_array($data)) {
338
-                $_data[0] = key($data);
339
-                $_data[1] = isset($data[1]) ? $data[1] : false;
340
-            } else {
341
-                $_data[0] = $data;
342
-            }
343
-
344
-            $data = (array)$data;
345
-
346
-            if (! isset($data[1])) {
347
-                $_data[1] = false;
348
-            }
349
-
350
-            $sortable[$id] = $_data;
351
-        }
352
-        $primary               = $this->get_primary_column_name();
353
-        $this->_column_headers = array($columns, $hidden, $sortable, $primary);
354
-    }
355
-
356
-
357
-    /**
358
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
359
-     *
360
-     * @return string
361
-     */
362
-    protected function get_primary_column_name()
363
-    {
364
-        foreach (class_parents($this) as $parent) {
365
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
366
-                return parent::get_primary_column_name();
367
-            }
368
-        }
369
-        return $this->_primary_column;
370
-    }
371
-
372
-
373
-    /**
374
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
375
-     *
376
-     * @param EE_Base_Class $item
377
-     * @param string        $column_name
378
-     * @param string        $primary
379
-     * @return string
380
-     */
381
-    protected function handle_row_actions($item, $column_name, $primary)
382
-    {
383
-        foreach (class_parents($this) as $parent) {
384
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
385
-                return parent::handle_row_actions($item, $column_name, $primary);
386
-            }
387
-        }
388
-        return '';
389
-    }
390
-
391
-
392
-    /**
393
-     * _get_bulk_actions
394
-     * This is a wrapper called by WP_List_Table::get_bulk_actions()
395
-     *
396
-     * @access protected
397
-     * @return array bulk_actions
398
-     */
399
-    protected function _get_bulk_actions()
400
-    {
401
-        $actions = array();
402
-        //the _views property should have the bulk_actions, so let's go through and extract them into a properly
403
-        // formatted array for the wp_list_table();
404
-        foreach ($this->_views as $view => $args) {
405
-            if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
406
-                //each bulk action will correspond with a admin page route, so we can check whatever the capability is
407
-                // for that page route and skip adding the bulk action if no access for the current logged in user.
408
-                foreach ($args['bulk_action'] as $route => $label) {
409
-                    if ($this->_admin_page->check_user_access($route, true)) {
410
-                        $actions[$route] = $label;
411
-                    }
412
-                }
413
-            }
414
-        }
415
-        return $actions;
416
-    }
417
-
418
-
419
-    /**
420
-     * Generate the table navigation above or below the table.
421
-     * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
422
-     *
423
-     * @since 4.9.44.rc.001
424
-     */
425
-    public function display_tablenav($which)
426
-    {
427
-        if ('top' === $which) {
428
-            wp_nonce_field('bulk-' . $this->_args['plural']);
429
-        }
430
-        ?>
25
+	/**
26
+	 * holds the data that will be processed for the table
27
+	 *
28
+	 * @var array $_data
29
+	 */
30
+	protected $_data;
31
+
32
+
33
+	/**
34
+	 * This holds the value of all the data available for the given view (for all pages).
35
+	 *
36
+	 * @var int $_all_data_count
37
+	 */
38
+	protected $_all_data_count;
39
+
40
+
41
+	/**
42
+	 * Will contain the count of trashed items for the view label.
43
+	 *
44
+	 * @var int $_trashed_count
45
+	 */
46
+	protected $_trashed_count;
47
+
48
+
49
+	/**
50
+	 * This is what will be referenced as the slug for the current screen
51
+	 *
52
+	 * @var string $_screen
53
+	 */
54
+	protected $_screen;
55
+
56
+
57
+	/**
58
+	 * this is the EE_Admin_Page object
59
+	 *
60
+	 * @var EE_Admin_Page $_admin_page
61
+	 */
62
+	protected $_admin_page;
63
+
64
+
65
+	/**
66
+	 * The current view
67
+	 *
68
+	 * @var string $_view
69
+	 */
70
+	protected $_view;
71
+
72
+
73
+	/**
74
+	 * array of possible views for this table
75
+	 *
76
+	 * @var array $_views
77
+	 */
78
+	protected $_views;
79
+
80
+
81
+	/**
82
+	 * An array of key => value pairs containing information about the current table
83
+	 * array(
84
+	 *        'plural' => 'plural label',
85
+	 *        'singular' => 'singular label',
86
+	 *        'ajax' => false, //whether to use ajax or not
87
+	 *        'screen' => null, //string used to reference what screen this is
88
+	 *        (WP_List_table converts to screen object)
89
+	 * )
90
+	 *
91
+	 * @var array $_wp_list_args
92
+	 */
93
+	protected $_wp_list_args;
94
+
95
+	/**
96
+	 * an array of column names
97
+	 * array(
98
+	 *    'internal-name' => 'Title'
99
+	 * )
100
+	 *
101
+	 * @var array $_columns
102
+	 */
103
+	protected $_columns;
104
+
105
+	/**
106
+	 * An array of sortable columns
107
+	 * array(
108
+	 *    'internal-name' => 'orderby' //or
109
+	 *    'internal-name' => array( 'orderby', true )
110
+	 * )
111
+	 *
112
+	 * @var array $_sortable_columns
113
+	 */
114
+	protected $_sortable_columns;
115
+
116
+	/**
117
+	 * callback method used to perform AJAX row reordering
118
+	 *
119
+	 * @var string $_ajax_sorting_callback
120
+	 */
121
+	protected $_ajax_sorting_callback;
122
+
123
+	/**
124
+	 * An array of hidden columns (if needed)
125
+	 * array('internal-name', 'internal-name')
126
+	 *
127
+	 * @var array $_hidden_columns
128
+	 */
129
+	protected $_hidden_columns;
130
+
131
+	/**
132
+	 * holds the per_page value
133
+	 *
134
+	 * @var int $_per_page
135
+	 */
136
+	protected $_per_page;
137
+
138
+	/**
139
+	 * holds what page number is currently being viewed
140
+	 *
141
+	 * @var int $_current_page
142
+	 */
143
+	protected $_current_page;
144
+
145
+	/**
146
+	 * the reference string for the nonce_action
147
+	 *
148
+	 * @var string $_nonce_action_ref
149
+	 */
150
+	protected $_nonce_action_ref;
151
+
152
+	/**
153
+	 * property to hold incoming request data (as set by the admin_page_core)
154
+	 *
155
+	 * @var array $_req_data
156
+	 */
157
+	protected $_req_data;
158
+
159
+
160
+	/**
161
+	 * yes / no array for admin form fields
162
+	 *
163
+	 * @var array $_yes_no
164
+	 */
165
+	protected $_yes_no = array();
166
+
167
+	/**
168
+	 * Array describing buttons that should appear at the bottom of the page
169
+	 * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
170
+	 * and the values are another array with the following keys
171
+	 * array(
172
+	 *    'route' => 'page_route',
173
+	 *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
174
+	 * )
175
+	 *
176
+	 * @var array $_bottom_buttons
177
+	 */
178
+	protected $_bottom_buttons = array();
179
+
180
+
181
+	/**
182
+	 * Used to indicate what should be the primary column for the list table.
183
+	 * If not present then falls back to what WP calculates
184
+	 * as the primary column.
185
+	 *
186
+	 * @type string $_primary_column
187
+	 */
188
+	protected $_primary_column = '';
189
+
190
+
191
+	/**
192
+	 * Used to indicate whether the table has a checkbox column or not.
193
+	 *
194
+	 * @type bool $_has_checkbox_column
195
+	 */
196
+	protected $_has_checkbox_column = false;
197
+
198
+
199
+	/**
200
+	 * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
201
+	 */
202
+	public function __construct(EE_Admin_Page $admin_page)
203
+	{
204
+		$this->_admin_page   = $admin_page;
205
+		$this->_req_data     = $this->_admin_page->get_request_data();
206
+		$this->_view         = $this->_admin_page->get_view();
207
+		$this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208
+		$this->_current_page = $this->get_pagenum();
209
+		$this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
210
+		$this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211
+
212
+		$this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
213
+
214
+		$this->_setup_data();
215
+		$this->_add_view_counts();
216
+
217
+		$this->_nonce_action_ref = $this->_view;
218
+
219
+		$this->_set_properties();
220
+
221
+		//set primary column
222
+		add_filter('list_table_primary_column', array($this, 'set_primary_column'));
223
+
224
+		//set parent defaults
225
+		parent::__construct($this->_wp_list_args);
226
+
227
+		$this->prepare_items();
228
+	}
229
+
230
+
231
+	/**
232
+	 * _setup_data
233
+	 * this method is used to setup the $_data, $_all_data_count, and _per_page properties
234
+	 *
235
+	 * @uses $this->_admin_page
236
+	 * @return void
237
+	 */
238
+	abstract protected function _setup_data();
239
+
240
+
241
+	/**
242
+	 * set the properties that this class needs to be able to execute wp_list_table properly
243
+	 * properties set:
244
+	 * _wp_list_args = what the arguments required for the parent _wp_list_table.
245
+	 * _columns = set the columns in an array.
246
+	 * _sortable_columns = columns that are sortable (array).
247
+	 * _hidden_columns = columns that are hidden (array)
248
+	 * _default_orderby = the default orderby for sorting.
249
+	 *
250
+	 * @abstract
251
+	 * @access protected
252
+	 * @return void
253
+	 */
254
+	abstract protected function _set_properties();
255
+
256
+
257
+	/**
258
+	 * _get_table_filters
259
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
260
+	 * get's shown in the table.
261
+	 *
262
+	 * @abstract
263
+	 * @access protected
264
+	 * @return string
265
+	 */
266
+	abstract protected function _get_table_filters();
267
+
268
+
269
+	/**
270
+	 * this is a method that child class will do to add counts to the views array so when views are displayed the
271
+	 * counts of the views is accurate.
272
+	 *
273
+	 * @abstract
274
+	 * @access protected
275
+	 * @return void
276
+	 */
277
+	abstract protected function _add_view_counts();
278
+
279
+
280
+	/**
281
+	 * _get_hidden_fields
282
+	 * returns a html string of hidden fields so if any table filters are used the current view will be respected.
283
+	 *
284
+	 * @return string
285
+	 */
286
+	protected function _get_hidden_fields()
287
+	{
288
+		$action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
289
+		$action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290
+		//if action is STILL empty, then we set it to default
291
+		$action = empty($action) ? 'default' : $action;
292
+		$field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
+		$field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
+		$field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
295
+
296
+		$bulk_actions = $this->_get_bulk_actions();
297
+		foreach ($bulk_actions as $bulk_action => $label) {
298
+			$field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
299
+				. ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
300
+		}
301
+
302
+		return $field;
303
+	}
304
+
305
+
306
+	/**
307
+	 * _set_column_info
308
+	 * we're using this to set the column headers property.
309
+	 *
310
+	 * @access protected
311
+	 * @return void
312
+	 */
313
+	protected function _set_column_info()
314
+	{
315
+		$columns   = $this->get_columns();
316
+		$hidden    = $this->get_hidden_columns();
317
+		$_sortable = $this->get_sortable_columns();
318
+
319
+		/**
320
+		 * Dynamic hook allowing for adding sortable columns in this list table.
321
+		 * Note that $this->screen->id is in the format
322
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
323
+		 * table it is: event-espresso_page_espresso_messages.
324
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
325
+		 * hook prefix ("event-espresso") will be different.
326
+		 *
327
+		 * @var array
328
+		 */
329
+		$_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
330
+
331
+		$sortable = array();
332
+		foreach ($_sortable as $id => $data) {
333
+			if (empty($data)) {
334
+				continue;
335
+			}
336
+			//fix for offset errors with WP_List_Table default get_columninfo()
337
+			if (is_array($data)) {
338
+				$_data[0] = key($data);
339
+				$_data[1] = isset($data[1]) ? $data[1] : false;
340
+			} else {
341
+				$_data[0] = $data;
342
+			}
343
+
344
+			$data = (array)$data;
345
+
346
+			if (! isset($data[1])) {
347
+				$_data[1] = false;
348
+			}
349
+
350
+			$sortable[$id] = $_data;
351
+		}
352
+		$primary               = $this->get_primary_column_name();
353
+		$this->_column_headers = array($columns, $hidden, $sortable, $primary);
354
+	}
355
+
356
+
357
+	/**
358
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
359
+	 *
360
+	 * @return string
361
+	 */
362
+	protected function get_primary_column_name()
363
+	{
364
+		foreach (class_parents($this) as $parent) {
365
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
366
+				return parent::get_primary_column_name();
367
+			}
368
+		}
369
+		return $this->_primary_column;
370
+	}
371
+
372
+
373
+	/**
374
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
375
+	 *
376
+	 * @param EE_Base_Class $item
377
+	 * @param string        $column_name
378
+	 * @param string        $primary
379
+	 * @return string
380
+	 */
381
+	protected function handle_row_actions($item, $column_name, $primary)
382
+	{
383
+		foreach (class_parents($this) as $parent) {
384
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
385
+				return parent::handle_row_actions($item, $column_name, $primary);
386
+			}
387
+		}
388
+		return '';
389
+	}
390
+
391
+
392
+	/**
393
+	 * _get_bulk_actions
394
+	 * This is a wrapper called by WP_List_Table::get_bulk_actions()
395
+	 *
396
+	 * @access protected
397
+	 * @return array bulk_actions
398
+	 */
399
+	protected function _get_bulk_actions()
400
+	{
401
+		$actions = array();
402
+		//the _views property should have the bulk_actions, so let's go through and extract them into a properly
403
+		// formatted array for the wp_list_table();
404
+		foreach ($this->_views as $view => $args) {
405
+			if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
406
+				//each bulk action will correspond with a admin page route, so we can check whatever the capability is
407
+				// for that page route and skip adding the bulk action if no access for the current logged in user.
408
+				foreach ($args['bulk_action'] as $route => $label) {
409
+					if ($this->_admin_page->check_user_access($route, true)) {
410
+						$actions[$route] = $label;
411
+					}
412
+				}
413
+			}
414
+		}
415
+		return $actions;
416
+	}
417
+
418
+
419
+	/**
420
+	 * Generate the table navigation above or below the table.
421
+	 * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
422
+	 *
423
+	 * @since 4.9.44.rc.001
424
+	 */
425
+	public function display_tablenav($which)
426
+	{
427
+		if ('top' === $which) {
428
+			wp_nonce_field('bulk-' . $this->_args['plural']);
429
+		}
430
+		?>
431 431
         <div class="tablenav <?php echo esc_attr($which); ?>">
432 432
             <?php if ($this->_get_bulk_actions()) { ?>
433 433
                 <div class="alignleft actions bulkactions">
434 434
                     <?php $this->bulk_actions(); ?>
435 435
                 </div>
436 436
             <?php }
437
-            $this->extra_tablenav($which);
438
-            $this->pagination($which);
439
-            ?>
437
+			$this->extra_tablenav($which);
438
+			$this->pagination($which);
439
+			?>
440 440
 
441 441
             <br class="clear"/>
442 442
         </div>
443 443
         <?php
444
-    }
445
-
446
-
447
-    /**
448
-     * _filters
449
-     * This receives the filters array from children _get_table_filters() and assembles the string including the filter
450
-     * button.
451
-     *
452
-     * @access private
453
-     * @return string html showing filters
454
-     */
455
-    private function _filters()
456
-    {
457
-        $classname = get_class($this);
458
-        $filters   = apply_filters(
459
-            "FHEE__{$classname}__filters",
460
-            (array) $this->_get_table_filters(),
461
-            $this,
462
-            $this->_screen
463
-        );
464
-
465
-        if (empty($filters)) {
466
-            return;
467
-        }
468
-        foreach ($filters as $filter) {
469
-            echo $filter;
470
-        }
471
-        //add filter button at end
472
-        echo '<input type="submit" class="button-secondary" value="'
473
-             . esc_html__('Filter', 'event_espresso')
474
-             . '" id="post-query-submit" />';
475
-        //add reset filters button at end
476
-        echo '<a class="button button-secondary"  href="'
477
-             . $this->_admin_page->get_current_page_view_url()
478
-             . '" style="display:inline-block">'
479
-             . esc_html__('Reset Filters', 'event_espresso')
480
-             . '</a>';
481
-    }
482
-
483
-
484
-    /**
485
-     * Callback for 'list_table_primary_column' WordPress filter
486
-     * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
487
-     * column when class is instantiated.
488
-     *
489
-     * @see WP_List_Table::get_primary_column_name
490
-     * @param string $column_name
491
-     * @return string
492
-     */
493
-    public function set_primary_column($column_name)
494
-    {
495
-        return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
496
-    }
497
-
498
-
499
-    /**
500
-     *
501
-     */
502
-    public function prepare_items()
503
-    {
504
-
505
-        $this->_set_column_info();
506
-        //$this->_column_headers = $this->get_column_info();
507
-        $total_items = $this->_all_data_count;
508
-        $this->process_bulk_action();
509
-
510
-        $this->items = $this->_data;
511
-        $this->set_pagination_args(
512
-            array(
513
-                'total_items' => $total_items,
514
-                'per_page'    => $this->_per_page,
515
-                'total_pages' => ceil($total_items / $this->_per_page),
516
-            )
517
-        );
518
-    }
519
-
520
-
521
-    /**
522
-     * This column is the default for when there is no defined column method for a registered column.
523
-     * This can be overridden by child classes, but allows for hooking in for custom columns.
524
-     *
525
-     * @param EE_Base_Class $item
526
-     * @param string        $column_name The column being called.
527
-     * @return string html content for the column
528
-     */
529
-    public function column_default($item, $column_name)
530
-    {
531
-        /**
532
-         * Dynamic hook allowing for adding additional column content in this list table.
533
-         * Note that $this->screen->id is in the format
534
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
535
-         * table it is: event-espresso_page_espresso_messages.
536
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
537
-         * hook prefix ("event-espresso") will be different.
538
-         */
539
-        do_action(
540
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
541
-            $item,
542
-            $this->_screen
543
-        );
544
-    }
545
-
546
-
547
-    /**
548
-     * Get a list of columns. The format is:
549
-     * 'internal-name' => 'Title'
550
-     *
551
-     * @since  3.1.0
552
-     * @access public
553
-     * @abstract
554
-     * @return array
555
-     */
556
-    public function get_columns()
557
-    {
558
-        /**
559
-         * Dynamic hook allowing for adding additional columns in this list table.
560
-         * Note that $this->screen->id is in the format
561
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
562
-         * table it is: event-espresso_page_espresso_messages.
563
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
564
-         * hook prefix ("event-espresso") will be different.
565
-         *
566
-         * @var array
567
-         */
568
-        $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
569
-        return $columns;
570
-    }
571
-
572
-
573
-    /**
574
-     * Get an associative array ( id => link ) with the list
575
-     * of views available on this table.
576
-     *
577
-     * @since  3.1.0
578
-     * @access protected
579
-     * @return array
580
-     */
581
-    public function get_views()
582
-    {
583
-        return $this->_views;
584
-    }
585
-
586
-
587
-    /**
588
-     * Generate the views html.
589
-     */
590
-    public function display_views()
591
-    {
592
-        $views           = $this->get_views();
593
-        $assembled_views = array();
594
-
595
-        if (empty($views)) {
596
-            return;
597
-        }
598
-        echo "<ul class='subsubsub'>\n";
599
-        foreach ($views as $view) {
600
-            $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
601
-            if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
602
-                $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>"
603
-                                                  . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>'
604
-                                                  . ' <span class="count">(' . $count . ')</span>';
605
-            }
606
-        }
607
-
608
-        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
609
-        echo "</ul>";
610
-    }
611
-
612
-
613
-    /**
614
-     * Generates content for a single row of the table
615
-     *
616
-     * @since  4.1
617
-     * @access public
618
-     * @param EE_Base_Class $item The current item
619
-     */
620
-    public function single_row($item)
621
-    {
622
-        $row_class = $this->_get_row_class($item);
623
-        echo '<tr class="' . esc_attr($row_class) . '">';
624
-        $this->single_row_columns($item);
625
-        echo '</tr>';
626
-    }
627
-
628
-
629
-    /**
630
-     * This simply sets up the row class for the table rows.
631
-     * Allows for easier overriding of child methods for setting up sorting.
632
-     *
633
-     * @param  EE_Base_Class $item the current item
634
-     * @return string
635
-     */
636
-    protected function _get_row_class($item)
637
-    {
638
-        static $row_class = '';
639
-        $row_class = ($row_class === '' ? 'alternate' : '');
640
-
641
-        $new_row_class = $row_class;
642
-
643
-        if (! empty($this->_ajax_sorting_callback)) {
644
-            $new_row_class .= ' rowsortable';
645
-        }
646
-
647
-        return $new_row_class;
648
-    }
649
-
650
-
651
-    /**
652
-     * @return array
653
-     */
654
-    public function get_sortable_columns()
655
-    {
656
-        return (array)$this->_sortable_columns;
657
-    }
658
-
659
-
660
-    /**
661
-     * @return string
662
-     */
663
-    public function get_ajax_sorting_callback()
664
-    {
665
-        return $this->_ajax_sorting_callback;
666
-    }
667
-
668
-
669
-    /**
670
-     * @return array
671
-     */
672
-    public function get_hidden_columns()
673
-    {
674
-        $user_id     = get_current_user_id();
675
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
676
-        if (empty($has_default) && ! empty($this->_hidden_columns)) {
677
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
678
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
679
-        }
680
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
681
-        return (array) get_user_option($ref, $user_id);
682
-    }
683
-
684
-
685
-    /**
686
-     * Generates the columns for a single row of the table.
687
-     * Overridden from wp_list_table so as to allow us to filter the column content for a given
688
-     * column.
689
-     *
690
-     * @since 3.1.0
691
-     * @param EE_Base_Class $item The current item
692
-     */
693
-    public function single_row_columns($item)
694
-    {
695
-        list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
696
-
697
-        global $wp_version;
698
-        $use_hidden_class = version_compare($wp_version, '4.3-RC', '>=');
699
-
700
-        foreach ($columns as $column_name => $column_display_name) {
701
-
702
-            /**
703
-             * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
704
-             * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
705
-             */
706
-            $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
707
-            $style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
708
-
709
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
710
-            if ($primary === $column_name) {
711
-                $classes .= ' has-row-actions column-primary';
712
-            }
713
-
714
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
715
-
716
-            $class = "class='$classes'";
717
-
718
-            $attributes = "$class$style$data";
719
-
720
-            if ($column_name === 'cb') {
721
-                echo '<th scope="row" class="check-column">';
722
-                echo apply_filters(
723
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
724
-                    $this->column_cb($item),
725
-                    $item,
726
-                    $this
727
-                );
728
-                echo '</th>';
729
-            } elseif (method_exists($this, 'column_' . $column_name)) {
730
-                echo "<td $attributes>";
731
-                echo apply_filters(
732
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
733
-                    call_user_func(array($this, 'column_' . $column_name), $item),
734
-                    $item,
735
-                    $this
736
-                );
737
-                echo $this->handle_row_actions($item, $column_name, $primary);
738
-                echo "</td>";
739
-            } else {
740
-                echo "<td $attributes>";
741
-                echo apply_filters(
742
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
743
-                    $this->column_default($item, $column_name),
744
-                    $item,
745
-                    $column_name,
746
-                    $this
747
-                );
748
-                echo $this->handle_row_actions($item, $column_name, $primary);
749
-                echo "</td>";
750
-            }
751
-        }
752
-    }
753
-
754
-
755
-    /**
756
-     * Extra controls to be displayed between bulk actions and pagination
757
-     *
758
-     * @access public
759
-     * @param string $which
760
-     * @throws \EE_Error
761
-     */
762
-    public function extra_tablenav($which)
763
-    {
764
-        if ($which === 'top') {
765
-            $this->_filters();
766
-            echo $this->_get_hidden_fields();
767
-        } else {
768
-            echo '<div class="list-table-bottom-buttons alignleft actions">';
769
-            foreach ($this->_bottom_buttons as $type => $action) {
770
-                $route         = isset($action['route']) ? $action['route'] : '';
771
-                $extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
772
-                echo $this->_admin_page->get_action_link_or_button(
773
-                    $route,
774
-                    $type,
775
-                    $extra_request,
776
-                    'button button-secondary',
777
-                    '',
778
-                    false
779
-                );
780
-            }
781
-            do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
782
-            echo '</div>';
783
-        }
784
-        //echo $this->_entries_per_page_dropdown;
785
-    }
786
-
787
-
788
-    /**
789
-     * Get an associative array ( option_name => option_title ) with the list
790
-     * of bulk actions available on this table.
791
-     *
792
-     * @since  3.1.0
793
-     * @access protected
794
-     * @return array
795
-     */
796
-    public function get_bulk_actions()
797
-    {
798
-        return (array) $this->_get_bulk_actions();
799
-    }
800
-
801
-    /**
802
-     * Processing bulk actions.
803
-     */
804
-    public function process_bulk_action()
805
-    {
806
-        //this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
807
-        //reference in case there is a case where it gets used.
808
-    }
809
-
810
-
811
-    /**
812
-     * returns the EE admin page this list table is associated with
813
-     *
814
-     * @return EE_Admin_Page
815
-     */
816
-    public function get_admin_page()
817
-    {
818
-        return $this->_admin_page;
819
-    }
820
-
821
-
822
-    /**
823
-     * A "helper" function for all children to provide an html string of
824
-     * actions to output in their content.  It is preferable for child classes
825
-     * to use this method for generating their actions content so that it's
826
-     * filterable by plugins
827
-     *
828
-     * @param string        $action_container           what are the html container
829
-     *                                                  elements for this actions string?
830
-     * @param string        $action_class               What class is for the container
831
-     *                                                  element.
832
-     * @param string        $action_items               The contents for the action items
833
-     *                                                  container.  This is filtered before
834
-     *                                                  returned.
835
-     * @param string        $action_id                  What id (optional) is used for the
836
-     *                                                  container element.
837
-     * @param EE_Base_Class $item                       The object for the column displaying
838
-     *                                                  the actions.
839
-     * @return string The assembled action elements container.
840
-     */
841
-    protected function _action_string(
842
-        $action_items,
843
-        $item,
844
-        $action_container = 'ul',
845
-        $action_class = '',
846
-        $action_id = ''
847
-    ) {
848
-        $content      = '';
849
-        $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
850
-        $action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
851
-        $content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
852
-        try {
853
-            $content .= apply_filters(
854
-                'FHEE__EE_Admin_List_Table___action_string__action_items',
855
-                $action_items,
856
-                $item,
857
-                $this
858
-            );
859
-        } catch (\Exception $e) {
860
-            if (WP_DEBUG) {
861
-                \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
862
-            }
863
-            $content .= $action_items;
864
-        }
865
-        $content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
866
-        return $content;
867
-    }
444
+	}
445
+
446
+
447
+	/**
448
+	 * _filters
449
+	 * This receives the filters array from children _get_table_filters() and assembles the string including the filter
450
+	 * button.
451
+	 *
452
+	 * @access private
453
+	 * @return string html showing filters
454
+	 */
455
+	private function _filters()
456
+	{
457
+		$classname = get_class($this);
458
+		$filters   = apply_filters(
459
+			"FHEE__{$classname}__filters",
460
+			(array) $this->_get_table_filters(),
461
+			$this,
462
+			$this->_screen
463
+		);
464
+
465
+		if (empty($filters)) {
466
+			return;
467
+		}
468
+		foreach ($filters as $filter) {
469
+			echo $filter;
470
+		}
471
+		//add filter button at end
472
+		echo '<input type="submit" class="button-secondary" value="'
473
+			 . esc_html__('Filter', 'event_espresso')
474
+			 . '" id="post-query-submit" />';
475
+		//add reset filters button at end
476
+		echo '<a class="button button-secondary"  href="'
477
+			 . $this->_admin_page->get_current_page_view_url()
478
+			 . '" style="display:inline-block">'
479
+			 . esc_html__('Reset Filters', 'event_espresso')
480
+			 . '</a>';
481
+	}
482
+
483
+
484
+	/**
485
+	 * Callback for 'list_table_primary_column' WordPress filter
486
+	 * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
487
+	 * column when class is instantiated.
488
+	 *
489
+	 * @see WP_List_Table::get_primary_column_name
490
+	 * @param string $column_name
491
+	 * @return string
492
+	 */
493
+	public function set_primary_column($column_name)
494
+	{
495
+		return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
496
+	}
497
+
498
+
499
+	/**
500
+	 *
501
+	 */
502
+	public function prepare_items()
503
+	{
504
+
505
+		$this->_set_column_info();
506
+		//$this->_column_headers = $this->get_column_info();
507
+		$total_items = $this->_all_data_count;
508
+		$this->process_bulk_action();
509
+
510
+		$this->items = $this->_data;
511
+		$this->set_pagination_args(
512
+			array(
513
+				'total_items' => $total_items,
514
+				'per_page'    => $this->_per_page,
515
+				'total_pages' => ceil($total_items / $this->_per_page),
516
+			)
517
+		);
518
+	}
519
+
520
+
521
+	/**
522
+	 * This column is the default for when there is no defined column method for a registered column.
523
+	 * This can be overridden by child classes, but allows for hooking in for custom columns.
524
+	 *
525
+	 * @param EE_Base_Class $item
526
+	 * @param string        $column_name The column being called.
527
+	 * @return string html content for the column
528
+	 */
529
+	public function column_default($item, $column_name)
530
+	{
531
+		/**
532
+		 * Dynamic hook allowing for adding additional column content in this list table.
533
+		 * Note that $this->screen->id is in the format
534
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
535
+		 * table it is: event-espresso_page_espresso_messages.
536
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
537
+		 * hook prefix ("event-espresso") will be different.
538
+		 */
539
+		do_action(
540
+			'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
541
+			$item,
542
+			$this->_screen
543
+		);
544
+	}
545
+
546
+
547
+	/**
548
+	 * Get a list of columns. The format is:
549
+	 * 'internal-name' => 'Title'
550
+	 *
551
+	 * @since  3.1.0
552
+	 * @access public
553
+	 * @abstract
554
+	 * @return array
555
+	 */
556
+	public function get_columns()
557
+	{
558
+		/**
559
+		 * Dynamic hook allowing for adding additional columns in this list table.
560
+		 * Note that $this->screen->id is in the format
561
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
562
+		 * table it is: event-espresso_page_espresso_messages.
563
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
564
+		 * hook prefix ("event-espresso") will be different.
565
+		 *
566
+		 * @var array
567
+		 */
568
+		$columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
569
+		return $columns;
570
+	}
571
+
572
+
573
+	/**
574
+	 * Get an associative array ( id => link ) with the list
575
+	 * of views available on this table.
576
+	 *
577
+	 * @since  3.1.0
578
+	 * @access protected
579
+	 * @return array
580
+	 */
581
+	public function get_views()
582
+	{
583
+		return $this->_views;
584
+	}
585
+
586
+
587
+	/**
588
+	 * Generate the views html.
589
+	 */
590
+	public function display_views()
591
+	{
592
+		$views           = $this->get_views();
593
+		$assembled_views = array();
594
+
595
+		if (empty($views)) {
596
+			return;
597
+		}
598
+		echo "<ul class='subsubsub'>\n";
599
+		foreach ($views as $view) {
600
+			$count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
601
+			if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
602
+				$assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>"
603
+												  . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>'
604
+												  . ' <span class="count">(' . $count . ')</span>';
605
+			}
606
+		}
607
+
608
+		echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
609
+		echo "</ul>";
610
+	}
611
+
612
+
613
+	/**
614
+	 * Generates content for a single row of the table
615
+	 *
616
+	 * @since  4.1
617
+	 * @access public
618
+	 * @param EE_Base_Class $item The current item
619
+	 */
620
+	public function single_row($item)
621
+	{
622
+		$row_class = $this->_get_row_class($item);
623
+		echo '<tr class="' . esc_attr($row_class) . '">';
624
+		$this->single_row_columns($item);
625
+		echo '</tr>';
626
+	}
627
+
628
+
629
+	/**
630
+	 * This simply sets up the row class for the table rows.
631
+	 * Allows for easier overriding of child methods for setting up sorting.
632
+	 *
633
+	 * @param  EE_Base_Class $item the current item
634
+	 * @return string
635
+	 */
636
+	protected function _get_row_class($item)
637
+	{
638
+		static $row_class = '';
639
+		$row_class = ($row_class === '' ? 'alternate' : '');
640
+
641
+		$new_row_class = $row_class;
642
+
643
+		if (! empty($this->_ajax_sorting_callback)) {
644
+			$new_row_class .= ' rowsortable';
645
+		}
646
+
647
+		return $new_row_class;
648
+	}
649
+
650
+
651
+	/**
652
+	 * @return array
653
+	 */
654
+	public function get_sortable_columns()
655
+	{
656
+		return (array)$this->_sortable_columns;
657
+	}
658
+
659
+
660
+	/**
661
+	 * @return string
662
+	 */
663
+	public function get_ajax_sorting_callback()
664
+	{
665
+		return $this->_ajax_sorting_callback;
666
+	}
667
+
668
+
669
+	/**
670
+	 * @return array
671
+	 */
672
+	public function get_hidden_columns()
673
+	{
674
+		$user_id     = get_current_user_id();
675
+		$has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
676
+		if (empty($has_default) && ! empty($this->_hidden_columns)) {
677
+			update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
678
+			update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
679
+		}
680
+		$ref = 'manage' . $this->screen->id . 'columnshidden';
681
+		return (array) get_user_option($ref, $user_id);
682
+	}
683
+
684
+
685
+	/**
686
+	 * Generates the columns for a single row of the table.
687
+	 * Overridden from wp_list_table so as to allow us to filter the column content for a given
688
+	 * column.
689
+	 *
690
+	 * @since 3.1.0
691
+	 * @param EE_Base_Class $item The current item
692
+	 */
693
+	public function single_row_columns($item)
694
+	{
695
+		list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
696
+
697
+		global $wp_version;
698
+		$use_hidden_class = version_compare($wp_version, '4.3-RC', '>=');
699
+
700
+		foreach ($columns as $column_name => $column_display_name) {
701
+
702
+			/**
703
+			 * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
704
+			 * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
705
+			 */
706
+			$hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
707
+			$style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
708
+
709
+			$classes = $column_name . ' column-' . $column_name . $hidden_class;
710
+			if ($primary === $column_name) {
711
+				$classes .= ' has-row-actions column-primary';
712
+			}
713
+
714
+			$data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
715
+
716
+			$class = "class='$classes'";
717
+
718
+			$attributes = "$class$style$data";
719
+
720
+			if ($column_name === 'cb') {
721
+				echo '<th scope="row" class="check-column">';
722
+				echo apply_filters(
723
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
724
+					$this->column_cb($item),
725
+					$item,
726
+					$this
727
+				);
728
+				echo '</th>';
729
+			} elseif (method_exists($this, 'column_' . $column_name)) {
730
+				echo "<td $attributes>";
731
+				echo apply_filters(
732
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
733
+					call_user_func(array($this, 'column_' . $column_name), $item),
734
+					$item,
735
+					$this
736
+				);
737
+				echo $this->handle_row_actions($item, $column_name, $primary);
738
+				echo "</td>";
739
+			} else {
740
+				echo "<td $attributes>";
741
+				echo apply_filters(
742
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
743
+					$this->column_default($item, $column_name),
744
+					$item,
745
+					$column_name,
746
+					$this
747
+				);
748
+				echo $this->handle_row_actions($item, $column_name, $primary);
749
+				echo "</td>";
750
+			}
751
+		}
752
+	}
753
+
754
+
755
+	/**
756
+	 * Extra controls to be displayed between bulk actions and pagination
757
+	 *
758
+	 * @access public
759
+	 * @param string $which
760
+	 * @throws \EE_Error
761
+	 */
762
+	public function extra_tablenav($which)
763
+	{
764
+		if ($which === 'top') {
765
+			$this->_filters();
766
+			echo $this->_get_hidden_fields();
767
+		} else {
768
+			echo '<div class="list-table-bottom-buttons alignleft actions">';
769
+			foreach ($this->_bottom_buttons as $type => $action) {
770
+				$route         = isset($action['route']) ? $action['route'] : '';
771
+				$extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
772
+				echo $this->_admin_page->get_action_link_or_button(
773
+					$route,
774
+					$type,
775
+					$extra_request,
776
+					'button button-secondary',
777
+					'',
778
+					false
779
+				);
780
+			}
781
+			do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
782
+			echo '</div>';
783
+		}
784
+		//echo $this->_entries_per_page_dropdown;
785
+	}
786
+
787
+
788
+	/**
789
+	 * Get an associative array ( option_name => option_title ) with the list
790
+	 * of bulk actions available on this table.
791
+	 *
792
+	 * @since  3.1.0
793
+	 * @access protected
794
+	 * @return array
795
+	 */
796
+	public function get_bulk_actions()
797
+	{
798
+		return (array) $this->_get_bulk_actions();
799
+	}
800
+
801
+	/**
802
+	 * Processing bulk actions.
803
+	 */
804
+	public function process_bulk_action()
805
+	{
806
+		//this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
807
+		//reference in case there is a case where it gets used.
808
+	}
809
+
810
+
811
+	/**
812
+	 * returns the EE admin page this list table is associated with
813
+	 *
814
+	 * @return EE_Admin_Page
815
+	 */
816
+	public function get_admin_page()
817
+	{
818
+		return $this->_admin_page;
819
+	}
820
+
821
+
822
+	/**
823
+	 * A "helper" function for all children to provide an html string of
824
+	 * actions to output in their content.  It is preferable for child classes
825
+	 * to use this method for generating their actions content so that it's
826
+	 * filterable by plugins
827
+	 *
828
+	 * @param string        $action_container           what are the html container
829
+	 *                                                  elements for this actions string?
830
+	 * @param string        $action_class               What class is for the container
831
+	 *                                                  element.
832
+	 * @param string        $action_items               The contents for the action items
833
+	 *                                                  container.  This is filtered before
834
+	 *                                                  returned.
835
+	 * @param string        $action_id                  What id (optional) is used for the
836
+	 *                                                  container element.
837
+	 * @param EE_Base_Class $item                       The object for the column displaying
838
+	 *                                                  the actions.
839
+	 * @return string The assembled action elements container.
840
+	 */
841
+	protected function _action_string(
842
+		$action_items,
843
+		$item,
844
+		$action_container = 'ul',
845
+		$action_class = '',
846
+		$action_id = ''
847
+	) {
848
+		$content      = '';
849
+		$action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
850
+		$action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
851
+		$content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
852
+		try {
853
+			$content .= apply_filters(
854
+				'FHEE__EE_Admin_List_Table___action_string__action_items',
855
+				$action_items,
856
+				$item,
857
+				$this
858
+			);
859
+		} catch (\Exception $e) {
860
+			if (WP_DEBUG) {
861
+				\EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
862
+			}
863
+			$content .= $action_items;
864
+		}
865
+		$content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
866
+		return $content;
867
+	}
868 868
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@  discard block
 block discarded – undo
2 2
 
3 3
 defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed.');
4 4
 
5
-if (! class_exists('WP_List_Table')) {
6
-    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
+if ( ! class_exists('WP_List_Table')) {
6
+    require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
         $this->_view         = $this->_admin_page->get_view();
207 207
         $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208 208
         $this->_current_page = $this->get_pagenum();
209
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
209
+        $this->_screen       = $this->_admin_page->get_current_page().'_'.$this->_admin_page->get_current_view();
210 210
         $this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211 211
 
212
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
212
+        $this->_per_page = $this->get_items_per_page($this->_screen.'_per_page', 10);
213 213
 
214 214
         $this->_setup_data();
215 215
         $this->_add_view_counts();
@@ -289,14 +289,14 @@  discard block
 block discarded – undo
289 289
         $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290 290
         //if action is STILL empty, then we set it to default
291 291
         $action = empty($action) ? 'default' : $action;
292
-        $field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
-        $field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
-        $field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
292
+        $field  = '<input type="hidden" name="page" value="'.$this->_req_data['page'].'" />'."\n";
293
+        $field  .= '<input type="hidden" name="route" value="'.$action.'" />'."\n"; /**/
294
+        $field  .= '<input type="hidden" name="perpage" value="'.$this->_per_page.'" />'."\n";
295 295
 
296 296
         $bulk_actions = $this->_get_bulk_actions();
297 297
         foreach ($bulk_actions as $bulk_action => $label) {
298
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
299
-                . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
298
+            $field .= '<input type="hidden" name="'.$bulk_action.'_nonce"'
299
+                . ' value="'.wp_create_nonce($bulk_action.'_nonce').'" />'."\n";
300 300
         }
301 301
 
302 302
         return $field;
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
                 $_data[0] = $data;
342 342
             }
343 343
 
344
-            $data = (array)$data;
344
+            $data = (array) $data;
345 345
 
346
-            if (! isset($data[1])) {
346
+            if ( ! isset($data[1])) {
347 347
                 $_data[1] = false;
348 348
             }
349 349
 
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
     public function display_tablenav($which)
426 426
     {
427 427
         if ('top' === $which) {
428
-            wp_nonce_field('bulk-' . $this->_args['plural']);
428
+            wp_nonce_field('bulk-'.$this->_args['plural']);
429 429
         }
430 430
         ?>
431 431
         <div class="tablenav <?php echo esc_attr($which); ?>">
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
          * hook prefix ("event-espresso") will be different.
538 538
          */
539 539
         do_action(
540
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
540
+            'AHEE__EE_Admin_List_Table__column_'.$column_name.'__'.$this->screen->id,
541 541
             $item,
542 542
             $this->_screen
543 543
         );
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
          *
566 566
          * @var array
567 567
          */
568
-        $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
568
+        $columns = apply_filters('FHEE_manage_'.$this->screen->id.'_columns', $this->_columns, $this->_screen);
569 569
         return $columns;
570 570
     }
571 571
 
@@ -599,13 +599,13 @@  discard block
 block discarded – undo
599 599
         foreach ($views as $view) {
600 600
             $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
601 601
             if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
602
-                $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>"
603
-                                                  . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>'
604
-                                                  . ' <span class="count">(' . $count . ')</span>';
602
+                $assembled_views[$view['slug']] = "\t<li class='".$view['class']."'>"
603
+                                                  . '<a href="'.$view['url'].'">'.$view['label'].'</a>'
604
+                                                  . ' <span class="count">('.$count.')</span>';
605 605
             }
606 606
         }
607 607
 
608
-        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
608
+        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views)."</li>\n" : '';
609 609
         echo "</ul>";
610 610
     }
611 611
 
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
     public function single_row($item)
621 621
     {
622 622
         $row_class = $this->_get_row_class($item);
623
-        echo '<tr class="' . esc_attr($row_class) . '">';
623
+        echo '<tr class="'.esc_attr($row_class).'">';
624 624
         $this->single_row_columns($item);
625 625
         echo '</tr>';
626 626
     }
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 
641 641
         $new_row_class = $row_class;
642 642
 
643
-        if (! empty($this->_ajax_sorting_callback)) {
643
+        if ( ! empty($this->_ajax_sorting_callback)) {
644 644
             $new_row_class .= ' rowsortable';
645 645
         }
646 646
 
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
      */
654 654
     public function get_sortable_columns()
655 655
     {
656
-        return (array)$this->_sortable_columns;
656
+        return (array) $this->_sortable_columns;
657 657
     }
658 658
 
659 659
 
@@ -672,12 +672,12 @@  discard block
 block discarded – undo
672 672
     public function get_hidden_columns()
673 673
     {
674 674
         $user_id     = get_current_user_id();
675
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
675
+        $has_default = get_user_option('default'.$this->screen->id.'columnshidden', $user_id);
676 676
         if (empty($has_default) && ! empty($this->_hidden_columns)) {
677
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
678
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
677
+            update_user_option($user_id, 'default'.$this->screen->id.'columnshidden', true);
678
+            update_user_option($user_id, 'manage'.$this->screen->id.'columnshidden', $this->_hidden_columns, true);
679 679
         }
680
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
680
+        $ref = 'manage'.$this->screen->id.'columnshidden';
681 681
         return (array) get_user_option($ref, $user_id);
682 682
     }
683 683
 
@@ -706,12 +706,12 @@  discard block
 block discarded – undo
706 706
             $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
707 707
             $style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
708 708
 
709
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
709
+            $classes = $column_name.' column-'.$column_name.$hidden_class;
710 710
             if ($primary === $column_name) {
711 711
                 $classes .= ' has-row-actions column-primary';
712 712
             }
713 713
 
714
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
714
+            $data = ' data-colname="'.wp_strip_all_tags($column_display_name).'"';
715 715
 
716 716
             $class = "class='$classes'";
717 717
 
@@ -726,11 +726,11 @@  discard block
 block discarded – undo
726 726
                     $this
727 727
                 );
728 728
                 echo '</th>';
729
-            } elseif (method_exists($this, 'column_' . $column_name)) {
729
+            } elseif (method_exists($this, 'column_'.$column_name)) {
730 730
                 echo "<td $attributes>";
731 731
                 echo apply_filters(
732
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
733
-                    call_user_func(array($this, 'column_' . $column_name), $item),
732
+                    'FHEE__EE_Admin_List_Table__single_row_columns__column_'.$column_name.'__column_content',
733
+                    call_user_func(array($this, 'column_'.$column_name), $item),
734 734
                     $item,
735 735
                     $this
736 736
                 );
@@ -846,9 +846,9 @@  discard block
 block discarded – undo
846 846
         $action_id = ''
847 847
     ) {
848 848
         $content      = '';
849
-        $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
850
-        $action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
851
-        $content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
849
+        $action_class = ! empty($action_class) ? ' class="'.$action_class.'"' : '';
850
+        $action_id    = ! empty($action_id) ? ' id="'.$action_id.'"' : '';
851
+        $content .= ! empty($action_container) ? '<'.$action_container.$action_class.$action_id.'>' : '';
852 852
         try {
853 853
             $content .= apply_filters(
854 854
                 'FHEE__EE_Admin_List_Table___action_string__action_items',
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
             }
863 863
             $content .= $action_items;
864 864
         }
865
-        $content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
865
+        $content .= ! empty($action_container) ? '</'.$action_container.'>' : '';
866 866
         return $content;
867 867
     }
868 868
 }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +3632 added lines, -3632 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
 /**
@@ -17,2222 +17,2222 @@  discard block
 block discarded – undo
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19 19
     
20
-    /**
21
-     * @type EE_Message_Resource_Manager $_message_resource_manager
22
-     */
23
-    protected $_message_resource_manager;
24
-    
25
-    /**
26
-     * @type string $_active_message_type_name
27
-     */
28
-    protected $_active_message_type_name = '';
29
-    
30
-    /**
31
-     * @type EE_messenger $_active_messenger
32
-     */
33
-    protected $_active_messenger;
34
-    protected $_activate_state;
35
-    protected $_activate_meta_box_type;
36
-    protected $_current_message_meta_box;
37
-    protected $_current_message_meta_box_object;
38
-    protected $_context_switcher;
39
-    protected $_shortcodes = array();
40
-    protected $_active_messengers = array();
41
-    protected $_active_message_types = array();
42
-    
43
-    /**
44
-     * @var EE_Message_Template_Group $_message_template_group
45
-     */
46
-    protected $_message_template_group;
47
-    protected $_m_mt_settings = array();
48
-    
49
-    
50
-    /**
51
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
-     * IF there is no group then it gets automatically set to the Default template pack.
53
-     *
54
-     * @since 4.5.0
55
-     *
56
-     * @var EE_Messages_Template_Pack
57
-     */
58
-    protected $_template_pack;
59
-    
60
-    
61
-    /**
62
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
-     * group is.  If there is no group then it automatically gets set to default.
64
-     *
65
-     * @since 4.5.0
66
-     *
67
-     * @var string
68
-     */
69
-    protected $_variation;
70
-    
71
-    
72
-    /**
73
-     * @param bool $routing
74
-     */
75
-    public function __construct($routing = true)
76
-    {
77
-        //make sure messages autoloader is running
78
-        EED_Messages::set_autoloaders();
79
-        parent::__construct($routing);
80
-    }
81
-    
82
-    
83
-    protected function _init_page_props()
84
-    {
85
-        $this->page_slug        = EE_MSG_PG_SLUG;
86
-        $this->page_label       = __('Messages Settings', 'event_espresso');
87
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
-        $this->_admin_base_path = EE_MSG_ADMIN;
89
-        
90
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
-        
92
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
-        $this->_load_message_resource_manager();
94
-    }
95
-    
96
-    
97
-    /**
98
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
-     *
100
-     *
101
-     * @throws EE_Error
102
-     */
103
-    protected function _load_message_resource_manager()
104
-    {
105
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
-    }
107
-    
108
-    
109
-    /**
110
-     * @deprecated 4.9.9.rc.014
111
-     * @return array
112
-     */
113
-    public function get_messengers_for_list_table()
114
-    {
115
-        EE_Error::doing_it_wrong(
116
-            __METHOD__,
117
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
20
+	/**
21
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
22
+	 */
23
+	protected $_message_resource_manager;
24
+    
25
+	/**
26
+	 * @type string $_active_message_type_name
27
+	 */
28
+	protected $_active_message_type_name = '';
29
+    
30
+	/**
31
+	 * @type EE_messenger $_active_messenger
32
+	 */
33
+	protected $_active_messenger;
34
+	protected $_activate_state;
35
+	protected $_activate_meta_box_type;
36
+	protected $_current_message_meta_box;
37
+	protected $_current_message_meta_box_object;
38
+	protected $_context_switcher;
39
+	protected $_shortcodes = array();
40
+	protected $_active_messengers = array();
41
+	protected $_active_message_types = array();
42
+    
43
+	/**
44
+	 * @var EE_Message_Template_Group $_message_template_group
45
+	 */
46
+	protected $_message_template_group;
47
+	protected $_m_mt_settings = array();
48
+    
49
+    
50
+	/**
51
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
+	 * IF there is no group then it gets automatically set to the Default template pack.
53
+	 *
54
+	 * @since 4.5.0
55
+	 *
56
+	 * @var EE_Messages_Template_Pack
57
+	 */
58
+	protected $_template_pack;
59
+    
60
+    
61
+	/**
62
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
+	 * group is.  If there is no group then it automatically gets set to default.
64
+	 *
65
+	 * @since 4.5.0
66
+	 *
67
+	 * @var string
68
+	 */
69
+	protected $_variation;
70
+    
71
+    
72
+	/**
73
+	 * @param bool $routing
74
+	 */
75
+	public function __construct($routing = true)
76
+	{
77
+		//make sure messages autoloader is running
78
+		EED_Messages::set_autoloaders();
79
+		parent::__construct($routing);
80
+	}
81
+    
82
+    
83
+	protected function _init_page_props()
84
+	{
85
+		$this->page_slug        = EE_MSG_PG_SLUG;
86
+		$this->page_label       = __('Messages Settings', 'event_espresso');
87
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
+		$this->_admin_base_path = EE_MSG_ADMIN;
89
+        
90
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
+        
92
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
+		$this->_load_message_resource_manager();
94
+	}
95
+    
96
+    
97
+	/**
98
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
+	 *
100
+	 *
101
+	 * @throws EE_Error
102
+	 */
103
+	protected function _load_message_resource_manager()
104
+	{
105
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
+	}
107
+    
108
+    
109
+	/**
110
+	 * @deprecated 4.9.9.rc.014
111
+	 * @return array
112
+	 */
113
+	public function get_messengers_for_list_table()
114
+	{
115
+		EE_Error::doing_it_wrong(
116
+			__METHOD__,
117
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
118 118
 			values for use in creating a messenger filter dropdown which is now generated differently via
119 119
 			 Messages_Admin_Page::get_messengers_select_input', 'event_espresso'),
120
-            '4.9.9.rc.014'
121
-        );
122
-        
123
-        $m_values          = array();
124
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
-        //setup messengers for selects
126
-        $i = 1;
127
-        foreach ($active_messengers as $active_messenger) {
128
-            if ($active_messenger instanceof EE_Message) {
129
-                $m_values[$i]['id']   = $active_messenger->messenger();
130
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
-                $i++;
132
-            }
133
-        }
134
-        
135
-        return $m_values;
136
-    }
137
-    
138
-    
139
-    /**
140
-     * @deprecated 4.9.9.rc.014
141
-     * @return array
142
-     */
143
-    public function get_message_types_for_list_table()
144
-    {
145
-        EE_Error::doing_it_wrong(
146
-            __METHOD__,
147
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
120
+			'4.9.9.rc.014'
121
+		);
122
+        
123
+		$m_values          = array();
124
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
+		//setup messengers for selects
126
+		$i = 1;
127
+		foreach ($active_messengers as $active_messenger) {
128
+			if ($active_messenger instanceof EE_Message) {
129
+				$m_values[$i]['id']   = $active_messenger->messenger();
130
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
+				$i++;
132
+			}
133
+		}
134
+        
135
+		return $m_values;
136
+	}
137
+    
138
+    
139
+	/**
140
+	 * @deprecated 4.9.9.rc.014
141
+	 * @return array
142
+	 */
143
+	public function get_message_types_for_list_table()
144
+	{
145
+		EE_Error::doing_it_wrong(
146
+			__METHOD__,
147
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
148 148
 			values for use in creating a message type filter dropdown which is now generated differently via
149 149
 			 Messages_Admin_Page::get_message_types_select_input', 'event_espresso'),
150
-            '4.9.9.rc.014'
151
-        );
152
-        
153
-        $mt_values       = array();
154
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
-        $i               = 1;
156
-        foreach ($active_messages as $active_message) {
157
-            if ($active_message instanceof EE_Message) {
158
-                $mt_values[$i]['id']   = $active_message->message_type();
159
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
-                $i++;
161
-            }
162
-        }
163
-        
164
-        return $mt_values;
165
-    }
166
-    
167
-    
168
-    /**
169
-     * @deprecated 4.9.9.rc.014
170
-     * @return array
171
-     */
172
-    public function get_contexts_for_message_types_for_list_table()
173
-    {
174
-        EE_Error::doing_it_wrong(
175
-            __METHOD__,
176
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
150
+			'4.9.9.rc.014'
151
+		);
152
+        
153
+		$mt_values       = array();
154
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
+		$i               = 1;
156
+		foreach ($active_messages as $active_message) {
157
+			if ($active_message instanceof EE_Message) {
158
+				$mt_values[$i]['id']   = $active_message->message_type();
159
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
+				$i++;
161
+			}
162
+		}
163
+        
164
+		return $mt_values;
165
+	}
166
+    
167
+    
168
+	/**
169
+	 * @deprecated 4.9.9.rc.014
170
+	 * @return array
171
+	 */
172
+	public function get_contexts_for_message_types_for_list_table()
173
+	{
174
+		EE_Error::doing_it_wrong(
175
+			__METHOD__,
176
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
177 177
 			values for use in creating a message type context filter dropdown which is now generated differently via
178 178
 			 Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'),
179
-            '4.9.9.rc.014'
180
-        );
181
-        
182
-        $contexts                = array();
183
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
-        foreach ($active_message_contexts as $active_message) {
185
-            if ($active_message instanceof EE_Message) {
186
-                $message_type = $active_message->message_type_object();
187
-                if ($message_type instanceof EE_message_type) {
188
-                    $message_type_contexts = $message_type->get_contexts();
189
-                    foreach ($message_type_contexts as $context => $context_details) {
190
-                        $contexts[$context] = $context_details['label'];
191
-                    }
192
-                }
193
-            }
194
-        }
195
-        
196
-        return $contexts;
197
-    }
198
-    
199
-    
200
-    /**
201
-     * Generate select input with provided messenger options array.
202
-     *
203
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
-     *                                 labels.
205
-     *
206
-     * @return string
207
-     */
208
-    public function get_messengers_select_input($messenger_options)
209
-    {
210
-        //if empty or just one value then just return an empty string
211
-        if (empty($messenger_options)
212
-            || ! is_array($messenger_options)
213
-            || count($messenger_options) === 1
214
-        ) {
215
-            return '';
216
-        }
217
-        //merge in default
218
-        $messenger_options = array_merge(
219
-            array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
-            $messenger_options
221
-        );
222
-        $input             = new EE_Select_Input(
223
-            $messenger_options,
224
-            array(
225
-                'html_name'  => 'ee_messenger_filter_by',
226
-                'html_id'    => 'ee_messenger_filter_by',
227
-                'html_class' => 'wide',
228
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
-                    : 'none_selected'
231
-            )
232
-        );
233
-        
234
-        return $input->get_html_for_input();
235
-    }
236
-    
237
-    
238
-    /**
239
-     * Generate select input with provided message type options array.
240
-     *
241
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
-     *                                    message type labels
243
-     *
244
-     * @return string
245
-     */
246
-    public function get_message_types_select_input($message_type_options)
247
-    {
248
-        //if empty or count of options is 1 then just return an empty string
249
-        if (empty($message_type_options)
250
-            || ! is_array($message_type_options)
251
-            || count($message_type_options) === 1
252
-        ) {
253
-            return '';
254
-        }
255
-        //merge in default
256
-        $message_type_options = array_merge(
257
-            array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
-            $message_type_options
259
-        );
260
-        $input                = new EE_Select_Input(
261
-            $message_type_options,
262
-            array(
263
-                'html_name'  => 'ee_message_type_filter_by',
264
-                'html_id'    => 'ee_message_type_filter_by',
265
-                'html_class' => 'wide',
266
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
-                    : 'none_selected',
269
-            )
270
-        );
271
-        
272
-        return $input->get_html_for_input();
273
-    }
274
-    
275
-    
276
-    /**
277
-     * Generate select input with provide message type contexts array.
278
-     *
279
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
-     *                               context label.
281
-     *
282
-     * @return string
283
-     */
284
-    public function get_contexts_for_message_types_select_input($context_options)
285
-    {
286
-        //if empty or count of options is one then just return empty string
287
-        if (empty($context_options)
288
-            || ! is_array($context_options)
289
-            || count($context_options) === 1
290
-        ) {
291
-            return '';
292
-        }
293
-        //merge in default
294
-        $context_options = array_merge(
295
-            array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
-            $context_options
297
-        );
298
-        $input           = new EE_Select_Input(
299
-            $context_options,
300
-            array(
301
-                'html_name'  => 'ee_context_filter_by',
302
-                'html_id'    => 'ee_context_filter_by',
303
-                'html_class' => 'wide',
304
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
305
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
306
-                    : 'none_selected',
307
-            )
308
-        );
309
-        
310
-        return $input->get_html_for_input();
311
-    }
312
-    
313
-    
314
-    protected function _ajax_hooks()
315
-    {
316
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
-    }
322
-    
323
-    
324
-    protected function _define_page_props()
325
-    {
326
-        $this->_admin_page_title = $this->page_label;
327
-        $this->_labels           = array(
328
-            'buttons'    => array(
329
-                'add'    => __('Add New Message Template', 'event_espresso'),
330
-                'edit'   => __('Edit Message Template', 'event_espresso'),
331
-                'delete' => __('Delete Message Template', 'event_espresso')
332
-            ),
333
-            'publishbox' => __('Update Actions', 'event_espresso')
334
-        );
335
-    }
336
-    
337
-    
338
-    /**
339
-     *        an array for storing key => value pairs of request actions and their corresponding methods
340
-     * @access protected
341
-     * @return void
342
-     */
343
-    protected function _set_page_routes()
344
-    {
345
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
-            ? $this->_req_data['GRP_ID']
347
-            : 0;
348
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
-            ? $this->_req_data['id']
350
-            : $grp_id;
351
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
-            ? $this->_req_data['MSG_ID']
353
-            : 0;
354
-        
355
-        $this->_page_routes = array(
356
-            'default'                          => array(
357
-                'func'       => '_message_queue_list_table',
358
-                'capability' => 'ee_read_global_messages'
359
-            ),
360
-            'global_mtps'                      => array(
361
-                'func'       => '_ee_default_messages_overview_list_table',
362
-                'capability' => 'ee_read_global_messages'
363
-            ),
364
-            'custom_mtps'                      => array(
365
-                'func'       => '_custom_mtps_preview',
366
-                'capability' => 'ee_read_messages'
367
-            ),
368
-            'add_new_message_template'         => array(
369
-                'func'       => '_add_message_template',
370
-                'capability' => 'ee_edit_messages',
371
-                'noheader'   => true
372
-            ),
373
-            'edit_message_template'            => array(
374
-                'func'       => '_edit_message_template',
375
-                'capability' => 'ee_edit_message',
376
-                'obj_id'     => $grp_id
377
-            ),
378
-            'preview_message'                  => array(
379
-                'func'               => '_preview_message',
380
-                'capability'         => 'ee_read_message',
381
-                'obj_id'             => $grp_id,
382
-                'noheader'           => true,
383
-                'headers_sent_route' => 'display_preview_message'
384
-            ),
385
-            'display_preview_message'          => array(
386
-                'func'       => '_display_preview_message',
387
-                'capability' => 'ee_read_message',
388
-                'obj_id'     => $grp_id
389
-            ),
390
-            'insert_message_template'          => array(
391
-                'func'       => '_insert_or_update_message_template',
392
-                'capability' => 'ee_edit_messages',
393
-                'args'       => array('new_template' => true),
394
-                'noheader'   => true
395
-            ),
396
-            'update_message_template'          => array(
397
-                'func'       => '_insert_or_update_message_template',
398
-                'capability' => 'ee_edit_message',
399
-                'obj_id'     => $grp_id,
400
-                'args'       => array('new_template' => false),
401
-                'noheader'   => true
402
-            ),
403
-            'trash_message_template'           => array(
404
-                'func'       => '_trash_or_restore_message_template',
405
-                'capability' => 'ee_delete_message',
406
-                'obj_id'     => $grp_id,
407
-                'args'       => array('trash' => true, 'all' => true),
408
-                'noheader'   => true
409
-            ),
410
-            'trash_message_template_context'   => array(
411
-                'func'       => '_trash_or_restore_message_template',
412
-                'capability' => 'ee_delete_message',
413
-                'obj_id'     => $grp_id,
414
-                'args'       => array('trash' => true),
415
-                'noheader'   => true
416
-            ),
417
-            'restore_message_template'         => array(
418
-                'func'       => '_trash_or_restore_message_template',
419
-                'capability' => 'ee_delete_message',
420
-                'obj_id'     => $grp_id,
421
-                'args'       => array('trash' => false, 'all' => true),
422
-                'noheader'   => true
423
-            ),
424
-            'restore_message_template_context' => array(
425
-                'func'       => '_trash_or_restore_message_template',
426
-                'capability' => 'ee_delete_message',
427
-                'obj_id'     => $grp_id,
428
-                'args'       => array('trash' => false),
429
-                'noheader'   => true
430
-            ),
431
-            'delete_message_template'          => array(
432
-                'func'       => '_delete_message_template',
433
-                'capability' => 'ee_delete_message',
434
-                'obj_id'     => $grp_id,
435
-                'noheader'   => true
436
-            ),
437
-            'reset_to_default'                 => array(
438
-                'func'       => '_reset_to_default_template',
439
-                'capability' => 'ee_edit_message',
440
-                'obj_id'     => $grp_id,
441
-                'noheader'   => true
442
-            ),
443
-            'settings'                         => array(
444
-                'func'       => '_settings',
445
-                'capability' => 'manage_options'
446
-            ),
447
-            'update_global_settings'           => array(
448
-                'func'       => '_update_global_settings',
449
-                'capability' => 'manage_options',
450
-                'noheader'   => true
451
-            ),
452
-            'generate_now'                     => array(
453
-                'func'       => '_generate_now',
454
-                'capability' => 'ee_send_message',
455
-                'noheader'   => true
456
-            ),
457
-            'generate_and_send_now'            => array(
458
-                'func'       => '_generate_and_send_now',
459
-                'capability' => 'ee_send_message',
460
-                'noheader'   => true
461
-            ),
462
-            'queue_for_resending'              => array(
463
-                'func'       => '_queue_for_resending',
464
-                'capability' => 'ee_send_message',
465
-                'noheader'   => true
466
-            ),
467
-            'send_now'                         => array(
468
-                'func'       => '_send_now',
469
-                'capability' => 'ee_send_message',
470
-                'noheader'   => true
471
-            ),
472
-            'delete_ee_message'                => array(
473
-                'func'       => '_delete_ee_messages',
474
-                'capability' => 'ee_delete_message',
475
-                'noheader'   => true
476
-            ),
477
-            'delete_ee_messages'               => array(
478
-                'func'       => '_delete_ee_messages',
479
-                'capability' => 'ee_delete_messages',
480
-                'noheader'   => true,
481
-                'obj_id'     => $msg_id
482
-            )
483
-        );
484
-    }
485
-    
486
-    
487
-    protected function _set_page_config()
488
-    {
489
-        $this->_page_config = array(
490
-            'default'                  => array(
491
-                'nav'           => array(
492
-                    'label' => __('Message Activity', 'event_espresso'),
493
-                    'order' => 10
494
-                ),
495
-                'list_table'    => 'EE_Message_List_Table',
496
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
-                'require_nonce' => false
498
-            ),
499
-            'global_mtps'              => array(
500
-                'nav'           => array(
501
-                    'label' => __('Default Message Templates', 'event_espresso'),
502
-                    'order' => 20
503
-                ),
504
-                'list_table'    => 'Messages_Template_List_Table',
505
-                'help_tabs'     => array(
506
-                    'messages_overview_help_tab'                                => array(
507
-                        'title'    => __('Messages Overview', 'event_espresso'),
508
-                        'filename' => 'messages_overview'
509
-                    ),
510
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
511
-                        'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
-                        'filename' => 'messages_overview_table_column_headings'
513
-                    ),
514
-                    'messages_overview_messages_filters_help_tab'               => array(
515
-                        'title'    => __('Message Filters', 'event_espresso'),
516
-                        'filename' => 'messages_overview_filters'
517
-                    ),
518
-                    'messages_overview_messages_views_help_tab'                 => array(
519
-                        'title'    => __('Message Views', 'event_espresso'),
520
-                        'filename' => 'messages_overview_views'
521
-                    ),
522
-                    'message_overview_message_types_help_tab'                   => array(
523
-                        'title'    => __('Message Types', 'event_espresso'),
524
-                        'filename' => 'messages_overview_types'
525
-                    ),
526
-                    'messages_overview_messengers_help_tab'                     => array(
527
-                        'title'    => __('Messengers', 'event_espresso'),
528
-                        'filename' => 'messages_overview_messengers',
529
-                    ),
530
-                ),
531
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
532
-                'require_nonce' => false
533
-            ),
534
-            'custom_mtps'              => array(
535
-                'nav'           => array(
536
-                    'label' => __('Custom Message Templates', 'event_espresso'),
537
-                    'order' => 30
538
-                ),
539
-                'help_tabs'     => array(),
540
-                'help_tour'     => array(),
541
-                'require_nonce' => false
542
-            ),
543
-            'add_new_message_template' => array(
544
-                'nav'           => array(
545
-                    'label'      => __('Add New Message Templates', 'event_espresso'),
546
-                    'order'      => 5,
547
-                    'persistent' => false
548
-                ),
549
-                'require_nonce' => false
550
-            ),
551
-            'edit_message_template'    => array(
552
-                'labels'        => array(
553
-                    'buttons'    => array(
554
-                        'reset' => __('Reset Templates'),
555
-                    ),
556
-                    'publishbox' => __('Update Actions', 'event_espresso')
557
-                ),
558
-                'nav'           => array(
559
-                    'label'      => __('Edit Message Templates', 'event_espresso'),
560
-                    'order'      => 5,
561
-                    'persistent' => false,
562
-                    'url'        => ''
563
-                ),
564
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
565
-                'has_metaboxes' => true,
566
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
567
-                'help_tabs'     => array(
568
-                    'edit_message_template'       => array(
569
-                        'title'    => __('Message Template Editor', 'event_espresso'),
570
-                        'callback' => 'edit_message_template_help_tab'
571
-                    ),
572
-                    'message_templates_help_tab'  => array(
573
-                        'title'    => __('Message Templates', 'event_espresso'),
574
-                        'filename' => 'messages_templates'
575
-                    ),
576
-                    'message_template_shortcodes' => array(
577
-                        'title'    => __('Message Shortcodes', 'event_espresso'),
578
-                        'callback' => 'message_template_shortcodes_help_tab'
579
-                    ),
580
-                    'message_preview_help_tab'    => array(
581
-                        'title'    => __('Message Preview', 'event_espresso'),
582
-                        'filename' => 'messages_preview'
583
-                    ),
584
-                    'messages_overview_other_help_tab'                          => array(
585
-                        'title'    => __('Messages Other', 'event_espresso'),
586
-                        'filename' => 'messages_overview_other',
587
-                    ),
588
-                ),
589
-                'require_nonce' => false
590
-            ),
591
-            'display_preview_message'  => array(
592
-                'nav'           => array(
593
-                    'label'      => __('Message Preview', 'event_espresso'),
594
-                    'order'      => 5,
595
-                    'url'        => '',
596
-                    'persistent' => false
597
-                ),
598
-                'help_tabs'     => array(
599
-                    'preview_message' => array(
600
-                        'title'    => __('About Previews', 'event_espresso'),
601
-                        'callback' => 'preview_message_help_tab'
602
-                    )
603
-                ),
604
-                'require_nonce' => false
605
-            ),
606
-            'settings'                 => array(
607
-                'nav'           => array(
608
-                    'label' => __('Settings', 'event_espresso'),
609
-                    'order' => 40
610
-                ),
611
-                'metaboxes'     => array('_messages_settings_metaboxes'),
612
-                'help_tabs'     => array(
613
-                    'messages_settings_help_tab'               => array(
614
-                        'title'    => __('Messages Settings', 'event_espresso'),
615
-                        'filename' => 'messages_settings'
616
-                    ),
617
-                    'messages_settings_message_types_help_tab' => array(
618
-                        'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
-                        'filename' => 'messages_settings_message_types'
620
-                    ),
621
-                    'messages_settings_messengers_help_tab'    => array(
622
-                        'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
-                        'filename' => 'messages_settings_messengers'
624
-                    ),
625
-                ),
626
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
627
-                'require_nonce' => false
628
-            )
629
-        );
630
-    }
631
-    
632
-    
633
-    protected function _add_screen_options()
634
-    {
635
-        //todo
636
-    }
637
-    
638
-    
639
-    protected function _add_screen_options_global_mtps()
640
-    {
641
-        /**
642
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
644
-         */
645
-        $page_title              = $this->_admin_page_title;
646
-        $this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
-        $this->_per_page_screen_option();
648
-        $this->_admin_page_title = $page_title;
649
-    }
650
-    
651
-    
652
-    protected function _add_screen_options_default()
653
-    {
654
-        $this->_admin_page_title = __('Message Activity', 'event_espresso');
655
-        $this->_per_page_screen_option();
656
-    }
657
-    
658
-    
659
-    //none of the below group are currently used for Messages
660
-    protected function _add_feature_pointers()
661
-    {
662
-    }
663
-    
664
-    public function admin_init()
665
-    {
666
-    }
667
-    
668
-    public function admin_notices()
669
-    {
670
-    }
671
-    
672
-    public function admin_footer_scripts()
673
-    {
674
-    }
675
-    
676
-    
677
-    public function messages_help_tab()
678
-    {
679
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
-    }
681
-    
682
-    
683
-    public function messengers_help_tab()
684
-    {
685
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
-    }
687
-    
688
-    
689
-    public function message_types_help_tab()
690
-    {
691
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
-    }
693
-    
694
-    
695
-    public function messages_overview_help_tab()
696
-    {
697
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
-    }
699
-    
700
-    
701
-    public function message_templates_help_tab()
702
-    {
703
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
-    }
705
-    
706
-    
707
-    public function edit_message_template_help_tab()
708
-    {
709
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
-                'event_espresso') . '" />';
711
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
-                'event_espresso') . '" />';
713
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
-                'event_espresso') . '" />';
715
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
-                'event_espresso') . '" />';
717
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
-                'event_espresso') . '" />';
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
-            $args);
721
-    }
722
-    
723
-    
724
-    public function message_template_shortcodes_help_tab()
725
-    {
726
-        $this->_set_shortcodes();
727
-        $args['shortcodes'] = $this->_shortcodes;
728
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
-            $args);
730
-    }
179
+			'4.9.9.rc.014'
180
+		);
181
+        
182
+		$contexts                = array();
183
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
+		foreach ($active_message_contexts as $active_message) {
185
+			if ($active_message instanceof EE_Message) {
186
+				$message_type = $active_message->message_type_object();
187
+				if ($message_type instanceof EE_message_type) {
188
+					$message_type_contexts = $message_type->get_contexts();
189
+					foreach ($message_type_contexts as $context => $context_details) {
190
+						$contexts[$context] = $context_details['label'];
191
+					}
192
+				}
193
+			}
194
+		}
195
+        
196
+		return $contexts;
197
+	}
198
+    
199
+    
200
+	/**
201
+	 * Generate select input with provided messenger options array.
202
+	 *
203
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
+	 *                                 labels.
205
+	 *
206
+	 * @return string
207
+	 */
208
+	public function get_messengers_select_input($messenger_options)
209
+	{
210
+		//if empty or just one value then just return an empty string
211
+		if (empty($messenger_options)
212
+			|| ! is_array($messenger_options)
213
+			|| count($messenger_options) === 1
214
+		) {
215
+			return '';
216
+		}
217
+		//merge in default
218
+		$messenger_options = array_merge(
219
+			array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
+			$messenger_options
221
+		);
222
+		$input             = new EE_Select_Input(
223
+			$messenger_options,
224
+			array(
225
+				'html_name'  => 'ee_messenger_filter_by',
226
+				'html_id'    => 'ee_messenger_filter_by',
227
+				'html_class' => 'wide',
228
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
+					: 'none_selected'
231
+			)
232
+		);
233
+        
234
+		return $input->get_html_for_input();
235
+	}
236
+    
237
+    
238
+	/**
239
+	 * Generate select input with provided message type options array.
240
+	 *
241
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
+	 *                                    message type labels
243
+	 *
244
+	 * @return string
245
+	 */
246
+	public function get_message_types_select_input($message_type_options)
247
+	{
248
+		//if empty or count of options is 1 then just return an empty string
249
+		if (empty($message_type_options)
250
+			|| ! is_array($message_type_options)
251
+			|| count($message_type_options) === 1
252
+		) {
253
+			return '';
254
+		}
255
+		//merge in default
256
+		$message_type_options = array_merge(
257
+			array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
+			$message_type_options
259
+		);
260
+		$input                = new EE_Select_Input(
261
+			$message_type_options,
262
+			array(
263
+				'html_name'  => 'ee_message_type_filter_by',
264
+				'html_id'    => 'ee_message_type_filter_by',
265
+				'html_class' => 'wide',
266
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
+					: 'none_selected',
269
+			)
270
+		);
271
+        
272
+		return $input->get_html_for_input();
273
+	}
274
+    
275
+    
276
+	/**
277
+	 * Generate select input with provide message type contexts array.
278
+	 *
279
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
+	 *                               context label.
281
+	 *
282
+	 * @return string
283
+	 */
284
+	public function get_contexts_for_message_types_select_input($context_options)
285
+	{
286
+		//if empty or count of options is one then just return empty string
287
+		if (empty($context_options)
288
+			|| ! is_array($context_options)
289
+			|| count($context_options) === 1
290
+		) {
291
+			return '';
292
+		}
293
+		//merge in default
294
+		$context_options = array_merge(
295
+			array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
+			$context_options
297
+		);
298
+		$input           = new EE_Select_Input(
299
+			$context_options,
300
+			array(
301
+				'html_name'  => 'ee_context_filter_by',
302
+				'html_id'    => 'ee_context_filter_by',
303
+				'html_class' => 'wide',
304
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
305
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
306
+					: 'none_selected',
307
+			)
308
+		);
309
+        
310
+		return $input->get_html_for_input();
311
+	}
312
+    
313
+    
314
+	protected function _ajax_hooks()
315
+	{
316
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
+	}
322
+    
323
+    
324
+	protected function _define_page_props()
325
+	{
326
+		$this->_admin_page_title = $this->page_label;
327
+		$this->_labels           = array(
328
+			'buttons'    => array(
329
+				'add'    => __('Add New Message Template', 'event_espresso'),
330
+				'edit'   => __('Edit Message Template', 'event_espresso'),
331
+				'delete' => __('Delete Message Template', 'event_espresso')
332
+			),
333
+			'publishbox' => __('Update Actions', 'event_espresso')
334
+		);
335
+	}
336
+    
337
+    
338
+	/**
339
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
340
+	 * @access protected
341
+	 * @return void
342
+	 */
343
+	protected function _set_page_routes()
344
+	{
345
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
+			? $this->_req_data['GRP_ID']
347
+			: 0;
348
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
+			? $this->_req_data['id']
350
+			: $grp_id;
351
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
+			? $this->_req_data['MSG_ID']
353
+			: 0;
354
+        
355
+		$this->_page_routes = array(
356
+			'default'                          => array(
357
+				'func'       => '_message_queue_list_table',
358
+				'capability' => 'ee_read_global_messages'
359
+			),
360
+			'global_mtps'                      => array(
361
+				'func'       => '_ee_default_messages_overview_list_table',
362
+				'capability' => 'ee_read_global_messages'
363
+			),
364
+			'custom_mtps'                      => array(
365
+				'func'       => '_custom_mtps_preview',
366
+				'capability' => 'ee_read_messages'
367
+			),
368
+			'add_new_message_template'         => array(
369
+				'func'       => '_add_message_template',
370
+				'capability' => 'ee_edit_messages',
371
+				'noheader'   => true
372
+			),
373
+			'edit_message_template'            => array(
374
+				'func'       => '_edit_message_template',
375
+				'capability' => 'ee_edit_message',
376
+				'obj_id'     => $grp_id
377
+			),
378
+			'preview_message'                  => array(
379
+				'func'               => '_preview_message',
380
+				'capability'         => 'ee_read_message',
381
+				'obj_id'             => $grp_id,
382
+				'noheader'           => true,
383
+				'headers_sent_route' => 'display_preview_message'
384
+			),
385
+			'display_preview_message'          => array(
386
+				'func'       => '_display_preview_message',
387
+				'capability' => 'ee_read_message',
388
+				'obj_id'     => $grp_id
389
+			),
390
+			'insert_message_template'          => array(
391
+				'func'       => '_insert_or_update_message_template',
392
+				'capability' => 'ee_edit_messages',
393
+				'args'       => array('new_template' => true),
394
+				'noheader'   => true
395
+			),
396
+			'update_message_template'          => array(
397
+				'func'       => '_insert_or_update_message_template',
398
+				'capability' => 'ee_edit_message',
399
+				'obj_id'     => $grp_id,
400
+				'args'       => array('new_template' => false),
401
+				'noheader'   => true
402
+			),
403
+			'trash_message_template'           => array(
404
+				'func'       => '_trash_or_restore_message_template',
405
+				'capability' => 'ee_delete_message',
406
+				'obj_id'     => $grp_id,
407
+				'args'       => array('trash' => true, 'all' => true),
408
+				'noheader'   => true
409
+			),
410
+			'trash_message_template_context'   => array(
411
+				'func'       => '_trash_or_restore_message_template',
412
+				'capability' => 'ee_delete_message',
413
+				'obj_id'     => $grp_id,
414
+				'args'       => array('trash' => true),
415
+				'noheader'   => true
416
+			),
417
+			'restore_message_template'         => array(
418
+				'func'       => '_trash_or_restore_message_template',
419
+				'capability' => 'ee_delete_message',
420
+				'obj_id'     => $grp_id,
421
+				'args'       => array('trash' => false, 'all' => true),
422
+				'noheader'   => true
423
+			),
424
+			'restore_message_template_context' => array(
425
+				'func'       => '_trash_or_restore_message_template',
426
+				'capability' => 'ee_delete_message',
427
+				'obj_id'     => $grp_id,
428
+				'args'       => array('trash' => false),
429
+				'noheader'   => true
430
+			),
431
+			'delete_message_template'          => array(
432
+				'func'       => '_delete_message_template',
433
+				'capability' => 'ee_delete_message',
434
+				'obj_id'     => $grp_id,
435
+				'noheader'   => true
436
+			),
437
+			'reset_to_default'                 => array(
438
+				'func'       => '_reset_to_default_template',
439
+				'capability' => 'ee_edit_message',
440
+				'obj_id'     => $grp_id,
441
+				'noheader'   => true
442
+			),
443
+			'settings'                         => array(
444
+				'func'       => '_settings',
445
+				'capability' => 'manage_options'
446
+			),
447
+			'update_global_settings'           => array(
448
+				'func'       => '_update_global_settings',
449
+				'capability' => 'manage_options',
450
+				'noheader'   => true
451
+			),
452
+			'generate_now'                     => array(
453
+				'func'       => '_generate_now',
454
+				'capability' => 'ee_send_message',
455
+				'noheader'   => true
456
+			),
457
+			'generate_and_send_now'            => array(
458
+				'func'       => '_generate_and_send_now',
459
+				'capability' => 'ee_send_message',
460
+				'noheader'   => true
461
+			),
462
+			'queue_for_resending'              => array(
463
+				'func'       => '_queue_for_resending',
464
+				'capability' => 'ee_send_message',
465
+				'noheader'   => true
466
+			),
467
+			'send_now'                         => array(
468
+				'func'       => '_send_now',
469
+				'capability' => 'ee_send_message',
470
+				'noheader'   => true
471
+			),
472
+			'delete_ee_message'                => array(
473
+				'func'       => '_delete_ee_messages',
474
+				'capability' => 'ee_delete_message',
475
+				'noheader'   => true
476
+			),
477
+			'delete_ee_messages'               => array(
478
+				'func'       => '_delete_ee_messages',
479
+				'capability' => 'ee_delete_messages',
480
+				'noheader'   => true,
481
+				'obj_id'     => $msg_id
482
+			)
483
+		);
484
+	}
485
+    
486
+    
487
+	protected function _set_page_config()
488
+	{
489
+		$this->_page_config = array(
490
+			'default'                  => array(
491
+				'nav'           => array(
492
+					'label' => __('Message Activity', 'event_espresso'),
493
+					'order' => 10
494
+				),
495
+				'list_table'    => 'EE_Message_List_Table',
496
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
+				'require_nonce' => false
498
+			),
499
+			'global_mtps'              => array(
500
+				'nav'           => array(
501
+					'label' => __('Default Message Templates', 'event_espresso'),
502
+					'order' => 20
503
+				),
504
+				'list_table'    => 'Messages_Template_List_Table',
505
+				'help_tabs'     => array(
506
+					'messages_overview_help_tab'                                => array(
507
+						'title'    => __('Messages Overview', 'event_espresso'),
508
+						'filename' => 'messages_overview'
509
+					),
510
+					'messages_overview_messages_table_column_headings_help_tab' => array(
511
+						'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
+						'filename' => 'messages_overview_table_column_headings'
513
+					),
514
+					'messages_overview_messages_filters_help_tab'               => array(
515
+						'title'    => __('Message Filters', 'event_espresso'),
516
+						'filename' => 'messages_overview_filters'
517
+					),
518
+					'messages_overview_messages_views_help_tab'                 => array(
519
+						'title'    => __('Message Views', 'event_espresso'),
520
+						'filename' => 'messages_overview_views'
521
+					),
522
+					'message_overview_message_types_help_tab'                   => array(
523
+						'title'    => __('Message Types', 'event_espresso'),
524
+						'filename' => 'messages_overview_types'
525
+					),
526
+					'messages_overview_messengers_help_tab'                     => array(
527
+						'title'    => __('Messengers', 'event_espresso'),
528
+						'filename' => 'messages_overview_messengers',
529
+					),
530
+				),
531
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
532
+				'require_nonce' => false
533
+			),
534
+			'custom_mtps'              => array(
535
+				'nav'           => array(
536
+					'label' => __('Custom Message Templates', 'event_espresso'),
537
+					'order' => 30
538
+				),
539
+				'help_tabs'     => array(),
540
+				'help_tour'     => array(),
541
+				'require_nonce' => false
542
+			),
543
+			'add_new_message_template' => array(
544
+				'nav'           => array(
545
+					'label'      => __('Add New Message Templates', 'event_espresso'),
546
+					'order'      => 5,
547
+					'persistent' => false
548
+				),
549
+				'require_nonce' => false
550
+			),
551
+			'edit_message_template'    => array(
552
+				'labels'        => array(
553
+					'buttons'    => array(
554
+						'reset' => __('Reset Templates'),
555
+					),
556
+					'publishbox' => __('Update Actions', 'event_espresso')
557
+				),
558
+				'nav'           => array(
559
+					'label'      => __('Edit Message Templates', 'event_espresso'),
560
+					'order'      => 5,
561
+					'persistent' => false,
562
+					'url'        => ''
563
+				),
564
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
565
+				'has_metaboxes' => true,
566
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
567
+				'help_tabs'     => array(
568
+					'edit_message_template'       => array(
569
+						'title'    => __('Message Template Editor', 'event_espresso'),
570
+						'callback' => 'edit_message_template_help_tab'
571
+					),
572
+					'message_templates_help_tab'  => array(
573
+						'title'    => __('Message Templates', 'event_espresso'),
574
+						'filename' => 'messages_templates'
575
+					),
576
+					'message_template_shortcodes' => array(
577
+						'title'    => __('Message Shortcodes', 'event_espresso'),
578
+						'callback' => 'message_template_shortcodes_help_tab'
579
+					),
580
+					'message_preview_help_tab'    => array(
581
+						'title'    => __('Message Preview', 'event_espresso'),
582
+						'filename' => 'messages_preview'
583
+					),
584
+					'messages_overview_other_help_tab'                          => array(
585
+						'title'    => __('Messages Other', 'event_espresso'),
586
+						'filename' => 'messages_overview_other',
587
+					),
588
+				),
589
+				'require_nonce' => false
590
+			),
591
+			'display_preview_message'  => array(
592
+				'nav'           => array(
593
+					'label'      => __('Message Preview', 'event_espresso'),
594
+					'order'      => 5,
595
+					'url'        => '',
596
+					'persistent' => false
597
+				),
598
+				'help_tabs'     => array(
599
+					'preview_message' => array(
600
+						'title'    => __('About Previews', 'event_espresso'),
601
+						'callback' => 'preview_message_help_tab'
602
+					)
603
+				),
604
+				'require_nonce' => false
605
+			),
606
+			'settings'                 => array(
607
+				'nav'           => array(
608
+					'label' => __('Settings', 'event_espresso'),
609
+					'order' => 40
610
+				),
611
+				'metaboxes'     => array('_messages_settings_metaboxes'),
612
+				'help_tabs'     => array(
613
+					'messages_settings_help_tab'               => array(
614
+						'title'    => __('Messages Settings', 'event_espresso'),
615
+						'filename' => 'messages_settings'
616
+					),
617
+					'messages_settings_message_types_help_tab' => array(
618
+						'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
+						'filename' => 'messages_settings_message_types'
620
+					),
621
+					'messages_settings_messengers_help_tab'    => array(
622
+						'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
+						'filename' => 'messages_settings_messengers'
624
+					),
625
+				),
626
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
627
+				'require_nonce' => false
628
+			)
629
+		);
630
+	}
631
+    
632
+    
633
+	protected function _add_screen_options()
634
+	{
635
+		//todo
636
+	}
637
+    
638
+    
639
+	protected function _add_screen_options_global_mtps()
640
+	{
641
+		/**
642
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
644
+		 */
645
+		$page_title              = $this->_admin_page_title;
646
+		$this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
+		$this->_per_page_screen_option();
648
+		$this->_admin_page_title = $page_title;
649
+	}
650
+    
651
+    
652
+	protected function _add_screen_options_default()
653
+	{
654
+		$this->_admin_page_title = __('Message Activity', 'event_espresso');
655
+		$this->_per_page_screen_option();
656
+	}
657
+    
658
+    
659
+	//none of the below group are currently used for Messages
660
+	protected function _add_feature_pointers()
661
+	{
662
+	}
663
+    
664
+	public function admin_init()
665
+	{
666
+	}
667
+    
668
+	public function admin_notices()
669
+	{
670
+	}
671
+    
672
+	public function admin_footer_scripts()
673
+	{
674
+	}
675
+    
676
+    
677
+	public function messages_help_tab()
678
+	{
679
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
+	}
681
+    
682
+    
683
+	public function messengers_help_tab()
684
+	{
685
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
+	}
687
+    
688
+    
689
+	public function message_types_help_tab()
690
+	{
691
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
+	}
693
+    
694
+    
695
+	public function messages_overview_help_tab()
696
+	{
697
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
+	}
699
+    
700
+    
701
+	public function message_templates_help_tab()
702
+	{
703
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
+	}
705
+    
706
+    
707
+	public function edit_message_template_help_tab()
708
+	{
709
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
+				'event_espresso') . '" />';
711
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
+				'event_espresso') . '" />';
713
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
+				'event_espresso') . '" />';
715
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
+				'event_espresso') . '" />';
717
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
+				'event_espresso') . '" />';
719
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
+			$args);
721
+	}
722
+    
723
+    
724
+	public function message_template_shortcodes_help_tab()
725
+	{
726
+		$this->_set_shortcodes();
727
+		$args['shortcodes'] = $this->_shortcodes;
728
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
+			$args);
730
+	}
731 731
     
732 732
     
733
-    public function preview_message_help_tab()
734
-    {
735
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
-    }
733
+	public function preview_message_help_tab()
734
+	{
735
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
+	}
737 737
     
738
-    
739
-    public function settings_help_tab()
740
-    {
741
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
-                'event_espresso') . '" />';
743
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
-                'event_espresso') . '" />';
745
-        $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
-        $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
-    }
738
+    
739
+	public function settings_help_tab()
740
+	{
741
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
+				'event_espresso') . '" />';
743
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
+				'event_espresso') . '" />';
745
+		$args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
+		$args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
+	}
749 749
     
750 750
     
751
-    public function load_scripts_styles()
752
-    {
753
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
-        wp_enqueue_style('espresso_ee_msg');
751
+	public function load_scripts_styles()
752
+	{
753
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
+		wp_enqueue_style('espresso_ee_msg');
755 755
         
756
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
-    }
756
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
+	}
761 761
     
762 762
     
763
-    public function load_scripts_styles_default()
764
-    {
765
-        wp_enqueue_script('ee-msg-list-table-js');
766
-    }
763
+	public function load_scripts_styles_default()
764
+	{
765
+		wp_enqueue_script('ee-msg-list-table-js');
766
+	}
767 767
     
768 768
     
769
-    public function wp_editor_css($mce_css)
770
-    {
771
-        //if we're on the edit_message_template route
772
-        if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
-            $message_type_name = $this->_active_message_type_name;
769
+	public function wp_editor_css($mce_css)
770
+	{
771
+		//if we're on the edit_message_template route
772
+		if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
+			$message_type_name = $this->_active_message_type_name;
774 774
             
775
-            //we're going to REPLACE the existing mce css
776
-            //we need to get the css file location from the active messenger
777
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
-                'wpeditor', $this->_variation);
779
-        }
775
+			//we're going to REPLACE the existing mce css
776
+			//we need to get the css file location from the active messenger
777
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
+				'wpeditor', $this->_variation);
779
+		}
780 780
         
781
-        return $mce_css;
782
-    }
781
+		return $mce_css;
782
+	}
783 783
     
784 784
     
785
-    public function load_scripts_styles_edit_message_template()
786
-    {
785
+	public function load_scripts_styles_edit_message_template()
786
+	{
787 787
         
788
-        $this->_set_shortcodes();
788
+		$this->_set_shortcodes();
789 789
         
790
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
-            __('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.',
792
-                'event_espresso'),
793
-            $this->_message_template_group->messenger_obj()->label['singular'],
794
-            $this->_message_template_group->message_type_obj()->label['singular']
795
-        );
796
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797
-            'event_espresso');
790
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
+			__('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.',
792
+				'event_espresso'),
793
+			$this->_message_template_group->messenger_obj()->label['singular'],
794
+			$this->_message_template_group->message_type_obj()->label['singular']
795
+		);
796
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797
+			'event_espresso');
798 798
         
799
-        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
-            EVENT_ESPRESSO_VERSION);
799
+		wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
+			EVENT_ESPRESSO_VERSION);
801 801
         
802
-        wp_enqueue_script('ee_admin_js');
803
-        wp_enqueue_script('ee_msgs_edit_js');
802
+		wp_enqueue_script('ee_admin_js');
803
+		wp_enqueue_script('ee_msgs_edit_js');
804 804
         
805
-        //add in special css for tiny_mce
806
-        add_filter('mce_css', array($this, 'wp_editor_css'));
807
-    }
805
+		//add in special css for tiny_mce
806
+		add_filter('mce_css', array($this, 'wp_editor_css'));
807
+	}
808 808
     
809 809
     
810
-    public function load_scripts_styles_display_preview_message()
811
-    {
810
+	public function load_scripts_styles_display_preview_message()
811
+	{
812 812
         
813
-        $this->_set_message_template_group();
813
+		$this->_set_message_template_group();
814 814
         
815
-        if (isset($this->_req_data['messenger'])) {
816
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
-        }
815
+		if (isset($this->_req_data['messenger'])) {
816
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
+		}
818 818
         
819
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
819
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
820 820
         
821 821
         
822
-        wp_enqueue_style('espresso_preview_css',
823
-            $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
-                $this->_variation));
825
-    }
822
+		wp_enqueue_style('espresso_preview_css',
823
+			$this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
+				$this->_variation));
825
+	}
826 826
     
827 827
     
828
-    public function load_scripts_styles_settings()
829
-    {
830
-        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
-            EVENT_ESPRESSO_VERSION);
832
-        wp_enqueue_style('ee-text-links');
833
-        wp_enqueue_style('ee-message-settings');
828
+	public function load_scripts_styles_settings()
829
+	{
830
+		wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
+			EVENT_ESPRESSO_VERSION);
832
+		wp_enqueue_style('ee-text-links');
833
+		wp_enqueue_style('ee-message-settings');
834 834
         
835
-        wp_enqueue_script('ee-messages-settings');
836
-    }
835
+		wp_enqueue_script('ee-messages-settings');
836
+	}
837 837
     
838 838
     
839
-    /**
840
-     * set views array for List Table
841
-     */
842
-    public function _set_list_table_views_global_mtps()
843
-    {
844
-        $this->_views = array(
845
-            'in_use' => array(
846
-                'slug'        => 'in_use',
847
-                'label'       => __('In Use', 'event_espresso'),
848
-                'count'       => 0,
849
-            )
850
-        );
851
-    }
839
+	/**
840
+	 * set views array for List Table
841
+	 */
842
+	public function _set_list_table_views_global_mtps()
843
+	{
844
+		$this->_views = array(
845
+			'in_use' => array(
846
+				'slug'        => 'in_use',
847
+				'label'       => __('In Use', 'event_espresso'),
848
+				'count'       => 0,
849
+			)
850
+		);
851
+	}
852 852
 
853 853
 
854
-    /**
855
-     * Set views array for the Custom Template List Table
856
-     */
857
-    public function _set_list_table_views_custom_mtps()
858
-    {
859
-        $this->_set_list_table_views_global_mtps();
860
-        $this->_views['in_use']['bulk_action'] = array(
861
-                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
862
-        );
863
-    }
864
-    
865
-    
866
-    /**
867
-     * set views array for message queue list table
868
-     */
869
-    public function _set_list_table_views_default()
870
-    {
871
-        EE_Registry::instance()->load_helper('Template');
872
-        
873
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
874
-            'message_list_table_bulk_actions')
875
-            ? array(
876
-                'generate_now'          => __('Generate Now', 'event_espresso'),
877
-                'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
878
-                'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
879
-                'send_now'              => __('Send Now', 'event_espresso')
880
-            )
881
-            : array();
882
-        
883
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
884
-            'message_list_table_bulk_actions')
885
-            ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
886
-            : array();
887
-        
888
-        
889
-        $this->_views = array(
890
-            'all' => array(
891
-                'slug'        => 'all',
892
-                'label'       => __('All', 'event_espresso'),
893
-                'count'       => 0,
894
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
895
-            )
896
-        );
897
-        
898
-        
899
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
900
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
901
-                continue;
902
-            }
903
-            $status_bulk_actions = $common_bulk_actions;
904
-            //unset bulk actions not applying to status
905
-            if (! empty($status_bulk_actions)) {
906
-                switch ($status) {
907
-                    case EEM_Message::status_idle:
908
-                    case EEM_Message::status_resend:
909
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
910
-                        break;
854
+	/**
855
+	 * Set views array for the Custom Template List Table
856
+	 */
857
+	public function _set_list_table_views_custom_mtps()
858
+	{
859
+		$this->_set_list_table_views_global_mtps();
860
+		$this->_views['in_use']['bulk_action'] = array(
861
+				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
862
+		);
863
+	}
864
+    
865
+    
866
+	/**
867
+	 * set views array for message queue list table
868
+	 */
869
+	public function _set_list_table_views_default()
870
+	{
871
+		EE_Registry::instance()->load_helper('Template');
872
+        
873
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
874
+			'message_list_table_bulk_actions')
875
+			? array(
876
+				'generate_now'          => __('Generate Now', 'event_espresso'),
877
+				'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
878
+				'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
879
+				'send_now'              => __('Send Now', 'event_espresso')
880
+			)
881
+			: array();
882
+        
883
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
884
+			'message_list_table_bulk_actions')
885
+			? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
886
+			: array();
887
+        
888
+        
889
+		$this->_views = array(
890
+			'all' => array(
891
+				'slug'        => 'all',
892
+				'label'       => __('All', 'event_espresso'),
893
+				'count'       => 0,
894
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
895
+			)
896
+		);
897
+        
898
+        
899
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
900
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
901
+				continue;
902
+			}
903
+			$status_bulk_actions = $common_bulk_actions;
904
+			//unset bulk actions not applying to status
905
+			if (! empty($status_bulk_actions)) {
906
+				switch ($status) {
907
+					case EEM_Message::status_idle:
908
+					case EEM_Message::status_resend:
909
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
910
+						break;
911 911
                     
912
-                    case EEM_Message::status_failed:
913
-                    case EEM_Message::status_debug_only:
914
-                    case EEM_Message::status_messenger_executing:
915
-                        $status_bulk_actions = array();
916
-                        break;
912
+					case EEM_Message::status_failed:
913
+					case EEM_Message::status_debug_only:
914
+					case EEM_Message::status_messenger_executing:
915
+						$status_bulk_actions = array();
916
+						break;
917 917
                     
918
-                    case EEM_Message::status_incomplete:
919
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
920
-                        break;
918
+					case EEM_Message::status_incomplete:
919
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
920
+						break;
921 921
                     
922
-                    case EEM_Message::status_retry:
923
-                    case EEM_Message::status_sent:
924
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
925
-                        break;
926
-                }
927
-            }
922
+					case EEM_Message::status_retry:
923
+					case EEM_Message::status_sent:
924
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
925
+						break;
926
+				}
927
+			}
928 928
 
929
-            //skip adding messenger executing status to views because it will be included with the Failed view.
930
-            if ( $status === EEM_Message::status_messenger_executing ) {
931
-                continue;
932
-            }
929
+			//skip adding messenger executing status to views because it will be included with the Failed view.
930
+			if ( $status === EEM_Message::status_messenger_executing ) {
931
+				continue;
932
+			}
933 933
             
934
-            $this->_views[strtolower($status)] = array(
935
-                'slug'        => strtolower($status),
936
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
937
-                'count'       => 0,
938
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
939
-            );
940
-        }
941
-    }
942
-    
943
-    
944
-    protected function _ee_default_messages_overview_list_table()
945
-    {
946
-        $this->_admin_page_title = __('Default Message Templates', 'event_espresso');
947
-        $this->display_admin_list_table_page_with_no_sidebar();
948
-    }
949
-    
950
-    
951
-    protected function _message_queue_list_table()
952
-    {
953
-        $this->_search_btn_label                   = __('Message Activity', 'event_espresso');
954
-        $this->_template_args['per_column']        = 6;
955
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
956
-        $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
957
-        $this->display_admin_list_table_page_with_no_sidebar();
958
-    }
959
-    
960
-    
961
-    protected function _message_legend_items()
962
-    {
963
-        
964
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
965
-        $action_items       = array();
966
-        
967
-        foreach ($action_css_classes as $action_item => $action_details) {
968
-            if ($action_item === 'see_notifications_for') {
969
-                continue;
970
-            }
971
-            $action_items[$action_item] = array(
972
-                'class' => $action_details['css_class'],
973
-                'desc'  => $action_details['label']
974
-            );
975
-        }
976
-        
977
-        /** @type array $status_items status legend setup */
978
-        $status_items = array(
979
-            'sent_status'       => array(
980
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
981
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
982
-            ),
983
-            'idle_status'       => array(
984
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
985
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
986
-            ),
987
-            'failed_status'     => array(
988
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
989
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
990
-            ),
991
-            'messenger_executing_status' => array(
992
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
993
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
994
-            ),
995
-            'resend_status'     => array(
996
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
997
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
998
-            ),
999
-            'incomplete_status' => array(
1000
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1001
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1002
-            ),
1003
-            'retry_status'      => array(
1004
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1005
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1006
-            )
1007
-        );
1008
-        if (EEM_Message::debug()) {
1009
-            $status_items['debug_only_status'] = array(
1010
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1011
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1012
-            );
1013
-        }
1014
-        
1015
-        return array_merge($action_items, $status_items);
1016
-    }
1017
-    
1018
-    
1019
-    protected function _custom_mtps_preview()
1020
-    {
1021
-        $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1022
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1023
-                'event_espresso') . '" />';
1024
-        $this->_template_args['preview_text'] = '<strong>' . __('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.',
1025
-                'event_espresso') . '</strong>';
1026
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1027
-    }
1028
-    
1029
-    
1030
-    /**
1031
-     * get_message_templates
1032
-     * This gets all the message templates for listing on the overview list.
1033
-     *
1034
-     * @access public
1035
-     *
1036
-     * @param int    $perpage the amount of templates groups to show per page
1037
-     * @param string $type    the current _view we're getting templates for
1038
-     * @param bool   $count   return count?
1039
-     * @param bool   $all     disregard any paging info (get all data);
1040
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1041
-     *
1042
-     * @return array
1043
-     */
1044
-    public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1045
-    {
1046
-        
1047
-        $MTP = EEM_Message_Template_Group::instance();
1048
-        
1049
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1050
-        $orderby                    = $this->_req_data['orderby'];
1051
-        
1052
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1053
-        
1054
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1055
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1056
-        
1057
-        $offset = ($current_page - 1) * $per_page;
1058
-        $limit  = $all ? null : array($offset, $per_page);
1059
-        
1060
-        
1061
-        //options will match what is in the _views array property
1062
-        switch ($type) {
934
+			$this->_views[strtolower($status)] = array(
935
+				'slug'        => strtolower($status),
936
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
937
+				'count'       => 0,
938
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
939
+			);
940
+		}
941
+	}
942
+    
943
+    
944
+	protected function _ee_default_messages_overview_list_table()
945
+	{
946
+		$this->_admin_page_title = __('Default Message Templates', 'event_espresso');
947
+		$this->display_admin_list_table_page_with_no_sidebar();
948
+	}
949
+    
950
+    
951
+	protected function _message_queue_list_table()
952
+	{
953
+		$this->_search_btn_label                   = __('Message Activity', 'event_espresso');
954
+		$this->_template_args['per_column']        = 6;
955
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
956
+		$this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
957
+		$this->display_admin_list_table_page_with_no_sidebar();
958
+	}
959
+    
960
+    
961
+	protected function _message_legend_items()
962
+	{
963
+        
964
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
965
+		$action_items       = array();
966
+        
967
+		foreach ($action_css_classes as $action_item => $action_details) {
968
+			if ($action_item === 'see_notifications_for') {
969
+				continue;
970
+			}
971
+			$action_items[$action_item] = array(
972
+				'class' => $action_details['css_class'],
973
+				'desc'  => $action_details['label']
974
+			);
975
+		}
976
+        
977
+		/** @type array $status_items status legend setup */
978
+		$status_items = array(
979
+			'sent_status'       => array(
980
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
981
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
982
+			),
983
+			'idle_status'       => array(
984
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
985
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
986
+			),
987
+			'failed_status'     => array(
988
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
989
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
990
+			),
991
+			'messenger_executing_status' => array(
992
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
993
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
994
+			),
995
+			'resend_status'     => array(
996
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
997
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
998
+			),
999
+			'incomplete_status' => array(
1000
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1001
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1002
+			),
1003
+			'retry_status'      => array(
1004
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1005
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1006
+			)
1007
+		);
1008
+		if (EEM_Message::debug()) {
1009
+			$status_items['debug_only_status'] = array(
1010
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1011
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1012
+			);
1013
+		}
1014
+        
1015
+		return array_merge($action_items, $status_items);
1016
+	}
1017
+    
1018
+    
1019
+	protected function _custom_mtps_preview()
1020
+	{
1021
+		$this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1022
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1023
+				'event_espresso') . '" />';
1024
+		$this->_template_args['preview_text'] = '<strong>' . __('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.',
1025
+				'event_espresso') . '</strong>';
1026
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1027
+	}
1028
+    
1029
+    
1030
+	/**
1031
+	 * get_message_templates
1032
+	 * This gets all the message templates for listing on the overview list.
1033
+	 *
1034
+	 * @access public
1035
+	 *
1036
+	 * @param int    $perpage the amount of templates groups to show per page
1037
+	 * @param string $type    the current _view we're getting templates for
1038
+	 * @param bool   $count   return count?
1039
+	 * @param bool   $all     disregard any paging info (get all data);
1040
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1041
+	 *
1042
+	 * @return array
1043
+	 */
1044
+	public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1045
+	{
1046
+        
1047
+		$MTP = EEM_Message_Template_Group::instance();
1048
+        
1049
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1050
+		$orderby                    = $this->_req_data['orderby'];
1051
+        
1052
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1053
+        
1054
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1055
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1056
+        
1057
+		$offset = ($current_page - 1) * $per_page;
1058
+		$limit  = $all ? null : array($offset, $per_page);
1059
+        
1060
+        
1061
+		//options will match what is in the _views array property
1062
+		switch ($type) {
1063 1063
             
1064
-            case 'in_use':
1065
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1066
-                break;
1064
+			case 'in_use':
1065
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1066
+				break;
1067 1067
             
1068
-            default:
1069
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1068
+			default:
1069
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1070 1070
             
1071
-        }
1072
-        
1073
-        return $templates;
1074
-    }
1075
-    
1076
-    
1077
-    /**
1078
-     * filters etc might need a list of installed message_types
1079
-     * @return array an array of message type objects
1080
-     */
1081
-    public function get_installed_message_types()
1082
-    {
1083
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1084
-        $installed               = array();
1085
-        
1086
-        foreach ($installed_message_types as $message_type) {
1087
-            $installed[$message_type->name] = $message_type;
1088
-        }
1089
-        
1090
-        return $installed;
1091
-    }
1092
-    
1093
-    
1094
-    /**
1095
-     * _add_message_template
1096
-     *
1097
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1098
-     *
1099
-     * @param string $message_type
1100
-     * @param string $messenger
1101
-     * @param string $GRP_ID
1102
-     *
1103
-     * @throws EE_error
1104
-     */
1105
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1106
-    {
1107
-        //set values override any request data
1108
-        $message_type = ! empty($message_type) ? $message_type : '';
1109
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1110
-        
1111
-        $messenger = ! empty($messenger) ? $messenger : '';
1112
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1113
-        
1114
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1115
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1116
-        
1117
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1118
-        if (empty($message_type) || empty($messenger)) {
1119
-            throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1120
-                'event_espresso'));
1121
-        }
1122
-        
1123
-        //we need the GRP_ID for the template being used as the base for the new template
1124
-        if (empty($GRP_ID)) {
1125
-            throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1126
-                'event_espresso'));
1127
-        }
1128
-        
1129
-        //let's just make sure the template gets generated!
1130
-        
1131
-        //we need to reassign some variables for what the insert is expecting
1132
-        $this->_req_data['MTP_messenger']    = $messenger;
1133
-        $this->_req_data['MTP_message_type'] = $message_type;
1134
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1135
-        $this->_insert_or_update_message_template(true);
1136
-    }
1137
-    
1138
-    
1139
-    /**
1140
-     * public wrapper for the _add_message_template method
1141
-     *
1142
-     * @param string $message_type     message type slug
1143
-     * @param string $messenger        messenger slug
1144
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1145
-     *                                 off of.
1146
-     */
1147
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1148
-    {
1149
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1150
-    }
1151
-    
1152
-    
1153
-    /**
1154
-     * _edit_message_template
1155
-     *
1156
-     * @access protected
1157
-     * @return void
1158
-     */
1159
-    protected function _edit_message_template()
1160
-    {
1161
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1162
-        $template_fields = '';
1163
-        $sidebar_fields  = '';
1164
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1165
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1166
-        
1167
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1168
-            ? absint($this->_req_data['id'])
1169
-            : false;
1170
-        
1171
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1172
-        $message_template_group = $this->_message_template_group;
1173
-        $c_label                = $message_template_group->context_label();
1174
-        $c_config               = $message_template_group->contexts_config();
1175
-        
1176
-        reset($c_config);
1177
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1178
-            ? strtolower($this->_req_data['context'])
1179
-            : key($c_config);
1180
-        
1181
-        
1182
-        if (empty($GRP_ID)) {
1183
-            $action = 'insert_message_template';
1184
-            //$button_both = false;
1185
-            //$button_text = array( __( 'Save','event_espresso') );
1186
-            //$button_actions = array('something_different');
1187
-            //$referrer = false;
1188
-            $edit_message_template_form_url = add_query_arg(
1189
-                array('action' => $action, 'noheader' => true),
1190
-                EE_MSG_ADMIN_URL
1191
-            );
1192
-        } else {
1193
-            $action = 'update_message_template';
1194
-            //$button_both = true;
1195
-            //$button_text = array();
1196
-            //$button_actions = array();
1197
-            //$referrer = $this->_admin_base_url;
1198
-            $edit_message_template_form_url = add_query_arg(
1199
-                array('action' => $action, 'noheader' => true),
1200
-                EE_MSG_ADMIN_URL
1201
-            );
1202
-        }
1203
-        
1204
-        //set active messenger for this view
1205
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1206
-            $message_template_group->messenger()
1207
-        );
1208
-        $this->_active_message_type_name = $message_template_group->message_type();
1209
-        
1210
-        
1211
-        //Do we have any validation errors?
1212
-        $validators = $this->_get_transient();
1213
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1214
-        
1215
-        
1216
-        //we need to assemble the title from Various details
1217
-        $context_label = sprintf(
1218
-            __('(%s %s)', 'event_espresso'),
1219
-            $c_config[$context]['label'],
1220
-            ucwords($c_label['label'])
1221
-        );
1222
-        
1223
-        $title = sprintf(
1224
-            __(' %s %s Template %s', 'event_espresso'),
1225
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1226
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1227
-            $context_label
1228
-        );
1229
-        
1230
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1231
-        $this->_template_args['message_template'] = $message_template_group;
1232
-        $this->_template_args['is_extra_fields']  = false;
1233
-        
1234
-        
1235
-        //let's get EEH_MSG_Template so we can get template form fields
1236
-        $template_field_structure = EEH_MSG_Template::get_fields(
1237
-            $message_template_group->messenger(),
1238
-            $message_template_group->message_type()
1239
-        );
1240
-        
1241
-        if ( ! $template_field_structure) {
1242
-            $template_field_structure = false;
1243
-            $template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1244
-                'event_espresso');
1245
-        }
1246
-        
1247
-        
1248
-        $message_templates = $message_template_group->context_templates();
1249
-        
1250
-        
1251
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1252
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1253
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1254
-                unset($template_field_structure[$context][$reference_field]);
1255
-            }
1256
-        }
1257
-        
1258
-        //let's loop through the template_field_structure and actually assemble the input fields!
1259
-        if ( ! empty($template_field_structure)) {
1260
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1261
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1262
-                if ($template_field == 'extra') {
1263
-                    $this->_template_args['is_extra_fields'] = true;
1264
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1265
-                        $message_template = $message_templates[$context][$reference_field];
1266
-                        $content          = $message_template instanceof EE_Message_Template
1267
-                            ? $message_template->get('MTP_content')
1268
-                            : '';
1269
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1270
-                            //let's verify if we need this extra field via the shortcodes parameter.
1271
-                            $continue = false;
1272
-                            if (isset($extra_array['shortcodes_required'])) {
1273
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1274
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1275
-                                        $continue = true;
1276
-                                    }
1277
-                                }
1278
-                                if ($continue) {
1279
-                                    continue;
1280
-                                }
1281
-                            }
1071
+		}
1072
+        
1073
+		return $templates;
1074
+	}
1075
+    
1076
+    
1077
+	/**
1078
+	 * filters etc might need a list of installed message_types
1079
+	 * @return array an array of message type objects
1080
+	 */
1081
+	public function get_installed_message_types()
1082
+	{
1083
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1084
+		$installed               = array();
1085
+        
1086
+		foreach ($installed_message_types as $message_type) {
1087
+			$installed[$message_type->name] = $message_type;
1088
+		}
1089
+        
1090
+		return $installed;
1091
+	}
1092
+    
1093
+    
1094
+	/**
1095
+	 * _add_message_template
1096
+	 *
1097
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1098
+	 *
1099
+	 * @param string $message_type
1100
+	 * @param string $messenger
1101
+	 * @param string $GRP_ID
1102
+	 *
1103
+	 * @throws EE_error
1104
+	 */
1105
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1106
+	{
1107
+		//set values override any request data
1108
+		$message_type = ! empty($message_type) ? $message_type : '';
1109
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1110
+        
1111
+		$messenger = ! empty($messenger) ? $messenger : '';
1112
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1113
+        
1114
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1115
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1116
+        
1117
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1118
+		if (empty($message_type) || empty($messenger)) {
1119
+			throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1120
+				'event_espresso'));
1121
+		}
1122
+        
1123
+		//we need the GRP_ID for the template being used as the base for the new template
1124
+		if (empty($GRP_ID)) {
1125
+			throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1126
+				'event_espresso'));
1127
+		}
1128
+        
1129
+		//let's just make sure the template gets generated!
1130
+        
1131
+		//we need to reassign some variables for what the insert is expecting
1132
+		$this->_req_data['MTP_messenger']    = $messenger;
1133
+		$this->_req_data['MTP_message_type'] = $message_type;
1134
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1135
+		$this->_insert_or_update_message_template(true);
1136
+	}
1137
+    
1138
+    
1139
+	/**
1140
+	 * public wrapper for the _add_message_template method
1141
+	 *
1142
+	 * @param string $message_type     message type slug
1143
+	 * @param string $messenger        messenger slug
1144
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1145
+	 *                                 off of.
1146
+	 */
1147
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1148
+	{
1149
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1150
+	}
1151
+    
1152
+    
1153
+	/**
1154
+	 * _edit_message_template
1155
+	 *
1156
+	 * @access protected
1157
+	 * @return void
1158
+	 */
1159
+	protected function _edit_message_template()
1160
+	{
1161
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1162
+		$template_fields = '';
1163
+		$sidebar_fields  = '';
1164
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1165
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1166
+        
1167
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1168
+			? absint($this->_req_data['id'])
1169
+			: false;
1170
+        
1171
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1172
+		$message_template_group = $this->_message_template_group;
1173
+		$c_label                = $message_template_group->context_label();
1174
+		$c_config               = $message_template_group->contexts_config();
1175
+        
1176
+		reset($c_config);
1177
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1178
+			? strtolower($this->_req_data['context'])
1179
+			: key($c_config);
1180
+        
1181
+        
1182
+		if (empty($GRP_ID)) {
1183
+			$action = 'insert_message_template';
1184
+			//$button_both = false;
1185
+			//$button_text = array( __( 'Save','event_espresso') );
1186
+			//$button_actions = array('something_different');
1187
+			//$referrer = false;
1188
+			$edit_message_template_form_url = add_query_arg(
1189
+				array('action' => $action, 'noheader' => true),
1190
+				EE_MSG_ADMIN_URL
1191
+			);
1192
+		} else {
1193
+			$action = 'update_message_template';
1194
+			//$button_both = true;
1195
+			//$button_text = array();
1196
+			//$button_actions = array();
1197
+			//$referrer = $this->_admin_base_url;
1198
+			$edit_message_template_form_url = add_query_arg(
1199
+				array('action' => $action, 'noheader' => true),
1200
+				EE_MSG_ADMIN_URL
1201
+			);
1202
+		}
1203
+        
1204
+		//set active messenger for this view
1205
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1206
+			$message_template_group->messenger()
1207
+		);
1208
+		$this->_active_message_type_name = $message_template_group->message_type();
1209
+        
1210
+        
1211
+		//Do we have any validation errors?
1212
+		$validators = $this->_get_transient();
1213
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1214
+        
1215
+        
1216
+		//we need to assemble the title from Various details
1217
+		$context_label = sprintf(
1218
+			__('(%s %s)', 'event_espresso'),
1219
+			$c_config[$context]['label'],
1220
+			ucwords($c_label['label'])
1221
+		);
1222
+        
1223
+		$title = sprintf(
1224
+			__(' %s %s Template %s', 'event_espresso'),
1225
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1226
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1227
+			$context_label
1228
+		);
1229
+        
1230
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1231
+		$this->_template_args['message_template'] = $message_template_group;
1232
+		$this->_template_args['is_extra_fields']  = false;
1233
+        
1234
+        
1235
+		//let's get EEH_MSG_Template so we can get template form fields
1236
+		$template_field_structure = EEH_MSG_Template::get_fields(
1237
+			$message_template_group->messenger(),
1238
+			$message_template_group->message_type()
1239
+		);
1240
+        
1241
+		if ( ! $template_field_structure) {
1242
+			$template_field_structure = false;
1243
+			$template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1244
+				'event_espresso');
1245
+		}
1246
+        
1247
+        
1248
+		$message_templates = $message_template_group->context_templates();
1249
+        
1250
+        
1251
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1252
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1253
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1254
+				unset($template_field_structure[$context][$reference_field]);
1255
+			}
1256
+		}
1257
+        
1258
+		//let's loop through the template_field_structure and actually assemble the input fields!
1259
+		if ( ! empty($template_field_structure)) {
1260
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1261
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1262
+				if ($template_field == 'extra') {
1263
+					$this->_template_args['is_extra_fields'] = true;
1264
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1265
+						$message_template = $message_templates[$context][$reference_field];
1266
+						$content          = $message_template instanceof EE_Message_Template
1267
+							? $message_template->get('MTP_content')
1268
+							: '';
1269
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1270
+							//let's verify if we need this extra field via the shortcodes parameter.
1271
+							$continue = false;
1272
+							if (isset($extra_array['shortcodes_required'])) {
1273
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1274
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1275
+										$continue = true;
1276
+									}
1277
+								}
1278
+								if ($continue) {
1279
+									continue;
1280
+								}
1281
+							}
1282 1282
                             
1283
-                            $field_id                                = $reference_field . '-' . $extra_field . '-content';
1284
-                            $template_form_fields[$field_id]         = $extra_array;
1285
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1286
-                            $css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1283
+							$field_id                                = $reference_field . '-' . $extra_field . '-content';
1284
+							$template_form_fields[$field_id]         = $extra_array;
1285
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1286
+							$css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1287 1287
                             
1288
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1289
-                                                                            && in_array($extra_field, $v_fields)
1290
-                                                                            &&
1291
-                                                                            (
1292
-                                                                                is_array($validators[$extra_field])
1293
-                                                                                && isset($validators[$extra_field]['msg'])
1294
-                                                                            )
1295
-                                ? 'validate-error ' . $css_class
1296
-                                : $css_class;
1288
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1289
+																			&& in_array($extra_field, $v_fields)
1290
+																			&&
1291
+																			(
1292
+																				is_array($validators[$extra_field])
1293
+																				&& isset($validators[$extra_field]['msg'])
1294
+																			)
1295
+								? 'validate-error ' . $css_class
1296
+								: $css_class;
1297 1297
                             
1298
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1299
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1300
-                                : '';
1298
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1299
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1300
+								: '';
1301 1301
                             
1302
-                            //do we have a validation error?  if we do then let's use that value instead
1303
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1302
+							//do we have a validation error?  if we do then let's use that value instead
1303
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1304 1304
                             
1305 1305
                             
1306
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1306
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1307 1307
                             
1308
-                            //shortcode selector
1309
-                            $field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1310
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1311
-                                $field_name_to_use,
1312
-                                $field_id
1313
-                            );
1308
+							//shortcode selector
1309
+							$field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1310
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1311
+								$field_name_to_use,
1312
+								$field_id
1313
+							);
1314 1314
                             
1315
-                            if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1316
-                                //we want to decode the entities
1317
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1318
-                                    html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1319
-                                );
1315
+							if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1316
+								//we want to decode the entities
1317
+								$template_form_fields[$field_id]['value'] = stripslashes(
1318
+									html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1319
+								);
1320 1320
                                 
1321
-                            }/**/
1322
-                        }
1323
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1324
-                        $templatefield_templatename_id = $reference_field . '-name';
1321
+							}/**/
1322
+						}
1323
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1324
+						$templatefield_templatename_id = $reference_field . '-name';
1325 1325
                         
1326
-                        $template_form_fields[$templatefield_MTP_id] = array(
1327
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1328
-                            'label'      => null,
1329
-                            'input'      => 'hidden',
1330
-                            'type'       => 'int',
1331
-                            'required'   => false,
1332
-                            'validation' => false,
1333
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1334
-                            'css_class'  => '',
1335
-                            'format'     => '%d',
1336
-                            'db-col'     => 'MTP_ID'
1337
-                        );
1326
+						$template_form_fields[$templatefield_MTP_id] = array(
1327
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1328
+							'label'      => null,
1329
+							'input'      => 'hidden',
1330
+							'type'       => 'int',
1331
+							'required'   => false,
1332
+							'validation' => false,
1333
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1334
+							'css_class'  => '',
1335
+							'format'     => '%d',
1336
+							'db-col'     => 'MTP_ID'
1337
+						);
1338 1338
                         
1339
-                        $template_form_fields[$templatefield_templatename_id] = array(
1340
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1341
-                            'label'      => null,
1342
-                            'input'      => 'hidden',
1343
-                            'type'       => 'string',
1344
-                            'required'   => false,
1345
-                            'validation' => true,
1346
-                            'value'      => $reference_field,
1347
-                            'css_class'  => '',
1348
-                            'format'     => '%s',
1349
-                            'db-col'     => 'MTP_template_field'
1350
-                        );
1351
-                    }
1352
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1353
-                } else {
1354
-                    $field_id                                 = $template_field . '-content';
1355
-                    $template_form_fields[$field_id]          = $field_setup_array;
1356
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1357
-                    $message_template                         = isset($message_templates[$context][$template_field])
1358
-                        ? $message_templates[$context][$template_field]
1359
-                        : null;
1360
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1361
-                                                                && is_array($message_templates[$context])
1362
-                                                                && $message_template instanceof EE_Message_Template
1363
-                        ? $message_template->get('MTP_content')
1364
-                        : '';
1339
+						$template_form_fields[$templatefield_templatename_id] = array(
1340
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1341
+							'label'      => null,
1342
+							'input'      => 'hidden',
1343
+							'type'       => 'string',
1344
+							'required'   => false,
1345
+							'validation' => true,
1346
+							'value'      => $reference_field,
1347
+							'css_class'  => '',
1348
+							'format'     => '%s',
1349
+							'db-col'     => 'MTP_template_field'
1350
+						);
1351
+					}
1352
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1353
+				} else {
1354
+					$field_id                                 = $template_field . '-content';
1355
+					$template_form_fields[$field_id]          = $field_setup_array;
1356
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1357
+					$message_template                         = isset($message_templates[$context][$template_field])
1358
+						? $message_templates[$context][$template_field]
1359
+						: null;
1360
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1361
+																&& is_array($message_templates[$context])
1362
+																&& $message_template instanceof EE_Message_Template
1363
+						? $message_template->get('MTP_content')
1364
+						: '';
1365 1365
                     
1366
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1367
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1368
-                        ? $validators[$template_field]['value']
1369
-                        : $template_form_fields[$field_id]['value'];
1366
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1367
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1368
+						? $validators[$template_field]['value']
1369
+						: $template_form_fields[$field_id]['value'];
1370 1370
                     
1371 1371
                     
1372
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1373
-                    $css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1374
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1375
-                                                                    && in_array($template_field, $v_fields)
1376
-                                                                    && isset($validators[$template_field]['msg'])
1377
-                        ? 'validate-error ' . $css_class
1378
-                        : $css_class;
1372
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1373
+					$css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1374
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1375
+																	&& in_array($template_field, $v_fields)
1376
+																	&& isset($validators[$template_field]['msg'])
1377
+						? 'validate-error ' . $css_class
1378
+						: $css_class;
1379 1379
                     
1380
-                    //shortcode selector
1381
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1382
-                        $template_field, $field_id
1383
-                    );
1384
-                }
1380
+					//shortcode selector
1381
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1382
+						$template_field, $field_id
1383
+					);
1384
+				}
1385 1385
                 
1386
-                //k took care of content field(s) now let's take care of others.
1386
+				//k took care of content field(s) now let's take care of others.
1387 1387
                 
1388
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1389
-                $templatefield_field_templatename_id = $template_field . '-name';
1388
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1389
+				$templatefield_field_templatename_id = $template_field . '-name';
1390 1390
                 
1391
-                //foreach template field there are actually two form fields created
1392
-                $template_form_fields[$templatefield_MTP_id] = array(
1393
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1394
-                    'label'      => null,
1395
-                    'input'      => 'hidden',
1396
-                    'type'       => 'int',
1397
-                    'required'   => false,
1398
-                    'validation' => true,
1399
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1400
-                    'css_class'  => '',
1401
-                    'format'     => '%d',
1402
-                    'db-col'     => 'MTP_ID'
1403
-                );
1391
+				//foreach template field there are actually two form fields created
1392
+				$template_form_fields[$templatefield_MTP_id] = array(
1393
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1394
+					'label'      => null,
1395
+					'input'      => 'hidden',
1396
+					'type'       => 'int',
1397
+					'required'   => false,
1398
+					'validation' => true,
1399
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1400
+					'css_class'  => '',
1401
+					'format'     => '%d',
1402
+					'db-col'     => 'MTP_ID'
1403
+				);
1404 1404
                 
1405
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1406
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1407
-                    'label'      => null,
1408
-                    'input'      => 'hidden',
1409
-                    'type'       => 'string',
1410
-                    'required'   => false,
1411
-                    'validation' => true,
1412
-                    'value'      => $template_field,
1413
-                    'css_class'  => '',
1414
-                    'format'     => '%s',
1415
-                    'db-col'     => 'MTP_template_field'
1416
-                );
1405
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1406
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1407
+					'label'      => null,
1408
+					'input'      => 'hidden',
1409
+					'type'       => 'string',
1410
+					'required'   => false,
1411
+					'validation' => true,
1412
+					'value'      => $template_field,
1413
+					'css_class'  => '',
1414
+					'format'     => '%s',
1415
+					'db-col'     => 'MTP_template_field'
1416
+				);
1417 1417
                 
1418
-            }
1418
+			}
1419 1419
             
1420
-            //add other fields
1421
-            $template_form_fields['ee-msg-current-context'] = array(
1422
-                'name'       => 'MTP_context',
1423
-                'label'      => null,
1424
-                'input'      => 'hidden',
1425
-                'type'       => 'string',
1426
-                'required'   => false,
1427
-                'validation' => true,
1428
-                'value'      => $context,
1429
-                'css_class'  => '',
1430
-                'format'     => '%s',
1431
-                'db-col'     => 'MTP_context'
1432
-            );
1420
+			//add other fields
1421
+			$template_form_fields['ee-msg-current-context'] = array(
1422
+				'name'       => 'MTP_context',
1423
+				'label'      => null,
1424
+				'input'      => 'hidden',
1425
+				'type'       => 'string',
1426
+				'required'   => false,
1427
+				'validation' => true,
1428
+				'value'      => $context,
1429
+				'css_class'  => '',
1430
+				'format'     => '%s',
1431
+				'db-col'     => 'MTP_context'
1432
+			);
1433 1433
             
1434
-            $template_form_fields['ee-msg-grp-id'] = array(
1435
-                'name'       => 'GRP_ID',
1436
-                'label'      => null,
1437
-                'input'      => 'hidden',
1438
-                'type'       => 'int',
1439
-                'required'   => false,
1440
-                'validation' => true,
1441
-                'value'      => $GRP_ID,
1442
-                'css_class'  => '',
1443
-                'format'     => '%d',
1444
-                'db-col'     => 'GRP_ID'
1445
-            );
1434
+			$template_form_fields['ee-msg-grp-id'] = array(
1435
+				'name'       => 'GRP_ID',
1436
+				'label'      => null,
1437
+				'input'      => 'hidden',
1438
+				'type'       => 'int',
1439
+				'required'   => false,
1440
+				'validation' => true,
1441
+				'value'      => $GRP_ID,
1442
+				'css_class'  => '',
1443
+				'format'     => '%d',
1444
+				'db-col'     => 'GRP_ID'
1445
+			);
1446 1446
             
1447
-            $template_form_fields['ee-msg-messenger'] = array(
1448
-                'name'       => 'MTP_messenger',
1449
-                'label'      => null,
1450
-                'input'      => 'hidden',
1451
-                'type'       => 'string',
1452
-                'required'   => false,
1453
-                'validation' => true,
1454
-                'value'      => $message_template_group->messenger(),
1455
-                'css_class'  => '',
1456
-                'format'     => '%s',
1457
-                'db-col'     => 'MTP_messenger'
1458
-            );
1447
+			$template_form_fields['ee-msg-messenger'] = array(
1448
+				'name'       => 'MTP_messenger',
1449
+				'label'      => null,
1450
+				'input'      => 'hidden',
1451
+				'type'       => 'string',
1452
+				'required'   => false,
1453
+				'validation' => true,
1454
+				'value'      => $message_template_group->messenger(),
1455
+				'css_class'  => '',
1456
+				'format'     => '%s',
1457
+				'db-col'     => 'MTP_messenger'
1458
+			);
1459 1459
             
1460
-            $template_form_fields['ee-msg-message-type'] = array(
1461
-                'name'       => 'MTP_message_type',
1462
-                'label'      => null,
1463
-                'input'      => 'hidden',
1464
-                'type'       => 'string',
1465
-                'required'   => false,
1466
-                'validation' => true,
1467
-                'value'      => $message_template_group->message_type(),
1468
-                'css_class'  => '',
1469
-                'format'     => '%s',
1470
-                'db-col'     => 'MTP_message_type'
1471
-            );
1460
+			$template_form_fields['ee-msg-message-type'] = array(
1461
+				'name'       => 'MTP_message_type',
1462
+				'label'      => null,
1463
+				'input'      => 'hidden',
1464
+				'type'       => 'string',
1465
+				'required'   => false,
1466
+				'validation' => true,
1467
+				'value'      => $message_template_group->message_type(),
1468
+				'css_class'  => '',
1469
+				'format'     => '%s',
1470
+				'db-col'     => 'MTP_message_type'
1471
+			);
1472 1472
             
1473
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1474
-                'name'       => 'MTP_is_global',
1475
-                'label'      => __('Global Template', 'event_espresso'),
1476
-                'input'      => 'hidden',
1477
-                'type'       => 'int',
1478
-                'required'   => false,
1479
-                'validation' => true,
1480
-                'value'      => $message_template_group->get('MTP_is_global'),
1481
-                'css_class'  => '',
1482
-                'format'     => '%d',
1483
-                'db-col'     => 'MTP_is_global'
1484
-            );
1473
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1474
+				'name'       => 'MTP_is_global',
1475
+				'label'      => __('Global Template', 'event_espresso'),
1476
+				'input'      => 'hidden',
1477
+				'type'       => 'int',
1478
+				'required'   => false,
1479
+				'validation' => true,
1480
+				'value'      => $message_template_group->get('MTP_is_global'),
1481
+				'css_class'  => '',
1482
+				'format'     => '%d',
1483
+				'db-col'     => 'MTP_is_global'
1484
+			);
1485 1485
             
1486
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1487
-                'name'       => 'MTP_is_override',
1488
-                'label'      => __('Override all custom', 'event_espresso'),
1489
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1490
-                'type'       => 'int',
1491
-                'required'   => false,
1492
-                'validation' => true,
1493
-                'value'      => $message_template_group->get('MTP_is_override'),
1494
-                'css_class'  => '',
1495
-                'format'     => '%d',
1496
-                'db-col'     => 'MTP_is_override'
1497
-            );
1486
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1487
+				'name'       => 'MTP_is_override',
1488
+				'label'      => __('Override all custom', 'event_espresso'),
1489
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1490
+				'type'       => 'int',
1491
+				'required'   => false,
1492
+				'validation' => true,
1493
+				'value'      => $message_template_group->get('MTP_is_override'),
1494
+				'css_class'  => '',
1495
+				'format'     => '%d',
1496
+				'db-col'     => 'MTP_is_override'
1497
+			);
1498 1498
             
1499
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1500
-                'name'       => 'MTP_is_active',
1501
-                'label'      => __('Active Template', 'event_espresso'),
1502
-                'input'      => 'hidden',
1503
-                'type'       => 'int',
1504
-                'required'   => false,
1505
-                'validation' => true,
1506
-                'value'      => $message_template_group->is_active(),
1507
-                'css_class'  => '',
1508
-                'format'     => '%d',
1509
-                'db-col'     => 'MTP_is_active'
1510
-            );
1499
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1500
+				'name'       => 'MTP_is_active',
1501
+				'label'      => __('Active Template', 'event_espresso'),
1502
+				'input'      => 'hidden',
1503
+				'type'       => 'int',
1504
+				'required'   => false,
1505
+				'validation' => true,
1506
+				'value'      => $message_template_group->is_active(),
1507
+				'css_class'  => '',
1508
+				'format'     => '%d',
1509
+				'db-col'     => 'MTP_is_active'
1510
+			);
1511 1511
             
1512
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1513
-                'name'       => 'MTP_deleted',
1514
-                'label'      => null,
1515
-                'input'      => 'hidden',
1516
-                'type'       => 'int',
1517
-                'required'   => false,
1518
-                'validation' => true,
1519
-                'value'      => $message_template_group->get('MTP_deleted'),
1520
-                'css_class'  => '',
1521
-                'format'     => '%d',
1522
-                'db-col'     => 'MTP_deleted'
1523
-            );
1524
-            $sidebar_form_fields['ee-msg-author']  = array(
1525
-                'name'       => 'MTP_user_id',
1526
-                'label'      => __('Author', 'event_espresso'),
1527
-                'input'      => 'hidden',
1528
-                'type'       => 'int',
1529
-                'required'   => false,
1530
-                'validation' => false,
1531
-                'value'      => $message_template_group->user(),
1532
-                'format'     => '%d',
1533
-                'db-col'     => 'MTP_user_id'
1534
-            );
1512
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1513
+				'name'       => 'MTP_deleted',
1514
+				'label'      => null,
1515
+				'input'      => 'hidden',
1516
+				'type'       => 'int',
1517
+				'required'   => false,
1518
+				'validation' => true,
1519
+				'value'      => $message_template_group->get('MTP_deleted'),
1520
+				'css_class'  => '',
1521
+				'format'     => '%d',
1522
+				'db-col'     => 'MTP_deleted'
1523
+			);
1524
+			$sidebar_form_fields['ee-msg-author']  = array(
1525
+				'name'       => 'MTP_user_id',
1526
+				'label'      => __('Author', 'event_espresso'),
1527
+				'input'      => 'hidden',
1528
+				'type'       => 'int',
1529
+				'required'   => false,
1530
+				'validation' => false,
1531
+				'value'      => $message_template_group->user(),
1532
+				'format'     => '%d',
1533
+				'db-col'     => 'MTP_user_id'
1534
+			);
1535 1535
             
1536
-            $sidebar_form_fields['ee-msg-route'] = array(
1537
-                'name'  => 'action',
1538
-                'input' => 'hidden',
1539
-                'type'  => 'string',
1540
-                'value' => $action
1541
-            );
1536
+			$sidebar_form_fields['ee-msg-route'] = array(
1537
+				'name'  => 'action',
1538
+				'input' => 'hidden',
1539
+				'type'  => 'string',
1540
+				'value' => $action
1541
+			);
1542 1542
             
1543
-            $sidebar_form_fields['ee-msg-id']        = array(
1544
-                'name'  => 'id',
1545
-                'input' => 'hidden',
1546
-                'type'  => 'int',
1547
-                'value' => $GRP_ID
1548
-            );
1549
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1550
-                'name'  => $action . '_nonce',
1551
-                'input' => 'hidden',
1552
-                'type'  => 'string',
1553
-                'value' => wp_create_nonce($action . '_nonce')
1554
-            );
1543
+			$sidebar_form_fields['ee-msg-id']        = array(
1544
+				'name'  => 'id',
1545
+				'input' => 'hidden',
1546
+				'type'  => 'int',
1547
+				'value' => $GRP_ID
1548
+			);
1549
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1550
+				'name'  => $action . '_nonce',
1551
+				'input' => 'hidden',
1552
+				'type'  => 'string',
1553
+				'value' => wp_create_nonce($action . '_nonce')
1554
+			);
1555 1555
             
1556
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1557
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1558
-                    'name'  => 'template_switch',
1559
-                    'input' => 'hidden',
1560
-                    'type'  => 'int',
1561
-                    'value' => 1
1562
-                );
1563
-            }
1556
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1557
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1558
+					'name'  => 'template_switch',
1559
+					'input' => 'hidden',
1560
+					'type'  => 'int',
1561
+					'value' => 1
1562
+				);
1563
+			}
1564 1564
             
1565 1565
             
1566
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1567
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1566
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1567
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1568 1568
             
1569 1569
             
1570
-        } //end if ( !empty($template_field_structure) )
1570
+		} //end if ( !empty($template_field_structure) )
1571 1571
         
1572
-        //set extra content for publish box
1573
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1574
-        $this->_set_publish_post_box_vars(
1575
-            'id',
1576
-            $GRP_ID,
1577
-            false,
1578
-            add_query_arg(
1579
-                array('action' => 'global_mtps'),
1580
-                $this->_admin_base_url
1581
-            )
1582
-        );
1583
-        
1584
-        //add preview button
1585
-        $preview_url    = parent::add_query_args_and_nonce(
1586
-            array(
1587
-                'message_type' => $message_template_group->message_type(),
1588
-                'messenger'    => $message_template_group->messenger(),
1589
-                'context'      => $context,
1590
-                'GRP_ID'       => $GRP_ID,
1591
-                'action'       => 'preview_message'
1592
-            ),
1593
-            $this->_admin_base_url
1594
-        );
1595
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1596
-                'event_espresso') . '</a>';
1597
-        
1598
-        
1599
-        //setup context switcher
1600
-        $context_switcher_args = array(
1601
-            'page'    => 'espresso_messages',
1602
-            'action'  => 'edit_message_template',
1603
-            'id'      => $GRP_ID,
1604
-            'context' => $context,
1605
-            'extra'   => $preview_button
1606
-        );
1607
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1608
-        
1609
-        
1610
-        //main box
1611
-        $this->_template_args['template_fields']                         = $template_fields;
1612
-        $this->_template_args['sidebar_box_id']                          = 'details';
1613
-        $this->_template_args['action']                                  = $action;
1614
-        $this->_template_args['context']                                 = $context;
1615
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1616
-        $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1617
-        
1618
-        
1619
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1620
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1621
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1622
-        
1623
-        $this->_template_path = $this->_template_args['GRP_ID']
1624
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1625
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1626
-        
1627
-        //send along EE_Message_Template_Group object for further template use.
1628
-        $this->_template_args['MTP'] = $message_template_group;
1629
-        
1630
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1631
-            $this->_template_args, true);
1632
-        
1633
-        
1634
-        //finally, let's set the admin_page title
1635
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1636
-        
1637
-        
1638
-        //we need to take care of setting the shortcodes property for use elsewhere.
1639
-        $this->_set_shortcodes();
1640
-        
1641
-        
1642
-        //final template wrapper
1643
-        $this->display_admin_page_with_sidebar();
1644
-    }
1645
-    
1646
-    
1647
-    public function filter_tinymce_init($mceInit, $editor_id)
1648
-    {
1649
-        return $mceInit;
1650
-    }
1651
-    
1652
-    
1653
-    public function add_context_switcher()
1654
-    {
1655
-        return $this->_context_switcher;
1656
-    }
1657
-    
1658
-    public function _add_form_element_before()
1659
-    {
1660
-        return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1661
-    }
1662
-    
1663
-    public function _add_form_element_after()
1664
-    {
1665
-        return '</form>';
1666
-    }
1667
-    
1668
-    
1669
-    /**
1670
-     * This executes switching the template pack for a message template.
1671
-     *
1672
-     * @since 4.5.0
1673
-     *
1674
-     */
1675
-    public function switch_template_pack()
1676
-    {
1677
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1678
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1679
-        
1680
-        //verify we have needed values.
1681
-        if (empty($GRP_ID) || empty($template_pack)) {
1682
-            $this->_template_args['error'] = true;
1683
-            EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1684
-                __FILE__, __FUNCTION__, __LINE__);
1685
-        } else {
1686
-            //get template, set the new template_pack and then reset to default
1687
-            /** @type EE_Message_Template_Group $message_template_group */
1688
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1572
+		//set extra content for publish box
1573
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1574
+		$this->_set_publish_post_box_vars(
1575
+			'id',
1576
+			$GRP_ID,
1577
+			false,
1578
+			add_query_arg(
1579
+				array('action' => 'global_mtps'),
1580
+				$this->_admin_base_url
1581
+			)
1582
+		);
1583
+        
1584
+		//add preview button
1585
+		$preview_url    = parent::add_query_args_and_nonce(
1586
+			array(
1587
+				'message_type' => $message_template_group->message_type(),
1588
+				'messenger'    => $message_template_group->messenger(),
1589
+				'context'      => $context,
1590
+				'GRP_ID'       => $GRP_ID,
1591
+				'action'       => 'preview_message'
1592
+			),
1593
+			$this->_admin_base_url
1594
+		);
1595
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1596
+				'event_espresso') . '</a>';
1597
+        
1598
+        
1599
+		//setup context switcher
1600
+		$context_switcher_args = array(
1601
+			'page'    => 'espresso_messages',
1602
+			'action'  => 'edit_message_template',
1603
+			'id'      => $GRP_ID,
1604
+			'context' => $context,
1605
+			'extra'   => $preview_button
1606
+		);
1607
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1608
+        
1609
+        
1610
+		//main box
1611
+		$this->_template_args['template_fields']                         = $template_fields;
1612
+		$this->_template_args['sidebar_box_id']                          = 'details';
1613
+		$this->_template_args['action']                                  = $action;
1614
+		$this->_template_args['context']                                 = $context;
1615
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1616
+		$this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1617
+        
1618
+        
1619
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1620
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1621
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1622
+        
1623
+		$this->_template_path = $this->_template_args['GRP_ID']
1624
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1625
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1626
+        
1627
+		//send along EE_Message_Template_Group object for further template use.
1628
+		$this->_template_args['MTP'] = $message_template_group;
1629
+        
1630
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1631
+			$this->_template_args, true);
1632
+        
1633
+        
1634
+		//finally, let's set the admin_page title
1635
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1636
+        
1637
+        
1638
+		//we need to take care of setting the shortcodes property for use elsewhere.
1639
+		$this->_set_shortcodes();
1640
+        
1641
+        
1642
+		//final template wrapper
1643
+		$this->display_admin_page_with_sidebar();
1644
+	}
1645
+    
1646
+    
1647
+	public function filter_tinymce_init($mceInit, $editor_id)
1648
+	{
1649
+		return $mceInit;
1650
+	}
1651
+    
1652
+    
1653
+	public function add_context_switcher()
1654
+	{
1655
+		return $this->_context_switcher;
1656
+	}
1657
+    
1658
+	public function _add_form_element_before()
1659
+	{
1660
+		return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1661
+	}
1662
+    
1663
+	public function _add_form_element_after()
1664
+	{
1665
+		return '</form>';
1666
+	}
1667
+    
1668
+    
1669
+	/**
1670
+	 * This executes switching the template pack for a message template.
1671
+	 *
1672
+	 * @since 4.5.0
1673
+	 *
1674
+	 */
1675
+	public function switch_template_pack()
1676
+	{
1677
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1678
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1679
+        
1680
+		//verify we have needed values.
1681
+		if (empty($GRP_ID) || empty($template_pack)) {
1682
+			$this->_template_args['error'] = true;
1683
+			EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1684
+				__FILE__, __FUNCTION__, __LINE__);
1685
+		} else {
1686
+			//get template, set the new template_pack and then reset to default
1687
+			/** @type EE_Message_Template_Group $message_template_group */
1688
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1689 1689
             
1690
-            $message_template_group->set_template_pack_name($template_pack);
1691
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1692
-            $this->_req_data['mt']   = $message_template_group->message_type();
1690
+			$message_template_group->set_template_pack_name($template_pack);
1691
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1692
+			$this->_req_data['mt']   = $message_template_group->message_type();
1693 1693
             
1694
-            $query_args = $this->_reset_to_default_template();
1694
+			$query_args = $this->_reset_to_default_template();
1695 1695
             
1696
-            if (empty($query_args['id'])) {
1697
-                EE_Error::add_error(
1698
-                    __(
1699
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1700
-                        'event_espresso'
1701
-                    ),
1702
-                    __FILE__, __FUNCTION__, __LINE__
1703
-                );
1704
-                $this->_template_args['error'] = true;
1705
-            } else {
1706
-                $template_label       = $message_template_group->get_template_pack()->label;
1707
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1708
-                EE_Error::add_success(
1709
-                    sprintf(
1710
-                        __(
1711
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1712
-                            'event_espresso'
1713
-                        ),
1714
-                        $template_label,
1715
-                        $template_pack_labels->template_pack
1716
-                    )
1717
-                );
1718
-                //generate the redirect url for js.
1719
-                $url                                          = self::add_query_args_and_nonce($query_args,
1720
-                    $this->_admin_base_url);
1721
-                $this->_template_args['data']['redirect_url'] = $url;
1722
-                $this->_template_args['success']              = true;
1723
-            }
1696
+			if (empty($query_args['id'])) {
1697
+				EE_Error::add_error(
1698
+					__(
1699
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1700
+						'event_espresso'
1701
+					),
1702
+					__FILE__, __FUNCTION__, __LINE__
1703
+				);
1704
+				$this->_template_args['error'] = true;
1705
+			} else {
1706
+				$template_label       = $message_template_group->get_template_pack()->label;
1707
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1708
+				EE_Error::add_success(
1709
+					sprintf(
1710
+						__(
1711
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1712
+							'event_espresso'
1713
+						),
1714
+						$template_label,
1715
+						$template_pack_labels->template_pack
1716
+					)
1717
+				);
1718
+				//generate the redirect url for js.
1719
+				$url                                          = self::add_query_args_and_nonce($query_args,
1720
+					$this->_admin_base_url);
1721
+				$this->_template_args['data']['redirect_url'] = $url;
1722
+				$this->_template_args['success']              = true;
1723
+			}
1724 1724
             
1725
-            $this->_return_json();
1725
+			$this->_return_json();
1726 1726
             
1727
-        }
1728
-    }
1729
-    
1730
-    
1731
-    /**
1732
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1733
-     * they want.
1734
-     *
1735
-     * @access protected
1736
-     * @return array|null
1737
-     */
1738
-    protected function _reset_to_default_template()
1739
-    {
1740
-        
1741
-        $templates = array();
1742
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1743
-        //we need to make sure we've got the info we need.
1744
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1745
-            EE_Error::add_error(
1746
-                __(
1747
-                    '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.',
1748
-                    'event_espresso'
1749
-                ),
1750
-                __FILE__, __FUNCTION__, __LINE__
1751
-            );
1752
-        }
1753
-        
1754
-        // all templates will be reset to whatever the defaults are
1755
-        // for the global template matching the messenger and message type.
1756
-        $success = ! empty($GRP_ID) ? true : false;
1757
-        
1758
-        if ($success) {
1727
+		}
1728
+	}
1729
+    
1730
+    
1731
+	/**
1732
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1733
+	 * they want.
1734
+	 *
1735
+	 * @access protected
1736
+	 * @return array|null
1737
+	 */
1738
+	protected function _reset_to_default_template()
1739
+	{
1740
+        
1741
+		$templates = array();
1742
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1743
+		//we need to make sure we've got the info we need.
1744
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1745
+			EE_Error::add_error(
1746
+				__(
1747
+					'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.',
1748
+					'event_espresso'
1749
+				),
1750
+				__FILE__, __FUNCTION__, __LINE__
1751
+			);
1752
+		}
1753
+        
1754
+		// all templates will be reset to whatever the defaults are
1755
+		// for the global template matching the messenger and message type.
1756
+		$success = ! empty($GRP_ID) ? true : false;
1757
+        
1758
+		if ($success) {
1759 1759
             
1760
-            //let's first determine if the incoming template is a global template,
1761
-            // if it isn't then we need to get the global template matching messenger and message type.
1762
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1760
+			//let's first determine if the incoming template is a global template,
1761
+			// if it isn't then we need to get the global template matching messenger and message type.
1762
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1763 1763
             
1764 1764
             
1765
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1766
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
1765
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1766
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
1767 1767
             
1768
-            if ($success) {
1769
-                // if successfully deleted, lets generate the new ones.
1770
-                // Note. We set GLOBAL to true, because resets on ANY template
1771
-                // will use the related global template defaults for regeneration.
1772
-                // This means that if a custom template is reset it resets to whatever the related global template is.
1773
-                // HOWEVER, we DO keep the template pack and template variation set
1774
-                // for the current custom template when resetting.
1775
-                $templates = $this->_generate_new_templates(
1776
-                    $this->_req_data['msgr'],
1777
-                    $this->_req_data['mt'],
1778
-                    $GRP_ID,
1779
-                    true
1780
-                );
1781
-            }
1768
+			if ($success) {
1769
+				// if successfully deleted, lets generate the new ones.
1770
+				// Note. We set GLOBAL to true, because resets on ANY template
1771
+				// will use the related global template defaults for regeneration.
1772
+				// This means that if a custom template is reset it resets to whatever the related global template is.
1773
+				// HOWEVER, we DO keep the template pack and template variation set
1774
+				// for the current custom template when resetting.
1775
+				$templates = $this->_generate_new_templates(
1776
+					$this->_req_data['msgr'],
1777
+					$this->_req_data['mt'],
1778
+					$GRP_ID,
1779
+					true
1780
+				);
1781
+			}
1782 1782
             
1783
-        }
1784
-        
1785
-        //any error messages?
1786
-        if ( ! $success) {
1787
-            EE_Error::add_error(
1788
-                __('Something went wrong with deleting existing templates. Unable to reset to default',
1789
-                    'event_espresso'),
1790
-                __FILE__, __FUNCTION__, __LINE__
1791
-            );
1792
-        }
1793
-        
1794
-        //all good, let's add a success message!
1795
-        if ($success && ! empty($templates)) {
1796
-            $templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1797
-            EE_Error::overwrite_success();
1798
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1799
-        }
1800
-        
1801
-        
1802
-        $query_args = array(
1803
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1804
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1805
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1806
-        );
1807
-        
1808
-        //if called via ajax then we return query args otherwise redirect
1809
-        if (defined('DOING_AJAX') && DOING_AJAX) {
1810
-            return $query_args;
1811
-        } else {
1812
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1783
+		}
1784
+        
1785
+		//any error messages?
1786
+		if ( ! $success) {
1787
+			EE_Error::add_error(
1788
+				__('Something went wrong with deleting existing templates. Unable to reset to default',
1789
+					'event_espresso'),
1790
+				__FILE__, __FUNCTION__, __LINE__
1791
+			);
1792
+		}
1793
+        
1794
+		//all good, let's add a success message!
1795
+		if ($success && ! empty($templates)) {
1796
+			$templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1797
+			EE_Error::overwrite_success();
1798
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1799
+		}
1800
+        
1801
+        
1802
+		$query_args = array(
1803
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1804
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1805
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1806
+		);
1807
+        
1808
+		//if called via ajax then we return query args otherwise redirect
1809
+		if (defined('DOING_AJAX') && DOING_AJAX) {
1810
+			return $query_args;
1811
+		} else {
1812
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1813 1813
             
1814
-            return null;
1815
-        }
1816
-    }
1817
-    
1818
-    
1819
-    /**
1820
-     * Retrieve and set the message preview for display.
1821
-     *
1822
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1823
-     *
1824
-     * @return string
1825
-     */
1826
-    public function _preview_message($send = false)
1827
-    {
1828
-        //first make sure we've got the necessary parameters
1829
-        if (
1830
-        ! isset(
1831
-            $this->_req_data['message_type'],
1832
-            $this->_req_data['messenger'],
1833
-            $this->_req_data['messenger'],
1834
-            $this->_req_data['GRP_ID']
1835
-        )
1836
-        ) {
1837
-            EE_Error::add_error(
1838
-                __('Missing necessary parameters for displaying preview', 'event_espresso'),
1839
-                __FILE__, __FUNCTION__, __LINE__
1840
-            );
1841
-        }
1842
-        
1843
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1844
-        
1845
-        
1846
-        //get the preview!
1847
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1848
-            $this->_req_data['messenger'], $send);
1849
-        
1850
-        if ($send) {
1851
-            return $preview;
1852
-        }
1853
-        
1854
-        //let's add a button to go back to the edit view
1855
-        $query_args             = array(
1856
-            'id'      => $this->_req_data['GRP_ID'],
1857
-            'context' => $this->_req_data['context'],
1858
-            'action'  => 'edit_message_template'
1859
-        );
1860
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1861
-        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1862
-                'event_espresso') . '</a>';
1863
-        $message_types          = $this->get_installed_message_types();
1864
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1865
-        $active_messenger_label = $active_messenger instanceof EE_messenger
1866
-            ? ucwords($active_messenger->label['singular'])
1867
-            : esc_html__('Unknown Messenger', 'event_espresso');
1868
-        //let's provide a helpful title for context
1869
-        $preview_title = sprintf(
1870
-            __('Viewing Preview for %s %s Message Template', 'event_espresso'),
1871
-            $active_messenger_label,
1872
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1873
-        );
1874
-        //setup display of preview.
1875
-        $this->_admin_page_title                    = $preview_title;
1876
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1877
-        $this->_template_args['data']['force_json'] = true;
1878
-        
1879
-        return '';
1880
-    }
1881
-    
1882
-    
1883
-    /**
1884
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1885
-     * gets called automatically.
1886
-     *
1887
-     * @since 4.5.0
1888
-     *
1889
-     * @return string
1890
-     */
1891
-    protected function _display_preview_message()
1892
-    {
1893
-        $this->display_admin_page_with_no_sidebar();
1894
-    }
1895
-    
1896
-    
1897
-    /**
1898
-     * registers metaboxes that should show up on the "edit_message_template" page
1899
-     *
1900
-     * @access protected
1901
-     * @return void
1902
-     */
1903
-    protected function _register_edit_meta_boxes()
1904
-    {
1905
-        add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1906
-            array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1907
-        add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1908
-            $this->_current_screen->id, 'side', 'high');
1909
-        add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1910
-            $this->_current_screen->id, 'side', 'high');
1911
-    }
1912
-    
1913
-    
1914
-    /**
1915
-     * metabox content for all template pack and variation selection.
1916
-     *
1917
-     * @since 4.5.0
1918
-     *
1919
-     * @return string
1920
-     */
1921
-    public function template_pack_meta_box()
1922
-    {
1923
-        $this->_set_message_template_group();
1924
-        
1925
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
1926
-        
1927
-        $tp_select_values = array();
1928
-        
1929
-        foreach ($tp_collection as $tp) {
1930
-            //only include template packs that support this messenger and message type!
1931
-            $supports = $tp->get_supports();
1932
-            if (
1933
-                ! isset($supports[$this->_message_template_group->messenger()])
1934
-                || ! in_array(
1935
-                    $this->_message_template_group->message_type(),
1936
-                    $supports[$this->_message_template_group->messenger()]
1937
-                )
1938
-            ) {
1939
-                //not supported
1940
-                continue;
1941
-            }
1814
+			return null;
1815
+		}
1816
+	}
1817
+    
1818
+    
1819
+	/**
1820
+	 * Retrieve and set the message preview for display.
1821
+	 *
1822
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1823
+	 *
1824
+	 * @return string
1825
+	 */
1826
+	public function _preview_message($send = false)
1827
+	{
1828
+		//first make sure we've got the necessary parameters
1829
+		if (
1830
+		! isset(
1831
+			$this->_req_data['message_type'],
1832
+			$this->_req_data['messenger'],
1833
+			$this->_req_data['messenger'],
1834
+			$this->_req_data['GRP_ID']
1835
+		)
1836
+		) {
1837
+			EE_Error::add_error(
1838
+				__('Missing necessary parameters for displaying preview', 'event_espresso'),
1839
+				__FILE__, __FUNCTION__, __LINE__
1840
+			);
1841
+		}
1842
+        
1843
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1844
+        
1845
+        
1846
+		//get the preview!
1847
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1848
+			$this->_req_data['messenger'], $send);
1849
+        
1850
+		if ($send) {
1851
+			return $preview;
1852
+		}
1853
+        
1854
+		//let's add a button to go back to the edit view
1855
+		$query_args             = array(
1856
+			'id'      => $this->_req_data['GRP_ID'],
1857
+			'context' => $this->_req_data['context'],
1858
+			'action'  => 'edit_message_template'
1859
+		);
1860
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1861
+		$preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1862
+				'event_espresso') . '</a>';
1863
+		$message_types          = $this->get_installed_message_types();
1864
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1865
+		$active_messenger_label = $active_messenger instanceof EE_messenger
1866
+			? ucwords($active_messenger->label['singular'])
1867
+			: esc_html__('Unknown Messenger', 'event_espresso');
1868
+		//let's provide a helpful title for context
1869
+		$preview_title = sprintf(
1870
+			__('Viewing Preview for %s %s Message Template', 'event_espresso'),
1871
+			$active_messenger_label,
1872
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1873
+		);
1874
+		//setup display of preview.
1875
+		$this->_admin_page_title                    = $preview_title;
1876
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1877
+		$this->_template_args['data']['force_json'] = true;
1878
+        
1879
+		return '';
1880
+	}
1881
+    
1882
+    
1883
+	/**
1884
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1885
+	 * gets called automatically.
1886
+	 *
1887
+	 * @since 4.5.0
1888
+	 *
1889
+	 * @return string
1890
+	 */
1891
+	protected function _display_preview_message()
1892
+	{
1893
+		$this->display_admin_page_with_no_sidebar();
1894
+	}
1895
+    
1896
+    
1897
+	/**
1898
+	 * registers metaboxes that should show up on the "edit_message_template" page
1899
+	 *
1900
+	 * @access protected
1901
+	 * @return void
1902
+	 */
1903
+	protected function _register_edit_meta_boxes()
1904
+	{
1905
+		add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1906
+			array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1907
+		add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1908
+			$this->_current_screen->id, 'side', 'high');
1909
+		add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1910
+			$this->_current_screen->id, 'side', 'high');
1911
+	}
1912
+    
1913
+    
1914
+	/**
1915
+	 * metabox content for all template pack and variation selection.
1916
+	 *
1917
+	 * @since 4.5.0
1918
+	 *
1919
+	 * @return string
1920
+	 */
1921
+	public function template_pack_meta_box()
1922
+	{
1923
+		$this->_set_message_template_group();
1924
+        
1925
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
1926
+        
1927
+		$tp_select_values = array();
1928
+        
1929
+		foreach ($tp_collection as $tp) {
1930
+			//only include template packs that support this messenger and message type!
1931
+			$supports = $tp->get_supports();
1932
+			if (
1933
+				! isset($supports[$this->_message_template_group->messenger()])
1934
+				|| ! in_array(
1935
+					$this->_message_template_group->message_type(),
1936
+					$supports[$this->_message_template_group->messenger()]
1937
+				)
1938
+			) {
1939
+				//not supported
1940
+				continue;
1941
+			}
1942 1942
             
1943
-            $tp_select_values[] = array(
1944
-                'text' => $tp->label,
1945
-                'id'   => $tp->dbref
1946
-            );
1947
-        }
1948
-        
1949
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1950
-        if (empty($tp_select_values)) {
1951
-            $tp_select_values[] = array(
1952
-                'text' => __('Default', 'event_espresso'),
1953
-                'id'   => 'default'
1954
-            );
1955
-        }
1956
-        
1957
-        //setup variation select values for the currently selected template.
1958
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
1959
-            $this->_message_template_group->messenger(),
1960
-            $this->_message_template_group->message_type()
1961
-        );
1962
-        $variations_select_values = array();
1963
-        foreach ($variations as $variation => $label) {
1964
-            $variations_select_values[] = array(
1965
-                'text' => $label,
1966
-                'id'   => $variation
1967
-            );
1968
-        }
1969
-        
1970
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1971
-        
1972
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1973
-            'MTP_template_pack',
1974
-            $tp_select_values,
1975
-            $this->_message_template_group->get_template_pack_name()
1976
-        );
1977
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
1978
-            'MTP_template_variation',
1979
-            $variations_select_values,
1980
-            $this->_message_template_group->get_template_pack_variation()
1981
-        );
1982
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
1983
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
1984
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1985
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1986
-        
1987
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1988
-        
1989
-        EEH_Template::display_template($template, $template_args);
1990
-    }
1991
-    
1992
-    
1993
-    /**
1994
-     * This meta box holds any extra actions related to Message Templates
1995
-     * For now, this includes Resetting templates to defaults and sending a test email.
1996
-     *
1997
-     * @access  public
1998
-     * @return void
1999
-     * @throws \EE_Error
2000
-     */
2001
-    public function extra_actions_meta_box()
2002
-    {
2003
-        $template_form_fields = array();
2004
-        
2005
-        $extra_args = array(
2006
-            'msgr'   => $this->_message_template_group->messenger(),
2007
-            'mt'     => $this->_message_template_group->message_type(),
2008
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2009
-        );
2010
-        //first we need to see if there are any fields
2011
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2012
-        
2013
-        if ( ! empty($fields)) {
2014
-            //yup there be fields
2015
-            foreach ($fields as $field => $config) {
2016
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2017
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2018
-                $default  = isset($config['default']) ? $config['default'] : '';
2019
-                $default  = isset($config['value']) ? $config['value'] : $default;
1943
+			$tp_select_values[] = array(
1944
+				'text' => $tp->label,
1945
+				'id'   => $tp->dbref
1946
+			);
1947
+		}
1948
+        
1949
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1950
+		if (empty($tp_select_values)) {
1951
+			$tp_select_values[] = array(
1952
+				'text' => __('Default', 'event_espresso'),
1953
+				'id'   => 'default'
1954
+			);
1955
+		}
1956
+        
1957
+		//setup variation select values for the currently selected template.
1958
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
1959
+			$this->_message_template_group->messenger(),
1960
+			$this->_message_template_group->message_type()
1961
+		);
1962
+		$variations_select_values = array();
1963
+		foreach ($variations as $variation => $label) {
1964
+			$variations_select_values[] = array(
1965
+				'text' => $label,
1966
+				'id'   => $variation
1967
+			);
1968
+		}
1969
+        
1970
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1971
+        
1972
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1973
+			'MTP_template_pack',
1974
+			$tp_select_values,
1975
+			$this->_message_template_group->get_template_pack_name()
1976
+		);
1977
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
1978
+			'MTP_template_variation',
1979
+			$variations_select_values,
1980
+			$this->_message_template_group->get_template_pack_variation()
1981
+		);
1982
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
1983
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
1984
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1985
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1986
+        
1987
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1988
+        
1989
+		EEH_Template::display_template($template, $template_args);
1990
+	}
1991
+    
1992
+    
1993
+	/**
1994
+	 * This meta box holds any extra actions related to Message Templates
1995
+	 * For now, this includes Resetting templates to defaults and sending a test email.
1996
+	 *
1997
+	 * @access  public
1998
+	 * @return void
1999
+	 * @throws \EE_Error
2000
+	 */
2001
+	public function extra_actions_meta_box()
2002
+	{
2003
+		$template_form_fields = array();
2004
+        
2005
+		$extra_args = array(
2006
+			'msgr'   => $this->_message_template_group->messenger(),
2007
+			'mt'     => $this->_message_template_group->message_type(),
2008
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2009
+		);
2010
+		//first we need to see if there are any fields
2011
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2012
+        
2013
+		if ( ! empty($fields)) {
2014
+			//yup there be fields
2015
+			foreach ($fields as $field => $config) {
2016
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2017
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2018
+				$default  = isset($config['default']) ? $config['default'] : '';
2019
+				$default  = isset($config['value']) ? $config['value'] : $default;
2020 2020
                 
2021
-                // if type is hidden and the value is empty
2022
-                // something may have gone wrong so let's correct with the defaults
2023
-                $fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2024
-                    ? $default
2025
-                    : '';
2026
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2027
-                    ? $existing[$field]
2028
-                    : $fix;
2021
+				// if type is hidden and the value is empty
2022
+				// something may have gone wrong so let's correct with the defaults
2023
+				$fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2024
+					? $default
2025
+					: '';
2026
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2027
+					? $existing[$field]
2028
+					: $fix;
2029 2029
                 
2030
-                $template_form_fields[$field_id] = array(
2031
-                    'name'       => 'test_settings_fld[' . $field . ']',
2032
-                    'label'      => $config['label'],
2033
-                    'input'      => $config['input'],
2034
-                    'type'       => $config['type'],
2035
-                    'required'   => $config['required'],
2036
-                    'validation' => $config['validation'],
2037
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2038
-                    'css_class'  => $config['css_class'],
2039
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2040
-                    'default'    => $default,
2041
-                    'format'     => $config['format']
2042
-                );
2043
-            }
2044
-        }
2045
-        
2046
-        $test_settings_fields = ! empty($template_form_fields)
2047
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2048
-            : '';
2049
-        
2050
-        $test_settings_html = '';
2051
-        //print out $test_settings_fields
2052
-        if ( ! empty($test_settings_fields)) {
2053
-            echo $test_settings_fields;
2054
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2055
-            $test_settings_html .= 'name="test_button" value="';
2056
-            $test_settings_html .= __('Test Send', 'event_espresso');
2057
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2058
-        }
2059
-        
2060
-        //and button
2061
-        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2062
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2063
-        $test_settings_html .= $this->get_action_link_or_button(
2064
-            'reset_to_default',
2065
-            'reset',
2066
-            $extra_args,
2067
-            'button-primary reset-default-button'
2068
-        );
2069
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2070
-        echo $test_settings_html;
2071
-    }
2072
-    
2073
-    
2074
-    /**
2075
-     * This returns the shortcode selector skeleton for a given context and field.
2076
-     *
2077
-     * @since 4.9.rc.000
2078
-     *
2079
-     * @param string $field           The name of the field retrieving shortcodes for.
2080
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2081
-     *
2082
-     * @return string
2083
-     */
2084
-    protected function _get_shortcode_selector($field, $linked_input_id)
2085
-    {
2086
-        $template_args = array(
2087
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2088
-            'fieldname'       => $field,
2089
-            'linked_input_id' => $linked_input_id
2090
-        );
2091
-        
2092
-        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2093
-            $template_args, true);
2094
-    }
2095
-    
2096
-    
2097
-    /**
2098
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2099
-     * page)
2100
-     *
2101
-     * @access public
2102
-     * @return void
2103
-     */
2104
-    public function shortcode_meta_box()
2105
-    {
2106
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2107
-        //$messenger = $this->_message_template_group->messenger_obj();
2108
-        //now let's set the content depending on the status of the shortcodes array
2109
-        if (empty($shortcodes)) {
2110
-            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2111
-            echo $content;
2112
-        } else {
2113
-            //$alt = 0;
2114
-            ?>
2030
+				$template_form_fields[$field_id] = array(
2031
+					'name'       => 'test_settings_fld[' . $field . ']',
2032
+					'label'      => $config['label'],
2033
+					'input'      => $config['input'],
2034
+					'type'       => $config['type'],
2035
+					'required'   => $config['required'],
2036
+					'validation' => $config['validation'],
2037
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2038
+					'css_class'  => $config['css_class'],
2039
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2040
+					'default'    => $default,
2041
+					'format'     => $config['format']
2042
+				);
2043
+			}
2044
+		}
2045
+        
2046
+		$test_settings_fields = ! empty($template_form_fields)
2047
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2048
+			: '';
2049
+        
2050
+		$test_settings_html = '';
2051
+		//print out $test_settings_fields
2052
+		if ( ! empty($test_settings_fields)) {
2053
+			echo $test_settings_fields;
2054
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2055
+			$test_settings_html .= 'name="test_button" value="';
2056
+			$test_settings_html .= __('Test Send', 'event_espresso');
2057
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2058
+		}
2059
+        
2060
+		//and button
2061
+		$test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2062
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2063
+		$test_settings_html .= $this->get_action_link_or_button(
2064
+			'reset_to_default',
2065
+			'reset',
2066
+			$extra_args,
2067
+			'button-primary reset-default-button'
2068
+		);
2069
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2070
+		echo $test_settings_html;
2071
+	}
2072
+    
2073
+    
2074
+	/**
2075
+	 * This returns the shortcode selector skeleton for a given context and field.
2076
+	 *
2077
+	 * @since 4.9.rc.000
2078
+	 *
2079
+	 * @param string $field           The name of the field retrieving shortcodes for.
2080
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2081
+	 *
2082
+	 * @return string
2083
+	 */
2084
+	protected function _get_shortcode_selector($field, $linked_input_id)
2085
+	{
2086
+		$template_args = array(
2087
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2088
+			'fieldname'       => $field,
2089
+			'linked_input_id' => $linked_input_id
2090
+		);
2091
+        
2092
+		return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2093
+			$template_args, true);
2094
+	}
2095
+    
2096
+    
2097
+	/**
2098
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2099
+	 * page)
2100
+	 *
2101
+	 * @access public
2102
+	 * @return void
2103
+	 */
2104
+	public function shortcode_meta_box()
2105
+	{
2106
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2107
+		//$messenger = $this->_message_template_group->messenger_obj();
2108
+		//now let's set the content depending on the status of the shortcodes array
2109
+		if (empty($shortcodes)) {
2110
+			$content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2111
+			echo $content;
2112
+		} else {
2113
+			//$alt = 0;
2114
+			?>
2115 2115
             <div
2116 2116
                 style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2117 2117
             <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2118
-                    'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2118
+					'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2119 2119
             <?php
2120
-        }
2121
-        
2122
-        
2123
-    }
2124
-    
2125
-    
2126
-    /**
2127
-     * used to set the $_shortcodes property for when its needed elsewhere.
2128
-     *
2129
-     * @access protected
2130
-     * @return void
2131
-     */
2132
-    protected function _set_shortcodes()
2133
-    {
2134
-        
2135
-        //no need to run this if the property is already set
2136
-        if ( ! empty($this->_shortcodes)) {
2137
-            return;
2138
-        }
2139
-        
2140
-        $this->_shortcodes = $this->_get_shortcodes();
2141
-    }
2142
-    
2143
-    
2144
-    /**
2145
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2146
-     * property)
2147
-     *
2148
-     * @access  protected
2149
-     *
2150
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2151
-     *                         for. Defaults to all (for the given context)
2152
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2153
-     *
2154
-     * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2155
-     *                        true just an array of shortcode/label pairs.
2156
-     */
2157
-    protected function _get_shortcodes($fields = array(), $merged = true)
2158
-    {
2159
-        $this->_set_message_template_group();
2160
-        
2161
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2162
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2163
-        $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2164
-        
2165
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2166
-    }
2167
-    
2168
-    
2169
-    /**
2170
-     * This sets the _message_template property (containing the called message_template object)
2171
-     *
2172
-     * @access protected
2173
-     * @return  void
2174
-     */
2175
-    protected function _set_message_template_group()
2176
-    {
2177
-        
2178
-        if ( ! empty($this->_message_template_group)) {
2179
-            return;
2180
-        } //get out if this is already set.
2181
-        
2182
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2183
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2184
-        
2185
-        //let's get the message templates
2186
-        $MTP = EEM_Message_Template_Group::instance();
2187
-        
2188
-        if (empty($GRP_ID)) {
2189
-            $this->_message_template_group = $MTP->create_default_object();
2190
-        } else {
2191
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2192
-        }
2193
-        
2194
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2195
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2196
-        
2197
-    }
2198
-    
2199
-    
2200
-    /**
2201
-     * sets up a context switcher for edit forms
2202
-     *
2203
-     * @access  protected
2204
-     *
2205
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2206
-     * @param array                      $args                  various things the context switcher needs.
2207
-     *
2208
-     */
2209
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2210
-    {
2211
-        $context_details = $template_group_object->contexts_config();
2212
-        $context_label   = $template_group_object->context_label();
2213
-        ob_start();
2214
-        ?>
2120
+		}
2121
+        
2122
+        
2123
+	}
2124
+    
2125
+    
2126
+	/**
2127
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2128
+	 *
2129
+	 * @access protected
2130
+	 * @return void
2131
+	 */
2132
+	protected function _set_shortcodes()
2133
+	{
2134
+        
2135
+		//no need to run this if the property is already set
2136
+		if ( ! empty($this->_shortcodes)) {
2137
+			return;
2138
+		}
2139
+        
2140
+		$this->_shortcodes = $this->_get_shortcodes();
2141
+	}
2142
+    
2143
+    
2144
+	/**
2145
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2146
+	 * property)
2147
+	 *
2148
+	 * @access  protected
2149
+	 *
2150
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2151
+	 *                         for. Defaults to all (for the given context)
2152
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2153
+	 *
2154
+	 * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2155
+	 *                        true just an array of shortcode/label pairs.
2156
+	 */
2157
+	protected function _get_shortcodes($fields = array(), $merged = true)
2158
+	{
2159
+		$this->_set_message_template_group();
2160
+        
2161
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2162
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2163
+		$context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2164
+        
2165
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2166
+	}
2167
+    
2168
+    
2169
+	/**
2170
+	 * This sets the _message_template property (containing the called message_template object)
2171
+	 *
2172
+	 * @access protected
2173
+	 * @return  void
2174
+	 */
2175
+	protected function _set_message_template_group()
2176
+	{
2177
+        
2178
+		if ( ! empty($this->_message_template_group)) {
2179
+			return;
2180
+		} //get out if this is already set.
2181
+        
2182
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2183
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2184
+        
2185
+		//let's get the message templates
2186
+		$MTP = EEM_Message_Template_Group::instance();
2187
+        
2188
+		if (empty($GRP_ID)) {
2189
+			$this->_message_template_group = $MTP->create_default_object();
2190
+		} else {
2191
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2192
+		}
2193
+        
2194
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2195
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2196
+        
2197
+	}
2198
+    
2199
+    
2200
+	/**
2201
+	 * sets up a context switcher for edit forms
2202
+	 *
2203
+	 * @access  protected
2204
+	 *
2205
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2206
+	 * @param array                      $args                  various things the context switcher needs.
2207
+	 *
2208
+	 */
2209
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2210
+	{
2211
+		$context_details = $template_group_object->contexts_config();
2212
+		$context_label   = $template_group_object->context_label();
2213
+		ob_start();
2214
+		?>
2215 2215
         <div class="ee-msg-switcher-container">
2216 2216
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2217 2217
                 <?php
2218
-                foreach ($args as $name => $value) {
2219
-                    if ($name == 'context' || empty($value) || $name == 'extra') {
2220
-                        continue;
2221
-                    }
2222
-                    ?>
2218
+				foreach ($args as $name => $value) {
2219
+					if ($name == 'context' || empty($value) || $name == 'extra') {
2220
+						continue;
2221
+					}
2222
+					?>
2223 2223
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2224 2224
                     <?php
2225
-                }
2226
-                //setup nonce_url
2227
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2228
-                ?>
2225
+				}
2226
+				//setup nonce_url
2227
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2228
+				?>
2229 2229
                 <select name="context">
2230 2230
                     <?php
2231
-                    $context_templates = $template_group_object->context_templates();
2232
-                    if (is_array($context_templates)) :
2233
-                        foreach ($context_templates as $context => $template_fields) :
2234
-                            $checked = ($context == $args['context']) ? 'selected="selected"' : '';
2235
-                            ?>
2231
+					$context_templates = $template_group_object->context_templates();
2232
+					if (is_array($context_templates)) :
2233
+						foreach ($context_templates as $context => $template_fields) :
2234
+							$checked = ($context == $args['context']) ? 'selected="selected"' : '';
2235
+							?>
2236 2236
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2237 2237
                                 <?php echo $context_details[$context]['label']; ?>
2238 2238
                             </option>
@@ -2245,1584 +2245,1584 @@  discard block
 block discarded – undo
2245 2245
             <?php echo $args['extra']; ?>
2246 2246
         </div> <!-- end .ee-msg-switcher-container -->
2247 2247
         <?php
2248
-        $output = ob_get_contents();
2249
-        ob_clean();
2250
-        $this->_context_switcher = $output;
2251
-    }
2252
-    
2253
-    
2254
-    /**
2255
-     * utility for sanitizing new values coming in.
2256
-     * Note: this is only used when updating a context.
2257
-     *
2258
-     * @access protected
2259
-     *
2260
-     * @param int $index This helps us know which template field to select from the request array.
2261
-     *
2262
-     * @return array
2263
-     */
2264
-    protected function _set_message_template_column_values($index)
2265
-    {
2266
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2267
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2268
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2269
-            }
2270
-        } /*else {
2248
+		$output = ob_get_contents();
2249
+		ob_clean();
2250
+		$this->_context_switcher = $output;
2251
+	}
2252
+    
2253
+    
2254
+	/**
2255
+	 * utility for sanitizing new values coming in.
2256
+	 * Note: this is only used when updating a context.
2257
+	 *
2258
+	 * @access protected
2259
+	 *
2260
+	 * @param int $index This helps us know which template field to select from the request array.
2261
+	 *
2262
+	 * @return array
2263
+	 */
2264
+	protected function _set_message_template_column_values($index)
2265
+	{
2266
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2267
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2268
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2269
+			}
2270
+		} /*else {
2271 2271
 			$this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content'];
2272 2272
 		}*/
2273 2273
         
2274 2274
         
2275
-        $set_column_values = array(
2276
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2277
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2278
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2279
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2280
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2281
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2282
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2283
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2284
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2285
-                ? absint($this->_req_data['MTP_is_global'])
2286
-                : 0,
2287
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2288
-                ? absint($this->_req_data['MTP_is_override'])
2289
-                : 0,
2290
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2291
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2292
-        );
2293
-        
2294
-        
2295
-        return $set_column_values;
2296
-    }
2297
-    
2298
-    
2299
-    protected function _insert_or_update_message_template($new = false)
2300
-    {
2301
-        
2302
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2303
-        $success  = 0;
2304
-        $override = false;
2305
-        
2306
-        //setup notices description
2307
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2308
-        
2309
-        //need the message type and messenger objects to be able to use the labels for the notices
2310
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2311
-        $messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2312
-        
2313
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2314
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2315
-        
2316
-        $message_type_label = $message_type_object instanceof EE_message_type
2317
-            ? ucwords($message_type_object->label['singular'])
2318
-            : '';
2319
-        
2320
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2321
-            ? $this->_req_data['MTP_context']
2322
-            : '';
2323
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2324
-        
2325
-        $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2326
-        $item_desc .= 'Message Template';
2327
-        $query_args  = array();
2328
-        $edit_array  = array();
2329
-        $action_desc = '';
2330
-        
2331
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2332
-        if ($new) {
2333
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2334
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2335
-                if (empty($edit_array)) {
2336
-                    $success = 0;
2337
-                } else {
2338
-                    $success    = 1;
2339
-                    $edit_array = $edit_array[0];
2340
-                    $query_args = array(
2341
-                        'id'      => $edit_array['GRP_ID'],
2342
-                        'context' => $edit_array['MTP_context'],
2343
-                        'action'  => 'edit_message_template'
2344
-                    );
2345
-                }
2346
-            }
2347
-            $action_desc = 'created';
2348
-        } else {
2349
-            $MTPG = EEM_Message_Template_Group::instance();
2350
-            $MTP  = EEM_Message_Template::instance();
2275
+		$set_column_values = array(
2276
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2277
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2278
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2279
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2280
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2281
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2282
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2283
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2284
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2285
+				? absint($this->_req_data['MTP_is_global'])
2286
+				: 0,
2287
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2288
+				? absint($this->_req_data['MTP_is_override'])
2289
+				: 0,
2290
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2291
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2292
+		);
2293
+        
2294
+        
2295
+		return $set_column_values;
2296
+	}
2297
+    
2298
+    
2299
+	protected function _insert_or_update_message_template($new = false)
2300
+	{
2301
+        
2302
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2303
+		$success  = 0;
2304
+		$override = false;
2305
+        
2306
+		//setup notices description
2307
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2308
+        
2309
+		//need the message type and messenger objects to be able to use the labels for the notices
2310
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2311
+		$messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2312
+        
2313
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2314
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2315
+        
2316
+		$message_type_label = $message_type_object instanceof EE_message_type
2317
+			? ucwords($message_type_object->label['singular'])
2318
+			: '';
2319
+        
2320
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2321
+			? $this->_req_data['MTP_context']
2322
+			: '';
2323
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2324
+        
2325
+		$item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2326
+		$item_desc .= 'Message Template';
2327
+		$query_args  = array();
2328
+		$edit_array  = array();
2329
+		$action_desc = '';
2330
+        
2331
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2332
+		if ($new) {
2333
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2334
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2335
+				if (empty($edit_array)) {
2336
+					$success = 0;
2337
+				} else {
2338
+					$success    = 1;
2339
+					$edit_array = $edit_array[0];
2340
+					$query_args = array(
2341
+						'id'      => $edit_array['GRP_ID'],
2342
+						'context' => $edit_array['MTP_context'],
2343
+						'action'  => 'edit_message_template'
2344
+					);
2345
+				}
2346
+			}
2347
+			$action_desc = 'created';
2348
+		} else {
2349
+			$MTPG = EEM_Message_Template_Group::instance();
2350
+			$MTP  = EEM_Message_Template::instance();
2351 2351
             
2352 2352
             
2353
-            //run update for each template field in displayed context
2354
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2355
-                EE_Error::add_error(
2356
-                    __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2357
-                        'event_espresso'),
2358
-                    __FILE__, __FUNCTION__, __LINE__
2359
-                );
2360
-                $success = 0;
2353
+			//run update for each template field in displayed context
2354
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2355
+				EE_Error::add_error(
2356
+					__('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2357
+						'event_espresso'),
2358
+					__FILE__, __FUNCTION__, __LINE__
2359
+				);
2360
+				$success = 0;
2361 2361
                 
2362
-            } else {
2363
-                //first validate all fields!
2364
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2365
-                    $message_type_slug);
2362
+			} else {
2363
+				//first validate all fields!
2364
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2365
+					$message_type_slug);
2366 2366
                 
2367
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2368
-                if (is_array($validates) && ! empty($validates)) {
2369
-                    //add the transient so when the form loads we know which fields to highlight
2370
-                    $this->_add_transient('edit_message_template', $validates);
2367
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2368
+				if (is_array($validates) && ! empty($validates)) {
2369
+					//add the transient so when the form loads we know which fields to highlight
2370
+					$this->_add_transient('edit_message_template', $validates);
2371 2371
                     
2372
-                    $success = 0;
2372
+					$success = 0;
2373 2373
                     
2374
-                    //setup notices
2375
-                    foreach ($validates as $field => $error) {
2376
-                        if (isset($error['msg'])) {
2377
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2378
-                        }
2379
-                    }
2374
+					//setup notices
2375
+					foreach ($validates as $field => $error) {
2376
+						if (isset($error['msg'])) {
2377
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2378
+						}
2379
+					}
2380 2380
                     
2381
-                } else {
2382
-                    $set_column_values = array();
2383
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2384
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2381
+				} else {
2382
+					$set_column_values = array();
2383
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2384
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2385 2385
                         
2386
-                        $where_cols_n_values = array(
2387
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2388
-                        );
2386
+						$where_cols_n_values = array(
2387
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2388
+						);
2389 2389
                         
2390
-                        $message_template_fields = array(
2391
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2392
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2393
-                            'MTP_context'        => $set_column_values['MTP_context'],
2394
-                            'MTP_content'        => $set_column_values['MTP_content']
2395
-                        );
2396
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2397
-                            if ($updated === false) {
2398
-                                EE_Error::add_error(
2399
-                                    sprintf(
2400
-                                        __('%s field was NOT updated for some reason', 'event_espresso'),
2401
-                                        $template_field
2402
-                                    ),
2403
-                                    __FILE__, __FUNCTION__, __LINE__
2404
-                                );
2405
-                            } else {
2406
-                                $success = 1;
2407
-                            }
2408
-                        }
2409
-                        $action_desc = 'updated';
2410
-                    }
2390
+						$message_template_fields = array(
2391
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2392
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2393
+							'MTP_context'        => $set_column_values['MTP_context'],
2394
+							'MTP_content'        => $set_column_values['MTP_content']
2395
+						);
2396
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2397
+							if ($updated === false) {
2398
+								EE_Error::add_error(
2399
+									sprintf(
2400
+										__('%s field was NOT updated for some reason', 'event_espresso'),
2401
+										$template_field
2402
+									),
2403
+									__FILE__, __FUNCTION__, __LINE__
2404
+								);
2405
+							} else {
2406
+								$success = 1;
2407
+							}
2408
+						}
2409
+						$action_desc = 'updated';
2410
+					}
2411 2411
                     
2412
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2413
-                    $mtpg_fields = array(
2414
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2415
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2416
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2417
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2418
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2419
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2420
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2421
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2422
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2423
-                            : '',
2424
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2425
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2426
-                            : ''
2427
-                    );
2412
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2413
+					$mtpg_fields = array(
2414
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2415
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2416
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2417
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2418
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2419
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2420
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2421
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2422
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2423
+							: '',
2424
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2425
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2426
+							: ''
2427
+					);
2428 2428
                     
2429
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2430
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2429
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2430
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2431 2431
                     
2432
-                    if ($updated === false) {
2433
-                        EE_Error::add_error(
2434
-                            sprintf(
2435
-                                __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2436
-                                $set_column_values['GRP_ID']
2437
-                            ),
2438
-                            __FILE__, __FUNCTION__, __LINE__
2439
-                        );
2440
-                    } else {
2441
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2442
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2443
-                            ? $this->_req_data['MTP_template_pack']
2444
-                            : 'default';
2432
+					if ($updated === false) {
2433
+						EE_Error::add_error(
2434
+							sprintf(
2435
+								__('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2436
+								$set_column_values['GRP_ID']
2437
+							),
2438
+							__FILE__, __FUNCTION__, __LINE__
2439
+						);
2440
+					} else {
2441
+						//k now we need to ensure the template_pack and template_variation fields are set.
2442
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2443
+							? $this->_req_data['MTP_template_pack']
2444
+							: 'default';
2445 2445
                         
2446
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2447
-                            ? $this->_req_data['MTP_template_variation']
2448
-                            : 'default';
2446
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2447
+							? $this->_req_data['MTP_template_variation']
2448
+							: 'default';
2449 2449
                         
2450
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2451
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2452
-                            $mtpg_obj->set_template_pack_name($template_pack);
2453
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2454
-                        }
2455
-                        $success = 1;
2456
-                    }
2457
-                }
2458
-            }
2450
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2451
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2452
+							$mtpg_obj->set_template_pack_name($template_pack);
2453
+							$mtpg_obj->set_template_pack_variation($template_variation);
2454
+						}
2455
+						$success = 1;
2456
+					}
2457
+				}
2458
+			}
2459 2459
             
2460
-        }
2461
-        
2462
-        //we return things differently if doing ajax
2463
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2464
-            $this->_template_args['success'] = $success;
2465
-            $this->_template_args['error']   = ! $success ? true : false;
2466
-            $this->_template_args['content'] = '';
2467
-            $this->_template_args['data']    = array(
2468
-                'grpID'        => $edit_array['GRP_ID'],
2469
-                'templateName' => $edit_array['template_name']
2470
-            );
2471
-            if ($success) {
2472
-                EE_Error::overwrite_success();
2473
-                EE_Error::add_success(__('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.',
2474
-                    'event_espresso'));
2475
-            }
2460
+		}
2461
+        
2462
+		//we return things differently if doing ajax
2463
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2464
+			$this->_template_args['success'] = $success;
2465
+			$this->_template_args['error']   = ! $success ? true : false;
2466
+			$this->_template_args['content'] = '';
2467
+			$this->_template_args['data']    = array(
2468
+				'grpID'        => $edit_array['GRP_ID'],
2469
+				'templateName' => $edit_array['template_name']
2470
+			);
2471
+			if ($success) {
2472
+				EE_Error::overwrite_success();
2473
+				EE_Error::add_success(__('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.',
2474
+					'event_espresso'));
2475
+			}
2476 2476
             
2477
-            $this->_return_json();
2478
-        }
2479
-        
2480
-        
2481
-        //was a test send triggered?
2482
-        if (isset($this->_req_data['test_button'])) {
2483
-            EE_Error::overwrite_success();
2484
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2485
-            $override = true;
2486
-        }
2487
-        
2488
-        if (empty($query_args)) {
2489
-            $query_args = array(
2490
-                'id'      => $this->_req_data['GRP_ID'],
2491
-                'context' => $context_slug,
2492
-                'action'  => 'edit_message_template'
2493
-            );
2494
-        }
2495
-        
2496
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2497
-    }
2498
-    
2499
-    
2500
-    /**
2501
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2502
-     *
2503
-     * @param  string $context      what context being tested
2504
-     * @param  string $messenger    messenger being tested
2505
-     * @param  string $message_type message type being tested
2506
-     *
2507
-     */
2508
-    protected function _do_test_send($context, $messenger, $message_type)
2509
-    {
2510
-        //set things up for preview
2511
-        $this->_req_data['messenger']    = $messenger;
2512
-        $this->_req_data['message_type'] = $message_type;
2513
-        $this->_req_data['context']      = $context;
2514
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2515
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2516
-        
2517
-        //let's save any existing fields that might be required by the messenger
2518
-        if (
2519
-            isset($this->_req_data['test_settings_fld'])
2520
-            && $active_messenger instanceof EE_messenger
2521
-            && apply_filters(
2522
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2523
-                true,
2524
-                $this->_req_data['test_settings_fld'],
2525
-                $active_messenger
2526
-            )
2527
-        ) {
2528
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2529
-        }
2530
-        
2531
-        $success = $this->_preview_message(true);
2532
-        
2533
-        if ($success) {
2534
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2535
-        } else {
2536
-            EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2537
-                __LINE__);
2538
-        }
2539
-    }
2540
-    
2541
-    
2542
-    /**
2543
-     * _generate_new_templates
2544
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2545
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2546
-     * for the event.
2547
-     *
2548
-     *
2549
-     * @param  string $messenger     the messenger we are generating templates for
2550
-     * @param array   $message_types array of message types that the templates are generated for.
2551
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2552
-     *                               indicate the message_template_group being used as the base.
2553
-     *
2554
-     * @param bool    $global
2555
-     *
2556
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2557
-     *                               encountering problems.
2558
-     * @throws \EE_Error
2559
-     */
2560
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2561
-    {
2562
-        
2563
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2564
-        if (empty($message_types)) {
2565
-            return true;
2566
-        }
2567
-        
2568
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2569
-    }
2570
-    
2571
-    
2572
-    /**
2573
-     * [_trash_or_restore_message_template]
2574
-     *
2575
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2576
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2577
-     *                        an individual context (FALSE).
2578
-     *
2579
-     * @return void
2580
-     */
2581
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2582
-    {
2583
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2584
-        $MTP = EEM_Message_Template_Group::instance();
2585
-        
2586
-        $success = 1;
2587
-        
2588
-        //incoming GRP_IDs
2589
-        if ($all) {
2590
-            //Checkboxes
2591
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2592
-                //if array has more than one element then success message should be plural.
2593
-                //todo: what about nonce?
2594
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2477
+			$this->_return_json();
2478
+		}
2479
+        
2480
+        
2481
+		//was a test send triggered?
2482
+		if (isset($this->_req_data['test_button'])) {
2483
+			EE_Error::overwrite_success();
2484
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2485
+			$override = true;
2486
+		}
2487
+        
2488
+		if (empty($query_args)) {
2489
+			$query_args = array(
2490
+				'id'      => $this->_req_data['GRP_ID'],
2491
+				'context' => $context_slug,
2492
+				'action'  => 'edit_message_template'
2493
+			);
2494
+		}
2495
+        
2496
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2497
+	}
2498
+    
2499
+    
2500
+	/**
2501
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2502
+	 *
2503
+	 * @param  string $context      what context being tested
2504
+	 * @param  string $messenger    messenger being tested
2505
+	 * @param  string $message_type message type being tested
2506
+	 *
2507
+	 */
2508
+	protected function _do_test_send($context, $messenger, $message_type)
2509
+	{
2510
+		//set things up for preview
2511
+		$this->_req_data['messenger']    = $messenger;
2512
+		$this->_req_data['message_type'] = $message_type;
2513
+		$this->_req_data['context']      = $context;
2514
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2515
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2516
+        
2517
+		//let's save any existing fields that might be required by the messenger
2518
+		if (
2519
+			isset($this->_req_data['test_settings_fld'])
2520
+			&& $active_messenger instanceof EE_messenger
2521
+			&& apply_filters(
2522
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2523
+				true,
2524
+				$this->_req_data['test_settings_fld'],
2525
+				$active_messenger
2526
+			)
2527
+		) {
2528
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2529
+		}
2530
+        
2531
+		$success = $this->_preview_message(true);
2532
+        
2533
+		if ($success) {
2534
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2535
+		} else {
2536
+			EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2537
+				__LINE__);
2538
+		}
2539
+	}
2540
+    
2541
+    
2542
+	/**
2543
+	 * _generate_new_templates
2544
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2545
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2546
+	 * for the event.
2547
+	 *
2548
+	 *
2549
+	 * @param  string $messenger     the messenger we are generating templates for
2550
+	 * @param array   $message_types array of message types that the templates are generated for.
2551
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2552
+	 *                               indicate the message_template_group being used as the base.
2553
+	 *
2554
+	 * @param bool    $global
2555
+	 *
2556
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2557
+	 *                               encountering problems.
2558
+	 * @throws \EE_Error
2559
+	 */
2560
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2561
+	{
2562
+        
2563
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2564
+		if (empty($message_types)) {
2565
+			return true;
2566
+		}
2567
+        
2568
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2569
+	}
2570
+    
2571
+    
2572
+	/**
2573
+	 * [_trash_or_restore_message_template]
2574
+	 *
2575
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2576
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2577
+	 *                        an individual context (FALSE).
2578
+	 *
2579
+	 * @return void
2580
+	 */
2581
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2582
+	{
2583
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2584
+		$MTP = EEM_Message_Template_Group::instance();
2585
+        
2586
+		$success = 1;
2587
+        
2588
+		//incoming GRP_IDs
2589
+		if ($all) {
2590
+			//Checkboxes
2591
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2592
+				//if array has more than one element then success message should be plural.
2593
+				//todo: what about nonce?
2594
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2595 2595
                 
2596
-                //cycle through checkboxes
2597
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2598
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
-                    if ( ! $trashed_or_restored) {
2600
-                        $success = 0;
2601
-                    }
2602
-                }
2603
-            } else {
2604
-                //grab single GRP_ID and handle
2605
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2606
-                if ( ! empty($GRP_ID)) {
2607
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2608
-                    if ( ! $trashed_or_restored) {
2609
-                        $success = 0;
2610
-                    }
2611
-                } else {
2612
-                    $success = 0;
2613
-                }
2614
-            }
2596
+				//cycle through checkboxes
2597
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2598
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
+					if ( ! $trashed_or_restored) {
2600
+						$success = 0;
2601
+					}
2602
+				}
2603
+			} else {
2604
+				//grab single GRP_ID and handle
2605
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2606
+				if ( ! empty($GRP_ID)) {
2607
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2608
+					if ( ! $trashed_or_restored) {
2609
+						$success = 0;
2610
+					}
2611
+				} else {
2612
+					$success = 0;
2613
+				}
2614
+			}
2615 2615
             
2616
-        }
2616
+		}
2617 2617
         
2618
-        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2618
+		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2619 2619
         
2620
-        $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2620
+		$action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2621 2621
         
2622
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2623
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2622
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2623
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2624 2624
         
2625
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2626
-            'event_espresso') : $item_desc;
2625
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2626
+			'event_espresso') : $item_desc;
2627 2627
         
2628
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
2628
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
2629 2629
         
2630
-    }
2630
+	}
2631 2631
     
2632 2632
     
2633
-    /**
2634
-     * [_delete_message_template]
2635
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2636
-     * @return void
2637
-     */
2638
-    protected function _delete_message_template()
2639
-    {
2640
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2633
+	/**
2634
+	 * [_delete_message_template]
2635
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2636
+	 * @return void
2637
+	 */
2638
+	protected function _delete_message_template()
2639
+	{
2640
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2641 2641
         
2642
-        //checkboxes
2643
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2644
-            //if array has more than one element then success message should be plural
2645
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2642
+		//checkboxes
2643
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2644
+			//if array has more than one element then success message should be plural
2645
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2646 2646
             
2647
-            //cycle through bulk action checkboxes
2648
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2649
-                $success = $this->_delete_mtp_permanently($GRP_ID);
2650
-            }
2651
-        } else {
2652
-            //grab single grp_id and delete
2653
-            $GRP_ID  = absint($this->_req_data['id']);
2654
-            $success = $this->_delete_mtp_permanently($GRP_ID);
2655
-        }
2656
-        
2657
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2658
-        
2659
-    }
2660
-    
2661
-    
2662
-    /**
2663
-     * helper for permanently deleting a mtP group and all related message_templates
2664
-     *
2665
-     * @param  int  $GRP_ID        The group being deleted
2666
-     * @param  bool $include_group whether to delete the Message Template Group as well.
2667
-     *
2668
-     * @return bool        boolean to indicate the success of the deletes or not.
2669
-     */
2670
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2671
-    {
2672
-        $success = 1;
2673
-        $MTPG    = EEM_Message_Template_Group::instance();
2674
-        //first let's GET this group
2675
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
2676
-        //then delete permanently all the related Message Templates
2677
-        $deleted = $MTG->delete_related_permanently('Message_Template');
2678
-        
2679
-        if ($deleted === 0) {
2680
-            $success = 0;
2681
-        }
2682
-        
2683
-        //now delete permanently this particular group
2684
-        
2685
-        if ($include_group && ! $MTG->delete_permanently()) {
2686
-            $success = 0;
2687
-        }
2688
-        
2689
-        return $success;
2690
-    }
2691
-    
2692
-    
2693
-    /**
2694
-     *    _learn_more_about_message_templates_link
2695
-     * @access protected
2696
-     * @return string
2697
-     */
2698
-    protected function _learn_more_about_message_templates_link()
2699
-    {
2700
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2701
-            'event_espresso') . '</a>';
2702
-    }
2703
-    
2704
-    
2705
-    /**
2706
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2707
-     * ajax and other routes.
2708
-     * @return void
2709
-     */
2710
-    protected function _settings()
2711
-    {
2712
-        
2713
-        
2714
-        $this->_set_m_mt_settings();
2715
-        
2716
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2717
-        
2718
-        //let's setup the messenger tabs
2719
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2720
-            'messenger_links', '|', $selected_messenger);
2721
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2722
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2723
-        
2724
-        $this->display_admin_page_with_sidebar();
2725
-        
2726
-    }
2727
-    
2728
-    
2729
-    /**
2730
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2731
-     *
2732
-     * @access protected
2733
-     * @return void
2734
-     */
2735
-    protected function _set_m_mt_settings()
2736
-    {
2737
-        //first if this is already set then lets get out no need to regenerate data.
2738
-        if ( ! empty($this->_m_mt_settings)) {
2739
-            return;
2740
-        }
2741
-        
2742
-        //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2743
-        
2744
-        //get all installed messengers and message_types
2745
-        /** @type EE_messenger[] $messengers */
2746
-        $messengers = $this->_message_resource_manager->installed_messengers();
2747
-        /** @type EE_message_type[] $message_types */
2748
-        $message_types = $this->_message_resource_manager->installed_message_types();
2749
-        
2750
-        
2751
-        //assemble the array for the _tab_text_links helper
2752
-        
2753
-        foreach ($messengers as $messenger) {
2754
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2755
-                'label' => ucwords($messenger->label['singular']),
2756
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2757
-                'href'  => $messenger->name,
2758
-                'title' => __('Modify this Messenger', 'event_espresso'),
2759
-                'slug'  => $messenger->name,
2760
-                'obj'   => $messenger
2761
-            );
2647
+			//cycle through bulk action checkboxes
2648
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2649
+				$success = $this->_delete_mtp_permanently($GRP_ID);
2650
+			}
2651
+		} else {
2652
+			//grab single grp_id and delete
2653
+			$GRP_ID  = absint($this->_req_data['id']);
2654
+			$success = $this->_delete_mtp_permanently($GRP_ID);
2655
+		}
2656
+        
2657
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2658
+        
2659
+	}
2660
+    
2661
+    
2662
+	/**
2663
+	 * helper for permanently deleting a mtP group and all related message_templates
2664
+	 *
2665
+	 * @param  int  $GRP_ID        The group being deleted
2666
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
2667
+	 *
2668
+	 * @return bool        boolean to indicate the success of the deletes or not.
2669
+	 */
2670
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2671
+	{
2672
+		$success = 1;
2673
+		$MTPG    = EEM_Message_Template_Group::instance();
2674
+		//first let's GET this group
2675
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
2676
+		//then delete permanently all the related Message Templates
2677
+		$deleted = $MTG->delete_related_permanently('Message_Template');
2678
+        
2679
+		if ($deleted === 0) {
2680
+			$success = 0;
2681
+		}
2682
+        
2683
+		//now delete permanently this particular group
2684
+        
2685
+		if ($include_group && ! $MTG->delete_permanently()) {
2686
+			$success = 0;
2687
+		}
2688
+        
2689
+		return $success;
2690
+	}
2691
+    
2692
+    
2693
+	/**
2694
+	 *    _learn_more_about_message_templates_link
2695
+	 * @access protected
2696
+	 * @return string
2697
+	 */
2698
+	protected function _learn_more_about_message_templates_link()
2699
+	{
2700
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2701
+			'event_espresso') . '</a>';
2702
+	}
2703
+    
2704
+    
2705
+	/**
2706
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2707
+	 * ajax and other routes.
2708
+	 * @return void
2709
+	 */
2710
+	protected function _settings()
2711
+	{
2712
+        
2713
+        
2714
+		$this->_set_m_mt_settings();
2715
+        
2716
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2717
+        
2718
+		//let's setup the messenger tabs
2719
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2720
+			'messenger_links', '|', $selected_messenger);
2721
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2722
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2723
+        
2724
+		$this->display_admin_page_with_sidebar();
2725
+        
2726
+	}
2727
+    
2728
+    
2729
+	/**
2730
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2731
+	 *
2732
+	 * @access protected
2733
+	 * @return void
2734
+	 */
2735
+	protected function _set_m_mt_settings()
2736
+	{
2737
+		//first if this is already set then lets get out no need to regenerate data.
2738
+		if ( ! empty($this->_m_mt_settings)) {
2739
+			return;
2740
+		}
2741
+        
2742
+		//$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2743
+        
2744
+		//get all installed messengers and message_types
2745
+		/** @type EE_messenger[] $messengers */
2746
+		$messengers = $this->_message_resource_manager->installed_messengers();
2747
+		/** @type EE_message_type[] $message_types */
2748
+		$message_types = $this->_message_resource_manager->installed_message_types();
2749
+        
2750
+        
2751
+		//assemble the array for the _tab_text_links helper
2752
+        
2753
+		foreach ($messengers as $messenger) {
2754
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2755
+				'label' => ucwords($messenger->label['singular']),
2756
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2757
+				'href'  => $messenger->name,
2758
+				'title' => __('Modify this Messenger', 'event_espresso'),
2759
+				'slug'  => $messenger->name,
2760
+				'obj'   => $messenger
2761
+			);
2762 2762
             
2763 2763
             
2764
-            $message_types_for_messenger = $messenger->get_valid_message_types();
2764
+			$message_types_for_messenger = $messenger->get_valid_message_types();
2765 2765
             
2766
-            foreach ($message_types as $message_type) {
2767
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2768
-                if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2769
-                    continue;
2770
-                }
2766
+			foreach ($message_types as $message_type) {
2767
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2768
+				if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2769
+					continue;
2770
+				}
2771 2771
                 
2772
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2773
-                    $message_type->name) ? 'active' : 'inactive';
2772
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2773
+					$message_type->name) ? 'active' : 'inactive';
2774 2774
                 
2775
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2776
-                    'label'    => ucwords($message_type->label['singular']),
2777
-                    'class'    => 'message-type-' . $a_or_i,
2778
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2779
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2780
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2781
-                    'title'    => $a_or_i == 'active'
2782
-                        ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2783
-                        : __('Drag this message type to the messenger to activate', 'event_espresso'),
2784
-                    'content'  => $a_or_i == 'active'
2785
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
2786
-                        : $this->_message_type_settings_content($message_type, $messenger),
2787
-                    'slug'     => $message_type->name,
2788
-                    'active'   => $a_or_i == 'active' ? true : false,
2789
-                    'obj'      => $message_type
2790
-                );
2791
-            }
2792
-        }
2793
-    }
2794
-    
2795
-    
2796
-    /**
2797
-     * This just prepares the content for the message type settings
2798
-     *
2799
-     * @param  object  $message_type The message type object
2800
-     * @param  object  $messenger    The messenger object
2801
-     * @param  boolean $active       Whether the message type is active or not
2802
-     *
2803
-     * @return string                html output for the content
2804
-     */
2805
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
2806
-    {
2807
-        //get message type fields
2808
-        $fields                                         = $message_type->get_admin_settings_fields();
2809
-        $settings_template_args['template_form_fields'] = '';
2810
-        
2811
-        if ( ! empty($fields) && $active) {
2775
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2776
+					'label'    => ucwords($message_type->label['singular']),
2777
+					'class'    => 'message-type-' . $a_or_i,
2778
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2779
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2780
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2781
+					'title'    => $a_or_i == 'active'
2782
+						? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2783
+						: __('Drag this message type to the messenger to activate', 'event_espresso'),
2784
+					'content'  => $a_or_i == 'active'
2785
+						? $this->_message_type_settings_content($message_type, $messenger, true)
2786
+						: $this->_message_type_settings_content($message_type, $messenger),
2787
+					'slug'     => $message_type->name,
2788
+					'active'   => $a_or_i == 'active' ? true : false,
2789
+					'obj'      => $message_type
2790
+				);
2791
+			}
2792
+		}
2793
+	}
2794
+    
2795
+    
2796
+	/**
2797
+	 * This just prepares the content for the message type settings
2798
+	 *
2799
+	 * @param  object  $message_type The message type object
2800
+	 * @param  object  $messenger    The messenger object
2801
+	 * @param  boolean $active       Whether the message type is active or not
2802
+	 *
2803
+	 * @return string                html output for the content
2804
+	 */
2805
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
2806
+	{
2807
+		//get message type fields
2808
+		$fields                                         = $message_type->get_admin_settings_fields();
2809
+		$settings_template_args['template_form_fields'] = '';
2810
+        
2811
+		if ( ! empty($fields) && $active) {
2812 2812
             
2813
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2813
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2814 2814
             
2815
-            foreach ($fields as $fldname => $fldprops) {
2816
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2817
-                $template_form_field[$field_id] = array(
2818
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2819
-                    'label'      => $fldprops['label'],
2820
-                    'input'      => $fldprops['field_type'],
2821
-                    'type'       => $fldprops['value_type'],
2822
-                    'required'   => $fldprops['required'],
2823
-                    'validation' => $fldprops['validation'],
2824
-                    'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2825
-                    'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2826
-                    'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2827
-                    'css_class'  => 'no-drag',
2828
-                    'format'     => $fldprops['format']
2829
-                );
2830
-            }
2815
+			foreach ($fields as $fldname => $fldprops) {
2816
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2817
+				$template_form_field[$field_id] = array(
2818
+					'name'       => 'message_type_settings[' . $fldname . ']',
2819
+					'label'      => $fldprops['label'],
2820
+					'input'      => $fldprops['field_type'],
2821
+					'type'       => $fldprops['value_type'],
2822
+					'required'   => $fldprops['required'],
2823
+					'validation' => $fldprops['validation'],
2824
+					'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2825
+					'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2826
+					'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2827
+					'css_class'  => 'no-drag',
2828
+					'format'     => $fldprops['format']
2829
+				);
2830
+			}
2831 2831
             
2832 2832
             
2833
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2834
-                'string', 'ee_mt_activate_form') : '';
2835
-        }
2836
-        
2837
-        $settings_template_args['description'] = $message_type->description;
2838
-        //we also need some hidden fields
2839
-        $settings_template_args['hidden_fields'] = array(
2840
-            'message_type_settings[messenger]'    => array(
2841
-                'type'  => 'hidden',
2842
-                'value' => $messenger->name
2843
-            ),
2844
-            'message_type_settings[message_type]' => array(
2845
-                'type'  => 'hidden',
2846
-                'value' => $message_type->name
2847
-            ),
2848
-            'type'                                => array(
2849
-                'type'  => 'hidden',
2850
-                'value' => 'message_type'
2851
-            )
2852
-        );
2853
-        
2854
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2855
-            'array');
2856
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2857
-        
2858
-        
2859
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2860
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
2861
-        
2862
-        return $content;
2863
-    }
2864
-    
2865
-    
2866
-    /**
2867
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
2868
-     *
2869
-     * @access protected
2870
-     * @return void
2871
-     */
2872
-    protected function _messages_settings_metaboxes()
2873
-    {
2874
-        $this->_set_m_mt_settings();
2875
-        $m_boxes         = $mt_boxes = array();
2876
-        $m_template_args = $mt_template_args = array();
2877
-        
2878
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2879
-        
2880
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
2881
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2882
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2883
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2884
-                //messenger meta boxes
2885
-                $active                                 = $selected_messenger == $messenger ? true : false;
2886
-                $active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2887
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2888
-                    : '';
2889
-                $m_boxes[$messenger . '_a_box']         = sprintf(
2890
-                    __('%s Settings', 'event_espresso'),
2891
-                    $tab_array['label']
2892
-                );
2893
-                $m_template_args[$messenger . '_a_box'] = array(
2894
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2895
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2896
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2897
-                        : '',
2898
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2899
-                    'hidden'                 => $active ? '' : ' hidden',
2900
-                    'hide_on_message'        => $hide_on_message,
2901
-                    'messenger'              => $messenger,
2902
-                    'active'                 => $active
2903
-                );
2904
-                // message type meta boxes
2905
-                // (which is really just the inactive container for each messenger
2906
-                // showing inactive message types for that messenger)
2907
-                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2908
-                $mt_template_args[$messenger . '_i_box'] = array(
2909
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2910
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2911
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2912
-                        : '',
2913
-                    'hidden'                 => $active ? '' : ' hidden',
2914
-                    'hide_on_message'        => $hide_on_message,
2915
-                    'hide_off_message'       => $hide_off_message,
2916
-                    'messenger'              => $messenger,
2917
-                    'active'                 => $active
2918
-                );
2919
-            }
2920
-        }
2921
-        
2922
-        
2923
-        //register messenger metaboxes
2924
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2925
-        foreach ($m_boxes as $box => $label) {
2926
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2927
-            $msgr          = str_replace('_a_box', '', $box);
2928
-            add_meta_box(
2929
-                'espresso_' . $msgr . '_settings',
2930
-                $label,
2931
-                function ($post, $metabox) {
2932
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2933
-                        $metabox["args"]["template_args"], true);
2934
-                },
2935
-                $this->_current_screen->id,
2936
-                'normal',
2937
-                'high',
2938
-                $callback_args
2939
-            );
2940
-        }
2941
-        
2942
-        //register message type metaboxes
2943
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2944
-        foreach ($mt_boxes as $box => $label) {
2945
-            $callback_args = array(
2946
-                'template_path' => $mt_template_path,
2947
-                'template_args' => $mt_template_args[$box]
2948
-            );
2949
-            $mt            = str_replace('_i_box', '', $box);
2950
-            add_meta_box(
2951
-                'espresso_' . $mt . '_inactive_mts',
2952
-                $label,
2953
-                function ($post, $metabox) {
2954
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2955
-                        $metabox["args"]["template_args"], true);
2956
-                },
2957
-                $this->_current_screen->id,
2958
-                'side',
2959
-                'high',
2960
-                $callback_args
2961
-            );
2962
-        }
2963
-        
2964
-        //register metabox for global messages settings but only when on the main site.  On single site installs this will
2965
-        //always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2966
-        if (is_main_site()) {
2967
-            add_meta_box(
2968
-                'espresso_global_message_settings',
2969
-                __('Global Message Settings', 'event_espresso'),
2970
-                array($this, 'global_messages_settings_metabox_content'),
2971
-                $this->_current_screen->id,
2972
-                'normal',
2973
-                'low',
2974
-                array()
2975
-            );
2976
-        }
2977
-        
2978
-    }
2979
-    
2980
-    
2981
-    /**
2982
-     *  This generates the content for the global messages settings metabox.
2983
-     * @return string
2984
-     */
2985
-    public function global_messages_settings_metabox_content()
2986
-    {
2987
-        $form = $this->_generate_global_settings_form();
2988
-        echo $form->form_open(
2989
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2990
-                'POST'
2991
-            )
2992
-             . $form->get_html()
2993
-             . $form->form_close();
2994
-    }
2995
-    
2996
-    
2997
-    /**
2998
-     * This generates and returns the form object for the global messages settings.
2999
-     * @return EE_Form_Section_Proper
3000
-     */
3001
-    protected function _generate_global_settings_form()
3002
-    {
3003
-        EE_Registry::instance()->load_helper('HTML');
3004
-        /** @var EE_Network_Core_Config $network_config */
3005
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3006
-        
3007
-        return new EE_Form_Section_Proper(
3008
-            array(
3009
-                'name'            => 'global_messages_settings',
3010
-                'html_id'         => 'global_messages_settings',
3011
-                'html_class'      => 'form-table',
3012
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3013
-                'subsections'     => apply_filters(
3014
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3015
-                    array(
3016
-                        'do_messages_on_same_request' => new EE_Select_Input(
3017
-                            array(
3018
-                                true  => esc_html__("On the same request", "event_espresso"),
3019
-                                false => esc_html__("On a separate request", "event_espresso")
3020
-                            ),
3021
-                            array(
3022
-                                'default'         => $network_config->do_messages_on_same_request,
3023
-                                'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'),
3024
-                                'html_help_text'  => esc_html__('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.',
3025
-                                    'event_espresso'),
3026
-                            )
3027
-                        ),
3028
-                        'delete_threshold' => new EE_Select_Input(
3029
-                            array(
3030
-                                0 => esc_html__('Forever', 'event_espresso'),
3031
-                                3 => esc_html__('3 Months', 'event_espresso'),
3032
-                                6 => esc_html__('6 Months', 'event_espresso'),
3033
-                                9 => esc_html__('9 Months', 'event_espresso'),
3034
-                                12 => esc_html__('12 Months', 'event_espresso'),
3035
-                                24 => esc_html__('24 Months', 'event_espresso'),
3036
-                                36 => esc_html__('36 Months', 'event_espresso')
3037
-                            ),
3038
-                            array(
3039
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3040
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3041
-                                'html_help_text' => esc_html__('You can control how long a record of processed messages is kept 
2833
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2834
+				'string', 'ee_mt_activate_form') : '';
2835
+		}
2836
+        
2837
+		$settings_template_args['description'] = $message_type->description;
2838
+		//we also need some hidden fields
2839
+		$settings_template_args['hidden_fields'] = array(
2840
+			'message_type_settings[messenger]'    => array(
2841
+				'type'  => 'hidden',
2842
+				'value' => $messenger->name
2843
+			),
2844
+			'message_type_settings[message_type]' => array(
2845
+				'type'  => 'hidden',
2846
+				'value' => $message_type->name
2847
+			),
2848
+			'type'                                => array(
2849
+				'type'  => 'hidden',
2850
+				'value' => 'message_type'
2851
+			)
2852
+		);
2853
+        
2854
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2855
+			'array');
2856
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2857
+        
2858
+        
2859
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2860
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
2861
+        
2862
+		return $content;
2863
+	}
2864
+    
2865
+    
2866
+	/**
2867
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
2868
+	 *
2869
+	 * @access protected
2870
+	 * @return void
2871
+	 */
2872
+	protected function _messages_settings_metaboxes()
2873
+	{
2874
+		$this->_set_m_mt_settings();
2875
+		$m_boxes         = $mt_boxes = array();
2876
+		$m_template_args = $mt_template_args = array();
2877
+        
2878
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2879
+        
2880
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
2881
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2882
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2883
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2884
+				//messenger meta boxes
2885
+				$active                                 = $selected_messenger == $messenger ? true : false;
2886
+				$active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2887
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2888
+					: '';
2889
+				$m_boxes[$messenger . '_a_box']         = sprintf(
2890
+					__('%s Settings', 'event_espresso'),
2891
+					$tab_array['label']
2892
+				);
2893
+				$m_template_args[$messenger . '_a_box'] = array(
2894
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2895
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2896
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2897
+						: '',
2898
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2899
+					'hidden'                 => $active ? '' : ' hidden',
2900
+					'hide_on_message'        => $hide_on_message,
2901
+					'messenger'              => $messenger,
2902
+					'active'                 => $active
2903
+				);
2904
+				// message type meta boxes
2905
+				// (which is really just the inactive container for each messenger
2906
+				// showing inactive message types for that messenger)
2907
+				$mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2908
+				$mt_template_args[$messenger . '_i_box'] = array(
2909
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2910
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2911
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2912
+						: '',
2913
+					'hidden'                 => $active ? '' : ' hidden',
2914
+					'hide_on_message'        => $hide_on_message,
2915
+					'hide_off_message'       => $hide_off_message,
2916
+					'messenger'              => $messenger,
2917
+					'active'                 => $active
2918
+				);
2919
+			}
2920
+		}
2921
+        
2922
+        
2923
+		//register messenger metaboxes
2924
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2925
+		foreach ($m_boxes as $box => $label) {
2926
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2927
+			$msgr          = str_replace('_a_box', '', $box);
2928
+			add_meta_box(
2929
+				'espresso_' . $msgr . '_settings',
2930
+				$label,
2931
+				function ($post, $metabox) {
2932
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2933
+						$metabox["args"]["template_args"], true);
2934
+				},
2935
+				$this->_current_screen->id,
2936
+				'normal',
2937
+				'high',
2938
+				$callback_args
2939
+			);
2940
+		}
2941
+        
2942
+		//register message type metaboxes
2943
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2944
+		foreach ($mt_boxes as $box => $label) {
2945
+			$callback_args = array(
2946
+				'template_path' => $mt_template_path,
2947
+				'template_args' => $mt_template_args[$box]
2948
+			);
2949
+			$mt            = str_replace('_i_box', '', $box);
2950
+			add_meta_box(
2951
+				'espresso_' . $mt . '_inactive_mts',
2952
+				$label,
2953
+				function ($post, $metabox) {
2954
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2955
+						$metabox["args"]["template_args"], true);
2956
+				},
2957
+				$this->_current_screen->id,
2958
+				'side',
2959
+				'high',
2960
+				$callback_args
2961
+			);
2962
+		}
2963
+        
2964
+		//register metabox for global messages settings but only when on the main site.  On single site installs this will
2965
+		//always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2966
+		if (is_main_site()) {
2967
+			add_meta_box(
2968
+				'espresso_global_message_settings',
2969
+				__('Global Message Settings', 'event_espresso'),
2970
+				array($this, 'global_messages_settings_metabox_content'),
2971
+				$this->_current_screen->id,
2972
+				'normal',
2973
+				'low',
2974
+				array()
2975
+			);
2976
+		}
2977
+        
2978
+	}
2979
+    
2980
+    
2981
+	/**
2982
+	 *  This generates the content for the global messages settings metabox.
2983
+	 * @return string
2984
+	 */
2985
+	public function global_messages_settings_metabox_content()
2986
+	{
2987
+		$form = $this->_generate_global_settings_form();
2988
+		echo $form->form_open(
2989
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2990
+				'POST'
2991
+			)
2992
+			 . $form->get_html()
2993
+			 . $form->form_close();
2994
+	}
2995
+    
2996
+    
2997
+	/**
2998
+	 * This generates and returns the form object for the global messages settings.
2999
+	 * @return EE_Form_Section_Proper
3000
+	 */
3001
+	protected function _generate_global_settings_form()
3002
+	{
3003
+		EE_Registry::instance()->load_helper('HTML');
3004
+		/** @var EE_Network_Core_Config $network_config */
3005
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3006
+        
3007
+		return new EE_Form_Section_Proper(
3008
+			array(
3009
+				'name'            => 'global_messages_settings',
3010
+				'html_id'         => 'global_messages_settings',
3011
+				'html_class'      => 'form-table',
3012
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3013
+				'subsections'     => apply_filters(
3014
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3015
+					array(
3016
+						'do_messages_on_same_request' => new EE_Select_Input(
3017
+							array(
3018
+								true  => esc_html__("On the same request", "event_espresso"),
3019
+								false => esc_html__("On a separate request", "event_espresso")
3020
+							),
3021
+							array(
3022
+								'default'         => $network_config->do_messages_on_same_request,
3023
+								'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'),
3024
+								'html_help_text'  => esc_html__('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.',
3025
+									'event_espresso'),
3026
+							)
3027
+						),
3028
+						'delete_threshold' => new EE_Select_Input(
3029
+							array(
3030
+								0 => esc_html__('Forever', 'event_espresso'),
3031
+								3 => esc_html__('3 Months', 'event_espresso'),
3032
+								6 => esc_html__('6 Months', 'event_espresso'),
3033
+								9 => esc_html__('9 Months', 'event_espresso'),
3034
+								12 => esc_html__('12 Months', 'event_espresso'),
3035
+								24 => esc_html__('24 Months', 'event_espresso'),
3036
+								36 => esc_html__('36 Months', 'event_espresso')
3037
+							),
3038
+							array(
3039
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3040
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3041
+								'html_help_text' => esc_html__('You can control how long a record of processed messages is kept 
3042 3042
                                                     via this option.', 'event_espresso'),
3043
-                            )
3044
-                        ),
3045
-                        'update_settings'             => new EE_Submit_Input(
3046
-                            array(
3047
-                                'default'         => esc_html__('Update', 'event_espresso'),
3048
-                                'html_label_text' => '&nbsp'
3049
-                            )
3050
-                        )
3051
-                    )
3052
-                )
3053
-            )
3054
-        );
3055
-    }
3056
-    
3057
-    
3058
-    /**
3059
-     * This handles updating the global settings set on the admin page.
3060
-     * @throws \EE_Error
3061
-     */
3062
-    protected function _update_global_settings()
3063
-    {
3064
-        /** @var EE_Network_Core_Config $network_config */
3065
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3066
-        $messages_config = EE_Registry::instance()->CFG->messages;
3067
-        $form           = $this->_generate_global_settings_form();
3068
-        if ($form->was_submitted()) {
3069
-            $form->receive_form_submission();
3070
-            if ($form->is_valid()) {
3071
-                $valid_data = $form->valid_data();
3072
-                foreach ($valid_data as $property => $value) {
3073
-                    $setter = 'set_' . $property;
3074
-                    if (method_exists($network_config, $setter)) {
3075
-                        $network_config->{$setter}($value);
3076
-                    } else if (
3077
-                        property_exists($network_config, $property)
3078
-                        && $network_config->{$property} !== $value
3079
-                    ) {
3080
-                        $network_config->{$property} = $value;
3081
-                    } else if (
3082
-                        property_exists($messages_config, $property)
3083
-                        && $messages_config->{$property} !== $value
3084
-                    ) {
3085
-                        $messages_config->{$property} = $value;
3086
-                    }
3087
-                }
3088
-                //only update if the form submission was valid!
3089
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3090
-                EE_Registry::instance()->CFG->update_espresso_config();
3091
-                EE_Error::overwrite_success();
3092
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3093
-            }
3094
-        }
3095
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3096
-    }
3097
-    
3098
-    
3099
-    /**
3100
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3101
-     *
3102
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3103
-     *
3104
-     * @return string            html formatted tabs
3105
-     */
3106
-    protected function _get_mt_tabs($tab_array)
3107
-    {
3108
-        $tab_array = (array)$tab_array;
3109
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3110
-        $tabs      = '';
3111
-        
3112
-        foreach ($tab_array as $tab) {
3113
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3114
-        }
3115
-        
3116
-        return $tabs;
3117
-    }
3118
-    
3119
-    
3120
-    /**
3121
-     * This prepares the content of the messenger meta box admin settings
3122
-     *
3123
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3124
-     *
3125
-     * @return string            html formatted content
3126
-     */
3127
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3128
-    {
3129
-        
3130
-        $fields                                         = $messenger->get_admin_settings_fields();
3131
-        $settings_template_args['template_form_fields'] = '';
3132
-        
3133
-        //is $messenger active?
3134
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3135
-        
3136
-        
3137
-        if ( ! empty($fields)) {
3043
+							)
3044
+						),
3045
+						'update_settings'             => new EE_Submit_Input(
3046
+							array(
3047
+								'default'         => esc_html__('Update', 'event_espresso'),
3048
+								'html_label_text' => '&nbsp'
3049
+							)
3050
+						)
3051
+					)
3052
+				)
3053
+			)
3054
+		);
3055
+	}
3056
+    
3057
+    
3058
+	/**
3059
+	 * This handles updating the global settings set on the admin page.
3060
+	 * @throws \EE_Error
3061
+	 */
3062
+	protected function _update_global_settings()
3063
+	{
3064
+		/** @var EE_Network_Core_Config $network_config */
3065
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3066
+		$messages_config = EE_Registry::instance()->CFG->messages;
3067
+		$form           = $this->_generate_global_settings_form();
3068
+		if ($form->was_submitted()) {
3069
+			$form->receive_form_submission();
3070
+			if ($form->is_valid()) {
3071
+				$valid_data = $form->valid_data();
3072
+				foreach ($valid_data as $property => $value) {
3073
+					$setter = 'set_' . $property;
3074
+					if (method_exists($network_config, $setter)) {
3075
+						$network_config->{$setter}($value);
3076
+					} else if (
3077
+						property_exists($network_config, $property)
3078
+						&& $network_config->{$property} !== $value
3079
+					) {
3080
+						$network_config->{$property} = $value;
3081
+					} else if (
3082
+						property_exists($messages_config, $property)
3083
+						&& $messages_config->{$property} !== $value
3084
+					) {
3085
+						$messages_config->{$property} = $value;
3086
+					}
3087
+				}
3088
+				//only update if the form submission was valid!
3089
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3090
+				EE_Registry::instance()->CFG->update_espresso_config();
3091
+				EE_Error::overwrite_success();
3092
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3093
+			}
3094
+		}
3095
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3096
+	}
3097
+    
3098
+    
3099
+	/**
3100
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3101
+	 *
3102
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3103
+	 *
3104
+	 * @return string            html formatted tabs
3105
+	 */
3106
+	protected function _get_mt_tabs($tab_array)
3107
+	{
3108
+		$tab_array = (array)$tab_array;
3109
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3110
+		$tabs      = '';
3111
+        
3112
+		foreach ($tab_array as $tab) {
3113
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3114
+		}
3115
+        
3116
+		return $tabs;
3117
+	}
3118
+    
3119
+    
3120
+	/**
3121
+	 * This prepares the content of the messenger meta box admin settings
3122
+	 *
3123
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3124
+	 *
3125
+	 * @return string            html formatted content
3126
+	 */
3127
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3128
+	{
3129
+        
3130
+		$fields                                         = $messenger->get_admin_settings_fields();
3131
+		$settings_template_args['template_form_fields'] = '';
3132
+        
3133
+		//is $messenger active?
3134
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3135
+        
3136
+        
3137
+		if ( ! empty($fields)) {
3138 3138
             
3139
-            $existing_settings = $messenger->get_existing_admin_settings();
3139
+			$existing_settings = $messenger->get_existing_admin_settings();
3140 3140
             
3141
-            foreach ($fields as $fldname => $fldprops) {
3142
-                $field_id                       = $messenger->name . '-' . $fldname;
3143
-                $template_form_field[$field_id] = array(
3144
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3145
-                    'label'      => $fldprops['label'],
3146
-                    'input'      => $fldprops['field_type'],
3147
-                    'type'       => $fldprops['value_type'],
3148
-                    'required'   => $fldprops['required'],
3149
-                    'validation' => $fldprops['validation'],
3150
-                    'value'      => isset($existing_settings[$field_id])
3151
-                        ? $existing_settings[$field_id]
3152
-                        : $fldprops['default'],
3153
-                    'css_class'  => '',
3154
-                    'format'     => $fldprops['format']
3155
-                );
3156
-            }
3141
+			foreach ($fields as $fldname => $fldprops) {
3142
+				$field_id                       = $messenger->name . '-' . $fldname;
3143
+				$template_form_field[$field_id] = array(
3144
+					'name'       => 'messenger_settings[' . $field_id . ']',
3145
+					'label'      => $fldprops['label'],
3146
+					'input'      => $fldprops['field_type'],
3147
+					'type'       => $fldprops['value_type'],
3148
+					'required'   => $fldprops['required'],
3149
+					'validation' => $fldprops['validation'],
3150
+					'value'      => isset($existing_settings[$field_id])
3151
+						? $existing_settings[$field_id]
3152
+						: $fldprops['default'],
3153
+					'css_class'  => '',
3154
+					'format'     => $fldprops['format']
3155
+				);
3156
+			}
3157 3157
             
3158 3158
             
3159
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3160
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3161
-                : '';
3162
-        }
3163
-        
3164
-        //we also need some hidden fields
3165
-        $settings_template_args['hidden_fields'] = array(
3166
-            'messenger_settings[messenger]' => array(
3167
-                'type'  => 'hidden',
3168
-                'value' => $messenger->name
3169
-            ),
3170
-            'type'                          => array(
3171
-                'type'  => 'hidden',
3172
-                'value' => 'messenger'
3173
-            )
3174
-        );
3175
-        
3176
-        //make sure any active message types that are existing are included in the hidden fields
3177
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3178
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3179
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3180
-                    'type'  => 'hidden',
3181
-                    'value' => $mt
3182
-                );
3183
-            }
3184
-        }
3185
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3186
-            $settings_template_args['hidden_fields'],
3187
-            'array'
3188
-        );
3189
-        $active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3190
-        
3191
-        $settings_template_args['messenger']           = $messenger->name;
3192
-        $settings_template_args['description']         = $messenger->description;
3193
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3194
-        
3195
-        
3196
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3197
-            ? $settings_template_args['show_hide_edit_form']
3198
-            : ' hidden';
3199
-        
3200
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3201
-            ? ' hidden'
3202
-            : $settings_template_args['show_hide_edit_form'];
3203
-        
3204
-        
3205
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3206
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3207
-        $settings_template_args['on_off_status'] = $active ? true : false;
3208
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3209
-        $content                                 = EEH_Template::display_template($template, $settings_template_args,
3210
-            true);
3211
-        
3212
-        return $content;
3213
-    }
3214
-    
3215
-    
3216
-    /**
3217
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3218
-     */
3219
-    public function activate_messenger_toggle()
3220
-    {
3221
-        $success = true;
3222
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3223
-        //let's check that we have required data
3224
-        if ( ! isset($this->_req_data['messenger'])) {
3225
-            EE_Error::add_error(
3226
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3227
-                __FILE__,
3228
-                __FUNCTION__,
3229
-                __LINE__
3230
-            );
3231
-            $success = false;
3232
-        }
3233
-        
3234
-        //do a nonce check here since we're not arriving via a normal route
3235
-        $nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3236
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3237
-        
3238
-        $this->_verify_nonce($nonce, $nonce_ref);
3239
-        
3240
-        
3241
-        if ( ! isset($this->_req_data['status'])) {
3242
-            EE_Error::add_error(
3243
-                __(
3244
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3245
-                    'event_espresso'
3246
-                ),
3247
-                __FILE__,
3248
-                __FUNCTION__,
3249
-                __LINE__
3250
-            );
3251
-            $success = false;
3252
-        }
3253
-        
3254
-        //do check to verify we have a valid status.
3255
-        $status = $this->_req_data['status'];
3256
-        
3257
-        if ($status != 'off' && $status != 'on') {
3258
-            EE_Error::add_error(
3259
-                sprintf(
3260
-                    __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3261
-                    $this->_req_data['status']
3262
-                ),
3263
-                __FILE__,
3264
-                __FUNCTION__,
3265
-                __LINE__
3266
-            );
3267
-            $success = false;
3268
-        }
3269
-        
3270
-        if ($success) {
3271
-            //made it here?  Stop dawdling then!!
3272
-            $success = $status == 'off'
3273
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3274
-                : $this->_activate_messenger($this->_req_data['messenger']);
3275
-        }
3276
-        
3277
-        $this->_template_args['success'] = $success;
3278
-        
3279
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3280
-        $this->_return_json();
3281
-        
3282
-    }
3283
-    
3284
-    
3285
-    /**
3286
-     * used by ajax from the messages settings page to activate|deactivate a message type
3287
-     *
3288
-     */
3289
-    public function activate_mt_toggle()
3290
-    {
3291
-        $success = true;
3292
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3293
-        
3294
-        //let's make sure we have the necessary data
3295
-        if ( ! isset($this->_req_data['message_type'])) {
3296
-            EE_Error::add_error(
3297
-                __('Message Type name needed to toggle activation. None given', 'event_espresso'),
3298
-                __FILE__, __FUNCTION__, __LINE__
3299
-            );
3300
-            $success = false;
3301
-        }
3302
-        
3303
-        if ( ! isset($this->_req_data['messenger'])) {
3304
-            EE_Error::add_error(
3305
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3306
-                __FILE__, __FUNCTION__, __LINE__
3307
-            );
3308
-            $success = false;
3309
-        }
3310
-        
3311
-        if ( ! isset($this->_req_data['status'])) {
3312
-            EE_Error::add_error(
3313
-                __('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3314
-                    'event_espresso'),
3315
-                __FILE__, __FUNCTION__, __LINE__
3316
-            );
3317
-            $success = false;
3318
-        }
3319
-        
3320
-        
3321
-        //do check to verify we have a valid status.
3322
-        $status = $this->_req_data['status'];
3323
-        
3324
-        if ($status != 'activate' && $status != 'deactivate') {
3325
-            EE_Error::add_error(
3326
-                sprintf(
3327
-                    __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3328
-                    $this->_req_data['status']
3329
-                ),
3330
-                __FILE__, __FUNCTION__, __LINE__
3331
-            );
3332
-            $success = false;
3333
-        }
3334
-        
3335
-        
3336
-        //do a nonce check here since we're not arriving via a normal route
3337
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3338
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3339
-        
3340
-        $this->_verify_nonce($nonce, $nonce_ref);
3341
-        
3342
-        if ($success) {
3343
-            //made it here? um, what are you waiting for then?
3344
-            $success = $status == 'deactivate'
3345
-                ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3346
-                    $this->_req_data['message_type'])
3347
-                : $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3348
-                    $this->_req_data['message_type']);
3349
-        }
3350
-        
3351
-        $this->_template_args['success'] = $success;
3352
-        $this->_return_json();
3353
-    }
3354
-    
3355
-    
3356
-    /**
3357
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3358
-     *
3359
-     * @param string $messenger_name The name of the messenger being activated
3360
-     *
3361
-     * @return bool
3362
-     */
3363
-    protected function _activate_messenger($messenger_name)
3364
-    {
3365
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3366
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3367
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3368
-        
3369
-        //ensure is active
3370
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3371
-        
3372
-        //set response_data for reload
3373
-        foreach ($message_types_to_activate as $message_type_name) {
3374
-            /** @var EE_message_type $message_type */
3375
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3376
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3377
-                    $message_type_name)
3378
-                && $message_type instanceof EE_message_type
3379
-            ) {
3380
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3381
-                if ($message_type->get_admin_settings_fields()) {
3382
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3383
-                }
3384
-            }
3385
-        }
3386
-        
3387
-        //add success message for activating messenger
3388
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3389
-        
3390
-    }
3391
-    
3392
-    
3393
-    /**
3394
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3395
-     *
3396
-     * @param string $messenger_name The name of the messenger being activated
3397
-     *
3398
-     * @return bool
3399
-     */
3400
-    protected function _deactivate_messenger($messenger_name)
3401
-    {
3402
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3403
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3404
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3405
-        
3406
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3407
-    }
3408
-    
3409
-    
3410
-    /**
3411
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3412
-     *
3413
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3414
-     * @param string $message_type_name The name of the message type being activated for the messenger
3415
-     *
3416
-     * @return bool
3417
-     */
3418
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3419
-    {
3420
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3421
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3422
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3423
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3424
-        
3425
-        //ensure is active
3426
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3427
-        
3428
-        //set response for load
3429
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3430
-            $message_type_name)
3431
-        ) {
3432
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3433
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3434
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3435
-            }
3436
-        }
3437
-        
3438
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3439
-            $message_type_to_activate);
3440
-    }
3441
-    
3442
-    
3443
-    /**
3444
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3445
-     *
3446
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3447
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3448
-     *
3449
-     * @return bool
3450
-     */
3451
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3452
-    {
3453
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3454
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3455
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3456
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3457
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3458
-        
3459
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3460
-            $message_type_to_deactivate);
3461
-    }
3462
-    
3463
-    
3464
-    /**
3465
-     * This just initializes the defaults for activating messenger and message type responses.
3466
-     */
3467
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
3468
-    {
3469
-        $this->_template_args['data']['active_mts'] = array();
3470
-        $this->_template_args['data']['mt_reload']  = array();
3471
-    }
3472
-    
3473
-    
3474
-    /**
3475
-     * Setup appropriate response for activating a messenger and/or message types
3476
-     *
3477
-     * @param EE_messenger         $messenger
3478
-     * @param EE_message_type|null $message_type
3479
-     *
3480
-     * @return bool
3481
-     * @throws EE_Error
3482
-     */
3483
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
3484
-        $messenger,
3485
-        EE_Message_Type $message_type = null
3486
-    ) {
3487
-        //if $messenger isn't a valid messenger object then get out.
3488
-        if ( ! $messenger instanceof EE_Messenger) {
3489
-            EE_Error::add_error(
3490
-                __('The messenger being activated is not a valid messenger', 'event_espresso'),
3491
-                __FILE__,
3492
-                __FUNCTION__,
3493
-                __LINE__
3494
-            );
3159
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3160
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3161
+				: '';
3162
+		}
3163
+        
3164
+		//we also need some hidden fields
3165
+		$settings_template_args['hidden_fields'] = array(
3166
+			'messenger_settings[messenger]' => array(
3167
+				'type'  => 'hidden',
3168
+				'value' => $messenger->name
3169
+			),
3170
+			'type'                          => array(
3171
+				'type'  => 'hidden',
3172
+				'value' => 'messenger'
3173
+			)
3174
+		);
3175
+        
3176
+		//make sure any active message types that are existing are included in the hidden fields
3177
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3178
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3179
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3180
+					'type'  => 'hidden',
3181
+					'value' => $mt
3182
+				);
3183
+			}
3184
+		}
3185
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3186
+			$settings_template_args['hidden_fields'],
3187
+			'array'
3188
+		);
3189
+		$active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3190
+        
3191
+		$settings_template_args['messenger']           = $messenger->name;
3192
+		$settings_template_args['description']         = $messenger->description;
3193
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3194
+        
3195
+        
3196
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3197
+			? $settings_template_args['show_hide_edit_form']
3198
+			: ' hidden';
3199
+        
3200
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3201
+			? ' hidden'
3202
+			: $settings_template_args['show_hide_edit_form'];
3203
+        
3204
+        
3205
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3206
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3207
+		$settings_template_args['on_off_status'] = $active ? true : false;
3208
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3209
+		$content                                 = EEH_Template::display_template($template, $settings_template_args,
3210
+			true);
3211
+        
3212
+		return $content;
3213
+	}
3214
+    
3215
+    
3216
+	/**
3217
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3218
+	 */
3219
+	public function activate_messenger_toggle()
3220
+	{
3221
+		$success = true;
3222
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3223
+		//let's check that we have required data
3224
+		if ( ! isset($this->_req_data['messenger'])) {
3225
+			EE_Error::add_error(
3226
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3227
+				__FILE__,
3228
+				__FUNCTION__,
3229
+				__LINE__
3230
+			);
3231
+			$success = false;
3232
+		}
3233
+        
3234
+		//do a nonce check here since we're not arriving via a normal route
3235
+		$nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3236
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3237
+        
3238
+		$this->_verify_nonce($nonce, $nonce_ref);
3239
+        
3240
+        
3241
+		if ( ! isset($this->_req_data['status'])) {
3242
+			EE_Error::add_error(
3243
+				__(
3244
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3245
+					'event_espresso'
3246
+				),
3247
+				__FILE__,
3248
+				__FUNCTION__,
3249
+				__LINE__
3250
+			);
3251
+			$success = false;
3252
+		}
3253
+        
3254
+		//do check to verify we have a valid status.
3255
+		$status = $this->_req_data['status'];
3256
+        
3257
+		if ($status != 'off' && $status != 'on') {
3258
+			EE_Error::add_error(
3259
+				sprintf(
3260
+					__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3261
+					$this->_req_data['status']
3262
+				),
3263
+				__FILE__,
3264
+				__FUNCTION__,
3265
+				__LINE__
3266
+			);
3267
+			$success = false;
3268
+		}
3269
+        
3270
+		if ($success) {
3271
+			//made it here?  Stop dawdling then!!
3272
+			$success = $status == 'off'
3273
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3274
+				: $this->_activate_messenger($this->_req_data['messenger']);
3275
+		}
3276
+        
3277
+		$this->_template_args['success'] = $success;
3278
+        
3279
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3280
+		$this->_return_json();
3281
+        
3282
+	}
3283
+    
3284
+    
3285
+	/**
3286
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3287
+	 *
3288
+	 */
3289
+	public function activate_mt_toggle()
3290
+	{
3291
+		$success = true;
3292
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3293
+        
3294
+		//let's make sure we have the necessary data
3295
+		if ( ! isset($this->_req_data['message_type'])) {
3296
+			EE_Error::add_error(
3297
+				__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3298
+				__FILE__, __FUNCTION__, __LINE__
3299
+			);
3300
+			$success = false;
3301
+		}
3302
+        
3303
+		if ( ! isset($this->_req_data['messenger'])) {
3304
+			EE_Error::add_error(
3305
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3306
+				__FILE__, __FUNCTION__, __LINE__
3307
+			);
3308
+			$success = false;
3309
+		}
3310
+        
3311
+		if ( ! isset($this->_req_data['status'])) {
3312
+			EE_Error::add_error(
3313
+				__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3314
+					'event_espresso'),
3315
+				__FILE__, __FUNCTION__, __LINE__
3316
+			);
3317
+			$success = false;
3318
+		}
3319
+        
3320
+        
3321
+		//do check to verify we have a valid status.
3322
+		$status = $this->_req_data['status'];
3323
+        
3324
+		if ($status != 'activate' && $status != 'deactivate') {
3325
+			EE_Error::add_error(
3326
+				sprintf(
3327
+					__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3328
+					$this->_req_data['status']
3329
+				),
3330
+				__FILE__, __FUNCTION__, __LINE__
3331
+			);
3332
+			$success = false;
3333
+		}
3334
+        
3335
+        
3336
+		//do a nonce check here since we're not arriving via a normal route
3337
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3338
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3339
+        
3340
+		$this->_verify_nonce($nonce, $nonce_ref);
3341
+        
3342
+		if ($success) {
3343
+			//made it here? um, what are you waiting for then?
3344
+			$success = $status == 'deactivate'
3345
+				? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3346
+					$this->_req_data['message_type'])
3347
+				: $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3348
+					$this->_req_data['message_type']);
3349
+		}
3350
+        
3351
+		$this->_template_args['success'] = $success;
3352
+		$this->_return_json();
3353
+	}
3354
+    
3355
+    
3356
+	/**
3357
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3358
+	 *
3359
+	 * @param string $messenger_name The name of the messenger being activated
3360
+	 *
3361
+	 * @return bool
3362
+	 */
3363
+	protected function _activate_messenger($messenger_name)
3364
+	{
3365
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3366
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3367
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3368
+        
3369
+		//ensure is active
3370
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3371
+        
3372
+		//set response_data for reload
3373
+		foreach ($message_types_to_activate as $message_type_name) {
3374
+			/** @var EE_message_type $message_type */
3375
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3376
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3377
+					$message_type_name)
3378
+				&& $message_type instanceof EE_message_type
3379
+			) {
3380
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3381
+				if ($message_type->get_admin_settings_fields()) {
3382
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3383
+				}
3384
+			}
3385
+		}
3386
+        
3387
+		//add success message for activating messenger
3388
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3389
+        
3390
+	}
3391
+    
3392
+    
3393
+	/**
3394
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3395
+	 *
3396
+	 * @param string $messenger_name The name of the messenger being activated
3397
+	 *
3398
+	 * @return bool
3399
+	 */
3400
+	protected function _deactivate_messenger($messenger_name)
3401
+	{
3402
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3403
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3404
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3405
+        
3406
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3407
+	}
3408
+    
3409
+    
3410
+	/**
3411
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3412
+	 *
3413
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3414
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3415
+	 *
3416
+	 * @return bool
3417
+	 */
3418
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3419
+	{
3420
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3421
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3422
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3423
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3424
+        
3425
+		//ensure is active
3426
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3427
+        
3428
+		//set response for load
3429
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3430
+			$message_type_name)
3431
+		) {
3432
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3433
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3434
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3435
+			}
3436
+		}
3437
+        
3438
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3439
+			$message_type_to_activate);
3440
+	}
3441
+    
3442
+    
3443
+	/**
3444
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3445
+	 *
3446
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3447
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3448
+	 *
3449
+	 * @return bool
3450
+	 */
3451
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3452
+	{
3453
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3454
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3455
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3456
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3457
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3458
+        
3459
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3460
+			$message_type_to_deactivate);
3461
+	}
3462
+    
3463
+    
3464
+	/**
3465
+	 * This just initializes the defaults for activating messenger and message type responses.
3466
+	 */
3467
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
3468
+	{
3469
+		$this->_template_args['data']['active_mts'] = array();
3470
+		$this->_template_args['data']['mt_reload']  = array();
3471
+	}
3472
+    
3473
+    
3474
+	/**
3475
+	 * Setup appropriate response for activating a messenger and/or message types
3476
+	 *
3477
+	 * @param EE_messenger         $messenger
3478
+	 * @param EE_message_type|null $message_type
3479
+	 *
3480
+	 * @return bool
3481
+	 * @throws EE_Error
3482
+	 */
3483
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
3484
+		$messenger,
3485
+		EE_Message_Type $message_type = null
3486
+	) {
3487
+		//if $messenger isn't a valid messenger object then get out.
3488
+		if ( ! $messenger instanceof EE_Messenger) {
3489
+			EE_Error::add_error(
3490
+				__('The messenger being activated is not a valid messenger', 'event_espresso'),
3491
+				__FILE__,
3492
+				__FUNCTION__,
3493
+				__LINE__
3494
+			);
3495 3495
             
3496
-            return false;
3497
-        }
3498
-        //activated
3499
-        if ($this->_template_args['data']['active_mts']) {
3500
-            EE_Error::overwrite_success();
3501
-            //activated a message type with the messenger
3502
-            if ($message_type instanceof EE_message_type) {
3503
-                EE_Error::add_success(
3504
-                    sprintf(
3505
-                        __('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3506
-                        ucwords($message_type->label['singular']),
3507
-                        ucwords($messenger->label['singular'])
3508
-                    )
3509
-                );
3496
+			return false;
3497
+		}
3498
+		//activated
3499
+		if ($this->_template_args['data']['active_mts']) {
3500
+			EE_Error::overwrite_success();
3501
+			//activated a message type with the messenger
3502
+			if ($message_type instanceof EE_message_type) {
3503
+				EE_Error::add_success(
3504
+					sprintf(
3505
+						__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3506
+						ucwords($message_type->label['singular']),
3507
+						ucwords($messenger->label['singular'])
3508
+					)
3509
+				);
3510 3510
                 
3511
-                //if message type was invoice then let's make sure we activate the invoice payment method.
3512
-                if ($message_type->name == 'invoice') {
3513
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
3514
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3515
-                    if ($pm instanceof EE_Payment_Method) {
3516
-                        EE_Error::add_attention(__('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.',
3517
-                            'event_espresso'));
3518
-                    }
3519
-                }
3520
-                //just toggles the entire messenger
3521
-            } else {
3522
-                EE_Error::add_success(
3523
-                    sprintf(
3524
-                        __('%s messenger has been successfully activated', 'event_espresso'),
3525
-                        ucwords($messenger->label['singular'])
3526
-                    )
3527
-                );
3528
-            }
3511
+				//if message type was invoice then let's make sure we activate the invoice payment method.
3512
+				if ($message_type->name == 'invoice') {
3513
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
3514
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3515
+					if ($pm instanceof EE_Payment_Method) {
3516
+						EE_Error::add_attention(__('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.',
3517
+							'event_espresso'));
3518
+					}
3519
+				}
3520
+				//just toggles the entire messenger
3521
+			} else {
3522
+				EE_Error::add_success(
3523
+					sprintf(
3524
+						__('%s messenger has been successfully activated', 'event_espresso'),
3525
+						ucwords($messenger->label['singular'])
3526
+					)
3527
+				);
3528
+			}
3529 3529
             
3530
-            return true;
3530
+			return true;
3531 3531
             
3532
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3533
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3534
-            //in which case we just give a success message for the messenger being successfully activated.
3535
-        } else {
3536
-            if ( ! $messenger->get_default_message_types()) {
3537
-                //messenger doesn't have any default message types so still a success.
3538
-                EE_Error::add_success(
3539
-                    sprintf(
3540
-                        __('%s messenger was successfully activated.', 'event_espresso'),
3541
-                        ucwords($messenger->label['singular'])
3542
-                    )
3543
-                );
3532
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3533
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3534
+			//in which case we just give a success message for the messenger being successfully activated.
3535
+		} else {
3536
+			if ( ! $messenger->get_default_message_types()) {
3537
+				//messenger doesn't have any default message types so still a success.
3538
+				EE_Error::add_success(
3539
+					sprintf(
3540
+						__('%s messenger was successfully activated.', 'event_espresso'),
3541
+						ucwords($messenger->label['singular'])
3542
+					)
3543
+				);
3544 3544
                 
3545
-                return true;
3546
-            } else {
3547
-                EE_Error::add_error(
3548
-                    $message_type instanceof EE_message_type
3549
-                        ? sprintf(
3550
-                        __('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3551
-                        ucwords($message_type->label['singular']),
3552
-                        ucwords($messenger->label['singular'])
3553
-                    )
3554
-                        : sprintf(
3555
-                        __('%s messenger was not successfully activated', 'event_espresso'),
3556
-                        ucwords($messenger->label['singular'])
3557
-                    ),
3558
-                    __FILE__,
3559
-                    __FUNCTION__,
3560
-                    __LINE__
3561
-                );
3545
+				return true;
3546
+			} else {
3547
+				EE_Error::add_error(
3548
+					$message_type instanceof EE_message_type
3549
+						? sprintf(
3550
+						__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3551
+						ucwords($message_type->label['singular']),
3552
+						ucwords($messenger->label['singular'])
3553
+					)
3554
+						: sprintf(
3555
+						__('%s messenger was not successfully activated', 'event_espresso'),
3556
+						ucwords($messenger->label['singular'])
3557
+					),
3558
+					__FILE__,
3559
+					__FUNCTION__,
3560
+					__LINE__
3561
+				);
3562 3562
                 
3563
-                return false;
3564
-            }
3565
-        }
3566
-    }
3567
-    
3568
-    
3569
-    /**
3570
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
3571
-     *
3572
-     * @param EE_messenger         $messenger
3573
-     * @param EE_message_type|null $message_type
3574
-     *
3575
-     * @return bool
3576
-     */
3577
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3578
-        $messenger,
3579
-        EE_message_type $message_type = null
3580
-    ) {
3581
-        EE_Error::overwrite_success();
3582
-        
3583
-        //if $messenger isn't a valid messenger object then get out.
3584
-        if ( ! $messenger instanceof EE_Messenger) {
3585
-            EE_Error::add_error(
3586
-                __('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3587
-                __FILE__,
3588
-                __FUNCTION__,
3589
-                __LINE__
3590
-            );
3563
+				return false;
3564
+			}
3565
+		}
3566
+	}
3567
+    
3568
+    
3569
+	/**
3570
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
3571
+	 *
3572
+	 * @param EE_messenger         $messenger
3573
+	 * @param EE_message_type|null $message_type
3574
+	 *
3575
+	 * @return bool
3576
+	 */
3577
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3578
+		$messenger,
3579
+		EE_message_type $message_type = null
3580
+	) {
3581
+		EE_Error::overwrite_success();
3582
+        
3583
+		//if $messenger isn't a valid messenger object then get out.
3584
+		if ( ! $messenger instanceof EE_Messenger) {
3585
+			EE_Error::add_error(
3586
+				__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3587
+				__FILE__,
3588
+				__FUNCTION__,
3589
+				__LINE__
3590
+			);
3591 3591
             
3592
-            return false;
3593
-        }
3594
-        
3595
-        if ($message_type instanceof EE_message_type) {
3596
-            $message_type_name = $message_type->name;
3597
-            EE_Error::add_success(
3598
-                sprintf(
3599
-                    __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3600
-                    ucwords($message_type->label['singular']),
3601
-                    ucwords($messenger->label['singular'])
3602
-                )
3603
-            );
3604
-        } else {
3605
-            $message_type_name = '';
3606
-            EE_Error::add_success(
3607
-                sprintf(
3608
-                    __('%s messenger has been successfully deactivated.', 'event_espresso'),
3609
-                    ucwords($messenger->label['singular'])
3610
-                )
3611
-            );
3612
-        }
3613
-        
3614
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3615
-        if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3616
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
3617
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3618
-            if ($count_updated > 0) {
3619
-                $msg = $message_type_name == 'invoice'
3620
-                    ? __('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.',
3621
-                        'event_espresso')
3622
-                    : __('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.',
3623
-                        'event_espresso');
3624
-                EE_Error::add_attention($msg);
3625
-            }
3626
-        }
3627
-        
3628
-        return true;
3629
-    }
3630
-    
3631
-    
3632
-    /**
3633
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3634
-     */
3635
-    public function update_mt_form()
3636
-    {
3637
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3638
-            EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3639
-                __LINE__);
3640
-            $this->_return_json();
3641
-        }
3642
-        
3643
-        $message_types = $this->get_installed_message_types();
3644
-        
3645
-        $message_type = $message_types[$this->_req_data['message_type']];
3646
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3647
-        
3648
-        $content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3649
-        $this->_template_args['success'] = true;
3650
-        $this->_template_args['content'] = $content;
3651
-        $this->_return_json();
3652
-    }
3653
-    
3654
-    
3655
-    /**
3656
-     * this handles saving the settings for a messenger or message type
3657
-     *
3658
-     */
3659
-    public function save_settings()
3660
-    {
3661
-        if ( ! isset($this->_req_data['type'])) {
3662
-            EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3663
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3664
-            $this->_template_args['error'] = true;
3665
-            $this->_return_json();
3666
-        }
3667
-        
3668
-        
3669
-        if ($this->_req_data['type'] == 'messenger') {
3670
-            $settings  = $this->_req_data['messenger_settings']; //this should be an array.
3671
-            $messenger = $settings['messenger'];
3672
-            //let's setup the settings data
3673
-            foreach ($settings as $key => $value) {
3674
-                switch ($key) {
3675
-                    case 'messenger' :
3676
-                        unset($settings['messenger']);
3677
-                        break;
3678
-                    case 'message_types' :
3679
-                        unset($settings['message_types']);
3680
-                        break;
3681
-                    default :
3682
-                        $settings[$key] = $value;
3683
-                        break;
3684
-                }
3685
-            }
3686
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3687
-        } else if ($this->_req_data['type'] == 'message_type') {
3688
-            $settings     = $this->_req_data['message_type_settings'];
3689
-            $messenger    = $settings['messenger'];
3690
-            $message_type = $settings['message_type'];
3592
+			return false;
3593
+		}
3594
+        
3595
+		if ($message_type instanceof EE_message_type) {
3596
+			$message_type_name = $message_type->name;
3597
+			EE_Error::add_success(
3598
+				sprintf(
3599
+					__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3600
+					ucwords($message_type->label['singular']),
3601
+					ucwords($messenger->label['singular'])
3602
+				)
3603
+			);
3604
+		} else {
3605
+			$message_type_name = '';
3606
+			EE_Error::add_success(
3607
+				sprintf(
3608
+					__('%s messenger has been successfully deactivated.', 'event_espresso'),
3609
+					ucwords($messenger->label['singular'])
3610
+				)
3611
+			);
3612
+		}
3613
+        
3614
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3615
+		if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3616
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
3617
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3618
+			if ($count_updated > 0) {
3619
+				$msg = $message_type_name == 'invoice'
3620
+					? __('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.',
3621
+						'event_espresso')
3622
+					: __('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.',
3623
+						'event_espresso');
3624
+				EE_Error::add_attention($msg);
3625
+			}
3626
+		}
3627
+        
3628
+		return true;
3629
+	}
3630
+    
3631
+    
3632
+	/**
3633
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3634
+	 */
3635
+	public function update_mt_form()
3636
+	{
3637
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3638
+			EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3639
+				__LINE__);
3640
+			$this->_return_json();
3641
+		}
3642
+        
3643
+		$message_types = $this->get_installed_message_types();
3644
+        
3645
+		$message_type = $message_types[$this->_req_data['message_type']];
3646
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3647
+        
3648
+		$content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3649
+		$this->_template_args['success'] = true;
3650
+		$this->_template_args['content'] = $content;
3651
+		$this->_return_json();
3652
+	}
3653
+    
3654
+    
3655
+	/**
3656
+	 * this handles saving the settings for a messenger or message type
3657
+	 *
3658
+	 */
3659
+	public function save_settings()
3660
+	{
3661
+		if ( ! isset($this->_req_data['type'])) {
3662
+			EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3663
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3664
+			$this->_template_args['error'] = true;
3665
+			$this->_return_json();
3666
+		}
3667
+        
3668
+        
3669
+		if ($this->_req_data['type'] == 'messenger') {
3670
+			$settings  = $this->_req_data['messenger_settings']; //this should be an array.
3671
+			$messenger = $settings['messenger'];
3672
+			//let's setup the settings data
3673
+			foreach ($settings as $key => $value) {
3674
+				switch ($key) {
3675
+					case 'messenger' :
3676
+						unset($settings['messenger']);
3677
+						break;
3678
+					case 'message_types' :
3679
+						unset($settings['message_types']);
3680
+						break;
3681
+					default :
3682
+						$settings[$key] = $value;
3683
+						break;
3684
+				}
3685
+			}
3686
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3687
+		} else if ($this->_req_data['type'] == 'message_type') {
3688
+			$settings     = $this->_req_data['message_type_settings'];
3689
+			$messenger    = $settings['messenger'];
3690
+			$message_type = $settings['message_type'];
3691 3691
             
3692
-            foreach ($settings as $key => $value) {
3693
-                switch ($key) {
3694
-                    case 'messenger' :
3695
-                        unset($settings['messenger']);
3696
-                        break;
3697
-                    case 'message_type' :
3698
-                        unset($settings['message_type']);
3699
-                        break;
3700
-                    default :
3701
-                        $settings[$key] = $value;
3702
-                        break;
3703
-                }
3704
-            }
3692
+			foreach ($settings as $key => $value) {
3693
+				switch ($key) {
3694
+					case 'messenger' :
3695
+						unset($settings['messenger']);
3696
+						break;
3697
+					case 'message_type' :
3698
+						unset($settings['message_type']);
3699
+						break;
3700
+					default :
3701
+						$settings[$key] = $value;
3702
+						break;
3703
+				}
3704
+			}
3705 3705
             
3706
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3707
-        }
3708
-        
3709
-        //okay we should have the data all setup.  Now we just update!
3710
-        $success = $this->_message_resource_manager->update_active_messengers_option();
3711
-        
3712
-        if ($success) {
3713
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
3714
-        } else {
3715
-            EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3716
-        }
3717
-        
3718
-        $this->_template_args['success'] = $success;
3719
-        $this->_return_json();
3720
-    }
3721
-    
3722
-    
3723
-    
3724
-    
3725
-    /**  EE MESSAGE PROCESSING ACTIONS **/
3726
-    
3727
-    
3728
-    /**
3729
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3730
-     * However, this does not send immediately, it just queues for sending.
3731
-     *
3732
-     * @since 4.9.0
3733
-     */
3734
-    protected function _generate_now()
3735
-    {
3736
-        $msg_ids = $this->_get_msg_ids_from_request();
3737
-        EED_Messages::generate_now($msg_ids);
3738
-        $this->_redirect_after_action(false, '', '', array(), true);
3739
-    }
3740
-    
3741
-    
3742
-    /**
3743
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3744
-     * are EEM_Message::status_resend or EEM_Message::status_idle
3745
-     *
3746
-     * @since 4.9.0
3747
-     *
3748
-     */
3749
-    protected function _generate_and_send_now()
3750
-    {
3751
-        $this->_generate_now();
3752
-        $this->_send_now();
3753
-        $this->_redirect_after_action(false, '', '', array(), true);
3754
-    }
3755
-    
3756
-    
3757
-    /**
3758
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3759
-     *
3760
-     * @since 4.9.0
3761
-     */
3762
-    protected function _queue_for_resending()
3763
-    {
3764
-        $msg_ids = $this->_get_msg_ids_from_request();
3765
-        EED_Messages::queue_for_resending($msg_ids);
3766
-        $this->_redirect_after_action(false, '', '', array(), true);
3767
-    }
3768
-    
3769
-    
3770
-    /**
3771
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3772
-     *
3773
-     * @since 4.9.0
3774
-     */
3775
-    protected function _send_now()
3776
-    {
3777
-        $msg_ids = $this->_get_msg_ids_from_request();
3778
-        EED_Messages::send_now($msg_ids);
3779
-        $this->_redirect_after_action(false, '', '', array(), true);
3780
-    }
3781
-    
3782
-    
3783
-    /**
3784
-     * Deletes EE_messages for IDs in the request.
3785
-     *
3786
-     * @since 4.9.0
3787
-     */
3788
-    protected function _delete_ee_messages()
3789
-    {
3790
-        $msg_ids       = $this->_get_msg_ids_from_request();
3791
-        $deleted_count = 0;
3792
-        foreach ($msg_ids as $msg_id) {
3793
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3794
-                $deleted_count++;
3795
-            }
3796
-        }
3797
-        if ($deleted_count) {
3798
-            $this->_redirect_after_action(
3799
-                true,
3800
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
3801
-                __('deleted', 'event_espresso')
3802
-            );
3803
-        } else {
3804
-            EE_Error::add_error(
3805
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3806
-                __FILE__, __FUNCTION__, __LINE__
3807
-            );
3808
-            $this->_redirect_after_action(false, '', '', array(), true);
3809
-        }
3810
-    }
3811
-    
3812
-    
3813
-    /**
3814
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3815
-     * @since 4.9.0
3816
-     * @return array
3817
-     */
3818
-    protected function _get_msg_ids_from_request()
3819
-    {
3820
-        if ( ! isset($this->_req_data['MSG_ID'])) {
3821
-            return array();
3822
-        }
3823
-        
3824
-        return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3825
-    }
3706
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3707
+		}
3708
+        
3709
+		//okay we should have the data all setup.  Now we just update!
3710
+		$success = $this->_message_resource_manager->update_active_messengers_option();
3711
+        
3712
+		if ($success) {
3713
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
3714
+		} else {
3715
+			EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3716
+		}
3717
+        
3718
+		$this->_template_args['success'] = $success;
3719
+		$this->_return_json();
3720
+	}
3721
+    
3722
+    
3723
+    
3724
+    
3725
+	/**  EE MESSAGE PROCESSING ACTIONS **/
3726
+    
3727
+    
3728
+	/**
3729
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3730
+	 * However, this does not send immediately, it just queues for sending.
3731
+	 *
3732
+	 * @since 4.9.0
3733
+	 */
3734
+	protected function _generate_now()
3735
+	{
3736
+		$msg_ids = $this->_get_msg_ids_from_request();
3737
+		EED_Messages::generate_now($msg_ids);
3738
+		$this->_redirect_after_action(false, '', '', array(), true);
3739
+	}
3740
+    
3741
+    
3742
+	/**
3743
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3744
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
3745
+	 *
3746
+	 * @since 4.9.0
3747
+	 *
3748
+	 */
3749
+	protected function _generate_and_send_now()
3750
+	{
3751
+		$this->_generate_now();
3752
+		$this->_send_now();
3753
+		$this->_redirect_after_action(false, '', '', array(), true);
3754
+	}
3755
+    
3756
+    
3757
+	/**
3758
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3759
+	 *
3760
+	 * @since 4.9.0
3761
+	 */
3762
+	protected function _queue_for_resending()
3763
+	{
3764
+		$msg_ids = $this->_get_msg_ids_from_request();
3765
+		EED_Messages::queue_for_resending($msg_ids);
3766
+		$this->_redirect_after_action(false, '', '', array(), true);
3767
+	}
3768
+    
3769
+    
3770
+	/**
3771
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3772
+	 *
3773
+	 * @since 4.9.0
3774
+	 */
3775
+	protected function _send_now()
3776
+	{
3777
+		$msg_ids = $this->_get_msg_ids_from_request();
3778
+		EED_Messages::send_now($msg_ids);
3779
+		$this->_redirect_after_action(false, '', '', array(), true);
3780
+	}
3781
+    
3782
+    
3783
+	/**
3784
+	 * Deletes EE_messages for IDs in the request.
3785
+	 *
3786
+	 * @since 4.9.0
3787
+	 */
3788
+	protected function _delete_ee_messages()
3789
+	{
3790
+		$msg_ids       = $this->_get_msg_ids_from_request();
3791
+		$deleted_count = 0;
3792
+		foreach ($msg_ids as $msg_id) {
3793
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3794
+				$deleted_count++;
3795
+			}
3796
+		}
3797
+		if ($deleted_count) {
3798
+			$this->_redirect_after_action(
3799
+				true,
3800
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
3801
+				__('deleted', 'event_espresso')
3802
+			);
3803
+		} else {
3804
+			EE_Error::add_error(
3805
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3806
+				__FILE__, __FUNCTION__, __LINE__
3807
+			);
3808
+			$this->_redirect_after_action(false, '', '', array(), true);
3809
+		}
3810
+	}
3811
+    
3812
+    
3813
+	/**
3814
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3815
+	 * @since 4.9.0
3816
+	 * @return array
3817
+	 */
3818
+	protected function _get_msg_ids_from_request()
3819
+	{
3820
+		if ( ! isset($this->_req_data['MSG_ID'])) {
3821
+			return array();
3822
+		}
3823
+        
3824
+		return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3825
+	}
3826 3826
     
3827 3827
     
3828 3828
 }
Please login to merge, or discard this patch.
core/domain/DomainBase.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -18,132 +18,132 @@
 block discarded – undo
18 18
 abstract class DomainBase
19 19
 {
20 20
 
21
-    /**
22
-     * Equivalent to `__FILE__` for main plugin file.
23
-     *
24
-     * @var string
25
-     */
26
-    private static $plugin_file = '';
27
-
28
-    /**
29
-     * String indicating version for plugin
30
-     *
31
-     * @var string
32
-     */
33
-    private static $version = '';
34
-
35
-    /**
36
-     * @var string $plugin_basename
37
-     */
38
-    private static $plugin_basename = '';
39
-
40
-    /**
41
-     * @var string $plugin_path
42
-     */
43
-    private static $plugin_path = '';
44
-
45
-    /**
46
-     * @var string $plugin_url
47
-     */
48
-    private static $plugin_url = '';
49
-
50
-
51
-
52
-    /**
53
-     * Initializes internal static properties.
54
-     *
55
-     * @param string $plugin_file
56
-     * @param string $version
57
-     */
58
-    public static function init($plugin_file, $version)
59
-    {
60
-        self::$plugin_file = $plugin_file;
61
-        self::$version = $version;
62
-        self::$plugin_basename = plugin_basename($plugin_file);
63
-        self::$plugin_path = plugin_dir_path($plugin_file);
64
-        self::$plugin_url = plugin_dir_url($plugin_file);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return string
71
-     * @throws DomainException
72
-     */
73
-    public static function pluginFile()
74
-    {
75
-        self::verifyInitialized(__METHOD__);
76
-        return self::$plugin_file;
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * @return string
83
-     * @throws DomainException
84
-     */
85
-    public static function pluginBasename()
86
-    {
87
-        self::verifyInitialized(__METHOD__);
88
-        return self::$plugin_basename;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * @return string
95
-     * @throws DomainException
96
-     */
97
-    public static function pluginPath()
98
-    {
99
-        self::verifyInitialized(__METHOD__);
100
-        return self::$plugin_path;
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * @return string
107
-     * @throws DomainException
108
-     */
109
-    public static function pluginUrl()
110
-    {
111
-        self::verifyInitialized(__METHOD__);
112
-        return self::$plugin_url;
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * @return string
119
-     * @throws DomainException
120
-     */
121
-    public static function version()
122
-    {
123
-        self::verifyInitialized(__METHOD__);
124
-        return self::$version;
125
-    }
126
-
127
-
128
-
129
-    /**
130
-     * @param string $method
131
-     * @throws DomainException
132
-     */
133
-    private static function verifyInitialized($method)
134
-    {
135
-        if (self::$plugin_file === '') {
136
-            throw new DomainException(
137
-                sprintf(
138
-                    esc_html__(
139
-                        '%1$s needs to be called before %2$s can return a value.',
140
-                        'event_espresso'
141
-                    ),
142
-                    get_called_class() . '::init()',
143
-                    "{$method}()"
144
-                )
145
-            );
146
-        }
147
-    }
21
+	/**
22
+	 * Equivalent to `__FILE__` for main plugin file.
23
+	 *
24
+	 * @var string
25
+	 */
26
+	private static $plugin_file = '';
27
+
28
+	/**
29
+	 * String indicating version for plugin
30
+	 *
31
+	 * @var string
32
+	 */
33
+	private static $version = '';
34
+
35
+	/**
36
+	 * @var string $plugin_basename
37
+	 */
38
+	private static $plugin_basename = '';
39
+
40
+	/**
41
+	 * @var string $plugin_path
42
+	 */
43
+	private static $plugin_path = '';
44
+
45
+	/**
46
+	 * @var string $plugin_url
47
+	 */
48
+	private static $plugin_url = '';
49
+
50
+
51
+
52
+	/**
53
+	 * Initializes internal static properties.
54
+	 *
55
+	 * @param string $plugin_file
56
+	 * @param string $version
57
+	 */
58
+	public static function init($plugin_file, $version)
59
+	{
60
+		self::$plugin_file = $plugin_file;
61
+		self::$version = $version;
62
+		self::$plugin_basename = plugin_basename($plugin_file);
63
+		self::$plugin_path = plugin_dir_path($plugin_file);
64
+		self::$plugin_url = plugin_dir_url($plugin_file);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return string
71
+	 * @throws DomainException
72
+	 */
73
+	public static function pluginFile()
74
+	{
75
+		self::verifyInitialized(__METHOD__);
76
+		return self::$plugin_file;
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * @return string
83
+	 * @throws DomainException
84
+	 */
85
+	public static function pluginBasename()
86
+	{
87
+		self::verifyInitialized(__METHOD__);
88
+		return self::$plugin_basename;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * @return string
95
+	 * @throws DomainException
96
+	 */
97
+	public static function pluginPath()
98
+	{
99
+		self::verifyInitialized(__METHOD__);
100
+		return self::$plugin_path;
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * @return string
107
+	 * @throws DomainException
108
+	 */
109
+	public static function pluginUrl()
110
+	{
111
+		self::verifyInitialized(__METHOD__);
112
+		return self::$plugin_url;
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * @return string
119
+	 * @throws DomainException
120
+	 */
121
+	public static function version()
122
+	{
123
+		self::verifyInitialized(__METHOD__);
124
+		return self::$version;
125
+	}
126
+
127
+
128
+
129
+	/**
130
+	 * @param string $method
131
+	 * @throws DomainException
132
+	 */
133
+	private static function verifyInitialized($method)
134
+	{
135
+		if (self::$plugin_file === '') {
136
+			throw new DomainException(
137
+				sprintf(
138
+					esc_html__(
139
+						'%1$s needs to be called before %2$s can return a value.',
140
+						'event_espresso'
141
+					),
142
+					get_called_class() . '::init()',
143
+					"{$method}()"
144
+				)
145
+			);
146
+		}
147
+	}
148 148
 
149 149
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@
 block discarded – undo
139 139
                         '%1$s needs to be called before %2$s can return a value.',
140 140
                         'event_espresso'
141 141
                     ),
142
-                    get_called_class() . '::init()',
142
+                    get_called_class().'::init()',
143 143
                     "{$method}()"
144 144
                 )
145 145
             );
Please login to merge, or discard this patch.