Completed
Branch FET-9795-new-interfaces (f37aef)
by
unknown
92:51 queued 80:52
created
core/libraries/plugin_api/EE_Register_Capabilities.lib.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -47,33 +47,33 @@  discard block
 block discarded – undo
47 47
 	 * @throws EE_Error
48 48
 	 * @return void
49 49
 	 */
50
-	public static function register( $cap_reference = NULL, $setup_args = array() ) {
50
+	public static function register($cap_reference = NULL, $setup_args = array()) {
51 51
 		//required fields MUST be present, so let's make sure they are.
52
-		if ( ! isset( $cap_reference ) || ! is_array( $setup_args ) || empty( $setup_args['capabilities'] ) ) {
52
+		if ( ! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
53 53
 			throw new EE_Error(
54
-				__( 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', 'event_espresso' )
54
+				__('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', 'event_espresso')
55 55
 			);
56 56
 		}
57 57
 		//make sure we don't register twice
58
-		if( isset( self::$_registry[ $cap_reference ] ) ){
58
+		if (isset(self::$_registry[$cap_reference])) {
59 59
 			return;
60 60
 		}
61 61
 		//make sure this is not registered too late or too early.
62
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' ) || did_action( 'AHEE__EE_System___detect_if_activation_or_upgrade__begin' ) ) {
63
-			EE_Error::doing_it_wrong( __METHOD__, sprintf( __('%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', 'event_espresso'), $cap_reference ), '4.5.0' );
62
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) {
63
+			EE_Error::doing_it_wrong(__METHOD__, sprintf(__('%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', 'event_espresso'), $cap_reference), '4.5.0');
64 64
 		}
65 65
 		//some preliminary sanitization and setting to the $_registry property
66 66
 		self::$_registry[$cap_reference] = array(
67
-			'caps' => isset( $setup_args['capabilities'] ) && is_array( $setup_args['capabilities'] ) ? $setup_args['capabilities'] : array(),
68
-			'cap_maps' => isset( $setup_args['capability_maps'] ) ? $setup_args['capability_maps'] : array()
67
+			'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) ? $setup_args['capabilities'] : array(),
68
+			'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array()
69 69
 		);
70 70
 		//set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once)
71
-		add_filter( 'FHEE__EE_Capabilities__init_caps_map__caps', array( 'EE_Register_Capabilities', 'register_capabilities' ), 10 );
71
+		add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array('EE_Register_Capabilities', 'register_capabilities'), 10);
72 72
 		//add filter for cap maps
73
-		add_filter( 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', array( 'EE_Register_Capabilities', 'register_cap_maps' ), 10 );
73
+		add_filter('FHEE__EE_Capabilities___set_meta_caps__meta_caps', array('EE_Register_Capabilities', 'register_cap_maps'), 10);
74 74
 		//init_role_caps to register new capabilities
75
-		if ( is_admin() ) {
76
-			EE_Registry::instance()->load_core( 'Capabilities' );
75
+		if (is_admin()) {
76
+			EE_Registry::instance()->load_core('Capabilities');
77 77
 			EE_Capabilities::instance()->init_caps();
78 78
 		}
79 79
 	}
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @return array merged in new caps.
90 90
 	 */
91
-	public static function register_capabilities( $incoming_caps ) {
92
-		foreach ( self::$_registry as $ref => $caps_and_cap_map ) {
93
-			$incoming_caps = array_merge_recursive( $incoming_caps, $caps_and_cap_map[ 'caps' ] );
91
+	public static function register_capabilities($incoming_caps) {
92
+		foreach (self::$_registry as $ref => $caps_and_cap_map) {
93
+			$incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']);
94 94
 		}
95 95
 		return $incoming_caps;
96 96
 	}
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
 	 * @return EE_Meta_Capability_Map[]
106 106
 	 * @throws EE_Error
107 107
 	 */
108
-	public static function register_cap_maps( $cap_maps ) {
108
+	public static function register_cap_maps($cap_maps) {
109 109
 		//loop through and instantiate cap maps.
110
-		foreach ( self::$_registry as $cap_reference => $setup ) {
111
-			if ( ! isset( $setup['cap_maps'] ) ) {
110
+		foreach (self::$_registry as $cap_reference => $setup) {
111
+			if ( ! isset($setup['cap_maps'])) {
112 112
 				continue;
113 113
 			}
114
-			foreach ( $setup['cap_maps'] as $cap_class => $args ) {
114
+			foreach ($setup['cap_maps'] as $cap_class => $args) {
115 115
 
116 116
 				/**
117 117
 				 * account for cases where capability maps may be indexed
@@ -138,19 +138,19 @@  discard block
 block discarded – undo
138 138
 				 * 	...
139 139
 				 * )
140 140
 				 */
141
-				if ( is_numeric( $cap_class ) ) {
142
-					$cap_class = key( $args );
141
+				if (is_numeric($cap_class)) {
142
+					$cap_class = key($args);
143 143
 					$args = $args[$cap_class];
144 144
 				}
145 145
 
146
-				if ( ! class_exists( $cap_class ) ) {
147
-					throw new EE_Error( sprintf( __( 'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments', 'event_espresso' ), $cap_reference ) );
146
+				if ( ! class_exists($cap_class)) {
147
+					throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments', 'event_espresso'), $cap_reference));
148 148
 				}
149 149
 
150
-				if ( count( $args ) !== 2 ) {
151
-					throw new EE_Error( sprintf( __('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.', 'event_espresso' ), $cap_reference ) );
150
+				if (count($args) !== 2) {
151
+					throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.', 'event_espresso'), $cap_reference));
152 152
 				}
153
-				$cap_maps[] = new $cap_class( $args[0], $args[1] );
153
+				$cap_maps[] = new $cap_class($args[0], $args[1]);
154 154
 			}
155 155
 		}
156 156
 		return $cap_maps;
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
 
160 160
 
161 161
 
162
-	public static function deregister( $cap_reference = NULL ) {
163
-		if ( !empty( self::$_registry[$cap_reference] ) ) {
164
-			unset( self::$_registry[ $cap_reference ] );
162
+	public static function deregister($cap_reference = NULL) {
163
+		if ( ! empty(self::$_registry[$cap_reference])) {
164
+			unset(self::$_registry[$cap_reference]);
165 165
 		}
166 166
 
167 167
 		//re init caps to grab the changes due to removed caps.
Please login to merge, or discard this patch.
core/EE_Deprecated.core.php 1 patch
Spacing   +174 added lines, -174 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(
Please login to merge, or discard this patch.
core/EE_Capabilities.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
      * @since                        4.5.0
806 806
      *
807 807
      * @param string $meta_cap   What meta capability is this mapping.
808
-     * @param array  $map_values array {
808
+     * @param string[]  $map_values array {
809 809
      *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
810 810
      *                           capabilities that don't get mapped to.
811 811
      *
@@ -880,8 +880,8 @@  discard block
 block discarded – undo
880 880
      * @since 4.6.x
881 881
      *
882 882
      * @param $caps
883
-     * @param $cap
884
-     * @param $user_id
883
+     * @param string $cap
884
+     * @param integer $user_id
885 885
      * @param $args
886 886
      *
887 887
      * @return array
Please login to merge, or discard this patch.
Indentation   +1175 added lines, -1175 removed lines patch added patch discarded remove patch
@@ -17,800 +17,800 @@  discard block
 block discarded – undo
17 17
 final class EE_Capabilities extends EE_Base
18 18
 {
19 19
 
20
-    /**
21
-     * the name of the wp option used to store caps previously initialized
22
-     */
23
-    const option_name = 'ee_caps_initialized';
24
-
25
-    /**
26
-     * instance of EE_Capabilities object
27
-     *
28
-     * @var EE_Capabilities
29
-     */
30
-    private static $_instance;
31
-
32
-
33
-    /**
34
-     * This is a map of caps that correspond to a default WP_Role.
35
-     * Array is indexed by Role and values are ee capabilities.
36
-     *
37
-     * @since 4.5.0
38
-     *
39
-     * @var array
40
-     */
41
-    private $_caps_map = array();
42
-
43
-
44
-    /**
45
-     * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for
46
-     * a user depending on context.
47
-     *
48
-     * @var EE_Meta_Capability_Map[]
49
-     */
50
-    private $_meta_caps = array();
51
-
52
-
53
-    /**
54
-     * singleton method used to instantiate class object
55
-     *
56
-     * @since 4.5.0
57
-     *
58
-     * @return EE_Capabilities
59
-     */
60
-    public static function instance()
61
-    {
62
-        //check if instantiated, and if not do so.
63
-        if (! self::$_instance instanceof EE_Capabilities) {
64
-            self::$_instance = new self();
65
-        }
66
-        return self::$_instance;
67
-    }
68
-
69
-
70
-    /**
71
-     * private constructor
72
-     *
73
-     * @since 4.5.0
74
-     *
75
-     * @return \EE_Capabilities
76
-     */
77
-    private function __construct()
78
-    {
79
-    }
80
-
81
-
82
-    /**
83
-     * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
84
-     *
85
-     * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
86
-     *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
87
-     *                    ensures that they are up to date.
88
-     *
89
-     *
90
-     * @since 4.5.0
91
-     * @return void
92
-     */
93
-    public function init_caps($reset = false)
94
-    {
95
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
96
-            $this->_caps_map = $this->_init_caps_map();
97
-            $this->init_role_caps($reset);
98
-            $this->_set_meta_caps();
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * This sets the meta caps property.
105
-     * @since 4.5.0
106
-     *
107
-     * @return void
108
-     */
109
-    private function _set_meta_caps()
110
-    {
111
-        //make sure we're only ever initializing the default _meta_caps array once if it's empty.
112
-        $this->_meta_caps = $this->_get_default_meta_caps_array();
113
-        $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps);
114
-        //add filter for map_meta_caps but only if models can query.
115
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
116
-            add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
117
-        }
118
-    }
119
-
120
-
121
-    /**
122
-     * This builds and returns the default meta_caps array only once.
123
-     *
124
-     * @since  4.8.28.rc.012
125
-     * @return array
126
-     * @throws \EE_Error
127
-     */
128
-    private function _get_default_meta_caps_array()
129
-    {
130
-        static $default_meta_caps = array();
131
-        if (empty($default_meta_caps)) {
132
-            $default_meta_caps = array(
133
-                //edits
134
-                new EE_Meta_Capability_Map_Edit(
135
-                    'ee_edit_event',
136
-                    array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
137
-                ),
138
-                new EE_Meta_Capability_Map_Edit(
139
-                    'ee_edit_venue',
140
-                    array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
141
-                ),
142
-                new EE_Meta_Capability_Map_Edit(
143
-                    'ee_edit_registration',
144
-                    array('Registration', '', 'ee_edit_others_registrations', '')
145
-                ),
146
-                new EE_Meta_Capability_Map_Edit(
147
-                    'ee_edit_checkin',
148
-                    array('Registration', '', 'ee_edit_others_checkins', '')
149
-                ),
150
-                new EE_Meta_Capability_Map_Messages_Cap(
151
-                    'ee_edit_message',
152
-                    array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
153
-                ),
154
-                new EE_Meta_Capability_Map_Edit(
155
-                    'ee_edit_default_ticket',
156
-                    array('Ticket', '', 'ee_edit_others_default_tickets', '')
157
-                ),
158
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
159
-                    'ee_edit_question',
160
-                    array('Question', '', '', 'ee_edit_system_questions')
161
-                ),
162
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
163
-                    'ee_edit_question_group',
164
-                    array('Question_Group', '', '', 'ee_edit_system_question_groups')
165
-                ),
166
-                new EE_Meta_Capability_Map_Edit(
167
-                    'ee_edit_payment_method',
168
-                    array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
169
-                ),
170
-                //reads
171
-                new EE_Meta_Capability_Map_Read(
172
-                    'ee_read_event',
173
-                    array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
174
-                ),
175
-                new EE_Meta_Capability_Map_Read(
176
-                    'ee_read_venue',
177
-                    array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
178
-                ),
179
-                new EE_Meta_Capability_Map_Read(
180
-                    'ee_read_registration',
181
-                    array('Registration', '', '', 'ee_edit_others_registrations')
182
-                ),
183
-                new EE_Meta_Capability_Map_Read(
184
-                    'ee_read_checkin',
185
-                    array('Registration', '', '', 'ee_read_others_checkins')
186
-                ),
187
-                new EE_Meta_Capability_Map_Messages_Cap(
188
-                    'ee_read_message',
189
-                    array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
190
-                ),
191
-                new EE_Meta_Capability_Map_Read(
192
-                    'ee_read_default_ticket',
193
-                    array('Ticket', '', '', 'ee_read_others_default_tickets')
194
-                ),
195
-                new EE_Meta_Capability_Map_Read(
196
-                    'ee_read_payment_method',
197
-                    array('Payment_Method', '', '', 'ee_read_others_payment_methods')),
198
-
199
-                //deletes
200
-                new EE_Meta_Capability_Map_Delete(
201
-                    'ee_delete_event',
202
-                    array(
203
-                        'Event',
204
-                        'ee_delete_published_events',
205
-                        'ee_delete_others_events',
206
-                        'ee_delete_private_events',
207
-                    )
208
-                ),
209
-                new EE_Meta_Capability_Map_Delete(
210
-                    'ee_delete_venue',
211
-                    array(
212
-                        'Venue',
213
-                        'ee_delete_published_venues',
214
-                        'ee_delete_others_venues',
215
-                        'ee_delete_private_venues',
216
-                    )
217
-                ),
218
-                new EE_Meta_Capability_Map_Delete(
219
-                    'ee_delete_registration',
220
-                    array('Registration', '', 'ee_delete_others_registrations', '')
221
-                ),
222
-                new EE_Meta_Capability_Map_Delete(
223
-                    'ee_delete_checkin',
224
-                    array('Registration', '', 'ee_delete_others_checkins', '')
225
-                ),
226
-                new EE_Meta_Capability_Map_Messages_Cap(
227
-                    'ee_delete_message',
228
-                    array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
229
-                ),
230
-                new EE_Meta_Capability_Map_Delete(
231
-                    'ee_delete_default_ticket',
232
-                    array('Ticket', '', 'ee_delete_others_default_tickets', '')
233
-                ),
234
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
235
-                    'ee_delete_question',
236
-                    array('Question', '', '', 'delete_system_questions')
237
-                ),
238
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
239
-                    'ee_delete_question_group',
240
-                    array('Question_Group', '', '', 'delete_system_question_groups')
241
-                ),
242
-                new EE_Meta_Capability_Map_Delete(
243
-                    'ee_delete_payment_method',
244
-                    array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
245
-                ),
246
-            );
247
-        }
248
-        return $default_meta_caps;
249
-    }
250
-
251
-
252
-    /**
253
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
254
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
255
-     *
256
-     * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
257
-     *
258
-     * @since 4.5.0
259
-     * @see   wp-includes/capabilities.php
260
-     *
261
-     * @param array  $caps    actual users capabilities
262
-     * @param string $cap     initial capability name that is being checked (the "map" key)
263
-     * @param int    $user_id The user id
264
-     * @param array  $args    Adds context to the cap. Typically the object ID.
265
-     * @return array actual users capabilities
266
-     * @throws EE_Error
267
-     */
268
-    public function map_meta_caps($caps, $cap, $user_id, $args)
269
-    {
270
-        if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
271
-            //loop through our _meta_caps array
272
-            foreach ($this->_meta_caps as $meta_map) {
273
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
274
-                    continue;
275
-                }
276
-                // don't load models if there is no object ID in the args
277
-                if(!empty($args[0])){
278
-                    $meta_map->ensure_is_model();
279
-                }
280
-                $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
281
-            }
282
-        }
283
-        return $caps;
284
-    }
285
-
286
-
287
-    /**
288
-     * This sets up and returns the initial capabilities map for Event Espresso
289
-     *
290
-     * @since 4.5.0
291
-     *
292
-     * @return array
293
-     */
294
-    private function _init_caps_map()
295
-    {
296
-        $caps = array(
297
-            'administrator'           => array(
298
-                //basic access
299
-                'ee_read_ee',
300
-                //gateways
301
-                /**
302
-                 * note that with payment method capabilities, although we've implemented
303
-                 * capability mapping which will be used for accessing payment methods owned by
304
-                 * other users.  This is not fully implemented yet in the payment method ui.
305
-                 * Currently only the "plural" caps are in active use.
306
-                 * (Specific payment method caps are in use as well).
307
-                 **/
308
-                'ee_manage_gateways',
309
-                'ee_read_payment_method',
310
-                'ee_read_payment_methods',
311
-                'ee_read_others_payment_methods',
312
-                'ee_edit_payment_method',
313
-                'ee_edit_payment_methods',
314
-                'ee_edit_others_payment_methods',
315
-                'ee_delete_payment_method',
316
-                'ee_delete_payment_methods',
317
-                //events
318
-                'ee_publish_events',
319
-                'ee_read_private_events',
320
-                'ee_read_others_events',
321
-                'ee_read_event',
322
-                'ee_read_events',
323
-                'ee_edit_event',
324
-                'ee_edit_events',
325
-                'ee_edit_published_events',
326
-                'ee_edit_others_events',
327
-                'ee_edit_private_events',
328
-                'ee_delete_published_events',
329
-                'ee_delete_private_events',
330
-                'ee_delete_event',
331
-                'ee_delete_events',
332
-                'ee_delete_others_events',
333
-                //event categories
334
-                'ee_manage_event_categories',
335
-                'ee_edit_event_category',
336
-                'ee_delete_event_category',
337
-                'ee_assign_event_category',
338
-                //venues
339
-                'ee_publish_venues',
340
-                'ee_read_venue',
341
-                'ee_read_venues',
342
-                'ee_read_others_venues',
343
-                'ee_read_private_venues',
344
-                'ee_edit_venue',
345
-                'ee_edit_venues',
346
-                'ee_edit_others_venues',
347
-                'ee_edit_published_venues',
348
-                'ee_edit_private_venues',
349
-                'ee_delete_venue',
350
-                'ee_delete_venues',
351
-                'ee_delete_others_venues',
352
-                'ee_delete_private_venues',
353
-                'ee_delete_published_venues',
354
-                //venue categories
355
-                'ee_manage_venue_categories',
356
-                'ee_edit_venue_category',
357
-                'ee_delete_venue_category',
358
-                'ee_assign_venue_category',
359
-                //contacts
360
-                'ee_read_contact',
361
-                'ee_read_contacts',
362
-                'ee_edit_contact',
363
-                'ee_edit_contacts',
364
-                'ee_delete_contact',
365
-                'ee_delete_contacts',
366
-                //registrations
367
-                'ee_read_registration',
368
-                'ee_read_registrations',
369
-                'ee_read_others_registrations',
370
-                'ee_edit_registration',
371
-                'ee_edit_registrations',
372
-                'ee_edit_others_registrations',
373
-                'ee_delete_registration',
374
-                'ee_delete_registrations',
375
-                //checkins
376
-                'ee_read_checkin',
377
-                'ee_read_others_checkins',
378
-                'ee_read_checkins',
379
-                'ee_edit_checkin',
380
-                'ee_edit_checkins',
381
-                'ee_edit_others_checkins',
382
-                'ee_delete_checkin',
383
-                'ee_delete_checkins',
384
-                'ee_delete_others_checkins',
385
-                //transactions && payments
386
-                'ee_read_transaction',
387
-                'ee_read_transactions',
388
-                'ee_edit_payments',
389
-                'ee_delete_payments',
390
-                //messages
391
-                'ee_read_message',
392
-                'ee_read_messages',
393
-                'ee_read_others_messages',
394
-                'ee_read_global_messages',
395
-                'ee_edit_global_messages',
396
-                'ee_edit_message',
397
-                'ee_edit_messages',
398
-                'ee_edit_others_messages',
399
-                'ee_delete_message',
400
-                'ee_delete_messages',
401
-                'ee_delete_others_messages',
402
-                'ee_delete_global_messages',
403
-                'ee_send_message',
404
-                //tickets
405
-                'ee_read_default_ticket',
406
-                'ee_read_default_tickets',
407
-                'ee_read_others_default_tickets',
408
-                'ee_edit_default_ticket',
409
-                'ee_edit_default_tickets',
410
-                'ee_edit_others_default_tickets',
411
-                'ee_delete_default_ticket',
412
-                'ee_delete_default_tickets',
413
-                'ee_delete_others_default_tickets',
414
-                //prices
415
-                'ee_edit_default_price',
416
-                'ee_edit_default_prices',
417
-                'ee_delete_default_price',
418
-                'ee_delete_default_prices',
419
-                'ee_edit_default_price_type',
420
-                'ee_edit_default_price_types',
421
-                'ee_delete_default_price_type',
422
-                'ee_delete_default_price_types',
423
-                'ee_read_default_prices',
424
-                'ee_read_default_price_types',
425
-                //registration form
426
-                'ee_edit_question',
427
-                'ee_edit_questions',
428
-                'ee_edit_system_questions',
429
-                'ee_read_questions',
430
-                'ee_delete_question',
431
-                'ee_delete_questions',
432
-                'ee_edit_question_group',
433
-                'ee_edit_question_groups',
434
-                'ee_read_question_groups',
435
-                'ee_edit_system_question_groups',
436
-                'ee_delete_question_group',
437
-                'ee_delete_question_groups',
438
-                //event_type taxonomy
439
-                'ee_assign_event_type',
440
-                'ee_manage_event_types',
441
-                'ee_edit_event_type',
442
-                'ee_delete_event_type',
443
-            ),
444
-            'ee_events_administrator' => array(
445
-                //core wp caps
446
-                'read',
447
-                'read_private_pages',
448
-                'read_private_posts',
449
-                'edit_users',
450
-                'edit_posts',
451
-                'edit_pages',
452
-                'edit_published_posts',
453
-                'edit_published_pages',
454
-                'edit_private_pages',
455
-                'edit_private_posts',
456
-                'edit_others_posts',
457
-                'edit_others_pages',
458
-                'publish_posts',
459
-                'publish_pages',
460
-                'delete_posts',
461
-                'delete_pages',
462
-                'delete_private_pages',
463
-                'delete_private_posts',
464
-                'delete_published_pages',
465
-                'delete_published_posts',
466
-                'delete_others_posts',
467
-                'delete_others_pages',
468
-                'manage_categories',
469
-                'manage_links',
470
-                'moderate_comments',
471
-                'unfiltered_html',
472
-                'upload_files',
473
-                'export',
474
-                'import',
475
-                'list_users',
476
-                'level_1', //required if user with this role shows up in author dropdowns
477
-                //basic ee access
478
-                'ee_read_ee',
479
-                //events
480
-                'ee_publish_events',
481
-                'ee_read_private_events',
482
-                'ee_read_others_events',
483
-                'ee_read_event',
484
-                'ee_read_events',
485
-                'ee_edit_event',
486
-                'ee_edit_events',
487
-                'ee_edit_published_events',
488
-                'ee_edit_others_events',
489
-                'ee_edit_private_events',
490
-                'ee_delete_published_events',
491
-                'ee_delete_private_events',
492
-                'ee_delete_event',
493
-                'ee_delete_events',
494
-                'ee_delete_others_events',
495
-                //event categories
496
-                'ee_manage_event_categories',
497
-                'ee_edit_event_category',
498
-                'ee_delete_event_category',
499
-                'ee_assign_event_category',
500
-                //venues
501
-                'ee_publish_venues',
502
-                'ee_read_venue',
503
-                'ee_read_venues',
504
-                'ee_read_others_venues',
505
-                'ee_read_private_venues',
506
-                'ee_edit_venue',
507
-                'ee_edit_venues',
508
-                'ee_edit_others_venues',
509
-                'ee_edit_published_venues',
510
-                'ee_edit_private_venues',
511
-                'ee_delete_venue',
512
-                'ee_delete_venues',
513
-                'ee_delete_others_venues',
514
-                'ee_delete_private_venues',
515
-                'ee_delete_published_venues',
516
-                //venue categories
517
-                'ee_manage_venue_categories',
518
-                'ee_edit_venue_category',
519
-                'ee_delete_venue_category',
520
-                'ee_assign_venue_category',
521
-                //contacts
522
-                'ee_read_contact',
523
-                'ee_read_contacts',
524
-                'ee_edit_contact',
525
-                'ee_edit_contacts',
526
-                'ee_delete_contact',
527
-                'ee_delete_contacts',
528
-                //registrations
529
-                'ee_read_registration',
530
-                'ee_read_registrations',
531
-                'ee_read_others_registrations',
532
-                'ee_edit_registration',
533
-                'ee_edit_registrations',
534
-                'ee_edit_others_registrations',
535
-                'ee_delete_registration',
536
-                'ee_delete_registrations',
537
-                //checkins
538
-                'ee_read_checkin',
539
-                'ee_read_others_checkins',
540
-                'ee_read_checkins',
541
-                'ee_edit_checkin',
542
-                'ee_edit_checkins',
543
-                'ee_edit_others_checkins',
544
-                'ee_delete_checkin',
545
-                'ee_delete_checkins',
546
-                'ee_delete_others_checkins',
547
-                //transactions && payments
548
-                'ee_read_transaction',
549
-                'ee_read_transactions',
550
-                'ee_edit_payments',
551
-                'ee_delete_payments',
552
-                //messages
553
-                'ee_read_message',
554
-                'ee_read_messages',
555
-                'ee_read_others_messages',
556
-                'ee_read_global_messages',
557
-                'ee_edit_global_messages',
558
-                'ee_edit_message',
559
-                'ee_edit_messages',
560
-                'ee_edit_others_messages',
561
-                'ee_delete_message',
562
-                'ee_delete_messages',
563
-                'ee_delete_others_messages',
564
-                'ee_delete_global_messages',
565
-                'ee_send_message',
566
-                //tickets
567
-                'ee_read_default_ticket',
568
-                'ee_read_default_tickets',
569
-                'ee_read_others_default_tickets',
570
-                'ee_edit_default_ticket',
571
-                'ee_edit_default_tickets',
572
-                'ee_edit_others_default_tickets',
573
-                'ee_delete_default_ticket',
574
-                'ee_delete_default_tickets',
575
-                'ee_delete_others_default_tickets',
576
-                //prices
577
-                'ee_edit_default_price',
578
-                'ee_edit_default_prices',
579
-                'ee_delete_default_price',
580
-                'ee_delete_default_prices',
581
-                'ee_edit_default_price_type',
582
-                'ee_edit_default_price_types',
583
-                'ee_delete_default_price_type',
584
-                'ee_delete_default_price_types',
585
-                'ee_read_default_prices',
586
-                'ee_read_default_price_types',
587
-                //registration form
588
-                'ee_edit_question',
589
-                'ee_edit_questions',
590
-                'ee_edit_system_questions',
591
-                'ee_read_questions',
592
-                'ee_delete_question',
593
-                'ee_delete_questions',
594
-                'ee_edit_question_group',
595
-                'ee_edit_question_groups',
596
-                'ee_read_question_groups',
597
-                'ee_edit_system_question_groups',
598
-                'ee_delete_question_group',
599
-                'ee_delete_question_groups',
600
-                //event_type taxonomy
601
-                'ee_assign_event_type',
602
-                'ee_manage_event_types',
603
-                'ee_edit_event_type',
604
-                'ee_delete_event_type',
605
-            )
606
-        );
607
-        $caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps);
608
-        return $caps;
609
-    }
610
-
611
-
612
-    /**
613
-     * This adds all the default caps to roles as registered in the _caps_map property.
614
-     *
615
-     * @since 4.5.0
616
-     *
617
-     * @param bool  $reset      allows for resetting the default capabilities saved on roles.  Note that this doesn't
618
-     *                          actually REMOVE any capabilities from existing roles, it just resaves defaults roles
619
-     *                          and ensures that they are up to date.
620
-     * @param array $custom_map Optional.  Can be used to send a custom map of roles and capabilities for setting them
621
-     *                          up.  Note that this should ONLY be called on activation hook or some other one-time
622
-     *                          task otherwise the caps will be added on every request.
623
-     *
624
-     * @return void
625
-     */
626
-    public function init_role_caps($reset = false, $custom_map = array())
627
-    {
628
-        $caps_map = empty($custom_map) ? $this->_caps_map : $custom_map;
629
-        //first let's determine if these caps have already been set.
630
-        $caps_set_before = get_option(self::option_name, array());
631
-        //if not reset, see what caps are new for each role. if they're new, add them.
632
-        foreach ($caps_map as $role => $caps_for_role) {
633
-            foreach ($caps_for_role as $cap) {
634
-                //first check we haven't already added this cap before, or it's a reset
635
-                if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) {
636
-                    if ($this->add_cap_to_role($role, $cap)) {
637
-                        $caps_set_before[ $role ][] = $cap;
638
-                    }
639
-                }
640
-            }
641
-        }
642
-        //now let's just save the cap that has been set.
643
-        update_option(self::option_name, $caps_set_before);
644
-        do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before);
645
-    }
646
-
647
-
648
-    /**
649
-     * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
650
-     * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
651
-     * this is a wrapper for $wp_role->add_cap()
652
-     *
653
-     * @see   wp-includes/capabilities.php
654
-     *
655
-     * @since 4.5.0
656
-     *
657
-     * @param string $role  A WordPress role the capability is being added to
658
-     * @param string $cap   The capability being added to the role
659
-     * @param bool   $grant Whether to grant access to this cap on this role.
660
-     *
661
-     * @return bool
662
-     */
663
-    public function add_cap_to_role($role, $cap, $grant = true)
664
-    {
665
-        $role_object = get_role($role);
666
-        //if the role isn't available then we create it.
667
-        if (! $role_object instanceof WP_Role) {
668
-            //if a plugin wants to create a specific role name then they should create the role before
669
-            //EE_Capabilities does.  Otherwise this function will create the role name from the slug:
670
-            // - removes any `ee_` namespacing from the start of the slug.
671
-            // - replaces `_` with ` ` (empty space).
672
-            // - sentence case on the resulting string.
673
-            $role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role)));
674
-            $role_object = add_role($role, $role_label);
675
-        }
676
-        if ($role_object instanceof WP_Role) {
677
-            $role_object->add_cap($cap, $grant);
678
-            return true;
679
-        }
680
-        return false;
681
-    }
682
-
683
-
684
-    /**
685
-     * Functions similarly to add_cap_to_role except removes cap from given role.
686
-     * Wrapper for $wp_role->remove_cap()
687
-     *
688
-     * @see   wp-includes/capabilities.php
689
-     * @since 4.5.0
690
-     *
691
-     * @param string $role A WordPress role the capability is being removed from.
692
-     * @param string $cap  The capability being removed
693
-     *
694
-     * @return void
695
-     */
696
-    public function remove_cap_from_role($role, $cap)
697
-    {
698
-        $role = get_role($role);
699
-        if ($role instanceof WP_Role) {
700
-            $role->remove_cap($cap);
701
-        }
702
-    }
703
-
704
-
705
-    /**
706
-     * Wrapper for the native WP current_user_can() method.
707
-     * This is provided as a handy method for a couple things:
708
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
709
-     * write those filters wherever current_user_can is called).
710
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
711
-     *
712
-     * @since 4.5.0
713
-     *
714
-     * @param string $cap     The cap being checked.
715
-     * @param string $context The context where the current_user_can is being called from.
716
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
717
-     *                        filters.
718
-     *
719
-     * @return bool  Whether user can or not.
720
-     */
721
-    public function current_user_can($cap, $context, $id = 0)
722
-    {
723
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
724
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
725
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap,
726
-            $id);
727
-        return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap);
728
-    }
729
-
730
-
731
-    /**
732
-     * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
733
-     *
734
-     * @param int|WP_User $user    Either the user_id or a WP_User object
735
-     * @param string      $cap     The capability string being checked
736
-     * @param string      $context The context where the user_can is being called from (used in filters).
737
-     * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
738
-     *                             filters)
739
-     *
740
-     * @return bool Whether user can or not.
741
-     */
742
-    public function user_can($user, $cap, $context, $id = 0)
743
-    {
744
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
745
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
746
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user,
747
-            $id);
748
-        return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap);
749
-    }
750
-
751
-
752
-    /**
753
-     * Wrapper for the native WP current_user_can_for_blog() method.
754
-     * This is provided as a handy method for a couple things:
755
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
756
-     * write those filters wherever current_user_can is called).
757
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
758
-     *
759
-     * @since 4.5.0
760
-     *
761
-     * @param int    $blog_id The blog id that is being checked for.
762
-     * @param string $cap     The cap being checked.
763
-     * @param string $context The context where the current_user_can is being called from.
764
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
765
-     *                        filters.
766
-     *
767
-     * @return bool  Whether user can or not.
768
-     */
769
-    public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
770
-    {
771
-        $user_can = ! empty($id)
772
-            ? current_user_can_for_blog($blog_id, $cap, $id)
773
-            : current_user_can($blog_id, $cap);
774
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
775
-        $user_can = apply_filters(
776
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
777
-            $user_can,
778
-            $blog_id,
779
-            $cap,
780
-            $id
781
-        );
782
-        $user_can = apply_filters(
783
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
784
-            $user_can,
785
-            $context,
786
-            $blog_id,
787
-            $cap,
788
-            $id
789
-        );
790
-        return $user_can;
791
-    }
792
-
793
-
794
-    /**
795
-     * This helper method just returns an array of registered EE capabilities.
796
-     * Note this array is filtered.  It is assumed that all available EE capabilities are assigned to the administrator
797
-     * role.
798
-     *
799
-     * @since 4.5.0
800
-     *
801
-     * @param string $role If empty then the entire role/capability map is returned.  Otherwise just the capabilities
802
-     *                     for the given role are returned.
803
-     *
804
-     * @return array
805
-     */
806
-    public function get_ee_capabilities($role = 'administrator')
807
-    {
808
-        $capabilities = $this->_init_caps_map();
809
-        if (empty($role)) {
810
-            return $capabilities;
811
-        }
812
-        return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array();
813
-    }
20
+	/**
21
+	 * the name of the wp option used to store caps previously initialized
22
+	 */
23
+	const option_name = 'ee_caps_initialized';
24
+
25
+	/**
26
+	 * instance of EE_Capabilities object
27
+	 *
28
+	 * @var EE_Capabilities
29
+	 */
30
+	private static $_instance;
31
+
32
+
33
+	/**
34
+	 * This is a map of caps that correspond to a default WP_Role.
35
+	 * Array is indexed by Role and values are ee capabilities.
36
+	 *
37
+	 * @since 4.5.0
38
+	 *
39
+	 * @var array
40
+	 */
41
+	private $_caps_map = array();
42
+
43
+
44
+	/**
45
+	 * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for
46
+	 * a user depending on context.
47
+	 *
48
+	 * @var EE_Meta_Capability_Map[]
49
+	 */
50
+	private $_meta_caps = array();
51
+
52
+
53
+	/**
54
+	 * singleton method used to instantiate class object
55
+	 *
56
+	 * @since 4.5.0
57
+	 *
58
+	 * @return EE_Capabilities
59
+	 */
60
+	public static function instance()
61
+	{
62
+		//check if instantiated, and if not do so.
63
+		if (! self::$_instance instanceof EE_Capabilities) {
64
+			self::$_instance = new self();
65
+		}
66
+		return self::$_instance;
67
+	}
68
+
69
+
70
+	/**
71
+	 * private constructor
72
+	 *
73
+	 * @since 4.5.0
74
+	 *
75
+	 * @return \EE_Capabilities
76
+	 */
77
+	private function __construct()
78
+	{
79
+	}
80
+
81
+
82
+	/**
83
+	 * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
84
+	 *
85
+	 * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
86
+	 *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
87
+	 *                    ensures that they are up to date.
88
+	 *
89
+	 *
90
+	 * @since 4.5.0
91
+	 * @return void
92
+	 */
93
+	public function init_caps($reset = false)
94
+	{
95
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
96
+			$this->_caps_map = $this->_init_caps_map();
97
+			$this->init_role_caps($reset);
98
+			$this->_set_meta_caps();
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * This sets the meta caps property.
105
+	 * @since 4.5.0
106
+	 *
107
+	 * @return void
108
+	 */
109
+	private function _set_meta_caps()
110
+	{
111
+		//make sure we're only ever initializing the default _meta_caps array once if it's empty.
112
+		$this->_meta_caps = $this->_get_default_meta_caps_array();
113
+		$this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps);
114
+		//add filter for map_meta_caps but only if models can query.
115
+		if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
116
+			add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
117
+		}
118
+	}
119
+
120
+
121
+	/**
122
+	 * This builds and returns the default meta_caps array only once.
123
+	 *
124
+	 * @since  4.8.28.rc.012
125
+	 * @return array
126
+	 * @throws \EE_Error
127
+	 */
128
+	private function _get_default_meta_caps_array()
129
+	{
130
+		static $default_meta_caps = array();
131
+		if (empty($default_meta_caps)) {
132
+			$default_meta_caps = array(
133
+				//edits
134
+				new EE_Meta_Capability_Map_Edit(
135
+					'ee_edit_event',
136
+					array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
137
+				),
138
+				new EE_Meta_Capability_Map_Edit(
139
+					'ee_edit_venue',
140
+					array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
141
+				),
142
+				new EE_Meta_Capability_Map_Edit(
143
+					'ee_edit_registration',
144
+					array('Registration', '', 'ee_edit_others_registrations', '')
145
+				),
146
+				new EE_Meta_Capability_Map_Edit(
147
+					'ee_edit_checkin',
148
+					array('Registration', '', 'ee_edit_others_checkins', '')
149
+				),
150
+				new EE_Meta_Capability_Map_Messages_Cap(
151
+					'ee_edit_message',
152
+					array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
153
+				),
154
+				new EE_Meta_Capability_Map_Edit(
155
+					'ee_edit_default_ticket',
156
+					array('Ticket', '', 'ee_edit_others_default_tickets', '')
157
+				),
158
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
159
+					'ee_edit_question',
160
+					array('Question', '', '', 'ee_edit_system_questions')
161
+				),
162
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
163
+					'ee_edit_question_group',
164
+					array('Question_Group', '', '', 'ee_edit_system_question_groups')
165
+				),
166
+				new EE_Meta_Capability_Map_Edit(
167
+					'ee_edit_payment_method',
168
+					array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
169
+				),
170
+				//reads
171
+				new EE_Meta_Capability_Map_Read(
172
+					'ee_read_event',
173
+					array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
174
+				),
175
+				new EE_Meta_Capability_Map_Read(
176
+					'ee_read_venue',
177
+					array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
178
+				),
179
+				new EE_Meta_Capability_Map_Read(
180
+					'ee_read_registration',
181
+					array('Registration', '', '', 'ee_edit_others_registrations')
182
+				),
183
+				new EE_Meta_Capability_Map_Read(
184
+					'ee_read_checkin',
185
+					array('Registration', '', '', 'ee_read_others_checkins')
186
+				),
187
+				new EE_Meta_Capability_Map_Messages_Cap(
188
+					'ee_read_message',
189
+					array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
190
+				),
191
+				new EE_Meta_Capability_Map_Read(
192
+					'ee_read_default_ticket',
193
+					array('Ticket', '', '', 'ee_read_others_default_tickets')
194
+				),
195
+				new EE_Meta_Capability_Map_Read(
196
+					'ee_read_payment_method',
197
+					array('Payment_Method', '', '', 'ee_read_others_payment_methods')),
198
+
199
+				//deletes
200
+				new EE_Meta_Capability_Map_Delete(
201
+					'ee_delete_event',
202
+					array(
203
+						'Event',
204
+						'ee_delete_published_events',
205
+						'ee_delete_others_events',
206
+						'ee_delete_private_events',
207
+					)
208
+				),
209
+				new EE_Meta_Capability_Map_Delete(
210
+					'ee_delete_venue',
211
+					array(
212
+						'Venue',
213
+						'ee_delete_published_venues',
214
+						'ee_delete_others_venues',
215
+						'ee_delete_private_venues',
216
+					)
217
+				),
218
+				new EE_Meta_Capability_Map_Delete(
219
+					'ee_delete_registration',
220
+					array('Registration', '', 'ee_delete_others_registrations', '')
221
+				),
222
+				new EE_Meta_Capability_Map_Delete(
223
+					'ee_delete_checkin',
224
+					array('Registration', '', 'ee_delete_others_checkins', '')
225
+				),
226
+				new EE_Meta_Capability_Map_Messages_Cap(
227
+					'ee_delete_message',
228
+					array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
229
+				),
230
+				new EE_Meta_Capability_Map_Delete(
231
+					'ee_delete_default_ticket',
232
+					array('Ticket', '', 'ee_delete_others_default_tickets', '')
233
+				),
234
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
235
+					'ee_delete_question',
236
+					array('Question', '', '', 'delete_system_questions')
237
+				),
238
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
239
+					'ee_delete_question_group',
240
+					array('Question_Group', '', '', 'delete_system_question_groups')
241
+				),
242
+				new EE_Meta_Capability_Map_Delete(
243
+					'ee_delete_payment_method',
244
+					array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
245
+				),
246
+			);
247
+		}
248
+		return $default_meta_caps;
249
+	}
250
+
251
+
252
+	/**
253
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
254
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
255
+	 *
256
+	 * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
257
+	 *
258
+	 * @since 4.5.0
259
+	 * @see   wp-includes/capabilities.php
260
+	 *
261
+	 * @param array  $caps    actual users capabilities
262
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
263
+	 * @param int    $user_id The user id
264
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
265
+	 * @return array actual users capabilities
266
+	 * @throws EE_Error
267
+	 */
268
+	public function map_meta_caps($caps, $cap, $user_id, $args)
269
+	{
270
+		if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
271
+			//loop through our _meta_caps array
272
+			foreach ($this->_meta_caps as $meta_map) {
273
+				if (! $meta_map instanceof EE_Meta_Capability_Map) {
274
+					continue;
275
+				}
276
+				// don't load models if there is no object ID in the args
277
+				if(!empty($args[0])){
278
+					$meta_map->ensure_is_model();
279
+				}
280
+				$caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
281
+			}
282
+		}
283
+		return $caps;
284
+	}
285
+
286
+
287
+	/**
288
+	 * This sets up and returns the initial capabilities map for Event Espresso
289
+	 *
290
+	 * @since 4.5.0
291
+	 *
292
+	 * @return array
293
+	 */
294
+	private function _init_caps_map()
295
+	{
296
+		$caps = array(
297
+			'administrator'           => array(
298
+				//basic access
299
+				'ee_read_ee',
300
+				//gateways
301
+				/**
302
+				 * note that with payment method capabilities, although we've implemented
303
+				 * capability mapping which will be used for accessing payment methods owned by
304
+				 * other users.  This is not fully implemented yet in the payment method ui.
305
+				 * Currently only the "plural" caps are in active use.
306
+				 * (Specific payment method caps are in use as well).
307
+				 **/
308
+				'ee_manage_gateways',
309
+				'ee_read_payment_method',
310
+				'ee_read_payment_methods',
311
+				'ee_read_others_payment_methods',
312
+				'ee_edit_payment_method',
313
+				'ee_edit_payment_methods',
314
+				'ee_edit_others_payment_methods',
315
+				'ee_delete_payment_method',
316
+				'ee_delete_payment_methods',
317
+				//events
318
+				'ee_publish_events',
319
+				'ee_read_private_events',
320
+				'ee_read_others_events',
321
+				'ee_read_event',
322
+				'ee_read_events',
323
+				'ee_edit_event',
324
+				'ee_edit_events',
325
+				'ee_edit_published_events',
326
+				'ee_edit_others_events',
327
+				'ee_edit_private_events',
328
+				'ee_delete_published_events',
329
+				'ee_delete_private_events',
330
+				'ee_delete_event',
331
+				'ee_delete_events',
332
+				'ee_delete_others_events',
333
+				//event categories
334
+				'ee_manage_event_categories',
335
+				'ee_edit_event_category',
336
+				'ee_delete_event_category',
337
+				'ee_assign_event_category',
338
+				//venues
339
+				'ee_publish_venues',
340
+				'ee_read_venue',
341
+				'ee_read_venues',
342
+				'ee_read_others_venues',
343
+				'ee_read_private_venues',
344
+				'ee_edit_venue',
345
+				'ee_edit_venues',
346
+				'ee_edit_others_venues',
347
+				'ee_edit_published_venues',
348
+				'ee_edit_private_venues',
349
+				'ee_delete_venue',
350
+				'ee_delete_venues',
351
+				'ee_delete_others_venues',
352
+				'ee_delete_private_venues',
353
+				'ee_delete_published_venues',
354
+				//venue categories
355
+				'ee_manage_venue_categories',
356
+				'ee_edit_venue_category',
357
+				'ee_delete_venue_category',
358
+				'ee_assign_venue_category',
359
+				//contacts
360
+				'ee_read_contact',
361
+				'ee_read_contacts',
362
+				'ee_edit_contact',
363
+				'ee_edit_contacts',
364
+				'ee_delete_contact',
365
+				'ee_delete_contacts',
366
+				//registrations
367
+				'ee_read_registration',
368
+				'ee_read_registrations',
369
+				'ee_read_others_registrations',
370
+				'ee_edit_registration',
371
+				'ee_edit_registrations',
372
+				'ee_edit_others_registrations',
373
+				'ee_delete_registration',
374
+				'ee_delete_registrations',
375
+				//checkins
376
+				'ee_read_checkin',
377
+				'ee_read_others_checkins',
378
+				'ee_read_checkins',
379
+				'ee_edit_checkin',
380
+				'ee_edit_checkins',
381
+				'ee_edit_others_checkins',
382
+				'ee_delete_checkin',
383
+				'ee_delete_checkins',
384
+				'ee_delete_others_checkins',
385
+				//transactions && payments
386
+				'ee_read_transaction',
387
+				'ee_read_transactions',
388
+				'ee_edit_payments',
389
+				'ee_delete_payments',
390
+				//messages
391
+				'ee_read_message',
392
+				'ee_read_messages',
393
+				'ee_read_others_messages',
394
+				'ee_read_global_messages',
395
+				'ee_edit_global_messages',
396
+				'ee_edit_message',
397
+				'ee_edit_messages',
398
+				'ee_edit_others_messages',
399
+				'ee_delete_message',
400
+				'ee_delete_messages',
401
+				'ee_delete_others_messages',
402
+				'ee_delete_global_messages',
403
+				'ee_send_message',
404
+				//tickets
405
+				'ee_read_default_ticket',
406
+				'ee_read_default_tickets',
407
+				'ee_read_others_default_tickets',
408
+				'ee_edit_default_ticket',
409
+				'ee_edit_default_tickets',
410
+				'ee_edit_others_default_tickets',
411
+				'ee_delete_default_ticket',
412
+				'ee_delete_default_tickets',
413
+				'ee_delete_others_default_tickets',
414
+				//prices
415
+				'ee_edit_default_price',
416
+				'ee_edit_default_prices',
417
+				'ee_delete_default_price',
418
+				'ee_delete_default_prices',
419
+				'ee_edit_default_price_type',
420
+				'ee_edit_default_price_types',
421
+				'ee_delete_default_price_type',
422
+				'ee_delete_default_price_types',
423
+				'ee_read_default_prices',
424
+				'ee_read_default_price_types',
425
+				//registration form
426
+				'ee_edit_question',
427
+				'ee_edit_questions',
428
+				'ee_edit_system_questions',
429
+				'ee_read_questions',
430
+				'ee_delete_question',
431
+				'ee_delete_questions',
432
+				'ee_edit_question_group',
433
+				'ee_edit_question_groups',
434
+				'ee_read_question_groups',
435
+				'ee_edit_system_question_groups',
436
+				'ee_delete_question_group',
437
+				'ee_delete_question_groups',
438
+				//event_type taxonomy
439
+				'ee_assign_event_type',
440
+				'ee_manage_event_types',
441
+				'ee_edit_event_type',
442
+				'ee_delete_event_type',
443
+			),
444
+			'ee_events_administrator' => array(
445
+				//core wp caps
446
+				'read',
447
+				'read_private_pages',
448
+				'read_private_posts',
449
+				'edit_users',
450
+				'edit_posts',
451
+				'edit_pages',
452
+				'edit_published_posts',
453
+				'edit_published_pages',
454
+				'edit_private_pages',
455
+				'edit_private_posts',
456
+				'edit_others_posts',
457
+				'edit_others_pages',
458
+				'publish_posts',
459
+				'publish_pages',
460
+				'delete_posts',
461
+				'delete_pages',
462
+				'delete_private_pages',
463
+				'delete_private_posts',
464
+				'delete_published_pages',
465
+				'delete_published_posts',
466
+				'delete_others_posts',
467
+				'delete_others_pages',
468
+				'manage_categories',
469
+				'manage_links',
470
+				'moderate_comments',
471
+				'unfiltered_html',
472
+				'upload_files',
473
+				'export',
474
+				'import',
475
+				'list_users',
476
+				'level_1', //required if user with this role shows up in author dropdowns
477
+				//basic ee access
478
+				'ee_read_ee',
479
+				//events
480
+				'ee_publish_events',
481
+				'ee_read_private_events',
482
+				'ee_read_others_events',
483
+				'ee_read_event',
484
+				'ee_read_events',
485
+				'ee_edit_event',
486
+				'ee_edit_events',
487
+				'ee_edit_published_events',
488
+				'ee_edit_others_events',
489
+				'ee_edit_private_events',
490
+				'ee_delete_published_events',
491
+				'ee_delete_private_events',
492
+				'ee_delete_event',
493
+				'ee_delete_events',
494
+				'ee_delete_others_events',
495
+				//event categories
496
+				'ee_manage_event_categories',
497
+				'ee_edit_event_category',
498
+				'ee_delete_event_category',
499
+				'ee_assign_event_category',
500
+				//venues
501
+				'ee_publish_venues',
502
+				'ee_read_venue',
503
+				'ee_read_venues',
504
+				'ee_read_others_venues',
505
+				'ee_read_private_venues',
506
+				'ee_edit_venue',
507
+				'ee_edit_venues',
508
+				'ee_edit_others_venues',
509
+				'ee_edit_published_venues',
510
+				'ee_edit_private_venues',
511
+				'ee_delete_venue',
512
+				'ee_delete_venues',
513
+				'ee_delete_others_venues',
514
+				'ee_delete_private_venues',
515
+				'ee_delete_published_venues',
516
+				//venue categories
517
+				'ee_manage_venue_categories',
518
+				'ee_edit_venue_category',
519
+				'ee_delete_venue_category',
520
+				'ee_assign_venue_category',
521
+				//contacts
522
+				'ee_read_contact',
523
+				'ee_read_contacts',
524
+				'ee_edit_contact',
525
+				'ee_edit_contacts',
526
+				'ee_delete_contact',
527
+				'ee_delete_contacts',
528
+				//registrations
529
+				'ee_read_registration',
530
+				'ee_read_registrations',
531
+				'ee_read_others_registrations',
532
+				'ee_edit_registration',
533
+				'ee_edit_registrations',
534
+				'ee_edit_others_registrations',
535
+				'ee_delete_registration',
536
+				'ee_delete_registrations',
537
+				//checkins
538
+				'ee_read_checkin',
539
+				'ee_read_others_checkins',
540
+				'ee_read_checkins',
541
+				'ee_edit_checkin',
542
+				'ee_edit_checkins',
543
+				'ee_edit_others_checkins',
544
+				'ee_delete_checkin',
545
+				'ee_delete_checkins',
546
+				'ee_delete_others_checkins',
547
+				//transactions && payments
548
+				'ee_read_transaction',
549
+				'ee_read_transactions',
550
+				'ee_edit_payments',
551
+				'ee_delete_payments',
552
+				//messages
553
+				'ee_read_message',
554
+				'ee_read_messages',
555
+				'ee_read_others_messages',
556
+				'ee_read_global_messages',
557
+				'ee_edit_global_messages',
558
+				'ee_edit_message',
559
+				'ee_edit_messages',
560
+				'ee_edit_others_messages',
561
+				'ee_delete_message',
562
+				'ee_delete_messages',
563
+				'ee_delete_others_messages',
564
+				'ee_delete_global_messages',
565
+				'ee_send_message',
566
+				//tickets
567
+				'ee_read_default_ticket',
568
+				'ee_read_default_tickets',
569
+				'ee_read_others_default_tickets',
570
+				'ee_edit_default_ticket',
571
+				'ee_edit_default_tickets',
572
+				'ee_edit_others_default_tickets',
573
+				'ee_delete_default_ticket',
574
+				'ee_delete_default_tickets',
575
+				'ee_delete_others_default_tickets',
576
+				//prices
577
+				'ee_edit_default_price',
578
+				'ee_edit_default_prices',
579
+				'ee_delete_default_price',
580
+				'ee_delete_default_prices',
581
+				'ee_edit_default_price_type',
582
+				'ee_edit_default_price_types',
583
+				'ee_delete_default_price_type',
584
+				'ee_delete_default_price_types',
585
+				'ee_read_default_prices',
586
+				'ee_read_default_price_types',
587
+				//registration form
588
+				'ee_edit_question',
589
+				'ee_edit_questions',
590
+				'ee_edit_system_questions',
591
+				'ee_read_questions',
592
+				'ee_delete_question',
593
+				'ee_delete_questions',
594
+				'ee_edit_question_group',
595
+				'ee_edit_question_groups',
596
+				'ee_read_question_groups',
597
+				'ee_edit_system_question_groups',
598
+				'ee_delete_question_group',
599
+				'ee_delete_question_groups',
600
+				//event_type taxonomy
601
+				'ee_assign_event_type',
602
+				'ee_manage_event_types',
603
+				'ee_edit_event_type',
604
+				'ee_delete_event_type',
605
+			)
606
+		);
607
+		$caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps);
608
+		return $caps;
609
+	}
610
+
611
+
612
+	/**
613
+	 * This adds all the default caps to roles as registered in the _caps_map property.
614
+	 *
615
+	 * @since 4.5.0
616
+	 *
617
+	 * @param bool  $reset      allows for resetting the default capabilities saved on roles.  Note that this doesn't
618
+	 *                          actually REMOVE any capabilities from existing roles, it just resaves defaults roles
619
+	 *                          and ensures that they are up to date.
620
+	 * @param array $custom_map Optional.  Can be used to send a custom map of roles and capabilities for setting them
621
+	 *                          up.  Note that this should ONLY be called on activation hook or some other one-time
622
+	 *                          task otherwise the caps will be added on every request.
623
+	 *
624
+	 * @return void
625
+	 */
626
+	public function init_role_caps($reset = false, $custom_map = array())
627
+	{
628
+		$caps_map = empty($custom_map) ? $this->_caps_map : $custom_map;
629
+		//first let's determine if these caps have already been set.
630
+		$caps_set_before = get_option(self::option_name, array());
631
+		//if not reset, see what caps are new for each role. if they're new, add them.
632
+		foreach ($caps_map as $role => $caps_for_role) {
633
+			foreach ($caps_for_role as $cap) {
634
+				//first check we haven't already added this cap before, or it's a reset
635
+				if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) {
636
+					if ($this->add_cap_to_role($role, $cap)) {
637
+						$caps_set_before[ $role ][] = $cap;
638
+					}
639
+				}
640
+			}
641
+		}
642
+		//now let's just save the cap that has been set.
643
+		update_option(self::option_name, $caps_set_before);
644
+		do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before);
645
+	}
646
+
647
+
648
+	/**
649
+	 * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
650
+	 * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
651
+	 * this is a wrapper for $wp_role->add_cap()
652
+	 *
653
+	 * @see   wp-includes/capabilities.php
654
+	 *
655
+	 * @since 4.5.0
656
+	 *
657
+	 * @param string $role  A WordPress role the capability is being added to
658
+	 * @param string $cap   The capability being added to the role
659
+	 * @param bool   $grant Whether to grant access to this cap on this role.
660
+	 *
661
+	 * @return bool
662
+	 */
663
+	public function add_cap_to_role($role, $cap, $grant = true)
664
+	{
665
+		$role_object = get_role($role);
666
+		//if the role isn't available then we create it.
667
+		if (! $role_object instanceof WP_Role) {
668
+			//if a plugin wants to create a specific role name then they should create the role before
669
+			//EE_Capabilities does.  Otherwise this function will create the role name from the slug:
670
+			// - removes any `ee_` namespacing from the start of the slug.
671
+			// - replaces `_` with ` ` (empty space).
672
+			// - sentence case on the resulting string.
673
+			$role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role)));
674
+			$role_object = add_role($role, $role_label);
675
+		}
676
+		if ($role_object instanceof WP_Role) {
677
+			$role_object->add_cap($cap, $grant);
678
+			return true;
679
+		}
680
+		return false;
681
+	}
682
+
683
+
684
+	/**
685
+	 * Functions similarly to add_cap_to_role except removes cap from given role.
686
+	 * Wrapper for $wp_role->remove_cap()
687
+	 *
688
+	 * @see   wp-includes/capabilities.php
689
+	 * @since 4.5.0
690
+	 *
691
+	 * @param string $role A WordPress role the capability is being removed from.
692
+	 * @param string $cap  The capability being removed
693
+	 *
694
+	 * @return void
695
+	 */
696
+	public function remove_cap_from_role($role, $cap)
697
+	{
698
+		$role = get_role($role);
699
+		if ($role instanceof WP_Role) {
700
+			$role->remove_cap($cap);
701
+		}
702
+	}
703
+
704
+
705
+	/**
706
+	 * Wrapper for the native WP current_user_can() method.
707
+	 * This is provided as a handy method for a couple things:
708
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
709
+	 * write those filters wherever current_user_can is called).
710
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
711
+	 *
712
+	 * @since 4.5.0
713
+	 *
714
+	 * @param string $cap     The cap being checked.
715
+	 * @param string $context The context where the current_user_can is being called from.
716
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
717
+	 *                        filters.
718
+	 *
719
+	 * @return bool  Whether user can or not.
720
+	 */
721
+	public function current_user_can($cap, $context, $id = 0)
722
+	{
723
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
724
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
725
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap,
726
+			$id);
727
+		return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap);
728
+	}
729
+
730
+
731
+	/**
732
+	 * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
733
+	 *
734
+	 * @param int|WP_User $user    Either the user_id or a WP_User object
735
+	 * @param string      $cap     The capability string being checked
736
+	 * @param string      $context The context where the user_can is being called from (used in filters).
737
+	 * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
738
+	 *                             filters)
739
+	 *
740
+	 * @return bool Whether user can or not.
741
+	 */
742
+	public function user_can($user, $cap, $context, $id = 0)
743
+	{
744
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
745
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
746
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user,
747
+			$id);
748
+		return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap);
749
+	}
750
+
751
+
752
+	/**
753
+	 * Wrapper for the native WP current_user_can_for_blog() method.
754
+	 * This is provided as a handy method for a couple things:
755
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
756
+	 * write those filters wherever current_user_can is called).
757
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
758
+	 *
759
+	 * @since 4.5.0
760
+	 *
761
+	 * @param int    $blog_id The blog id that is being checked for.
762
+	 * @param string $cap     The cap being checked.
763
+	 * @param string $context The context where the current_user_can is being called from.
764
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
765
+	 *                        filters.
766
+	 *
767
+	 * @return bool  Whether user can or not.
768
+	 */
769
+	public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
770
+	{
771
+		$user_can = ! empty($id)
772
+			? current_user_can_for_blog($blog_id, $cap, $id)
773
+			: current_user_can($blog_id, $cap);
774
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
775
+		$user_can = apply_filters(
776
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
777
+			$user_can,
778
+			$blog_id,
779
+			$cap,
780
+			$id
781
+		);
782
+		$user_can = apply_filters(
783
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
784
+			$user_can,
785
+			$context,
786
+			$blog_id,
787
+			$cap,
788
+			$id
789
+		);
790
+		return $user_can;
791
+	}
792
+
793
+
794
+	/**
795
+	 * This helper method just returns an array of registered EE capabilities.
796
+	 * Note this array is filtered.  It is assumed that all available EE capabilities are assigned to the administrator
797
+	 * role.
798
+	 *
799
+	 * @since 4.5.0
800
+	 *
801
+	 * @param string $role If empty then the entire role/capability map is returned.  Otherwise just the capabilities
802
+	 *                     for the given role are returned.
803
+	 *
804
+	 * @return array
805
+	 */
806
+	public function get_ee_capabilities($role = 'administrator')
807
+	{
808
+		$capabilities = $this->_init_caps_map();
809
+		if (empty($role)) {
810
+			return $capabilities;
811
+		}
812
+		return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array();
813
+	}
814 814
 }
815 815
 
816 816
 
@@ -827,142 +827,142 @@  discard block
 block discarded – undo
827 827
 abstract class EE_Meta_Capability_Map
828 828
 {
829 829
 
830
-    public $meta_cap;
831
-
832
-    /**
833
-     * @var EEM_Base
834
-     */
835
-    protected $_model;
836
-
837
-    protected $_model_name;
838
-
839
-    public $published_cap = '';
840
-
841
-    public $others_cap = '';
842
-
843
-    public $private_cap = '';
844
-
845
-
846
-    /**
847
-     * constructor.
848
-     * Receives the setup arguments for the map.
849
-     *
850
-     * @since                        4.5.0
851
-     *
852
-     * @param string $meta_cap   What meta capability is this mapping.
853
-     * @param array  $map_values array {
854
-     *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
855
-     *                           capabilities that don't get mapped to.
856
-     *
857
-     * @type         $map_values [0] string A string representing the model name. Required.  String's
858
-     *                               should always be used when Menu Maps are registered via the
859
-     *                               plugin API as models are not allowed to be instantiated when
860
-     *                               in maintenance mode 2 (migrations).
861
-     * @type         $map_values [1] string represents the capability used for published. Optional.
862
-     * @type         $map_values [2] string represents the capability used for "others". Optional.
863
-     * @type         $map_values [3] string represents the capability used for private. Optional.
864
-     *                               }
865
-     * @throws EE_Error
866
-     */
867
-    public function __construct($meta_cap, $map_values)
868
-    {
869
-        $this->meta_cap = $meta_cap;
870
-        //verify there are four args in the $map_values array;
871
-        if (count($map_values) !== 4) {
872
-            throw new EE_Error(
873
-                sprintf(
874
-                    __(
875
-                        'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
876
-                        'event_espresso'
877
-                    ),
878
-                    '<br>' . print_r($map_values, true)
879
-                )
880
-            );
881
-        }
882
-        //set properties
883
-        $this->_model = null;
884
-        $this->_model_name = $map_values[0];
885
-        $this->published_cap = (string)$map_values[1];
886
-        $this->others_cap = (string)$map_values[2];
887
-        $this->private_cap = (string)$map_values[3];
888
-    }
889
-
890
-    /**
891
-     * Makes it so this object stops filtering caps
892
-     */
893
-    public function remove_filters()
894
-    {
895
-        remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
896
-    }
897
-
898
-
899
-    /**
900
-     * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
901
-     *
902
-     * @since 4.5.0
903
-     * @throws EE_Error
904
-     *
905
-     * @return void
906
-     */
907
-    public function ensure_is_model()
908
-    {
909
-        //is it already instantiated?
910
-        if ($this->_model instanceof EEM_Base) {
911
-            return;
912
-        }
913
-        //ensure model name is string
914
-        $this->_model_name = (string)$this->_model_name;
915
-        //error proof if the name has EEM in it
916
-        $this->_model_name = str_replace('EEM', '', $this->_model_name);
917
-        $this->_model = EE_Registry::instance()->load_model($this->_model_name);
918
-        if (! $this->_model instanceof EEM_Base) {
919
-            throw new EE_Error(
920
-                sprintf(
921
-                    __(
922
-                        'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
923
-                        'event_espresso'
924
-                    ),
925
-                    get_class($this),
926
-                    $this->_model
927
-                )
928
-            );
929
-        }
930
-    }
931
-
932
-
933
-    /**
934
-     *
935
-     * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
936
-     * @since 4.6.x
937
-     *
938
-     * @param $caps
939
-     * @param $cap
940
-     * @param $user_id
941
-     * @param $args
942
-     *
943
-     * @return array
944
-     */
945
-    public function map_meta_caps($caps, $cap, $user_id, $args)
946
-    {
947
-        return $this->_map_meta_caps($caps, $cap, $user_id, $args);
948
-    }
949
-
950
-
951
-    /**
952
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
953
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
954
-     *
955
-     * @since 4.5.0
956
-     * @see   wp-includes/capabilities.php
957
-     *
958
-     * @param array  $caps    actual users capabilities
959
-     * @param string $cap     initial capability name that is being checked (the "map" key)
960
-     * @param int    $user_id The user id
961
-     * @param array  $args    Adds context to the cap. Typically the object ID.
962
-     *
963
-     * @return array   actual users capabilities
964
-     */
965
-    abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
830
+	public $meta_cap;
831
+
832
+	/**
833
+	 * @var EEM_Base
834
+	 */
835
+	protected $_model;
836
+
837
+	protected $_model_name;
838
+
839
+	public $published_cap = '';
840
+
841
+	public $others_cap = '';
842
+
843
+	public $private_cap = '';
844
+
845
+
846
+	/**
847
+	 * constructor.
848
+	 * Receives the setup arguments for the map.
849
+	 *
850
+	 * @since                        4.5.0
851
+	 *
852
+	 * @param string $meta_cap   What meta capability is this mapping.
853
+	 * @param array  $map_values array {
854
+	 *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
855
+	 *                           capabilities that don't get mapped to.
856
+	 *
857
+	 * @type         $map_values [0] string A string representing the model name. Required.  String's
858
+	 *                               should always be used when Menu Maps are registered via the
859
+	 *                               plugin API as models are not allowed to be instantiated when
860
+	 *                               in maintenance mode 2 (migrations).
861
+	 * @type         $map_values [1] string represents the capability used for published. Optional.
862
+	 * @type         $map_values [2] string represents the capability used for "others". Optional.
863
+	 * @type         $map_values [3] string represents the capability used for private. Optional.
864
+	 *                               }
865
+	 * @throws EE_Error
866
+	 */
867
+	public function __construct($meta_cap, $map_values)
868
+	{
869
+		$this->meta_cap = $meta_cap;
870
+		//verify there are four args in the $map_values array;
871
+		if (count($map_values) !== 4) {
872
+			throw new EE_Error(
873
+				sprintf(
874
+					__(
875
+						'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
876
+						'event_espresso'
877
+					),
878
+					'<br>' . print_r($map_values, true)
879
+				)
880
+			);
881
+		}
882
+		//set properties
883
+		$this->_model = null;
884
+		$this->_model_name = $map_values[0];
885
+		$this->published_cap = (string)$map_values[1];
886
+		$this->others_cap = (string)$map_values[2];
887
+		$this->private_cap = (string)$map_values[3];
888
+	}
889
+
890
+	/**
891
+	 * Makes it so this object stops filtering caps
892
+	 */
893
+	public function remove_filters()
894
+	{
895
+		remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
896
+	}
897
+
898
+
899
+	/**
900
+	 * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
901
+	 *
902
+	 * @since 4.5.0
903
+	 * @throws EE_Error
904
+	 *
905
+	 * @return void
906
+	 */
907
+	public function ensure_is_model()
908
+	{
909
+		//is it already instantiated?
910
+		if ($this->_model instanceof EEM_Base) {
911
+			return;
912
+		}
913
+		//ensure model name is string
914
+		$this->_model_name = (string)$this->_model_name;
915
+		//error proof if the name has EEM in it
916
+		$this->_model_name = str_replace('EEM', '', $this->_model_name);
917
+		$this->_model = EE_Registry::instance()->load_model($this->_model_name);
918
+		if (! $this->_model instanceof EEM_Base) {
919
+			throw new EE_Error(
920
+				sprintf(
921
+					__(
922
+						'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
923
+						'event_espresso'
924
+					),
925
+					get_class($this),
926
+					$this->_model
927
+				)
928
+			);
929
+		}
930
+	}
931
+
932
+
933
+	/**
934
+	 *
935
+	 * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
936
+	 * @since 4.6.x
937
+	 *
938
+	 * @param $caps
939
+	 * @param $cap
940
+	 * @param $user_id
941
+	 * @param $args
942
+	 *
943
+	 * @return array
944
+	 */
945
+	public function map_meta_caps($caps, $cap, $user_id, $args)
946
+	{
947
+		return $this->_map_meta_caps($caps, $cap, $user_id, $args);
948
+	}
949
+
950
+
951
+	/**
952
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
953
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
954
+	 *
955
+	 * @since 4.5.0
956
+	 * @see   wp-includes/capabilities.php
957
+	 *
958
+	 * @param array  $caps    actual users capabilities
959
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
960
+	 * @param int    $user_id The user id
961
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
962
+	 *
963
+	 * @return array   actual users capabilities
964
+	 */
965
+	abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
966 966
 }
967 967
 
968 968
 
@@ -978,83 +978,83 @@  discard block
 block discarded – undo
978 978
 class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map
979 979
 {
980 980
 
981
-    /**
982
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
983
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
984
-     *
985
-     * @since 4.5.0
986
-     * @see   wp-includes/capabilities.php
987
-     *
988
-     * @param array  $caps    actual users capabilities
989
-     * @param string $cap     initial capability name that is being checked (the "map" key)
990
-     * @param int    $user_id The user id
991
-     * @param array  $args    Adds context to the cap. Typically the object ID.
992
-     *
993
-     * @return array   actual users capabilities
994
-     */
995
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
996
-    {
997
-        //only process if we're checking our mapped_cap
998
-        if ($cap !== $this->meta_cap) {
999
-            return $caps;
1000
-        }
1001
-
1002
-        //cast $user_id to int for later explicit comparisons
1003
-        $user_id = (int) $user_id;
1004
-
1005
-        /** @var EE_Base_Class $obj */
1006
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1007
-        //if no obj then let's just do cap
1008
-        if (! $obj instanceof EE_Base_Class) {
1009
-            $caps[] = $cap;
1010
-            return $caps;
1011
-        }
1012
-        if ($obj instanceof EE_CPT_Base) {
1013
-            //if the item author is set and the user is the author...
1014
-            if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1015
-                if (empty($this->published_cap)) {
1016
-                    $caps[] = $cap;
1017
-                } else {
1018
-                    //if obj is published...
1019
-                    if ($obj->status() === 'publish') {
1020
-                        $caps[] = $this->published_cap;
1021
-                    } else {
1022
-                        $caps[] = $cap;
1023
-                    }
1024
-                }
1025
-            } else {
1026
-                //the user is trying to edit someone else's obj
1027
-                if (! empty($this->others_cap)) {
1028
-                    $caps[] = $this->others_cap;
1029
-                }
1030
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1031
-                    $caps[] = $this->published_cap;
1032
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1033
-                    $caps[] = $this->private_cap;
1034
-                }
1035
-            }
1036
-        } else {
1037
-            //not a cpt object so handled differently
1038
-            $has_cap = false;
1039
-            try {
1040
-                $has_cap = method_exists($obj, 'wp_user')
1041
-                    && $obj->wp_user()
1042
-                    && $obj->wp_user() === $user_id;
1043
-            } catch (Exception $e) {
1044
-                if (WP_DEBUG) {
1045
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1046
-                }
1047
-            }
1048
-            if ($has_cap) {
1049
-                $caps[] = $cap;
1050
-            } else {
1051
-                if (! empty($this->others_cap)) {
1052
-                    $caps[] = $this->others_cap;
1053
-                }
1054
-            }
1055
-        }
1056
-        return $caps;
1057
-    }
981
+	/**
982
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
983
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
984
+	 *
985
+	 * @since 4.5.0
986
+	 * @see   wp-includes/capabilities.php
987
+	 *
988
+	 * @param array  $caps    actual users capabilities
989
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
990
+	 * @param int    $user_id The user id
991
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
992
+	 *
993
+	 * @return array   actual users capabilities
994
+	 */
995
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
996
+	{
997
+		//only process if we're checking our mapped_cap
998
+		if ($cap !== $this->meta_cap) {
999
+			return $caps;
1000
+		}
1001
+
1002
+		//cast $user_id to int for later explicit comparisons
1003
+		$user_id = (int) $user_id;
1004
+
1005
+		/** @var EE_Base_Class $obj */
1006
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1007
+		//if no obj then let's just do cap
1008
+		if (! $obj instanceof EE_Base_Class) {
1009
+			$caps[] = $cap;
1010
+			return $caps;
1011
+		}
1012
+		if ($obj instanceof EE_CPT_Base) {
1013
+			//if the item author is set and the user is the author...
1014
+			if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1015
+				if (empty($this->published_cap)) {
1016
+					$caps[] = $cap;
1017
+				} else {
1018
+					//if obj is published...
1019
+					if ($obj->status() === 'publish') {
1020
+						$caps[] = $this->published_cap;
1021
+					} else {
1022
+						$caps[] = $cap;
1023
+					}
1024
+				}
1025
+			} else {
1026
+				//the user is trying to edit someone else's obj
1027
+				if (! empty($this->others_cap)) {
1028
+					$caps[] = $this->others_cap;
1029
+				}
1030
+				if (! empty($this->published_cap) && $obj->status() === 'publish') {
1031
+					$caps[] = $this->published_cap;
1032
+				} elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1033
+					$caps[] = $this->private_cap;
1034
+				}
1035
+			}
1036
+		} else {
1037
+			//not a cpt object so handled differently
1038
+			$has_cap = false;
1039
+			try {
1040
+				$has_cap = method_exists($obj, 'wp_user')
1041
+					&& $obj->wp_user()
1042
+					&& $obj->wp_user() === $user_id;
1043
+			} catch (Exception $e) {
1044
+				if (WP_DEBUG) {
1045
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1046
+				}
1047
+			}
1048
+			if ($has_cap) {
1049
+				$caps[] = $cap;
1050
+			} else {
1051
+				if (! empty($this->others_cap)) {
1052
+					$caps[] = $this->others_cap;
1053
+				}
1054
+			}
1055
+		}
1056
+		return $caps;
1057
+	}
1058 1058
 }
1059 1059
 
1060 1060
 
@@ -1071,24 +1071,24 @@  discard block
 block discarded – undo
1071 1071
 class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit
1072 1072
 {
1073 1073
 
1074
-    /**
1075
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1076
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1077
-     *
1078
-     * @since 4.5.0
1079
-     * @see   wp-includes/capabilities.php
1080
-     *
1081
-     * @param array  $caps    actual users capabilities
1082
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1083
-     * @param int    $user_id The user id
1084
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1085
-     *
1086
-     * @return array   actual users capabilities
1087
-     */
1088
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1089
-    {
1090
-        return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1091
-    }
1074
+	/**
1075
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1076
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1077
+	 *
1078
+	 * @since 4.5.0
1079
+	 * @see   wp-includes/capabilities.php
1080
+	 *
1081
+	 * @param array  $caps    actual users capabilities
1082
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1083
+	 * @param int    $user_id The user id
1084
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1085
+	 *
1086
+	 * @return array   actual users capabilities
1087
+	 */
1088
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1089
+	{
1090
+		return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1091
+	}
1092 1092
 }
1093 1093
 
1094 1094
 
@@ -1104,75 +1104,75 @@  discard block
 block discarded – undo
1104 1104
 class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map
1105 1105
 {
1106 1106
 
1107
-    /**
1108
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1109
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1110
-     *
1111
-     * @since 4.5.0
1112
-     * @see   wp-includes/capabilities.php
1113
-     *
1114
-     * @param array  $caps    actual users capabilities
1115
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1116
-     * @param int    $user_id The user id
1117
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1118
-     *
1119
-     * @return array   actual users capabilities
1120
-     */
1121
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1122
-    {
1123
-        //only process if we're checking our mapped cap;
1124
-        if ($cap !== $this->meta_cap) {
1125
-            return $caps;
1126
-        }
1127
-
1128
-        //cast $user_id to int for later explicit comparisons
1129
-        $user_id = (int) $user_id;
1130
-
1131
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1132
-        //if no obj then let's just do cap
1133
-        if (! $obj instanceof EE_Base_Class) {
1134
-            $caps[] = $cap;
1135
-            return $caps;
1136
-        }
1137
-        if ($obj instanceof EE_CPT_Base) {
1138
-            $status_obj = get_post_status_object($obj->status());
1139
-            if ($status_obj->public) {
1140
-                $caps[] = $cap;
1141
-                return $caps;
1142
-            }
1143
-            //if the item author is set and the user is the author...
1144
-            if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1145
-                $caps[] = $cap;
1146
-            } elseif ($status_obj->private && ! empty($this->private_cap)) {
1147
-                //the user is trying to view someone else's obj
1148
-                $caps[] = $this->private_cap;
1149
-            } elseif (! empty($this->others_cap)) {
1150
-                $caps[] = $this->others_cap;
1151
-            } else {
1152
-                $caps[] = $cap;
1153
-            }
1154
-        } else {
1155
-            //not a cpt object so handled differently
1156
-            $has_cap = false;
1157
-            try {
1158
-                $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $obj->wp_user() === $user_id;
1159
-            } catch (Exception $e) {
1160
-                if (WP_DEBUG) {
1161
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1162
-                }
1163
-            }
1164
-            if ($has_cap) {
1165
-                $caps[] = $cap;
1166
-            } elseif (! empty($this->private_cap)) {
1167
-                $caps[] = $this->private_cap;
1168
-            } elseif (! empty($this->others_cap)) {
1169
-                $caps[] = $this->others_cap;
1170
-            } else {
1171
-                $caps[] = $cap;
1172
-            }
1173
-        }
1174
-        return $caps;
1175
-    }
1107
+	/**
1108
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1109
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1110
+	 *
1111
+	 * @since 4.5.0
1112
+	 * @see   wp-includes/capabilities.php
1113
+	 *
1114
+	 * @param array  $caps    actual users capabilities
1115
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1116
+	 * @param int    $user_id The user id
1117
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1118
+	 *
1119
+	 * @return array   actual users capabilities
1120
+	 */
1121
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1122
+	{
1123
+		//only process if we're checking our mapped cap;
1124
+		if ($cap !== $this->meta_cap) {
1125
+			return $caps;
1126
+		}
1127
+
1128
+		//cast $user_id to int for later explicit comparisons
1129
+		$user_id = (int) $user_id;
1130
+
1131
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1132
+		//if no obj then let's just do cap
1133
+		if (! $obj instanceof EE_Base_Class) {
1134
+			$caps[] = $cap;
1135
+			return $caps;
1136
+		}
1137
+		if ($obj instanceof EE_CPT_Base) {
1138
+			$status_obj = get_post_status_object($obj->status());
1139
+			if ($status_obj->public) {
1140
+				$caps[] = $cap;
1141
+				return $caps;
1142
+			}
1143
+			//if the item author is set and the user is the author...
1144
+			if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1145
+				$caps[] = $cap;
1146
+			} elseif ($status_obj->private && ! empty($this->private_cap)) {
1147
+				//the user is trying to view someone else's obj
1148
+				$caps[] = $this->private_cap;
1149
+			} elseif (! empty($this->others_cap)) {
1150
+				$caps[] = $this->others_cap;
1151
+			} else {
1152
+				$caps[] = $cap;
1153
+			}
1154
+		} else {
1155
+			//not a cpt object so handled differently
1156
+			$has_cap = false;
1157
+			try {
1158
+				$has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $obj->wp_user() === $user_id;
1159
+			} catch (Exception $e) {
1160
+				if (WP_DEBUG) {
1161
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1162
+				}
1163
+			}
1164
+			if ($has_cap) {
1165
+				$caps[] = $cap;
1166
+			} elseif (! empty($this->private_cap)) {
1167
+				$caps[] = $this->private_cap;
1168
+			} elseif (! empty($this->others_cap)) {
1169
+				$caps[] = $this->others_cap;
1170
+			} else {
1171
+				$caps[] = $cap;
1172
+			}
1173
+		}
1174
+		return $caps;
1175
+	}
1176 1176
 }
1177 1177
 
1178 1178
 
@@ -1189,52 +1189,52 @@  discard block
 block discarded – undo
1189 1189
 class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map
1190 1190
 {
1191 1191
 
1192
-    /**
1193
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1194
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1195
-     *
1196
-     * @since 4.5.0
1197
-     * @see   wp-includes/capabilities.php
1198
-     *
1199
-     * @param array  $caps    actual users capabilities
1200
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1201
-     * @param int    $user_id The user id
1202
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1203
-     *
1204
-     * @return array   actual users capabilities
1205
-     */
1206
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1207
-    {
1208
-        //only process if we're checking our mapped_cap
1209
-        if ($cap !== $this->meta_cap) {
1210
-            return $caps;
1211
-        }
1212
-
1213
-        //cast $user_id to int for later explicit comparisons
1214
-        $user_id = (int) $user_id;
1215
-
1216
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1217
-        //if no obj then let's just do cap
1218
-        if (! $obj instanceof EE_Message_Template_Group) {
1219
-            $caps[] = $cap;
1220
-            return $caps;
1221
-        }
1222
-        $is_global = $obj->is_global();
1223
-        if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1224
-            if ($is_global) {
1225
-                $caps[] = $this->private_cap;
1226
-            } else {
1227
-                $caps[] = $cap;
1228
-            }
1229
-        } else {
1230
-            if ($is_global) {
1231
-                $caps[] = $this->private_cap;
1232
-            } else {
1233
-                $caps[] = $this->others_cap;
1234
-            }
1235
-        }
1236
-        return $caps;
1237
-    }
1192
+	/**
1193
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1194
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1195
+	 *
1196
+	 * @since 4.5.0
1197
+	 * @see   wp-includes/capabilities.php
1198
+	 *
1199
+	 * @param array  $caps    actual users capabilities
1200
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1201
+	 * @param int    $user_id The user id
1202
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1203
+	 *
1204
+	 * @return array   actual users capabilities
1205
+	 */
1206
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1207
+	{
1208
+		//only process if we're checking our mapped_cap
1209
+		if ($cap !== $this->meta_cap) {
1210
+			return $caps;
1211
+		}
1212
+
1213
+		//cast $user_id to int for later explicit comparisons
1214
+		$user_id = (int) $user_id;
1215
+
1216
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1217
+		//if no obj then let's just do cap
1218
+		if (! $obj instanceof EE_Message_Template_Group) {
1219
+			$caps[] = $cap;
1220
+			return $caps;
1221
+		}
1222
+		$is_global = $obj->is_global();
1223
+		if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1224
+			if ($is_global) {
1225
+				$caps[] = $this->private_cap;
1226
+			} else {
1227
+				$caps[] = $cap;
1228
+			}
1229
+		} else {
1230
+			if ($is_global) {
1231
+				$caps[] = $this->private_cap;
1232
+			} else {
1233
+				$caps[] = $this->others_cap;
1234
+			}
1235
+		}
1236
+		return $caps;
1237
+	}
1238 1238
 }
1239 1239
 
1240 1240
 
@@ -1251,41 +1251,41 @@  discard block
 block discarded – undo
1251 1251
 class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map
1252 1252
 {
1253 1253
 
1254
-    /**
1255
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1256
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1257
-     *
1258
-     * @since 4.5.0
1259
-     * @see   wp-includes/capabilities.php
1260
-     *
1261
-     * @param array  $caps    actual users capabilities
1262
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1263
-     * @param int    $user_id The user id
1264
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1265
-     *
1266
-     * @return array   actual users capabilities
1267
-     */
1268
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1269
-    {
1270
-        //only process if we're checking our mapped_cap
1271
-        if ($cap !== $this->meta_cap) {
1272
-            return $caps;
1273
-        }
1274
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1275
-        //if no obj then let's just do cap
1276
-        if (! $obj instanceof EE_Base_Class) {
1277
-            $caps[] = $cap;
1278
-            return $caps;
1279
-        }
1280
-        $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1281
-        $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1282
-        if ($is_system) {
1283
-            $caps[] = $this->private_cap;
1284
-        } else {
1285
-            $caps[] = $cap;
1286
-        }
1287
-        return $caps;
1288
-    }
1254
+	/**
1255
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1256
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1257
+	 *
1258
+	 * @since 4.5.0
1259
+	 * @see   wp-includes/capabilities.php
1260
+	 *
1261
+	 * @param array  $caps    actual users capabilities
1262
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1263
+	 * @param int    $user_id The user id
1264
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1265
+	 *
1266
+	 * @return array   actual users capabilities
1267
+	 */
1268
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1269
+	{
1270
+		//only process if we're checking our mapped_cap
1271
+		if ($cap !== $this->meta_cap) {
1272
+			return $caps;
1273
+		}
1274
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1275
+		//if no obj then let's just do cap
1276
+		if (! $obj instanceof EE_Base_Class) {
1277
+			$caps[] = $cap;
1278
+			return $caps;
1279
+		}
1280
+		$is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1281
+		$is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1282
+		if ($is_system) {
1283
+			$caps[] = $this->private_cap;
1284
+		} else {
1285
+			$caps[] = $cap;
1286
+		}
1287
+		return $caps;
1288
+	}
1289 1289
 
1290 1290
 
1291 1291
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     public static function instance()
61 61
     {
62 62
         //check if instantiated, and if not do so.
63
-        if (! self::$_instance instanceof EE_Capabilities) {
63
+        if ( ! self::$_instance instanceof EE_Capabilities) {
64 64
             self::$_instance = new self();
65 65
         }
66 66
         return self::$_instance;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         $this->_meta_caps = $this->_get_default_meta_caps_array();
113 113
         $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps);
114 114
         //add filter for map_meta_caps but only if models can query.
115
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
115
+        if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
116 116
             add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
117 117
         }
118 118
     }
@@ -270,11 +270,11 @@  discard block
 block discarded – undo
270 270
         if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
271 271
             //loop through our _meta_caps array
272 272
             foreach ($this->_meta_caps as $meta_map) {
273
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
273
+                if ( ! $meta_map instanceof EE_Meta_Capability_Map) {
274 274
                     continue;
275 275
                 }
276 276
                 // don't load models if there is no object ID in the args
277
-                if(!empty($args[0])){
277
+                if ( ! empty($args[0])) {
278 278
                     $meta_map->ensure_is_model();
279 279
                 }
280 280
                 $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
@@ -632,9 +632,9 @@  discard block
 block discarded – undo
632 632
         foreach ($caps_map as $role => $caps_for_role) {
633 633
             foreach ($caps_for_role as $cap) {
634 634
                 //first check we haven't already added this cap before, or it's a reset
635
-                if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) {
635
+                if ($reset || ! isset($caps_set_before[$role]) || ! in_array($cap, $caps_set_before[$role])) {
636 636
                     if ($this->add_cap_to_role($role, $cap)) {
637
-                        $caps_set_before[ $role ][] = $cap;
637
+                        $caps_set_before[$role][] = $cap;
638 638
                     }
639 639
                 }
640 640
             }
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
     {
665 665
         $role_object = get_role($role);
666 666
         //if the role isn't available then we create it.
667
-        if (! $role_object instanceof WP_Role) {
667
+        if ( ! $role_object instanceof WP_Role) {
668 668
             //if a plugin wants to create a specific role name then they should create the role before
669 669
             //EE_Capabilities does.  Otherwise this function will create the role name from the slug:
670 670
             // - removes any `ee_` namespacing from the start of the slug.
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
     public function current_user_can($cap, $context, $id = 0)
722 722
     {
723 723
         //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
724
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
724
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id);
725 725
         $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap,
726 726
             $id);
727 727
         return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap);
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
     public function user_can($user, $cap, $context, $id = 0)
743 743
     {
744 744
         //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
745
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
745
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id);
746 746
         $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user,
747 747
             $id);
748 748
         return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap);
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
             : current_user_can($blog_id, $cap);
774 774
         //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
775 775
         $user_can = apply_filters(
776
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
776
+            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context,
777 777
             $user_can,
778 778
             $blog_id,
779 779
             $cap,
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
         if (empty($role)) {
810 810
             return $capabilities;
811 811
         }
812
-        return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array();
812
+        return isset($capabilities[$role]) ? $capabilities[$role] : array();
813 813
     }
814 814
 }
815 815
 
@@ -875,16 +875,16 @@  discard block
 block discarded – undo
875 875
                         'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
876 876
                         'event_espresso'
877 877
                     ),
878
-                    '<br>' . print_r($map_values, true)
878
+                    '<br>'.print_r($map_values, true)
879 879
                 )
880 880
             );
881 881
         }
882 882
         //set properties
883 883
         $this->_model = null;
884 884
         $this->_model_name = $map_values[0];
885
-        $this->published_cap = (string)$map_values[1];
886
-        $this->others_cap = (string)$map_values[2];
887
-        $this->private_cap = (string)$map_values[3];
885
+        $this->published_cap = (string) $map_values[1];
886
+        $this->others_cap = (string) $map_values[2];
887
+        $this->private_cap = (string) $map_values[3];
888 888
     }
889 889
 
890 890
     /**
@@ -911,11 +911,11 @@  discard block
 block discarded – undo
911 911
             return;
912 912
         }
913 913
         //ensure model name is string
914
-        $this->_model_name = (string)$this->_model_name;
914
+        $this->_model_name = (string) $this->_model_name;
915 915
         //error proof if the name has EEM in it
916 916
         $this->_model_name = str_replace('EEM', '', $this->_model_name);
917 917
         $this->_model = EE_Registry::instance()->load_model($this->_model_name);
918
-        if (! $this->_model instanceof EEM_Base) {
918
+        if ( ! $this->_model instanceof EEM_Base) {
919 919
             throw new EE_Error(
920 920
                 sprintf(
921 921
                     __(
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
         /** @var EE_Base_Class $obj */
1006 1006
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1007 1007
         //if no obj then let's just do cap
1008
-        if (! $obj instanceof EE_Base_Class) {
1008
+        if ( ! $obj instanceof EE_Base_Class) {
1009 1009
             $caps[] = $cap;
1010 1010
             return $caps;
1011 1011
         }
@@ -1024,12 +1024,12 @@  discard block
 block discarded – undo
1024 1024
                 }
1025 1025
             } else {
1026 1026
                 //the user is trying to edit someone else's obj
1027
-                if (! empty($this->others_cap)) {
1027
+                if ( ! empty($this->others_cap)) {
1028 1028
                     $caps[] = $this->others_cap;
1029 1029
                 }
1030
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1030
+                if ( ! empty($this->published_cap) && $obj->status() === 'publish') {
1031 1031
                     $caps[] = $this->published_cap;
1032
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1032
+                } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') {
1033 1033
                     $caps[] = $this->private_cap;
1034 1034
                 }
1035 1035
             }
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
             if ($has_cap) {
1049 1049
                 $caps[] = $cap;
1050 1050
             } else {
1051
-                if (! empty($this->others_cap)) {
1051
+                if ( ! empty($this->others_cap)) {
1052 1052
                     $caps[] = $this->others_cap;
1053 1053
                 }
1054 1054
             }
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
 
1131 1131
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1132 1132
         //if no obj then let's just do cap
1133
-        if (! $obj instanceof EE_Base_Class) {
1133
+        if ( ! $obj instanceof EE_Base_Class) {
1134 1134
             $caps[] = $cap;
1135 1135
             return $caps;
1136 1136
         }
@@ -1146,7 +1146,7 @@  discard block
 block discarded – undo
1146 1146
             } elseif ($status_obj->private && ! empty($this->private_cap)) {
1147 1147
                 //the user is trying to view someone else's obj
1148 1148
                 $caps[] = $this->private_cap;
1149
-            } elseif (! empty($this->others_cap)) {
1149
+            } elseif ( ! empty($this->others_cap)) {
1150 1150
                 $caps[] = $this->others_cap;
1151 1151
             } else {
1152 1152
                 $caps[] = $cap;
@@ -1163,9 +1163,9 @@  discard block
 block discarded – undo
1163 1163
             }
1164 1164
             if ($has_cap) {
1165 1165
                 $caps[] = $cap;
1166
-            } elseif (! empty($this->private_cap)) {
1166
+            } elseif ( ! empty($this->private_cap)) {
1167 1167
                 $caps[] = $this->private_cap;
1168
-            } elseif (! empty($this->others_cap)) {
1168
+            } elseif ( ! empty($this->others_cap)) {
1169 1169
                 $caps[] = $this->others_cap;
1170 1170
             } else {
1171 1171
                 $caps[] = $cap;
@@ -1215,7 +1215,7 @@  discard block
 block discarded – undo
1215 1215
 
1216 1216
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1217 1217
         //if no obj then let's just do cap
1218
-        if (! $obj instanceof EE_Message_Template_Group) {
1218
+        if ( ! $obj instanceof EE_Message_Template_Group) {
1219 1219
             $caps[] = $cap;
1220 1220
             return $caps;
1221 1221
         }
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
         }
1274 1274
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1275 1275
         //if no obj then let's just do cap
1276
-        if (! $obj instanceof EE_Base_Class) {
1276
+        if ( ! $obj instanceof EE_Base_Class) {
1277 1277
             $caps[] = $cap;
1278 1278
             return $caps;
1279 1279
         }
Please login to merge, or discard this patch.
core/exceptions/ExceptionStackTraceDisplay.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 			// add generic non-identifying messages for non-privileged users
119 119
 			if ( ! WP_DEBUG ) {
120 120
 				$output .= '<span class="ee-error-user-msg-spn">'
121
-				           . trim( $msg )
122
-				           . '</span> &nbsp; <sup>'
123
-				           . $code
124
-				           . '</sup><br />';
121
+						   . trim( $msg )
122
+						   . '</span> &nbsp; <sup>'
123
+						   . $code
124
+						   . '</sup><br />';
125 125
 			} else {
126 126
 				// or helpful developer messages if debugging is on
127 127
 				$output .= '
@@ -130,39 +130,39 @@  discard block
 block discarded – undo
130 130
 				'
131 131
 				. sprintf(
132 132
 					__( '%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso' ),
133
-				    '<strong class="ee-error-dev-msg-str">',
133
+					'<strong class="ee-error-dev-msg-str">',
134 134
 					get_class( $exception ),
135 135
 					'</strong>  &nbsp; <span>',
136 136
 					$code . '</span>'
137 137
 				)
138 138
 				. '<br />
139 139
 				<span class="big-text">"'
140
-				           . trim( $msg )
141
-				           . '"</span><br/>
140
+						   . trim( $msg )
141
+						   . '"</span><br/>
142 142
 				<a id="display-ee-error-trace-1'
143
-				           . $time
144
-				           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1'
145
-				           . $time
146
-				           . '">
143
+						   . $time
144
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1'
145
+						   . $time
146
+						   . '">
147 147
 					'
148
-				           . __( 'click to view backtrace and class/method details', 'event_espresso' )
149
-				           . '
148
+						   . __( 'click to view backtrace and class/method details', 'event_espresso' )
149
+						   . '
150 150
 				</a><br />
151 151
 				'
152
-				           . $exception->getFile()
153
-				           . sprintf(
154
-					           __( '%1$s( line no: %2$s )%3$s', 'event_espresso' ),
155
-					           ' &nbsp; <span class="small-text lt-grey-text">',
156
-					           $exception->getLine(),
157
-					           '</span>'
158
-				           )
159
-				           . '
152
+						   . $exception->getFile()
153
+						   . sprintf(
154
+							   __( '%1$s( line no: %2$s )%3$s', 'event_espresso' ),
155
+							   ' &nbsp; <span class="small-text lt-grey-text">',
156
+							   $exception->getLine(),
157
+							   '</span>'
158
+						   )
159
+						   . '
160 160
 			</p>
161 161
 			<div id="ee-error-trace-1'
162
-				           . $time
163
-				           . '-dv" class="ee-error-trace-dv" style="display: none;">
162
+						   . $time
163
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
164 164
 				'
165
-				           . $trace_details;
165
+						   . $trace_details;
166 166
 				if ( ! empty( $class ) ) {
167 167
 					$output .= '
168 168
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;">
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
 			if ( wp_script_is( 'ee_error_js', 'enqueued' ) ) {
372 372
 				return '';
373 373
 			} else if ( wp_script_is( 'ee_error_js', 'registered' ) ) {
374
-                wp_enqueue_style('espresso_default');
375
-                wp_enqueue_style('espresso_custom_css');
376
-                wp_enqueue_script( 'ee_error_js' );
374
+				wp_enqueue_style('espresso_default');
375
+				wp_enqueue_style('espresso_custom_css');
376
+				wp_enqueue_script( 'ee_error_js' );
377 377
 				wp_localize_script( 'ee_error_js', 'ee_settings', array( 'wp_debug' => WP_DEBUG ) );
378 378
 			}
379 379
 		} else {
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\exceptions;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @param \Exception $exception
24 24
 	 */
25
-	public function __construct( \Exception $exception ) {
26
-		if ( WP_DEBUG ) {
27
-			$this->displayException( $exception );
25
+	public function __construct(\Exception $exception) {
26
+		if (WP_DEBUG) {
27
+			$this->displayException($exception);
28 28
 		}
29 29
 	}
30 30
 
@@ -34,27 +34,27 @@  discard block
 block discarded – undo
34 34
 	 * @access protected
35 35
 	 * @param \Exception $exception
36 36
 	 */
37
-	protected function displayException( \Exception $exception ) {
37
+	protected function displayException(\Exception $exception) {
38 38
 
39 39
 		$error_code = '';
40 40
 		$trace_details = '';
41 41
 		$time = time();
42 42
 		$trace = $exception->getTrace();
43 43
 		// get separate user and developer messages if they exist
44
-		$msg = explode( '||', $exception->getMessage() );
44
+		$msg = explode('||', $exception->getMessage());
45 45
 		$user_msg = $msg[0];
46
-		$dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0];
46
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
47 47
 		$msg = WP_DEBUG ? $dev_msg : $user_msg;
48 48
 		// start gathering output
49 49
 		$output = $this->exceptionStyles();
50 50
 		$output .= '
51 51
 <div id="ee-error-message" class="error">';
52
-		if ( ! WP_DEBUG ) {
52
+		if ( ! WP_DEBUG) {
53 53
 			$output .= '
54 54
 	<p>';
55 55
 		}
56 56
 			// process trace info
57
-			if ( empty( $trace ) ) {
57
+			if (empty($trace)) {
58 58
 				$trace_details .= __(
59 59
 					'Sorry, but no trace information was available for this exception.',
60 60
 					'event_espresso'
@@ -67,47 +67,47 @@  discard block
 block discarded – undo
67 67
 					<th scope="col" align="right" style="width:2.5%;">#</th>
68 68
 					<th scope="col" align="right" style="width:3.5%;">Line</th>
69 69
 					<th scope="col" align="left" style="width:40%;">File</th>
70
-					<th scope="col" align="left">' . __( 'Class', 'event_espresso' ) . '->' . __( 'Method( arguments )', 'event_espresso' ) . '</th>
70
+					<th scope="col" align="left">' . __('Class', 'event_espresso').'->'.__('Method( arguments )', 'event_espresso').'</th>
71 71
 				</tr>';
72
-				$last_on_stack = count( $trace ) - 1;
72
+				$last_on_stack = count($trace) - 1;
73 73
 				// reverse array so that stack is in proper chronological order
74
-				$sorted_trace = array_reverse( $trace );
75
-				foreach ( $sorted_trace as $nmbr => $trace ) {
76
-					$file = isset( $trace['file'] ) ? $trace['file'] : '';
77
-					$class = isset( $trace['class'] ) ? $trace['class'] : '';
78
-					$type = isset( $trace['type'] ) ? $trace['type'] : '';
79
-					$function = isset( $trace['function'] ) ? $trace['function'] : '';
80
-					$args = isset( $trace['args'] ) ? $this->_convert_args_to_string( $trace['args'] ) : '';
81
-					$args = isset( $trace['args'] ) && count( $trace['args'] ) > 4  ? ' <br />' . $args . '<br />' : $args;
82
-					$line = isset( $trace['line'] ) ? $trace['line'] : '';
74
+				$sorted_trace = array_reverse($trace);
75
+				foreach ($sorted_trace as $nmbr => $trace) {
76
+					$file = isset($trace['file']) ? $trace['file'] : '';
77
+					$class = isset($trace['class']) ? $trace['class'] : '';
78
+					$type = isset($trace['type']) ? $trace['type'] : '';
79
+					$function = isset($trace['function']) ? $trace['function'] : '';
80
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
81
+					$args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />'.$args.'<br />' : $args;
82
+					$line = isset($trace['line']) ? $trace['line'] : '';
83 83
 					$zebra = $nmbr % 2 !== 0 ? ' odd' : '';
84
-					if ( empty( $file ) && ! empty( $class ) ) {
85
-						$a = new \ReflectionClass( $class );
84
+					if (empty($file) && ! empty($class)) {
85
+						$a = new \ReflectionClass($class);
86 86
 						$file = $a->getFileName();
87
-						if ( empty( $line ) && ! empty( $function ) ) {
88
-							$b = new \ReflectionMethod( $class, $function );
87
+						if (empty($line) && ! empty($function)) {
88
+							$b = new \ReflectionMethod($class, $function);
89 89
 							$line = $b->getStartLine();
90 90
 						}
91 91
 					}
92
-					if ( $nmbr === $last_on_stack ) {
92
+					if ($nmbr === $last_on_stack) {
93 93
 						$file = $exception->getFile() !== '' ? $exception->getFile() : $file;
94 94
 						$line = $exception->getLine() !== '' ? $exception->getLine() : $line;
95
-						$error_code = $this->generate_error_code( $file, $trace['function'], $line );
95
+						$error_code = $this->generate_error_code($file, $trace['function'], $line);
96 96
 					}
97
-					$file = \EEH_File::standardise_directory_separators( $file );
98
-					$nmbr = ! empty( $nmbr ) ? $nmbr : '&nbsp;';
99
-					$line = ! empty( $line ) ? $line : '&nbsp;';
100
-					$file = ! empty( $file ) ? $file : '&nbsp;';
101
-					$class_display = ! empty( $class ) ? $class : '';
102
-					$type = ! empty( $type ) ? $type : '';
103
-					$function = ! empty( $function ) ? $function : '';
104
-					$args = ! empty( $args ) ? '( ' . $args . ' )' : '()';
97
+					$file = \EEH_File::standardise_directory_separators($file);
98
+					$nmbr = ! empty($nmbr) ? $nmbr : '&nbsp;';
99
+					$line = ! empty($line) ? $line : '&nbsp;';
100
+					$file = ! empty($file) ? $file : '&nbsp;';
101
+					$class_display = ! empty($class) ? $class : '';
102
+					$type = ! empty($type) ? $type : '';
103
+					$function = ! empty($function) ? $function : '';
104
+					$args = ! empty($args) ? '( '.$args.' )' : '()';
105 105
 					$trace_details .= '
106 106
 					<tr>
107
-						<td align="right" valign="top" class="' . $zebra . '">' . $nmbr . '</td>
108
-						<td align="right" valign="top" class="' . $zebra . '">' . $line . '</td>
109
-						<td align="left" valign="top" class="' . $zebra . '">' . $file . '</td>
110
-						<td align="left" valign="top" class="' . $zebra . '">' . $class_display . $type . $function . $args . '</td>
107
+						<td align="right" valign="top" class="' . $zebra.'">'.$nmbr.'</td>
108
+						<td align="right" valign="top" class="' . $zebra.'">'.$line.'</td>
109
+						<td align="left" valign="top" class="' . $zebra.'">'.$file.'</td>
110
+						<td align="left" valign="top" class="' . $zebra.'">'.$class_display.$type.$function.$args.'</td>
111 111
 					</tr>';
112 112
 				}
113 113
 				$trace_details .= '
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 			}
117 117
 			$code = $exception->getCode() ? $exception->getCode() : $error_code;
118 118
 			// add generic non-identifying messages for non-privileged users
119
-			if ( ! WP_DEBUG ) {
119
+			if ( ! WP_DEBUG) {
120 120
 				$output .= '<span class="ee-error-user-msg-spn">'
121
-				           . trim( $msg )
121
+				           . trim($msg)
122 122
 				           . '</span> &nbsp; <sup>'
123 123
 				           . $code
124 124
 				           . '</sup><br />';
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
 			<p class="ee-error-dev-msg-pg">
130 130
 				'
131 131
 				. sprintf(
132
-					__( '%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso' ),
132
+					__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'),
133 133
 				    '<strong class="ee-error-dev-msg-str">',
134
-					get_class( $exception ),
134
+					get_class($exception),
135 135
 					'</strong>  &nbsp; <span>',
136
-					$code . '</span>'
136
+					$code.'</span>'
137 137
 				)
138 138
 				. '<br />
139 139
 				<span class="big-text">"'
140
-				           . trim( $msg )
140
+				           . trim($msg)
141 141
 				           . '"</span><br/>
142 142
 				<a id="display-ee-error-trace-1'
143 143
 				           . $time
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 				           . $time
146 146
 				           . '">
147 147
 					'
148
-				           . __( 'click to view backtrace and class/method details', 'event_espresso' )
148
+				           . __('click to view backtrace and class/method details', 'event_espresso')
149 149
 				           . '
150 150
 				</a><br />
151 151
 				'
152 152
 				           . $exception->getFile()
153 153
 				           . sprintf(
154
-					           __( '%1$s( line no: %2$s )%3$s', 'event_espresso' ),
154
+					           __('%1$s( line no: %2$s )%3$s', 'event_espresso'),
155 155
 					           ' &nbsp; <span class="small-text lt-grey-text">',
156 156
 					           $exception->getLine(),
157 157
 					           '</span>'
@@ -163,14 +163,14 @@  discard block
 block discarded – undo
163 163
 				           . '-dv" class="ee-error-trace-dv" style="display: none;">
164 164
 				'
165 165
 				           . $trace_details;
166
-				if ( ! empty( $class ) ) {
166
+				if ( ! empty($class)) {
167 167
 					$output .= '
168 168
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;">
169 169
 					<div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;">
170
-						<h3>' . __( 'Class Details', 'event_espresso' ) . '</h3>';
171
-					$a = new \ReflectionClass( $class );
170
+						<h3>' . __('Class Details', 'event_espresso').'</h3>';
171
+					$a = new \ReflectionClass($class);
172 172
 					$output .= '
173
-						<pre>' . $a . '</pre>
173
+						<pre>' . $a.'</pre>
174 174
 					</div>
175 175
 				</div>';
176 176
 				}
@@ -180,16 +180,16 @@  discard block
 block discarded – undo
180 180
 		<br />';
181 181
 			}
182 182
 		// remove last linebreak
183
-		$output = substr( $output, 0, count( $output ) - 7 );
184
-		if ( ! WP_DEBUG ) {
183
+		$output = substr($output, 0, count($output) - 7);
184
+		if ( ! WP_DEBUG) {
185 185
 			$output .= '
186 186
 	</p>';
187 187
 		}
188 188
 		$output .= '
189 189
 </div>';
190
-		$output .= $this->printScripts( true );
191
-		if ( defined( 'DOING_AJAX' ) ) {
192
-			echo wp_json_encode( array( 'error' => $output ) );
190
+		$output .= $this->printScripts(true);
191
+		if (defined('DOING_AJAX')) {
192
+			echo wp_json_encode(array('error' => $output));
193 193
 			exit();
194 194
 		}
195 195
 		echo $output;
@@ -206,56 +206,56 @@  discard block
 block discarded – undo
206 206
 	 * @param bool  $array
207 207
 	 * @return string
208 208
 	 */
209
-	private function _convert_args_to_string( $arguments = array(), $indent = 0, $array = false ) {
209
+	private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) {
210 210
 		$args = array();
211
-		$args_count = count( $arguments );
212
-		if ( $args_count > 2 ) {
211
+		$args_count = count($arguments);
212
+		if ($args_count > 2) {
213 213
 			$indent++;
214 214
 			$args[] = '<br />';
215 215
 		}
216 216
 		$x = 0;
217
-		foreach ( $arguments as $arg ) {
217
+		foreach ($arguments as $arg) {
218 218
 			$x++;
219
-			for( $i = 0; $i < $indent; $i++ ) {
219
+			for ($i = 0; $i < $indent; $i++) {
220 220
 				$args[] = ' &nbsp;&nbsp; ';
221 221
 			}
222
-			if ( is_string( $arg ) ) {
223
-				if ( ! $array && strlen( $arg ) > 75 ) {
222
+			if (is_string($arg)) {
223
+				if ( ! $array && strlen($arg) > 75) {
224 224
 					$args[] = "<br />";
225
-					for ( $i = 0; $i <= $indent; $i++ ) {
225
+					for ($i = 0; $i <= $indent; $i++) {
226 226
 						$args[] = ' &nbsp;&nbsp; ';
227 227
 					}
228
-					$args[] = "'" . $arg . "'<br />";
228
+					$args[] = "'".$arg."'<br />";
229 229
 				} else {
230
-					$args[] = " '" . $arg . "'";
230
+					$args[] = " '".$arg."'";
231 231
 				}
232
-			} elseif ( is_array( $arg ) ) {
233
-				$arg_count = count( $arg );
234
-				if ( $arg_count > 2 ) {
232
+			} elseif (is_array($arg)) {
233
+				$arg_count = count($arg);
234
+				if ($arg_count > 2) {
235 235
 					$indent++;
236
-					$args[] = " array(" . $this->_convert_args_to_string( $arg, $indent, true ) . ")";
236
+					$args[] = " array(".$this->_convert_args_to_string($arg, $indent, true).")";
237 237
 					$indent--;
238
-				} else if ( $arg_count === 0 ) {
238
+				} else if ($arg_count === 0) {
239 239
 					$args[] = " array()";
240 240
 				} else {
241
-					$args[] = " array( " . $this->_convert_args_to_string( $arg ) . " )";
241
+					$args[] = " array( ".$this->_convert_args_to_string($arg)." )";
242 242
 				}
243
-			} elseif ( $arg === null ) {
243
+			} elseif ($arg === null) {
244 244
 				$args[] = ' null';
245
-			} elseif ( is_bool( $arg ) ) {
245
+			} elseif (is_bool($arg)) {
246 246
 				$args[] = $arg ? ' true' : ' false';
247
-			} elseif ( is_object( $arg ) ) {
248
-				$args[] = get_class( $arg );
249
-			} elseif ( is_resource( $arg ) ) {
250
-				$args[] = get_resource_type( $arg );
247
+			} elseif (is_object($arg)) {
248
+				$args[] = get_class($arg);
249
+			} elseif (is_resource($arg)) {
250
+				$args[] = get_resource_type($arg);
251 251
 			} else {
252 252
 				$args[] = $arg;
253 253
 			}
254
-			if ( $x === $args_count ) {
255
-				if ( $args_count > 2 ) {
254
+			if ($x === $args_count) {
255
+				if ($args_count > 2) {
256 256
 					$args[] = "<br />";
257 257
 					$indent--;
258
-					for ( $i = 1; $i < $indent; $i++ ) {
258
+					for ($i = 1; $i < $indent; $i++) {
259 259
 						$args[] = ' &nbsp;&nbsp; ';
260 260
 					}
261 261
 				}
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 				$args[] = $args_count > 2 ? ",<br />" : ', ';
264 264
 			}
265 265
 		}
266
-		return implode( '', $args );
266
+		return implode('', $args);
267 267
 	}
268 268
 
269 269
 
@@ -278,11 +278,11 @@  discard block
 block discarded – undo
278 278
 	 * @param string $line
279 279
 	 * @return string
280 280
 	 */
281
-	protected function generate_error_code( $file = '', $func = '', $line = '' ) {
282
-		$file_bits = explode( '.', basename( $file ) );
283
-		$error_code = ! empty( $file_bits[0] ) ? $file_bits[0] : '';
284
-		$error_code .= ! empty( $func ) ? ' - ' . $func : '';
285
-		$error_code .= ! empty( $line ) ? ' - ' . $line : '';
281
+	protected function generate_error_code($file = '', $func = '', $line = '') {
282
+		$file_bits = explode('.', basename($file));
283
+		$error_code = ! empty($file_bits[0]) ? $file_bits[0] : '';
284
+		$error_code .= ! empty($func) ? ' - '.$func : '';
285
+		$error_code .= ! empty($line) ? ' - '.$line : '';
286 286
 		return $error_code;
287 287
 	}
288 288
 
@@ -366,26 +366,26 @@  discard block
 block discarded – undo
366 366
 	 * @param bool $force_print
367 367
 	 * @return string|void
368 368
 	 */
369
-	private function printScripts( $force_print = false ) {
370
-		if ( ! $force_print  && ( did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' ) ) ) {
371
-			if ( wp_script_is( 'ee_error_js', 'enqueued' ) ) {
369
+	private function printScripts($force_print = false) {
370
+		if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
371
+			if (wp_script_is('ee_error_js', 'enqueued')) {
372 372
 				return '';
373
-			} else if ( wp_script_is( 'ee_error_js', 'registered' ) ) {
373
+			} else if (wp_script_is('ee_error_js', 'registered')) {
374 374
                 wp_enqueue_style('espresso_default');
375 375
                 wp_enqueue_style('espresso_custom_css');
376
-                wp_enqueue_script( 'ee_error_js' );
377
-				wp_localize_script( 'ee_error_js', 'ee_settings', array( 'wp_debug' => WP_DEBUG ) );
376
+                wp_enqueue_script('ee_error_js');
377
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
378 378
 			}
379 379
 		} else {
380 380
 			return '
381 381
 <script>
382 382
 /* <![CDATA[ */
383
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
383
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
384 384
 /* ]]> */
385 385
 </script>
386
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
387
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
388
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
386
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
387
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
388
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
389 389
 ';
390 390
 		}
391 391
 		return '';
Please login to merge, or discard this patch.
modules/events_archive_filters/EED_Events_Archive_Filters.module.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -589,9 +589,9 @@
 block discarded – undo
589 589
 	 */
590 590
 	private function _load_assests() {
591 591
 		do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' );
592
-        wp_enqueue_style('espresso_default');
593
-        wp_enqueue_style('espresso_custom_css');
594
-        add_filter( 'FHEE_load_EE_Session', '__return_true' );
592
+		wp_enqueue_style('espresso_default');
593
+		wp_enqueue_style('espresso_custom_css');
594
+		add_filter( 'FHEE_load_EE_Session', '__return_true' );
595 595
 		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
596 596
 		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
597 597
 			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
Please login to merge, or discard this patch.
Spacing   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @return EED_Events_Archive_Filters
30 30
 	 */
31 31
 	public static function instance() {
32
-		return parent::get_instance( __CLASS__ );
32
+		return parent::get_instance(__CLASS__);
33 33
 	}
34 34
 
35 35
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 *	@var 	$_types
72 72
 	 * 	@access 	protected
73 73
 	 */
74
-	protected static $_types = array( 'grid', 'text', 'dates' );
74
+	protected static $_types = array('grid', 'text', 'dates');
75 75
 
76 76
 
77 77
 //	public static $espresso_event_list_ID = 0;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 *  @access 	public
126 126
 	 *  @return 	void
127 127
 	 */
128
-	public function run( $WP ) {
128
+	public function run($WP) {
129 129
 //		do_action( 'AHEE__EED_Events_Archive_Filters__before_run' );
130 130
 //		// set config
131 131
 //		if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters ) || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters instanceof EE_Events_Archive_Config ) {
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	private function _filter_query_parts() {
172 172
 		// build event list query
173
-		add_filter( 'posts_join', array( $this, 'posts_join' ), 1, 2 );
174
-		add_filter( 'posts_where', array( $this, 'posts_where' ), 1, 2 );
175
-		add_filter( 'posts_orderby', array( $this, 'posts_orderby' ), 1, 2 );
173
+		add_filter('posts_join', array($this, 'posts_join'), 1, 2);
174
+		add_filter('posts_where', array($this, 'posts_where'), 1, 2);
175
+		add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2);
176 176
 	}
177 177
 
178 178
 	/**
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 	 *  @return 	string
183 183
 	 */
184 184
 	public static function set_type() {
185
-		do_action( 'AHEE__EED_Events_Archive_Filters__before_set_type' );
186
-		EED_Events_Archive_Filters::$_types = apply_filters( 'EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types );
187
-		$view = isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid';
188
-		$elf_type = EE_Registry::instance()->REQ->is_set( 'elf_type' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_type' )) : '';
189
-		$view = ! empty( $elf_type ) ? $elf_type : $view;
190
-		$view = apply_filters( 'EED_Events_Archive_Filters__set_type__type', $view );
191
-		if ( ! empty( $view ) && in_array( $view, EED_Events_Archive_Filters::$_types )) {
185
+		do_action('AHEE__EED_Events_Archive_Filters__before_set_type');
186
+		EED_Events_Archive_Filters::$_types = apply_filters('EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types);
187
+		$view = isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid';
188
+		$elf_type = EE_Registry::instance()->REQ->is_set('elf_type') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_type')) : '';
189
+		$view = ! empty($elf_type) ? $elf_type : $view;
190
+		$view = apply_filters('EED_Events_Archive_Filters__set_type__type', $view);
191
+		if ( ! empty($view) && in_array($view, EED_Events_Archive_Filters::$_types)) {
192 192
 			self::$_type = $view;
193 193
 		}
194 194
 	}
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 	 *  @param	boolean	$req_only if TRUE, then ignore defaults and only return $_POST value
201 201
 	 *  @return 	boolean
202 202
 	 */
203
-	private static function _show_expired( $req_only = FALSE ) {
203
+	private static function _show_expired($req_only = FALSE) {
204 204
 		// get default value for "display_expired_events" as set in the EE General Settings > Templates > Event Listings
205
-		$show_expired = ! $req_only && isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE;
205
+		$show_expired = ! $req_only && isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE;
206 206
 		// override default expired option if set via filter
207
-		$show_expired = EE_Registry::instance()->REQ->is_set( 'elf_expired_chk' ) ? absint( EE_Registry::instance()->REQ->get( 'elf_expired_chk' )) : $show_expired;
207
+		$show_expired = EE_Registry::instance()->REQ->is_set('elf_expired_chk') ? absint(EE_Registry::instance()->REQ->get('elf_expired_chk')) : $show_expired;
208 208
 		return $show_expired ? TRUE : FALSE;
209 209
 	}
210 210
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *  @return 	string
216 216
 	 */
217 217
 	private static function _event_category_slug() {
218
-		return EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : '';
218
+		return EE_Registry::instance()->REQ->is_set('elf_category_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_category_dd')) : '';
219 219
 	}
220 220
 
221 221
 	/**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 *  @return 	string
226 226
 	 */
227 227
 	private static function _display_month() {
228
-		return EE_Registry::instance()->REQ->is_set( 'elf_month_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_month_dd' )) : '';
228
+		return EE_Registry::instance()->REQ->is_set('elf_month_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_month_dd')) : '';
229 229
 	}
230 230
 
231 231
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	public function get_post_data() {
240 240
 		$this->_elf_month = EED_Events_Archive_Filters::_display_month();
241 241
 		$this->_elf_category = EED_Events_Archive_Filters::_event_category_slug();
242
-		$this->_show_expired = EED_Events_Archive_Filters::_show_expired( TRUE );
242
+		$this->_show_expired = EED_Events_Archive_Filters::_show_expired(TRUE);
243 243
 //		EEH_Debug_Tools::printr( EE_Registry::instance()->REQ, 'EE_Registry::instance()->REQ  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
244 244
 //		echo '<h4>$this->_elf_month : ' . $this->_elf_month . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
245 245
 //		echo '<h4>$this->_elf_category : ' . $this->_elf_category . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 	 *  @access 	public
257 257
 	 *  @return 	void
258 258
 	 */
259
-	public function posts_join( $SQL, WP_Query $wp_query ) {
260
-		if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) {
259
+	public function posts_join($SQL, WP_Query $wp_query) {
260
+		if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') {
261 261
 			// Category
262 262
 //			$elf_category = EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : '';
263
-			$SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms( EED_Events_Archive_Filters::_event_category_slug() );
263
+			$SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms(EED_Events_Archive_Filters::_event_category_slug());
264 264
 		}
265 265
 		return $SQL;
266 266
 	}
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 	 *  @param	mixed boolean|string	$join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet
274 274
 	 *  @return 	string
275 275
 	 */
276
-	public static function posts_join_sql_for_terms( $join_terms = NULL ) {
277
-		$SQL= '';
278
-		if ( ! empty( $join_terms )) {
276
+	public static function posts_join_sql_for_terms($join_terms = NULL) {
277
+		$SQL = '';
278
+		if ( ! empty($join_terms)) {
279 279
 			global $wpdb;
280 280
 			$SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
281 281
 			$SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
@@ -293,28 +293,28 @@  discard block
 block discarded – undo
293 293
 	 *  @param	array	$orderby_params
294 294
 	 *  @return 	string
295 295
 	 */
296
-	public static function posts_join_for_orderby( $orderby_params = array() ) {
296
+	public static function posts_join_for_orderby($orderby_params = array()) {
297 297
 		global $wpdb;
298
-		$SQL= '';
299
-		$orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params );
300
-		foreach( $orderby_params as $orderby ) {
301
-			switch ( $orderby ) {
298
+		$SQL = '';
299
+		$orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params);
300
+		foreach ($orderby_params as $orderby) {
301
+			switch ($orderby) {
302 302
 
303 303
 				case 'ticket_start' :
304 304
 				case 'ticket_end' :
305
-					$SQL .= ' LEFT JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' ON (' . EEM_Datetime::instance()->table() . '.DTT_ID = ' . EEM_Datetime_Ticket::instance()->table() . '.DTT_ID )';
306
-					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table() . ' ON (' . EEM_Datetime_Ticket::instance()->table() . '.TKT_ID = ' . EEM_Ticket::instance()->table() . '.TKT_ID )';
305
+					$SQL .= ' LEFT JOIN '.EEM_Datetime_Ticket::instance()->table().' ON ('.EEM_Datetime::instance()->table().'.DTT_ID = '.EEM_Datetime_Ticket::instance()->table().'.DTT_ID )';
306
+					$SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table().' ON ('.EEM_Datetime_Ticket::instance()->table().'.TKT_ID = '.EEM_Ticket::instance()->table().'.TKT_ID )';
307 307
 					break;
308 308
 
309 309
 				case 'venue_title' :
310 310
 				case 'city' :
311
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )';
312
-					$SQL .= ' LEFT JOIN ' . EEM_Venue::instance()->table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Venue::instance()->table() . '.VNU_ID )';
311
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )';
312
+					$SQL .= ' LEFT JOIN '.EEM_Venue::instance()->table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Venue::instance()->table().'.VNU_ID )';
313 313
 					break;
314 314
 
315 315
 				case 'state' :
316
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )';
317
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->second_table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Event_Venue::instance()->second_table() . '.VNU_ID )';
316
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )';
317
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->second_table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Event_Venue::instance()->second_table().'.VNU_ID )';
318 318
 					break;
319 319
 
320 320
 				break;
@@ -331,16 +331,16 @@  discard block
 block discarded – undo
331 331
 	 *  @access 	public
332 332
 	 *  @return 	void
333 333
 	 */
334
-	public function posts_where( $SQL, WP_Query $wp_query ) {
335
-		if ( isset( $wp_query->query_vars ) && isset( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'espresso_events'  ) {
334
+	public function posts_where($SQL, WP_Query $wp_query) {
335
+		if (isset($wp_query->query_vars) && isset($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'espresso_events') {
336 336
 			// Show Expired ?
337
-			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired( EED_Events_Archive_Filters::_show_expired() );
337
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired(EED_Events_Archive_Filters::_show_expired());
338 338
 			// Category
339 339
 			//$elf_category = EED_Events_Archive_Filters::_event_category_slug();
340
-			$SQL .=  EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug( EED_Events_Archive_Filters::_event_category_slug() );
340
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug(EED_Events_Archive_Filters::_event_category_slug());
341 341
 			// Start Date
342 342
 			//$elf_month = EED_Events_Archive_Filters::_display_month();
343
-			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month( EED_Events_Archive_Filters::_display_month() );
343
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month(EED_Events_Archive_Filters::_display_month());
344 344
 		}
345 345
 		return $SQL;
346 346
 	}
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 	 *  @param	boolean	$show_expired if TRUE, then displayed past events
354 354
 	 *  @return 	string
355 355
 	 */
356
-	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
357
-		return  ! $show_expired ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > "' . date('Y-m-d H:s:i') . '" ' : '';
356
+	public static function posts_where_sql_for_show_expired($show_expired = FALSE) {
357
+		return  ! $show_expired ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > "'.date('Y-m-d H:s:i').'" ' : '';
358 358
 	}
359 359
 
360 360
 
@@ -365,9 +365,9 @@  discard block
 block discarded – undo
365 365
 	 *  @param	boolean	$event_category_slug
366 366
 	 *  @return 	string
367 367
 	 */
368
-	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
368
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) {
369 369
 		global $wpdb;
370
-		return  ! empty( $event_category_slug ) ? ' AND ' . $wpdb->terms . '.slug = "' . $event_category_slug . '" ' : '';
370
+		return  ! empty($event_category_slug) ? ' AND '.$wpdb->terms.'.slug = "'.$event_category_slug.'" ' : '';
371 371
 	}
372 372
 
373 373
 	/**
@@ -377,15 +377,15 @@  discard block
 block discarded – undo
377 377
 	 *  @param	boolean	$month
378 378
 	 *  @return 	string
379 379
 	 */
380
-	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
381
-		$SQL= '';
382
-		if ( ! empty( $month )) {
380
+	public static function posts_where_sql_for_event_list_month($month = NULL) {
381
+		$SQL = '';
382
+		if ( ! empty($month)) {
383 383
 			// event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
384
-			$SQL = ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start';
385
-			$SQL .= ' <= "' . date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '"';
384
+			$SQL = ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_start';
385
+			$SQL .= ' <= "'.date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)).'"';
386 386
 			// event end date is GREATER than the start of the month ( so nothing that ended before this month )
387
-			$SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end';
388
-			$SQL .= ' >= "' . date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '" ';
387
+			$SQL .= ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end';
388
+			$SQL .= ' >= "'.date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)).'" ';
389 389
 		}
390 390
 		return $SQL;
391 391
 	}
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 	 *  @access 	public
398 398
 	 *  @return 	void
399 399
 	 */
400
-	public function posts_orderby( $SQL, WP_Query $wp_query ) {
401
-		if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) {
402
-			$SQL = EED_Events_Archive_Filters::posts_orderby_sql( array( 'start_date' ));
400
+	public function posts_orderby($SQL, WP_Query $wp_query) {
401
+		if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') {
402
+			$SQL = EED_Events_Archive_Filters::posts_orderby_sql(array('start_date'));
403 403
 		}
404 404
 		return $SQL;
405 405
 	}
@@ -428,54 +428,54 @@  discard block
 block discarded – undo
428 428
 	 *  @param	boolean	$orderby_params
429 429
 	 *  @return 	string
430 430
 	 */
431
-	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
431
+	public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') {
432 432
 		global $wpdb;
433 433
 		$SQL = '';
434 434
 		$cntr = 1;
435
-		$orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params );
436
-		foreach( $orderby_params as $orderby ) {
437
-			$glue = $cntr == 1 || $cntr == count( $orderby_params ) ? ' ' : ', ';
438
-			switch ( $orderby ) {
435
+		$orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params);
436
+		foreach ($orderby_params as $orderby) {
437
+			$glue = $cntr == 1 || $cntr == count($orderby_params) ? ' ' : ', ';
438
+			switch ($orderby) {
439 439
 
440 440
 				case 'id' :
441 441
 				case 'ID' :
442
-					$SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
442
+					$SQL .= $glue.$wpdb->posts.'.ID '.$sort;
443 443
 					break;
444 444
 
445 445
 				case 'start_date' :
446
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort;
446
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_start '.$sort;
447 447
 					break;
448 448
 
449 449
 				case 'end_date' :
450
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
450
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort;
451 451
 					break;
452 452
 
453 453
 				case 'event_name' :
454
-					$SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
454
+					$SQL .= $glue.$wpdb->posts.'.post_title '.$sort;
455 455
 					break;
456 456
 
457 457
 				case 'category_slug' :
458
-					$SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
458
+					$SQL .= $glue.$wpdb->terms.'.slug '.$sort;
459 459
 					break;
460 460
 
461 461
 				case 'ticket_start' :
462
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
462
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort;
463 463
 					break;
464 464
 
465 465
 				case 'ticket_end' :
466
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
466
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort;
467 467
 					break;
468 468
 
469 469
 				case 'venue_title' :
470
-					$SQL .= $glue . 'venue_title ' . $sort;
470
+					$SQL .= $glue.'venue_title '.$sort;
471 471
 					break;
472 472
 
473 473
 				case 'city' :
474
-					$SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
474
+					$SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort;
475 475
 				break;
476 476
 
477 477
 				case 'state' :
478
-					$SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
478
+					$SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort;
479 479
 				break;
480 480
 
481 481
 			}
@@ -495,26 +495,26 @@  discard block
 block discarded – undo
495 495
 	 */
496 496
 	public function template_redirect() {
497 497
 		// add event list filters
498
-		add_action( 'loop_start', array( $this, 'event_list_template_filters' ));
498
+		add_action('loop_start', array($this, 'event_list_template_filters'));
499 499
 		// and pagination
500
-		add_action( 'loop_start', array( $this, 'event_list_pagination' ));
501
-		add_action( 'loop_end', array( $this, 'event_list_pagination' ));
500
+		add_action('loop_start', array($this, 'event_list_pagination'));
501
+		add_action('loop_end', array($this, 'event_list_pagination'));
502 502
 		// if NOT a custom template
503
-		if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_events.php' ) {
503
+		if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_events.php') {
504 504
 			// don't know if theme uses the_excerpt
505
-			add_filter( 'the_excerpt', array( $this, 'event_details' ), 100 );
506
-			add_filter( 'the_excerpt', array( $this, 'event_tickets' ), 110 );
507
-			add_filter( 'the_excerpt', array( $this, 'event_datetimes' ), 120 );
508
-			add_filter( 'the_excerpt', array( $this, 'event_venues' ), 130 );
505
+			add_filter('the_excerpt', array($this, 'event_details'), 100);
506
+			add_filter('the_excerpt', array($this, 'event_tickets'), 110);
507
+			add_filter('the_excerpt', array($this, 'event_datetimes'), 120);
508
+			add_filter('the_excerpt', array($this, 'event_venues'), 130);
509 509
 			// or the_content
510
-			add_filter( 'the_content', array( $this, 'event_details' ), 100 );
511
-			add_filter( 'the_content', array( $this, 'event_tickets' ), 110 );
512
-			add_filter( 'the_content', array( $this, 'event_datetimes' ), 120 );
513
-			add_filter( 'the_content', array( $this, 'event_venues' ), 130 );
510
+			add_filter('the_content', array($this, 'event_details'), 100);
511
+			add_filter('the_content', array($this, 'event_tickets'), 110);
512
+			add_filter('the_content', array($this, 'event_datetimes'), 120);
513
+			add_filter('the_content', array($this, 'event_venues'), 130);
514 514
 		} else {
515
-			remove_all_filters( 'excerpt_length' );
516
-			add_filter( 'excerpt_length', array( $this, 'excerpt_length' ), 10 );
517
-			add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 10 );
515
+			remove_all_filters('excerpt_length');
516
+			add_filter('excerpt_length', array($this, 'excerpt_length'), 10);
517
+			add_filter('excerpt_more', array($this, 'excerpt_more'), 10);
518 518
 		}
519 519
 	}
520 520
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 	 *  	@return 		void
528 528
 	 */
529 529
 	public function event_list_pagination() {
530
-		echo '<div class="ee-pagination-dv clear">' . espresso_event_list_pagination() . '</div>';
530
+		echo '<div class="ee-pagination-dv clear">'.espresso_event_list_pagination().'</div>';
531 531
 	}
532 532
 
533 533
 
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
 	 * 	@param		string 	$content
539 539
 	 *  	@return 		void
540 540
 	 */
541
-	public function event_details( $content ) {
542
-		return EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-details.php', array( 'the_content' => $content ), TRUE );
541
+	public function event_details($content) {
542
+		return EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-details.php', array('the_content' => $content), TRUE);
543 543
 	}
544 544
 
545 545
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * 	@param		string 	$content
551 551
 	 *  	@return 		void
552 552
 	 */
553
-	public function event_tickets( $content ) {
554
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-tickets.php', array(), TRUE );
553
+	public function event_tickets($content) {
554
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-tickets.php', array(), TRUE);
555 555
 	}
556 556
 
557 557
 	/**
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 	 * 	@param		string 	$content
562 562
 	 *  	@return 		void
563 563
 	 */
564
-	public function event_datetimes( $content ) {
565
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-datetimes.php', array(), TRUE );
564
+	public function event_datetimes($content) {
565
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-datetimes.php', array(), TRUE);
566 566
 	}
567 567
 
568 568
 	/**
@@ -572,8 +572,8 @@  discard block
 block discarded – undo
572 572
 	 * 	@param		string 	$content
573 573
 	 *  	@return 		void
574 574
 	 */
575
-	public function event_venues( $content ) {
576
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-venues.php', array(), TRUE );
575
+	public function event_venues($content) {
576
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-venues.php', array(), TRUE);
577 577
 	}
578 578
 
579 579
 
@@ -588,13 +588,13 @@  discard block
 block discarded – undo
588 588
 	 *  @return 	void
589 589
 	 */
590 590
 	private function _load_assests() {
591
-		do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' );
591
+		do_action('AHEE__EED_Events_Archive_Filters__before_load_assests');
592 592
         wp_enqueue_style('espresso_default');
593 593
         wp_enqueue_style('espresso_custom_css');
594
-        add_filter( 'FHEE_load_EE_Session', '__return_true' );
595
-		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
596
-		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
597
-			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
594
+        add_filter('FHEE_load_EE_Session', '__return_true');
595
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
596
+		if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
597
+			add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
598 598
 		}
599 599
 		//add_filter( 'the_excerpt', array( $this, 'the_excerpt' ), 999 );
600 600
 	}
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
 	 *  @access 	private
610 610
 	 *  @return 	string
611 611
 	 */
612
-	private function _get_template( $which = 'part' ) {
613
-		return EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php';
612
+	private function _get_template($which = 'part') {
613
+		return EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php';
614 614
 	}
615 615
 
616 616
 
@@ -621,13 +621,13 @@  discard block
 block discarded – undo
621 621
 	 *  @access 	public
622 622
 	 *  @return 	void
623 623
 	 */
624
-	public function excerpt_length( $length ) {
624
+	public function excerpt_length($length) {
625 625
 
626
-		if ( self::$_type == 'grid' ) {
626
+		if (self::$_type == 'grid') {
627 627
 			return 36;
628 628
 		}
629 629
 
630
-		switch ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) {
630
+		switch (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) {
631 631
 			case 'tiny' :
632 632
 				return 12;
633 633
 				break;
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 	 *  @access 	public
652 652
 	 *  @return 	void
653 653
 	 */
654
-	public function excerpt_more( $more ) {
654
+	public function excerpt_more($more) {
655 655
 		return '&hellip;';
656 656
 	}
657 657
 
@@ -681,22 +681,22 @@  discard block
 block discarded – undo
681 681
 	 */
682 682
 	public function wp_enqueue_scripts() {
683 683
 		// get some style
684
-		if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) {
684
+		if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) {
685 685
 			// first check uploads folder
686
-			if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css' )) {
687
-				wp_register_style( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' ));
686
+			if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.css')) {
687
+				wp_register_style('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default'));
688 688
 			} else {
689
-				wp_register_style( 'archive-espresso_events', EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' ));
689
+				wp_register_style('archive-espresso_events', EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default'));
690 690
 			}
691
-			if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js' )) {
692
-				wp_register_script( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE  );
691
+			if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.js')) {
692
+				wp_register_script('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE);
693 693
 			} else {
694
-				wp_register_script( 'archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE );
694
+				wp_register_script('archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE);
695 695
 			}
696
-			wp_enqueue_style( 'archive-espresso_events' );
697
-			wp_enqueue_script( 'jquery-masonry' );
698
-			wp_enqueue_script( 'archive-espresso_events' );
699
-			add_action( 'wp_footer', array( 'EED_Events_Archive_Filters', 'localize_grid_event_lists' ), 1 );
696
+			wp_enqueue_style('archive-espresso_events');
697
+			wp_enqueue_script('jquery-masonry');
698
+			wp_enqueue_script('archive-espresso_events');
699
+			add_action('wp_footer', array('EED_Events_Archive_Filters', 'localize_grid_event_lists'), 1);
700 700
 		}
701 701
 	}
702 702
 
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	 *  @return 	void
712 712
 	 */
713 713
 	public static function localize_grid_event_lists() {
714
-		wp_localize_script( 'archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists );
714
+		wp_localize_script('archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists);
715 715
 	}
716 716
 
717 717
 
@@ -726,9 +726,9 @@  discard block
 block discarded – undo
726 726
 	 */
727 727
 	public static function template_settings_form() {
728 728
 		$EE = EE_Registry::instance();
729
-		$EE->CFG->template_settings->EED_Events_Archive_Filters = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config();
730
-		$EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters( 'FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters );
731
-		EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters );
729
+		$EE->CFG->template_settings->EED_Events_Archive_Filters = isset($EE->CFG->template_settings->EED_Events_Archive_Filters) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config();
730
+		$EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters('FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters);
731
+		EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters);
732 732
 	}
733 733
 
734 734
 
@@ -742,16 +742,16 @@  discard block
 block discarded – undo
742 742
 	 *  @static
743 743
 	 *  @return 	void
744 744
 	 */
745
-	public static function set_default_settings( $CFG ) {
745
+	public static function set_default_settings($CFG) {
746 746
 		//EEH_Debug_Tools::printr( $CFG, '$CFG  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
747
-		$CFG->display_description = isset( $CFG->display_description ) && ! empty( $CFG->display_description ) ? $CFG->display_description : 1;
748
-		$CFG->display_address = isset( $CFG->display_address ) && ! empty( $CFG->display_address ) ? $CFG->display_address : TRUE;
749
-		$CFG->display_venue_details = isset( $CFG->display_venue_details ) && ! empty( $CFG->display_venue_details ) ? $CFG->display_venue_details : TRUE;
750
-		$CFG->display_expired_events = isset( $CFG->display_expired_events ) && ! empty( $CFG->display_expired_events ) ? $CFG->display_expired_events : FALSE;
751
-		$CFG->default_type = isset( $CFG->default_type ) && ! empty( $CFG->default_type ) ? $CFG->default_type : 'grid';
752
-		$CFG->event_list_grid_size = isset( $CFG->event_list_grid_size ) && ! empty( $CFG->event_list_grid_size ) ? $CFG->event_list_grid_size : 'medium';
753
-		$CFG->templates['full'] = isset( $CFG->templates['full'] ) && ! empty( $CFG->templates['full'] ) ? $CFG->templates['full'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php';
754
-		$CFG->templates['part'] = isset( $CFG->templates['part'] ) && ! empty( $CFG->templates['part'] ) ? $CFG->templates['part'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php';
747
+		$CFG->display_description = isset($CFG->display_description) && ! empty($CFG->display_description) ? $CFG->display_description : 1;
748
+		$CFG->display_address = isset($CFG->display_address) && ! empty($CFG->display_address) ? $CFG->display_address : TRUE;
749
+		$CFG->display_venue_details = isset($CFG->display_venue_details) && ! empty($CFG->display_venue_details) ? $CFG->display_venue_details : TRUE;
750
+		$CFG->display_expired_events = isset($CFG->display_expired_events) && ! empty($CFG->display_expired_events) ? $CFG->display_expired_events : FALSE;
751
+		$CFG->default_type = isset($CFG->default_type) && ! empty($CFG->default_type) ? $CFG->default_type : 'grid';
752
+		$CFG->event_list_grid_size = isset($CFG->event_list_grid_size) && ! empty($CFG->event_list_grid_size) ? $CFG->event_list_grid_size : 'medium';
753
+		$CFG->templates['full'] = isset($CFG->templates['full']) && ! empty($CFG->templates['full']) ? $CFG->templates['full'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php';
754
+		$CFG->templates['part'] = isset($CFG->templates['part']) && ! empty($CFG->templates['part']) ? $CFG->templates['part'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php';
755 755
 		return $CFG;
756 756
 	}
757 757
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 	 *  @access 	public
764 764
 	 *  @return 	void
765 765
 	 */
766
-	public function filter_config( $CFG ) {
766
+	public function filter_config($CFG) {
767 767
 		return $CFG;
768 768
 	}
769 769
 
@@ -776,32 +776,32 @@  discard block
 block discarded – undo
776 776
 	 *  @access 	public
777 777
 	 *  @return 	void
778 778
 	 */
779
-	public static function update_template_settings( $CFG, $REQ ) {
779
+	public static function update_template_settings($CFG, $REQ) {
780 780
 //		EEH_Debug_Tools::printr( $REQ, '$REQ  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
781 781
 //		EEH_Debug_Tools::printr( $CFG, '$CFG  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
782 782
 		//$CFG->template_settings->EED_Events_Archive_Filters = new stdClass();
783
-		$CFG->EED_Events_Archive_Filters->display_description = isset( $REQ['display_description_in_event_list'] ) ? absint( $REQ['display_description_in_event_list'] ) : 1;
784
-		$CFG->EED_Events_Archive_Filters->display_address = isset( $REQ['display_address_in_event_list'] ) ? absint( $REQ['display_address_in_event_list'] ) : TRUE;
785
-		$CFG->EED_Events_Archive_Filters->display_venue_details = isset( $REQ['display_venue_details_in_event_list'] ) ? absint( $REQ['display_venue_details_in_event_list'] ) : TRUE;
786
-		$CFG->EED_Events_Archive_Filters->display_expired_events = isset( $REQ['display_expired_events'] ) ? absint( $REQ['display_expired_events'] ) : FALSE;
787
-		$CFG->EED_Events_Archive_Filters->default_type = isset( $REQ['default_type'] ) ? sanitize_text_field( $REQ['default_type'] ) : 'grid';
788
-		$CFG->EED_Events_Archive_Filters->event_list_grid_size = isset( $REQ['event_list_grid_size'] ) ? sanitize_text_field( $REQ['event_list_grid_size'] ) : 'medium';
783
+		$CFG->EED_Events_Archive_Filters->display_description = isset($REQ['display_description_in_event_list']) ? absint($REQ['display_description_in_event_list']) : 1;
784
+		$CFG->EED_Events_Archive_Filters->display_address = isset($REQ['display_address_in_event_list']) ? absint($REQ['display_address_in_event_list']) : TRUE;
785
+		$CFG->EED_Events_Archive_Filters->display_venue_details = isset($REQ['display_venue_details_in_event_list']) ? absint($REQ['display_venue_details_in_event_list']) : TRUE;
786
+		$CFG->EED_Events_Archive_Filters->display_expired_events = isset($REQ['display_expired_events']) ? absint($REQ['display_expired_events']) : FALSE;
787
+		$CFG->EED_Events_Archive_Filters->default_type = isset($REQ['default_type']) ? sanitize_text_field($REQ['default_type']) : 'grid';
788
+		$CFG->EED_Events_Archive_Filters->event_list_grid_size = isset($REQ['event_list_grid_size']) ? sanitize_text_field($REQ['event_list_grid_size']) : 'medium';
789 789
 		$CFG->EED_Events_Archive_Filters->templates = array(
790
-				'full'  => EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'
790
+				'full'  => EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'
791 791
 			);
792 792
 
793
-		switch ( $CFG->EED_Events_Archive_Filters->default_type ) {
793
+		switch ($CFG->EED_Events_Archive_Filters->default_type) {
794 794
 			case 'dates' :
795
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-dates-view.php';
795
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-dates-view.php';
796 796
 				break;
797 797
 			case 'text' :
798
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-text-view.php';
798
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-text-view.php';
799 799
 				break;
800 800
 			default :
801
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php';
801
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php';
802 802
 		}
803 803
 
804
-		$CFG->EED_Events_Archive_Filters = isset( $REQ['reset_event_list_settings'] ) && absint( $REQ['reset_event_list_settings'] ) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters;
804
+		$CFG->EED_Events_Archive_Filters = isset($REQ['reset_event_list_settings']) && absint($REQ['reset_event_list_settings']) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters;
805 805
 		return $CFG;
806 806
 	}
807 807
 
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 	 *  @return 	void
817 817
 	 */
818 818
 	public static function get_template_part() {
819
-		switch ( self::$_type ) {
819
+		switch (self::$_type) {
820 820
 			case 'dates' :
821 821
 					return 'archive-espresso_events-dates-view.php';
822 822
 				break;
@@ -840,13 +840,13 @@  discard block
 block discarded – undo
840 840
 	 */
841 841
 	public function event_list_template_filters() {
842 842
 		$args = array(
843
-			'form_url' => get_post_type_archive_link( 'espresso_events' ), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ),
843
+			'form_url' => get_post_type_archive_link('espresso_events'), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ),
844 844
 			'elf_month' => EED_Events_Archive_Filters::_display_month(),
845 845
 			'elf_category' => EED_Events_Archive_Filters::_event_category_slug(),
846 846
 			'elf_show_expired' => EED_Events_Archive_Filters::_show_expired(),
847 847
 			'elf_type' => self::$_type
848 848
 		);
849
-		EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-filters.php', $args );
849
+		EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-filters.php', $args);
850 850
 	}
851 851
 
852 852
 
@@ -859,16 +859,16 @@  discard block
 block discarded – undo
859 859
 	 *  @access 	public
860 860
 	 *  @return 	void
861 861
 	 */
862
-	public static function event_list_css( $extra_class = '' ) {
862
+	public static function event_list_css($extra_class = '') {
863 863
 		$EE = EE_Registry::instance();
864
-		$event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array();
864
+		$event_list_css = ! empty($extra_class) ? array($extra_class) : array();
865 865
 		$event_list_css[] = 'espresso-event-list-event';
866
-		if ( self::$_type == 'grid' ) {
867
-			$event_list_grid_size = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium';
868
-			$event_list_css[] = $event_list_grid_size . '-event-list-grid';
866
+		if (self::$_type == 'grid') {
867
+			$event_list_grid_size = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium';
868
+			$event_list_css[] = $event_list_grid_size.'-event-list-grid';
869 869
 		}
870
-		$event_list_css = apply_filters( 'EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css );
871
-		return implode( ' ', $event_list_css );
870
+		$event_list_css = apply_filters('EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css);
871
+		return implode(' ', $event_list_css);
872 872
 	}
873 873
 
874 874
 
@@ -894,9 +894,9 @@  discard block
 block discarded – undo
894 894
 	 *  @access 	public
895 895
 	 *  @return 	void
896 896
 	 */
897
-	public static function display_description( $value ) {
897
+	public static function display_description($value) {
898 898
 		$EE = EE_Registry::instance();
899
-		$display_description= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1;
899
+		$display_description = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_description) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1;
900 900
 		return $display_description === $value ? TRUE : FALSE;
901 901
 	}
902 902
 
@@ -910,9 +910,9 @@  discard block
 block discarded – undo
910 910
 	 */
911 911
 	public static function display_venue_details() {
912 912
 		$EE = EE_Registry::instance();
913
-		$display_venue_details= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE;
913
+		$display_venue_details = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE;
914 914
 		$venue_name = EEH_Venue_View::venue_name();
915
-		return $display_venue_details && ! empty( $venue_name ) ? TRUE : FALSE;
915
+		return $display_venue_details && ! empty($venue_name) ? TRUE : FALSE;
916 916
 	}
917 917
 
918 918
 
@@ -924,9 +924,9 @@  discard block
 block discarded – undo
924 924
 	 */
925 925
 	public static function display_address() {
926 926
 		$EE = EE_Registry::instance();
927
-		$display_address= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE;
927
+		$display_address = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_address) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE;
928 928
 		$venue_name = EEH_Venue_View::venue_name();
929
-		return $display_address && ! empty( $venue_name ) ? TRUE : FALSE;
929
+		return $display_address && ! empty($venue_name) ? TRUE : FALSE;
930 930
 	}
931 931
 
932 932
 
@@ -940,22 +940,22 @@  discard block
 block discarded – undo
940 940
 	public static function pagination() {
941 941
 		global $wp_query;
942 942
 		$big = 999999999; // need an unlikely integer
943
-		$pagination = paginate_links( array(
944
-			'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
943
+		$pagination = paginate_links(array(
944
+			'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
945 945
 			'format' => '?paged=%#%',
946
-			'current' => max( 1, get_query_var('paged') ),
946
+			'current' => max(1, get_query_var('paged')),
947 947
 			'total' => $wp_query->max_num_pages,
948 948
 			'show_all'     => TRUE,
949 949
 			'end_size'     => 10,
950 950
 			'mid_size'     => 6,
951 951
 			'prev_next'    => TRUE,
952
-			'prev_text'    => __( '&lsaquo; PREV', 'event_espresso' ),
953
-			'next_text'    => __( 'NEXT &rsaquo;', 'event_espresso' ),
952
+			'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
953
+			'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
954 954
 			'type'         => 'plain',
955 955
 			'add_args'     => FALSE,
956 956
 			'add_fragment' => ''
957 957
 		));
958
-		return ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
958
+		return ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : '';
959 959
 	}
960 960
 
961 961
 
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
 	 *  @return 	void
970 970
 	 */
971 971
 	public static function event_list_title() {
972
-		return apply_filters( 'EED_Events_Archive_Filters__event_list_title__event_list_title', __( 'Upcoming Events', 'event_espresso' ));
972
+		return apply_filters('EED_Events_Archive_Filters__event_list_title__event_list_title', __('Upcoming Events', 'event_espresso'));
973 973
 	}
974 974
 
975 975
 
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 1 patch
Indentation   +1221 added lines, -1221 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -16,1226 +16,1226 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Extend_Events_Admin_Page constructor.
21
-     *
22
-     * @param bool $routing
23
-     */
24
-    public function __construct($routing = true)
25
-    {
26
-        parent::__construct($routing);
27
-        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
-        }
32
-    }
33
-
34
-
35
-
36
-    protected function _extend_page_config()
37
-    {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
-        //is there a evt_id in the request?
40
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
-            ? $this->_req_data['EVT_ID']
42
-            : 0;
43
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
-        //tkt_id?
45
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
-            ? $this->_req_data['TKT_ID']
47
-            : 0;
48
-        $new_page_routes = array(
49
-            'duplicate_event'          => array(
50
-                'func'       => '_duplicate_event',
51
-                'capability' => 'ee_edit_event',
52
-                'obj_id'     => $evt_id,
53
-                'noheader'   => true,
54
-            ),
55
-            'ticket_list_table'        => array(
56
-                'func'       => '_tickets_overview_list_table',
57
-                'capability' => 'ee_read_default_tickets',
58
-            ),
59
-            'trash_ticket'             => array(
60
-                'func'       => '_trash_or_restore_ticket',
61
-                'capability' => 'ee_delete_default_ticket',
62
-                'obj_id'     => $tkt_id,
63
-                'noheader'   => true,
64
-                'args'       => array('trash' => true),
65
-            ),
66
-            'trash_tickets'            => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_tickets',
69
-                'noheader'   => true,
70
-                'args'       => array('trash' => true),
71
-            ),
72
-            'restore_ticket'           => array(
73
-                'func'       => '_trash_or_restore_ticket',
74
-                'capability' => 'ee_delete_default_ticket',
75
-                'obj_id'     => $tkt_id,
76
-                'noheader'   => true,
77
-            ),
78
-            'restore_tickets'          => array(
79
-                'func'       => '_trash_or_restore_ticket',
80
-                'capability' => 'ee_delete_default_tickets',
81
-                'noheader'   => true,
82
-            ),
83
-            'delete_ticket'            => array(
84
-                'func'       => '_delete_ticket',
85
-                'capability' => 'ee_delete_default_ticket',
86
-                'obj_id'     => $tkt_id,
87
-                'noheader'   => true,
88
-            ),
89
-            'delete_tickets'           => array(
90
-                'func'       => '_delete_ticket',
91
-                'capability' => 'ee_delete_default_tickets',
92
-                'noheader'   => true,
93
-            ),
94
-            'import_page'              => array(
95
-                'func'       => '_import_page',
96
-                'capability' => 'import',
97
-            ),
98
-            'import'                   => array(
99
-                'func'       => '_import_events',
100
-                'capability' => 'import',
101
-                'noheader'   => true,
102
-            ),
103
-            'import_events'            => array(
104
-                'func'       => '_import_events',
105
-                'capability' => 'import',
106
-                'noheader'   => true,
107
-            ),
108
-            'export_events'            => array(
109
-                'func'       => '_events_export',
110
-                'capability' => 'export',
111
-                'noheader'   => true,
112
-            ),
113
-            'export_categories'        => array(
114
-                'func'       => '_categories_export',
115
-                'capability' => 'export',
116
-                'noheader'   => true,
117
-            ),
118
-            'sample_export_file'       => array(
119
-                'func'       => '_sample_export_file',
120
-                'capability' => 'export',
121
-                'noheader'   => true,
122
-            ),
123
-            'update_template_settings' => array(
124
-                'func'       => '_update_template_settings',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ),
128
-        );
129
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
-        //partial route/config override
131
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
-        $this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
-        $this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
-        $this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
-        $this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
-        //add tickets tab but only if there are more than one default ticket!
138
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
-            array(array('TKT_is_default' => 1)),
140
-            'TKT_ID',
141
-            true
142
-        );
143
-        if ($tkt_count > 1) {
144
-            $new_page_config = array(
145
-                'ticket_list_table' => array(
146
-                    'nav'           => array(
147
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
148
-                        'order' => 60,
149
-                    ),
150
-                    'list_table'    => 'Tickets_List_Table',
151
-                    'require_nonce' => false,
152
-                ),
153
-            );
154
-        }
155
-        //template settings
156
-        $new_page_config['template_settings'] = array(
157
-            'nav'           => array(
158
-                'label' => esc_html__('Templates', 'event_espresso'),
159
-                'order' => 30,
160
-            ),
161
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
-            'help_tabs'     => array(
163
-                'general_settings_templates_help_tab' => array(
164
-                    'title'    => esc_html__('Templates', 'event_espresso'),
165
-                    'filename' => 'general_settings_templates',
166
-                ),
167
-            ),
168
-            'help_tour'     => array('Templates_Help_Tour'),
169
-            'require_nonce' => false,
170
-        );
171
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
172
-        //add filters and actions
173
-        //modifying _views
174
-        add_filter(
175
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
-            array($this, 'add_additional_datetime_button'),
177
-            10,
178
-            2
179
-        );
180
-        add_filter(
181
-            'FHEE_event_datetime_metabox_clone_button_template',
182
-            array($this, 'add_datetime_clone_button'),
183
-            10,
184
-            2
185
-        );
186
-        add_filter(
187
-            'FHEE_event_datetime_metabox_timezones_template',
188
-            array($this, 'datetime_timezones_template'),
189
-            10,
190
-            2
191
-        );
192
-        //filters for event list table
193
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
-        add_filter(
195
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
-            array($this, 'extra_list_table_actions'),
197
-            10,
198
-            2
199
-        );
200
-        //legend item
201
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
-        add_action('admin_init', array($this, 'admin_init'));
203
-        //heartbeat stuff
204
-        add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * admin_init
211
-     */
212
-    public function admin_init()
213
-    {
214
-        EE_Registry::$i18n_js_strings = array_merge(
215
-            EE_Registry::$i18n_js_strings,
216
-            array(
217
-                'image_confirm'          => esc_html__(
218
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
-                    'event_espresso'
220
-                ),
221
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
-            )
227
-        );
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
-     * accordingly.
235
-     *
236
-     * @param array $response The existing heartbeat response array.
237
-     * @param array $data     The incoming data package.
238
-     * @return array  possibly appended response.
239
-     */
240
-    public function heartbeat_response($response, $data)
241
-    {
242
-        /**
243
-         * check whether count of tickets is approaching the potential
244
-         * limits for the server.
245
-         */
246
-        if ( ! empty($data['input_count'])) {
247
-            $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
-                $data['input_count']
249
-            );
250
-        }
251
-        return $response;
252
-    }
253
-
254
-
255
-
256
-    protected function _add_screen_options_ticket_list_table()
257
-    {
258
-        $this->_per_page_screen_option();
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * @param string $return
265
-     * @param int    $id
266
-     * @param string $new_title
267
-     * @param string $new_slug
268
-     * @return string
269
-     */
270
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
-    {
272
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
-        //make sure this is only when editing
274
-        if ( ! empty($id)) {
275
-            $href  = EE_Admin_Page::add_query_args_and_nonce(
276
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
-                $this->_admin_base_url
278
-            );
279
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
280
-            $return .= '<a href="'
281
-                       . $href
282
-                       . '" title="'
283
-                       . $title
284
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
-                       . $title
286
-                       . '</button>';
287
-        }
288
-        return $return;
289
-    }
290
-
291
-
292
-
293
-    public function _set_list_table_views_ticket_list_table()
294
-    {
295
-        $this->_views = array(
296
-            'all'     => array(
297
-                'slug'        => 'all',
298
-                'label'       => esc_html__('All', 'event_espresso'),
299
-                'count'       => 0,
300
-                'bulk_action' => array(
301
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
-                ),
303
-            ),
304
-            'trashed' => array(
305
-                'slug'        => 'trashed',
306
-                'label'       => esc_html__('Trash', 'event_espresso'),
307
-                'count'       => 0,
308
-                'bulk_action' => array(
309
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
-                ),
312
-            ),
313
-        );
314
-    }
315
-
316
-
317
-
318
-    public function load_scripts_styles_edit()
319
-    {
320
-        wp_register_script(
321
-            'ee-event-editor-heartbeat',
322
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
-            array('ee_admin_js', 'heartbeat'),
324
-            EVENT_ESPRESSO_VERSION,
325
-            true
326
-        );
327
-        wp_enqueue_script('ee-accounting');
328
-        //styles
329
-        wp_enqueue_style('espresso-ui-theme');
330
-        wp_enqueue_script('event_editor_js');
331
-        wp_enqueue_script('ee-event-editor-heartbeat');
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * @param $template
338
-     * @param $template_args
339
-     * @return mixed
340
-     */
341
-    public function add_additional_datetime_button($template, $template_args)
342
-    {
343
-        return EEH_Template::display_template(
344
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
345
-            $template_args,
346
-            true
347
-        );
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * @param $template
354
-     * @param $template_args
355
-     * @return mixed
356
-     */
357
-    public function add_datetime_clone_button($template, $template_args)
358
-    {
359
-        return EEH_Template::display_template(
360
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
361
-            $template_args,
362
-            true
363
-        );
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * @param $template
370
-     * @param $template_args
371
-     * @return mixed
372
-     */
373
-    public function datetime_timezones_template($template, $template_args)
374
-    {
375
-        return EEH_Template::display_template(
376
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
377
-            $template_args,
378
-            true
379
-        );
380
-    }
381
-
382
-
383
-
384
-    protected function _set_list_table_views_default()
385
-    {
386
-        parent::_set_list_table_views_default();
387
-        $new_views = array(
388
-            'today' => array(
389
-                'slug'        => 'today',
390
-                'label'       => esc_html__('Today', 'event_espresso'),
391
-                'count'       => $this->total_events_today(),
392
-                'bulk_action' => array(
393
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
394
-                ),
395
-            ),
396
-            'month' => array(
397
-                'slug'        => 'month',
398
-                'label'       => esc_html__('This Month', 'event_espresso'),
399
-                'count'       => $this->total_events_this_month(),
400
-                'bulk_action' => array(
401
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
-                ),
403
-            ),
404
-        );
405
-        $this->_views = array_merge($this->_views, $new_views);
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * @param array     $action_links
412
-     * @param \EE_Event $event
413
-     * @return array
414
-     */
415
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
416
-    {
417
-        if (
418
-        EE_Registry::instance()->CAP->current_user_can(
419
-            'ee_read_registrations',
420
-            'espresso_registrations_reports',
421
-            $event->ID()
422
-        )
423
-        ) {
424
-            $reports_query_args = array(
425
-                'action' => 'reports',
426
-                'EVT_ID' => $event->ID(),
427
-            );
428
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
429
-            $action_links[]     = '<a href="'
430
-                                  . $reports_link
431
-                                  . '" title="'
432
-                                  . esc_attr__('View Report', 'event_espresso')
433
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
434
-                                  . "\n\t";
435
-        }
436
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
437
-            EE_Registry::instance()->load_helper('MSG_Template');
438
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
439
-                'see_notifications_for',
440
-                null,
441
-                array('EVT_ID' => $event->ID())
442
-            );
443
-        }
444
-        return $action_links;
445
-    }
446
-
447
-
448
-
449
-    /**
450
-     * @param $items
451
-     * @return mixed
452
-     */
453
-    public function additional_legend_items($items)
454
-    {
455
-        if (
456
-        EE_Registry::instance()->CAP->current_user_can(
457
-            'ee_read_registrations',
458
-            'espresso_registrations_reports'
459
-        )
460
-        ) {
461
-            $items['reports'] = array(
462
-                'class' => 'dashicons dashicons-chart-bar',
463
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
464
-            );
465
-        }
466
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
467
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
468
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
469
-                $items['view_related_messages'] = array(
470
-                    'class' => $related_for_icon['css_class'],
471
-                    'desc'  => $related_for_icon['label'],
472
-                );
473
-            }
474
-        }
475
-        return $items;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * This is the callback method for the duplicate event route
482
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
483
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
484
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
485
-     * After duplication the redirect is to the new event edit page.
486
-     *
487
-     * @return void
488
-     * @access protected
489
-     * @throws EE_Error If EE_Event is not available with given ID
490
-     */
491
-    protected function _duplicate_event()
492
-    {
493
-        // first make sure the ID for the event is in the request.
494
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
495
-        if ( ! isset($this->_req_data['EVT_ID'])) {
496
-            EE_Error::add_error(
497
-                esc_html__(
498
-                    'In order to duplicate an event an Event ID is required.  None was given.',
499
-                    'event_espresso'
500
-                ),
501
-                __FILE__,
502
-                __FUNCTION__,
503
-                __LINE__
504
-            );
505
-            $this->_redirect_after_action(false, '', '', array(), true);
506
-            return;
507
-        }
508
-        //k we've got EVT_ID so let's use that to get the event we'll duplicate
509
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
510
-        if ( ! $orig_event instanceof EE_Event) {
511
-            throw new EE_Error(
512
-                sprintf(
513
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
514
-                    $this->_req_data['EVT_ID']
515
-                )
516
-            );
517
-        }
518
-        //k now let's clone the $orig_event before getting relations
519
-        $new_event = clone $orig_event;
520
-        //original datetimes
521
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
522
-        //other original relations
523
-        $orig_ven = $orig_event->get_many_related('Venue');
524
-        //reset the ID and modify other details to make it clear this is a dupe
525
-        $new_event->set('EVT_ID', 0);
526
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
527
-        $new_event->set('EVT_name', $new_name);
528
-        $new_event->set(
529
-            'EVT_slug',
530
-            wp_unique_post_slug(
531
-                sanitize_title($orig_event->name()),
532
-                0,
533
-                'publish',
534
-                'espresso_events',
535
-                0
536
-            )
537
-        );
538
-        $new_event->set('status', 'draft');
539
-        //duplicate discussion settings
540
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
541
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
542
-        //save the new event
543
-        $new_event->save();
544
-        //venues
545
-        foreach ($orig_ven as $ven) {
546
-            $new_event->_add_relation_to($ven, 'Venue');
547
-        }
548
-        $new_event->save();
549
-        //now we need to get the question group relations and handle that
550
-        //first primary question groups
551
-        $orig_primary_qgs = $orig_event->get_many_related(
552
-            'Question_Group',
553
-            array(array('Event_Question_Group.EQG_primary' => 1))
554
-        );
555
-        if ( ! empty($orig_primary_qgs)) {
556
-            foreach ($orig_primary_qgs as $id => $obj) {
557
-                if ($obj instanceof EE_Question_Group) {
558
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
559
-                }
560
-            }
561
-        }
562
-        //next additional attendee question groups
563
-        $orig_additional_qgs = $orig_event->get_many_related(
564
-            'Question_Group',
565
-            array(array('Event_Question_Group.EQG_primary' => 0))
566
-        );
567
-        if ( ! empty($orig_additional_qgs)) {
568
-            foreach ($orig_additional_qgs as $id => $obj) {
569
-                if ($obj instanceof EE_Question_Group) {
570
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
571
-                }
572
-            }
573
-        }
574
-        //now save
575
-        $new_event->save();
576
-        //k now that we have the new event saved we can loop through the datetimes and start adding relations.
577
-        $cloned_tickets = array();
578
-        foreach ($orig_datetimes as $orig_dtt) {
579
-            if ( ! $orig_dtt instanceof EE_Datetime) {
580
-                continue;
581
-            }
582
-            $new_dtt   = clone $orig_dtt;
583
-            $orig_tkts = $orig_dtt->tickets();
584
-            //save new dtt then add to event
585
-            $new_dtt->set('DTT_ID', 0);
586
-            $new_dtt->set('DTT_sold', 0);
587
-            $new_dtt->save();
588
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
589
-            $new_event->save();
590
-            //now let's get the ticket relations setup.
591
-            foreach ((array)$orig_tkts as $orig_tkt) {
592
-                //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
593
-                if ( ! $orig_tkt instanceof EE_Ticket) {
594
-                    continue;
595
-                }
596
-                //is this ticket archived?  If it is then let's skip
597
-                if ($orig_tkt->get('TKT_deleted')) {
598
-                    continue;
599
-                }
600
-                // does this original ticket already exist in the clone_tickets cache?
601
-                //  If so we'll just use the new ticket from it.
602
-                if (isset($cloned_tickets[$orig_tkt->ID()])) {
603
-                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
604
-                } else {
605
-                    $new_tkt = clone $orig_tkt;
606
-                    //get relations on the $orig_tkt that we need to setup.
607
-                    $orig_prices = $orig_tkt->prices();
608
-                    $new_tkt->set('TKT_ID', 0);
609
-                    $new_tkt->set('TKT_sold', 0);
610
-                    $new_tkt->set('TKT_reserved', 0);
611
-                    $new_tkt->save(); //make sure new ticket has ID.
612
-                    //price relations on new ticket need to be setup.
613
-                    foreach ($orig_prices as $orig_price) {
614
-                        $new_price = clone $orig_price;
615
-                        $new_price->set('PRC_ID', 0);
616
-                        $new_price->save();
617
-                        $new_tkt->_add_relation_to($new_price, 'Price');
618
-                        $new_tkt->save();
619
-                    }
620
-                }
621
-                // k now we can add the new ticket as a relation to the new datetime
622
-                // and make sure its added to our cached $cloned_tickets array
623
-                // for use with later datetimes that have the same ticket.
624
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
625
-                $new_dtt->save();
626
-                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
627
-            }
628
-        }
629
-        //clone taxonomy information
630
-        $taxonomies_to_clone_with = apply_filters(
631
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
632
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
633
-        );
634
-        //get terms for original event (notice)
635
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
636
-        //loop through terms and add them to new event.
637
-        foreach ($orig_terms as $term) {
638
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
639
-        }
640
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
641
-        //now let's redirect to the edit page for this duplicated event if we have a new event id.
642
-        if ($new_event->ID()) {
643
-            $redirect_args = array(
644
-                'post'   => $new_event->ID(),
645
-                'action' => 'edit',
646
-            );
647
-            EE_Error::add_success(
648
-                esc_html__(
649
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
650
-                    'event_espresso'
651
-                )
652
-            );
653
-        } else {
654
-            $redirect_args = array(
655
-                'action' => 'default',
656
-            );
657
-            EE_Error::add_error(
658
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
659
-                __FILE__,
660
-                __FUNCTION__,
661
-                __LINE__
662
-            );
663
-        }
664
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
665
-    }
666
-
667
-
668
-    protected function _import_page()
669
-    {
670
-        $title                                      = esc_html__('Import', 'event_espresso');
671
-        $intro                                      = esc_html__(
672
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
673
-            'event_espresso'
674
-        );
675
-        $form_url                                   = EVENTS_ADMIN_URL;
676
-        $action                                     = 'import_events';
677
-        $type                                       = 'csv';
678
-        $this->_template_args['form']               = EE_Import::instance()->upload_form(
679
-            $title, $intro, $form_url, $action, $type
680
-        );
681
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
682
-            array('action' => 'sample_export_file'),
683
-            $this->_admin_base_url
684
-        );
685
-        $content                                    = EEH_Template::display_template(
686
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
687
-            $this->_template_args,
688
-            true
689
-        );
690
-        $this->_template_args['admin_page_content'] = $content;
691
-        $this->display_admin_page_with_sidebar();
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * _import_events
698
-     * This handles displaying the screen and running imports for importing events.
699
-     *
700
-     * @return void
701
-     */
702
-    protected function _import_events()
703
-    {
704
-        require_once(EE_CLASSES . 'EE_Import.class.php');
705
-        $success = EE_Import::instance()->import();
706
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * _events_export
713
-     * Will export all (or just the given event) to a Excel compatible file.
714
-     *
715
-     * @access protected
716
-     * @return void
717
-     */
718
-    protected function _events_export()
719
-    {
720
-        if (isset($this->_req_data['EVT_ID'])) {
721
-            $event_ids = $this->_req_data['EVT_ID'];
722
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
723
-            $event_ids = $this->_req_data['EVT_IDs'];
724
-        } else {
725
-            $event_ids = null;
726
-        }
727
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
728
-        $new_request_args = array(
729
-            'export' => 'report',
730
-            'action' => 'all_event_data',
731
-            'EVT_ID' => $event_ids,
732
-        );
733
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
734
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
735
-            require_once(EE_CLASSES . 'EE_Export.class.php');
736
-            $EE_Export = EE_Export::instance($this->_req_data);
737
-            $EE_Export->export();
738
-        }
739
-    }
740
-
741
-
742
-
743
-    /**
744
-     * handle category exports()
745
-     *
746
-     * @return void
747
-     */
748
-    protected function _categories_export()
749
-    {
750
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
751
-        $new_request_args = array(
752
-            'export'       => 'report',
753
-            'action'       => 'categories',
754
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
755
-        );
756
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
757
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
758
-            require_once(EE_CLASSES . 'EE_Export.class.php');
759
-            $EE_Export = EE_Export::instance($this->_req_data);
760
-            $EE_Export->export();
761
-        }
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * Creates a sample CSV file for importing
768
-     */
769
-    protected function _sample_export_file()
770
-    {
771
-        //		require_once(EE_CLASSES . 'EE_Export.class.php');
772
-        EE_Export::instance()->export_sample();
773
-    }
774
-
775
-
776
-
777
-    /*************        Template Settings        *************/
778
-    protected function _template_settings()
779
-    {
780
-        $this->_template_args['values'] = $this->_yes_no_values;
781
-        /**
782
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
783
-         * from General_Settings_Admin_Page to here.
784
-         */
785
-        $this->_template_args = apply_filters(
786
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
787
-            $this->_template_args
788
-        );
789
-        $this->_set_add_edit_form_tags('update_template_settings');
790
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
791
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
792
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
793
-            $this->_template_args,
794
-            true
795
-        );
796
-        $this->display_admin_page_with_sidebar();
797
-    }
798
-
799
-
800
-
801
-    protected function _update_template_settings()
802
-    {
803
-        /**
804
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
-         * from General_Settings_Admin_Page to here.
806
-         */
807
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
808
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
809
-            EE_Registry::instance()->CFG->template_settings,
810
-            $this->_req_data
811
-        );
812
-        //update custom post type slugs and detect if we need to flush rewrite rules
813
-        $old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
814
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
815
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
816
-            : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
817
-        $what                                              = 'Template Settings';
818
-        $success                                           = $this->_update_espresso_configuration(
819
-            $what,
820
-            EE_Registry::instance()->CFG->template_settings,
821
-            __FILE__,
822
-            __FUNCTION__,
823
-            __LINE__
824
-        );
825
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
826
-            update_option('ee_flush_rewrite_rules', true);
827
-        }
828
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
829
-    }
830
-
831
-
832
-
833
-    /**
834
-     * _premium_event_editor_meta_boxes
835
-     * add all metaboxes related to the event_editor
836
-     *
837
-     * @access protected
838
-     * @return void
839
-     */
840
-    protected function _premium_event_editor_meta_boxes()
841
-    {
842
-        $this->verify_cpt_object();
843
-        add_meta_box(
844
-            'espresso_event_editor_event_options',
845
-            esc_html__('Event Registration Options', 'event_espresso'),
846
-            array($this, 'registration_options_meta_box'),
847
-            $this->page_slug,
848
-            'side',
849
-            'core'
850
-        );
851
-    }
852
-
853
-
854
-
855
-    /**
856
-     * override caf metabox
857
-     *
858
-     * @return void
859
-     */
860
-    public function registration_options_meta_box()
861
-    {
862
-        $yes_no_values = array(
863
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
864
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
865
-        );
866
-        $default_reg_status_values = EEM_Registration::reg_status_array(
867
-            array(
868
-                EEM_Registration::status_id_cancelled,
869
-                EEM_Registration::status_id_declined,
870
-                EEM_Registration::status_id_incomplete,
871
-                EEM_Registration::status_id_wait_list,
872
-            ),
873
-            true
874
-        );
875
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
876
-        $template_args['_event']                          = $this->_cpt_model_obj;
877
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
878
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
879
-            'default_reg_status',
880
-            $default_reg_status_values,
881
-            $this->_cpt_model_obj->default_registration_status()
882
-        );
883
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
884
-            'display_desc',
885
-            $yes_no_values,
886
-            $this->_cpt_model_obj->display_description()
887
-        );
888
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
889
-            'display_ticket_selector',
890
-            $yes_no_values,
891
-            $this->_cpt_model_obj->display_ticket_selector(),
892
-            '',
893
-            '',
894
-            false
895
-        );
896
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
897
-            'EVT_default_registration_status',
898
-            $default_reg_status_values,
899
-            $this->_cpt_model_obj->default_registration_status()
900
-        );
901
-        $template_args['additional_registration_options'] = apply_filters(
902
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
903
-            '',
904
-            $template_args,
905
-            $yes_no_values,
906
-            $default_reg_status_values
907
-        );
908
-        EEH_Template::display_template(
909
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
910
-            $template_args
911
-        );
912
-    }
913
-
914
-
915
-
916
-    /**
917
-     * wp_list_table_mods for caf
918
-     * ============================
919
-     */
920
-    /**
921
-     * hook into list table filters and provide filters for caffeinated list table
922
-     *
923
-     * @param  array $old_filters    any existing filters present
924
-     * @param  array $list_table_obj the list table object
925
-     * @return array                  new filters
926
-     */
927
-    public function list_table_filters($old_filters, $list_table_obj)
928
-    {
929
-        $filters = array();
930
-        //first month/year filters
931
-        $filters[] = $this->espresso_event_months_dropdown();
932
-        $status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
933
-        //active status dropdown
934
-        if ($status !== 'draft') {
935
-            $filters[] = $this->active_status_dropdown(
936
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
937
-            );
938
-        }
939
-        //category filter
940
-        $filters[] = $this->category_dropdown();
941
-        return array_merge($old_filters, $filters);
942
-    }
943
-
944
-
945
-
946
-    /**
947
-     * espresso_event_months_dropdown
948
-     *
949
-     * @access public
950
-     * @return string                dropdown listing month/year selections for events.
951
-     */
952
-    public function espresso_event_months_dropdown()
953
-    {
954
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
955
-        // Note we need to include any other filters that are set!
956
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
957
-        //categories?
958
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
959
-            ? $this->_req_data['EVT_CAT']
960
-            : null;
961
-        //active status?
962
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
963
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
964
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
965
-    }
966
-
967
-
968
-
969
-    /**
970
-     * returns a list of "active" statuses on the event
971
-     *
972
-     * @param  string $current_value whatever the current active status is
973
-     * @return string
974
-     */
975
-    public function active_status_dropdown($current_value = '')
976
-    {
977
-        $select_name = 'active_status';
978
-        $values      = array(
979
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
980
-            'active'   => esc_html__('Active', 'event_espresso'),
981
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
982
-            'expired'  => esc_html__('Expired', 'event_espresso'),
983
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
984
-        );
985
-        $id          = 'id="espresso-active-status-dropdown-filter"';
986
-        $class       = 'wide';
987
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
988
-    }
989
-
990
-
991
-
992
-    /**
993
-     * output a dropdown of the categories for the category filter on the event admin list table
994
-     *
995
-     * @access  public
996
-     * @return string html
997
-     */
998
-    public function category_dropdown()
999
-    {
1000
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1001
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * get total number of events today
1008
-     *
1009
-     * @access public
1010
-     * @return int
1011
-     */
1012
-    public function total_events_today()
1013
-    {
1014
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1015
-            'DTT_EVT_start',
1016
-            date('Y-m-d') . ' 00:00:00',
1017
-            'Y-m-d H:i:s',
1018
-            'UTC'
1019
-        );
1020
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1021
-            'DTT_EVT_start',
1022
-            date('Y-m-d') . ' 23:59:59',
1023
-            'Y-m-d H:i:s',
1024
-            'UTC'
1025
-        );
1026
-        $where = array(
1027
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1028
-        );
1029
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1030
-        return $count;
1031
-    }
1032
-
1033
-
1034
-
1035
-    /**
1036
-     * get total number of events this month
1037
-     *
1038
-     * @access public
1039
-     * @return int
1040
-     */
1041
-    public function total_events_this_month()
1042
-    {
1043
-        //Dates
1044
-        $this_year_r     = date('Y');
1045
-        $this_month_r    = date('m');
1046
-        $days_this_month = date('t');
1047
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1048
-            'DTT_EVT_start',
1049
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1050
-            'Y-m-d H:i:s',
1051
-            'UTC'
1052
-        );
1053
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1054
-            'DTT_EVT_start',
1055
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1056
-            'Y-m-d H:i:s',
1057
-            'UTC'
1058
-        );
1059
-        $where = array(
1060
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1061
-        );
1062
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1063
-        return $count;
1064
-    }
1065
-
1066
-
1067
-
1068
-    /** DEFAULT TICKETS STUFF **/
1069
-    public function _tickets_overview_list_table()
1070
-    {
1071
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1072
-        $this->display_admin_list_table_page_with_no_sidebar();
1073
-    }
1074
-
1075
-
1076
-
1077
-    /**
1078
-     * @param int  $per_page
1079
-     * @param bool $count
1080
-     * @param bool $trashed
1081
-     * @return \EE_Soft_Delete_Base_Class[]|int
1082
-     */
1083
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1084
-    {
1085
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1086
-        $order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1087
-        switch ($orderby) {
1088
-            case 'TKT_name' :
1089
-                $orderby = array('TKT_name' => $order);
1090
-                break;
1091
-            case 'TKT_price' :
1092
-                $orderby = array('TKT_price' => $order);
1093
-                break;
1094
-            case 'TKT_uses' :
1095
-                $orderby = array('TKT_uses' => $order);
1096
-                break;
1097
-            case 'TKT_min' :
1098
-                $orderby = array('TKT_min' => $order);
1099
-                break;
1100
-            case 'TKT_max' :
1101
-                $orderby = array('TKT_max' => $order);
1102
-                break;
1103
-            case 'TKT_qty' :
1104
-                $orderby = array('TKT_qty' => $order);
1105
-                break;
1106
-        }
1107
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1108
-            ? $this->_req_data['paged']
1109
-            : 1;
1110
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1111
-            ? $this->_req_data['perpage']
1112
-            : $per_page;
1113
-        $_where       = array(
1114
-            'TKT_is_default' => 1,
1115
-            'TKT_deleted'    => $trashed,
1116
-        );
1117
-        $offset       = ($current_page - 1) * $per_page;
1118
-        $limit        = array($offset, $per_page);
1119
-        if (isset($this->_req_data['s'])) {
1120
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1121
-            $_where['OR'] = array(
1122
-                'TKT_name'        => array('LIKE', $sstr),
1123
-                'TKT_description' => array('LIKE', $sstr),
1124
-            );
1125
-        }
1126
-        $query_params = array(
1127
-            $_where,
1128
-            'order_by' => $orderby,
1129
-            'limit'    => $limit,
1130
-            'group_by' => 'TKT_ID',
1131
-        );
1132
-        if ($count) {
1133
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1134
-        } else {
1135
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1136
-        }
1137
-    }
1138
-
1139
-
1140
-
1141
-    /**
1142
-     * @param bool $trash
1143
-     */
1144
-    protected function _trash_or_restore_ticket($trash = false)
1145
-    {
1146
-        $success = 1;
1147
-        $TKT = EEM_Ticket::instance();
1148
-        //checkboxes?
1149
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1150
-            //if array has more than one element then success message should be plural
1151
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1152
-            //cycle thru the boxes
1153
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1154
-                if ($trash) {
1155
-                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1156
-                        $success = 0;
1157
-                    }
1158
-                } else {
1159
-                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1160
-                        $success = 0;
1161
-                    }
1162
-                }
1163
-            }
1164
-        } else {
1165
-            //grab single id and trash
1166
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1167
-            if ($trash) {
1168
-                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1169
-                    $success = 0;
1170
-                }
1171
-            } else {
1172
-                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1173
-                    $success = 0;
1174
-                }
1175
-            }
1176
-        }
1177
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1178
-        $query_args  = array(
1179
-            'action' => 'ticket_list_table',
1180
-            'status' => $trash ? '' : 'trashed',
1181
-        );
1182
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1183
-    }
1184
-
1185
-
1186
-
1187
-    protected function _delete_ticket()
1188
-    {
1189
-        $success = 1;
1190
-        //checkboxes?
1191
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1192
-            //if array has more than one element then success message should be plural
1193
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1194
-            //cycle thru the boxes
1195
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1196
-                //delete
1197
-                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1198
-                    $success = 0;
1199
-                }
1200
-            }
1201
-        } else {
1202
-            //grab single id and trash
1203
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1204
-            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1205
-                $success = 0;
1206
-            }
1207
-        }
1208
-        $action_desc = 'deleted';
1209
-        $query_args  = array(
1210
-            'action' => 'ticket_list_table',
1211
-            'status' => 'trashed',
1212
-        );
1213
-        //fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1214
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1215
-            array(array('TKT_is_default' => 1)),
1216
-            'TKT_ID',
1217
-            true
1218
-        )
1219
-        ) {
1220
-            $query_args = array();
1221
-        }
1222
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1223
-    }
1224
-
1225
-
1226
-
1227
-    /**
1228
-     * @param int $TKT_ID
1229
-     * @return bool|int
1230
-     */
1231
-    protected function _delete_the_ticket($TKT_ID)
1232
-    {
1233
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1234
-        $tkt->_remove_relations('Datetime');
1235
-        //delete all related prices first
1236
-        $tkt->delete_related_permanently('Price');
1237
-        return $tkt->delete_permanently();
1238
-    }
19
+	/**
20
+	 * Extend_Events_Admin_Page constructor.
21
+	 *
22
+	 * @param bool $routing
23
+	 */
24
+	public function __construct($routing = true)
25
+	{
26
+		parent::__construct($routing);
27
+		if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
+		}
32
+	}
33
+
34
+
35
+
36
+	protected function _extend_page_config()
37
+	{
38
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
+		//is there a evt_id in the request?
40
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
+			? $this->_req_data['EVT_ID']
42
+			: 0;
43
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
+		//tkt_id?
45
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
+			? $this->_req_data['TKT_ID']
47
+			: 0;
48
+		$new_page_routes = array(
49
+			'duplicate_event'          => array(
50
+				'func'       => '_duplicate_event',
51
+				'capability' => 'ee_edit_event',
52
+				'obj_id'     => $evt_id,
53
+				'noheader'   => true,
54
+			),
55
+			'ticket_list_table'        => array(
56
+				'func'       => '_tickets_overview_list_table',
57
+				'capability' => 'ee_read_default_tickets',
58
+			),
59
+			'trash_ticket'             => array(
60
+				'func'       => '_trash_or_restore_ticket',
61
+				'capability' => 'ee_delete_default_ticket',
62
+				'obj_id'     => $tkt_id,
63
+				'noheader'   => true,
64
+				'args'       => array('trash' => true),
65
+			),
66
+			'trash_tickets'            => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_tickets',
69
+				'noheader'   => true,
70
+				'args'       => array('trash' => true),
71
+			),
72
+			'restore_ticket'           => array(
73
+				'func'       => '_trash_or_restore_ticket',
74
+				'capability' => 'ee_delete_default_ticket',
75
+				'obj_id'     => $tkt_id,
76
+				'noheader'   => true,
77
+			),
78
+			'restore_tickets'          => array(
79
+				'func'       => '_trash_or_restore_ticket',
80
+				'capability' => 'ee_delete_default_tickets',
81
+				'noheader'   => true,
82
+			),
83
+			'delete_ticket'            => array(
84
+				'func'       => '_delete_ticket',
85
+				'capability' => 'ee_delete_default_ticket',
86
+				'obj_id'     => $tkt_id,
87
+				'noheader'   => true,
88
+			),
89
+			'delete_tickets'           => array(
90
+				'func'       => '_delete_ticket',
91
+				'capability' => 'ee_delete_default_tickets',
92
+				'noheader'   => true,
93
+			),
94
+			'import_page'              => array(
95
+				'func'       => '_import_page',
96
+				'capability' => 'import',
97
+			),
98
+			'import'                   => array(
99
+				'func'       => '_import_events',
100
+				'capability' => 'import',
101
+				'noheader'   => true,
102
+			),
103
+			'import_events'            => array(
104
+				'func'       => '_import_events',
105
+				'capability' => 'import',
106
+				'noheader'   => true,
107
+			),
108
+			'export_events'            => array(
109
+				'func'       => '_events_export',
110
+				'capability' => 'export',
111
+				'noheader'   => true,
112
+			),
113
+			'export_categories'        => array(
114
+				'func'       => '_categories_export',
115
+				'capability' => 'export',
116
+				'noheader'   => true,
117
+			),
118
+			'sample_export_file'       => array(
119
+				'func'       => '_sample_export_file',
120
+				'capability' => 'export',
121
+				'noheader'   => true,
122
+			),
123
+			'update_template_settings' => array(
124
+				'func'       => '_update_template_settings',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			),
128
+		);
129
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
+		//partial route/config override
131
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
+		$this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
+		$this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
+		$this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
+		$this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
+		//add tickets tab but only if there are more than one default ticket!
138
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
+			array(array('TKT_is_default' => 1)),
140
+			'TKT_ID',
141
+			true
142
+		);
143
+		if ($tkt_count > 1) {
144
+			$new_page_config = array(
145
+				'ticket_list_table' => array(
146
+					'nav'           => array(
147
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
148
+						'order' => 60,
149
+					),
150
+					'list_table'    => 'Tickets_List_Table',
151
+					'require_nonce' => false,
152
+				),
153
+			);
154
+		}
155
+		//template settings
156
+		$new_page_config['template_settings'] = array(
157
+			'nav'           => array(
158
+				'label' => esc_html__('Templates', 'event_espresso'),
159
+				'order' => 30,
160
+			),
161
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
+			'help_tabs'     => array(
163
+				'general_settings_templates_help_tab' => array(
164
+					'title'    => esc_html__('Templates', 'event_espresso'),
165
+					'filename' => 'general_settings_templates',
166
+				),
167
+			),
168
+			'help_tour'     => array('Templates_Help_Tour'),
169
+			'require_nonce' => false,
170
+		);
171
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
172
+		//add filters and actions
173
+		//modifying _views
174
+		add_filter(
175
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
+			array($this, 'add_additional_datetime_button'),
177
+			10,
178
+			2
179
+		);
180
+		add_filter(
181
+			'FHEE_event_datetime_metabox_clone_button_template',
182
+			array($this, 'add_datetime_clone_button'),
183
+			10,
184
+			2
185
+		);
186
+		add_filter(
187
+			'FHEE_event_datetime_metabox_timezones_template',
188
+			array($this, 'datetime_timezones_template'),
189
+			10,
190
+			2
191
+		);
192
+		//filters for event list table
193
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
+		add_filter(
195
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
+			array($this, 'extra_list_table_actions'),
197
+			10,
198
+			2
199
+		);
200
+		//legend item
201
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
+		add_action('admin_init', array($this, 'admin_init'));
203
+		//heartbeat stuff
204
+		add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * admin_init
211
+	 */
212
+	public function admin_init()
213
+	{
214
+		EE_Registry::$i18n_js_strings = array_merge(
215
+			EE_Registry::$i18n_js_strings,
216
+			array(
217
+				'image_confirm'          => esc_html__(
218
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
+					'event_espresso'
220
+				),
221
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
+			)
227
+		);
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
+	 * accordingly.
235
+	 *
236
+	 * @param array $response The existing heartbeat response array.
237
+	 * @param array $data     The incoming data package.
238
+	 * @return array  possibly appended response.
239
+	 */
240
+	public function heartbeat_response($response, $data)
241
+	{
242
+		/**
243
+		 * check whether count of tickets is approaching the potential
244
+		 * limits for the server.
245
+		 */
246
+		if ( ! empty($data['input_count'])) {
247
+			$response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
+				$data['input_count']
249
+			);
250
+		}
251
+		return $response;
252
+	}
253
+
254
+
255
+
256
+	protected function _add_screen_options_ticket_list_table()
257
+	{
258
+		$this->_per_page_screen_option();
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * @param string $return
265
+	 * @param int    $id
266
+	 * @param string $new_title
267
+	 * @param string $new_slug
268
+	 * @return string
269
+	 */
270
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
+	{
272
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
+		//make sure this is only when editing
274
+		if ( ! empty($id)) {
275
+			$href  = EE_Admin_Page::add_query_args_and_nonce(
276
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
+				$this->_admin_base_url
278
+			);
279
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
280
+			$return .= '<a href="'
281
+					   . $href
282
+					   . '" title="'
283
+					   . $title
284
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
+					   . $title
286
+					   . '</button>';
287
+		}
288
+		return $return;
289
+	}
290
+
291
+
292
+
293
+	public function _set_list_table_views_ticket_list_table()
294
+	{
295
+		$this->_views = array(
296
+			'all'     => array(
297
+				'slug'        => 'all',
298
+				'label'       => esc_html__('All', 'event_espresso'),
299
+				'count'       => 0,
300
+				'bulk_action' => array(
301
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
+				),
303
+			),
304
+			'trashed' => array(
305
+				'slug'        => 'trashed',
306
+				'label'       => esc_html__('Trash', 'event_espresso'),
307
+				'count'       => 0,
308
+				'bulk_action' => array(
309
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
+				),
312
+			),
313
+		);
314
+	}
315
+
316
+
317
+
318
+	public function load_scripts_styles_edit()
319
+	{
320
+		wp_register_script(
321
+			'ee-event-editor-heartbeat',
322
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
+			array('ee_admin_js', 'heartbeat'),
324
+			EVENT_ESPRESSO_VERSION,
325
+			true
326
+		);
327
+		wp_enqueue_script('ee-accounting');
328
+		//styles
329
+		wp_enqueue_style('espresso-ui-theme');
330
+		wp_enqueue_script('event_editor_js');
331
+		wp_enqueue_script('ee-event-editor-heartbeat');
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * @param $template
338
+	 * @param $template_args
339
+	 * @return mixed
340
+	 */
341
+	public function add_additional_datetime_button($template, $template_args)
342
+	{
343
+		return EEH_Template::display_template(
344
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
345
+			$template_args,
346
+			true
347
+		);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * @param $template
354
+	 * @param $template_args
355
+	 * @return mixed
356
+	 */
357
+	public function add_datetime_clone_button($template, $template_args)
358
+	{
359
+		return EEH_Template::display_template(
360
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
361
+			$template_args,
362
+			true
363
+		);
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * @param $template
370
+	 * @param $template_args
371
+	 * @return mixed
372
+	 */
373
+	public function datetime_timezones_template($template, $template_args)
374
+	{
375
+		return EEH_Template::display_template(
376
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
377
+			$template_args,
378
+			true
379
+		);
380
+	}
381
+
382
+
383
+
384
+	protected function _set_list_table_views_default()
385
+	{
386
+		parent::_set_list_table_views_default();
387
+		$new_views = array(
388
+			'today' => array(
389
+				'slug'        => 'today',
390
+				'label'       => esc_html__('Today', 'event_espresso'),
391
+				'count'       => $this->total_events_today(),
392
+				'bulk_action' => array(
393
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
394
+				),
395
+			),
396
+			'month' => array(
397
+				'slug'        => 'month',
398
+				'label'       => esc_html__('This Month', 'event_espresso'),
399
+				'count'       => $this->total_events_this_month(),
400
+				'bulk_action' => array(
401
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
+				),
403
+			),
404
+		);
405
+		$this->_views = array_merge($this->_views, $new_views);
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * @param array     $action_links
412
+	 * @param \EE_Event $event
413
+	 * @return array
414
+	 */
415
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
416
+	{
417
+		if (
418
+		EE_Registry::instance()->CAP->current_user_can(
419
+			'ee_read_registrations',
420
+			'espresso_registrations_reports',
421
+			$event->ID()
422
+		)
423
+		) {
424
+			$reports_query_args = array(
425
+				'action' => 'reports',
426
+				'EVT_ID' => $event->ID(),
427
+			);
428
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
429
+			$action_links[]     = '<a href="'
430
+								  . $reports_link
431
+								  . '" title="'
432
+								  . esc_attr__('View Report', 'event_espresso')
433
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
434
+								  . "\n\t";
435
+		}
436
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
437
+			EE_Registry::instance()->load_helper('MSG_Template');
438
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
439
+				'see_notifications_for',
440
+				null,
441
+				array('EVT_ID' => $event->ID())
442
+			);
443
+		}
444
+		return $action_links;
445
+	}
446
+
447
+
448
+
449
+	/**
450
+	 * @param $items
451
+	 * @return mixed
452
+	 */
453
+	public function additional_legend_items($items)
454
+	{
455
+		if (
456
+		EE_Registry::instance()->CAP->current_user_can(
457
+			'ee_read_registrations',
458
+			'espresso_registrations_reports'
459
+		)
460
+		) {
461
+			$items['reports'] = array(
462
+				'class' => 'dashicons dashicons-chart-bar',
463
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
464
+			);
465
+		}
466
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
467
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
468
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
469
+				$items['view_related_messages'] = array(
470
+					'class' => $related_for_icon['css_class'],
471
+					'desc'  => $related_for_icon['label'],
472
+				);
473
+			}
474
+		}
475
+		return $items;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * This is the callback method for the duplicate event route
482
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
483
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
484
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
485
+	 * After duplication the redirect is to the new event edit page.
486
+	 *
487
+	 * @return void
488
+	 * @access protected
489
+	 * @throws EE_Error If EE_Event is not available with given ID
490
+	 */
491
+	protected function _duplicate_event()
492
+	{
493
+		// first make sure the ID for the event is in the request.
494
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
495
+		if ( ! isset($this->_req_data['EVT_ID'])) {
496
+			EE_Error::add_error(
497
+				esc_html__(
498
+					'In order to duplicate an event an Event ID is required.  None was given.',
499
+					'event_espresso'
500
+				),
501
+				__FILE__,
502
+				__FUNCTION__,
503
+				__LINE__
504
+			);
505
+			$this->_redirect_after_action(false, '', '', array(), true);
506
+			return;
507
+		}
508
+		//k we've got EVT_ID so let's use that to get the event we'll duplicate
509
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
510
+		if ( ! $orig_event instanceof EE_Event) {
511
+			throw new EE_Error(
512
+				sprintf(
513
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
514
+					$this->_req_data['EVT_ID']
515
+				)
516
+			);
517
+		}
518
+		//k now let's clone the $orig_event before getting relations
519
+		$new_event = clone $orig_event;
520
+		//original datetimes
521
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
522
+		//other original relations
523
+		$orig_ven = $orig_event->get_many_related('Venue');
524
+		//reset the ID and modify other details to make it clear this is a dupe
525
+		$new_event->set('EVT_ID', 0);
526
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
527
+		$new_event->set('EVT_name', $new_name);
528
+		$new_event->set(
529
+			'EVT_slug',
530
+			wp_unique_post_slug(
531
+				sanitize_title($orig_event->name()),
532
+				0,
533
+				'publish',
534
+				'espresso_events',
535
+				0
536
+			)
537
+		);
538
+		$new_event->set('status', 'draft');
539
+		//duplicate discussion settings
540
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
541
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
542
+		//save the new event
543
+		$new_event->save();
544
+		//venues
545
+		foreach ($orig_ven as $ven) {
546
+			$new_event->_add_relation_to($ven, 'Venue');
547
+		}
548
+		$new_event->save();
549
+		//now we need to get the question group relations and handle that
550
+		//first primary question groups
551
+		$orig_primary_qgs = $orig_event->get_many_related(
552
+			'Question_Group',
553
+			array(array('Event_Question_Group.EQG_primary' => 1))
554
+		);
555
+		if ( ! empty($orig_primary_qgs)) {
556
+			foreach ($orig_primary_qgs as $id => $obj) {
557
+				if ($obj instanceof EE_Question_Group) {
558
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
559
+				}
560
+			}
561
+		}
562
+		//next additional attendee question groups
563
+		$orig_additional_qgs = $orig_event->get_many_related(
564
+			'Question_Group',
565
+			array(array('Event_Question_Group.EQG_primary' => 0))
566
+		);
567
+		if ( ! empty($orig_additional_qgs)) {
568
+			foreach ($orig_additional_qgs as $id => $obj) {
569
+				if ($obj instanceof EE_Question_Group) {
570
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
571
+				}
572
+			}
573
+		}
574
+		//now save
575
+		$new_event->save();
576
+		//k now that we have the new event saved we can loop through the datetimes and start adding relations.
577
+		$cloned_tickets = array();
578
+		foreach ($orig_datetimes as $orig_dtt) {
579
+			if ( ! $orig_dtt instanceof EE_Datetime) {
580
+				continue;
581
+			}
582
+			$new_dtt   = clone $orig_dtt;
583
+			$orig_tkts = $orig_dtt->tickets();
584
+			//save new dtt then add to event
585
+			$new_dtt->set('DTT_ID', 0);
586
+			$new_dtt->set('DTT_sold', 0);
587
+			$new_dtt->save();
588
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
589
+			$new_event->save();
590
+			//now let's get the ticket relations setup.
591
+			foreach ((array)$orig_tkts as $orig_tkt) {
592
+				//it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
593
+				if ( ! $orig_tkt instanceof EE_Ticket) {
594
+					continue;
595
+				}
596
+				//is this ticket archived?  If it is then let's skip
597
+				if ($orig_tkt->get('TKT_deleted')) {
598
+					continue;
599
+				}
600
+				// does this original ticket already exist in the clone_tickets cache?
601
+				//  If so we'll just use the new ticket from it.
602
+				if (isset($cloned_tickets[$orig_tkt->ID()])) {
603
+					$new_tkt = $cloned_tickets[$orig_tkt->ID()];
604
+				} else {
605
+					$new_tkt = clone $orig_tkt;
606
+					//get relations on the $orig_tkt that we need to setup.
607
+					$orig_prices = $orig_tkt->prices();
608
+					$new_tkt->set('TKT_ID', 0);
609
+					$new_tkt->set('TKT_sold', 0);
610
+					$new_tkt->set('TKT_reserved', 0);
611
+					$new_tkt->save(); //make sure new ticket has ID.
612
+					//price relations on new ticket need to be setup.
613
+					foreach ($orig_prices as $orig_price) {
614
+						$new_price = clone $orig_price;
615
+						$new_price->set('PRC_ID', 0);
616
+						$new_price->save();
617
+						$new_tkt->_add_relation_to($new_price, 'Price');
618
+						$new_tkt->save();
619
+					}
620
+				}
621
+				// k now we can add the new ticket as a relation to the new datetime
622
+				// and make sure its added to our cached $cloned_tickets array
623
+				// for use with later datetimes that have the same ticket.
624
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
625
+				$new_dtt->save();
626
+				$cloned_tickets[$orig_tkt->ID()] = $new_tkt;
627
+			}
628
+		}
629
+		//clone taxonomy information
630
+		$taxonomies_to_clone_with = apply_filters(
631
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
632
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
633
+		);
634
+		//get terms for original event (notice)
635
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
636
+		//loop through terms and add them to new event.
637
+		foreach ($orig_terms as $term) {
638
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
639
+		}
640
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
641
+		//now let's redirect to the edit page for this duplicated event if we have a new event id.
642
+		if ($new_event->ID()) {
643
+			$redirect_args = array(
644
+				'post'   => $new_event->ID(),
645
+				'action' => 'edit',
646
+			);
647
+			EE_Error::add_success(
648
+				esc_html__(
649
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
650
+					'event_espresso'
651
+				)
652
+			);
653
+		} else {
654
+			$redirect_args = array(
655
+				'action' => 'default',
656
+			);
657
+			EE_Error::add_error(
658
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
659
+				__FILE__,
660
+				__FUNCTION__,
661
+				__LINE__
662
+			);
663
+		}
664
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
665
+	}
666
+
667
+
668
+	protected function _import_page()
669
+	{
670
+		$title                                      = esc_html__('Import', 'event_espresso');
671
+		$intro                                      = esc_html__(
672
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
673
+			'event_espresso'
674
+		);
675
+		$form_url                                   = EVENTS_ADMIN_URL;
676
+		$action                                     = 'import_events';
677
+		$type                                       = 'csv';
678
+		$this->_template_args['form']               = EE_Import::instance()->upload_form(
679
+			$title, $intro, $form_url, $action, $type
680
+		);
681
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
682
+			array('action' => 'sample_export_file'),
683
+			$this->_admin_base_url
684
+		);
685
+		$content                                    = EEH_Template::display_template(
686
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
687
+			$this->_template_args,
688
+			true
689
+		);
690
+		$this->_template_args['admin_page_content'] = $content;
691
+		$this->display_admin_page_with_sidebar();
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * _import_events
698
+	 * This handles displaying the screen and running imports for importing events.
699
+	 *
700
+	 * @return void
701
+	 */
702
+	protected function _import_events()
703
+	{
704
+		require_once(EE_CLASSES . 'EE_Import.class.php');
705
+		$success = EE_Import::instance()->import();
706
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * _events_export
713
+	 * Will export all (or just the given event) to a Excel compatible file.
714
+	 *
715
+	 * @access protected
716
+	 * @return void
717
+	 */
718
+	protected function _events_export()
719
+	{
720
+		if (isset($this->_req_data['EVT_ID'])) {
721
+			$event_ids = $this->_req_data['EVT_ID'];
722
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
723
+			$event_ids = $this->_req_data['EVT_IDs'];
724
+		} else {
725
+			$event_ids = null;
726
+		}
727
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
728
+		$new_request_args = array(
729
+			'export' => 'report',
730
+			'action' => 'all_event_data',
731
+			'EVT_ID' => $event_ids,
732
+		);
733
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
734
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
735
+			require_once(EE_CLASSES . 'EE_Export.class.php');
736
+			$EE_Export = EE_Export::instance($this->_req_data);
737
+			$EE_Export->export();
738
+		}
739
+	}
740
+
741
+
742
+
743
+	/**
744
+	 * handle category exports()
745
+	 *
746
+	 * @return void
747
+	 */
748
+	protected function _categories_export()
749
+	{
750
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
751
+		$new_request_args = array(
752
+			'export'       => 'report',
753
+			'action'       => 'categories',
754
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
755
+		);
756
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
757
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
758
+			require_once(EE_CLASSES . 'EE_Export.class.php');
759
+			$EE_Export = EE_Export::instance($this->_req_data);
760
+			$EE_Export->export();
761
+		}
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * Creates a sample CSV file for importing
768
+	 */
769
+	protected function _sample_export_file()
770
+	{
771
+		//		require_once(EE_CLASSES . 'EE_Export.class.php');
772
+		EE_Export::instance()->export_sample();
773
+	}
774
+
775
+
776
+
777
+	/*************        Template Settings        *************/
778
+	protected function _template_settings()
779
+	{
780
+		$this->_template_args['values'] = $this->_yes_no_values;
781
+		/**
782
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
783
+		 * from General_Settings_Admin_Page to here.
784
+		 */
785
+		$this->_template_args = apply_filters(
786
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
787
+			$this->_template_args
788
+		);
789
+		$this->_set_add_edit_form_tags('update_template_settings');
790
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
791
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
792
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
793
+			$this->_template_args,
794
+			true
795
+		);
796
+		$this->display_admin_page_with_sidebar();
797
+	}
798
+
799
+
800
+
801
+	protected function _update_template_settings()
802
+	{
803
+		/**
804
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
+		 * from General_Settings_Admin_Page to here.
806
+		 */
807
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
808
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
809
+			EE_Registry::instance()->CFG->template_settings,
810
+			$this->_req_data
811
+		);
812
+		//update custom post type slugs and detect if we need to flush rewrite rules
813
+		$old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
814
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
815
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
816
+			: sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
817
+		$what                                              = 'Template Settings';
818
+		$success                                           = $this->_update_espresso_configuration(
819
+			$what,
820
+			EE_Registry::instance()->CFG->template_settings,
821
+			__FILE__,
822
+			__FUNCTION__,
823
+			__LINE__
824
+		);
825
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
826
+			update_option('ee_flush_rewrite_rules', true);
827
+		}
828
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
829
+	}
830
+
831
+
832
+
833
+	/**
834
+	 * _premium_event_editor_meta_boxes
835
+	 * add all metaboxes related to the event_editor
836
+	 *
837
+	 * @access protected
838
+	 * @return void
839
+	 */
840
+	protected function _premium_event_editor_meta_boxes()
841
+	{
842
+		$this->verify_cpt_object();
843
+		add_meta_box(
844
+			'espresso_event_editor_event_options',
845
+			esc_html__('Event Registration Options', 'event_espresso'),
846
+			array($this, 'registration_options_meta_box'),
847
+			$this->page_slug,
848
+			'side',
849
+			'core'
850
+		);
851
+	}
852
+
853
+
854
+
855
+	/**
856
+	 * override caf metabox
857
+	 *
858
+	 * @return void
859
+	 */
860
+	public function registration_options_meta_box()
861
+	{
862
+		$yes_no_values = array(
863
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
864
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
865
+		);
866
+		$default_reg_status_values = EEM_Registration::reg_status_array(
867
+			array(
868
+				EEM_Registration::status_id_cancelled,
869
+				EEM_Registration::status_id_declined,
870
+				EEM_Registration::status_id_incomplete,
871
+				EEM_Registration::status_id_wait_list,
872
+			),
873
+			true
874
+		);
875
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
876
+		$template_args['_event']                          = $this->_cpt_model_obj;
877
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
878
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
879
+			'default_reg_status',
880
+			$default_reg_status_values,
881
+			$this->_cpt_model_obj->default_registration_status()
882
+		);
883
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
884
+			'display_desc',
885
+			$yes_no_values,
886
+			$this->_cpt_model_obj->display_description()
887
+		);
888
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
889
+			'display_ticket_selector',
890
+			$yes_no_values,
891
+			$this->_cpt_model_obj->display_ticket_selector(),
892
+			'',
893
+			'',
894
+			false
895
+		);
896
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
897
+			'EVT_default_registration_status',
898
+			$default_reg_status_values,
899
+			$this->_cpt_model_obj->default_registration_status()
900
+		);
901
+		$template_args['additional_registration_options'] = apply_filters(
902
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
903
+			'',
904
+			$template_args,
905
+			$yes_no_values,
906
+			$default_reg_status_values
907
+		);
908
+		EEH_Template::display_template(
909
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
910
+			$template_args
911
+		);
912
+	}
913
+
914
+
915
+
916
+	/**
917
+	 * wp_list_table_mods for caf
918
+	 * ============================
919
+	 */
920
+	/**
921
+	 * hook into list table filters and provide filters for caffeinated list table
922
+	 *
923
+	 * @param  array $old_filters    any existing filters present
924
+	 * @param  array $list_table_obj the list table object
925
+	 * @return array                  new filters
926
+	 */
927
+	public function list_table_filters($old_filters, $list_table_obj)
928
+	{
929
+		$filters = array();
930
+		//first month/year filters
931
+		$filters[] = $this->espresso_event_months_dropdown();
932
+		$status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
933
+		//active status dropdown
934
+		if ($status !== 'draft') {
935
+			$filters[] = $this->active_status_dropdown(
936
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
937
+			);
938
+		}
939
+		//category filter
940
+		$filters[] = $this->category_dropdown();
941
+		return array_merge($old_filters, $filters);
942
+	}
943
+
944
+
945
+
946
+	/**
947
+	 * espresso_event_months_dropdown
948
+	 *
949
+	 * @access public
950
+	 * @return string                dropdown listing month/year selections for events.
951
+	 */
952
+	public function espresso_event_months_dropdown()
953
+	{
954
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
955
+		// Note we need to include any other filters that are set!
956
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
957
+		//categories?
958
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
959
+			? $this->_req_data['EVT_CAT']
960
+			: null;
961
+		//active status?
962
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
963
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
964
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
965
+	}
966
+
967
+
968
+
969
+	/**
970
+	 * returns a list of "active" statuses on the event
971
+	 *
972
+	 * @param  string $current_value whatever the current active status is
973
+	 * @return string
974
+	 */
975
+	public function active_status_dropdown($current_value = '')
976
+	{
977
+		$select_name = 'active_status';
978
+		$values      = array(
979
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
980
+			'active'   => esc_html__('Active', 'event_espresso'),
981
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
982
+			'expired'  => esc_html__('Expired', 'event_espresso'),
983
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
984
+		);
985
+		$id          = 'id="espresso-active-status-dropdown-filter"';
986
+		$class       = 'wide';
987
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
988
+	}
989
+
990
+
991
+
992
+	/**
993
+	 * output a dropdown of the categories for the category filter on the event admin list table
994
+	 *
995
+	 * @access  public
996
+	 * @return string html
997
+	 */
998
+	public function category_dropdown()
999
+	{
1000
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1001
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * get total number of events today
1008
+	 *
1009
+	 * @access public
1010
+	 * @return int
1011
+	 */
1012
+	public function total_events_today()
1013
+	{
1014
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1015
+			'DTT_EVT_start',
1016
+			date('Y-m-d') . ' 00:00:00',
1017
+			'Y-m-d H:i:s',
1018
+			'UTC'
1019
+		);
1020
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1021
+			'DTT_EVT_start',
1022
+			date('Y-m-d') . ' 23:59:59',
1023
+			'Y-m-d H:i:s',
1024
+			'UTC'
1025
+		);
1026
+		$where = array(
1027
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1028
+		);
1029
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1030
+		return $count;
1031
+	}
1032
+
1033
+
1034
+
1035
+	/**
1036
+	 * get total number of events this month
1037
+	 *
1038
+	 * @access public
1039
+	 * @return int
1040
+	 */
1041
+	public function total_events_this_month()
1042
+	{
1043
+		//Dates
1044
+		$this_year_r     = date('Y');
1045
+		$this_month_r    = date('m');
1046
+		$days_this_month = date('t');
1047
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1048
+			'DTT_EVT_start',
1049
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1050
+			'Y-m-d H:i:s',
1051
+			'UTC'
1052
+		);
1053
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1054
+			'DTT_EVT_start',
1055
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1056
+			'Y-m-d H:i:s',
1057
+			'UTC'
1058
+		);
1059
+		$where = array(
1060
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1061
+		);
1062
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1063
+		return $count;
1064
+	}
1065
+
1066
+
1067
+
1068
+	/** DEFAULT TICKETS STUFF **/
1069
+	public function _tickets_overview_list_table()
1070
+	{
1071
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1072
+		$this->display_admin_list_table_page_with_no_sidebar();
1073
+	}
1074
+
1075
+
1076
+
1077
+	/**
1078
+	 * @param int  $per_page
1079
+	 * @param bool $count
1080
+	 * @param bool $trashed
1081
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1082
+	 */
1083
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1084
+	{
1085
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1086
+		$order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1087
+		switch ($orderby) {
1088
+			case 'TKT_name' :
1089
+				$orderby = array('TKT_name' => $order);
1090
+				break;
1091
+			case 'TKT_price' :
1092
+				$orderby = array('TKT_price' => $order);
1093
+				break;
1094
+			case 'TKT_uses' :
1095
+				$orderby = array('TKT_uses' => $order);
1096
+				break;
1097
+			case 'TKT_min' :
1098
+				$orderby = array('TKT_min' => $order);
1099
+				break;
1100
+			case 'TKT_max' :
1101
+				$orderby = array('TKT_max' => $order);
1102
+				break;
1103
+			case 'TKT_qty' :
1104
+				$orderby = array('TKT_qty' => $order);
1105
+				break;
1106
+		}
1107
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1108
+			? $this->_req_data['paged']
1109
+			: 1;
1110
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1111
+			? $this->_req_data['perpage']
1112
+			: $per_page;
1113
+		$_where       = array(
1114
+			'TKT_is_default' => 1,
1115
+			'TKT_deleted'    => $trashed,
1116
+		);
1117
+		$offset       = ($current_page - 1) * $per_page;
1118
+		$limit        = array($offset, $per_page);
1119
+		if (isset($this->_req_data['s'])) {
1120
+			$sstr         = '%' . $this->_req_data['s'] . '%';
1121
+			$_where['OR'] = array(
1122
+				'TKT_name'        => array('LIKE', $sstr),
1123
+				'TKT_description' => array('LIKE', $sstr),
1124
+			);
1125
+		}
1126
+		$query_params = array(
1127
+			$_where,
1128
+			'order_by' => $orderby,
1129
+			'limit'    => $limit,
1130
+			'group_by' => 'TKT_ID',
1131
+		);
1132
+		if ($count) {
1133
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1134
+		} else {
1135
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1136
+		}
1137
+	}
1138
+
1139
+
1140
+
1141
+	/**
1142
+	 * @param bool $trash
1143
+	 */
1144
+	protected function _trash_or_restore_ticket($trash = false)
1145
+	{
1146
+		$success = 1;
1147
+		$TKT = EEM_Ticket::instance();
1148
+		//checkboxes?
1149
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1150
+			//if array has more than one element then success message should be plural
1151
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1152
+			//cycle thru the boxes
1153
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1154
+				if ($trash) {
1155
+					if ( ! $TKT->delete_by_ID($TKT_ID)) {
1156
+						$success = 0;
1157
+					}
1158
+				} else {
1159
+					if ( ! $TKT->restore_by_ID($TKT_ID)) {
1160
+						$success = 0;
1161
+					}
1162
+				}
1163
+			}
1164
+		} else {
1165
+			//grab single id and trash
1166
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1167
+			if ($trash) {
1168
+				if ( ! $TKT->delete_by_ID($TKT_ID)) {
1169
+					$success = 0;
1170
+				}
1171
+			} else {
1172
+				if ( ! $TKT->restore_by_ID($TKT_ID)) {
1173
+					$success = 0;
1174
+				}
1175
+			}
1176
+		}
1177
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1178
+		$query_args  = array(
1179
+			'action' => 'ticket_list_table',
1180
+			'status' => $trash ? '' : 'trashed',
1181
+		);
1182
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1183
+	}
1184
+
1185
+
1186
+
1187
+	protected function _delete_ticket()
1188
+	{
1189
+		$success = 1;
1190
+		//checkboxes?
1191
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1192
+			//if array has more than one element then success message should be plural
1193
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1194
+			//cycle thru the boxes
1195
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1196
+				//delete
1197
+				if ( ! $this->_delete_the_ticket($TKT_ID)) {
1198
+					$success = 0;
1199
+				}
1200
+			}
1201
+		} else {
1202
+			//grab single id and trash
1203
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1204
+			if ( ! $this->_delete_the_ticket($TKT_ID)) {
1205
+				$success = 0;
1206
+			}
1207
+		}
1208
+		$action_desc = 'deleted';
1209
+		$query_args  = array(
1210
+			'action' => 'ticket_list_table',
1211
+			'status' => 'trashed',
1212
+		);
1213
+		//fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1214
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1215
+			array(array('TKT_is_default' => 1)),
1216
+			'TKT_ID',
1217
+			true
1218
+		)
1219
+		) {
1220
+			$query_args = array();
1221
+		}
1222
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1223
+	}
1224
+
1225
+
1226
+
1227
+	/**
1228
+	 * @param int $TKT_ID
1229
+	 * @return bool|int
1230
+	 */
1231
+	protected function _delete_the_ticket($TKT_ID)
1232
+	{
1233
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1234
+		$tkt->_remove_relations('Datetime');
1235
+		//delete all related prices first
1236
+		$tkt->delete_related_permanently('Price');
1237
+		return $tkt->delete_permanently();
1238
+	}
1239 1239
 
1240 1240
 
1241 1241
 
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function __construct($options_array = array())
86 86
     {
87
-        $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
87
+        $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88 88
             $this);
89 89
         //call parent first, as it may be setting the name
90 90
         parent::__construct($options_array);
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         if (isset($options_array['layout_strategy'])) {
108 108
             $this->_layout_strategy = $options_array['layout_strategy'];
109 109
         }
110
-        if (! $this->_layout_strategy) {
110
+        if ( ! $this->_layout_strategy) {
111 111
             $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112 112
         }
113 113
         $this->_layout_strategy->_construct_finalize($this);
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         if ($validate) {
259 259
             $this->_validate();
260 260
             //if it's invalid, we're going to want to re-display so remember what they submitted
261
-            if (! $this->is_valid()) {
261
+            if ( ! $this->is_valid()) {
262 262
                 $this->store_submitted_form_data_in_session();
263 263
             }
264 264
         }
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
     public function get_input($name, $require_construction_to_be_finalized = true)
439 439
     {
440 440
         $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
-        if (! $subsection instanceof EE_Form_Input_Base) {
441
+        if ( ! $subsection instanceof EE_Form_Input_Base) {
442 442
             throw new EE_Error(
443 443
                 sprintf(
444 444
                     __(
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
     public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474 474
     {
475 475
         $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
-        if (! $subsection instanceof EE_Form_Section_Proper) {
476
+        if ( ! $subsection instanceof EE_Form_Section_Proper) {
477 477
             throw new EE_Error(
478 478
                 sprintf(
479 479
                     __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
      */
512 512
     public function is_valid()
513 513
     {
514
-        if (! $this->has_received_submission()) {
514
+        if ( ! $this->has_received_submission()) {
515 515
             throw new EE_Error(
516 516
                 sprintf(
517 517
                     __(
@@ -521,14 +521,14 @@  discard block
 block discarded – undo
521 521
                 )
522 522
             );
523 523
         }
524
-        if (! parent::is_valid()) {
524
+        if ( ! parent::is_valid()) {
525 525
             return false;
526 526
         }
527 527
         // ok so no general errors to this entire form section.
528 528
         // so let's check the subsections, but only set errors if that hasn't been done yet
529 529
         $set_submission_errors = $this->submission_error_message() === '' ? true : false;
530 530
         foreach ($this->get_validatable_subsections() as $subsection) {
531
-            if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
531
+            if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532 532
                 if ($set_submission_errors) {
533 533
                     $this->set_submission_error_message($subsection->get_validation_error_string());
534 534
                 }
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
      */
548 548
     protected function _set_default_name_if_empty()
549 549
     {
550
-        if (! $this->_name) {
550
+        if ( ! $this->_name) {
551 551
             $classname = get_class($this);
552 552
             $default_name = str_replace("EE_", "", $classname);
553 553
             $this->_name = $default_name;
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
     {
633 633
         wp_register_script(
634 634
             'ee_form_section_validation',
635
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
635
+            EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js',
636 636
             array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
637 637
             EVENT_ESPRESSO_VERSION,
638 638
             true
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
      */
779 779
     public function ensure_scripts_localized()
780 780
     {
781
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
781
+        if ( ! EE_Form_Section_Proper::$_scripts_localized) {
782 782
             $this->_enqueue_and_localize_form_js();
783 783
         }
784 784
     }
@@ -874,8 +874,8 @@  discard block
 block discarded – undo
874 874
     protected function _validate()
875 875
     {
876 876
         foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
877
-            if (method_exists($this, '_validate_' . $subsection_name)) {
878
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
877
+            if (method_exists($this, '_validate_'.$subsection_name)) {
878
+                call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection));
879 879
             }
880 880
             $subsection->_validate();
881 881
         }
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
     public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1152 1152
     {
1153 1153
         foreach ($new_subsections as $subsection_name => $subsection) {
1154
-            if (! $subsection instanceof EE_Form_Section_Base) {
1154
+            if ( ! $subsection instanceof EE_Form_Section_Base) {
1155 1155
                 EE_Error::add_error(
1156 1156
                     sprintf(
1157 1157
                         __(
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
     public function html_name_prefix()
1250 1250
     {
1251 1251
         if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1252
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1252
+            return $this->parent_section()->html_name_prefix().'['.$this->name().']';
1253 1253
         } else {
1254 1254
             return $this->name();
1255 1255
         }
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
      */
1294 1294
     public function ensure_construct_finalized_called()
1295 1295
     {
1296
-        if (! $this->_construction_finalized) {
1296
+        if ( ! $this->_construction_finalized) {
1297 1297
             $this->_construct_finalize($this->_parent_section, $this->_name);
1298 1298
         }
1299 1299
     }
Please login to merge, or discard this patch.
Indentation   +1379 added lines, -1379 removed lines patch added patch discarded remove patch
@@ -11,1385 +11,1385 @@
 block discarded – undo
11 11
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
12 12
 {
13 13
 
14
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
15
-
16
-    /**
17
-     * Subsections
18
-     *
19
-     * @var EE_Form_Section_Validatable[]
20
-     */
21
-    protected $_subsections = array();
22
-
23
-    /**
24
-     * Strategy for laying out the form
25
-     *
26
-     * @var EE_Form_Section_Layout_Base
27
-     */
28
-    protected $_layout_strategy;
29
-
30
-    /**
31
-     * Whether or not this form has received and validated a form submission yet
32
-     *
33
-     * @var boolean
34
-     */
35
-    protected $_received_submission = false;
36
-
37
-    /**
38
-     * message displayed to users upon successful form submission
39
-     *
40
-     * @var string
41
-     */
42
-    protected $_form_submission_success_message = '';
43
-
44
-    /**
45
-     * message displayed to users upon unsuccessful form submission
46
-     *
47
-     * @var string
48
-     */
49
-    protected $_form_submission_error_message = '';
50
-
51
-    /**
52
-     * Stores all the data that will localized for form validation
53
-     *
54
-     * @var array
55
-     */
56
-    static protected $_js_localization = array();
57
-
58
-    /**
59
-     * whether or not the form's localized validation JS vars have been set
60
-     *
61
-     * @type boolean
62
-     */
63
-    static protected $_scripts_localized = false;
64
-
65
-
66
-
67
-    /**
68
-     * when constructing a proper form section, calls _construct_finalize on children
69
-     * so that they know who their parent is, and what name they've been given.
70
-     *
71
-     * @param array $options_array   {
72
-     * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
73
-     * @type        $include         string[] numerically-indexed where values are section names to be included,
74
-     *                               and in that order. This is handy if you want
75
-     *                               the subsections to be ordered differently than the default, and if you override
76
-     *                               which fields are shown
77
-     * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
78
-     *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
79
-     *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
80
-     *                               items from that list of inclusions)
81
-     * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
82
-     *                               } @see EE_Form_Section_Validatable::__construct()
83
-     * @throws \EE_Error
84
-     */
85
-    public function __construct($options_array = array())
86
-    {
87
-        $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88
-            $this);
89
-        //call parent first, as it may be setting the name
90
-        parent::__construct($options_array);
91
-        //if they've included subsections in the constructor, add them now
92
-        if (isset($options_array['include'])) {
93
-            //we are going to make sure we ONLY have those subsections to include
94
-            //AND we are going to make sure they're in that specified order
95
-            $reordered_subsections = array();
96
-            foreach ($options_array['include'] as $input_name) {
97
-                if (isset($this->_subsections[$input_name])) {
98
-                    $reordered_subsections[$input_name] = $this->_subsections[$input_name];
99
-                }
100
-            }
101
-            $this->_subsections = $reordered_subsections;
102
-        }
103
-        if (isset($options_array['exclude'])) {
104
-            $exclude = $options_array['exclude'];
105
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
106
-        }
107
-        if (isset($options_array['layout_strategy'])) {
108
-            $this->_layout_strategy = $options_array['layout_strategy'];
109
-        }
110
-        if (! $this->_layout_strategy) {
111
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112
-        }
113
-        $this->_layout_strategy->_construct_finalize($this);
114
-        //ok so we are definitely going to want the forms JS,
115
-        //so enqueue it or remember to enqueue it during wp_enqueue_scripts
116
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
117
-            //ok so they've constructed this object after when they should have.
118
-            //just enqueue the generic form scripts and initialize the form immediately in the JS
119
-            \EE_Form_Section_Proper::wp_enqueue_scripts(true);
120
-        } else {
121
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
122
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
123
-        }
124
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
125
-
126
-        /**
127
-         * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't
128
-         * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to
129
-         * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
130
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
131
-         * @since 4.9.32
132
-         * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling
133
-         *                                      _construct_finalize has been done
134
-         * @param array $options_array options passed into the constructor
135
-         */
136
-        do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array);
137
-
138
-        if (isset($options_array['name'])) {
139
-            $this->_construct_finalize(null, $options_array['name']);
140
-        }
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * Finishes construction given the parent form section and this form section's name
147
-     *
148
-     * @param EE_Form_Section_Proper $parent_form_section
149
-     * @param string                 $name
150
-     * @throws \EE_Error
151
-     */
152
-    public function _construct_finalize($parent_form_section, $name)
153
-    {
154
-        parent::_construct_finalize($parent_form_section, $name);
155
-        $this->_set_default_name_if_empty();
156
-        $this->_set_default_html_id_if_empty();
157
-        foreach ($this->_subsections as $subsection_name => $subsection) {
158
-            if ($subsection instanceof EE_Form_Section_Base) {
159
-                $subsection->_construct_finalize($this, $subsection_name);
160
-            } else {
161
-                throw new EE_Error(
162
-                    sprintf(
163
-                        __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
164
-                            'event_espresso'),
165
-                        $subsection_name,
166
-                        get_class($this),
167
-                        $subsection ? get_class($subsection) : __('NULL', 'event_espresso')
168
-                    )
169
-                );
170
-            }
171
-        }
172
-        /**
173
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
174
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived
175
-         * from the name like the HTML label id, etc), this is where it should be done.
176
-         * This might only happen just before displaying the form, or just before it receives form submission data.
177
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
178
-         * ensured it has a name, HTML IDs, etc
179
-         * @param EE_Form_Section_Proper $this
180
-         * @param EE_Form_Section_Proper|null $parent_form_section
181
-         * @param string $name
182
-         */
183
-        do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * Gets the layout strategy for this form section
190
-     *
191
-     * @return EE_Form_Section_Layout_Base
192
-     */
193
-    public function get_layout_strategy()
194
-    {
195
-        return $this->_layout_strategy;
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Gets the HTML for a single input for this form section according
202
-     * to the layout strategy
203
-     *
204
-     * @param EE_Form_Input_Base $input
205
-     * @return string
206
-     */
207
-    public function get_html_for_input($input)
208
-    {
209
-        return $this->_layout_strategy->layout_input($input);
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * was_submitted - checks if form inputs are present in request data
216
-     * Basically an alias for form_data_present_in() (which is used by both
217
-     * proper form sections and form inputs)
218
-     *
219
-     * @param null $form_data
220
-     * @return boolean
221
-     */
222
-    public function was_submitted($form_data = null)
223
-    {
224
-        return $this->form_data_present_in($form_data);
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * After the form section is initially created, call this to sanitize the data in the submission
231
-     * which relates to this form section, validate it, and set it as properties on the form.
232
-     *
233
-     * @param array|null $req_data should usually be $_POST (the default).
234
-     *                             However, you CAN supply a different array.
235
-     *                             Consider using set_defaults() instead however.
236
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
237
-     *                             the inputs will have the correct name in the request data for this function
238
-     *                             to find them and populate the form with them.
239
-     *                             If you have a flat form (with only input subsections),
240
-     *                             you can supply a flat array where keys
241
-     *                             are the form input names and values are their values)
242
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
243
-     *                             of course, to validate that data, and set errors on the invalid values.
244
-     *                             But if the data has already been validated
245
-     *                             (eg you validated the data then stored it in the DB)
246
-     *                             you may want to skip this step.
247
-     */
248
-    public function receive_form_submission($req_data = null, $validate = true)
249
-    {
250
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
251
-            $validate);
252
-        if ($req_data === null) {
253
-            $req_data = array_merge($_GET, $_POST);
254
-        }
255
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
256
-            $this);
257
-        $this->_normalize($req_data);
258
-        if ($validate) {
259
-            $this->_validate();
260
-            //if it's invalid, we're going to want to re-display so remember what they submitted
261
-            if (! $this->is_valid()) {
262
-                $this->store_submitted_form_data_in_session();
263
-            }
264
-        }
265
-        do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     * caches the originally submitted input values in the session
272
-     * so that they can be used to repopulate the form if it failed validation
273
-     *
274
-     * @return boolean whether or not the data was successfully stored in the session
275
-     */
276
-    protected function store_submitted_form_data_in_session()
277
-    {
278
-        return EE_Registry::instance()->SSN->set_session_data(
279
-            array(
280
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
281
-            )
282
-        );
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * retrieves the originally submitted input values in the session
289
-     * so that they can be used to repopulate the form if it failed validation
290
-     *
291
-     * @return array
292
-     */
293
-    protected function get_submitted_form_data_from_session()
294
-    {
295
-        $session = EE_Registry::instance()->SSN;
296
-        if ($session instanceof EE_Session) {
297
-            return $session->get_session_data(
298
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
299
-            );
300
-        } else {
301
-            return array();
302
-        }
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * flushed the originally submitted input values from the session
309
-     *
310
-     * @return boolean whether or not the data was successfully removed from the session
311
-     */
312
-    protected function flush_submitted_form_data_from_session()
313
-    {
314
-        return EE_Registry::instance()->SSN->reset_data(
315
-            array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
316
-        );
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * Populates this form and its subsections with data from the session.
323
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
324
-     * validation errors when displaying too)
325
-     * Returns true if the form was populated from the session, false otherwise
326
-     *
327
-     * @return boolean
328
-     */
329
-    public function populate_from_session()
330
-    {
331
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
332
-        if (empty($form_data_in_session)) {
333
-            return false;
334
-        }
335
-        $this->receive_form_submission($form_data_in_session);
336
-        $this->flush_submitted_form_data_from_session();
337
-        if ($this->form_data_present_in($form_data_in_session)) {
338
-            return true;
339
-        } else {
340
-            return false;
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * Populates the default data for the form, given an array where keys are
348
-     * the input names, and values are their values (preferably normalized to be their
349
-     * proper PHP types, not all strings... although that should be ok too).
350
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
351
-     * the value being an array formatted in teh same way
352
-     *
353
-     * @param array $default_data
354
-     */
355
-    public function populate_defaults($default_data)
356
-    {
357
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
358
-            if (isset($default_data[$subsection_name])) {
359
-                if ($subsection instanceof EE_Form_Input_Base) {
360
-                    $subsection->set_default($default_data[$subsection_name]);
361
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
362
-                    $subsection->populate_defaults($default_data[$subsection_name]);
363
-                }
364
-            }
365
-        }
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     * returns true if subsection exists
372
-     *
373
-     * @param string $name
374
-     * @return boolean
375
-     */
376
-    public function subsection_exists($name)
377
-    {
378
-        return isset($this->_subsections[$name]) ? true : false;
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * Gets the subsection specified by its name
385
-     *
386
-     * @param string  $name
387
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
388
-     *                                                      so that the inputs will be properly configured.
389
-     *                                                      However, some client code may be ok
390
-     *                                                      with construction finalize being called later
391
-     *                                                      (realizing that the subsections' html names
392
-     *                                                      might not be set yet, etc.)
393
-     * @return EE_Form_Section_Base
394
-     * @throws \EE_Error
395
-     */
396
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
397
-    {
398
-        if ($require_construction_to_be_finalized) {
399
-            $this->ensure_construct_finalized_called();
400
-        }
401
-        return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * Gets all the validatable subsections of this form section
408
-     *
409
-     * @return EE_Form_Section_Validatable[]
410
-     */
411
-    public function get_validatable_subsections()
412
-    {
413
-        $validatable_subsections = array();
414
-        foreach ($this->subsections() as $name => $obj) {
415
-            if ($obj instanceof EE_Form_Section_Validatable) {
416
-                $validatable_subsections[$name] = $obj;
417
-            }
418
-        }
419
-        return $validatable_subsections;
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
426
-     * throw an EE_Error.
427
-     *
428
-     * @param string  $name
429
-     * @param boolean $require_construction_to_be_finalized most client code should
430
-     *                                                      leave this as TRUE so that the inputs will be properly
431
-     *                                                      configured. However, some client code may be ok with
432
-     *                                                      construction finalize being called later
433
-     *                                                      (realizing that the subsections' html names might not be
434
-     *                                                      set yet, etc.)
435
-     * @return EE_Form_Input_Base
436
-     * @throws EE_Error
437
-     */
438
-    public function get_input($name, $require_construction_to_be_finalized = true)
439
-    {
440
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
-        if (! $subsection instanceof EE_Form_Input_Base) {
442
-            throw new EE_Error(
443
-                sprintf(
444
-                    __(
445
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
446
-                        'event_espresso'
447
-                    ),
448
-                    $name,
449
-                    get_class($this),
450
-                    $subsection ? get_class($subsection) : __("NULL", 'event_espresso')
451
-                )
452
-            );
453
-        }
454
-        return $subsection;
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * Like get_input(), gets the proper subsection of the form given the name,
461
-     * otherwise throws an EE_Error
462
-     *
463
-     * @param string  $name
464
-     * @param boolean $require_construction_to_be_finalized most client code should
465
-     *                                                      leave this as TRUE so that the inputs will be properly
466
-     *                                                      configured. However, some client code may be ok with
467
-     *                                                      construction finalize being called later
468
-     *                                                      (realizing that the subsections' html names might not be
469
-     *                                                      set yet, etc.)
470
-     * @return EE_Form_Section_Proper
471
-     * @throws EE_Error
472
-     */
473
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474
-    {
475
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
-        if (! $subsection instanceof EE_Form_Section_Proper) {
477
-            throw new EE_Error(
478
-                sprintf(
479
-                    __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
480
-                    $name,
481
-                    get_class($this)
482
-                )
483
-            );
484
-        }
485
-        return $subsection;
486
-    }
487
-
488
-
489
-
490
-    /**
491
-     * Gets the value of the specified input. Should be called after receive_form_submission()
492
-     * or populate_defaults() on the form, where the normalized value on the input is set.
493
-     *
494
-     * @param string $name
495
-     * @return mixed depending on the input's type and its normalization strategy
496
-     * @throws \EE_Error
497
-     */
498
-    public function get_input_value($name)
499
-    {
500
-        $input = $this->get_input($name);
501
-        return $input->normalized_value();
502
-    }
503
-
504
-
505
-
506
-    /**
507
-     * Checks if this form section itself is valid, and then checks its subsections
508
-     *
509
-     * @throws EE_Error
510
-     * @return boolean
511
-     */
512
-    public function is_valid()
513
-    {
514
-        if (! $this->has_received_submission()) {
515
-            throw new EE_Error(
516
-                sprintf(
517
-                    __(
518
-                        "You cannot check if a form is valid before receiving the form submission using receive_form_submission",
519
-                        "event_espresso"
520
-                    )
521
-                )
522
-            );
523
-        }
524
-        if (! parent::is_valid()) {
525
-            return false;
526
-        }
527
-        // ok so no general errors to this entire form section.
528
-        // so let's check the subsections, but only set errors if that hasn't been done yet
529
-        $set_submission_errors = $this->submission_error_message() === '' ? true : false;
530
-        foreach ($this->get_validatable_subsections() as $subsection) {
531
-            if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532
-                if ($set_submission_errors) {
533
-                    $this->set_submission_error_message($subsection->get_validation_error_string());
534
-                }
535
-                return false;
536
-            }
537
-        }
538
-        return true;
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     * gets teh default name of this form section if none is specified
545
-     *
546
-     * @return string
547
-     */
548
-    protected function _set_default_name_if_empty()
549
-    {
550
-        if (! $this->_name) {
551
-            $classname = get_class($this);
552
-            $default_name = str_replace("EE_", "", $classname);
553
-            $this->_name = $default_name;
554
-        }
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * Returns the HTML for the form, except for the form opening and closing tags
561
-     * (as the form section doesn't know where you necessarily want to send the information to),
562
-     * and except for a submit button. Enqueus JS and CSS; if called early enough we will
563
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
564
-     * Not doing_it_wrong because theoretically this CAN be used properly,
565
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
566
-     * any CSS.
567
-     *
568
-     * @throws \EE_Error
569
-     */
570
-    public function get_html_and_js()
571
-    {
572
-        $this->enqueue_js();
573
-        return $this->get_html();
574
-    }
575
-
576
-
577
-
578
-    /**
579
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
580
-     *
581
-     * @param bool $display_previously_submitted_data
582
-     * @return string
583
-     */
584
-    public function get_html($display_previously_submitted_data = true)
585
-    {
586
-        $this->ensure_construct_finalized_called();
587
-        if ($display_previously_submitted_data) {
588
-            $this->populate_from_session();
589
-        }
590
-        return $this->_form_html_filter
591
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
592
-            : $this->_layout_strategy->layout_form();
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * enqueues JS and CSS for the form.
599
-     * It is preferred to call this before wp_enqueue_scripts so the
600
-     * scripts and styles can be put in the header, but if called later
601
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
602
-     * only be in the header; but in HTML5 its ok in the body.
603
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
604
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
605
-     *
606
-     * @return string
607
-     * @throws \EE_Error
608
-     */
609
-    public function enqueue_js()
610
-    {
611
-        $this->_enqueue_and_localize_form_js();
612
-        foreach ($this->subsections() as $subsection) {
613
-            $subsection->enqueue_js();
614
-        }
615
-    }
616
-
617
-
618
-
619
-    /**
620
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
621
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
622
-     * the wp_enqueue_scripts hook.
623
-     * However, registering the form js and localizing it can happen when we
624
-     * actually output the form (which is preferred, seeing how teh form's fields
625
-     * could change until it's actually outputted)
626
-     *
627
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
628
-     *                                                    to be triggered automatically or not
629
-     * @return void
630
-     */
631
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
632
-    {
633
-        wp_register_script(
634
-            'ee_form_section_validation',
635
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
636
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
637
-            EVENT_ESPRESSO_VERSION,
638
-            true
639
-        );
640
-        wp_localize_script(
641
-            'ee_form_section_validation',
642
-            'ee_form_section_validation_init',
643
-            array('init' => $init_form_validation_automatically ? '1' : '0')
644
-        );
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * gets the variables used by form_section_validation.js.
651
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
652
-     * but before the wordpress hook wp_loaded
653
-     *
654
-     * @throws \EE_Error
655
-     */
656
-    public function _enqueue_and_localize_form_js()
657
-    {
658
-        $this->ensure_construct_finalized_called();
659
-        //actually, we don't want to localize just yet. There may be other forms on the page.
660
-        //so we need to add our form section data to a static variable accessible by all form sections
661
-        //and localize it just before the footer
662
-        $this->localize_validation_rules();
663
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
664
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
665
-    }
666
-
667
-
668
-
669
-    /**
670
-     * add our form section data to a static variable accessible by all form sections
671
-     *
672
-     * @param bool $return_for_subsection
673
-     * @return void
674
-     * @throws \EE_Error
675
-     */
676
-    public function localize_validation_rules($return_for_subsection = false)
677
-    {
678
-        // we only want to localize vars ONCE for the entire form,
679
-        // so if the form section doesn't have a parent, then it must be the top dog
680
-        if ($return_for_subsection || ! $this->parent_section()) {
681
-            EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
682
-                'form_section_id'  => $this->html_id(true),
683
-                'validation_rules' => $this->get_jquery_validation_rules(),
684
-                'other_data'       => $this->get_other_js_data(),
685
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
686
-            );
687
-            EE_Form_Section_Proper::$_scripts_localized = true;
688
-        }
689
-    }
690
-
691
-
692
-
693
-    /**
694
-     * Gets an array of extra data that will be useful for client-side javascript.
695
-     * This is primarily data added by inputs and forms in addition to any
696
-     * scripts they might enqueue
697
-     *
698
-     * @param array $form_other_js_data
699
-     * @return array
700
-     */
701
-    public function get_other_js_data($form_other_js_data = array())
702
-    {
703
-        foreach ($this->subsections() as $subsection) {
704
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
705
-        }
706
-        return $form_other_js_data;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * Gets a flat array of inputs for this form section and its subsections.
713
-     * Keys are their form names, and values are the inputs themselves
714
-     *
715
-     * @return EE_Form_Input_Base
716
-     */
717
-    public function inputs_in_subsections()
718
-    {
719
-        $inputs = array();
720
-        foreach ($this->subsections() as $subsection) {
721
-            if ($subsection instanceof EE_Form_Input_Base) {
722
-                $inputs[$subsection->html_name()] = $subsection;
723
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
724
-                $inputs += $subsection->inputs_in_subsections();
725
-            }
726
-        }
727
-        return $inputs;
728
-    }
729
-
730
-
731
-
732
-    /**
733
-     * Gets a flat array of all the validation errors.
734
-     * Keys are html names (because those should be unique)
735
-     * and values are a string of all their validation errors
736
-     *
737
-     * @return string[]
738
-     */
739
-    public function subsection_validation_errors_by_html_name()
740
-    {
741
-        $inputs = $this->inputs();
742
-        $errors = array();
743
-        foreach ($inputs as $form_input) {
744
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
745
-                $errors[$form_input->html_name()] = $form_input->get_validation_error_string();
746
-            }
747
-        }
748
-        return $errors;
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
755
-     * Should be setup by each form during the _enqueues_and_localize_form_js
756
-     */
757
-    public static function localize_script_for_all_forms()
758
-    {
759
-        //allow inputs and stuff to hook in their JS and stuff here
760
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
761
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
762
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
763
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
764
-            : 'wp_default';
765
-        EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
766
-        wp_enqueue_script('ee_form_section_validation');
767
-        wp_localize_script(
768
-            'ee_form_section_validation',
769
-            'ee_form_section_vars',
770
-            EE_Form_Section_Proper::$_js_localization
771
-        );
772
-    }
773
-
774
-
775
-
776
-    /**
777
-     * ensure_scripts_localized
778
-     */
779
-    public function ensure_scripts_localized()
780
-    {
781
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
782
-            $this->_enqueue_and_localize_form_js();
783
-        }
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
790
-     * is that the key here should be the same as the custom validation rule put in the JS file
791
-     *
792
-     * @return array keys are custom validation rules, and values are internationalized strings
793
-     */
794
-    private static function _get_localized_error_messages()
795
-    {
796
-        return array(
797
-            'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
798
-            'regex'    => __('Please check your input', 'event_espresso'),
799
-        );
800
-    }
801
-
802
-
803
-
804
-    /**
805
-     * @return array
806
-     */
807
-    public static function js_localization()
808
-    {
809
-        return self::$_js_localization;
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * @return array
816
-     */
817
-    public static function reset_js_localization()
818
-    {
819
-        self::$_js_localization = array();
820
-    }
821
-
822
-
823
-
824
-    /**
825
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
826
-     * See parent function for more...
827
-     *
828
-     * @return array
829
-     */
830
-    public function get_jquery_validation_rules()
831
-    {
832
-        $jquery_validation_rules = array();
833
-        foreach ($this->get_validatable_subsections() as $subsection) {
834
-            $jquery_validation_rules = array_merge(
835
-                $jquery_validation_rules,
836
-                $subsection->get_jquery_validation_rules()
837
-            );
838
-        }
839
-        return $jquery_validation_rules;
840
-    }
841
-
842
-
843
-
844
-    /**
845
-     * Sanitizes all the data and sets the sanitized value of each field
846
-     *
847
-     * @param array $req_data like $_POST
848
-     * @return void
849
-     */
850
-    protected function _normalize($req_data)
851
-    {
852
-        $this->_received_submission = true;
853
-        $this->_validation_errors = array();
854
-        foreach ($this->get_validatable_subsections() as $subsection) {
855
-            try {
856
-                $subsection->_normalize($req_data);
857
-            } catch (EE_Validation_Error $e) {
858
-                $subsection->add_validation_error($e);
859
-            }
860
-        }
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     * Performs validation on this form section and its subsections.
867
-     * For each subsection,
868
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
869
-     * and passes it the subsection, then calls _validate on that subsection.
870
-     * If you need to perform validation on the form as a whole (considering multiple)
871
-     * you would be best to override this _validate method,
872
-     * calling parent::_validate() first.
873
-     */
874
-    protected function _validate()
875
-    {
876
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
877
-            if (method_exists($this, '_validate_' . $subsection_name)) {
878
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
879
-            }
880
-            $subsection->_validate();
881
-        }
882
-    }
883
-
884
-
885
-
886
-    /**
887
-     * Gets all the validated inputs for the form section
888
-     *
889
-     * @return array
890
-     */
891
-    public function valid_data()
892
-    {
893
-        $inputs = array();
894
-        foreach ($this->subsections() as $subsection_name => $subsection) {
895
-            if ($subsection instanceof EE_Form_Section_Proper) {
896
-                $inputs[$subsection_name] = $subsection->valid_data();
897
-            } else if ($subsection instanceof EE_Form_Input_Base) {
898
-                $inputs[$subsection_name] = $subsection->normalized_value();
899
-            }
900
-        }
901
-        return $inputs;
902
-    }
903
-
904
-
905
-
906
-    /**
907
-     * Gets all the inputs on this form section
908
-     *
909
-     * @return EE_Form_Input_Base[]
910
-     */
911
-    public function inputs()
912
-    {
913
-        $inputs = array();
914
-        foreach ($this->subsections() as $subsection_name => $subsection) {
915
-            if ($subsection instanceof EE_Form_Input_Base) {
916
-                $inputs[$subsection_name] = $subsection;
917
-            }
918
-        }
919
-        return $inputs;
920
-    }
921
-
922
-
923
-
924
-    /**
925
-     * Gets all the subsections which are a proper form
926
-     *
927
-     * @return EE_Form_Section_Proper[]
928
-     */
929
-    public function subforms()
930
-    {
931
-        $form_sections = array();
932
-        foreach ($this->subsections() as $name => $obj) {
933
-            if ($obj instanceof EE_Form_Section_Proper) {
934
-                $form_sections[$name] = $obj;
935
-            }
936
-        }
937
-        return $form_sections;
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
944
-     * Consider using inputs() or subforms()
945
-     * if you only want form inputs or proper form sections.
946
-     *
947
-     * @param boolean $require_construction_to_be_finalized most client code should
948
-     *                                                      leave this as TRUE so that the inputs will be properly
949
-     *                                                      configured. However, some client code may be ok with
950
-     *                                                      construction finalize being called later
951
-     *                                                      (realizing that the subsections' html names might not be
952
-     *                                                      set yet, etc.)
953
-     * @return EE_Form_Section_Proper[]
954
-     */
955
-    public function subsections($require_construction_to_be_finalized = true)
956
-    {
957
-        if ($require_construction_to_be_finalized) {
958
-            $this->ensure_construct_finalized_called();
959
-        }
960
-        return $this->_subsections;
961
-    }
962
-
963
-
964
-
965
-    /**
966
-     * Returns a simple array where keys are input names, and values are their normalized
967
-     * values. (Similar to calling get_input_value on inputs)
968
-     *
969
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
970
-     *                                        or just this forms' direct children inputs
971
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
972
-     *                                        or allow multidimensional array
973
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
974
-     *                                        with array keys being input names
975
-     *                                        (regardless of whether they are from a subsection or not),
976
-     *                                        and if $flatten is FALSE it can be a multidimensional array
977
-     *                                        where keys are always subsection names and values are either
978
-     *                                        the input's normalized value, or an array like the top-level array
979
-     */
980
-    public function input_values($include_subform_inputs = false, $flatten = false)
981
-    {
982
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
983
-    }
984
-
985
-
986
-
987
-    /**
988
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
989
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
990
-     * is not necessarily the value we want to display to users. This creates an array
991
-     * where keys are the input names, and values are their display values
992
-     *
993
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
994
-     *                                        or just this forms' direct children inputs
995
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
996
-     *                                        or allow multidimensional array
997
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
998
-     *                                        with array keys being input names
999
-     *                                        (regardless of whether they are from a subsection or not),
1000
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1001
-     *                                        where keys are always subsection names and values are either
1002
-     *                                        the input's normalized value, or an array like the top-level array
1003
-     */
1004
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1005
-    {
1006
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1007
-    }
1008
-
1009
-
1010
-
1011
-    /**
1012
-     * Gets the input values from the form
1013
-     *
1014
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1015
-     *                                        or just the normalized value
1016
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1017
-     *                                        or just this forms' direct children inputs
1018
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1019
-     *                                        or allow multidimensional array
1020
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1021
-     *                                        input names (regardless of whether they are from a subsection or not),
1022
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1023
-     *                                        where keys are always subsection names and values are either
1024
-     *                                        the input's normalized value, or an array like the top-level array
1025
-     */
1026
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1027
-    {
1028
-        $input_values = array();
1029
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1030
-            if ($subsection instanceof EE_Form_Input_Base) {
1031
-                $input_values[$subsection_name] = $pretty
1032
-                    ? $subsection->pretty_value()
1033
-                    : $subsection->normalized_value();
1034
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1035
-                $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1036
-                if ($flatten) {
1037
-                    $input_values = array_merge($input_values, $subform_input_values);
1038
-                } else {
1039
-                    $input_values[$subsection_name] = $subform_input_values;
1040
-                }
1041
-            }
1042
-        }
1043
-        return $input_values;
1044
-    }
1045
-
1046
-
1047
-
1048
-    /**
1049
-     * Gets the originally submitted input values from the form
1050
-     *
1051
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1052
-     *                                   or just this forms' direct children inputs
1053
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1054
-     *                                   with array keys being input names
1055
-     *                                   (regardless of whether they are from a subsection or not),
1056
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1057
-     *                                   where keys are always subsection names and values are either
1058
-     *                                   the input's normalized value, or an array like the top-level array
1059
-     */
1060
-    public function submitted_values($include_subforms = false)
1061
-    {
1062
-        $submitted_values = array();
1063
-        foreach ($this->subsections() as $subsection) {
1064
-            if ($subsection instanceof EE_Form_Input_Base) {
1065
-                // is this input part of an array of inputs?
1066
-                if (strpos($subsection->html_name(), '[') !== false) {
1067
-                    $full_input_name = \EEH_Array::convert_array_values_to_keys(
1068
-                        explode('[', str_replace(']', '', $subsection->html_name())),
1069
-                        $subsection->raw_value()
1070
-                    );
1071
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1072
-                } else {
1073
-                    $submitted_values[$subsection->html_name()] = $subsection->raw_value();
1074
-                }
1075
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1076
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1077
-                $submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1078
-            }
1079
-        }
1080
-        return $submitted_values;
1081
-    }
1082
-
1083
-
1084
-
1085
-    /**
1086
-     * Indicates whether or not this form has received a submission yet
1087
-     * (ie, had receive_form_submission called on it yet)
1088
-     *
1089
-     * @return boolean
1090
-     * @throws \EE_Error
1091
-     */
1092
-    public function has_received_submission()
1093
-    {
1094
-        $this->ensure_construct_finalized_called();
1095
-        return $this->_received_submission;
1096
-    }
1097
-
1098
-
1099
-
1100
-    /**
1101
-     * Equivalent to passing 'exclude' in the constructor's options array.
1102
-     * Removes the listed inputs from the form
1103
-     *
1104
-     * @param array $inputs_to_exclude values are the input names
1105
-     * @return void
1106
-     */
1107
-    public function exclude(array $inputs_to_exclude = array())
1108
-    {
1109
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1110
-            unset($this->_subsections[$input_to_exclude_name]);
1111
-        }
1112
-    }
1113
-
1114
-
1115
-
1116
-    /**
1117
-     * @param array $inputs_to_hide
1118
-     * @throws \EE_Error
1119
-     */
1120
-    public function hide(array $inputs_to_hide = array())
1121
-    {
1122
-        foreach ($inputs_to_hide as $input_to_hide) {
1123
-            $input = $this->get_input($input_to_hide);
1124
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1125
-        }
1126
-    }
1127
-
1128
-
1129
-
1130
-    /**
1131
-     * add_subsections
1132
-     * Adds the listed subsections to the form section.
1133
-     * If $subsection_name_to_target is provided,
1134
-     * then new subsections are added before or after that subsection,
1135
-     * otherwise to the start or end of the entire subsections array.
1136
-     *
1137
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1138
-     *                                                          where keys are their names
1139
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1140
-     *                                                          should be added before or after
1141
-     *                                                          IF $subsection_name_to_target is null,
1142
-     *                                                          then $new_subsections will be added to
1143
-     *                                                          the beginning or end of the entire subsections array
1144
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1145
-     *                                                          $subsection_name_to_target,
1146
-     *                                                          or if $subsection_name_to_target is null,
1147
-     *                                                          before or after entire subsections array
1148
-     * @return void
1149
-     * @throws \EE_Error
1150
-     */
1151
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1152
-    {
1153
-        foreach ($new_subsections as $subsection_name => $subsection) {
1154
-            if (! $subsection instanceof EE_Form_Section_Base) {
1155
-                EE_Error::add_error(
1156
-                    sprintf(
1157
-                        __(
1158
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1159
-                            "event_espresso"
1160
-                        ),
1161
-                        get_class($subsection),
1162
-                        $subsection_name,
1163
-                        $this->name()
1164
-                    )
1165
-                );
1166
-                unset($new_subsections[$subsection_name]);
1167
-            }
1168
-        }
1169
-        $this->_subsections = EEH_Array::insert_into_array(
1170
-            $this->_subsections,
1171
-            $new_subsections,
1172
-            $subsection_name_to_target,
1173
-            $add_before
1174
-        );
1175
-        if ($this->_construction_finalized) {
1176
-            foreach ($this->_subsections as $name => $subsection) {
1177
-                $subsection->_construct_finalize($this, $name);
1178
-            }
1179
-        }
1180
-    }
1181
-
1182
-
1183
-
1184
-    /**
1185
-     * Just gets all validatable subsections to clean their sensitive data
1186
-     */
1187
-    public function clean_sensitive_data()
1188
-    {
1189
-        foreach ($this->get_validatable_subsections() as $subsection) {
1190
-            $subsection->clean_sensitive_data();
1191
-        }
1192
-    }
1193
-
1194
-
1195
-
1196
-    /**
1197
-     * @param string $form_submission_error_message
1198
-     */
1199
-    public function set_submission_error_message($form_submission_error_message = '')
1200
-    {
1201
-        $this->_form_submission_error_message .= ! empty($form_submission_error_message)
1202
-            ? $form_submission_error_message
1203
-            : __('Form submission failed due to errors', 'event_espresso');
1204
-    }
1205
-
1206
-
1207
-
1208
-    /**
1209
-     * @return string
1210
-     */
1211
-    public function submission_error_message()
1212
-    {
1213
-        return $this->_form_submission_error_message;
1214
-    }
1215
-
1216
-
1217
-
1218
-    /**
1219
-     * @param string $form_submission_success_message
1220
-     */
1221
-    public function set_submission_success_message($form_submission_success_message)
1222
-    {
1223
-        $this->_form_submission_success_message .= ! empty($form_submission_success_message)
1224
-            ? $form_submission_success_message
1225
-            : __('Form submitted successfully', 'event_espresso');
1226
-    }
1227
-
1228
-
1229
-
1230
-    /**
1231
-     * @return string
1232
-     */
1233
-    public function submission_success_message()
1234
-    {
1235
-        return $this->_form_submission_success_message;
1236
-    }
1237
-
1238
-
1239
-
1240
-    /**
1241
-     * Returns the prefix that should be used on child of this form section for
1242
-     * their html names. If this form section itself has a parent, prepends ITS
1243
-     * prefix onto this form section's prefix. Used primarily by
1244
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1245
-     *
1246
-     * @return string
1247
-     * @throws \EE_Error
1248
-     */
1249
-    public function html_name_prefix()
1250
-    {
1251
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1252
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1253
-        } else {
1254
-            return $this->name();
1255
-        }
1256
-    }
1257
-
1258
-
1259
-
1260
-    /**
1261
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1262
-     * calls it (assumes there is no parent and that we want the name to be whatever
1263
-     * was set, which is probably nothing, or the classname)
1264
-     *
1265
-     * @return string
1266
-     * @throws \EE_Error
1267
-     */
1268
-    public function name()
1269
-    {
1270
-        $this->ensure_construct_finalized_called();
1271
-        return parent::name();
1272
-    }
1273
-
1274
-
1275
-
1276
-    /**
1277
-     * @return EE_Form_Section_Proper
1278
-     * @throws \EE_Error
1279
-     */
1280
-    public function parent_section()
1281
-    {
1282
-        $this->ensure_construct_finalized_called();
1283
-        return parent::parent_section();
1284
-    }
1285
-
1286
-
1287
-
1288
-    /**
1289
-     * make sure construction finalized was called, otherwise children might not be ready
1290
-     *
1291
-     * @return void
1292
-     * @throws \EE_Error
1293
-     */
1294
-    public function ensure_construct_finalized_called()
1295
-    {
1296
-        if (! $this->_construction_finalized) {
1297
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1298
-        }
1299
-    }
1300
-
1301
-
1302
-
1303
-    /**
1304
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1305
-     * are in teh form data. If any are found, returns true. Else false
1306
-     *
1307
-     * @param array $req_data
1308
-     * @return boolean
1309
-     */
1310
-    public function form_data_present_in($req_data = null)
1311
-    {
1312
-        if ($req_data === null) {
1313
-            $req_data = $_POST;
1314
-        }
1315
-        foreach ($this->subsections() as $subsection) {
1316
-            if ($subsection instanceof EE_Form_Input_Base) {
1317
-                if ($subsection->form_data_present_in($req_data)) {
1318
-                    return true;
1319
-                }
1320
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1321
-                if ($subsection->form_data_present_in($req_data)) {
1322
-                    return true;
1323
-                }
1324
-            }
1325
-        }
1326
-        return false;
1327
-    }
1328
-
1329
-
1330
-
1331
-    /**
1332
-     * Gets validation errors for this form section and subsections
1333
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1334
-     * gets the validation errors for ALL subsection
1335
-     *
1336
-     * @return EE_Validation_Error[]
1337
-     */
1338
-    public function get_validation_errors_accumulated()
1339
-    {
1340
-        $validation_errors = $this->get_validation_errors();
1341
-        foreach ($this->get_validatable_subsections() as $subsection) {
1342
-            if ($subsection instanceof EE_Form_Section_Proper) {
1343
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1344
-            } else {
1345
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1346
-            }
1347
-            if ($validation_errors_on_this_subsection) {
1348
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1349
-            }
1350
-        }
1351
-        return $validation_errors;
1352
-    }
1353
-
1354
-
1355
-
1356
-    /**
1357
-     * This isn't just the name of an input, it's a path pointing to an input. The
1358
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1359
-     * dot-dot-slash (../) means to ascend into the parent section.
1360
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1361
-     * which will be returned.
1362
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1363
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1364
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1365
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1366
-     * Etc
1367
-     *
1368
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1369
-     * @return EE_Form_Section_Base
1370
-     */
1371
-    public function find_section_from_path($form_section_path)
1372
-    {
1373
-        //check if we can find the input from purely going straight up the tree
1374
-        $input = parent::find_section_from_path($form_section_path);
1375
-        if ($input instanceof EE_Form_Section_Base) {
1376
-            return $input;
1377
-        }
1378
-        $next_slash_pos = strpos($form_section_path, '/');
1379
-        if ($next_slash_pos !== false) {
1380
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1381
-            $subpath = substr($form_section_path, $next_slash_pos + 1);
1382
-        } else {
1383
-            $child_section_name = $form_section_path;
1384
-            $subpath = '';
1385
-        }
1386
-        $child_section = $this->get_subsection($child_section_name);
1387
-        if ($child_section instanceof EE_Form_Section_Base) {
1388
-            return $child_section->find_section_from_path($subpath);
1389
-        } else {
1390
-            return null;
1391
-        }
1392
-    }
14
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
15
+
16
+	/**
17
+	 * Subsections
18
+	 *
19
+	 * @var EE_Form_Section_Validatable[]
20
+	 */
21
+	protected $_subsections = array();
22
+
23
+	/**
24
+	 * Strategy for laying out the form
25
+	 *
26
+	 * @var EE_Form_Section_Layout_Base
27
+	 */
28
+	protected $_layout_strategy;
29
+
30
+	/**
31
+	 * Whether or not this form has received and validated a form submission yet
32
+	 *
33
+	 * @var boolean
34
+	 */
35
+	protected $_received_submission = false;
36
+
37
+	/**
38
+	 * message displayed to users upon successful form submission
39
+	 *
40
+	 * @var string
41
+	 */
42
+	protected $_form_submission_success_message = '';
43
+
44
+	/**
45
+	 * message displayed to users upon unsuccessful form submission
46
+	 *
47
+	 * @var string
48
+	 */
49
+	protected $_form_submission_error_message = '';
50
+
51
+	/**
52
+	 * Stores all the data that will localized for form validation
53
+	 *
54
+	 * @var array
55
+	 */
56
+	static protected $_js_localization = array();
57
+
58
+	/**
59
+	 * whether or not the form's localized validation JS vars have been set
60
+	 *
61
+	 * @type boolean
62
+	 */
63
+	static protected $_scripts_localized = false;
64
+
65
+
66
+
67
+	/**
68
+	 * when constructing a proper form section, calls _construct_finalize on children
69
+	 * so that they know who their parent is, and what name they've been given.
70
+	 *
71
+	 * @param array $options_array   {
72
+	 * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
73
+	 * @type        $include         string[] numerically-indexed where values are section names to be included,
74
+	 *                               and in that order. This is handy if you want
75
+	 *                               the subsections to be ordered differently than the default, and if you override
76
+	 *                               which fields are shown
77
+	 * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
78
+	 *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
79
+	 *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
80
+	 *                               items from that list of inclusions)
81
+	 * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
82
+	 *                               } @see EE_Form_Section_Validatable::__construct()
83
+	 * @throws \EE_Error
84
+	 */
85
+	public function __construct($options_array = array())
86
+	{
87
+		$options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88
+			$this);
89
+		//call parent first, as it may be setting the name
90
+		parent::__construct($options_array);
91
+		//if they've included subsections in the constructor, add them now
92
+		if (isset($options_array['include'])) {
93
+			//we are going to make sure we ONLY have those subsections to include
94
+			//AND we are going to make sure they're in that specified order
95
+			$reordered_subsections = array();
96
+			foreach ($options_array['include'] as $input_name) {
97
+				if (isset($this->_subsections[$input_name])) {
98
+					$reordered_subsections[$input_name] = $this->_subsections[$input_name];
99
+				}
100
+			}
101
+			$this->_subsections = $reordered_subsections;
102
+		}
103
+		if (isset($options_array['exclude'])) {
104
+			$exclude = $options_array['exclude'];
105
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
106
+		}
107
+		if (isset($options_array['layout_strategy'])) {
108
+			$this->_layout_strategy = $options_array['layout_strategy'];
109
+		}
110
+		if (! $this->_layout_strategy) {
111
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112
+		}
113
+		$this->_layout_strategy->_construct_finalize($this);
114
+		//ok so we are definitely going to want the forms JS,
115
+		//so enqueue it or remember to enqueue it during wp_enqueue_scripts
116
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
117
+			//ok so they've constructed this object after when they should have.
118
+			//just enqueue the generic form scripts and initialize the form immediately in the JS
119
+			\EE_Form_Section_Proper::wp_enqueue_scripts(true);
120
+		} else {
121
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
122
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
123
+		}
124
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
125
+
126
+		/**
127
+		 * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't
128
+		 * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to
129
+		 * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
130
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
131
+		 * @since 4.9.32
132
+		 * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling
133
+		 *                                      _construct_finalize has been done
134
+		 * @param array $options_array options passed into the constructor
135
+		 */
136
+		do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array);
137
+
138
+		if (isset($options_array['name'])) {
139
+			$this->_construct_finalize(null, $options_array['name']);
140
+		}
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * Finishes construction given the parent form section and this form section's name
147
+	 *
148
+	 * @param EE_Form_Section_Proper $parent_form_section
149
+	 * @param string                 $name
150
+	 * @throws \EE_Error
151
+	 */
152
+	public function _construct_finalize($parent_form_section, $name)
153
+	{
154
+		parent::_construct_finalize($parent_form_section, $name);
155
+		$this->_set_default_name_if_empty();
156
+		$this->_set_default_html_id_if_empty();
157
+		foreach ($this->_subsections as $subsection_name => $subsection) {
158
+			if ($subsection instanceof EE_Form_Section_Base) {
159
+				$subsection->_construct_finalize($this, $subsection_name);
160
+			} else {
161
+				throw new EE_Error(
162
+					sprintf(
163
+						__('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
164
+							'event_espresso'),
165
+						$subsection_name,
166
+						get_class($this),
167
+						$subsection ? get_class($subsection) : __('NULL', 'event_espresso')
168
+					)
169
+				);
170
+			}
171
+		}
172
+		/**
173
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
174
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived
175
+		 * from the name like the HTML label id, etc), this is where it should be done.
176
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
177
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
178
+		 * ensured it has a name, HTML IDs, etc
179
+		 * @param EE_Form_Section_Proper $this
180
+		 * @param EE_Form_Section_Proper|null $parent_form_section
181
+		 * @param string $name
182
+		 */
183
+		do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Gets the layout strategy for this form section
190
+	 *
191
+	 * @return EE_Form_Section_Layout_Base
192
+	 */
193
+	public function get_layout_strategy()
194
+	{
195
+		return $this->_layout_strategy;
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Gets the HTML for a single input for this form section according
202
+	 * to the layout strategy
203
+	 *
204
+	 * @param EE_Form_Input_Base $input
205
+	 * @return string
206
+	 */
207
+	public function get_html_for_input($input)
208
+	{
209
+		return $this->_layout_strategy->layout_input($input);
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * was_submitted - checks if form inputs are present in request data
216
+	 * Basically an alias for form_data_present_in() (which is used by both
217
+	 * proper form sections and form inputs)
218
+	 *
219
+	 * @param null $form_data
220
+	 * @return boolean
221
+	 */
222
+	public function was_submitted($form_data = null)
223
+	{
224
+		return $this->form_data_present_in($form_data);
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * After the form section is initially created, call this to sanitize the data in the submission
231
+	 * which relates to this form section, validate it, and set it as properties on the form.
232
+	 *
233
+	 * @param array|null $req_data should usually be $_POST (the default).
234
+	 *                             However, you CAN supply a different array.
235
+	 *                             Consider using set_defaults() instead however.
236
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
237
+	 *                             the inputs will have the correct name in the request data for this function
238
+	 *                             to find them and populate the form with them.
239
+	 *                             If you have a flat form (with only input subsections),
240
+	 *                             you can supply a flat array where keys
241
+	 *                             are the form input names and values are their values)
242
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
243
+	 *                             of course, to validate that data, and set errors on the invalid values.
244
+	 *                             But if the data has already been validated
245
+	 *                             (eg you validated the data then stored it in the DB)
246
+	 *                             you may want to skip this step.
247
+	 */
248
+	public function receive_form_submission($req_data = null, $validate = true)
249
+	{
250
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
251
+			$validate);
252
+		if ($req_data === null) {
253
+			$req_data = array_merge($_GET, $_POST);
254
+		}
255
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
256
+			$this);
257
+		$this->_normalize($req_data);
258
+		if ($validate) {
259
+			$this->_validate();
260
+			//if it's invalid, we're going to want to re-display so remember what they submitted
261
+			if (! $this->is_valid()) {
262
+				$this->store_submitted_form_data_in_session();
263
+			}
264
+		}
265
+		do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 * caches the originally submitted input values in the session
272
+	 * so that they can be used to repopulate the form if it failed validation
273
+	 *
274
+	 * @return boolean whether or not the data was successfully stored in the session
275
+	 */
276
+	protected function store_submitted_form_data_in_session()
277
+	{
278
+		return EE_Registry::instance()->SSN->set_session_data(
279
+			array(
280
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
281
+			)
282
+		);
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * retrieves the originally submitted input values in the session
289
+	 * so that they can be used to repopulate the form if it failed validation
290
+	 *
291
+	 * @return array
292
+	 */
293
+	protected function get_submitted_form_data_from_session()
294
+	{
295
+		$session = EE_Registry::instance()->SSN;
296
+		if ($session instanceof EE_Session) {
297
+			return $session->get_session_data(
298
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
299
+			);
300
+		} else {
301
+			return array();
302
+		}
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * flushed the originally submitted input values from the session
309
+	 *
310
+	 * @return boolean whether or not the data was successfully removed from the session
311
+	 */
312
+	protected function flush_submitted_form_data_from_session()
313
+	{
314
+		return EE_Registry::instance()->SSN->reset_data(
315
+			array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
316
+		);
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 * Populates this form and its subsections with data from the session.
323
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
324
+	 * validation errors when displaying too)
325
+	 * Returns true if the form was populated from the session, false otherwise
326
+	 *
327
+	 * @return boolean
328
+	 */
329
+	public function populate_from_session()
330
+	{
331
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
332
+		if (empty($form_data_in_session)) {
333
+			return false;
334
+		}
335
+		$this->receive_form_submission($form_data_in_session);
336
+		$this->flush_submitted_form_data_from_session();
337
+		if ($this->form_data_present_in($form_data_in_session)) {
338
+			return true;
339
+		} else {
340
+			return false;
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * Populates the default data for the form, given an array where keys are
348
+	 * the input names, and values are their values (preferably normalized to be their
349
+	 * proper PHP types, not all strings... although that should be ok too).
350
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
351
+	 * the value being an array formatted in teh same way
352
+	 *
353
+	 * @param array $default_data
354
+	 */
355
+	public function populate_defaults($default_data)
356
+	{
357
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
358
+			if (isset($default_data[$subsection_name])) {
359
+				if ($subsection instanceof EE_Form_Input_Base) {
360
+					$subsection->set_default($default_data[$subsection_name]);
361
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
362
+					$subsection->populate_defaults($default_data[$subsection_name]);
363
+				}
364
+			}
365
+		}
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 * returns true if subsection exists
372
+	 *
373
+	 * @param string $name
374
+	 * @return boolean
375
+	 */
376
+	public function subsection_exists($name)
377
+	{
378
+		return isset($this->_subsections[$name]) ? true : false;
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * Gets the subsection specified by its name
385
+	 *
386
+	 * @param string  $name
387
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
388
+	 *                                                      so that the inputs will be properly configured.
389
+	 *                                                      However, some client code may be ok
390
+	 *                                                      with construction finalize being called later
391
+	 *                                                      (realizing that the subsections' html names
392
+	 *                                                      might not be set yet, etc.)
393
+	 * @return EE_Form_Section_Base
394
+	 * @throws \EE_Error
395
+	 */
396
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
397
+	{
398
+		if ($require_construction_to_be_finalized) {
399
+			$this->ensure_construct_finalized_called();
400
+		}
401
+		return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * Gets all the validatable subsections of this form section
408
+	 *
409
+	 * @return EE_Form_Section_Validatable[]
410
+	 */
411
+	public function get_validatable_subsections()
412
+	{
413
+		$validatable_subsections = array();
414
+		foreach ($this->subsections() as $name => $obj) {
415
+			if ($obj instanceof EE_Form_Section_Validatable) {
416
+				$validatable_subsections[$name] = $obj;
417
+			}
418
+		}
419
+		return $validatable_subsections;
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
426
+	 * throw an EE_Error.
427
+	 *
428
+	 * @param string  $name
429
+	 * @param boolean $require_construction_to_be_finalized most client code should
430
+	 *                                                      leave this as TRUE so that the inputs will be properly
431
+	 *                                                      configured. However, some client code may be ok with
432
+	 *                                                      construction finalize being called later
433
+	 *                                                      (realizing that the subsections' html names might not be
434
+	 *                                                      set yet, etc.)
435
+	 * @return EE_Form_Input_Base
436
+	 * @throws EE_Error
437
+	 */
438
+	public function get_input($name, $require_construction_to_be_finalized = true)
439
+	{
440
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
+		if (! $subsection instanceof EE_Form_Input_Base) {
442
+			throw new EE_Error(
443
+				sprintf(
444
+					__(
445
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
446
+						'event_espresso'
447
+					),
448
+					$name,
449
+					get_class($this),
450
+					$subsection ? get_class($subsection) : __("NULL", 'event_espresso')
451
+				)
452
+			);
453
+		}
454
+		return $subsection;
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * Like get_input(), gets the proper subsection of the form given the name,
461
+	 * otherwise throws an EE_Error
462
+	 *
463
+	 * @param string  $name
464
+	 * @param boolean $require_construction_to_be_finalized most client code should
465
+	 *                                                      leave this as TRUE so that the inputs will be properly
466
+	 *                                                      configured. However, some client code may be ok with
467
+	 *                                                      construction finalize being called later
468
+	 *                                                      (realizing that the subsections' html names might not be
469
+	 *                                                      set yet, etc.)
470
+	 * @return EE_Form_Section_Proper
471
+	 * @throws EE_Error
472
+	 */
473
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474
+	{
475
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
+		if (! $subsection instanceof EE_Form_Section_Proper) {
477
+			throw new EE_Error(
478
+				sprintf(
479
+					__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
480
+					$name,
481
+					get_class($this)
482
+				)
483
+			);
484
+		}
485
+		return $subsection;
486
+	}
487
+
488
+
489
+
490
+	/**
491
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
492
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
493
+	 *
494
+	 * @param string $name
495
+	 * @return mixed depending on the input's type and its normalization strategy
496
+	 * @throws \EE_Error
497
+	 */
498
+	public function get_input_value($name)
499
+	{
500
+		$input = $this->get_input($name);
501
+		return $input->normalized_value();
502
+	}
503
+
504
+
505
+
506
+	/**
507
+	 * Checks if this form section itself is valid, and then checks its subsections
508
+	 *
509
+	 * @throws EE_Error
510
+	 * @return boolean
511
+	 */
512
+	public function is_valid()
513
+	{
514
+		if (! $this->has_received_submission()) {
515
+			throw new EE_Error(
516
+				sprintf(
517
+					__(
518
+						"You cannot check if a form is valid before receiving the form submission using receive_form_submission",
519
+						"event_espresso"
520
+					)
521
+				)
522
+			);
523
+		}
524
+		if (! parent::is_valid()) {
525
+			return false;
526
+		}
527
+		// ok so no general errors to this entire form section.
528
+		// so let's check the subsections, but only set errors if that hasn't been done yet
529
+		$set_submission_errors = $this->submission_error_message() === '' ? true : false;
530
+		foreach ($this->get_validatable_subsections() as $subsection) {
531
+			if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532
+				if ($set_submission_errors) {
533
+					$this->set_submission_error_message($subsection->get_validation_error_string());
534
+				}
535
+				return false;
536
+			}
537
+		}
538
+		return true;
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 * gets teh default name of this form section if none is specified
545
+	 *
546
+	 * @return string
547
+	 */
548
+	protected function _set_default_name_if_empty()
549
+	{
550
+		if (! $this->_name) {
551
+			$classname = get_class($this);
552
+			$default_name = str_replace("EE_", "", $classname);
553
+			$this->_name = $default_name;
554
+		}
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * Returns the HTML for the form, except for the form opening and closing tags
561
+	 * (as the form section doesn't know where you necessarily want to send the information to),
562
+	 * and except for a submit button. Enqueus JS and CSS; if called early enough we will
563
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
564
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
565
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
566
+	 * any CSS.
567
+	 *
568
+	 * @throws \EE_Error
569
+	 */
570
+	public function get_html_and_js()
571
+	{
572
+		$this->enqueue_js();
573
+		return $this->get_html();
574
+	}
575
+
576
+
577
+
578
+	/**
579
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
580
+	 *
581
+	 * @param bool $display_previously_submitted_data
582
+	 * @return string
583
+	 */
584
+	public function get_html($display_previously_submitted_data = true)
585
+	{
586
+		$this->ensure_construct_finalized_called();
587
+		if ($display_previously_submitted_data) {
588
+			$this->populate_from_session();
589
+		}
590
+		return $this->_form_html_filter
591
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
592
+			: $this->_layout_strategy->layout_form();
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * enqueues JS and CSS for the form.
599
+	 * It is preferred to call this before wp_enqueue_scripts so the
600
+	 * scripts and styles can be put in the header, but if called later
601
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
602
+	 * only be in the header; but in HTML5 its ok in the body.
603
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
604
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
605
+	 *
606
+	 * @return string
607
+	 * @throws \EE_Error
608
+	 */
609
+	public function enqueue_js()
610
+	{
611
+		$this->_enqueue_and_localize_form_js();
612
+		foreach ($this->subsections() as $subsection) {
613
+			$subsection->enqueue_js();
614
+		}
615
+	}
616
+
617
+
618
+
619
+	/**
620
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
621
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
622
+	 * the wp_enqueue_scripts hook.
623
+	 * However, registering the form js and localizing it can happen when we
624
+	 * actually output the form (which is preferred, seeing how teh form's fields
625
+	 * could change until it's actually outputted)
626
+	 *
627
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
628
+	 *                                                    to be triggered automatically or not
629
+	 * @return void
630
+	 */
631
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
632
+	{
633
+		wp_register_script(
634
+			'ee_form_section_validation',
635
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
636
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
637
+			EVENT_ESPRESSO_VERSION,
638
+			true
639
+		);
640
+		wp_localize_script(
641
+			'ee_form_section_validation',
642
+			'ee_form_section_validation_init',
643
+			array('init' => $init_form_validation_automatically ? '1' : '0')
644
+		);
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * gets the variables used by form_section_validation.js.
651
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
652
+	 * but before the wordpress hook wp_loaded
653
+	 *
654
+	 * @throws \EE_Error
655
+	 */
656
+	public function _enqueue_and_localize_form_js()
657
+	{
658
+		$this->ensure_construct_finalized_called();
659
+		//actually, we don't want to localize just yet. There may be other forms on the page.
660
+		//so we need to add our form section data to a static variable accessible by all form sections
661
+		//and localize it just before the footer
662
+		$this->localize_validation_rules();
663
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
664
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
665
+	}
666
+
667
+
668
+
669
+	/**
670
+	 * add our form section data to a static variable accessible by all form sections
671
+	 *
672
+	 * @param bool $return_for_subsection
673
+	 * @return void
674
+	 * @throws \EE_Error
675
+	 */
676
+	public function localize_validation_rules($return_for_subsection = false)
677
+	{
678
+		// we only want to localize vars ONCE for the entire form,
679
+		// so if the form section doesn't have a parent, then it must be the top dog
680
+		if ($return_for_subsection || ! $this->parent_section()) {
681
+			EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
682
+				'form_section_id'  => $this->html_id(true),
683
+				'validation_rules' => $this->get_jquery_validation_rules(),
684
+				'other_data'       => $this->get_other_js_data(),
685
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
686
+			);
687
+			EE_Form_Section_Proper::$_scripts_localized = true;
688
+		}
689
+	}
690
+
691
+
692
+
693
+	/**
694
+	 * Gets an array of extra data that will be useful for client-side javascript.
695
+	 * This is primarily data added by inputs and forms in addition to any
696
+	 * scripts they might enqueue
697
+	 *
698
+	 * @param array $form_other_js_data
699
+	 * @return array
700
+	 */
701
+	public function get_other_js_data($form_other_js_data = array())
702
+	{
703
+		foreach ($this->subsections() as $subsection) {
704
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
705
+		}
706
+		return $form_other_js_data;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * Gets a flat array of inputs for this form section and its subsections.
713
+	 * Keys are their form names, and values are the inputs themselves
714
+	 *
715
+	 * @return EE_Form_Input_Base
716
+	 */
717
+	public function inputs_in_subsections()
718
+	{
719
+		$inputs = array();
720
+		foreach ($this->subsections() as $subsection) {
721
+			if ($subsection instanceof EE_Form_Input_Base) {
722
+				$inputs[$subsection->html_name()] = $subsection;
723
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
724
+				$inputs += $subsection->inputs_in_subsections();
725
+			}
726
+		}
727
+		return $inputs;
728
+	}
729
+
730
+
731
+
732
+	/**
733
+	 * Gets a flat array of all the validation errors.
734
+	 * Keys are html names (because those should be unique)
735
+	 * and values are a string of all their validation errors
736
+	 *
737
+	 * @return string[]
738
+	 */
739
+	public function subsection_validation_errors_by_html_name()
740
+	{
741
+		$inputs = $this->inputs();
742
+		$errors = array();
743
+		foreach ($inputs as $form_input) {
744
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
745
+				$errors[$form_input->html_name()] = $form_input->get_validation_error_string();
746
+			}
747
+		}
748
+		return $errors;
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
755
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
756
+	 */
757
+	public static function localize_script_for_all_forms()
758
+	{
759
+		//allow inputs and stuff to hook in their JS and stuff here
760
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
761
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
762
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
763
+			? EE_Registry::instance()->CFG->registration->email_validation_level
764
+			: 'wp_default';
765
+		EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
766
+		wp_enqueue_script('ee_form_section_validation');
767
+		wp_localize_script(
768
+			'ee_form_section_validation',
769
+			'ee_form_section_vars',
770
+			EE_Form_Section_Proper::$_js_localization
771
+		);
772
+	}
773
+
774
+
775
+
776
+	/**
777
+	 * ensure_scripts_localized
778
+	 */
779
+	public function ensure_scripts_localized()
780
+	{
781
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
782
+			$this->_enqueue_and_localize_form_js();
783
+		}
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
790
+	 * is that the key here should be the same as the custom validation rule put in the JS file
791
+	 *
792
+	 * @return array keys are custom validation rules, and values are internationalized strings
793
+	 */
794
+	private static function _get_localized_error_messages()
795
+	{
796
+		return array(
797
+			'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
798
+			'regex'    => __('Please check your input', 'event_espresso'),
799
+		);
800
+	}
801
+
802
+
803
+
804
+	/**
805
+	 * @return array
806
+	 */
807
+	public static function js_localization()
808
+	{
809
+		return self::$_js_localization;
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * @return array
816
+	 */
817
+	public static function reset_js_localization()
818
+	{
819
+		self::$_js_localization = array();
820
+	}
821
+
822
+
823
+
824
+	/**
825
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
826
+	 * See parent function for more...
827
+	 *
828
+	 * @return array
829
+	 */
830
+	public function get_jquery_validation_rules()
831
+	{
832
+		$jquery_validation_rules = array();
833
+		foreach ($this->get_validatable_subsections() as $subsection) {
834
+			$jquery_validation_rules = array_merge(
835
+				$jquery_validation_rules,
836
+				$subsection->get_jquery_validation_rules()
837
+			);
838
+		}
839
+		return $jquery_validation_rules;
840
+	}
841
+
842
+
843
+
844
+	/**
845
+	 * Sanitizes all the data and sets the sanitized value of each field
846
+	 *
847
+	 * @param array $req_data like $_POST
848
+	 * @return void
849
+	 */
850
+	protected function _normalize($req_data)
851
+	{
852
+		$this->_received_submission = true;
853
+		$this->_validation_errors = array();
854
+		foreach ($this->get_validatable_subsections() as $subsection) {
855
+			try {
856
+				$subsection->_normalize($req_data);
857
+			} catch (EE_Validation_Error $e) {
858
+				$subsection->add_validation_error($e);
859
+			}
860
+		}
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 * Performs validation on this form section and its subsections.
867
+	 * For each subsection,
868
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
869
+	 * and passes it the subsection, then calls _validate on that subsection.
870
+	 * If you need to perform validation on the form as a whole (considering multiple)
871
+	 * you would be best to override this _validate method,
872
+	 * calling parent::_validate() first.
873
+	 */
874
+	protected function _validate()
875
+	{
876
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
877
+			if (method_exists($this, '_validate_' . $subsection_name)) {
878
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
879
+			}
880
+			$subsection->_validate();
881
+		}
882
+	}
883
+
884
+
885
+
886
+	/**
887
+	 * Gets all the validated inputs for the form section
888
+	 *
889
+	 * @return array
890
+	 */
891
+	public function valid_data()
892
+	{
893
+		$inputs = array();
894
+		foreach ($this->subsections() as $subsection_name => $subsection) {
895
+			if ($subsection instanceof EE_Form_Section_Proper) {
896
+				$inputs[$subsection_name] = $subsection->valid_data();
897
+			} else if ($subsection instanceof EE_Form_Input_Base) {
898
+				$inputs[$subsection_name] = $subsection->normalized_value();
899
+			}
900
+		}
901
+		return $inputs;
902
+	}
903
+
904
+
905
+
906
+	/**
907
+	 * Gets all the inputs on this form section
908
+	 *
909
+	 * @return EE_Form_Input_Base[]
910
+	 */
911
+	public function inputs()
912
+	{
913
+		$inputs = array();
914
+		foreach ($this->subsections() as $subsection_name => $subsection) {
915
+			if ($subsection instanceof EE_Form_Input_Base) {
916
+				$inputs[$subsection_name] = $subsection;
917
+			}
918
+		}
919
+		return $inputs;
920
+	}
921
+
922
+
923
+
924
+	/**
925
+	 * Gets all the subsections which are a proper form
926
+	 *
927
+	 * @return EE_Form_Section_Proper[]
928
+	 */
929
+	public function subforms()
930
+	{
931
+		$form_sections = array();
932
+		foreach ($this->subsections() as $name => $obj) {
933
+			if ($obj instanceof EE_Form_Section_Proper) {
934
+				$form_sections[$name] = $obj;
935
+			}
936
+		}
937
+		return $form_sections;
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
944
+	 * Consider using inputs() or subforms()
945
+	 * if you only want form inputs or proper form sections.
946
+	 *
947
+	 * @param boolean $require_construction_to_be_finalized most client code should
948
+	 *                                                      leave this as TRUE so that the inputs will be properly
949
+	 *                                                      configured. However, some client code may be ok with
950
+	 *                                                      construction finalize being called later
951
+	 *                                                      (realizing that the subsections' html names might not be
952
+	 *                                                      set yet, etc.)
953
+	 * @return EE_Form_Section_Proper[]
954
+	 */
955
+	public function subsections($require_construction_to_be_finalized = true)
956
+	{
957
+		if ($require_construction_to_be_finalized) {
958
+			$this->ensure_construct_finalized_called();
959
+		}
960
+		return $this->_subsections;
961
+	}
962
+
963
+
964
+
965
+	/**
966
+	 * Returns a simple array where keys are input names, and values are their normalized
967
+	 * values. (Similar to calling get_input_value on inputs)
968
+	 *
969
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
970
+	 *                                        or just this forms' direct children inputs
971
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
972
+	 *                                        or allow multidimensional array
973
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
974
+	 *                                        with array keys being input names
975
+	 *                                        (regardless of whether they are from a subsection or not),
976
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
977
+	 *                                        where keys are always subsection names and values are either
978
+	 *                                        the input's normalized value, or an array like the top-level array
979
+	 */
980
+	public function input_values($include_subform_inputs = false, $flatten = false)
981
+	{
982
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
983
+	}
984
+
985
+
986
+
987
+	/**
988
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
989
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
990
+	 * is not necessarily the value we want to display to users. This creates an array
991
+	 * where keys are the input names, and values are their display values
992
+	 *
993
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
994
+	 *                                        or just this forms' direct children inputs
995
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
996
+	 *                                        or allow multidimensional array
997
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
998
+	 *                                        with array keys being input names
999
+	 *                                        (regardless of whether they are from a subsection or not),
1000
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1001
+	 *                                        where keys are always subsection names and values are either
1002
+	 *                                        the input's normalized value, or an array like the top-level array
1003
+	 */
1004
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1005
+	{
1006
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1007
+	}
1008
+
1009
+
1010
+
1011
+	/**
1012
+	 * Gets the input values from the form
1013
+	 *
1014
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1015
+	 *                                        or just the normalized value
1016
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1017
+	 *                                        or just this forms' direct children inputs
1018
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1019
+	 *                                        or allow multidimensional array
1020
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1021
+	 *                                        input names (regardless of whether they are from a subsection or not),
1022
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1023
+	 *                                        where keys are always subsection names and values are either
1024
+	 *                                        the input's normalized value, or an array like the top-level array
1025
+	 */
1026
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1027
+	{
1028
+		$input_values = array();
1029
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1030
+			if ($subsection instanceof EE_Form_Input_Base) {
1031
+				$input_values[$subsection_name] = $pretty
1032
+					? $subsection->pretty_value()
1033
+					: $subsection->normalized_value();
1034
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1035
+				$subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1036
+				if ($flatten) {
1037
+					$input_values = array_merge($input_values, $subform_input_values);
1038
+				} else {
1039
+					$input_values[$subsection_name] = $subform_input_values;
1040
+				}
1041
+			}
1042
+		}
1043
+		return $input_values;
1044
+	}
1045
+
1046
+
1047
+
1048
+	/**
1049
+	 * Gets the originally submitted input values from the form
1050
+	 *
1051
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1052
+	 *                                   or just this forms' direct children inputs
1053
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1054
+	 *                                   with array keys being input names
1055
+	 *                                   (regardless of whether they are from a subsection or not),
1056
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1057
+	 *                                   where keys are always subsection names and values are either
1058
+	 *                                   the input's normalized value, or an array like the top-level array
1059
+	 */
1060
+	public function submitted_values($include_subforms = false)
1061
+	{
1062
+		$submitted_values = array();
1063
+		foreach ($this->subsections() as $subsection) {
1064
+			if ($subsection instanceof EE_Form_Input_Base) {
1065
+				// is this input part of an array of inputs?
1066
+				if (strpos($subsection->html_name(), '[') !== false) {
1067
+					$full_input_name = \EEH_Array::convert_array_values_to_keys(
1068
+						explode('[', str_replace(']', '', $subsection->html_name())),
1069
+						$subsection->raw_value()
1070
+					);
1071
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1072
+				} else {
1073
+					$submitted_values[$subsection->html_name()] = $subsection->raw_value();
1074
+				}
1075
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1076
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1077
+				$submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1078
+			}
1079
+		}
1080
+		return $submitted_values;
1081
+	}
1082
+
1083
+
1084
+
1085
+	/**
1086
+	 * Indicates whether or not this form has received a submission yet
1087
+	 * (ie, had receive_form_submission called on it yet)
1088
+	 *
1089
+	 * @return boolean
1090
+	 * @throws \EE_Error
1091
+	 */
1092
+	public function has_received_submission()
1093
+	{
1094
+		$this->ensure_construct_finalized_called();
1095
+		return $this->_received_submission;
1096
+	}
1097
+
1098
+
1099
+
1100
+	/**
1101
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1102
+	 * Removes the listed inputs from the form
1103
+	 *
1104
+	 * @param array $inputs_to_exclude values are the input names
1105
+	 * @return void
1106
+	 */
1107
+	public function exclude(array $inputs_to_exclude = array())
1108
+	{
1109
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1110
+			unset($this->_subsections[$input_to_exclude_name]);
1111
+		}
1112
+	}
1113
+
1114
+
1115
+
1116
+	/**
1117
+	 * @param array $inputs_to_hide
1118
+	 * @throws \EE_Error
1119
+	 */
1120
+	public function hide(array $inputs_to_hide = array())
1121
+	{
1122
+		foreach ($inputs_to_hide as $input_to_hide) {
1123
+			$input = $this->get_input($input_to_hide);
1124
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1125
+		}
1126
+	}
1127
+
1128
+
1129
+
1130
+	/**
1131
+	 * add_subsections
1132
+	 * Adds the listed subsections to the form section.
1133
+	 * If $subsection_name_to_target is provided,
1134
+	 * then new subsections are added before or after that subsection,
1135
+	 * otherwise to the start or end of the entire subsections array.
1136
+	 *
1137
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1138
+	 *                                                          where keys are their names
1139
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1140
+	 *                                                          should be added before or after
1141
+	 *                                                          IF $subsection_name_to_target is null,
1142
+	 *                                                          then $new_subsections will be added to
1143
+	 *                                                          the beginning or end of the entire subsections array
1144
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1145
+	 *                                                          $subsection_name_to_target,
1146
+	 *                                                          or if $subsection_name_to_target is null,
1147
+	 *                                                          before or after entire subsections array
1148
+	 * @return void
1149
+	 * @throws \EE_Error
1150
+	 */
1151
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1152
+	{
1153
+		foreach ($new_subsections as $subsection_name => $subsection) {
1154
+			if (! $subsection instanceof EE_Form_Section_Base) {
1155
+				EE_Error::add_error(
1156
+					sprintf(
1157
+						__(
1158
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1159
+							"event_espresso"
1160
+						),
1161
+						get_class($subsection),
1162
+						$subsection_name,
1163
+						$this->name()
1164
+					)
1165
+				);
1166
+				unset($new_subsections[$subsection_name]);
1167
+			}
1168
+		}
1169
+		$this->_subsections = EEH_Array::insert_into_array(
1170
+			$this->_subsections,
1171
+			$new_subsections,
1172
+			$subsection_name_to_target,
1173
+			$add_before
1174
+		);
1175
+		if ($this->_construction_finalized) {
1176
+			foreach ($this->_subsections as $name => $subsection) {
1177
+				$subsection->_construct_finalize($this, $name);
1178
+			}
1179
+		}
1180
+	}
1181
+
1182
+
1183
+
1184
+	/**
1185
+	 * Just gets all validatable subsections to clean their sensitive data
1186
+	 */
1187
+	public function clean_sensitive_data()
1188
+	{
1189
+		foreach ($this->get_validatable_subsections() as $subsection) {
1190
+			$subsection->clean_sensitive_data();
1191
+		}
1192
+	}
1193
+
1194
+
1195
+
1196
+	/**
1197
+	 * @param string $form_submission_error_message
1198
+	 */
1199
+	public function set_submission_error_message($form_submission_error_message = '')
1200
+	{
1201
+		$this->_form_submission_error_message .= ! empty($form_submission_error_message)
1202
+			? $form_submission_error_message
1203
+			: __('Form submission failed due to errors', 'event_espresso');
1204
+	}
1205
+
1206
+
1207
+
1208
+	/**
1209
+	 * @return string
1210
+	 */
1211
+	public function submission_error_message()
1212
+	{
1213
+		return $this->_form_submission_error_message;
1214
+	}
1215
+
1216
+
1217
+
1218
+	/**
1219
+	 * @param string $form_submission_success_message
1220
+	 */
1221
+	public function set_submission_success_message($form_submission_success_message)
1222
+	{
1223
+		$this->_form_submission_success_message .= ! empty($form_submission_success_message)
1224
+			? $form_submission_success_message
1225
+			: __('Form submitted successfully', 'event_espresso');
1226
+	}
1227
+
1228
+
1229
+
1230
+	/**
1231
+	 * @return string
1232
+	 */
1233
+	public function submission_success_message()
1234
+	{
1235
+		return $this->_form_submission_success_message;
1236
+	}
1237
+
1238
+
1239
+
1240
+	/**
1241
+	 * Returns the prefix that should be used on child of this form section for
1242
+	 * their html names. If this form section itself has a parent, prepends ITS
1243
+	 * prefix onto this form section's prefix. Used primarily by
1244
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1245
+	 *
1246
+	 * @return string
1247
+	 * @throws \EE_Error
1248
+	 */
1249
+	public function html_name_prefix()
1250
+	{
1251
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1252
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1253
+		} else {
1254
+			return $this->name();
1255
+		}
1256
+	}
1257
+
1258
+
1259
+
1260
+	/**
1261
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1262
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1263
+	 * was set, which is probably nothing, or the classname)
1264
+	 *
1265
+	 * @return string
1266
+	 * @throws \EE_Error
1267
+	 */
1268
+	public function name()
1269
+	{
1270
+		$this->ensure_construct_finalized_called();
1271
+		return parent::name();
1272
+	}
1273
+
1274
+
1275
+
1276
+	/**
1277
+	 * @return EE_Form_Section_Proper
1278
+	 * @throws \EE_Error
1279
+	 */
1280
+	public function parent_section()
1281
+	{
1282
+		$this->ensure_construct_finalized_called();
1283
+		return parent::parent_section();
1284
+	}
1285
+
1286
+
1287
+
1288
+	/**
1289
+	 * make sure construction finalized was called, otherwise children might not be ready
1290
+	 *
1291
+	 * @return void
1292
+	 * @throws \EE_Error
1293
+	 */
1294
+	public function ensure_construct_finalized_called()
1295
+	{
1296
+		if (! $this->_construction_finalized) {
1297
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1298
+		}
1299
+	}
1300
+
1301
+
1302
+
1303
+	/**
1304
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1305
+	 * are in teh form data. If any are found, returns true. Else false
1306
+	 *
1307
+	 * @param array $req_data
1308
+	 * @return boolean
1309
+	 */
1310
+	public function form_data_present_in($req_data = null)
1311
+	{
1312
+		if ($req_data === null) {
1313
+			$req_data = $_POST;
1314
+		}
1315
+		foreach ($this->subsections() as $subsection) {
1316
+			if ($subsection instanceof EE_Form_Input_Base) {
1317
+				if ($subsection->form_data_present_in($req_data)) {
1318
+					return true;
1319
+				}
1320
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1321
+				if ($subsection->form_data_present_in($req_data)) {
1322
+					return true;
1323
+				}
1324
+			}
1325
+		}
1326
+		return false;
1327
+	}
1328
+
1329
+
1330
+
1331
+	/**
1332
+	 * Gets validation errors for this form section and subsections
1333
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1334
+	 * gets the validation errors for ALL subsection
1335
+	 *
1336
+	 * @return EE_Validation_Error[]
1337
+	 */
1338
+	public function get_validation_errors_accumulated()
1339
+	{
1340
+		$validation_errors = $this->get_validation_errors();
1341
+		foreach ($this->get_validatable_subsections() as $subsection) {
1342
+			if ($subsection instanceof EE_Form_Section_Proper) {
1343
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1344
+			} else {
1345
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1346
+			}
1347
+			if ($validation_errors_on_this_subsection) {
1348
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1349
+			}
1350
+		}
1351
+		return $validation_errors;
1352
+	}
1353
+
1354
+
1355
+
1356
+	/**
1357
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1358
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1359
+	 * dot-dot-slash (../) means to ascend into the parent section.
1360
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1361
+	 * which will be returned.
1362
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1363
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1364
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1365
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1366
+	 * Etc
1367
+	 *
1368
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1369
+	 * @return EE_Form_Section_Base
1370
+	 */
1371
+	public function find_section_from_path($form_section_path)
1372
+	{
1373
+		//check if we can find the input from purely going straight up the tree
1374
+		$input = parent::find_section_from_path($form_section_path);
1375
+		if ($input instanceof EE_Form_Section_Base) {
1376
+			return $input;
1377
+		}
1378
+		$next_slash_pos = strpos($form_section_path, '/');
1379
+		if ($next_slash_pos !== false) {
1380
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1381
+			$subpath = substr($form_section_path, $next_slash_pos + 1);
1382
+		} else {
1383
+			$child_section_name = $form_section_path;
1384
+			$subpath = '';
1385
+		}
1386
+		$child_section = $this->get_subsection($child_section_name);
1387
+		if ($child_section instanceof EE_Form_Section_Base) {
1388
+			return $child_section->find_section_from_path($subpath);
1389
+		} else {
1390
+			return null;
1391
+		}
1392
+	}
1393 1393
 
1394 1394
 }
1395 1395
 
Please login to merge, or discard this patch.
admin_pages/transactions/Transactions_Admin_Page.core.php 2 patches
Indentation   +1963 added lines, -1963 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
 /**
@@ -27,1971 +27,1971 @@  discard block
 block discarded – undo
27 27
 class Transactions_Admin_Page extends EE_Admin_Page
28 28
 {
29 29
 
30
-    /**
31
-     * @var EE_Transaction
32
-     */
33
-    private $_transaction;
34
-
35
-    /**
36
-     * @var EE_Session
37
-     */
38
-    private $_session;
39
-
40
-    /**
41
-     * @var array $_txn_status
42
-     */
43
-    private static $_txn_status;
44
-
45
-    /**
46
-     * @var array $_pay_status
47
-     */
48
-    private static $_pay_status;
49
-
50
-    /**
51
-     * @var array $_existing_reg_payment_REG_IDs
52
-     */
53
-    protected $_existing_reg_payment_REG_IDs = null;
54
-
55
-
56
-    /**
57
-     * @Constructor
58
-     * @access public
59
-     *
60
-     * @param bool $routing
61
-     *
62
-     * @return Transactions_Admin_Page
63
-     */
64
-    public function __construct($routing = true)
65
-    {
66
-        parent::__construct($routing);
67
-    }
68
-
69
-
70
-    /**
71
-     *    _init_page_props
72
-     * @return void
73
-     */
74
-    protected function _init_page_props()
75
-    {
76
-        $this->page_slug        = TXN_PG_SLUG;
77
-        $this->page_label       = esc_html__('Transactions', 'event_espresso');
78
-        $this->_admin_base_url  = TXN_ADMIN_URL;
79
-        $this->_admin_base_path = TXN_ADMIN;
80
-    }
81
-
82
-
83
-    /**
84
-     *    _ajax_hooks
85
-     * @return void
86
-     */
87
-    protected function _ajax_hooks()
88
-    {
89
-        add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
90
-        add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
91
-        add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
92
-    }
93
-
94
-
95
-    /**
96
-     *    _define_page_props
97
-     * @return void
98
-     */
99
-    protected function _define_page_props()
100
-    {
101
-        $this->_admin_page_title = $this->page_label;
102
-        $this->_labels           = array(
103
-            'buttons' => array(
104
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
105
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
106
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
107
-            )
108
-        );
109
-    }
110
-
111
-
112
-    /**
113
-     *        grab url requests and route them
114
-     * @access private
115
-     * @return void
116
-     */
117
-    public function _set_page_routes()
118
-    {
119
-
120
-        $this->_set_transaction_status_array();
121
-
122
-        $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0;
123
-
124
-        $this->_page_routes = array(
125
-
126
-            'default' => array(
127
-                'func'       => '_transactions_overview_list_table',
128
-                'capability' => 'ee_read_transactions'
129
-            ),
130
-
131
-            'view_transaction' => array(
132
-                'func'       => '_transaction_details',
133
-                'capability' => 'ee_read_transaction',
134
-                'obj_id'     => $txn_id
135
-            ),
136
-
137
-            'send_payment_reminder' => array(
138
-                'func'       => '_send_payment_reminder',
139
-                'noheader'   => true,
140
-                'capability' => 'ee_send_message'
141
-            ),
142
-
143
-            'espresso_apply_payment' => array(
144
-                'func'       => 'apply_payments_or_refunds',
145
-                'noheader'   => true,
146
-                'capability' => 'ee_edit_payments'
147
-            ),
148
-
149
-            'espresso_apply_refund' => array(
150
-                'func'       => 'apply_payments_or_refunds',
151
-                'noheader'   => true,
152
-                'capability' => 'ee_edit_payments'
153
-            ),
154
-
155
-            'espresso_delete_payment' => array(
156
-                'func'       => 'delete_payment',
157
-                'noheader'   => true,
158
-                'capability' => 'ee_delete_payments'
159
-            ),
160
-
161
-        );
162
-
163
-    }
164
-
165
-
166
-    protected function _set_page_config()
167
-    {
168
-        $this->_page_config = array(
169
-            'default'          => array(
170
-                'nav'           => array(
171
-                    'label' => esc_html__('Overview', 'event_espresso'),
172
-                    'order' => 10
173
-                ),
174
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
175
-                'help_tabs'     => array(
176
-                    'transactions_overview_help_tab'                       => array(
177
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
178
-                        'filename' => 'transactions_overview'
179
-                    ),
180
-                    'transactions_overview_table_column_headings_help_tab' => array(
181
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
182
-                        'filename' => 'transactions_overview_table_column_headings'
183
-                    ),
184
-                    'transactions_overview_views_filters_help_tab'         => array(
185
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
186
-                        'filename' => 'transactions_overview_views_filters_search'
187
-                    ),
188
-                ),
189
-                'help_tour'     => array('Transactions_Overview_Help_Tour'),
190
-                /**
191
-                 * commented out because currently we are not displaying tips for transaction list table status but this
192
-                 * may change in a later iteration so want to keep the code for then.
193
-                 */
194
-                //'qtips' => array( 'Transactions_List_Table_Tips' ),
195
-                'require_nonce' => false
196
-            ),
197
-            'view_transaction' => array(
198
-                'nav'       => array(
199
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
200
-                    'order'      => 5,
201
-                    'url'        => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']),
202
-                        $this->_current_page_view_url) : $this->_admin_base_url,
203
-                    'persistent' => false
204
-                ),
205
-                'help_tabs' => array(
206
-                    'transactions_view_transaction_help_tab'                                              => array(
207
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
208
-                        'filename' => 'transactions_view_transaction'
209
-                    ),
210
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
211
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
212
-                        'filename' => 'transactions_view_transaction_transaction_details_table'
213
-                    ),
214
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => array(
215
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
216
-                        'filename' => 'transactions_view_transaction_attendees_registered'
217
-                    ),
218
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
219
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
220
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information'
221
-                    ),
222
-                ),
223
-                'qtips'     => array('Transaction_Details_Tips'),
224
-                'help_tour' => array('Transaction_Details_Help_Tour'),
225
-                'metaboxes' => array('_transaction_details_metaboxes'),
226
-
227
-                'require_nonce' => false
228
-            )
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * The below methods aren't used by this class currently
235
-     */
236
-    protected function _add_screen_options()
237
-    {
238
-    }
239
-
240
-    protected function _add_feature_pointers()
241
-    {
242
-    }
243
-
244
-    public function admin_init()
245
-    {
246
-        // IF a registration was JUST added via the admin...
247
-        if (
248
-        isset(
249
-            $this->_req_data['redirect_from'],
250
-            $this->_req_data['EVT_ID'],
251
-            $this->_req_data['event_name']
252
-        )
253
-        ) {
254
-            // then set a cookie so that we can block any attempts to use
255
-            // the back button as a way to enter another registration.
256
-            setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/');
257
-            // and update the global
258
-            $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
259
-        }
260
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
261
-            'event_espresso');
262
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__('An error occurred! Please refresh the page and try again.',
263
-            'event_espresso');
264
-        EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
265
-        EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
266
-        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
267
-        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__('This transaction has been overpaid ! Payments Total',
268
-            'event_espresso');
269
-    }
270
-
271
-    public function admin_notices()
272
-    {
273
-    }
274
-
275
-    public function admin_footer_scripts()
276
-    {
277
-    }
278
-
279
-
280
-    /**
281
-     * _set_transaction_status_array
282
-     * sets list of transaction statuses
283
-     *
284
-     * @access private
285
-     * @return void
286
-     */
287
-    private function _set_transaction_status_array()
288
-    {
289
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
290
-    }
291
-
292
-
293
-    /**
294
-     * get_transaction_status_array
295
-     * return the transaction status array for wp_list_table
296
-     *
297
-     * @access public
298
-     * @return array
299
-     */
300
-    public function get_transaction_status_array()
301
-    {
302
-        return self::$_txn_status;
303
-    }
304
-
305
-
306
-    /**
307
-     *    get list of payment statuses
308
-     *
309
-     * @access private
310
-     * @return void
311
-     */
312
-    private function _get_payment_status_array()
313
-    {
314
-        self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
315
-        $this->_template_args['payment_status'] = self::$_pay_status;
316
-
317
-    }
318
-
319
-
320
-    /**
321
-     *    _add_screen_options_default
322
-     *
323
-     * @access protected
324
-     * @return void
325
-     */
326
-    protected function _add_screen_options_default()
327
-    {
328
-        $this->_per_page_screen_option();
329
-    }
330
-
331
-
332
-    /**
333
-     * load_scripts_styles
334
-     *
335
-     * @access public
336
-     * @return void
337
-     */
338
-    public function load_scripts_styles()
339
-    {
340
-        //enqueue style
341
-        wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(),
342
-            EVENT_ESPRESSO_VERSION);
343
-        wp_enqueue_style('espresso_txn');
344
-        //scripts
345
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
346
-            'ee_admin_js',
347
-            'ee-datepicker',
348
-            'jquery-ui-datepicker',
349
-            'jquery-ui-draggable',
350
-            'ee-dialog',
351
-            'ee-accounting',
352
-            'ee-serialize-full-array'
353
-        ), EVENT_ESPRESSO_VERSION, true);
354
-        wp_enqueue_script('espresso_txn');
355
-
356
-    }
357
-
358
-
359
-    /**
360
-     *    load_scripts_styles_view_transaction
361
-     *
362
-     * @access public
363
-     * @return void
364
-     */
365
-    public function load_scripts_styles_view_transaction()
366
-    {
367
-        //styles
368
-        wp_enqueue_style('espresso-ui-theme');
369
-    }
370
-
371
-
372
-    /**
373
-     *    load_scripts_styles_default
374
-     *
375
-     * @access public
376
-     * @return void
377
-     */
378
-    public function load_scripts_styles_default()
379
-    {
380
-        //styles
381
-        wp_enqueue_style('espresso-ui-theme');
382
-    }
383
-
384
-
385
-    /**
386
-     *    _set_list_table_views_default
387
-     *
388
-     * @access protected
389
-     * @return void
390
-     */
391
-    protected function _set_list_table_views_default()
392
-    {
393
-        $this->_views = array(
394
-            'all'       => array(
395
-                'slug'  => 'all',
396
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
397
-                'count' => 0
398
-            ),
399
-            'abandoned' => array(
400
-                'slug'  => 'abandoned',
401
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
402
-                'count' => 0
403
-            ),
404
-            'failed'    => array(
405
-                'slug'  => 'failed',
406
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
407
-                'count' => 0
408
-            )
409
-        );
410
-    }
411
-
412
-
413
-    /**
414
-     * _set_transaction_object
415
-     * This sets the _transaction property for the transaction details screen
416
-     *
417
-     * @access private
418
-     * @return void
419
-     */
420
-    private function _set_transaction_object()
421
-    {
422
-        if (is_object($this->_transaction)) {
423
-            return;
424
-        } //get out we've already set the object
425
-
426
-        $TXN = EEM_Transaction::instance();
427
-
428
-        $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
429
-
430
-        //get transaction object
431
-        $this->_transaction = $TXN->get_one_by_ID($TXN_ID);
432
-        $this->_session     = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null;
433
-        $this->_transaction->verify_abandoned_transaction_status();
434
-
435
-        if (empty($this->_transaction)) {
436
-            $error_msg = esc_html__('An error occurred and the details for Transaction ID #',
437
-                    'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso');
438
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
439
-        }
440
-    }
441
-
442
-
443
-    /**
444
-     *    _transaction_legend_items
445
-     *
446
-     * @access protected
447
-     * @return array
448
-     */
449
-    protected function _transaction_legend_items()
450
-    {
451
-        EE_Registry::instance()->load_helper('MSG_Template');
452
-        $items = array();
453
-
454
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
455
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
456
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
457
-                $items['view_related_messages'] = array(
458
-                    'class' => $related_for_icon['css_class'],
459
-                    'desc'  => $related_for_icon['label'],
460
-                );
461
-            }
462
-        }
463
-
464
-        $items = apply_filters(
465
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
466
-            array_merge($items,
467
-                array(
468
-                    'view_details'      => array(
469
-                        'class' => 'dashicons dashicons-cart',
470
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso')
471
-                    ),
472
-                    'view_invoice'      => array(
473
-                        'class' => 'dashicons dashicons-media-spreadsheet',
474
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso')
475
-                    ),
476
-                    'view_receipt'      => array(
477
-                        'class' => 'dashicons dashicons-media-default',
478
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso')
479
-                    ),
480
-                    'view_registration' => array(
481
-                        'class' => 'dashicons dashicons-clipboard',
482
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso')
483
-                    )
484
-                )
485
-            )
486
-        );
487
-
488
-        if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
489
-            'espresso_transactions_send_payment_reminder')
490
-        ) {
491
-            if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
492
-                $items['send_payment_reminder'] = array(
493
-                    'class' => 'dashicons dashicons-email-alt',
494
-                    'desc'  => esc_html__('Send Payment Reminder', 'event_espresso')
495
-                );
496
-            } else {
497
-                $items['blank*'] = array(
498
-                    'class' => '',
499
-                    'desc'  => ''
500
-                );
501
-            }
502
-        } else {
503
-            $items['blank*'] = array(
504
-                'class' => '',
505
-                'desc'  => ''
506
-            );
507
-        }
508
-        $more_items = apply_filters(
509
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
510
-            array(
511
-                'overpaid'   => array(
512
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
513
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence')
514
-                ),
515
-                'complete'   => array(
516
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
517
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence')
518
-                ),
519
-                'incomplete' => array(
520
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
521
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence')
522
-                ),
523
-                'abandoned'  => array(
524
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
525
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence')
526
-                ),
527
-                'failed'     => array(
528
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
529
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence')
530
-                )
531
-            )
532
-        );
533
-
534
-        return array_merge($items, $more_items);
535
-    }
536
-
537
-
538
-    /**
539
-     *    _transactions_overview_list_table
540
-     *
541
-     * @access protected
542
-     * @return void
543
-     */
544
-    protected function _transactions_overview_list_table()
545
-    {
546
-        $this->_admin_page_title                   = esc_html__('Transactions', 'event_espresso');
547
-        $event                                     = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null;
548
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s',
549
-            'event_espresso'), '<h3>',
550
-            '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
551
-                EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event',
552
-                'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : '';
553
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
554
-        $this->display_admin_list_table_page_with_no_sidebar();
555
-    }
556
-
557
-
558
-    /**
559
-     *    _transaction_details
560
-     * generates HTML for the View Transaction Details Admin page
561
-     *
562
-     * @access protected
563
-     * @return void
564
-     */
565
-    protected function _transaction_details()
566
-    {
567
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
568
-
569
-        $this->_set_transaction_status_array();
570
-
571
-        $this->_template_args                      = array();
572
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
573
-
574
-        $this->_set_transaction_object();
575
-
576
-        $primary_registration = $this->_transaction->primary_registration();
577
-        $attendee             = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null;
578
-
579
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
580
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
581
-
582
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
583
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
584
-
585
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
586
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
587
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
588
-
589
-        $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
590
-        $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
591
-
592
-        if (
593
-            $attendee instanceof EE_Attendee
594
-            && EE_Registry::instance()->CAP->current_user_can(
595
-                'ee_send_message',
596
-                'espresso_transactions_send_payment_reminder'
597
-            )
598
-        ) {
599
-            $this->_template_args['send_payment_reminder_button'] =
600
-                EEH_MSG_Template::is_mt_active('payment_reminder')
601
-                && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code
602
-                && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code
603
-                    ? EEH_Template::get_button_or_link(
604
-                    EE_Admin_Page::add_query_args_and_nonce(
605
-                        array(
606
-                            'action'      => 'send_payment_reminder',
607
-                            'TXN_ID'      => $this->_transaction->ID(),
608
-                            'redirect_to' => 'view_transaction'
609
-                        ),
610
-                        TXN_ADMIN_URL
611
-                    ),
612
-                    __(' Send Payment Reminder', 'event_espresso'),
613
-                    'button secondary-button right',
614
-                    'dashicons dashicons-email-alt'
615
-                )
616
-                    : '';
617
-        } else {
618
-            $this->_template_args['send_payment_reminder_button'] = '';
619
-        }
620
-
621
-        $amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
622
-        $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true);
623
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
624
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
625
-        } else {
626
-            $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
627
-        }
628
-        $this->_template_args['amount_due_class'] = '';
629
-
630
-        if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
631
-            // paid in full
632
-            $this->_template_args['amount_due'] = false;
633
-        } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
634
-            // overpaid
635
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
636
-        } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) {
637
-            // monies owing
638
-            $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
639
-        } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) {
640
-            // no payments made yet
641
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
642
-        } elseif ($this->_transaction->get('TXN_total') == 0) {
643
-            // free event
644
-            $this->_template_args['amount_due'] = false;
645
-        }
646
-
647
-        $payment_method = $this->_transaction->payment_method();
648
-
649
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
650
-            ? $payment_method->admin_name()
651
-            : esc_html__('Unknown', 'event_espresso');
652
-
653
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
654
-        // link back to overview
655
-        $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER'])
656
-            ? $_SERVER['HTTP_REFERER']
657
-            : TXN_ADMIN_URL;
658
-
659
-
660
-        // next link
661
-        $next_txn                                 = $this->_transaction->next(
662
-            null,
663
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
664
-            'TXN_ID'
665
-        );
666
-        $this->_template_args['next_transaction'] = $next_txn
667
-            ? $this->_next_link(
668
-                EE_Admin_Page::add_query_args_and_nonce(
669
-                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
670
-                    TXN_ADMIN_URL
671
-                ),
672
-                'dashicons dashicons-arrow-right ee-icon-size-22'
673
-            )
674
-            : '';
675
-        // previous link
676
-        $previous_txn                                 = $this->_transaction->previous(
677
-            null,
678
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
679
-            'TXN_ID'
680
-        );
681
-        $this->_template_args['previous_transaction'] = $previous_txn
682
-            ? $this->_previous_link(
683
-                EE_Admin_Page::add_query_args_and_nonce(
684
-                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
685
-                    TXN_ADMIN_URL
686
-                ),
687
-                'dashicons dashicons-arrow-left ee-icon-size-22'
688
-            )
689
-            : '';
690
-
691
-        // were we just redirected here after adding a new registration ???
692
-        if (
693
-        isset(
694
-            $this->_req_data['redirect_from'],
695
-            $this->_req_data['EVT_ID'],
696
-            $this->_req_data['event_name']
697
-        )
698
-        ) {
699
-            if (
700
-            EE_Registry::instance()->CAP->current_user_can(
701
-                'ee_edit_registrations',
702
-                'espresso_registrations_new_registration',
703
-                $this->_req_data['EVT_ID']
704
-            )
705
-            ) {
706
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
707
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
708
-                    array(
709
-                        'page'     => 'espresso_registrations',
710
-                        'action'   => 'new_registration',
711
-                        'return'   => 'default',
712
-                        'TXN_ID'   => $this->_transaction->ID(),
713
-                        'event_id' => $this->_req_data['EVT_ID'],
714
-                    ),
715
-                    REG_ADMIN_URL
716
-                );
717
-                $this->_admin_page_title .= '">';
718
-
719
-                $this->_admin_page_title .= sprintf(
720
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
721
-                    htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
722
-                );
723
-                $this->_admin_page_title .= '</a>';
724
-            }
725
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
726
-        }
727
-        // grab messages at the last second
728
-        $this->_template_args['notices'] = EE_Error::get_notices();
729
-        // path to template
730
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
731
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
732
-            $this->_template_args, true);
733
-
734
-        // the details template wrapper
735
-        $this->display_admin_page_with_sidebar();
736
-
737
-    }
738
-
739
-
740
-    /**
741
-     *        _transaction_details_metaboxes
742
-     *
743
-     * @access protected
744
-     * @return void
745
-     */
746
-    protected function _transaction_details_metaboxes()
747
-    {
748
-
749
-        $this->_set_transaction_object();
750
-
751
-        add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'),
752
-            array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high');
753
-        add_meta_box(
754
-            'edit-txn-attendees-mbox',
755
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
756
-            array($this, 'txn_attendees_meta_box'),
757
-            $this->_wp_page_slug,
758
-            'normal',
759
-            'high',
760
-            array('TXN_ID' => $this->_transaction->ID())
761
-        );
762
-        add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'),
763
-            array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
764
-        add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'),
765
-            array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
766
-
767
-    }
768
-
769
-
770
-    /**
771
-     * txn_details_meta_box
772
-     * generates HTML for the Transaction main meta box
773
-     *
774
-     * @access public
775
-     * @return void
776
-     */
777
-    public function txn_details_meta_box()
778
-    {
779
-
780
-        $this->_set_transaction_object();
781
-        $this->_template_args['TXN_ID']   = $this->_transaction->ID();
782
-        $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null;
783
-
784
-        //get line table
785
-        EEH_Autoloader::register_line_item_display_autoloaders();
786
-        $Line_Item_Display                       = new EE_Line_Item_Display('admin_table',
787
-            'EE_Admin_Table_Line_Item_Display_Strategy');
788
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item());
789
-        $this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')->get('REG_code');
790
-
791
-        // process taxes
792
-        $taxes                         = $this->_transaction->get_many_related('Line_Item',
793
-            array(array('LIN_type' => EEM_Line_Item::type_tax)));
794
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
795
-
796
-        $this->_template_args['grand_total']     = EEH_Template::format_currency($this->_transaction->get('TXN_total'),
797
-            false, false);
798
-        $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
799
-        $this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
30
+	/**
31
+	 * @var EE_Transaction
32
+	 */
33
+	private $_transaction;
34
+
35
+	/**
36
+	 * @var EE_Session
37
+	 */
38
+	private $_session;
39
+
40
+	/**
41
+	 * @var array $_txn_status
42
+	 */
43
+	private static $_txn_status;
44
+
45
+	/**
46
+	 * @var array $_pay_status
47
+	 */
48
+	private static $_pay_status;
49
+
50
+	/**
51
+	 * @var array $_existing_reg_payment_REG_IDs
52
+	 */
53
+	protected $_existing_reg_payment_REG_IDs = null;
54
+
55
+
56
+	/**
57
+	 * @Constructor
58
+	 * @access public
59
+	 *
60
+	 * @param bool $routing
61
+	 *
62
+	 * @return Transactions_Admin_Page
63
+	 */
64
+	public function __construct($routing = true)
65
+	{
66
+		parent::__construct($routing);
67
+	}
68
+
69
+
70
+	/**
71
+	 *    _init_page_props
72
+	 * @return void
73
+	 */
74
+	protected function _init_page_props()
75
+	{
76
+		$this->page_slug        = TXN_PG_SLUG;
77
+		$this->page_label       = esc_html__('Transactions', 'event_espresso');
78
+		$this->_admin_base_url  = TXN_ADMIN_URL;
79
+		$this->_admin_base_path = TXN_ADMIN;
80
+	}
81
+
82
+
83
+	/**
84
+	 *    _ajax_hooks
85
+	 * @return void
86
+	 */
87
+	protected function _ajax_hooks()
88
+	{
89
+		add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
90
+		add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
91
+		add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
92
+	}
93
+
94
+
95
+	/**
96
+	 *    _define_page_props
97
+	 * @return void
98
+	 */
99
+	protected function _define_page_props()
100
+	{
101
+		$this->_admin_page_title = $this->page_label;
102
+		$this->_labels           = array(
103
+			'buttons' => array(
104
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
105
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
106
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
107
+			)
108
+		);
109
+	}
110
+
111
+
112
+	/**
113
+	 *        grab url requests and route them
114
+	 * @access private
115
+	 * @return void
116
+	 */
117
+	public function _set_page_routes()
118
+	{
119
+
120
+		$this->_set_transaction_status_array();
121
+
122
+		$txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0;
123
+
124
+		$this->_page_routes = array(
125
+
126
+			'default' => array(
127
+				'func'       => '_transactions_overview_list_table',
128
+				'capability' => 'ee_read_transactions'
129
+			),
130
+
131
+			'view_transaction' => array(
132
+				'func'       => '_transaction_details',
133
+				'capability' => 'ee_read_transaction',
134
+				'obj_id'     => $txn_id
135
+			),
136
+
137
+			'send_payment_reminder' => array(
138
+				'func'       => '_send_payment_reminder',
139
+				'noheader'   => true,
140
+				'capability' => 'ee_send_message'
141
+			),
142
+
143
+			'espresso_apply_payment' => array(
144
+				'func'       => 'apply_payments_or_refunds',
145
+				'noheader'   => true,
146
+				'capability' => 'ee_edit_payments'
147
+			),
148
+
149
+			'espresso_apply_refund' => array(
150
+				'func'       => 'apply_payments_or_refunds',
151
+				'noheader'   => true,
152
+				'capability' => 'ee_edit_payments'
153
+			),
154
+
155
+			'espresso_delete_payment' => array(
156
+				'func'       => 'delete_payment',
157
+				'noheader'   => true,
158
+				'capability' => 'ee_delete_payments'
159
+			),
160
+
161
+		);
162
+
163
+	}
164
+
165
+
166
+	protected function _set_page_config()
167
+	{
168
+		$this->_page_config = array(
169
+			'default'          => array(
170
+				'nav'           => array(
171
+					'label' => esc_html__('Overview', 'event_espresso'),
172
+					'order' => 10
173
+				),
174
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
175
+				'help_tabs'     => array(
176
+					'transactions_overview_help_tab'                       => array(
177
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
178
+						'filename' => 'transactions_overview'
179
+					),
180
+					'transactions_overview_table_column_headings_help_tab' => array(
181
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
182
+						'filename' => 'transactions_overview_table_column_headings'
183
+					),
184
+					'transactions_overview_views_filters_help_tab'         => array(
185
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
186
+						'filename' => 'transactions_overview_views_filters_search'
187
+					),
188
+				),
189
+				'help_tour'     => array('Transactions_Overview_Help_Tour'),
190
+				/**
191
+				 * commented out because currently we are not displaying tips for transaction list table status but this
192
+				 * may change in a later iteration so want to keep the code for then.
193
+				 */
194
+				//'qtips' => array( 'Transactions_List_Table_Tips' ),
195
+				'require_nonce' => false
196
+			),
197
+			'view_transaction' => array(
198
+				'nav'       => array(
199
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
200
+					'order'      => 5,
201
+					'url'        => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']),
202
+						$this->_current_page_view_url) : $this->_admin_base_url,
203
+					'persistent' => false
204
+				),
205
+				'help_tabs' => array(
206
+					'transactions_view_transaction_help_tab'                                              => array(
207
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
208
+						'filename' => 'transactions_view_transaction'
209
+					),
210
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
211
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
212
+						'filename' => 'transactions_view_transaction_transaction_details_table'
213
+					),
214
+					'transactions_view_transaction_attendees_registered_help_tab'                         => array(
215
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
216
+						'filename' => 'transactions_view_transaction_attendees_registered'
217
+					),
218
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
219
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
220
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information'
221
+					),
222
+				),
223
+				'qtips'     => array('Transaction_Details_Tips'),
224
+				'help_tour' => array('Transaction_Details_Help_Tour'),
225
+				'metaboxes' => array('_transaction_details_metaboxes'),
226
+
227
+				'require_nonce' => false
228
+			)
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * The below methods aren't used by this class currently
235
+	 */
236
+	protected function _add_screen_options()
237
+	{
238
+	}
239
+
240
+	protected function _add_feature_pointers()
241
+	{
242
+	}
243
+
244
+	public function admin_init()
245
+	{
246
+		// IF a registration was JUST added via the admin...
247
+		if (
248
+		isset(
249
+			$this->_req_data['redirect_from'],
250
+			$this->_req_data['EVT_ID'],
251
+			$this->_req_data['event_name']
252
+		)
253
+		) {
254
+			// then set a cookie so that we can block any attempts to use
255
+			// the back button as a way to enter another registration.
256
+			setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/');
257
+			// and update the global
258
+			$_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
259
+		}
260
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
261
+			'event_espresso');
262
+		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__('An error occurred! Please refresh the page and try again.',
263
+			'event_espresso');
264
+		EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
265
+		EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
266
+		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
267
+		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__('This transaction has been overpaid ! Payments Total',
268
+			'event_espresso');
269
+	}
270
+
271
+	public function admin_notices()
272
+	{
273
+	}
274
+
275
+	public function admin_footer_scripts()
276
+	{
277
+	}
278
+
279
+
280
+	/**
281
+	 * _set_transaction_status_array
282
+	 * sets list of transaction statuses
283
+	 *
284
+	 * @access private
285
+	 * @return void
286
+	 */
287
+	private function _set_transaction_status_array()
288
+	{
289
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
290
+	}
291
+
292
+
293
+	/**
294
+	 * get_transaction_status_array
295
+	 * return the transaction status array for wp_list_table
296
+	 *
297
+	 * @access public
298
+	 * @return array
299
+	 */
300
+	public function get_transaction_status_array()
301
+	{
302
+		return self::$_txn_status;
303
+	}
304
+
305
+
306
+	/**
307
+	 *    get list of payment statuses
308
+	 *
309
+	 * @access private
310
+	 * @return void
311
+	 */
312
+	private function _get_payment_status_array()
313
+	{
314
+		self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
315
+		$this->_template_args['payment_status'] = self::$_pay_status;
316
+
317
+	}
318
+
319
+
320
+	/**
321
+	 *    _add_screen_options_default
322
+	 *
323
+	 * @access protected
324
+	 * @return void
325
+	 */
326
+	protected function _add_screen_options_default()
327
+	{
328
+		$this->_per_page_screen_option();
329
+	}
330
+
331
+
332
+	/**
333
+	 * load_scripts_styles
334
+	 *
335
+	 * @access public
336
+	 * @return void
337
+	 */
338
+	public function load_scripts_styles()
339
+	{
340
+		//enqueue style
341
+		wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(),
342
+			EVENT_ESPRESSO_VERSION);
343
+		wp_enqueue_style('espresso_txn');
344
+		//scripts
345
+		wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
346
+			'ee_admin_js',
347
+			'ee-datepicker',
348
+			'jquery-ui-datepicker',
349
+			'jquery-ui-draggable',
350
+			'ee-dialog',
351
+			'ee-accounting',
352
+			'ee-serialize-full-array'
353
+		), EVENT_ESPRESSO_VERSION, true);
354
+		wp_enqueue_script('espresso_txn');
355
+
356
+	}
357
+
358
+
359
+	/**
360
+	 *    load_scripts_styles_view_transaction
361
+	 *
362
+	 * @access public
363
+	 * @return void
364
+	 */
365
+	public function load_scripts_styles_view_transaction()
366
+	{
367
+		//styles
368
+		wp_enqueue_style('espresso-ui-theme');
369
+	}
370
+
371
+
372
+	/**
373
+	 *    load_scripts_styles_default
374
+	 *
375
+	 * @access public
376
+	 * @return void
377
+	 */
378
+	public function load_scripts_styles_default()
379
+	{
380
+		//styles
381
+		wp_enqueue_style('espresso-ui-theme');
382
+	}
383
+
384
+
385
+	/**
386
+	 *    _set_list_table_views_default
387
+	 *
388
+	 * @access protected
389
+	 * @return void
390
+	 */
391
+	protected function _set_list_table_views_default()
392
+	{
393
+		$this->_views = array(
394
+			'all'       => array(
395
+				'slug'  => 'all',
396
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
397
+				'count' => 0
398
+			),
399
+			'abandoned' => array(
400
+				'slug'  => 'abandoned',
401
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
402
+				'count' => 0
403
+			),
404
+			'failed'    => array(
405
+				'slug'  => 'failed',
406
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
407
+				'count' => 0
408
+			)
409
+		);
410
+	}
411
+
412
+
413
+	/**
414
+	 * _set_transaction_object
415
+	 * This sets the _transaction property for the transaction details screen
416
+	 *
417
+	 * @access private
418
+	 * @return void
419
+	 */
420
+	private function _set_transaction_object()
421
+	{
422
+		if (is_object($this->_transaction)) {
423
+			return;
424
+		} //get out we've already set the object
425
+
426
+		$TXN = EEM_Transaction::instance();
427
+
428
+		$TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
429
+
430
+		//get transaction object
431
+		$this->_transaction = $TXN->get_one_by_ID($TXN_ID);
432
+		$this->_session     = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null;
433
+		$this->_transaction->verify_abandoned_transaction_status();
434
+
435
+		if (empty($this->_transaction)) {
436
+			$error_msg = esc_html__('An error occurred and the details for Transaction ID #',
437
+					'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso');
438
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
439
+		}
440
+	}
441
+
442
+
443
+	/**
444
+	 *    _transaction_legend_items
445
+	 *
446
+	 * @access protected
447
+	 * @return array
448
+	 */
449
+	protected function _transaction_legend_items()
450
+	{
451
+		EE_Registry::instance()->load_helper('MSG_Template');
452
+		$items = array();
453
+
454
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
455
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
456
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
457
+				$items['view_related_messages'] = array(
458
+					'class' => $related_for_icon['css_class'],
459
+					'desc'  => $related_for_icon['label'],
460
+				);
461
+			}
462
+		}
463
+
464
+		$items = apply_filters(
465
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
466
+			array_merge($items,
467
+				array(
468
+					'view_details'      => array(
469
+						'class' => 'dashicons dashicons-cart',
470
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso')
471
+					),
472
+					'view_invoice'      => array(
473
+						'class' => 'dashicons dashicons-media-spreadsheet',
474
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso')
475
+					),
476
+					'view_receipt'      => array(
477
+						'class' => 'dashicons dashicons-media-default',
478
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso')
479
+					),
480
+					'view_registration' => array(
481
+						'class' => 'dashicons dashicons-clipboard',
482
+						'desc'  => esc_html__('View Registration Details', 'event_espresso')
483
+					)
484
+				)
485
+			)
486
+		);
487
+
488
+		if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
489
+			'espresso_transactions_send_payment_reminder')
490
+		) {
491
+			if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
492
+				$items['send_payment_reminder'] = array(
493
+					'class' => 'dashicons dashicons-email-alt',
494
+					'desc'  => esc_html__('Send Payment Reminder', 'event_espresso')
495
+				);
496
+			} else {
497
+				$items['blank*'] = array(
498
+					'class' => '',
499
+					'desc'  => ''
500
+				);
501
+			}
502
+		} else {
503
+			$items['blank*'] = array(
504
+				'class' => '',
505
+				'desc'  => ''
506
+			);
507
+		}
508
+		$more_items = apply_filters(
509
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
510
+			array(
511
+				'overpaid'   => array(
512
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
513
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence')
514
+				),
515
+				'complete'   => array(
516
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
517
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence')
518
+				),
519
+				'incomplete' => array(
520
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
521
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence')
522
+				),
523
+				'abandoned'  => array(
524
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
525
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence')
526
+				),
527
+				'failed'     => array(
528
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
529
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence')
530
+				)
531
+			)
532
+		);
533
+
534
+		return array_merge($items, $more_items);
535
+	}
536
+
537
+
538
+	/**
539
+	 *    _transactions_overview_list_table
540
+	 *
541
+	 * @access protected
542
+	 * @return void
543
+	 */
544
+	protected function _transactions_overview_list_table()
545
+	{
546
+		$this->_admin_page_title                   = esc_html__('Transactions', 'event_espresso');
547
+		$event                                     = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null;
548
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s',
549
+			'event_espresso'), '<h3>',
550
+			'<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
551
+				EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event',
552
+				'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : '';
553
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
554
+		$this->display_admin_list_table_page_with_no_sidebar();
555
+	}
556
+
557
+
558
+	/**
559
+	 *    _transaction_details
560
+	 * generates HTML for the View Transaction Details Admin page
561
+	 *
562
+	 * @access protected
563
+	 * @return void
564
+	 */
565
+	protected function _transaction_details()
566
+	{
567
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
568
+
569
+		$this->_set_transaction_status_array();
570
+
571
+		$this->_template_args                      = array();
572
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
573
+
574
+		$this->_set_transaction_object();
575
+
576
+		$primary_registration = $this->_transaction->primary_registration();
577
+		$attendee             = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null;
578
+
579
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
580
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
581
+
582
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
583
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
584
+
585
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
586
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
587
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
588
+
589
+		$this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
590
+		$this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
591
+
592
+		if (
593
+			$attendee instanceof EE_Attendee
594
+			&& EE_Registry::instance()->CAP->current_user_can(
595
+				'ee_send_message',
596
+				'espresso_transactions_send_payment_reminder'
597
+			)
598
+		) {
599
+			$this->_template_args['send_payment_reminder_button'] =
600
+				EEH_MSG_Template::is_mt_active('payment_reminder')
601
+				&& $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code
602
+				&& $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code
603
+					? EEH_Template::get_button_or_link(
604
+					EE_Admin_Page::add_query_args_and_nonce(
605
+						array(
606
+							'action'      => 'send_payment_reminder',
607
+							'TXN_ID'      => $this->_transaction->ID(),
608
+							'redirect_to' => 'view_transaction'
609
+						),
610
+						TXN_ADMIN_URL
611
+					),
612
+					__(' Send Payment Reminder', 'event_espresso'),
613
+					'button secondary-button right',
614
+					'dashicons dashicons-email-alt'
615
+				)
616
+					: '';
617
+		} else {
618
+			$this->_template_args['send_payment_reminder_button'] = '';
619
+		}
620
+
621
+		$amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
622
+		$this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true);
623
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
624
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
625
+		} else {
626
+			$this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
627
+		}
628
+		$this->_template_args['amount_due_class'] = '';
629
+
630
+		if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
631
+			// paid in full
632
+			$this->_template_args['amount_due'] = false;
633
+		} elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
634
+			// overpaid
635
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
636
+		} elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) {
637
+			// monies owing
638
+			$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
639
+		} elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) {
640
+			// no payments made yet
641
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
642
+		} elseif ($this->_transaction->get('TXN_total') == 0) {
643
+			// free event
644
+			$this->_template_args['amount_due'] = false;
645
+		}
646
+
647
+		$payment_method = $this->_transaction->payment_method();
648
+
649
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
650
+			? $payment_method->admin_name()
651
+			: esc_html__('Unknown', 'event_espresso');
652
+
653
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
654
+		// link back to overview
655
+		$this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER'])
656
+			? $_SERVER['HTTP_REFERER']
657
+			: TXN_ADMIN_URL;
658
+
659
+
660
+		// next link
661
+		$next_txn                                 = $this->_transaction->next(
662
+			null,
663
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
664
+			'TXN_ID'
665
+		);
666
+		$this->_template_args['next_transaction'] = $next_txn
667
+			? $this->_next_link(
668
+				EE_Admin_Page::add_query_args_and_nonce(
669
+					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
670
+					TXN_ADMIN_URL
671
+				),
672
+				'dashicons dashicons-arrow-right ee-icon-size-22'
673
+			)
674
+			: '';
675
+		// previous link
676
+		$previous_txn                                 = $this->_transaction->previous(
677
+			null,
678
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
679
+			'TXN_ID'
680
+		);
681
+		$this->_template_args['previous_transaction'] = $previous_txn
682
+			? $this->_previous_link(
683
+				EE_Admin_Page::add_query_args_and_nonce(
684
+					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
685
+					TXN_ADMIN_URL
686
+				),
687
+				'dashicons dashicons-arrow-left ee-icon-size-22'
688
+			)
689
+			: '';
690
+
691
+		// were we just redirected here after adding a new registration ???
692
+		if (
693
+		isset(
694
+			$this->_req_data['redirect_from'],
695
+			$this->_req_data['EVT_ID'],
696
+			$this->_req_data['event_name']
697
+		)
698
+		) {
699
+			if (
700
+			EE_Registry::instance()->CAP->current_user_can(
701
+				'ee_edit_registrations',
702
+				'espresso_registrations_new_registration',
703
+				$this->_req_data['EVT_ID']
704
+			)
705
+			) {
706
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
707
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
708
+					array(
709
+						'page'     => 'espresso_registrations',
710
+						'action'   => 'new_registration',
711
+						'return'   => 'default',
712
+						'TXN_ID'   => $this->_transaction->ID(),
713
+						'event_id' => $this->_req_data['EVT_ID'],
714
+					),
715
+					REG_ADMIN_URL
716
+				);
717
+				$this->_admin_page_title .= '">';
718
+
719
+				$this->_admin_page_title .= sprintf(
720
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
721
+					htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
722
+				);
723
+				$this->_admin_page_title .= '</a>';
724
+			}
725
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
726
+		}
727
+		// grab messages at the last second
728
+		$this->_template_args['notices'] = EE_Error::get_notices();
729
+		// path to template
730
+		$template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
731
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
732
+			$this->_template_args, true);
733
+
734
+		// the details template wrapper
735
+		$this->display_admin_page_with_sidebar();
736
+
737
+	}
738
+
739
+
740
+	/**
741
+	 *        _transaction_details_metaboxes
742
+	 *
743
+	 * @access protected
744
+	 * @return void
745
+	 */
746
+	protected function _transaction_details_metaboxes()
747
+	{
748
+
749
+		$this->_set_transaction_object();
750
+
751
+		add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'),
752
+			array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high');
753
+		add_meta_box(
754
+			'edit-txn-attendees-mbox',
755
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
756
+			array($this, 'txn_attendees_meta_box'),
757
+			$this->_wp_page_slug,
758
+			'normal',
759
+			'high',
760
+			array('TXN_ID' => $this->_transaction->ID())
761
+		);
762
+		add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'),
763
+			array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
764
+		add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'),
765
+			array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
766
+
767
+	}
768
+
769
+
770
+	/**
771
+	 * txn_details_meta_box
772
+	 * generates HTML for the Transaction main meta box
773
+	 *
774
+	 * @access public
775
+	 * @return void
776
+	 */
777
+	public function txn_details_meta_box()
778
+	{
779
+
780
+		$this->_set_transaction_object();
781
+		$this->_template_args['TXN_ID']   = $this->_transaction->ID();
782
+		$this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null;
783
+
784
+		//get line table
785
+		EEH_Autoloader::register_line_item_display_autoloaders();
786
+		$Line_Item_Display                       = new EE_Line_Item_Display('admin_table',
787
+			'EE_Admin_Table_Line_Item_Display_Strategy');
788
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item());
789
+		$this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')->get('REG_code');
790
+
791
+		// process taxes
792
+		$taxes                         = $this->_transaction->get_many_related('Line_Item',
793
+			array(array('LIN_type' => EEM_Line_Item::type_tax)));
794
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
795
+
796
+		$this->_template_args['grand_total']     = EEH_Template::format_currency($this->_transaction->get('TXN_total'),
797
+			false, false);
798
+		$this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
799
+		$this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
800 800
 
801 801
 //		$txn_status_class = 'status-' . $this->_transaction->get('STS_ID');
802 802
 
803
-        // process payment details
804
-        $payments = $this->_transaction->get_many_related('Payment');
805
-        if ( ! empty($payments)) {
806
-            $this->_template_args['payments']              = $payments;
807
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
808
-        } else {
809
-            $this->_template_args['payments']              = false;
810
-            $this->_template_args['existing_reg_payments'] = array();
811
-        }
812
-
813
-        $this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
814
-        $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'),
815
-            TXN_ADMIN_URL);
816
-
817
-        if (isset($txn_details['invoice_number'])) {
818
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
819
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number',
820
-                'event_espresso');
821
-        }
822
-
823
-        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session');
824
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session',
825
-            'event_espresso');
826
-
827
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '';
828
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP',
829
-            'event_espresso');
830
-
831
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '';
832
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent',
833
-            'event_espresso');
834
-
835
-        $reg_steps = '<ul>';
836
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
837
-            if ($reg_step_status === true) {
838
-                $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
839
-                        ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
840
-            } else if (is_numeric($reg_step_status) && $reg_step_status !== false) {
841
-                $reg_steps .= '<li style="color:#2EA2CC">' . sprintf(
842
-                        esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
843
-                        ucwords(str_replace('_', ' ', $reg_step)),
844
-                        date(get_option('date_format') . ' ' . get_option('time_format'),
845
-                            ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)))
846
-                    ) . '</li>';
847
-            } else {
848
-                $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated',
849
-                        'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
850
-            }
851
-        }
852
-        $reg_steps .= '</ul>';
853
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
854
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress',
855
-            'event_espresso');
856
-
857
-
858
-        $this->_get_registrations_to_apply_payment_to();
859
-        $this->_get_payment_methods($payments);
860
-        $this->_get_payment_status_array();
861
-        $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
862
-
863
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
864
-            'action'  => 'edit_transaction',
865
-            'process' => 'transaction'
866
-        ), TXN_ADMIN_URL);
867
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
868
-            'page'   => 'espresso_transactions',
869
-            'action' => 'espresso_apply_payment'
870
-        ), WP_AJAX_URL);
871
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(array(
872
-            'page'   => 'espresso_transactions',
873
-            'action' => 'espresso_delete_payment'
874
-        ), WP_AJAX_URL);
875
-
876
-        // 'espresso_delete_payment_nonce'
877
-
878
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
879
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
880
-
881
-    }
882
-
883
-
884
-    /**
885
-     * _get_registration_payment_IDs
886
-     *
887
-     *    generates an array of Payment IDs and their corresponding Registration IDs
888
-     *
889
-     * @access protected
890
-     *
891
-     * @param EE_Payment[] $payments
892
-     *
893
-     * @return array
894
-     */
895
-    protected function _get_registration_payment_IDs($payments = array())
896
-    {
897
-        $existing_reg_payments = array();
898
-        // get all reg payments for these payments
899
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(array(
900
-            array(
901
-                'PAY_ID' => array(
902
-                    'IN',
903
-                    array_keys($payments)
904
-                )
905
-            )
906
-        ));
907
-        if ( ! empty($reg_payments)) {
908
-            foreach ($payments as $payment) {
909
-                if ( ! $payment instanceof EE_Payment) {
910
-                    continue;
911
-                } else if ( ! isset($existing_reg_payments[$payment->ID()])) {
912
-                    $existing_reg_payments[$payment->ID()] = array();
913
-                }
914
-                foreach ($reg_payments as $reg_payment) {
915
-                    if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) {
916
-                        $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
917
-                    }
918
-                }
919
-            }
920
-        }
921
-
922
-        return $existing_reg_payments;
923
-    }
924
-
925
-
926
-    /**
927
-     * _get_registrations_to_apply_payment_to
928
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
929
-     * which allows the admin to only apply the payment to the specific registrations
930
-     *
931
-     * @access protected
932
-     * @return void
933
-     * @throws \EE_Error
934
-     */
935
-    protected function _get_registrations_to_apply_payment_to()
936
-    {
937
-        // we want any registration with an active status (ie: not deleted or cancelled)
938
-        $query_params                      = array(
939
-            array(
940
-                'STS_ID' => array(
941
-                    'IN',
942
-                    array(
943
-                        EEM_Registration::status_id_approved,
944
-                        EEM_Registration::status_id_pending_payment,
945
-                        EEM_Registration::status_id_not_approved,
946
-                    )
947
-                )
948
-            )
949
-        );
950
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
951
-                '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;'
952
-            );
953
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
954
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
955
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
956
-            EEH_HTML::tr(
957
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
958
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
959
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
960
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
961
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
962
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
963
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
964
-            )
965
-        );
966
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
967
-        // get registrations for TXN
968
-        $registrations = $this->_transaction->registrations($query_params);
969
-        foreach ($registrations as $registration) {
970
-            if ($registration instanceof EE_Registration) {
971
-                $attendee_name = $registration->attendee() instanceof EE_Attendee
972
-                    ? $registration->attendee()->full_name()
973
-                    : esc_html__('Unknown Attendee', 'event_espresso');
974
-                $owing         = $registration->final_price() - $registration->paid();
975
-                $taxable       = $registration->ticket()->taxable()
976
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
977
-                    : '';
978
-                $checked       = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
979
-                    ? ' checked="checked"'
980
-                    : '';
981
-                $disabled      = $registration->final_price() > 0 ? '' : ' disabled';
982
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
983
-                    EEH_HTML::td($registration->ID()) .
984
-                    EEH_HTML::td($attendee_name) .
985
-                    EEH_HTML::td(
986
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
987
-                    ) .
988
-                    EEH_HTML::td($registration->event_name()) .
989
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
990
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
991
-                    EEH_HTML::td(
992
-                        '<input type="checkbox" value="' . $registration->ID()
993
-                        . '" name="txn_admin_payment[registrations]"'
994
-                        . $checked . $disabled . '>',
995
-                        '', 'jst-cntr'
996
-                    ),
997
-                    'apply-payment-registration-row-' . $registration->ID()
998
-                );
999
-            }
1000
-        }
1001
-        $registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1002
-        $registrations_to_apply_payment_to .= EEH_HTML::tablex();
1003
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1004
-        $registrations_to_apply_payment_to .= EEH_HTML::p(
1005
-            esc_html__(
1006
-                'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1007
-                'event_espresso'
1008
-            ),
1009
-            '', 'clear description'
1010
-        );
1011
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1012
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * _get_reg_status_selection
1018
-     *
1019
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1020
-     *         instead of events.
1021
-     * @access protected
1022
-     * @return void
1023
-     */
1024
-    protected function _get_reg_status_selection()
1025
-    {
1026
-        //first get all possible statuses
1027
-        $statuses = EEM_Registration::reg_status_array(array(), true);
1028
-        //let's add a "don't change" option.
1029
-        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1030
-        $status_array                                        = array_merge($status_array, $statuses);
1031
-        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]',
1032
-            $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status');
1033
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]',
1034
-            $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status');
1035
-
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     *    _get_payment_methods
1041
-     * Gets all the payment methods available generally, or the ones that are already
1042
-     * selected on these payments (in case their payment methods are no longer active).
1043
-     * Has the side-effect of updating the template args' payment_methods item
1044
-     * @access private
1045
-     *
1046
-     * @param EE_Payment[] to show on this page
1047
-     *
1048
-     * @return void
1049
-     */
1050
-    private function _get_payment_methods($payments = array())
1051
-    {
1052
-        $payment_methods_of_payments = array();
1053
-        foreach ($payments as $payment) {
1054
-            if ($payment instanceof EE_Payment) {
1055
-                $payment_methods_of_payments[] = $payment->get('PMD_ID');
1056
-            }
1057
-        }
1058
-        if ($payment_methods_of_payments) {
1059
-            $query_args = array(
1060
-                array(
1061
-                    'OR*payment_method_for_payment' => array(
1062
-                        'PMD_ID'    => array('IN', $payment_methods_of_payments),
1063
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')
1064
-                    )
1065
-                )
1066
-            );
1067
-        } else {
1068
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1069
-        }
1070
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     * txn_attendees_meta_box
1076
-     *    generates HTML for the Attendees Transaction main meta box
1077
-     *
1078
-     * @access public
1079
-     *
1080
-     * @param WP_Post $post
1081
-     * @param array   $metabox
1082
-     *
1083
-     * @return void
1084
-     */
1085
-    public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1086
-    {
1087
-
1088
-        extract($metabox['args']);
1089
-        $this->_template_args['post']            = $post;
1090
-        $this->_template_args['event_attendees'] = array();
1091
-        // process items in cart
1092
-        $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item')));
1093
-        if ( ! empty($line_items)) {
1094
-            foreach ($line_items as $item) {
1095
-                if ($item instanceof EE_Line_Item) {
1096
-                    switch ($item->OBJ_type()) {
1097
-
1098
-                        case 'Event' :
1099
-                            break;
1100
-
1101
-                        case 'Ticket' :
1102
-                            $ticket = $item->ticket();
1103
-                            //right now we're only handling tickets here.  Cause its expected that only tickets will have attendees right?
1104
-                            if ( ! $ticket instanceof EE_Ticket) {
1105
-                                continue;
1106
-                            }
1107
-                            try {
1108
-                                $event_name = $ticket->get_event_name();
1109
-                            } catch (Exception $e) {
1110
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1111
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1112
-                            }
1113
-                            $event_name .= ' - ' . $item->get('LIN_name');
1114
-                            $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1115
-                            // now get all of the registrations for this transaction that use this ticket
1116
-                            $registrations = $ticket->get_many_related('Registration',
1117
-                                array(array('TXN_ID' => $this->_transaction->ID())));
1118
-                            foreach ($registrations as $registration) {
1119
-                                if ( ! $registration instanceof EE_Registration) {
1120
-                                    continue;
1121
-                                }
1122
-                                $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']            = $registration->status_ID();
1123
-                                $this->_template_args['event_attendees'][$registration->ID()]['att_num']           = $registration->count();
1124
-                                $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name;
1125
-                                $this->_template_args['event_attendees'][$registration->ID()]['ticket_price']      = $ticket_price;
1126
-                                // attendee info
1127
-                                $attendee = $registration->get_first_related('Attendee');
1128
-                                if ($attendee instanceof EE_Attendee) {
1129
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = $attendee->ID();
1130
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name();
1131
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event',
1132
-                                            'event_espresso') . '">' . $attendee->email() . '</a>';
1133
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = EEH_Address::format($attendee,
1134
-                                        'inline', false, false);
1135
-                                } else {
1136
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1137
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1138
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1139
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1140
-                                }
1141
-                            }
1142
-                            break;
1143
-
1144
-                    }
1145
-                }
1146
-            }
1147
-
1148
-            $this->_template_args['transaction_form_url'] = add_query_arg(array(
1149
-                'action'  => 'edit_transaction',
1150
-                'process' => 'attendees'
1151
-            ), TXN_ADMIN_URL);
1152
-            echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1153
-                $this->_template_args, true);
1154
-
1155
-        } else {
1156
-            echo sprintf(
1157
-                esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1158
-                    'event_espresso'),
1159
-                '<p class="important-notice">',
1160
-                '</p>'
1161
-            );
1162
-        }
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * txn_registrant_side_meta_box
1168
-     * generates HTML for the Edit Transaction side meta box
1169
-     *
1170
-     * @access public
1171
-     * @throws \EE_Error
1172
-     * @return void
1173
-     */
1174
-    public function txn_registrant_side_meta_box()
1175
-    {
1176
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null;
1177
-        if ( ! $primary_att instanceof EE_Attendee) {
1178
-            $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1179
-                'event_espresso');
1180
-            $primary_att                                 = EEM_Attendee::instance()->create_default_object();
1181
-        }
1182
-        $this->_template_args['ATT_ID']            = $primary_att->ID();
1183
-        $this->_template_args['prime_reg_fname']   = $primary_att->fname();
1184
-        $this->_template_args['prime_reg_lname']   = $primary_att->lname();
1185
-        $this->_template_args['prime_reg_email']   = $primary_att->email();
1186
-        $this->_template_args['prime_reg_phone']   = $primary_att->phone();
1187
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1188
-            'action' => 'edit_attendee',
1189
-            'post'   => $primary_att->ID()
1190
-        ), REG_ADMIN_URL);
1191
-        // get formatted address for registrant
1192
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1193
-        echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1194
-            $this->_template_args, true);
1195
-    }
1196
-
1197
-
1198
-    /**
1199
-     * txn_billing_info_side_meta_box
1200
-     *    generates HTML for the Edit Transaction side meta box
1201
-     *
1202
-     * @access public
1203
-     * @return void
1204
-     */
1205
-    public function txn_billing_info_side_meta_box()
1206
-    {
1207
-
1208
-        $this->_template_args['billing_form']     = $this->_transaction->billing_info();
1209
-        $this->_template_args['billing_form_url'] = add_query_arg(
1210
-            array('action' => 'edit_transaction', 'process' => 'billing'),
1211
-            TXN_ADMIN_URL
1212
-        );
1213
-
1214
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1215
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1216
-    }
1217
-
1218
-
1219
-    /**
1220
-     * apply_payments_or_refunds
1221
-     *    registers a payment or refund made towards a transaction
1222
-     *
1223
-     * @access public
1224
-     * @return void
1225
-     */
1226
-    public function apply_payments_or_refunds()
1227
-    {
1228
-        $json_response_data = array('return_data' => false);
1229
-        $valid_data         = $this->_validate_payment_request_data();
1230
-        if ( ! empty($valid_data)) {
1231
-            $PAY_ID = $valid_data['PAY_ID'];
1232
-            //save  the new payment
1233
-            $payment = $this->_create_payment_from_request_data($valid_data);
1234
-            // get the TXN for this payment
1235
-            $transaction = $payment->transaction();
1236
-            // verify transaction
1237
-            if ($transaction instanceof EE_Transaction) {
1238
-                // calculate_total_payments_and_update_status
1239
-                $this->_process_transaction_payments($transaction);
1240
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1241
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1242
-                // apply payment to registrations (if applicable)
1243
-                if ( ! empty($REG_IDs)) {
1244
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1245
-                    $this->_maybe_send_notifications();
1246
-                    // now process status changes for the same registrations
1247
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1248
-                }
1249
-                $this->_maybe_send_notifications($payment);
1250
-                //prepare to render page
1251
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1252
-                do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction,
1253
-                    $payment);
1254
-            } else {
1255
-                EE_Error::add_error(
1256
-                    esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'),
1257
-                    __FILE__, __FUNCTION__, __LINE__
1258
-                );
1259
-            }
1260
-        } else {
1261
-            EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.',
1262
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1263
-        }
1264
-
1265
-        $notices              = EE_Error::get_notices(false, false, false);
1266
-        $this->_template_args = array(
1267
-            'data'    => $json_response_data,
1268
-            'error'   => $notices['errors'],
1269
-            'success' => $notices['success']
1270
-        );
1271
-        $this->_return_json();
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     * _validate_payment_request_data
1277
-     *
1278
-     * @return array
1279
-     */
1280
-    protected function _validate_payment_request_data()
1281
-    {
1282
-        if ( ! isset($this->_req_data['txn_admin_payment'])) {
1283
-            return false;
1284
-        }
1285
-        $payment_form = $this->_generate_payment_form_section();
1286
-        try {
1287
-            if ($payment_form->was_submitted()) {
1288
-                $payment_form->receive_form_submission();
1289
-                if ( ! $payment_form->is_valid()) {
1290
-                    $submission_error_messages = array();
1291
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1292
-                        if ($validation_error instanceof EE_Validation_Error) {
1293
-                            $submission_error_messages[] = sprintf(
1294
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1295
-                                $validation_error->get_form_section()->html_label_text(),
1296
-                                $validation_error->getMessage()
1297
-                            );
1298
-                        }
1299
-                    }
1300
-                    EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1301
-
1302
-                    return array();
1303
-                }
1304
-            }
1305
-        } catch (EE_Error $e) {
1306
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1307
-
1308
-            return array();
1309
-        }
1310
-
1311
-        return $payment_form->valid_data();
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * _generate_payment_form_section
1317
-     *
1318
-     * @return EE_Form_Section_Proper
1319
-     */
1320
-    protected function _generate_payment_form_section()
1321
-    {
1322
-        return new EE_Form_Section_Proper(
1323
-            array(
1324
-                'name'        => 'txn_admin_payment',
1325
-                'subsections' => array(
1326
-                    'PAY_ID'          => new EE_Text_Input(
1327
-                        array(
1328
-                            'default'               => 0,
1329
-                            'required'              => false,
1330
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1331
-                            'validation_strategies' => array(new EE_Int_Normalization())
1332
-                        )
1333
-                    ),
1334
-                    'TXN_ID'          => new EE_Text_Input(
1335
-                        array(
1336
-                            'default'               => 0,
1337
-                            'required'              => true,
1338
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1339
-                            'validation_strategies' => array(new EE_Int_Normalization())
1340
-                        )
1341
-                    ),
1342
-                    'type'            => new EE_Text_Input(
1343
-                        array(
1344
-                            'default'               => 1,
1345
-                            'required'              => true,
1346
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1347
-                            'validation_strategies' => array(new EE_Int_Normalization())
1348
-                        )
1349
-                    ),
1350
-                    'amount'          => new EE_Text_Input(
1351
-                        array(
1352
-                            'default'               => 0,
1353
-                            'required'              => true,
1354
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1355
-                            'validation_strategies' => array(new EE_Float_Normalization())
1356
-                        )
1357
-                    ),
1358
-                    'status'          => new EE_Text_Input(
1359
-                        array(
1360
-                            'default'         => EEM_Payment::status_id_approved,
1361
-                            'required'        => true,
1362
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1363
-                        )
1364
-                    ),
1365
-                    'PMD_ID'          => new EE_Text_Input(
1366
-                        array(
1367
-                            'default'               => 2,
1368
-                            'required'              => true,
1369
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1370
-                            'validation_strategies' => array(new EE_Int_Normalization())
1371
-                        )
1372
-                    ),
1373
-                    'date'            => new EE_Text_Input(
1374
-                        array(
1375
-                            'default'         => time(),
1376
-                            'required'        => true,
1377
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1378
-                        )
1379
-                    ),
1380
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1381
-                        array(
1382
-                            'default'               => '',
1383
-                            'required'              => false,
1384
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1385
-                            'validation_strategies' => array(
1386
-                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1387
-                                    100),
1388
-                            )
1389
-                        )
1390
-                    ),
1391
-                    'po_number'       => new EE_Text_Input(
1392
-                        array(
1393
-                            'default'               => '',
1394
-                            'required'              => false,
1395
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1396
-                            'validation_strategies' => array(
1397
-                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1398
-                                    100),
1399
-                            )
1400
-                        )
1401
-                    ),
1402
-                    'accounting'      => new EE_Text_Input(
1403
-                        array(
1404
-                            'default'               => '',
1405
-                            'required'              => false,
1406
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1407
-                            'validation_strategies' => array(
1408
-                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1409
-                                    100),
1410
-                            )
1411
-                        )
1412
-                    ),
1413
-                )
1414
-            )
1415
-        );
1416
-    }
1417
-
1418
-
1419
-    /**
1420
-     * _create_payment_from_request_data
1421
-     *
1422
-     * @param array $valid_data
1423
-     *
1424
-     * @return EE_Payment
1425
-     */
1426
-    protected function _create_payment_from_request_data($valid_data)
1427
-    {
1428
-        $PAY_ID = $valid_data['PAY_ID'];
1429
-        // get payment amount
1430
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1431
-        // payments have a type value of 1 and refunds have a type value of -1
1432
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1433
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1434
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1435
-        $date    = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a',
1436
-            current_time('timestamp'));
1437
-        $payment = EE_Payment::new_instance(
1438
-            array(
1439
-                'TXN_ID'              => $valid_data['TXN_ID'],
1440
-                'STS_ID'              => $valid_data['status'],
1441
-                'PAY_timestamp'       => $date,
1442
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1443
-                'PMD_ID'              => $valid_data['PMD_ID'],
1444
-                'PAY_amount'          => $amount,
1445
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1446
-                'PAY_po_number'       => $valid_data['po_number'],
1447
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1448
-                'PAY_details'         => $valid_data,
1449
-                'PAY_ID'              => $PAY_ID
1450
-            ),
1451
-            '',
1452
-            array('Y-m-d', 'g:i a')
1453
-        );
1454
-
1455
-        if ( ! $payment->save()) {
1456
-            EE_Error::add_error(
1457
-                sprintf(
1458
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1459
-                    $payment->ID()
1460
-                ),
1461
-                __FILE__, __FUNCTION__, __LINE__
1462
-            );
1463
-        }
1464
-
1465
-        return $payment;
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     * _process_transaction_payments
1471
-     *
1472
-     * @param \EE_Transaction $transaction
1473
-     *
1474
-     * @return array
1475
-     */
1476
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1477
-    {
1478
-        /** @type EE_Transaction_Payments $transaction_payments */
1479
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1480
-        //update the transaction with this payment
1481
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1482
-            EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'),
1483
-                __FILE__, __FUNCTION__, __LINE__);
1484
-        } else {
1485
-            EE_Error::add_error(
1486
-                esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.',
1487
-                    'event_espresso')
1488
-                , __FILE__, __FUNCTION__, __LINE__
1489
-            );
1490
-        }
1491
-    }
1492
-
1493
-
1494
-    /**
1495
-     * _get_REG_IDs_to_apply_payment_to
1496
-     *
1497
-     * returns a list of registration IDs that the payment will apply to
1498
-     *
1499
-     * @param \EE_Payment $payment
1500
-     *
1501
-     * @return array
1502
-     */
1503
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1504
-    {
1505
-        $REG_IDs = array();
1506
-        // grab array of IDs for specific registrations to apply changes to
1507
-        if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1508
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1509
-        }
1510
-        //nothing specified ? then get all reg IDs
1511
-        if (empty($REG_IDs)) {
1512
-            $registrations = $payment->transaction()->registrations();
1513
-            $REG_IDs       = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment);
1514
-        }
1515
-
1516
-        // ensure that REG_IDs are integers and NOT strings
1517
-        return array_map('intval', $REG_IDs);
1518
-    }
1519
-
1520
-
1521
-    /**
1522
-     * @return array
1523
-     */
1524
-    public function existing_reg_payment_REG_IDs()
1525
-    {
1526
-        return $this->_existing_reg_payment_REG_IDs;
1527
-    }
1528
-
1529
-
1530
-    /**
1531
-     * @param array $existing_reg_payment_REG_IDs
1532
-     */
1533
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1534
-    {
1535
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1536
-    }
1537
-
1538
-
1539
-    /**
1540
-     * _get_existing_reg_payment_REG_IDs
1541
-     *
1542
-     * returns a list of registration IDs that the payment is currently related to
1543
-     * as recorded in the database
1544
-     *
1545
-     * @param \EE_Payment $payment
1546
-     *
1547
-     * @return array
1548
-     */
1549
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1550
-    {
1551
-        if ($this->existing_reg_payment_REG_IDs() === null) {
1552
-            // let's get any existing reg payment records for this payment
1553
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1554
-            // but we only want the REG IDs, so grab the array keys
1555
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array();
1556
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1557
-        }
1558
-
1559
-        return $this->existing_reg_payment_REG_IDs();
1560
-    }
1561
-
1562
-
1563
-    /**
1564
-     * _remove_existing_registration_payments
1565
-     *
1566
-     * this calculates the difference between existing relations
1567
-     * to the supplied payment and the new list registration IDs,
1568
-     * removes any related registrations that no longer apply,
1569
-     * and then updates the registration paid fields
1570
-     *
1571
-     * @param \EE_Payment $payment
1572
-     * @param int         $PAY_ID
1573
-     *
1574
-     * @return bool;
1575
-     */
1576
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1577
-    {
1578
-        // newly created payments will have nothing recorded for $PAY_ID
1579
-        if ($PAY_ID == 0) {
1580
-            return false;
1581
-        }
1582
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1583
-        if (empty($existing_reg_payment_REG_IDs)) {
1584
-            return false;
1585
-        }
1586
-        /** @type EE_Transaction_Payments $transaction_payments */
1587
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1588
-
1589
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
1590
-            $payment,
1591
-            array(
1592
-                array(
1593
-                    'PAY_ID' => $payment->ID(),
1594
-                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1595
-                )
1596
-            )
1597
-        );
1598
-    }
1599
-
1600
-
1601
-    /**
1602
-     * _update_registration_payments
1603
-     *
1604
-     * this applies the payments to the selected registrations
1605
-     * but only if they have not already been paid for
1606
-     *
1607
-     * @param  EE_Transaction $transaction
1608
-     * @param \EE_Payment     $payment
1609
-     * @param array           $REG_IDs
1610
-     *
1611
-     * @return bool
1612
-     */
1613
-    protected function _update_registration_payments(
1614
-        EE_Transaction $transaction,
1615
-        EE_Payment $payment,
1616
-        $REG_IDs = array()
1617
-    ) {
1618
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1619
-        // so let's do that using our set of REG_IDs from the form
1620
-        $registration_query_where_params = array(
1621
-            'REG_ID' => array('IN', $REG_IDs)
1622
-        );
1623
-        // but add in some conditions regarding payment,
1624
-        // so that we don't apply payments to registrations that are free or have already been paid for
1625
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1626
-        if ( ! $payment->is_a_refund()) {
1627
-            $registration_query_where_params['REG_final_price']  = array('!=', 0);
1628
-            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1629
-        }
1630
-        //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ );
1631
-        $registrations = $transaction->registrations(array($registration_query_where_params));
1632
-        if ( ! empty($registrations)) {
1633
-            /** @type EE_Payment_Processor $payment_processor */
1634
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1635
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
1636
-        }
1637
-    }
1638
-
1639
-
1640
-    /**
1641
-     * _process_registration_status_change
1642
-     *
1643
-     * This processes requested registration status changes for all the registrations
1644
-     * on a given transaction and (optionally) sends out notifications for the changes.
1645
-     *
1646
-     * @param  EE_Transaction $transaction
1647
-     * @param array           $REG_IDs
1648
-     *
1649
-     * @return bool
1650
-     */
1651
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1652
-    {
1653
-        // first if there is no change in status then we get out.
1654
-        if (
1655
-            ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status'])
1656
-            || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN'
1657
-        ) {
1658
-            //no error message, no change requested, just nothing to do man.
1659
-            return false;
1660
-        }
1661
-        /** @type EE_Transaction_Processor $transaction_processor */
1662
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1663
-
1664
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1665
-        return $transaction_processor->manually_update_registration_statuses(
1666
-            $transaction,
1667
-            sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1668
-            array(array('REG_ID' => array('IN', $REG_IDs)))
1669
-        );
1670
-    }
1671
-
1672
-
1673
-    /**
1674
-     * _build_payment_json_response
1675
-     *
1676
-     * @access public
1677
-     *
1678
-     * @param \EE_Payment $payment
1679
-     * @param array       $REG_IDs
1680
-     * @param bool | null $delete_txn_reg_status_change
1681
-     *
1682
-     * @return array
1683
-     */
1684
-    protected function _build_payment_json_response(
1685
-        EE_Payment $payment,
1686
-        $REG_IDs = array(),
1687
-        $delete_txn_reg_status_change = null
1688
-    ) {
1689
-        // was the payment deleted ?
1690
-        if (is_bool($delete_txn_reg_status_change)) {
1691
-            return array(
1692
-                'PAY_ID'                       => $payment->ID(),
1693
-                'amount'                       => $payment->amount(),
1694
-                'total_paid'                   => $payment->transaction()->paid(),
1695
-                'txn_status'                   => $payment->transaction()->status_ID(),
1696
-                'pay_status'                   => $payment->STS_ID(),
1697
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
1698
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
1699
-            );
1700
-        } else {
1701
-            $this->_get_payment_status_array();
1702
-
1703
-            return array(
1704
-                'amount'           => $payment->amount(),
1705
-                'total_paid'       => $payment->transaction()->paid(),
1706
-                'txn_status'       => $payment->transaction()->status_ID(),
1707
-                'pay_status'       => $payment->STS_ID(),
1708
-                'PAY_ID'           => $payment->ID(),
1709
-                'STS_ID'           => $payment->STS_ID(),
1710
-                'status'           => self::$_pay_status[$payment->STS_ID()],
1711
-                'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
1712
-                'method'           => strtoupper($payment->source()),
1713
-                'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
1714
-                'gateway'          => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown",
1715
-                    'event_espresso'),
1716
-                'gateway_response' => $payment->gateway_response(),
1717
-                'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
1718
-                'po_number'        => $payment->po_number(),
1719
-                'extra_accntng'    => $payment->extra_accntng(),
1720
-                'registrations'    => $this->_registration_payment_data_array($REG_IDs),
1721
-            );
1722
-        }
1723
-    }
1724
-
1725
-
1726
-    /**
1727
-     * delete_payment
1728
-     *    delete a payment or refund made towards a transaction
1729
-     *
1730
-     * @access public
1731
-     * @return void
1732
-     */
1733
-    public function delete_payment()
1734
-    {
1735
-        $json_response_data = array('return_data' => false);
1736
-        $PAY_ID             = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0;
1737
-        if ($PAY_ID) {
1738
-            $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false;
1739
-            $payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
1740
-            if ($payment instanceof EE_Payment) {
1741
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1742
-                /** @type EE_Transaction_Payments $transaction_payments */
1743
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1744
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
1745
-                    $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs,
1746
-                        $delete_txn_reg_status_change);
1747
-                    if ($delete_txn_reg_status_change) {
1748
-                        $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
1749
-                        //MAKE sure we also add the delete_txn_req_status_change to the
1750
-                        //$_REQUEST global because that's how messages will be looking for it.
1751
-                        $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
1752
-                        $this->_maybe_send_notifications();
1753
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
1754
-                    }
1755
-                }
1756
-            } else {
1757
-                EE_Error::add_error(
1758
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
1759
-                    __FILE__, __FUNCTION__, __LINE__
1760
-                );
1761
-            }
1762
-        } else {
1763
-            EE_Error::add_error(
1764
-                esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.',
1765
-                    'event_espresso'),
1766
-                __FILE__, __FUNCTION__, __LINE__
1767
-            );
1768
-        }
1769
-        $notices              = EE_Error::get_notices(false, false, false);
1770
-        $this->_template_args = array(
1771
-            'data'      => $json_response_data,
1772
-            'success'   => $notices['success'],
1773
-            'error'     => $notices['errors'],
1774
-            'attention' => $notices['attention']
1775
-        );
1776
-        $this->_return_json();
1777
-    }
1778
-
1779
-
1780
-    /**
1781
-     * _registration_payment_data_array
1782
-     * adds info for 'owing' and 'paid' for each registration to the json response
1783
-     *
1784
-     * @access protected
1785
-     *
1786
-     * @param array $REG_IDs
1787
-     *
1788
-     * @return array
1789
-     */
1790
-    protected function _registration_payment_data_array($REG_IDs)
1791
-    {
1792
-        $registration_payment_data = array();
1793
-        //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
1794
-        if ( ! empty($REG_IDs)) {
1795
-            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
1796
-            foreach ($registrations as $registration) {
1797
-                if ($registration instanceof EE_Registration) {
1798
-                    $registration_payment_data[$registration->ID()] = array(
1799
-                        'paid'  => $registration->pretty_paid(),
1800
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
1801
-                    );
1802
-                }
1803
-            }
1804
-        }
1805
-
1806
-        return $registration_payment_data;
1807
-    }
1808
-
1809
-
1810
-    /**
1811
-     * _maybe_send_notifications
1812
-     *
1813
-     * determines whether or not the admin has indicated that notifications should be sent.
1814
-     * If so, will toggle a filter switch for delivering registration notices.
1815
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
1816
-     *
1817
-     * @access protected
1818
-     *
1819
-     * @param \EE_Payment | null $payment
1820
-     */
1821
-    protected function _maybe_send_notifications($payment = null)
1822
-    {
1823
-        switch ($payment instanceof EE_Payment) {
1824
-            // payment notifications
1825
-            case true :
1826
-                if (
1827
-                    isset(
1828
-                        $this->_req_data['txn_payments'],
1829
-                        $this->_req_data['txn_payments']['send_notifications']
1830
-                    ) &&
1831
-                    filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1832
-                ) {
1833
-                    $this->_process_payment_notification($payment);
1834
-                }
1835
-                break;
1836
-            // registration notifications
1837
-            case false :
1838
-                if (
1839
-                    isset(
1840
-                        $this->_req_data['txn_reg_status_change'],
1841
-                        $this->_req_data['txn_reg_status_change']['send_notifications']
1842
-                    ) &&
1843
-                    filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1844
-                ) {
1845
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
1846
-                }
1847
-                break;
1848
-        }
1849
-    }
1850
-
1851
-
1852
-    /**
1853
-     * _send_payment_reminder
1854
-     *    generates HTML for the View Transaction Details Admin page
1855
-     *
1856
-     * @access protected
1857
-     * @return void
1858
-     */
1859
-    protected function _send_payment_reminder()
1860
-    {
1861
-        $TXN_ID      = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
1862
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
1863
-        $query_args  = isset($this->_req_data['redirect_to']) ? array(
1864
-            'action' => $this->_req_data['redirect_to'],
1865
-            'TXN_ID' => $this->_req_data['TXN_ID']
1866
-        ) : array();
1867
-        do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
1868
-            $transaction);
1869
-        $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'),
1870
-            esc_html__('sent', 'event_espresso'), $query_args, true);
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     *  get_transactions
1876
-     *    get transactions for given parameters (used by list table)
1877
-     *
1878
-     * @param  int     $perpage how many transactions displayed per page
1879
-     * @param  boolean $count   return the count or objects
1880
-     * @param string   $view
1881
-     *
1882
-     * @return mixed int = count || array of transaction objects
1883
-     */
1884
-    public function get_transactions($perpage, $count = false, $view = '')
1885
-    {
1886
-
1887
-        $TXN = EEM_Transaction::instance();
1888
-
1889
-        $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y',
1890
-            strtotime('-10 year'));
1891
-        $end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y');
1892
-
1893
-        //make sure our timestamps start and end right at the boundaries for each day
1894
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1895
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1896
-
1897
-
1898
-        //convert to timestamps
1899
-        $start_date = strtotime($start_date);
1900
-        $end_date   = strtotime($end_date);
1901
-
1902
-        //makes sure start date is the lowest value and vice versa
1903
-        $start_date = min($start_date, $end_date);
1904
-        $end_date   = max($start_date, $end_date);
1905
-
1906
-        //convert to correct format for query
1907
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1908
-            date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s');
1909
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1910
-            date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s');
1911
-
1912
-
1913
-        //set orderby
1914
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1915
-
1916
-        switch ($this->_req_data['orderby']) {
1917
-            case 'TXN_ID':
1918
-                $orderby = 'TXN_ID';
1919
-                break;
1920
-            case 'ATT_fname':
1921
-                $orderby = 'Registration.Attendee.ATT_fname';
1922
-                break;
1923
-            case 'event_name':
1924
-                $orderby = 'Registration.Event.EVT_name';
1925
-                break;
1926
-            default: //'TXN_timestamp'
1927
-                $orderby = 'TXN_timestamp';
1928
-        }
1929
-
1930
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC';
1931
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1932
-        $per_page     = isset($perpage) && ! empty($perpage) ? $perpage : 10;
1933
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
1934
-
1935
-        $offset = ($current_page - 1) * $per_page;
1936
-        $limit  = array($offset, $per_page);
1937
-
1938
-        $_where = array(
1939
-            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
1940
-            'Registration.REG_count' => 1
1941
-        );
1942
-
1943
-        if (isset($this->_req_data['EVT_ID'])) {
1944
-            $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
1945
-        }
1946
-
1947
-        if (isset($this->_req_data['s'])) {
1948
-            $search_string = '%' . $this->_req_data['s'] . '%';
1949
-            $_where['OR']  = array(
1950
-                'Registration.Event.EVT_name'         => array('LIKE', $search_string),
1951
-                'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
1952
-                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
1953
-                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
1954
-                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
1955
-                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
1956
-                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
1957
-                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
1958
-                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
1959
-                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
1960
-                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
1961
-                'Registration.REG_final_price'        => array('LIKE', $search_string),
1962
-                'Registration.REG_code'               => array('LIKE', $search_string),
1963
-                'Registration.REG_count'              => array('LIKE', $search_string),
1964
-                'Registration.REG_group_size'         => array('LIKE', $search_string),
1965
-                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
1966
-                'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
1967
-                'Payment.PAY_source'                  => array('LIKE', $search_string),
1968
-                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
1969
-                'TXN_session_data'                    => array('LIKE', $search_string),
1970
-                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string)
1971
-            );
1972
-        }
1973
-
1974
-        //failed transactions
1975
-        $failed    = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false;
1976
-        $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false;
1977
-
1978
-        if ($failed) {
1979
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
1980
-        } else if ($abandoned) {
1981
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
1982
-        } else {
1983
-            $_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
1984
-            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
1985
-        }
1986
-
1987
-        $query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit);
1988
-
1989
-        $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params);
1990
-
1991
-
1992
-        return $transactions;
1993
-
1994
-    }
803
+		// process payment details
804
+		$payments = $this->_transaction->get_many_related('Payment');
805
+		if ( ! empty($payments)) {
806
+			$this->_template_args['payments']              = $payments;
807
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
808
+		} else {
809
+			$this->_template_args['payments']              = false;
810
+			$this->_template_args['existing_reg_payments'] = array();
811
+		}
812
+
813
+		$this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
814
+		$this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'),
815
+			TXN_ADMIN_URL);
816
+
817
+		if (isset($txn_details['invoice_number'])) {
818
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
819
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number',
820
+				'event_espresso');
821
+		}
822
+
823
+		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session');
824
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session',
825
+			'event_espresso');
826
+
827
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '';
828
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP',
829
+			'event_espresso');
830
+
831
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '';
832
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent',
833
+			'event_espresso');
834
+
835
+		$reg_steps = '<ul>';
836
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
837
+			if ($reg_step_status === true) {
838
+				$reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
839
+						ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
840
+			} else if (is_numeric($reg_step_status) && $reg_step_status !== false) {
841
+				$reg_steps .= '<li style="color:#2EA2CC">' . sprintf(
842
+						esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
843
+						ucwords(str_replace('_', ' ', $reg_step)),
844
+						date(get_option('date_format') . ' ' . get_option('time_format'),
845
+							($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)))
846
+					) . '</li>';
847
+			} else {
848
+				$reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated',
849
+						'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
850
+			}
851
+		}
852
+		$reg_steps .= '</ul>';
853
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
854
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress',
855
+			'event_espresso');
856
+
857
+
858
+		$this->_get_registrations_to_apply_payment_to();
859
+		$this->_get_payment_methods($payments);
860
+		$this->_get_payment_status_array();
861
+		$this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
862
+
863
+		$this->_template_args['transaction_form_url']    = add_query_arg(array(
864
+			'action'  => 'edit_transaction',
865
+			'process' => 'transaction'
866
+		), TXN_ADMIN_URL);
867
+		$this->_template_args['apply_payment_form_url']  = add_query_arg(array(
868
+			'page'   => 'espresso_transactions',
869
+			'action' => 'espresso_apply_payment'
870
+		), WP_AJAX_URL);
871
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(array(
872
+			'page'   => 'espresso_transactions',
873
+			'action' => 'espresso_delete_payment'
874
+		), WP_AJAX_URL);
875
+
876
+		// 'espresso_delete_payment_nonce'
877
+
878
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
879
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
880
+
881
+	}
882
+
883
+
884
+	/**
885
+	 * _get_registration_payment_IDs
886
+	 *
887
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
888
+	 *
889
+	 * @access protected
890
+	 *
891
+	 * @param EE_Payment[] $payments
892
+	 *
893
+	 * @return array
894
+	 */
895
+	protected function _get_registration_payment_IDs($payments = array())
896
+	{
897
+		$existing_reg_payments = array();
898
+		// get all reg payments for these payments
899
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(array(
900
+			array(
901
+				'PAY_ID' => array(
902
+					'IN',
903
+					array_keys($payments)
904
+				)
905
+			)
906
+		));
907
+		if ( ! empty($reg_payments)) {
908
+			foreach ($payments as $payment) {
909
+				if ( ! $payment instanceof EE_Payment) {
910
+					continue;
911
+				} else if ( ! isset($existing_reg_payments[$payment->ID()])) {
912
+					$existing_reg_payments[$payment->ID()] = array();
913
+				}
914
+				foreach ($reg_payments as $reg_payment) {
915
+					if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) {
916
+						$existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
917
+					}
918
+				}
919
+			}
920
+		}
921
+
922
+		return $existing_reg_payments;
923
+	}
924
+
925
+
926
+	/**
927
+	 * _get_registrations_to_apply_payment_to
928
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
929
+	 * which allows the admin to only apply the payment to the specific registrations
930
+	 *
931
+	 * @access protected
932
+	 * @return void
933
+	 * @throws \EE_Error
934
+	 */
935
+	protected function _get_registrations_to_apply_payment_to()
936
+	{
937
+		// we want any registration with an active status (ie: not deleted or cancelled)
938
+		$query_params                      = array(
939
+			array(
940
+				'STS_ID' => array(
941
+					'IN',
942
+					array(
943
+						EEM_Registration::status_id_approved,
944
+						EEM_Registration::status_id_pending_payment,
945
+						EEM_Registration::status_id_not_approved,
946
+					)
947
+				)
948
+			)
949
+		);
950
+		$registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
951
+				'', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;'
952
+			);
953
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
954
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
955
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
956
+			EEH_HTML::tr(
957
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
958
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
959
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
960
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
961
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
962
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
963
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
964
+			)
965
+		);
966
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
967
+		// get registrations for TXN
968
+		$registrations = $this->_transaction->registrations($query_params);
969
+		foreach ($registrations as $registration) {
970
+			if ($registration instanceof EE_Registration) {
971
+				$attendee_name = $registration->attendee() instanceof EE_Attendee
972
+					? $registration->attendee()->full_name()
973
+					: esc_html__('Unknown Attendee', 'event_espresso');
974
+				$owing         = $registration->final_price() - $registration->paid();
975
+				$taxable       = $registration->ticket()->taxable()
976
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
977
+					: '';
978
+				$checked       = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
979
+					? ' checked="checked"'
980
+					: '';
981
+				$disabled      = $registration->final_price() > 0 ? '' : ' disabled';
982
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
983
+					EEH_HTML::td($registration->ID()) .
984
+					EEH_HTML::td($attendee_name) .
985
+					EEH_HTML::td(
986
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
987
+					) .
988
+					EEH_HTML::td($registration->event_name()) .
989
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
990
+					EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
991
+					EEH_HTML::td(
992
+						'<input type="checkbox" value="' . $registration->ID()
993
+						. '" name="txn_admin_payment[registrations]"'
994
+						. $checked . $disabled . '>',
995
+						'', 'jst-cntr'
996
+					),
997
+					'apply-payment-registration-row-' . $registration->ID()
998
+				);
999
+			}
1000
+		}
1001
+		$registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1002
+		$registrations_to_apply_payment_to .= EEH_HTML::tablex();
1003
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1004
+		$registrations_to_apply_payment_to .= EEH_HTML::p(
1005
+			esc_html__(
1006
+				'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1007
+				'event_espresso'
1008
+			),
1009
+			'', 'clear description'
1010
+		);
1011
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1012
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * _get_reg_status_selection
1018
+	 *
1019
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1020
+	 *         instead of events.
1021
+	 * @access protected
1022
+	 * @return void
1023
+	 */
1024
+	protected function _get_reg_status_selection()
1025
+	{
1026
+		//first get all possible statuses
1027
+		$statuses = EEM_Registration::reg_status_array(array(), true);
1028
+		//let's add a "don't change" option.
1029
+		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1030
+		$status_array                                        = array_merge($status_array, $statuses);
1031
+		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]',
1032
+			$status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status');
1033
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]',
1034
+			$status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status');
1035
+
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 *    _get_payment_methods
1041
+	 * Gets all the payment methods available generally, or the ones that are already
1042
+	 * selected on these payments (in case their payment methods are no longer active).
1043
+	 * Has the side-effect of updating the template args' payment_methods item
1044
+	 * @access private
1045
+	 *
1046
+	 * @param EE_Payment[] to show on this page
1047
+	 *
1048
+	 * @return void
1049
+	 */
1050
+	private function _get_payment_methods($payments = array())
1051
+	{
1052
+		$payment_methods_of_payments = array();
1053
+		foreach ($payments as $payment) {
1054
+			if ($payment instanceof EE_Payment) {
1055
+				$payment_methods_of_payments[] = $payment->get('PMD_ID');
1056
+			}
1057
+		}
1058
+		if ($payment_methods_of_payments) {
1059
+			$query_args = array(
1060
+				array(
1061
+					'OR*payment_method_for_payment' => array(
1062
+						'PMD_ID'    => array('IN', $payment_methods_of_payments),
1063
+						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')
1064
+					)
1065
+				)
1066
+			);
1067
+		} else {
1068
+			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1069
+		}
1070
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 * txn_attendees_meta_box
1076
+	 *    generates HTML for the Attendees Transaction main meta box
1077
+	 *
1078
+	 * @access public
1079
+	 *
1080
+	 * @param WP_Post $post
1081
+	 * @param array   $metabox
1082
+	 *
1083
+	 * @return void
1084
+	 */
1085
+	public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1086
+	{
1087
+
1088
+		extract($metabox['args']);
1089
+		$this->_template_args['post']            = $post;
1090
+		$this->_template_args['event_attendees'] = array();
1091
+		// process items in cart
1092
+		$line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item')));
1093
+		if ( ! empty($line_items)) {
1094
+			foreach ($line_items as $item) {
1095
+				if ($item instanceof EE_Line_Item) {
1096
+					switch ($item->OBJ_type()) {
1097
+
1098
+						case 'Event' :
1099
+							break;
1100
+
1101
+						case 'Ticket' :
1102
+							$ticket = $item->ticket();
1103
+							//right now we're only handling tickets here.  Cause its expected that only tickets will have attendees right?
1104
+							if ( ! $ticket instanceof EE_Ticket) {
1105
+								continue;
1106
+							}
1107
+							try {
1108
+								$event_name = $ticket->get_event_name();
1109
+							} catch (Exception $e) {
1110
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1111
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1112
+							}
1113
+							$event_name .= ' - ' . $item->get('LIN_name');
1114
+							$ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1115
+							// now get all of the registrations for this transaction that use this ticket
1116
+							$registrations = $ticket->get_many_related('Registration',
1117
+								array(array('TXN_ID' => $this->_transaction->ID())));
1118
+							foreach ($registrations as $registration) {
1119
+								if ( ! $registration instanceof EE_Registration) {
1120
+									continue;
1121
+								}
1122
+								$this->_template_args['event_attendees'][$registration->ID()]['STS_ID']            = $registration->status_ID();
1123
+								$this->_template_args['event_attendees'][$registration->ID()]['att_num']           = $registration->count();
1124
+								$this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name;
1125
+								$this->_template_args['event_attendees'][$registration->ID()]['ticket_price']      = $ticket_price;
1126
+								// attendee info
1127
+								$attendee = $registration->get_first_related('Attendee');
1128
+								if ($attendee instanceof EE_Attendee) {
1129
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']   = $attendee->ID();
1130
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name();
1131
+									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event',
1132
+											'event_espresso') . '">' . $attendee->email() . '</a>';
1133
+									$this->_template_args['event_attendees'][$registration->ID()]['address']  = EEH_Address::format($attendee,
1134
+										'inline', false, false);
1135
+								} else {
1136
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1137
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1138
+									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1139
+									$this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1140
+								}
1141
+							}
1142
+							break;
1143
+
1144
+					}
1145
+				}
1146
+			}
1147
+
1148
+			$this->_template_args['transaction_form_url'] = add_query_arg(array(
1149
+				'action'  => 'edit_transaction',
1150
+				'process' => 'attendees'
1151
+			), TXN_ADMIN_URL);
1152
+			echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1153
+				$this->_template_args, true);
1154
+
1155
+		} else {
1156
+			echo sprintf(
1157
+				esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1158
+					'event_espresso'),
1159
+				'<p class="important-notice">',
1160
+				'</p>'
1161
+			);
1162
+		}
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * txn_registrant_side_meta_box
1168
+	 * generates HTML for the Edit Transaction side meta box
1169
+	 *
1170
+	 * @access public
1171
+	 * @throws \EE_Error
1172
+	 * @return void
1173
+	 */
1174
+	public function txn_registrant_side_meta_box()
1175
+	{
1176
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null;
1177
+		if ( ! $primary_att instanceof EE_Attendee) {
1178
+			$this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1179
+				'event_espresso');
1180
+			$primary_att                                 = EEM_Attendee::instance()->create_default_object();
1181
+		}
1182
+		$this->_template_args['ATT_ID']            = $primary_att->ID();
1183
+		$this->_template_args['prime_reg_fname']   = $primary_att->fname();
1184
+		$this->_template_args['prime_reg_lname']   = $primary_att->lname();
1185
+		$this->_template_args['prime_reg_email']   = $primary_att->email();
1186
+		$this->_template_args['prime_reg_phone']   = $primary_att->phone();
1187
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1188
+			'action' => 'edit_attendee',
1189
+			'post'   => $primary_att->ID()
1190
+		), REG_ADMIN_URL);
1191
+		// get formatted address for registrant
1192
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1193
+		echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1194
+			$this->_template_args, true);
1195
+	}
1196
+
1197
+
1198
+	/**
1199
+	 * txn_billing_info_side_meta_box
1200
+	 *    generates HTML for the Edit Transaction side meta box
1201
+	 *
1202
+	 * @access public
1203
+	 * @return void
1204
+	 */
1205
+	public function txn_billing_info_side_meta_box()
1206
+	{
1207
+
1208
+		$this->_template_args['billing_form']     = $this->_transaction->billing_info();
1209
+		$this->_template_args['billing_form_url'] = add_query_arg(
1210
+			array('action' => 'edit_transaction', 'process' => 'billing'),
1211
+			TXN_ADMIN_URL
1212
+		);
1213
+
1214
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1215
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1216
+	}
1217
+
1218
+
1219
+	/**
1220
+	 * apply_payments_or_refunds
1221
+	 *    registers a payment or refund made towards a transaction
1222
+	 *
1223
+	 * @access public
1224
+	 * @return void
1225
+	 */
1226
+	public function apply_payments_or_refunds()
1227
+	{
1228
+		$json_response_data = array('return_data' => false);
1229
+		$valid_data         = $this->_validate_payment_request_data();
1230
+		if ( ! empty($valid_data)) {
1231
+			$PAY_ID = $valid_data['PAY_ID'];
1232
+			//save  the new payment
1233
+			$payment = $this->_create_payment_from_request_data($valid_data);
1234
+			// get the TXN for this payment
1235
+			$transaction = $payment->transaction();
1236
+			// verify transaction
1237
+			if ($transaction instanceof EE_Transaction) {
1238
+				// calculate_total_payments_and_update_status
1239
+				$this->_process_transaction_payments($transaction);
1240
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1241
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1242
+				// apply payment to registrations (if applicable)
1243
+				if ( ! empty($REG_IDs)) {
1244
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1245
+					$this->_maybe_send_notifications();
1246
+					// now process status changes for the same registrations
1247
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1248
+				}
1249
+				$this->_maybe_send_notifications($payment);
1250
+				//prepare to render page
1251
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1252
+				do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction,
1253
+					$payment);
1254
+			} else {
1255
+				EE_Error::add_error(
1256
+					esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'),
1257
+					__FILE__, __FUNCTION__, __LINE__
1258
+				);
1259
+			}
1260
+		} else {
1261
+			EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.',
1262
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1263
+		}
1264
+
1265
+		$notices              = EE_Error::get_notices(false, false, false);
1266
+		$this->_template_args = array(
1267
+			'data'    => $json_response_data,
1268
+			'error'   => $notices['errors'],
1269
+			'success' => $notices['success']
1270
+		);
1271
+		$this->_return_json();
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 * _validate_payment_request_data
1277
+	 *
1278
+	 * @return array
1279
+	 */
1280
+	protected function _validate_payment_request_data()
1281
+	{
1282
+		if ( ! isset($this->_req_data['txn_admin_payment'])) {
1283
+			return false;
1284
+		}
1285
+		$payment_form = $this->_generate_payment_form_section();
1286
+		try {
1287
+			if ($payment_form->was_submitted()) {
1288
+				$payment_form->receive_form_submission();
1289
+				if ( ! $payment_form->is_valid()) {
1290
+					$submission_error_messages = array();
1291
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1292
+						if ($validation_error instanceof EE_Validation_Error) {
1293
+							$submission_error_messages[] = sprintf(
1294
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1295
+								$validation_error->get_form_section()->html_label_text(),
1296
+								$validation_error->getMessage()
1297
+							);
1298
+						}
1299
+					}
1300
+					EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1301
+
1302
+					return array();
1303
+				}
1304
+			}
1305
+		} catch (EE_Error $e) {
1306
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1307
+
1308
+			return array();
1309
+		}
1310
+
1311
+		return $payment_form->valid_data();
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * _generate_payment_form_section
1317
+	 *
1318
+	 * @return EE_Form_Section_Proper
1319
+	 */
1320
+	protected function _generate_payment_form_section()
1321
+	{
1322
+		return new EE_Form_Section_Proper(
1323
+			array(
1324
+				'name'        => 'txn_admin_payment',
1325
+				'subsections' => array(
1326
+					'PAY_ID'          => new EE_Text_Input(
1327
+						array(
1328
+							'default'               => 0,
1329
+							'required'              => false,
1330
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1331
+							'validation_strategies' => array(new EE_Int_Normalization())
1332
+						)
1333
+					),
1334
+					'TXN_ID'          => new EE_Text_Input(
1335
+						array(
1336
+							'default'               => 0,
1337
+							'required'              => true,
1338
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1339
+							'validation_strategies' => array(new EE_Int_Normalization())
1340
+						)
1341
+					),
1342
+					'type'            => new EE_Text_Input(
1343
+						array(
1344
+							'default'               => 1,
1345
+							'required'              => true,
1346
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1347
+							'validation_strategies' => array(new EE_Int_Normalization())
1348
+						)
1349
+					),
1350
+					'amount'          => new EE_Text_Input(
1351
+						array(
1352
+							'default'               => 0,
1353
+							'required'              => true,
1354
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1355
+							'validation_strategies' => array(new EE_Float_Normalization())
1356
+						)
1357
+					),
1358
+					'status'          => new EE_Text_Input(
1359
+						array(
1360
+							'default'         => EEM_Payment::status_id_approved,
1361
+							'required'        => true,
1362
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1363
+						)
1364
+					),
1365
+					'PMD_ID'          => new EE_Text_Input(
1366
+						array(
1367
+							'default'               => 2,
1368
+							'required'              => true,
1369
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1370
+							'validation_strategies' => array(new EE_Int_Normalization())
1371
+						)
1372
+					),
1373
+					'date'            => new EE_Text_Input(
1374
+						array(
1375
+							'default'         => time(),
1376
+							'required'        => true,
1377
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1378
+						)
1379
+					),
1380
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1381
+						array(
1382
+							'default'               => '',
1383
+							'required'              => false,
1384
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1385
+							'validation_strategies' => array(
1386
+								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1387
+									100),
1388
+							)
1389
+						)
1390
+					),
1391
+					'po_number'       => new EE_Text_Input(
1392
+						array(
1393
+							'default'               => '',
1394
+							'required'              => false,
1395
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1396
+							'validation_strategies' => array(
1397
+								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1398
+									100),
1399
+							)
1400
+						)
1401
+					),
1402
+					'accounting'      => new EE_Text_Input(
1403
+						array(
1404
+							'default'               => '',
1405
+							'required'              => false,
1406
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1407
+							'validation_strategies' => array(
1408
+								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1409
+									100),
1410
+							)
1411
+						)
1412
+					),
1413
+				)
1414
+			)
1415
+		);
1416
+	}
1417
+
1418
+
1419
+	/**
1420
+	 * _create_payment_from_request_data
1421
+	 *
1422
+	 * @param array $valid_data
1423
+	 *
1424
+	 * @return EE_Payment
1425
+	 */
1426
+	protected function _create_payment_from_request_data($valid_data)
1427
+	{
1428
+		$PAY_ID = $valid_data['PAY_ID'];
1429
+		// get payment amount
1430
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1431
+		// payments have a type value of 1 and refunds have a type value of -1
1432
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1433
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1434
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1435
+		$date    = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a',
1436
+			current_time('timestamp'));
1437
+		$payment = EE_Payment::new_instance(
1438
+			array(
1439
+				'TXN_ID'              => $valid_data['TXN_ID'],
1440
+				'STS_ID'              => $valid_data['status'],
1441
+				'PAY_timestamp'       => $date,
1442
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1443
+				'PMD_ID'              => $valid_data['PMD_ID'],
1444
+				'PAY_amount'          => $amount,
1445
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1446
+				'PAY_po_number'       => $valid_data['po_number'],
1447
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1448
+				'PAY_details'         => $valid_data,
1449
+				'PAY_ID'              => $PAY_ID
1450
+			),
1451
+			'',
1452
+			array('Y-m-d', 'g:i a')
1453
+		);
1454
+
1455
+		if ( ! $payment->save()) {
1456
+			EE_Error::add_error(
1457
+				sprintf(
1458
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1459
+					$payment->ID()
1460
+				),
1461
+				__FILE__, __FUNCTION__, __LINE__
1462
+			);
1463
+		}
1464
+
1465
+		return $payment;
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 * _process_transaction_payments
1471
+	 *
1472
+	 * @param \EE_Transaction $transaction
1473
+	 *
1474
+	 * @return array
1475
+	 */
1476
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1477
+	{
1478
+		/** @type EE_Transaction_Payments $transaction_payments */
1479
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1480
+		//update the transaction with this payment
1481
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1482
+			EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'),
1483
+				__FILE__, __FUNCTION__, __LINE__);
1484
+		} else {
1485
+			EE_Error::add_error(
1486
+				esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.',
1487
+					'event_espresso')
1488
+				, __FILE__, __FUNCTION__, __LINE__
1489
+			);
1490
+		}
1491
+	}
1492
+
1493
+
1494
+	/**
1495
+	 * _get_REG_IDs_to_apply_payment_to
1496
+	 *
1497
+	 * returns a list of registration IDs that the payment will apply to
1498
+	 *
1499
+	 * @param \EE_Payment $payment
1500
+	 *
1501
+	 * @return array
1502
+	 */
1503
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1504
+	{
1505
+		$REG_IDs = array();
1506
+		// grab array of IDs for specific registrations to apply changes to
1507
+		if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1508
+			$REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1509
+		}
1510
+		//nothing specified ? then get all reg IDs
1511
+		if (empty($REG_IDs)) {
1512
+			$registrations = $payment->transaction()->registrations();
1513
+			$REG_IDs       = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment);
1514
+		}
1515
+
1516
+		// ensure that REG_IDs are integers and NOT strings
1517
+		return array_map('intval', $REG_IDs);
1518
+	}
1519
+
1520
+
1521
+	/**
1522
+	 * @return array
1523
+	 */
1524
+	public function existing_reg_payment_REG_IDs()
1525
+	{
1526
+		return $this->_existing_reg_payment_REG_IDs;
1527
+	}
1528
+
1529
+
1530
+	/**
1531
+	 * @param array $existing_reg_payment_REG_IDs
1532
+	 */
1533
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1534
+	{
1535
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1536
+	}
1537
+
1538
+
1539
+	/**
1540
+	 * _get_existing_reg_payment_REG_IDs
1541
+	 *
1542
+	 * returns a list of registration IDs that the payment is currently related to
1543
+	 * as recorded in the database
1544
+	 *
1545
+	 * @param \EE_Payment $payment
1546
+	 *
1547
+	 * @return array
1548
+	 */
1549
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1550
+	{
1551
+		if ($this->existing_reg_payment_REG_IDs() === null) {
1552
+			// let's get any existing reg payment records for this payment
1553
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1554
+			// but we only want the REG IDs, so grab the array keys
1555
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array();
1556
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1557
+		}
1558
+
1559
+		return $this->existing_reg_payment_REG_IDs();
1560
+	}
1561
+
1562
+
1563
+	/**
1564
+	 * _remove_existing_registration_payments
1565
+	 *
1566
+	 * this calculates the difference between existing relations
1567
+	 * to the supplied payment and the new list registration IDs,
1568
+	 * removes any related registrations that no longer apply,
1569
+	 * and then updates the registration paid fields
1570
+	 *
1571
+	 * @param \EE_Payment $payment
1572
+	 * @param int         $PAY_ID
1573
+	 *
1574
+	 * @return bool;
1575
+	 */
1576
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1577
+	{
1578
+		// newly created payments will have nothing recorded for $PAY_ID
1579
+		if ($PAY_ID == 0) {
1580
+			return false;
1581
+		}
1582
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1583
+		if (empty($existing_reg_payment_REG_IDs)) {
1584
+			return false;
1585
+		}
1586
+		/** @type EE_Transaction_Payments $transaction_payments */
1587
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1588
+
1589
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
1590
+			$payment,
1591
+			array(
1592
+				array(
1593
+					'PAY_ID' => $payment->ID(),
1594
+					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1595
+				)
1596
+			)
1597
+		);
1598
+	}
1599
+
1600
+
1601
+	/**
1602
+	 * _update_registration_payments
1603
+	 *
1604
+	 * this applies the payments to the selected registrations
1605
+	 * but only if they have not already been paid for
1606
+	 *
1607
+	 * @param  EE_Transaction $transaction
1608
+	 * @param \EE_Payment     $payment
1609
+	 * @param array           $REG_IDs
1610
+	 *
1611
+	 * @return bool
1612
+	 */
1613
+	protected function _update_registration_payments(
1614
+		EE_Transaction $transaction,
1615
+		EE_Payment $payment,
1616
+		$REG_IDs = array()
1617
+	) {
1618
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1619
+		// so let's do that using our set of REG_IDs from the form
1620
+		$registration_query_where_params = array(
1621
+			'REG_ID' => array('IN', $REG_IDs)
1622
+		);
1623
+		// but add in some conditions regarding payment,
1624
+		// so that we don't apply payments to registrations that are free or have already been paid for
1625
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1626
+		if ( ! $payment->is_a_refund()) {
1627
+			$registration_query_where_params['REG_final_price']  = array('!=', 0);
1628
+			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1629
+		}
1630
+		//EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ );
1631
+		$registrations = $transaction->registrations(array($registration_query_where_params));
1632
+		if ( ! empty($registrations)) {
1633
+			/** @type EE_Payment_Processor $payment_processor */
1634
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1635
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
1636
+		}
1637
+	}
1638
+
1639
+
1640
+	/**
1641
+	 * _process_registration_status_change
1642
+	 *
1643
+	 * This processes requested registration status changes for all the registrations
1644
+	 * on a given transaction and (optionally) sends out notifications for the changes.
1645
+	 *
1646
+	 * @param  EE_Transaction $transaction
1647
+	 * @param array           $REG_IDs
1648
+	 *
1649
+	 * @return bool
1650
+	 */
1651
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1652
+	{
1653
+		// first if there is no change in status then we get out.
1654
+		if (
1655
+			! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status'])
1656
+			|| $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN'
1657
+		) {
1658
+			//no error message, no change requested, just nothing to do man.
1659
+			return false;
1660
+		}
1661
+		/** @type EE_Transaction_Processor $transaction_processor */
1662
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1663
+
1664
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1665
+		return $transaction_processor->manually_update_registration_statuses(
1666
+			$transaction,
1667
+			sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1668
+			array(array('REG_ID' => array('IN', $REG_IDs)))
1669
+		);
1670
+	}
1671
+
1672
+
1673
+	/**
1674
+	 * _build_payment_json_response
1675
+	 *
1676
+	 * @access public
1677
+	 *
1678
+	 * @param \EE_Payment $payment
1679
+	 * @param array       $REG_IDs
1680
+	 * @param bool | null $delete_txn_reg_status_change
1681
+	 *
1682
+	 * @return array
1683
+	 */
1684
+	protected function _build_payment_json_response(
1685
+		EE_Payment $payment,
1686
+		$REG_IDs = array(),
1687
+		$delete_txn_reg_status_change = null
1688
+	) {
1689
+		// was the payment deleted ?
1690
+		if (is_bool($delete_txn_reg_status_change)) {
1691
+			return array(
1692
+				'PAY_ID'                       => $payment->ID(),
1693
+				'amount'                       => $payment->amount(),
1694
+				'total_paid'                   => $payment->transaction()->paid(),
1695
+				'txn_status'                   => $payment->transaction()->status_ID(),
1696
+				'pay_status'                   => $payment->STS_ID(),
1697
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
1698
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
1699
+			);
1700
+		} else {
1701
+			$this->_get_payment_status_array();
1702
+
1703
+			return array(
1704
+				'amount'           => $payment->amount(),
1705
+				'total_paid'       => $payment->transaction()->paid(),
1706
+				'txn_status'       => $payment->transaction()->status_ID(),
1707
+				'pay_status'       => $payment->STS_ID(),
1708
+				'PAY_ID'           => $payment->ID(),
1709
+				'STS_ID'           => $payment->STS_ID(),
1710
+				'status'           => self::$_pay_status[$payment->STS_ID()],
1711
+				'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
1712
+				'method'           => strtoupper($payment->source()),
1713
+				'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
1714
+				'gateway'          => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown",
1715
+					'event_espresso'),
1716
+				'gateway_response' => $payment->gateway_response(),
1717
+				'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
1718
+				'po_number'        => $payment->po_number(),
1719
+				'extra_accntng'    => $payment->extra_accntng(),
1720
+				'registrations'    => $this->_registration_payment_data_array($REG_IDs),
1721
+			);
1722
+		}
1723
+	}
1724
+
1725
+
1726
+	/**
1727
+	 * delete_payment
1728
+	 *    delete a payment or refund made towards a transaction
1729
+	 *
1730
+	 * @access public
1731
+	 * @return void
1732
+	 */
1733
+	public function delete_payment()
1734
+	{
1735
+		$json_response_data = array('return_data' => false);
1736
+		$PAY_ID             = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0;
1737
+		if ($PAY_ID) {
1738
+			$delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false;
1739
+			$payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
1740
+			if ($payment instanceof EE_Payment) {
1741
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1742
+				/** @type EE_Transaction_Payments $transaction_payments */
1743
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1744
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
1745
+					$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs,
1746
+						$delete_txn_reg_status_change);
1747
+					if ($delete_txn_reg_status_change) {
1748
+						$this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
1749
+						//MAKE sure we also add the delete_txn_req_status_change to the
1750
+						//$_REQUEST global because that's how messages will be looking for it.
1751
+						$_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
1752
+						$this->_maybe_send_notifications();
1753
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
1754
+					}
1755
+				}
1756
+			} else {
1757
+				EE_Error::add_error(
1758
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
1759
+					__FILE__, __FUNCTION__, __LINE__
1760
+				);
1761
+			}
1762
+		} else {
1763
+			EE_Error::add_error(
1764
+				esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.',
1765
+					'event_espresso'),
1766
+				__FILE__, __FUNCTION__, __LINE__
1767
+			);
1768
+		}
1769
+		$notices              = EE_Error::get_notices(false, false, false);
1770
+		$this->_template_args = array(
1771
+			'data'      => $json_response_data,
1772
+			'success'   => $notices['success'],
1773
+			'error'     => $notices['errors'],
1774
+			'attention' => $notices['attention']
1775
+		);
1776
+		$this->_return_json();
1777
+	}
1778
+
1779
+
1780
+	/**
1781
+	 * _registration_payment_data_array
1782
+	 * adds info for 'owing' and 'paid' for each registration to the json response
1783
+	 *
1784
+	 * @access protected
1785
+	 *
1786
+	 * @param array $REG_IDs
1787
+	 *
1788
+	 * @return array
1789
+	 */
1790
+	protected function _registration_payment_data_array($REG_IDs)
1791
+	{
1792
+		$registration_payment_data = array();
1793
+		//if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
1794
+		if ( ! empty($REG_IDs)) {
1795
+			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
1796
+			foreach ($registrations as $registration) {
1797
+				if ($registration instanceof EE_Registration) {
1798
+					$registration_payment_data[$registration->ID()] = array(
1799
+						'paid'  => $registration->pretty_paid(),
1800
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
1801
+					);
1802
+				}
1803
+			}
1804
+		}
1805
+
1806
+		return $registration_payment_data;
1807
+	}
1808
+
1809
+
1810
+	/**
1811
+	 * _maybe_send_notifications
1812
+	 *
1813
+	 * determines whether or not the admin has indicated that notifications should be sent.
1814
+	 * If so, will toggle a filter switch for delivering registration notices.
1815
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
1816
+	 *
1817
+	 * @access protected
1818
+	 *
1819
+	 * @param \EE_Payment | null $payment
1820
+	 */
1821
+	protected function _maybe_send_notifications($payment = null)
1822
+	{
1823
+		switch ($payment instanceof EE_Payment) {
1824
+			// payment notifications
1825
+			case true :
1826
+				if (
1827
+					isset(
1828
+						$this->_req_data['txn_payments'],
1829
+						$this->_req_data['txn_payments']['send_notifications']
1830
+					) &&
1831
+					filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1832
+				) {
1833
+					$this->_process_payment_notification($payment);
1834
+				}
1835
+				break;
1836
+			// registration notifications
1837
+			case false :
1838
+				if (
1839
+					isset(
1840
+						$this->_req_data['txn_reg_status_change'],
1841
+						$this->_req_data['txn_reg_status_change']['send_notifications']
1842
+					) &&
1843
+					filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1844
+				) {
1845
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
1846
+				}
1847
+				break;
1848
+		}
1849
+	}
1850
+
1851
+
1852
+	/**
1853
+	 * _send_payment_reminder
1854
+	 *    generates HTML for the View Transaction Details Admin page
1855
+	 *
1856
+	 * @access protected
1857
+	 * @return void
1858
+	 */
1859
+	protected function _send_payment_reminder()
1860
+	{
1861
+		$TXN_ID      = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
1862
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
1863
+		$query_args  = isset($this->_req_data['redirect_to']) ? array(
1864
+			'action' => $this->_req_data['redirect_to'],
1865
+			'TXN_ID' => $this->_req_data['TXN_ID']
1866
+		) : array();
1867
+		do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
1868
+			$transaction);
1869
+		$this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'),
1870
+			esc_html__('sent', 'event_espresso'), $query_args, true);
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 *  get_transactions
1876
+	 *    get transactions for given parameters (used by list table)
1877
+	 *
1878
+	 * @param  int     $perpage how many transactions displayed per page
1879
+	 * @param  boolean $count   return the count or objects
1880
+	 * @param string   $view
1881
+	 *
1882
+	 * @return mixed int = count || array of transaction objects
1883
+	 */
1884
+	public function get_transactions($perpage, $count = false, $view = '')
1885
+	{
1886
+
1887
+		$TXN = EEM_Transaction::instance();
1888
+
1889
+		$start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y',
1890
+			strtotime('-10 year'));
1891
+		$end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y');
1892
+
1893
+		//make sure our timestamps start and end right at the boundaries for each day
1894
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1895
+		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1896
+
1897
+
1898
+		//convert to timestamps
1899
+		$start_date = strtotime($start_date);
1900
+		$end_date   = strtotime($end_date);
1901
+
1902
+		//makes sure start date is the lowest value and vice versa
1903
+		$start_date = min($start_date, $end_date);
1904
+		$end_date   = max($start_date, $end_date);
1905
+
1906
+		//convert to correct format for query
1907
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1908
+			date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s');
1909
+		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1910
+			date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s');
1911
+
1912
+
1913
+		//set orderby
1914
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1915
+
1916
+		switch ($this->_req_data['orderby']) {
1917
+			case 'TXN_ID':
1918
+				$orderby = 'TXN_ID';
1919
+				break;
1920
+			case 'ATT_fname':
1921
+				$orderby = 'Registration.Attendee.ATT_fname';
1922
+				break;
1923
+			case 'event_name':
1924
+				$orderby = 'Registration.Event.EVT_name';
1925
+				break;
1926
+			default: //'TXN_timestamp'
1927
+				$orderby = 'TXN_timestamp';
1928
+		}
1929
+
1930
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC';
1931
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1932
+		$per_page     = isset($perpage) && ! empty($perpage) ? $perpage : 10;
1933
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
1934
+
1935
+		$offset = ($current_page - 1) * $per_page;
1936
+		$limit  = array($offset, $per_page);
1937
+
1938
+		$_where = array(
1939
+			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
1940
+			'Registration.REG_count' => 1
1941
+		);
1942
+
1943
+		if (isset($this->_req_data['EVT_ID'])) {
1944
+			$_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
1945
+		}
1946
+
1947
+		if (isset($this->_req_data['s'])) {
1948
+			$search_string = '%' . $this->_req_data['s'] . '%';
1949
+			$_where['OR']  = array(
1950
+				'Registration.Event.EVT_name'         => array('LIKE', $search_string),
1951
+				'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
1952
+				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
1953
+				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
1954
+				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
1955
+				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
1956
+				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
1957
+				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
1958
+				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
1959
+				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
1960
+				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
1961
+				'Registration.REG_final_price'        => array('LIKE', $search_string),
1962
+				'Registration.REG_code'               => array('LIKE', $search_string),
1963
+				'Registration.REG_count'              => array('LIKE', $search_string),
1964
+				'Registration.REG_group_size'         => array('LIKE', $search_string),
1965
+				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
1966
+				'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
1967
+				'Payment.PAY_source'                  => array('LIKE', $search_string),
1968
+				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
1969
+				'TXN_session_data'                    => array('LIKE', $search_string),
1970
+				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string)
1971
+			);
1972
+		}
1973
+
1974
+		//failed transactions
1975
+		$failed    = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false;
1976
+		$abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false;
1977
+
1978
+		if ($failed) {
1979
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
1980
+		} else if ($abandoned) {
1981
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
1982
+		} else {
1983
+			$_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
1984
+			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
1985
+		}
1986
+
1987
+		$query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit);
1988
+
1989
+		$transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params);
1990
+
1991
+
1992
+		return $transactions;
1993
+
1994
+	}
1995 1995
 
1996 1996
 
1997 1997
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
     public function load_scripts_styles()
339 339
     {
340 340
         //enqueue style
341
-        wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(),
341
+        wp_register_style('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.css', array(),
342 342
             EVENT_ESPRESSO_VERSION);
343 343
         wp_enqueue_style('espresso_txn');
344 344
         //scripts
345
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
345
+        wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array(
346 346
             'ee_admin_js',
347 347
             'ee-datepicker',
348 348
             'jquery-ui-datepicker',
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 
435 435
         if (empty($this->_transaction)) {
436 436
             $error_msg = esc_html__('An error occurred and the details for Transaction ID #',
437
-                    'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso');
437
+                    'event_espresso').$TXN_ID.esc_html__(' could not be retrieved.', 'event_espresso');
438 438
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
439 439
         }
440 440
     }
@@ -509,23 +509,23 @@  discard block
 block discarded – undo
509 509
             'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
510 510
             array(
511 511
                 'overpaid'   => array(
512
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
512
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code,
513 513
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence')
514 514
                 ),
515 515
                 'complete'   => array(
516
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
516
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code,
517 517
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence')
518 518
                 ),
519 519
                 'incomplete' => array(
520
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
520
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code,
521 521
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence')
522 522
                 ),
523 523
                 'abandoned'  => array(
524
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
524
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code,
525 525
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence')
526 526
                 ),
527 527
                 'failed'     => array(
528
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
528
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code,
529 529
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence')
530 530
                 )
531 531
             )
@@ -547,10 +547,10 @@  discard block
 block discarded – undo
547 547
         $event                                     = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null;
548 548
         $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s',
549 549
             'event_espresso'), '<h3>',
550
-            '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
551
-                EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event',
552
-                'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : '';
553
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
550
+            '<a href="'.EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
551
+                EVENTS_ADMIN_URL).'" title="'.esc_attr__('Click to Edit event',
552
+                'event_espresso').'">'.$event->get('EVT_name').'</a>', '</h3>') : '';
553
+        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
554 554
         $this->display_admin_list_table_page_with_no_sidebar();
555 555
     }
556 556
 
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
 
585 585
         $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
586 586
         $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
587
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
587
+        $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID');
588 588
 
589 589
         $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
590 590
         $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
@@ -621,9 +621,9 @@  discard block
 block discarded – undo
621 621
         $amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
622 622
         $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true);
623 623
         if (EE_Registry::instance()->CFG->currency->sign_b4) {
624
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
624
+            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign.$this->_template_args['amount_due'];
625 625
         } else {
626
-            $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
626
+            $this->_template_args['amount_due'] = $this->_template_args['amount_due'].EE_Registry::instance()->CFG->currency->sign;
627 627
         }
628 628
         $this->_template_args['amount_due_class'] = '';
629 629
 
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 
659 659
 
660 660
         // next link
661
-        $next_txn                                 = $this->_transaction->next(
661
+        $next_txn = $this->_transaction->next(
662 662
             null,
663 663
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
664 664
             'TXN_ID'
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
             )
674 674
             : '';
675 675
         // previous link
676
-        $previous_txn                                 = $this->_transaction->previous(
676
+        $previous_txn = $this->_transaction->previous(
677 677
             null,
678 678
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
679 679
             'TXN_ID'
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
         // grab messages at the last second
728 728
         $this->_template_args['notices'] = EE_Error::get_notices();
729 729
         // path to template
730
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
730
+        $template_path                             = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php';
731 731
         $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
732 732
             $this->_template_args, true);
733 733
 
@@ -835,18 +835,18 @@  discard block
 block discarded – undo
835 835
         $reg_steps = '<ul>';
836 836
         foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
837 837
             if ($reg_step_status === true) {
838
-                $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
839
-                        ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
838
+                $reg_steps .= '<li style="color:#70cc50">'.sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
839
+                        ucwords(str_replace('_', ' ', $reg_step))).'</li>';
840 840
             } else if (is_numeric($reg_step_status) && $reg_step_status !== false) {
841
-                $reg_steps .= '<li style="color:#2EA2CC">' . sprintf(
841
+                $reg_steps .= '<li style="color:#2EA2CC">'.sprintf(
842 842
                         esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
843 843
                         ucwords(str_replace('_', ' ', $reg_step)),
844
-                        date(get_option('date_format') . ' ' . get_option('time_format'),
844
+                        date(get_option('date_format').' '.get_option('time_format'),
845 845
                             ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)))
846
-                    ) . '</li>';
846
+                    ).'</li>';
847 847
             } else {
848
-                $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated',
849
-                        'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
848
+                $reg_steps .= '<li style="color:#E76700">'.sprintf(esc_html__('%1$s : Never Initiated',
849
+                        'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))).'</li>';
850 850
             }
851 851
         }
852 852
         $reg_steps .= '</ul>';
@@ -860,11 +860,11 @@  discard block
 block discarded – undo
860 860
         $this->_get_payment_status_array();
861 861
         $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
862 862
 
863
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
863
+        $this->_template_args['transaction_form_url'] = add_query_arg(array(
864 864
             'action'  => 'edit_transaction',
865 865
             'process' => 'transaction'
866 866
         ), TXN_ADMIN_URL);
867
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
867
+        $this->_template_args['apply_payment_form_url'] = add_query_arg(array(
868 868
             'page'   => 'espresso_transactions',
869 869
             'action' => 'espresso_apply_payment'
870 870
         ), WP_AJAX_URL);
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
 
876 876
         // 'espresso_delete_payment_nonce'
877 877
 
878
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
878
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php';
879 879
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
880 880
 
881 881
     }
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
     protected function _get_registrations_to_apply_payment_to()
936 936
     {
937 937
         // we want any registration with an active status (ie: not deleted or cancelled)
938
-        $query_params                      = array(
938
+        $query_params = array(
939 939
             array(
940 940
                 'STS_ID' => array(
941 941
                     'IN',
@@ -947,19 +947,19 @@  discard block
 block discarded – undo
947 947
                 )
948 948
             )
949 949
         );
950
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
950
+        $registrations_to_apply_payment_to = EEH_HTML::br().EEH_HTML::div(
951 951
                 '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;'
952 952
             );
953
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
953
+        $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
954 954
         $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
955 955
         $registrations_to_apply_payment_to .= EEH_HTML::thead(
956 956
             EEH_HTML::tr(
957
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
958
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
959
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
960
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
961
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
962
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
957
+                EEH_HTML::th(esc_html__('ID', 'event_espresso')).
958
+                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')).
959
+                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')).
960
+                EEH_HTML::th(esc_html__('Event', 'event_espresso')).
961
+                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr').
962
+                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr').
963 963
                 EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
964 964
             )
965 965
         );
@@ -973,28 +973,28 @@  discard block
 block discarded – undo
973 973
                     : esc_html__('Unknown Attendee', 'event_espresso');
974 974
                 $owing         = $registration->final_price() - $registration->paid();
975 975
                 $taxable       = $registration->ticket()->taxable()
976
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
976
+                    ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>'
977 977
                     : '';
978 978
                 $checked       = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
979 979
                     ? ' checked="checked"'
980 980
                     : '';
981 981
                 $disabled      = $registration->final_price() > 0 ? '' : ' disabled';
982 982
                 $registrations_to_apply_payment_to .= EEH_HTML::tr(
983
-                    EEH_HTML::td($registration->ID()) .
984
-                    EEH_HTML::td($attendee_name) .
983
+                    EEH_HTML::td($registration->ID()).
984
+                    EEH_HTML::td($attendee_name).
985 985
                     EEH_HTML::td(
986
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
987
-                    ) .
988
-                    EEH_HTML::td($registration->event_name()) .
989
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
990
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
986
+                        $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable
987
+                    ).
988
+                    EEH_HTML::td($registration->event_name()).
989
+                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr').
990
+                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr').
991 991
                     EEH_HTML::td(
992
-                        '<input type="checkbox" value="' . $registration->ID()
992
+                        '<input type="checkbox" value="'.$registration->ID()
993 993
                         . '" name="txn_admin_payment[registrations]"'
994
-                        . $checked . $disabled . '>',
994
+                        . $checked.$disabled.'>',
995 995
                         '', 'jst-cntr'
996 996
                     ),
997
-                    'apply-payment-registration-row-' . $registration->ID()
997
+                    'apply-payment-registration-row-'.$registration->ID()
998 998
                 );
999 999
             }
1000 1000
         }
@@ -1060,12 +1060,12 @@  discard block
 block discarded – undo
1060 1060
                 array(
1061 1061
                     'OR*payment_method_for_payment' => array(
1062 1062
                         'PMD_ID'    => array('IN', $payment_methods_of_payments),
1063
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')
1063
+                        'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%')
1064 1064
                     )
1065 1065
                 )
1066 1066
             );
1067 1067
         } else {
1068
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1068
+            $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%')));
1069 1069
         }
1070 1070
         $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1071 1071
     }
@@ -1110,7 +1110,7 @@  discard block
 block discarded – undo
1110 1110
                                 EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1111 1111
                                 $event_name = esc_html__('Unknown Event', 'event_espresso');
1112 1112
                             }
1113
-                            $event_name .= ' - ' . $item->get('LIN_name');
1113
+                            $event_name .= ' - '.$item->get('LIN_name');
1114 1114
                             $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1115 1115
                             // now get all of the registrations for this transaction that use this ticket
1116 1116
                             $registrations = $ticket->get_many_related('Registration',
@@ -1128,8 +1128,8 @@  discard block
 block discarded – undo
1128 1128
                                 if ($attendee instanceof EE_Attendee) {
1129 1129
                                     $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = $attendee->ID();
1130 1130
                                     $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name();
1131
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event',
1132
-                                            'event_espresso') . '">' . $attendee->email() . '</a>';
1131
+                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:'.$attendee->email().'?subject='.$event_name.esc_html__(' Event',
1132
+                                            'event_espresso').'">'.$attendee->email().'</a>';
1133 1133
                                     $this->_template_args['event_attendees'][$registration->ID()]['address']  = EEH_Address::format($attendee,
1134 1134
                                         'inline', false, false);
1135 1135
                                 } else {
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
                 'action'  => 'edit_transaction',
1150 1150
                 'process' => 'attendees'
1151 1151
             ), TXN_ADMIN_URL);
1152
-            echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1152
+            echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php',
1153 1153
                 $this->_template_args, true);
1154 1154
 
1155 1155
         } else {
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
         ), REG_ADMIN_URL);
1191 1191
         // get formatted address for registrant
1192 1192
         $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1193
-        echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1193
+        echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php',
1194 1194
             $this->_template_args, true);
1195 1195
     }
1196 1196
 
@@ -1211,8 +1211,8 @@  discard block
 block discarded – undo
1211 1211
             TXN_ADMIN_URL
1212 1212
         );
1213 1213
 
1214
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1215
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1214
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php';
1215
+        echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/
1216 1216
     }
1217 1217
 
1218 1218
 
@@ -1505,7 +1505,7 @@  discard block
 block discarded – undo
1505 1505
         $REG_IDs = array();
1506 1506
         // grab array of IDs for specific registrations to apply changes to
1507 1507
         if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1508
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1508
+            $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1509 1509
         }
1510 1510
         //nothing specified ? then get all reg IDs
1511 1511
         if (empty($REG_IDs)) {
@@ -1891,8 +1891,8 @@  discard block
 block discarded – undo
1891 1891
         $end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y');
1892 1892
 
1893 1893
         //make sure our timestamps start and end right at the boundaries for each day
1894
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1895
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1894
+        $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
1895
+        $end_date   = date('Y-m-d', strtotime($end_date)).' 23:59:59';
1896 1896
 
1897 1897
 
1898 1898
         //convert to timestamps
@@ -1945,7 +1945,7 @@  discard block
 block discarded – undo
1945 1945
         }
1946 1946
 
1947 1947
         if (isset($this->_req_data['s'])) {
1948
-            $search_string = '%' . $this->_req_data['s'] . '%';
1948
+            $search_string = '%'.$this->_req_data['s'].'%';
1949 1949
             $_where['OR']  = array(
1950 1950
                 'Registration.Event.EVT_name'         => array('LIKE', $search_string),
1951 1951
                 'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 2 patches
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475 475
         $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476 476
         global $ee_menu_slugs;
477
-        $ee_menu_slugs = (array)$ee_menu_slugs;
477
+        $ee_menu_slugs = (array) $ee_menu_slugs;
478 478
         if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479 479
             return;
480 480
         }
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490 490
         $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491 491
         $this->_current_view = $this->_req_action;
492
-        $this->_req_nonce = $this->_req_action . '_nonce';
492
+        $this->_req_nonce = $this->_req_action.'_nonce';
493 493
         $this->_define_page_props();
494 494
         $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495 495
         //default things
@@ -510,11 +510,11 @@  discard block
 block discarded – undo
510 510
             $this->_extend_page_config_for_cpt();
511 511
         }
512 512
         //filter routes and page_config so addons can add their stuff. Filtering done per class
513
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
513
+        $this->_page_routes = apply_filters('FHEE__'.get_class($this).'__page_setup__page_routes', $this->_page_routes, $this);
514
+        $this->_page_config = apply_filters('FHEE__'.get_class($this).'__page_setup__page_config', $this->_page_config, $this);
515 515
         //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
516
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
517
+            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), 10, 2);
518 518
         }
519 519
         //next route only if routing enabled
520 520
         if ($this->_routing && ! defined('DOING_AJAX')) {
@@ -524,8 +524,8 @@  discard block
 block discarded – undo
524 524
             if ($this->_is_UI_request) {
525 525
                 //admin_init stuff - global, all views for this page class, specific view
526 526
                 add_action('admin_init', array($this, 'admin_init'), 10);
527
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
527
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
528
+                    add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15);
529 529
                 }
530 530
             } else {
531 531
                 //hijack regular WP loading and route admin request immediately
@@ -545,17 +545,17 @@  discard block
 block discarded – undo
545 545
      */
546 546
     private function _do_other_page_hooks()
547 547
     {
548
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
548
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array());
549 549
         foreach ($registered_pages as $page) {
550 550
             //now let's setup the file name and class that should be present
551 551
             $classname = str_replace('.class.php', '', $page);
552 552
             //autoloaders should take care of loading file
553 553
             if ( ! class_exists($classname)) {
554
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
554
+                $error_msg[] = sprintf(esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555 555
                 $error_msg[] = $error_msg[0]
556 556
                                . "\r\n"
557
-                               . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
557
+                               . sprintf(esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
+                                'event_espresso'), $page, '<br />', '<strong>'.$classname.'</strong>');
559 559
                 throw new EE_Error(implode('||', $error_msg));
560 560
             }
561 561
             $a = new ReflectionClass($classname);
@@ -591,13 +591,13 @@  discard block
 block discarded – undo
591 591
         //load admin_notices - global, page class, and view specific
592 592
         add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593 593
         add_action('admin_notices', array($this, 'admin_notices'), 10);
594
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
594
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
595
+            add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15);
596 596
         }
597 597
         //load network admin_notices - global, page class, and view specific
598 598
         add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
599
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
600
+            add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view));
601 601
         }
602 602
         //this will save any per_page screen options if they are present
603 603
         $this->_set_per_page_screen_options();
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
         //add screen options - global, page child class, and view specific
610 610
         $this->_add_global_screen_options();
611 611
         $this->_add_screen_options();
612
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
612
+        if (method_exists($this, '_add_screen_options_'.$this->_current_view)) {
613
+            call_user_func(array($this, '_add_screen_options_'.$this->_current_view));
614 614
         }
615 615
         //add help tab(s) and tours- set via page_config and qtips.
616 616
         $this->_add_help_tour();
@@ -619,31 +619,31 @@  discard block
 block discarded – undo
619 619
         //add feature_pointers - global, page child class, and view specific
620 620
         $this->_add_feature_pointers();
621 621
         $this->_add_global_feature_pointers();
622
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
622
+        if (method_exists($this, '_add_feature_pointer_'.$this->_current_view)) {
623
+            call_user_func(array($this, '_add_feature_pointer_'.$this->_current_view));
624 624
         }
625 625
         //enqueue scripts/styles - global, page class, and view specific
626 626
         add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627 627
         add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
628
+        if (method_exists($this, 'load_scripts_styles_'.$this->_current_view)) {
629
+            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_'.$this->_current_view), 15);
630 630
         }
631 631
         add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632 632
         //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633 633
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634 634
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
635
+        if (method_exists($this, 'admin_footer_scripts_'.$this->_current_view)) {
636
+            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_'.$this->_current_view), 101);
637 637
         }
638 638
         //admin footer scripts
639 639
         add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640 640
         add_action('admin_footer', array($this, 'admin_footer'), 100);
641
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
641
+        if (method_exists($this, 'admin_footer_'.$this->_current_view)) {
642
+            add_action('admin_footer', array($this, 'admin_footer_'.$this->_current_view), 101);
643 643
         }
644 644
         do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645 645
         //targeted hook
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
646
+        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__'.$this->page_slug.'__'.$this->_req_action);
647 647
     }
648 648
 
649 649
 
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
             // user error msg
720 720
             $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721 721
             // developer error msg
722
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
722
+            $error_msg .= '||'.$error_msg.__(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723 723
             throw new EE_Error($error_msg);
724 724
         }
725 725
         // and that the requested page route exists
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
             // user error msg
731 731
             $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732 732
             // developer error msg
733
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
733
+            $error_msg .= '||'.$error_msg.sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734 734
             throw new EE_Error($error_msg);
735 735
         }
736 736
         // and that a default route exists
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
             // user error msg
739 739
             $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740 740
             // developer error msg
741
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
741
+            $error_msg .= '||'.$error_msg.__(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742 742
             throw new EE_Error($error_msg);
743 743
         }
744 744
         //first lets' catch if the UI request has EVER been set.
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
             // user error msg
768 768
             $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769 769
             // developer error msg
770
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
770
+            $error_msg .= '||'.$error_msg.sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771 771
             throw new EE_Error($error_msg);
772 772
         }
773 773
     }
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             // these are not the droids you are looking for !!!
790 790
             $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791 791
             if (WP_DEBUG) {
792
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
792
+                $msg .= "\n  ".sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793 793
             }
794 794
             if ( ! defined('DOING_AJAX')) {
795 795
                 wp_die($msg);
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
                 if (strpos($key, 'nonce') !== false) {
968 968
                     continue;
969 969
                 }
970
-                $args['wp_referer[' . $key . ']'] = $value;
970
+                $args['wp_referer['.$key.']'] = $value;
971 971
             }
972 972
         }
973 973
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
                     if ($tour instanceof EE_Help_Tour_final_stop) {
1014 1014
                         continue;
1015 1015
                     }
1016
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1016
+                    $tb[] = '<button id="trigger-tour-'.$tour->get_slug().'" class="button-primary trigger-ee-help-tour">'.$tour->get_label().'</button>';
1017 1017
                 }
1018 1018
                 $tour_buttons .= implode('<br />', $tb);
1019 1019
                 $tour_buttons .= '</div></div>';
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
                     throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1026 1026
                             'event_espresso'), $config['help_sidebar'], get_class($this)));
1027 1027
                 }
1028
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1028
+                $content = apply_filters('FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029 1029
                 $content .= $tour_buttons; //add help tour buttons.
1030 1030
                 //do we have any help tours setup?  Cause if we do we want to add the buttons
1031 1031
                 $this->_current_screen->set_help_sidebar($content);
@@ -1038,13 +1038,13 @@  discard block
 block discarded – undo
1038 1038
             if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039 1039
                 $_ht['id'] = $this->page_slug;
1040 1040
                 $_ht['title'] = __('Help Tours', 'event_espresso');
1041
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1041
+                $_ht['content'] = '<p>'.__('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso').'</p>';
1042 1042
                 $this->_current_screen->add_help_tab($_ht);
1043 1043
             }/**/
1044 1044
             if ( ! isset($config['help_tabs'])) {
1045 1045
                 return;
1046 1046
             } //no help tabs for this route
1047
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1047
+            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1048 1048
                 //we're here so there ARE help tabs!
1049 1049
                 //make sure we've got what we need
1050 1050
                 if ( ! isset($cfg['title'])) {
@@ -1059,9 +1059,9 @@  discard block
 block discarded – undo
1059 1059
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060 1060
                     //second priority goes to filename
1061 1061
                 } else if ( ! empty($cfg['filename'])) {
1062
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1062
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1063 1063
                     //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1064
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1064
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tabs/'.$cfg['filename'].'.help_tab.php' : $file_path;
1065 1065
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066 1066
                     if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067 1067
                         EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
                     return;
1081 1081
                 }
1082 1082
                 //setup config array for help tab method
1083
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1083
+                $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1084 1084
                 $_ht = array(
1085 1085
                         'id'       => $id,
1086 1086
                         'title'    => $cfg['title'],
@@ -1118,9 +1118,9 @@  discard block
 block discarded – undo
1118 1118
             }
1119 1119
             if (isset($config['help_tour'])) {
1120 1120
                 foreach ($config['help_tour'] as $tour) {
1121
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1121
+                    $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php';
1122 1122
                     //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1123
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tours/'.$tour.'.class.php' : $file_path;
1124 1124
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125 1125
                     if ( ! is_readable($file_path)) {
1126 1126
                         EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
                     require_once $file_path;
1131 1131
                     if ( ! class_exists($tour)) {
1132 1132
                         $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1133
+                        $error_msg[] = $error_msg[0]."\r\n".sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1134 1134
                                         'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135 1135
                         throw new EE_Error(implode('||', $error_msg));
1136 1136
                     }
@@ -1162,11 +1162,11 @@  discard block
 block discarded – undo
1162 1162
     protected function _add_qtips()
1163 1163
     {
1164 1164
         if (isset($this->_route_config['qtips'])) {
1165
-            $qtips = (array)$this->_route_config['qtips'];
1165
+            $qtips = (array) $this->_route_config['qtips'];
1166 1166
             //load qtip loader
1167 1167
             $path = array(
1168
-                    $this->_get_dir() . '/qtips/',
1169
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1168
+                    $this->_get_dir().'/qtips/',
1169
+                    EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1170 1170
             );
1171 1171
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1172 1172
         }
@@ -1196,11 +1196,11 @@  discard block
 block discarded – undo
1196 1196
             if ( ! $this->check_user_access($slug, true)) {
1197 1197
                 continue;
1198 1198
             } //no nav tab becasue current user does not have access.
1199
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1199
+            $css_class = isset($config['css_class']) ? $config['css_class'].' ' : '';
1200 1200
             $this->_nav_tabs[$slug] = array(
1201 1201
                     'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202 1202
                     'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1203
+                    'css_class' => $this->_req_action == $slug ? $css_class.'nav-tab-active' : $css_class,
1204 1204
                     'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205 1205
             );
1206 1206
             $i++;
@@ -1263,11 +1263,11 @@  discard block
 block discarded – undo
1263 1263
             $capability = empty($capability) ? 'manage_options' : $capability;
1264 1264
         }
1265 1265
         $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1266
+        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug.'_'.$route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267 1267
             if ($verify_only) {
1268 1268
                 return false;
1269 1269
             } else {
1270
-                if ( is_user_logged_in() ) {
1270
+                if (is_user_logged_in()) {
1271 1271
                     wp_die(__('You do not have access to this route.', 'event_espresso'));
1272 1272
                 } else {
1273 1273
                     return false;
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
     public function admin_footer_global()
1360 1360
     {
1361 1361
         //dialog container for dialog helper
1362
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1362
+        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n";
1363 1363
         $d_cont .= '<div class="ee-notices"></div>';
1364 1364
         $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365 1365
         $d_cont .= '</div>';
@@ -1369,7 +1369,7 @@  discard block
 block discarded – undo
1369 1369
             echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370 1370
         }
1371 1371
         //current set timezone for timezone js
1372
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1372
+        echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>';
1373 1373
     }
1374 1374
 
1375 1375
 
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
     {
1395 1395
         $content = '';
1396 1396
         $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1397
+        $template_path = EE_ADMIN_TEMPLATE.'admin_help_popup.template.php';
1398 1398
         //loop through the array and setup content
1399 1399
         foreach ($help_array as $trigger => $help) {
1400 1400
             //make sure the array is setup properly
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
     private function _get_help_content()
1429 1429
     {
1430 1430
         //what is the method we're looking for?
1431
-        $method_name = '_help_popup_content_' . $this->_req_action;
1431
+        $method_name = '_help_popup_content_'.$this->_req_action;
1432 1432
         //if method doesn't exist let's get out.
1433 1433
         if ( ! method_exists($this, $method_name)) {
1434 1434
             return array();
@@ -1472,8 +1472,8 @@  discard block
 block discarded – undo
1472 1472
             $help_content = $this->_set_help_popup_content($help_array, false);
1473 1473
         }
1474 1474
         //let's setup the trigger
1475
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
-        $content = $content . $help_content;
1475
+        $content = '<a class="ee-dialog" href="?height='.$dimensions[0].'&width='.$dimensions[1].'&inlineId='.$trigger_id.'" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
+        $content = $content.$help_content;
1477 1477
         if ($display) {
1478 1478
             echo $content;
1479 1479
         } else {
@@ -1533,27 +1533,27 @@  discard block
 block discarded – undo
1533 1533
             add_action('admin_head', array($this, 'add_xdebug_style'));
1534 1534
         }
1535 1535
         // register all styles
1536
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1536
+        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
+        wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538 1538
         //helpers styles
1539
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1539
+        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540 1540
         /** SCRIPTS **/
1541 1541
         //register all scripts
1542
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1542
+        wp_register_script('ee-dialog', EE_ADMIN_URL.'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
+        wp_register_script('ee_admin_js', EE_ADMIN_URL.'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
+        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1545 1545
         add_filter('FHEE_load_joyride', '__return_true');
1546 1546
         //script for sorting tables
1547
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1547
+        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL."assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1548 1548
         //script for parsing uri's
1549
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1549
+        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1550 1550
         //and parsing associative serialized form elements
1551
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1551
+        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1552 1552
         //helpers scripts
1553
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1553
+        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
+        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
+        wp_register_script('ee-moment', EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
+        wp_register_script('ee-datepicker', EE_ADMIN_URL.'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1557 1557
         //google charts
1558 1558
         wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1559 1559
         // ENQUEUE ALL BASICS BY DEFAULT
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
          */
1578 1578
         if ( ! empty($this->_help_tour)) {
1579 1579
             //register the js for kicking things off
1580
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1580
+            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL.'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1581 1581
             //setup tours for the js tour object
1582 1582
             foreach ($this->_help_tour['tours'] as $tour) {
1583 1583
                 $tours[] = array(
@@ -1672,17 +1672,17 @@  discard block
 block discarded – undo
1672 1672
             return;
1673 1673
         } //not a list_table view so get out.
1674 1674
         //list table functions are per view specific (because some admin pages might have more than one listtable!)
1675
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1675
+        if (call_user_func(array($this, '_set_list_table_views_'.$this->_req_action)) === false) {
1676 1676
             //user error msg
1677 1677
             $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1678 1678
             //developer error msg
1679
-            $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1680
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1679
+            $error_msg .= '||'.sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1680
+                            $this->_req_action, '_set_list_table_views_'.$this->_req_action);
1681 1681
             throw new EE_Error($error_msg);
1682 1682
         }
1683 1683
         //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1684
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1685
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1684
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, $this->_views);
1685
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
1686 1686
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1687 1687
         $this->_set_list_table_view();
1688 1688
         $this->_set_list_table_object();
@@ -1757,7 +1757,7 @@  discard block
 block discarded – undo
1757 1757
             // check for current view
1758 1758
             $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1759 1759
             $query_args['action'] = $this->_req_action;
1760
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1760
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
1761 1761
             $query_args['status'] = $view['slug'];
1762 1762
             //merge any other arguments sent in.
1763 1763
             if (isset($extra_query_args[$view['slug']])) {
@@ -1795,14 +1795,14 @@  discard block
 block discarded – undo
1795 1795
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1796 1796
         foreach ($values as $value) {
1797 1797
             if ($value < $max_entries) {
1798
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1798
+                $selected = $value == $per_page ? ' selected="'.$per_page.'"' : '';
1799 1799
                 $entries_per_page_dropdown .= '
1800
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1800
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
1801 1801
             }
1802 1802
         }
1803
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1803
+        $selected = $max_entries == $per_page ? ' selected="'.$per_page.'"' : '';
1804 1804
         $entries_per_page_dropdown .= '
1805
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1805
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
1806 1806
         $entries_per_page_dropdown .= '
1807 1807
 					</select>
1808 1808
 					entries
@@ -1824,7 +1824,7 @@  discard block
 block discarded – undo
1824 1824
     public function _set_search_attributes()
1825 1825
     {
1826 1826
         $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1827
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1827
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
1828 1828
     }
1829 1829
 
1830 1830
     /*** END LIST TABLE METHODS **/
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
                     // user error msg
1863 1863
                     $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1864 1864
                     // developer error msg
1865
-                    $error_msg .= '||' . sprintf(
1865
+                    $error_msg .= '||'.sprintf(
1866 1866
                                     __(
1867 1867
                                             'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1868 1868
                                             'event_espresso'
@@ -1892,15 +1892,15 @@  discard block
 block discarded – undo
1892 1892
                 && is_array($this->_route_config['columns'])
1893 1893
                 && count($this->_route_config['columns']) === 2
1894 1894
         ) {
1895
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1895
+            add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1]));
1896 1896
             $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1897 1897
             $screen_id = $this->_current_screen->id;
1898
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1898
+            $screen_columns = (int) get_user_option("screen_layout_$screen_id");
1899 1899
             $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1900
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1900
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
1901 1901
             $this->_template_args['current_page'] = $this->_wp_page_slug;
1902 1902
             $this->_template_args['screen'] = $this->_current_screen;
1903
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1903
+            $this->_column_template_path = EE_ADMIN_TEMPLATE.'admin_details_metabox_column_wrapper.template.php';
1904 1904
             //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1905 1905
             $this->_route_config['has_metaboxes'] = true;
1906 1906
         }
@@ -1947,7 +1947,7 @@  discard block
 block discarded – undo
1947 1947
      */
1948 1948
     public function espresso_ratings_request()
1949 1949
     {
1950
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1950
+        $template_path = EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php';
1951 1951
         EEH_Template::display_template($template_path, array());
1952 1952
     }
1953 1953
 
@@ -1955,18 +1955,18 @@  discard block
 block discarded – undo
1955 1955
 
1956 1956
     public static function cached_rss_display($rss_id, $url)
1957 1957
     {
1958
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1958
+        $loading = '<p class="widget-loading hide-if-no-js">'.__('Loading&#8230;').'</p><p class="hide-if-js">'.__('This widget requires JavaScript.').'</p>';
1959 1959
         $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1960
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1961
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1962
-        $post = '</div>' . "\n";
1963
-        $cache_key = 'ee_rss_' . md5($rss_id);
1960
+        $pre = '<div class="espresso-rss-display">'."\n\t";
1961
+        $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>';
1962
+        $post = '</div>'."\n";
1963
+        $cache_key = 'ee_rss_'.md5($rss_id);
1964 1964
         if (false != ($output = get_transient($cache_key))) {
1965
-            echo $pre . $output . $post;
1965
+            echo $pre.$output.$post;
1966 1966
             return true;
1967 1967
         }
1968 1968
         if ( ! $doing_ajax) {
1969
-            echo $pre . $loading . $post;
1969
+            echo $pre.$loading.$post;
1970 1970
             return false;
1971 1971
         }
1972 1972
         ob_start();
@@ -2025,7 +2025,7 @@  discard block
 block discarded – undo
2025 2025
 
2026 2026
     public function espresso_sponsors_post_box()
2027 2027
     {
2028
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2028
+        $templatepath = EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php';
2029 2029
         EEH_Template::display_template($templatepath);
2030 2030
     }
2031 2031
 
@@ -2033,7 +2033,7 @@  discard block
 block discarded – undo
2033 2033
 
2034 2034
     private function _publish_post_box()
2035 2035
     {
2036
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2036
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2037 2037
         //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2038 2038
         if ( ! empty($this->_labels['publishbox'])) {
2039 2039
             $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
@@ -2050,7 +2050,7 @@  discard block
 block discarded – undo
2050 2050
     {
2051 2051
         //if we have extra content set let's add it in if not make sure its empty
2052 2052
         $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2053
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2053
+        $template_path = EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php';
2054 2054
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2055 2055
     }
2056 2056
 
@@ -2219,7 +2219,7 @@  discard block
 block discarded – undo
2219 2219
         //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2220 2220
         $call_back_func = $create_func ? create_function('$post, $metabox',
2221 2221
                 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2222
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2222
+        add_meta_box(str_replace('_', '-', $action).'-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2223 2223
     }
2224 2224
 
2225 2225
 
@@ -2299,10 +2299,10 @@  discard block
 block discarded – undo
2299 2299
                 ? 'poststuff'
2300 2300
                 : 'espresso-default-admin';
2301 2301
         $template_path = $sidebar
2302
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2303
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2302
+                ? EE_ADMIN_TEMPLATE.'admin_details_wrapper.template.php'
2303
+                : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2304 2304
         if (defined('DOING_AJAX') && DOING_AJAX) {
2305
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2305
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2306 2306
         }
2307 2307
         $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2308 2308
         $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
@@ -2348,7 +2348,7 @@  discard block
 block discarded – undo
2348 2348
                         true
2349 2349
                 )
2350 2350
                 : $this->_template_args['preview_action_button'];
2351
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2351
+        $template_path = EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php';
2352 2352
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2353 2353
                 $template_path,
2354 2354
                 $this->_template_args,
@@ -2399,7 +2399,7 @@  discard block
 block discarded – undo
2399 2399
         //setup search attributes
2400 2400
         $this->_set_search_attributes();
2401 2401
         $this->_template_args['current_page'] = $this->_wp_page_slug;
2402
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2402
+        $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2403 2403
         $this->_template_args['table_url'] = defined('DOING_AJAX')
2404 2404
                 ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2405 2405
                 : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
@@ -2409,29 +2409,29 @@  discard block
 block discarded – undo
2409 2409
         $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2410 2410
         if ( ! empty($ajax_sorting_callback)) {
2411 2411
             $sortable_list_table_form_fields = wp_nonce_field(
2412
-                    $ajax_sorting_callback . '_nonce',
2413
-                    $ajax_sorting_callback . '_nonce',
2412
+                    $ajax_sorting_callback.'_nonce',
2413
+                    $ajax_sorting_callback.'_nonce',
2414 2414
                     false,
2415 2415
                     false
2416 2416
             );
2417 2417
             //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2418 2418
             //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2419
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2420
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2419
+            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'.$this->page_slug.'" />';
2420
+            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'.$ajax_sorting_callback.'" />';
2421 2421
         } else {
2422 2422
             $sortable_list_table_form_fields = '';
2423 2423
         }
2424 2424
         $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2425 2425
         $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2426
-        $nonce_ref = $this->_req_action . '_nonce';
2427
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2426
+        $nonce_ref = $this->_req_action.'_nonce';
2427
+        $hidden_form_fields .= '<input type="hidden" name="'.$nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">';
2428 2428
         $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2429 2429
         //display message about search results?
2430 2430
         $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2431
-                ? '<p class="ee-search-results">' . sprintf(
2431
+                ? '<p class="ee-search-results">'.sprintf(
2432 2432
                         esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2433 2433
                         trim($this->_req_data['s'], '%')
2434
-                ) . '</p>'
2434
+                ).'</p>'
2435 2435
                 : '';
2436 2436
         // filter before_list_table template arg
2437 2437
         $this->_template_args['before_list_table'] = apply_filters(
@@ -2505,8 +2505,8 @@  discard block
 block discarded – undo
2505 2505
      */
2506 2506
     protected function _display_legend($items)
2507 2507
     {
2508
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2509
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2508
+        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array) $items, $this);
2509
+        $legend_template = EE_ADMIN_TEMPLATE.'admin_details_legend.template.php';
2510 2510
         return EEH_Template::display_template($legend_template, $this->_template_args, true);
2511 2511
     }
2512 2512
 
@@ -2598,15 +2598,15 @@  discard block
 block discarded – undo
2598 2598
         $this->_nav_tabs = $this->_get_main_nav_tabs();
2599 2599
         $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2600 2600
         $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2601
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2601
+        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content'.$this->_current_page.$this->_current_view,
2602 2602
                 isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2603
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2603
+        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content'.$this->_current_page.$this->_current_view,
2604 2604
                 isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2605 2605
         $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2606 2606
         // load settings page wrapper template
2607
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2607
+        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE.'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php';
2608 2608
         //about page?
2609
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2609
+        $template_path = $about ? EE_ADMIN_TEMPLATE.'about_admin_wrapper.template.php' : $template_path;
2610 2610
         if (defined('DOING_AJAX')) {
2611 2611
             $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2612 2612
             $this->_return_json();
@@ -2678,20 +2678,20 @@  discard block
 block discarded – undo
2678 2678
     protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2679 2679
     {
2680 2680
         //make sure $text and $actions are in an array
2681
-        $text = (array)$text;
2682
-        $actions = (array)$actions;
2681
+        $text = (array) $text;
2682
+        $actions = (array) $actions;
2683 2683
         $referrer_url = empty($referrer) ? '' : $referrer;
2684
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2685
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2684
+        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$_SERVER['REQUEST_URI'].'" />'
2685
+                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$referrer.'" />';
2686 2686
         $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2687 2687
         $default_names = array('save', 'save_and_close');
2688 2688
         //add in a hidden index for the current page (so save and close redirects properly)
2689 2689
         $this->_template_args['save_buttons'] = $referrer_url;
2690 2690
         foreach ($button_text as $key => $button) {
2691 2691
             $ref = $default_names[$key];
2692
-            $id = $this->_current_view . '_' . $ref;
2692
+            $id = $this->_current_view.'_'.$ref;
2693 2693
             $name = ! empty($actions) ? $actions[$key] : $ref;
2694
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2694
+            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '.$ref.'" value="'.$button.'" name="'.$name.'" id="'.$id.'" />';
2695 2695
             if ( ! $both) {
2696 2696
                 break;
2697 2697
             }
@@ -2727,15 +2727,15 @@  discard block
 block discarded – undo
2727 2727
     {
2728 2728
         if (empty($route)) {
2729 2729
             $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2730
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2730
+            $dev_msg = $user_msg."\n".sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
2732 2732
         }
2733 2733
         // open form
2734
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2734
+        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'.$this->_admin_base_url.'" id="'.$route.'_event_form" >';
2735 2735
         // add nonce
2736
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2736
+        $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
2737 2737
         //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2738
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2738
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
2739 2739
         // add REQUIRED form action
2740 2740
         $hidden_fields = array(
2741 2741
                 'action' => array('type' => 'hidden', 'value' => $route),
@@ -2745,8 +2745,8 @@  discard block
 block discarded – undo
2745 2745
         // generate form fields
2746 2746
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2747 2747
         // add fields to form
2748
-        foreach ((array)$form_fields as $field_name => $form_field) {
2749
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2748
+        foreach ((array) $form_fields as $field_name => $form_field) {
2749
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
2750 2750
         }
2751 2751
         // close form
2752 2752
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -2827,7 +2827,7 @@  discard block
 block discarded – undo
2827 2827
          * @param array $query_args       The original query_args array coming into the
2828 2828
          *                                method.
2829 2829
          */
2830
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2830
+        do_action('AHEE__'.$classname.'___redirect_after_action__before_redirect_modification_'.$this->_req_action, $query_args);
2831 2831
         //calculate where we're going (if we have a "save and close" button pushed)
2832 2832
         if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2833 2833
             // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
@@ -2843,7 +2843,7 @@  discard block
 block discarded – undo
2843 2843
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
2844 2844
                 //is there a wp_referer array in our _default_route_query_args property?
2845 2845
                 if ($query_param == 'wp_referer') {
2846
-                    $query_value = (array)$query_value;
2846
+                    $query_value = (array) $query_value;
2847 2847
                     foreach ($query_value as $reference => $value) {
2848 2848
                         if (strpos($reference, 'nonce') !== false) {
2849 2849
                             continue;
@@ -2869,11 +2869,11 @@  discard block
 block discarded – undo
2869 2869
         // if redirecting to anything other than the main page, add a nonce
2870 2870
         if (isset($query_args['action'])) {
2871 2871
             // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2872
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2872
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
2873 2873
         }
2874 2874
         //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2875
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2876
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2875
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
2876
+        $redirect_url = apply_filters('FHEE_redirect_'.$classname.$this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2877 2877
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2878 2878
         if (defined('DOING_AJAX')) {
2879 2879
             $default_data = array(
@@ -3003,7 +3003,7 @@  discard block
 block discarded – undo
3003 3003
         $args = array(
3004 3004
                 'label'   => $this->_admin_page_title,
3005 3005
                 'default' => 10,
3006
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3006
+                'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3007 3007
         );
3008 3008
         //ONLY add the screen option if the user has access to it.
3009 3009
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3036,8 +3036,8 @@  discard block
 block discarded – undo
3036 3036
             $map_option = $option;
3037 3037
             $option = str_replace('-', '_', $option);
3038 3038
             switch ($map_option) {
3039
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3040
-                    $value = (int)$value;
3039
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3040
+                    $value = (int) $value;
3041 3041
                     if ($value < 1 || $value > 999) {
3042 3042
                         return;
3043 3043
                     }
@@ -3064,7 +3064,7 @@  discard block
 block discarded – undo
3064 3064
      */
3065 3065
     public function set_template_args($data)
3066 3066
     {
3067
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3067
+        $this->_template_args = array_merge($this->_template_args, (array) $data);
3068 3068
     }
3069 3069
 
3070 3070
 
@@ -3086,12 +3086,12 @@  discard block
 block discarded – undo
3086 3086
             $this->_verify_route($route);
3087 3087
         }
3088 3088
         //now let's set the string for what kind of transient we're setting
3089
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3089
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3090 3090
         $data = $notices ? array('notices' => $data) : $data;
3091 3091
         //is there already a transient for this route?  If there is then let's ADD to that transient
3092 3092
         $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3093 3093
         if ($existing) {
3094
-            $data = array_merge((array)$data, (array)$existing);
3094
+            $data = array_merge((array) $data, (array) $existing);
3095 3095
         }
3096 3096
         if (is_multisite() && is_network_admin()) {
3097 3097
             set_site_transient($transient, $data, 8);
@@ -3112,7 +3112,7 @@  discard block
 block discarded – undo
3112 3112
     {
3113 3113
         $user_id = get_current_user_id();
3114 3114
         $route = ! $route ? $this->_req_action : $route;
3115
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3115
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3116 3116
         $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3117 3117
         //delete transient after retrieval (just in case it hasn't expired);
3118 3118
         if (is_multisite() && is_network_admin()) {
@@ -3353,7 +3353,7 @@  discard block
 block discarded – undo
3353 3353
      */
3354 3354
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3355 3355
     {
3356
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3356
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3357 3357
     }
3358 3358
 
3359 3359
 
@@ -3367,7 +3367,7 @@  discard block
 block discarded – undo
3367 3367
      */
3368 3368
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3369 3369
     {
3370
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3370
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3371 3371
     }
3372 3372
 
3373 3373
 
Please login to merge, or discard this patch.
Indentation   +3299 added lines, -3299 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\interfaces\InterminableInterface;
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
  * Event Espresso
@@ -30,2114 +30,2114 @@  discard block
 block discarded – undo
30 30
 {
31 31
 
32 32
 
33
-    //set in _init_page_props()
34
-    public $page_slug;
33
+	//set in _init_page_props()
34
+	public $page_slug;
35 35
 
36
-    public $page_label;
36
+	public $page_label;
37 37
 
38
-    public $page_folder;
38
+	public $page_folder;
39 39
 
40
-    //set in define_page_props()
41
-    protected $_admin_base_url;
40
+	//set in define_page_props()
41
+	protected $_admin_base_url;
42 42
 
43
-    protected $_admin_base_path;
43
+	protected $_admin_base_path;
44 44
 
45
-    protected $_admin_page_title;
45
+	protected $_admin_page_title;
46 46
 
47
-    protected $_labels;
47
+	protected $_labels;
48 48
 
49 49
 
50
-    //set early within EE_Admin_Init
51
-    protected $_wp_page_slug;
50
+	//set early within EE_Admin_Init
51
+	protected $_wp_page_slug;
52 52
 
53
-    //navtabs
54
-    protected $_nav_tabs;
53
+	//navtabs
54
+	protected $_nav_tabs;
55 55
 
56
-    protected $_default_nav_tab_name;
56
+	protected $_default_nav_tab_name;
57 57
 
58
-    //helptourstops
59
-    protected $_help_tour = array();
58
+	//helptourstops
59
+	protected $_help_tour = array();
60 60
 
61 61
 
62
-    //template variables (used by templates)
63
-    protected $_template_path;
62
+	//template variables (used by templates)
63
+	protected $_template_path;
64 64
 
65
-    protected $_column_template_path;
65
+	protected $_column_template_path;
66 66
 
67
-    /**
68
-     * @var array $_template_args
69
-     */
70
-    protected $_template_args = array();
67
+	/**
68
+	 * @var array $_template_args
69
+	 */
70
+	protected $_template_args = array();
71 71
 
72
-    /**
73
-     * this will hold the list table object for a given view.
74
-     *
75
-     * @var EE_Admin_List_Table $_list_table_object
76
-     */
77
-    protected $_list_table_object;
72
+	/**
73
+	 * this will hold the list table object for a given view.
74
+	 *
75
+	 * @var EE_Admin_List_Table $_list_table_object
76
+	 */
77
+	protected $_list_table_object;
78 78
 
79
-    //bools
80
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
79
+	//bools
80
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
81 81
 
82
-    protected $_routing;
82
+	protected $_routing;
83 83
 
84
-    //list table args
85
-    protected $_view;
84
+	//list table args
85
+	protected $_view;
86 86
 
87
-    protected $_views;
87
+	protected $_views;
88 88
 
89 89
 
90
-    //action => method pairs used for routing incoming requests
91
-    protected $_page_routes;
90
+	//action => method pairs used for routing incoming requests
91
+	protected $_page_routes;
92 92
 
93
-    protected $_page_config;
93
+	protected $_page_config;
94 94
 
95
-    //the current page route and route config
96
-    protected $_route;
95
+	//the current page route and route config
96
+	protected $_route;
97 97
 
98
-    protected $_route_config;
98
+	protected $_route_config;
99 99
 
100
-    /**
101
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
102
-     * actions.
103
-     *
104
-     * @since 4.6.x
105
-     * @var array.
106
-     */
107
-    protected $_default_route_query_args;
100
+	/**
101
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
102
+	 * actions.
103
+	 *
104
+	 * @since 4.6.x
105
+	 * @var array.
106
+	 */
107
+	protected $_default_route_query_args;
108 108
 
109
-    //set via request page and action args.
110
-    protected $_current_page;
109
+	//set via request page and action args.
110
+	protected $_current_page;
111 111
 
112
-    protected $_current_view;
112
+	protected $_current_view;
113 113
 
114
-    protected $_current_page_view_url;
114
+	protected $_current_page_view_url;
115 115
 
116
-    //sanitized request action (and nonce)
117
-    /**
118
-     * @var string $_req_action
119
-     */
120
-    protected $_req_action;
116
+	//sanitized request action (and nonce)
117
+	/**
118
+	 * @var string $_req_action
119
+	 */
120
+	protected $_req_action;
121 121
 
122
-    /**
123
-     * @var string $_req_nonce
124
-     */
125
-    protected $_req_nonce;
122
+	/**
123
+	 * @var string $_req_nonce
124
+	 */
125
+	protected $_req_nonce;
126 126
 
127
-    //search related
128
-    protected $_search_btn_label;
127
+	//search related
128
+	protected $_search_btn_label;
129 129
 
130
-    protected $_search_box_callback;
130
+	protected $_search_box_callback;
131 131
 
132
-    /**
133
-     * WP Current Screen object
134
-     *
135
-     * @var WP_Screen
136
-     */
137
-    protected $_current_screen;
132
+	/**
133
+	 * WP Current Screen object
134
+	 *
135
+	 * @var WP_Screen
136
+	 */
137
+	protected $_current_screen;
138 138
 
139
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
140
-    protected $_hook_obj;
139
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
140
+	protected $_hook_obj;
141 141
 
142
-    //for holding incoming request data
143
-    protected $_req_data;
142
+	//for holding incoming request data
143
+	protected $_req_data;
144 144
 
145
-    // yes / no array for admin form fields
146
-    protected $_yes_no_values = array();
147
-
148
-    //some default things shared by all child classes
149
-    protected $_default_espresso_metaboxes;
150
-
151
-    /**
152
-     *    EE_Registry Object
153
-     *
154
-     * @var    EE_Registry
155
-     * @access    protected
156
-     */
157
-    protected $EE = null;
158
-
159
-
160
-
161
-    /**
162
-     * This is just a property that flags whether the given route is a caffeinated route or not.
163
-     *
164
-     * @var boolean
165
-     */
166
-    protected $_is_caf = false;
167
-
168
-
169
-
170
-    /**
171
-     * @Constructor
172
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
173
-     * @access public
174
-     */
175
-    public function __construct($routing = true)
176
-    {
177
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
178
-            $this->_is_caf = true;
179
-        }
180
-        $this->_yes_no_values = array(
181
-                array('id' => true, 'text' => __('Yes', 'event_espresso')),
182
-                array('id' => false, 'text' => __('No', 'event_espresso')),
183
-        );
184
-        //set the _req_data property.
185
-        $this->_req_data = array_merge($_GET, $_POST);
186
-        //routing enabled?
187
-        $this->_routing = $routing;
188
-        //set initial page props (child method)
189
-        $this->_init_page_props();
190
-        //set global defaults
191
-        $this->_set_defaults();
192
-        //set early because incoming requests could be ajax related and we need to register those hooks.
193
-        $this->_global_ajax_hooks();
194
-        $this->_ajax_hooks();
195
-        //other_page_hooks have to be early too.
196
-        $this->_do_other_page_hooks();
197
-        //This just allows us to have extending classes do something specific
198
-        // before the parent constructor runs _page_setup().
199
-        if (method_exists($this, '_before_page_setup')) {
200
-            $this->_before_page_setup();
201
-        }
202
-        //set up page dependencies
203
-        $this->_page_setup();
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * _init_page_props
210
-     * Child classes use to set at least the following properties:
211
-     * $page_slug.
212
-     * $page_label.
213
-     *
214
-     * @abstract
215
-     * @access protected
216
-     * @return void
217
-     */
218
-    abstract protected function _init_page_props();
219
-
220
-
221
-
222
-    /**
223
-     * _ajax_hooks
224
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
225
-     * Note: within the ajax callback methods.
226
-     *
227
-     * @abstract
228
-     * @access protected
229
-     * @return void
230
-     */
231
-    abstract protected function _ajax_hooks();
232
-
233
-
234
-
235
-    /**
236
-     * _define_page_props
237
-     * child classes define page properties in here.  Must include at least:
238
-     * $_admin_base_url = base_url for all admin pages
239
-     * $_admin_page_title = default admin_page_title for admin pages
240
-     * $_labels = array of default labels for various automatically generated elements:
241
-     *    array(
242
-     *        'buttons' => array(
243
-     *            'add' => __('label for add new button'),
244
-     *            'edit' => __('label for edit button'),
245
-     *            'delete' => __('label for delete button')
246
-     *            )
247
-     *        )
248
-     *
249
-     * @abstract
250
-     * @access protected
251
-     * @return void
252
-     */
253
-    abstract protected function _define_page_props();
254
-
255
-
256
-
257
-    /**
258
-     * _set_page_routes
259
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
260
-     * route. Here's the format
261
-     * $this->_page_routes = array(
262
-     *        'default' => array(
263
-     *            'func' => '_default_method_handling_route',
264
-     *            'args' => array('array','of','args'),
265
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
266
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
267
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
268
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
269
-     *        ),
270
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
271
-     *        )
272
-     * )
273
-     *
274
-     * @abstract
275
-     * @access protected
276
-     * @return void
277
-     */
278
-    abstract protected function _set_page_routes();
279
-
280
-
281
-
282
-    /**
283
-     * _set_page_config
284
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
285
-     * Format:
286
-     * $this->_page_config = array(
287
-     *        'default' => array(
288
-     *            'labels' => array(
289
-     *                'buttons' => array(
290
-     *                    'add' => __('label for adding item'),
291
-     *                    'edit' => __('label for editing item'),
292
-     *                    'delete' => __('label for deleting item')
293
-     *                ),
294
-     *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
295
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
296
-     *            'nav' => array(
297
-     *                'label' => __('Label for Tab', 'event_espresso').
298
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
299
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
300
-     *                'order' => 10, //required to indicate tab position.
301
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
302
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
303
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
304
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
305
-     *            this flag to make sure the necessary js gets enqueued on page load.
306
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
307
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
308
-     *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
309
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
310
-     *                'tab_id' => array(
311
-     *                    'title' => 'tab_title',
312
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
313
-     *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
314
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
315
-     *                    ),
316
-     *                'tab2_id' => array(
317
-     *                    'title' => 'tab2 title',
318
-     *                    'filename' => 'file_name_2'
319
-     *                    'callback' => 'callback_method_for_content',
320
-     *                 ),
321
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
322
-     *            'help_tour' => array(
323
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
324
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
325
-     *            ),
326
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
327
-     *            'require_nonce' to FALSE
328
-     *            )
329
-     * )
330
-     *
331
-     * @abstract
332
-     * @access protected
333
-     * @return void
334
-     */
335
-    abstract protected function _set_page_config();
336
-
337
-
338
-
339
-
340
-
341
-    /** end sample help_tour methods **/
342
-    /**
343
-     * _add_screen_options
344
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
345
-     * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
346
-     *
347
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
348
-     *         see also WP_Screen object documents...
349
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
350
-     * @abstract
351
-     * @access protected
352
-     * @return void
353
-     */
354
-    abstract protected function _add_screen_options();
355
-
356
-
357
-
358
-    /**
359
-     * _add_feature_pointers
360
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
361
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
362
-     * Note: this is just a placeholder for now.  Implementation will come down the road
363
-     * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
364
-     *
365
-     * @link   http://eamann.com/tech/wordpress-portland/
366
-     * @abstract
367
-     * @access protected
368
-     * @return void
369
-     */
370
-    abstract protected function _add_feature_pointers();
371
-
372
-
373
-
374
-    /**
375
-     * load_scripts_styles
376
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
377
-     * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
378
-     *
379
-     * @abstract
380
-     * @access public
381
-     * @return void
382
-     */
383
-    abstract public function load_scripts_styles();
384
-
385
-
386
-
387
-    /**
388
-     * admin_init
389
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
390
-     *
391
-     * @abstract
392
-     * @access public
393
-     * @return void
394
-     */
395
-    abstract public function admin_init();
396
-
397
-
398
-
399
-    /**
400
-     * admin_notices
401
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
402
-     *
403
-     * @abstract
404
-     * @access public
405
-     * @return void
406
-     */
407
-    abstract public function admin_notices();
408
-
409
-
410
-
411
-    /**
412
-     * admin_footer_scripts
413
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
414
-     *
415
-     * @access public
416
-     * @return void
417
-     */
418
-    abstract public function admin_footer_scripts();
419
-
420
-
421
-
422
-    /**
423
-     * admin_footer
424
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
425
-     *
426
-     * @access  public
427
-     * @return void
428
-     */
429
-    public function admin_footer()
430
-    {
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * _global_ajax_hooks
437
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
438
-     * Note: within the ajax callback methods.
439
-     *
440
-     * @abstract
441
-     * @access protected
442
-     * @return void
443
-     */
444
-    protected function _global_ajax_hooks()
445
-    {
446
-        //for lazy loading of metabox content
447
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
448
-    }
449
-
450
-
451
-
452
-    public function ajax_metabox_content()
453
-    {
454
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
455
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
456
-        self::cached_rss_display($contentid, $url);
457
-        wp_die();
458
-    }
459
-
460
-
461
-
462
-    /**
463
-     * _page_setup
464
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
465
-     *
466
-     * @final
467
-     * @access protected
468
-     * @return void
469
-     */
470
-    final protected function _page_setup()
471
-    {
472
-        //requires?
473
-        //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
474
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
475
-        //next verify if we need to load anything...
476
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
477
-        $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
478
-        global $ee_menu_slugs;
479
-        $ee_menu_slugs = (array)$ee_menu_slugs;
480
-        if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
481
-            return;
482
-        }
483
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
484
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
485
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
486
-        }
487
-        // then set blank or -1 action values to 'default'
488
-        $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
489
-        //if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
490
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
492
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
493
-        $this->_current_view = $this->_req_action;
494
-        $this->_req_nonce = $this->_req_action . '_nonce';
495
-        $this->_define_page_props();
496
-        $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
497
-        //default things
498
-        $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
499
-        //set page configs
500
-        $this->_set_page_routes();
501
-        $this->_set_page_config();
502
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
503
-        if (isset($this->_req_data['wp_referer'])) {
504
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
505
-        }
506
-        //for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
507
-        if (method_exists($this, '_extend_page_config')) {
508
-            $this->_extend_page_config();
509
-        }
510
-        //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
511
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
512
-            $this->_extend_page_config_for_cpt();
513
-        }
514
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
515
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
516
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
517
-        //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
518
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
519
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
520
-        }
521
-        //next route only if routing enabled
522
-        if ($this->_routing && ! defined('DOING_AJAX')) {
523
-            $this->_verify_routes();
524
-            //next let's just check user_access and kill if no access
525
-            $this->check_user_access();
526
-            if ($this->_is_UI_request) {
527
-                //admin_init stuff - global, all views for this page class, specific view
528
-                add_action('admin_init', array($this, 'admin_init'), 10);
529
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
530
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
531
-                }
532
-            } else {
533
-                //hijack regular WP loading and route admin request immediately
534
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
535
-                $this->route_admin_request();
536
-            }
537
-        }
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
544
-     *
545
-     * @access private
546
-     * @return void
547
-     */
548
-    private function _do_other_page_hooks()
549
-    {
550
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
551
-        foreach ($registered_pages as $page) {
552
-            //now let's setup the file name and class that should be present
553
-            $classname = str_replace('.class.php', '', $page);
554
-            //autoloaders should take care of loading file
555
-            if ( ! class_exists($classname)) {
556
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
557
-                $error_msg[] = $error_msg[0]
558
-                               . "\r\n"
559
-                               . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
560
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
561
-                throw new EE_Error(implode('||', $error_msg));
562
-            }
563
-            $a = new ReflectionClass($classname);
564
-            //notice we are passing the instance of this class to the hook object.
565
-            $hookobj[] = $a->newInstance($this);
566
-        }
567
-    }
568
-
569
-
570
-
571
-    public function load_page_dependencies()
572
-    {
573
-        try {
574
-            $this->_load_page_dependencies();
575
-        } catch (EE_Error $e) {
576
-            $e->get_error();
577
-        }
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * load_page_dependencies
584
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
585
-     *
586
-     * @access public
587
-     * @return void
588
-     */
589
-    protected function _load_page_dependencies()
590
-    {
591
-        //let's set the current_screen and screen options to override what WP set
592
-        $this->_current_screen = get_current_screen();
593
-        //load admin_notices - global, page class, and view specific
594
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
595
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
596
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
597
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
598
-        }
599
-        //load network admin_notices - global, page class, and view specific
600
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
601
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
602
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
603
-        }
604
-        //this will save any per_page screen options if they are present
605
-        $this->_set_per_page_screen_options();
606
-        //setup list table properties
607
-        $this->_set_list_table();
608
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
609
-        $this->_add_registered_meta_boxes();
610
-        $this->_add_screen_columns();
611
-        //add screen options - global, page child class, and view specific
612
-        $this->_add_global_screen_options();
613
-        $this->_add_screen_options();
614
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
615
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
616
-        }
617
-        //add help tab(s) and tours- set via page_config and qtips.
618
-        $this->_add_help_tour();
619
-        $this->_add_help_tabs();
620
-        $this->_add_qtips();
621
-        //add feature_pointers - global, page child class, and view specific
622
-        $this->_add_feature_pointers();
623
-        $this->_add_global_feature_pointers();
624
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
625
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
626
-        }
627
-        //enqueue scripts/styles - global, page class, and view specific
628
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
629
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
630
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
631
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
632
-        }
633
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
634
-        //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
635
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
636
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
637
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
638
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
639
-        }
640
-        //admin footer scripts
641
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
642
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
643
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
644
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
645
-        }
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
647
-        //targeted hook
648
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
649
-    }
650
-
651
-
652
-
653
-    /**
654
-     * _set_defaults
655
-     * This sets some global defaults for class properties.
656
-     */
657
-    private function _set_defaults()
658
-    {
659
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
660
-        $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
661
-        $this->default_nav_tab_name = 'overview';
662
-        //init template args
663
-        $this->_template_args = array(
664
-                'admin_page_header'  => '',
665
-                'admin_page_content' => '',
666
-                'post_body_content'  => '',
667
-                'before_list_table'  => '',
668
-                'after_list_table'   => '',
669
-        );
670
-    }
671
-
672
-
673
-
674
-    /**
675
-     * route_admin_request
676
-     *
677
-     * @see    _route_admin_request()
678
-     * @access public
679
-     * @return void|exception error
680
-     */
681
-    public function route_admin_request()
682
-    {
683
-        try {
684
-            $this->_route_admin_request();
685
-        } catch (EE_Error $e) {
686
-            $e->get_error();
687
-        }
688
-    }
689
-
690
-
691
-
692
-    public function set_wp_page_slug($wp_page_slug)
693
-    {
694
-        $this->_wp_page_slug = $wp_page_slug;
695
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
696
-        if (is_network_admin()) {
697
-            $this->_wp_page_slug .= '-network';
698
-        }
699
-    }
700
-
701
-
702
-
703
-    /**
704
-     * _verify_routes
705
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
706
-     *
707
-     * @access protected
708
-     * @return void
709
-     */
710
-    protected function _verify_routes()
711
-    {
712
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
713
-        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
714
-            return false;
715
-        }
716
-        $this->_route = false;
717
-        $func = false;
718
-        $args = array();
719
-        // check that the page_routes array is not empty
720
-        if (empty($this->_page_routes)) {
721
-            // user error msg
722
-            $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
723
-            // developer error msg
724
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
725
-            throw new EE_Error($error_msg);
726
-        }
727
-        // and that the requested page route exists
728
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
729
-            $this->_route = $this->_page_routes[$this->_req_action];
730
-            $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
731
-        } else {
732
-            // user error msg
733
-            $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
734
-            // developer error msg
735
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
736
-            throw new EE_Error($error_msg);
737
-        }
738
-        // and that a default route exists
739
-        if ( ! array_key_exists('default', $this->_page_routes)) {
740
-            // user error msg
741
-            $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
742
-            // developer error msg
743
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
744
-            throw new EE_Error($error_msg);
745
-        }
746
-        //first lets' catch if the UI request has EVER been set.
747
-        if ($this->_is_UI_request === null) {
748
-            //lets set if this is a UI request or not.
749
-            $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
750
-            //wait a minute... we might have a noheader in the route array
751
-            $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
752
-        }
753
-        $this->_set_current_labels();
754
-    }
755
-
756
-
757
-
758
-    /**
759
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
760
-     *
761
-     * @param  string $route the route name we're verifying
762
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
763
-     */
764
-    protected function _verify_route($route)
765
-    {
766
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
767
-            return true;
768
-        } else {
769
-            // user error msg
770
-            $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
771
-            // developer error msg
772
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
773
-            throw new EE_Error($error_msg);
774
-        }
775
-    }
776
-
777
-
778
-
779
-    /**
780
-     * perform nonce verification
781
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
782
-     *
783
-     * @param  string $nonce     The nonce sent
784
-     * @param  string $nonce_ref The nonce reference string (name0)
785
-     * @return mixed (bool|die)
786
-     */
787
-    protected function _verify_nonce($nonce, $nonce_ref)
788
-    {
789
-        // verify nonce against expected value
790
-        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
791
-            // these are not the droids you are looking for !!!
792
-            $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
793
-            if (WP_DEBUG) {
794
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
795
-            }
796
-            if ( ! defined('DOING_AJAX')) {
797
-                wp_die($msg);
798
-            } else {
799
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
800
-                $this->_return_json();
801
-            }
802
-        }
803
-    }
804
-
805
-
806
-
807
-    /**
808
-     * _route_admin_request()
809
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
810
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
811
-     * in the page routes and then will try to load the corresponding method.
812
-     *
813
-     * @access protected
814
-     * @return void
815
-     * @throws \EE_Error
816
-     */
817
-    protected function _route_admin_request()
818
-    {
819
-        if ( ! $this->_is_UI_request) {
820
-            $this->_verify_routes();
821
-        }
822
-        $nonce_check = isset($this->_route_config['require_nonce'])
823
-            ? $this->_route_config['require_nonce']
824
-            : true;
825
-        if ($this->_req_action !== 'default' && $nonce_check) {
826
-            // set nonce from post data
827
-            $nonce = isset($this->_req_data[$this->_req_nonce])
828
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
829
-                : '';
830
-            $this->_verify_nonce($nonce, $this->_req_nonce);
831
-        }
832
-        //set the nav_tabs array but ONLY if this is  UI_request
833
-        if ($this->_is_UI_request) {
834
-            $this->_set_nav_tabs();
835
-        }
836
-        // grab callback function
837
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
838
-        // check if callback has args
839
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
840
-        $error_msg = '';
841
-        // action right before calling route
842
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
843
-        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
844
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
845
-        }
846
-        // right before calling the route, let's remove _wp_http_referer from the
847
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
848
-        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
849
-        if ( ! empty($func)) {
850
-            if (is_array($func)) {
851
-                list($class, $method) = $func;
852
-            } else if (strpos($func, '::') !== false) {
853
-                list($class, $method) = explode('::', $func);
854
-            } else {
855
-                $class = $this;
856
-                $method = $func;
857
-            }
858
-            if ( ! (is_object($class) && $class === $this)) {
859
-                // send along this admin page object for access by addons.
860
-                $args['admin_page_object'] = $this;
861
-            }
862
-
863
-            if (
864
-                //is it a method on a class that doesn't work?
865
-                (
866
-                    (
867
-                        method_exists($class, $method)
868
-                        && call_user_func_array(array($class, $method), $args) === false
869
-                    )
870
-                    && (
871
-                        //is it a standalone function that doesn't work?
872
-                        function_exists($method)
873
-                        && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
874
-                    )
875
-                )
876
-                || (
877
-                    //is it neither a class method NOR a standalone function?
878
-                    ! method_exists($class, $method)
879
-                    && ! function_exists($method)
880
-                )
881
-            ) {
882
-                // user error msg
883
-                $error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
884
-                // developer error msg
885
-                $error_msg .= '||';
886
-                $error_msg .= sprintf(
887
-                    __(
888
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
889
-                        'event_espresso'
890
-                    ),
891
-                    $method
892
-                );
893
-            }
894
-            if ( ! empty($error_msg)) {
895
-                throw new EE_Error($error_msg);
896
-            }
897
-        }
898
-        //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
899
-        //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
900
-        if ($this->_is_UI_request === false
901
-            && is_array($this->_route)
902
-            && ! empty($this->_route['headers_sent_route'])
903
-        ) {
904
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
905
-        }
906
-    }
907
-
908
-
909
-
910
-    /**
911
-     * This method just allows the resetting of page properties in the case where a no headers
912
-     * route redirects to a headers route in its route config.
913
-     *
914
-     * @since   4.3.0
915
-     * @param  string $new_route New (non header) route to redirect to.
916
-     * @return   void
917
-     */
918
-    protected function _reset_routing_properties($new_route)
919
-    {
920
-        $this->_is_UI_request = true;
921
-        //now we set the current route to whatever the headers_sent_route is set at
922
-        $this->_req_data['action'] = $new_route;
923
-        //rerun page setup
924
-        $this->_page_setup();
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * _add_query_arg
931
-     * adds nonce to array of arguments then calls WP add_query_arg function
932
-     *(internally just uses EEH_URL's function with the same name)
933
-     *
934
-     * @access public
935
-     * @param array  $args
936
-     * @param string $url
937
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
938
-     *                                        url in an associative array indexed by the key 'wp_referer';
939
-     *                                        Example usage:
940
-     *                                        If the current page is:
941
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
942
-     *                                        &action=default&event_id=20&month_range=March%202015
943
-     *                                        &_wpnonce=5467821
944
-     *                                        and you call:
945
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
946
-     *                                        array(
947
-     *                                        'action' => 'resend_something',
948
-     *                                        'page=>espresso_registrations'
949
-     *                                        ),
950
-     *                                        $some_url,
951
-     *                                        true
952
-     *                                        );
953
-     *                                        It will produce a url in this structure:
954
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
955
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
956
-     *                                        month_range]=March%202015
957
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
958
-     * @return string
959
-     */
960
-    public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
961
-    {
962
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
963
-        if ($sticky) {
964
-            $request = $_REQUEST;
965
-            unset($request['_wp_http_referer']);
966
-            unset($request['wp_referer']);
967
-            foreach ($request as $key => $value) {
968
-                //do not add nonces
969
-                if (strpos($key, 'nonce') !== false) {
970
-                    continue;
971
-                }
972
-                $args['wp_referer[' . $key . ']'] = $value;
973
-            }
974
-        }
975
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
976
-    }
977
-
978
-
979
-
980
-    /**
981
-     * This returns a generated link that will load the related help tab.
982
-     *
983
-     * @param  string $help_tab_id the id for the connected help tab
984
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
985
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
986
-     * @uses EEH_Template::get_help_tab_link()
987
-     * @return string              generated link
988
-     */
989
-    protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
990
-    {
991
-        return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
992
-    }
993
-
994
-
995
-
996
-    /**
997
-     * _add_help_tabs
998
-     * Note child classes define their help tabs within the page_config array.
999
-     *
1000
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1001
-     * @access protected
1002
-     * @return void
1003
-     */
1004
-    protected function _add_help_tabs()
1005
-    {
1006
-        $tour_buttons = '';
1007
-        if (isset($this->_page_config[$this->_req_action])) {
1008
-            $config = $this->_page_config[$this->_req_action];
1009
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1010
-            if (isset($this->_help_tour[$this->_req_action])) {
1011
-                $tb = array();
1012
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1013
-                foreach ($this->_help_tour['tours'] as $tour) {
1014
-                    //if this is the end tour then we don't need to setup a button
1015
-                    if ($tour instanceof EE_Help_Tour_final_stop) {
1016
-                        continue;
1017
-                    }
1018
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1019
-                }
1020
-                $tour_buttons .= implode('<br />', $tb);
1021
-                $tour_buttons .= '</div></div>';
1022
-            }
1023
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1024
-            if (is_array($config) && isset($config['help_sidebar'])) {
1025
-                //check that the callback given is valid
1026
-                if ( ! method_exists($this, $config['help_sidebar'])) {
1027
-                    throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1028
-                            'event_espresso'), $config['help_sidebar'], get_class($this)));
1029
-                }
1030
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1031
-                $content .= $tour_buttons; //add help tour buttons.
1032
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1033
-                $this->_current_screen->set_help_sidebar($content);
1034
-            }
1035
-            //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1036
-            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1037
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1038
-            }
1039
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1040
-            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1041
-                $_ht['id'] = $this->page_slug;
1042
-                $_ht['title'] = __('Help Tours', 'event_espresso');
1043
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1044
-                $this->_current_screen->add_help_tab($_ht);
1045
-            }/**/
1046
-            if ( ! isset($config['help_tabs'])) {
1047
-                return;
1048
-            } //no help tabs for this route
1049
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1050
-                //we're here so there ARE help tabs!
1051
-                //make sure we've got what we need
1052
-                if ( ! isset($cfg['title'])) {
1053
-                    throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1054
-                }
1055
-                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1056
-                    throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1057
-                            'event_espresso'));
1058
-                }
1059
-                //first priority goes to content.
1060
-                if ( ! empty($cfg['content'])) {
1061
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1062
-                    //second priority goes to filename
1063
-                } else if ( ! empty($cfg['filename'])) {
1064
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1065
-                    //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1066
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1067
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1068
-                    if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1069
-                        EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1070
-                                'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1071
-                        return;
1072
-                    }
1073
-                    $template_args['admin_page_obj'] = $this;
1074
-                    $content = EEH_Template::display_template($file_path, $template_args, true);
1075
-                } else {
1076
-                    $content = '';
1077
-                }
1078
-                //check if callback is valid
1079
-                if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1080
-                    EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1081
-                            'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1082
-                    return;
1083
-                }
1084
-                //setup config array for help tab method
1085
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1086
-                $_ht = array(
1087
-                        'id'       => $id,
1088
-                        'title'    => $cfg['title'],
1089
-                        'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1090
-                        'content'  => $content,
1091
-                );
1092
-                $this->_current_screen->add_help_tab($_ht);
1093
-            }
1094
-        }
1095
-    }
1096
-
1097
-
1098
-
1099
-    /**
1100
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1101
-     *
1102
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1103
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1104
-     * @access protected
1105
-     * @return void
1106
-     */
1107
-    protected function _add_help_tour()
1108
-    {
1109
-        $tours = array();
1110
-        $this->_help_tour = array();
1111
-        //exit early if help tours are turned off globally
1112
-        if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1113
-            return;
1114
-        }
1115
-        //loop through _page_config to find any help_tour defined
1116
-        foreach ($this->_page_config as $route => $config) {
1117
-            //we're only going to set things up for this route
1118
-            if ($route !== $this->_req_action) {
1119
-                continue;
1120
-            }
1121
-            if (isset($config['help_tour'])) {
1122
-                foreach ($config['help_tour'] as $tour) {
1123
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1124
-                    //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1125
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1126
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1127
-                    if ( ! is_readable($file_path)) {
1128
-                        EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1129
-                                $file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1130
-                        return;
1131
-                    }
1132
-                    require_once $file_path;
1133
-                    if ( ! class_exists($tour)) {
1134
-                        $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1135
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1136
-                                        'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1137
-                        throw new EE_Error(implode('||', $error_msg));
1138
-                    }
1139
-                    $a = new ReflectionClass($tour);
1140
-                    $tour_obj = $a->newInstance($this->_is_caf);
1141
-                    $tours[] = $tour_obj;
1142
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1143
-                }
1144
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1145
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1146
-                $tours[] = $end_stop_tour;
1147
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1148
-            }
1149
-        }
1150
-        if ( ! empty($tours)) {
1151
-            $this->_help_tour['tours'] = $tours;
1152
-        }
1153
-        //thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1154
-    }
1155
-
1156
-
1157
-
1158
-    /**
1159
-     * This simply sets up any qtips that have been defined in the page config
1160
-     *
1161
-     * @access protected
1162
-     * @return void
1163
-     */
1164
-    protected function _add_qtips()
1165
-    {
1166
-        if (isset($this->_route_config['qtips'])) {
1167
-            $qtips = (array)$this->_route_config['qtips'];
1168
-            //load qtip loader
1169
-            $path = array(
1170
-                    $this->_get_dir() . '/qtips/',
1171
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1172
-            );
1173
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1174
-        }
1175
-    }
1176
-
1177
-
1178
-
1179
-    /**
1180
-     * _set_nav_tabs
1181
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1182
-     *
1183
-     * @access protected
1184
-     * @return void
1185
-     */
1186
-    protected function _set_nav_tabs()
1187
-    {
1188
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1189
-        $i = 0;
1190
-        foreach ($this->_page_config as $slug => $config) {
1191
-            if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1192
-                continue;
1193
-            } //no nav tab for this config
1194
-            //check for persistent flag
1195
-            if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1196
-                continue;
1197
-            } //nav tab is only to appear when route requested.
1198
-            if ( ! $this->check_user_access($slug, true)) {
1199
-                continue;
1200
-            } //no nav tab becasue current user does not have access.
1201
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1202
-            $this->_nav_tabs[$slug] = array(
1203
-                    'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1204
-                    'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1205
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1206
-                    'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1207
-            );
1208
-            $i++;
1209
-        }
1210
-        //if $this->_nav_tabs is empty then lets set the default
1211
-        if (empty($this->_nav_tabs)) {
1212
-            $this->_nav_tabs[$this->default_nav_tab_name] = array(
1213
-                    'url'       => $this->admin_base_url,
1214
-                    'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1215
-                    'css_class' => 'nav-tab-active',
1216
-                    'order'     => 10,
1217
-            );
1218
-        }
1219
-        //now let's sort the tabs according to order
1220
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1221
-    }
1222
-
1223
-
1224
-
1225
-    /**
1226
-     * _set_current_labels
1227
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1228
-     *
1229
-     * @access private
1230
-     * @return void
1231
-     */
1232
-    private function _set_current_labels()
1233
-    {
1234
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1235
-            foreach ($this->_route_config['labels'] as $label => $text) {
1236
-                if (is_array($text)) {
1237
-                    foreach ($text as $sublabel => $subtext) {
1238
-                        $this->_labels[$label][$sublabel] = $subtext;
1239
-                    }
1240
-                } else {
1241
-                    $this->_labels[$label] = $text;
1242
-                }
1243
-            }
1244
-        }
1245
-    }
1246
-
1247
-
1248
-
1249
-    /**
1250
-     *        verifies user access for this admin page
1251
-     *
1252
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1253
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1254
-     * @return        BOOL|wp_die()
1255
-     */
1256
-    public function check_user_access($route_to_check = '', $verify_only = false)
1257
-    {
1258
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1259
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1260
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1261
-                ? $this->_page_routes[$route_to_check]['capability'] : null;
1262
-        if (empty($capability) && empty($route_to_check)) {
1263
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1264
-        } else {
1265
-            $capability = empty($capability) ? 'manage_options' : $capability;
1266
-        }
1267
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1268
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1269
-            if ($verify_only) {
1270
-                return false;
1271
-            } else {
1272
-                if ( is_user_logged_in() ) {
1273
-                    wp_die(__('You do not have access to this route.', 'event_espresso'));
1274
-                } else {
1275
-                    return false;
1276
-                }
1277
-            }
1278
-        }
1279
-        return true;
1280
-    }
1281
-
1282
-
1283
-
1284
-    /**
1285
-     * admin_init_global
1286
-     * This runs all the code that we want executed within the WP admin_init hook.
1287
-     * This method executes for ALL EE Admin pages.
1288
-     *
1289
-     * @access public
1290
-     * @return void
1291
-     */
1292
-    public function admin_init_global()
1293
-    {
1294
-    }
1295
-
1296
-
1297
-
1298
-    /**
1299
-     * wp_loaded_global
1300
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1301
-     *
1302
-     * @access public
1303
-     * @return void
1304
-     */
1305
-    public function wp_loaded()
1306
-    {
1307
-    }
1308
-
1309
-
1310
-
1311
-    /**
1312
-     * admin_notices
1313
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1314
-     *
1315
-     * @access public
1316
-     * @return void
1317
-     */
1318
-    public function admin_notices_global()
1319
-    {
1320
-        $this->_display_no_javascript_warning();
1321
-        $this->_display_espresso_notices();
1322
-    }
1323
-
1324
-
1325
-
1326
-    public function network_admin_notices_global()
1327
-    {
1328
-        $this->_display_no_javascript_warning();
1329
-        $this->_display_espresso_notices();
1330
-    }
1331
-
1332
-
1333
-
1334
-    /**
1335
-     * admin_footer_scripts_global
1336
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1337
-     *
1338
-     * @access public
1339
-     * @return void
1340
-     */
1341
-    public function admin_footer_scripts_global()
1342
-    {
1343
-        $this->_add_admin_page_ajax_loading_img();
1344
-        $this->_add_admin_page_overlay();
1345
-        //if metaboxes are present we need to add the nonce field
1346
-        if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1347
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1348
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1349
-        }
1350
-    }
1351
-
1352
-
1353
-
1354
-    /**
1355
-     * admin_footer_global
1356
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1357
-     *
1358
-     * @access  public
1359
-     * @return  void
1360
-     */
1361
-    public function admin_footer_global()
1362
-    {
1363
-        //dialog container for dialog helper
1364
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1365
-        $d_cont .= '<div class="ee-notices"></div>';
1366
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1367
-        $d_cont .= '</div>';
1368
-        echo $d_cont;
1369
-        //help tour stuff?
1370
-        if (isset($this->_help_tour[$this->_req_action])) {
1371
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1372
-        }
1373
-        //current set timezone for timezone js
1374
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1375
-    }
1376
-
1377
-
1378
-
1379
-    /**
1380
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1381
-     * For child classes:
1382
-     * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1383
-     * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1384
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1385
-     *    'help_trigger_id' => array(
1386
-     *        'title' => __('localized title for popup', 'event_espresso'),
1387
-     *        'content' => __('localized content for popup', 'event_espresso')
1388
-     *    )
1389
-     * );
1390
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1391
-     *
1392
-     * @access protected
1393
-     * @return string content
1394
-     */
1395
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1396
-    {
1397
-        $content = '';
1398
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1399
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1400
-        //loop through the array and setup content
1401
-        foreach ($help_array as $trigger => $help) {
1402
-            //make sure the array is setup properly
1403
-            if ( ! isset($help['title']) || ! isset($help['content'])) {
1404
-                throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1405
-                        'event_espresso'));
1406
-            }
1407
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1408
-            $template_args = array(
1409
-                    'help_popup_id'      => $trigger,
1410
-                    'help_popup_title'   => $help['title'],
1411
-                    'help_popup_content' => $help['content'],
1412
-            );
1413
-            $content .= EEH_Template::display_template($template_path, $template_args, true);
1414
-        }
1415
-        if ($display) {
1416
-            echo $content;
1417
-        } else {
1418
-            return $content;
1419
-        }
1420
-    }
1421
-
1422
-
1423
-
1424
-    /**
1425
-     * All this does is retrive the help content array if set by the EE_Admin_Page child
1426
-     *
1427
-     * @access private
1428
-     * @return array properly formatted array for help popup content
1429
-     */
1430
-    private function _get_help_content()
1431
-    {
1432
-        //what is the method we're looking for?
1433
-        $method_name = '_help_popup_content_' . $this->_req_action;
1434
-        //if method doesn't exist let's get out.
1435
-        if ( ! method_exists($this, $method_name)) {
1436
-            return array();
1437
-        }
1438
-        //k we're good to go let's retrieve the help array
1439
-        $help_array = call_user_func(array($this, $method_name));
1440
-        //make sure we've got an array!
1441
-        if ( ! is_array($help_array)) {
1442
-            throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1443
-        }
1444
-        return $help_array;
1445
-    }
1446
-
1447
-
1448
-
1449
-    /**
1450
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1451
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1452
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1453
-     *
1454
-     * @access protected
1455
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1456
-     * @param boolean $display    if false then we return the trigger string
1457
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1458
-     * @return string
1459
-     */
1460
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1461
-    {
1462
-        if (defined('DOING_AJAX')) {
1463
-            return;
1464
-        }
1465
-        //let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1466
-        $help_array = $this->_get_help_content();
1467
-        $help_content = '';
1468
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1469
-            $help_array[$trigger_id] = array(
1470
-                    'title'   => __('Missing Content', 'event_espresso'),
1471
-                    'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1472
-                            'event_espresso'),
1473
-            );
1474
-            $help_content = $this->_set_help_popup_content($help_array, false);
1475
-        }
1476
-        //let's setup the trigger
1477
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1478
-        $content = $content . $help_content;
1479
-        if ($display) {
1480
-            echo $content;
1481
-        } else {
1482
-            return $content;
1483
-        }
1484
-    }
1485
-
1486
-
1487
-
1488
-    /**
1489
-     * _add_global_screen_options
1490
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1491
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1492
-     *
1493
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1494
-     *         see also WP_Screen object documents...
1495
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1496
-     * @abstract
1497
-     * @access private
1498
-     * @return void
1499
-     */
1500
-    private function _add_global_screen_options()
1501
-    {
1502
-    }
1503
-
1504
-
1505
-
1506
-    /**
1507
-     * _add_global_feature_pointers
1508
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1509
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1510
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1511
-     *
1512
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1513
-     * @link   http://eamann.com/tech/wordpress-portland/
1514
-     * @abstract
1515
-     * @access protected
1516
-     * @return void
1517
-     */
1518
-    private function _add_global_feature_pointers()
1519
-    {
1520
-    }
1521
-
1522
-
1523
-
1524
-    /**
1525
-     * load_global_scripts_styles
1526
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1527
-     *
1528
-     * @return void
1529
-     */
1530
-    public function load_global_scripts_styles()
1531
-    {
1532
-        /** STYLES **/
1533
-        // add debugging styles
1534
-        if (WP_DEBUG) {
1535
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1536
-        }
1537
-        // register all styles
1538
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1539
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1540
-        //helpers styles
1541
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1542
-        /** SCRIPTS **/
1543
-        //register all scripts
1544
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1546
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1547
-        add_filter('FHEE_load_joyride', '__return_true');
1548
-        //script for sorting tables
1549
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1550
-        //script for parsing uri's
1551
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1552
-        //and parsing associative serialized form elements
1553
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
-        //helpers scripts
1555
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1557
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1558
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1559
-        //google charts
1560
-        wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1561
-        // ENQUEUE ALL BASICS BY DEFAULT
1562
-        wp_enqueue_style('ee-admin-css');
1563
-        wp_enqueue_script('ee_admin_js');
1564
-        wp_enqueue_script('ee-accounting');
1565
-        wp_enqueue_script('jquery-validate');
1566
-        //taking care of metaboxes
1567
-        if (
1568
-            empty($this->_cpt_route)
1569
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1570
-        ) {
1571
-            wp_enqueue_script('dashboard');
1572
-        }
1573
-        // LOCALIZED DATA
1574
-        //localize script for ajax lazy loading
1575
-        $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1576
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1577
-        /**
1578
-         * help tour stuff
1579
-         */
1580
-        if ( ! empty($this->_help_tour)) {
1581
-            //register the js for kicking things off
1582
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1583
-            //setup tours for the js tour object
1584
-            foreach ($this->_help_tour['tours'] as $tour) {
1585
-                $tours[] = array(
1586
-                        'id'      => $tour->get_slug(),
1587
-                        'options' => $tour->get_options(),
1588
-                );
1589
-            }
1590
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1591
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1592
-        }
1593
-    }
1594
-
1595
-
1596
-
1597
-    /**
1598
-     *        admin_footer_scripts_eei18n_js_strings
1599
-     *
1600
-     * @access        public
1601
-     * @return        void
1602
-     */
1603
-    public function admin_footer_scripts_eei18n_js_strings()
1604
-    {
1605
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1606
-        EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1607
-        EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1608
-        EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1609
-        EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1610
-        EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1611
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1612
-        EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1613
-        EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1614
-        EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1615
-        EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1616
-        EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1617
-        EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1618
-        EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1619
-        EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1620
-        EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1621
-        EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1622
-        EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1623
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1624
-        EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1625
-        EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1626
-        EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1627
-        EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1628
-        EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1629
-        EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1630
-        EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1631
-        EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1632
-        EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1633
-        EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1634
-        EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1635
-        EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1636
-        EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1637
-        EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1638
-        EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1639
-        EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1640
-        EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1641
-        EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1642
-        EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1643
-        EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1644
-        EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1645
-    }
1646
-
1647
-
1648
-
1649
-    /**
1650
-     *        load enhanced xdebug styles for ppl with failing eyesight
1651
-     *
1652
-     * @access        public
1653
-     * @return        void
1654
-     */
1655
-    public function add_xdebug_style()
1656
-    {
1657
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1658
-    }
1659
-
1660
-
1661
-    /************************/
1662
-    /** LIST TABLE METHODS **/
1663
-    /************************/
1664
-    /**
1665
-     * this sets up the list table if the current view requires it.
1666
-     *
1667
-     * @access protected
1668
-     * @return void
1669
-     */
1670
-    protected function _set_list_table()
1671
-    {
1672
-        //first is this a list_table view?
1673
-        if ( ! isset($this->_route_config['list_table'])) {
1674
-            return;
1675
-        } //not a list_table view so get out.
1676
-        //list table functions are per view specific (because some admin pages might have more than one listtable!)
1677
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1678
-            //user error msg
1679
-            $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1680
-            //developer error msg
1681
-            $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1682
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1683
-            throw new EE_Error($error_msg);
1684
-        }
1685
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1686
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1687
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1688
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1689
-        $this->_set_list_table_view();
1690
-        $this->_set_list_table_object();
1691
-    }
1692
-
1693
-
1694
-
1695
-    /**
1696
-     *        set current view for List Table
1697
-     *
1698
-     * @access public
1699
-     * @return array
1700
-     */
1701
-    protected function _set_list_table_view()
1702
-    {
1703
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1704
-        // looking at active items or dumpster diving ?
1705
-        if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1706
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1707
-        } else {
1708
-            $this->_view = sanitize_key($this->_req_data['status']);
1709
-        }
1710
-    }
1711
-
1712
-
1713
-
1714
-    /**
1715
-     * _set_list_table_object
1716
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1717
-     *
1718
-     * @throws \EE_Error
1719
-     */
1720
-    protected function _set_list_table_object()
1721
-    {
1722
-        if (isset($this->_route_config['list_table'])) {
1723
-            if ( ! class_exists($this->_route_config['list_table'])) {
1724
-                throw new EE_Error(
1725
-                        sprintf(
1726
-                                __(
1727
-                                        'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1728
-                                        'event_espresso'
1729
-                                ),
1730
-                                $this->_route_config['list_table'],
1731
-                                get_class($this)
1732
-                        )
1733
-                );
1734
-            }
1735
-            $list_table = $this->_route_config['list_table'];
1736
-            $this->_list_table_object = new $list_table($this);
1737
-        }
1738
-    }
1739
-
1740
-
1741
-
1742
-    /**
1743
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1744
-     *
1745
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1746
-     *                                                    urls.  The array should be indexed by the view it is being
1747
-     *                                                    added to.
1748
-     * @return array
1749
-     */
1750
-    public function get_list_table_view_RLs($extra_query_args = array())
1751
-    {
1752
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1753
-        if (empty($this->_views)) {
1754
-            $this->_views = array();
1755
-        }
1756
-        // cycle thru views
1757
-        foreach ($this->_views as $key => $view) {
1758
-            $query_args = array();
1759
-            // check for current view
1760
-            $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1761
-            $query_args['action'] = $this->_req_action;
1762
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1763
-            $query_args['status'] = $view['slug'];
1764
-            //merge any other arguments sent in.
1765
-            if (isset($extra_query_args[$view['slug']])) {
1766
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1767
-            }
1768
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1769
-        }
1770
-        return $this->_views;
1771
-    }
1772
-
1773
-
1774
-
1775
-    /**
1776
-     * _entries_per_page_dropdown
1777
-     * generates a drop down box for selecting the number of visiable rows in an admin page list table
1778
-     *
1779
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1780
-     * @access protected
1781
-     * @param int $max_entries total number of rows in the table
1782
-     * @return string
1783
-     */
1784
-    protected function _entries_per_page_dropdown($max_entries = false)
1785
-    {
1786
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1787
-        $values = array(10, 25, 50, 100);
1788
-        $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1789
-        if ($max_entries) {
1790
-            $values[] = $max_entries;
1791
-            sort($values);
1792
-        }
1793
-        $entries_per_page_dropdown = '
145
+	// yes / no array for admin form fields
146
+	protected $_yes_no_values = array();
147
+
148
+	//some default things shared by all child classes
149
+	protected $_default_espresso_metaboxes;
150
+
151
+	/**
152
+	 *    EE_Registry Object
153
+	 *
154
+	 * @var    EE_Registry
155
+	 * @access    protected
156
+	 */
157
+	protected $EE = null;
158
+
159
+
160
+
161
+	/**
162
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
163
+	 *
164
+	 * @var boolean
165
+	 */
166
+	protected $_is_caf = false;
167
+
168
+
169
+
170
+	/**
171
+	 * @Constructor
172
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
173
+	 * @access public
174
+	 */
175
+	public function __construct($routing = true)
176
+	{
177
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
178
+			$this->_is_caf = true;
179
+		}
180
+		$this->_yes_no_values = array(
181
+				array('id' => true, 'text' => __('Yes', 'event_espresso')),
182
+				array('id' => false, 'text' => __('No', 'event_espresso')),
183
+		);
184
+		//set the _req_data property.
185
+		$this->_req_data = array_merge($_GET, $_POST);
186
+		//routing enabled?
187
+		$this->_routing = $routing;
188
+		//set initial page props (child method)
189
+		$this->_init_page_props();
190
+		//set global defaults
191
+		$this->_set_defaults();
192
+		//set early because incoming requests could be ajax related and we need to register those hooks.
193
+		$this->_global_ajax_hooks();
194
+		$this->_ajax_hooks();
195
+		//other_page_hooks have to be early too.
196
+		$this->_do_other_page_hooks();
197
+		//This just allows us to have extending classes do something specific
198
+		// before the parent constructor runs _page_setup().
199
+		if (method_exists($this, '_before_page_setup')) {
200
+			$this->_before_page_setup();
201
+		}
202
+		//set up page dependencies
203
+		$this->_page_setup();
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * _init_page_props
210
+	 * Child classes use to set at least the following properties:
211
+	 * $page_slug.
212
+	 * $page_label.
213
+	 *
214
+	 * @abstract
215
+	 * @access protected
216
+	 * @return void
217
+	 */
218
+	abstract protected function _init_page_props();
219
+
220
+
221
+
222
+	/**
223
+	 * _ajax_hooks
224
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
225
+	 * Note: within the ajax callback methods.
226
+	 *
227
+	 * @abstract
228
+	 * @access protected
229
+	 * @return void
230
+	 */
231
+	abstract protected function _ajax_hooks();
232
+
233
+
234
+
235
+	/**
236
+	 * _define_page_props
237
+	 * child classes define page properties in here.  Must include at least:
238
+	 * $_admin_base_url = base_url for all admin pages
239
+	 * $_admin_page_title = default admin_page_title for admin pages
240
+	 * $_labels = array of default labels for various automatically generated elements:
241
+	 *    array(
242
+	 *        'buttons' => array(
243
+	 *            'add' => __('label for add new button'),
244
+	 *            'edit' => __('label for edit button'),
245
+	 *            'delete' => __('label for delete button')
246
+	 *            )
247
+	 *        )
248
+	 *
249
+	 * @abstract
250
+	 * @access protected
251
+	 * @return void
252
+	 */
253
+	abstract protected function _define_page_props();
254
+
255
+
256
+
257
+	/**
258
+	 * _set_page_routes
259
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
260
+	 * route. Here's the format
261
+	 * $this->_page_routes = array(
262
+	 *        'default' => array(
263
+	 *            'func' => '_default_method_handling_route',
264
+	 *            'args' => array('array','of','args'),
265
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
266
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
267
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
268
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
269
+	 *        ),
270
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
271
+	 *        )
272
+	 * )
273
+	 *
274
+	 * @abstract
275
+	 * @access protected
276
+	 * @return void
277
+	 */
278
+	abstract protected function _set_page_routes();
279
+
280
+
281
+
282
+	/**
283
+	 * _set_page_config
284
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
285
+	 * Format:
286
+	 * $this->_page_config = array(
287
+	 *        'default' => array(
288
+	 *            'labels' => array(
289
+	 *                'buttons' => array(
290
+	 *                    'add' => __('label for adding item'),
291
+	 *                    'edit' => __('label for editing item'),
292
+	 *                    'delete' => __('label for deleting item')
293
+	 *                ),
294
+	 *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
295
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
296
+	 *            'nav' => array(
297
+	 *                'label' => __('Label for Tab', 'event_espresso').
298
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
299
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
300
+	 *                'order' => 10, //required to indicate tab position.
301
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
302
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
303
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
304
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
305
+	 *            this flag to make sure the necessary js gets enqueued on page load.
306
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
307
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
308
+	 *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
309
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
310
+	 *                'tab_id' => array(
311
+	 *                    'title' => 'tab_title',
312
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
313
+	 *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
314
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
315
+	 *                    ),
316
+	 *                'tab2_id' => array(
317
+	 *                    'title' => 'tab2 title',
318
+	 *                    'filename' => 'file_name_2'
319
+	 *                    'callback' => 'callback_method_for_content',
320
+	 *                 ),
321
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
322
+	 *            'help_tour' => array(
323
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
324
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
325
+	 *            ),
326
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
327
+	 *            'require_nonce' to FALSE
328
+	 *            )
329
+	 * )
330
+	 *
331
+	 * @abstract
332
+	 * @access protected
333
+	 * @return void
334
+	 */
335
+	abstract protected function _set_page_config();
336
+
337
+
338
+
339
+
340
+
341
+	/** end sample help_tour methods **/
342
+	/**
343
+	 * _add_screen_options
344
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
345
+	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
346
+	 *
347
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
348
+	 *         see also WP_Screen object documents...
349
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
350
+	 * @abstract
351
+	 * @access protected
352
+	 * @return void
353
+	 */
354
+	abstract protected function _add_screen_options();
355
+
356
+
357
+
358
+	/**
359
+	 * _add_feature_pointers
360
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
361
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
362
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
363
+	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
364
+	 *
365
+	 * @link   http://eamann.com/tech/wordpress-portland/
366
+	 * @abstract
367
+	 * @access protected
368
+	 * @return void
369
+	 */
370
+	abstract protected function _add_feature_pointers();
371
+
372
+
373
+
374
+	/**
375
+	 * load_scripts_styles
376
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
377
+	 * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
378
+	 *
379
+	 * @abstract
380
+	 * @access public
381
+	 * @return void
382
+	 */
383
+	abstract public function load_scripts_styles();
384
+
385
+
386
+
387
+	/**
388
+	 * admin_init
389
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
390
+	 *
391
+	 * @abstract
392
+	 * @access public
393
+	 * @return void
394
+	 */
395
+	abstract public function admin_init();
396
+
397
+
398
+
399
+	/**
400
+	 * admin_notices
401
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
402
+	 *
403
+	 * @abstract
404
+	 * @access public
405
+	 * @return void
406
+	 */
407
+	abstract public function admin_notices();
408
+
409
+
410
+
411
+	/**
412
+	 * admin_footer_scripts
413
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
414
+	 *
415
+	 * @access public
416
+	 * @return void
417
+	 */
418
+	abstract public function admin_footer_scripts();
419
+
420
+
421
+
422
+	/**
423
+	 * admin_footer
424
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
425
+	 *
426
+	 * @access  public
427
+	 * @return void
428
+	 */
429
+	public function admin_footer()
430
+	{
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * _global_ajax_hooks
437
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
438
+	 * Note: within the ajax callback methods.
439
+	 *
440
+	 * @abstract
441
+	 * @access protected
442
+	 * @return void
443
+	 */
444
+	protected function _global_ajax_hooks()
445
+	{
446
+		//for lazy loading of metabox content
447
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
448
+	}
449
+
450
+
451
+
452
+	public function ajax_metabox_content()
453
+	{
454
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
455
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
456
+		self::cached_rss_display($contentid, $url);
457
+		wp_die();
458
+	}
459
+
460
+
461
+
462
+	/**
463
+	 * _page_setup
464
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
465
+	 *
466
+	 * @final
467
+	 * @access protected
468
+	 * @return void
469
+	 */
470
+	final protected function _page_setup()
471
+	{
472
+		//requires?
473
+		//admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
474
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
475
+		//next verify if we need to load anything...
476
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
477
+		$this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
478
+		global $ee_menu_slugs;
479
+		$ee_menu_slugs = (array)$ee_menu_slugs;
480
+		if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
481
+			return;
482
+		}
483
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
484
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
485
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
486
+		}
487
+		// then set blank or -1 action values to 'default'
488
+		$this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
489
+		//if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
490
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
492
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
493
+		$this->_current_view = $this->_req_action;
494
+		$this->_req_nonce = $this->_req_action . '_nonce';
495
+		$this->_define_page_props();
496
+		$this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
497
+		//default things
498
+		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
499
+		//set page configs
500
+		$this->_set_page_routes();
501
+		$this->_set_page_config();
502
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
503
+		if (isset($this->_req_data['wp_referer'])) {
504
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
505
+		}
506
+		//for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
507
+		if (method_exists($this, '_extend_page_config')) {
508
+			$this->_extend_page_config();
509
+		}
510
+		//for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
511
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
512
+			$this->_extend_page_config_for_cpt();
513
+		}
514
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
515
+		$this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
516
+		$this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
517
+		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
518
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
519
+			add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
520
+		}
521
+		//next route only if routing enabled
522
+		if ($this->_routing && ! defined('DOING_AJAX')) {
523
+			$this->_verify_routes();
524
+			//next let's just check user_access and kill if no access
525
+			$this->check_user_access();
526
+			if ($this->_is_UI_request) {
527
+				//admin_init stuff - global, all views for this page class, specific view
528
+				add_action('admin_init', array($this, 'admin_init'), 10);
529
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
530
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
531
+				}
532
+			} else {
533
+				//hijack regular WP loading and route admin request immediately
534
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
535
+				$this->route_admin_request();
536
+			}
537
+		}
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
544
+	 *
545
+	 * @access private
546
+	 * @return void
547
+	 */
548
+	private function _do_other_page_hooks()
549
+	{
550
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
551
+		foreach ($registered_pages as $page) {
552
+			//now let's setup the file name and class that should be present
553
+			$classname = str_replace('.class.php', '', $page);
554
+			//autoloaders should take care of loading file
555
+			if ( ! class_exists($classname)) {
556
+				$error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
557
+				$error_msg[] = $error_msg[0]
558
+							   . "\r\n"
559
+							   . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
560
+								'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
561
+				throw new EE_Error(implode('||', $error_msg));
562
+			}
563
+			$a = new ReflectionClass($classname);
564
+			//notice we are passing the instance of this class to the hook object.
565
+			$hookobj[] = $a->newInstance($this);
566
+		}
567
+	}
568
+
569
+
570
+
571
+	public function load_page_dependencies()
572
+	{
573
+		try {
574
+			$this->_load_page_dependencies();
575
+		} catch (EE_Error $e) {
576
+			$e->get_error();
577
+		}
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * load_page_dependencies
584
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
585
+	 *
586
+	 * @access public
587
+	 * @return void
588
+	 */
589
+	protected function _load_page_dependencies()
590
+	{
591
+		//let's set the current_screen and screen options to override what WP set
592
+		$this->_current_screen = get_current_screen();
593
+		//load admin_notices - global, page class, and view specific
594
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
595
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
596
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
597
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
598
+		}
599
+		//load network admin_notices - global, page class, and view specific
600
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
601
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
602
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
603
+		}
604
+		//this will save any per_page screen options if they are present
605
+		$this->_set_per_page_screen_options();
606
+		//setup list table properties
607
+		$this->_set_list_table();
608
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
609
+		$this->_add_registered_meta_boxes();
610
+		$this->_add_screen_columns();
611
+		//add screen options - global, page child class, and view specific
612
+		$this->_add_global_screen_options();
613
+		$this->_add_screen_options();
614
+		if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
615
+			call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
616
+		}
617
+		//add help tab(s) and tours- set via page_config and qtips.
618
+		$this->_add_help_tour();
619
+		$this->_add_help_tabs();
620
+		$this->_add_qtips();
621
+		//add feature_pointers - global, page child class, and view specific
622
+		$this->_add_feature_pointers();
623
+		$this->_add_global_feature_pointers();
624
+		if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
625
+			call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
626
+		}
627
+		//enqueue scripts/styles - global, page class, and view specific
628
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
629
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
630
+		if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
631
+			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
632
+		}
633
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
634
+		//admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
635
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
636
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
637
+		if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
638
+			add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
639
+		}
640
+		//admin footer scripts
641
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
642
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
643
+		if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
644
+			add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
645
+		}
646
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
647
+		//targeted hook
648
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
649
+	}
650
+
651
+
652
+
653
+	/**
654
+	 * _set_defaults
655
+	 * This sets some global defaults for class properties.
656
+	 */
657
+	private function _set_defaults()
658
+	{
659
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
660
+		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
661
+		$this->default_nav_tab_name = 'overview';
662
+		//init template args
663
+		$this->_template_args = array(
664
+				'admin_page_header'  => '',
665
+				'admin_page_content' => '',
666
+				'post_body_content'  => '',
667
+				'before_list_table'  => '',
668
+				'after_list_table'   => '',
669
+		);
670
+	}
671
+
672
+
673
+
674
+	/**
675
+	 * route_admin_request
676
+	 *
677
+	 * @see    _route_admin_request()
678
+	 * @access public
679
+	 * @return void|exception error
680
+	 */
681
+	public function route_admin_request()
682
+	{
683
+		try {
684
+			$this->_route_admin_request();
685
+		} catch (EE_Error $e) {
686
+			$e->get_error();
687
+		}
688
+	}
689
+
690
+
691
+
692
+	public function set_wp_page_slug($wp_page_slug)
693
+	{
694
+		$this->_wp_page_slug = $wp_page_slug;
695
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
696
+		if (is_network_admin()) {
697
+			$this->_wp_page_slug .= '-network';
698
+		}
699
+	}
700
+
701
+
702
+
703
+	/**
704
+	 * _verify_routes
705
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
706
+	 *
707
+	 * @access protected
708
+	 * @return void
709
+	 */
710
+	protected function _verify_routes()
711
+	{
712
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
713
+		if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
714
+			return false;
715
+		}
716
+		$this->_route = false;
717
+		$func = false;
718
+		$args = array();
719
+		// check that the page_routes array is not empty
720
+		if (empty($this->_page_routes)) {
721
+			// user error msg
722
+			$error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
723
+			// developer error msg
724
+			$error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
725
+			throw new EE_Error($error_msg);
726
+		}
727
+		// and that the requested page route exists
728
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
729
+			$this->_route = $this->_page_routes[$this->_req_action];
730
+			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
731
+		} else {
732
+			// user error msg
733
+			$error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
734
+			// developer error msg
735
+			$error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
736
+			throw new EE_Error($error_msg);
737
+		}
738
+		// and that a default route exists
739
+		if ( ! array_key_exists('default', $this->_page_routes)) {
740
+			// user error msg
741
+			$error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
742
+			// developer error msg
743
+			$error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
744
+			throw new EE_Error($error_msg);
745
+		}
746
+		//first lets' catch if the UI request has EVER been set.
747
+		if ($this->_is_UI_request === null) {
748
+			//lets set if this is a UI request or not.
749
+			$this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
750
+			//wait a minute... we might have a noheader in the route array
751
+			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
752
+		}
753
+		$this->_set_current_labels();
754
+	}
755
+
756
+
757
+
758
+	/**
759
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
760
+	 *
761
+	 * @param  string $route the route name we're verifying
762
+	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
763
+	 */
764
+	protected function _verify_route($route)
765
+	{
766
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
767
+			return true;
768
+		} else {
769
+			// user error msg
770
+			$error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
771
+			// developer error msg
772
+			$error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
773
+			throw new EE_Error($error_msg);
774
+		}
775
+	}
776
+
777
+
778
+
779
+	/**
780
+	 * perform nonce verification
781
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
782
+	 *
783
+	 * @param  string $nonce     The nonce sent
784
+	 * @param  string $nonce_ref The nonce reference string (name0)
785
+	 * @return mixed (bool|die)
786
+	 */
787
+	protected function _verify_nonce($nonce, $nonce_ref)
788
+	{
789
+		// verify nonce against expected value
790
+		if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
791
+			// these are not the droids you are looking for !!!
792
+			$msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
793
+			if (WP_DEBUG) {
794
+				$msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
795
+			}
796
+			if ( ! defined('DOING_AJAX')) {
797
+				wp_die($msg);
798
+			} else {
799
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
800
+				$this->_return_json();
801
+			}
802
+		}
803
+	}
804
+
805
+
806
+
807
+	/**
808
+	 * _route_admin_request()
809
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
810
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
811
+	 * in the page routes and then will try to load the corresponding method.
812
+	 *
813
+	 * @access protected
814
+	 * @return void
815
+	 * @throws \EE_Error
816
+	 */
817
+	protected function _route_admin_request()
818
+	{
819
+		if ( ! $this->_is_UI_request) {
820
+			$this->_verify_routes();
821
+		}
822
+		$nonce_check = isset($this->_route_config['require_nonce'])
823
+			? $this->_route_config['require_nonce']
824
+			: true;
825
+		if ($this->_req_action !== 'default' && $nonce_check) {
826
+			// set nonce from post data
827
+			$nonce = isset($this->_req_data[$this->_req_nonce])
828
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
829
+				: '';
830
+			$this->_verify_nonce($nonce, $this->_req_nonce);
831
+		}
832
+		//set the nav_tabs array but ONLY if this is  UI_request
833
+		if ($this->_is_UI_request) {
834
+			$this->_set_nav_tabs();
835
+		}
836
+		// grab callback function
837
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
838
+		// check if callback has args
839
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
840
+		$error_msg = '';
841
+		// action right before calling route
842
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
843
+		if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
844
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
845
+		}
846
+		// right before calling the route, let's remove _wp_http_referer from the
847
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
848
+		$_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
849
+		if ( ! empty($func)) {
850
+			if (is_array($func)) {
851
+				list($class, $method) = $func;
852
+			} else if (strpos($func, '::') !== false) {
853
+				list($class, $method) = explode('::', $func);
854
+			} else {
855
+				$class = $this;
856
+				$method = $func;
857
+			}
858
+			if ( ! (is_object($class) && $class === $this)) {
859
+				// send along this admin page object for access by addons.
860
+				$args['admin_page_object'] = $this;
861
+			}
862
+
863
+			if (
864
+				//is it a method on a class that doesn't work?
865
+				(
866
+					(
867
+						method_exists($class, $method)
868
+						&& call_user_func_array(array($class, $method), $args) === false
869
+					)
870
+					&& (
871
+						//is it a standalone function that doesn't work?
872
+						function_exists($method)
873
+						&& call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
874
+					)
875
+				)
876
+				|| (
877
+					//is it neither a class method NOR a standalone function?
878
+					! method_exists($class, $method)
879
+					&& ! function_exists($method)
880
+				)
881
+			) {
882
+				// user error msg
883
+				$error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
884
+				// developer error msg
885
+				$error_msg .= '||';
886
+				$error_msg .= sprintf(
887
+					__(
888
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
889
+						'event_espresso'
890
+					),
891
+					$method
892
+				);
893
+			}
894
+			if ( ! empty($error_msg)) {
895
+				throw new EE_Error($error_msg);
896
+			}
897
+		}
898
+		//if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
899
+		//now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
900
+		if ($this->_is_UI_request === false
901
+			&& is_array($this->_route)
902
+			&& ! empty($this->_route['headers_sent_route'])
903
+		) {
904
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
905
+		}
906
+	}
907
+
908
+
909
+
910
+	/**
911
+	 * This method just allows the resetting of page properties in the case where a no headers
912
+	 * route redirects to a headers route in its route config.
913
+	 *
914
+	 * @since   4.3.0
915
+	 * @param  string $new_route New (non header) route to redirect to.
916
+	 * @return   void
917
+	 */
918
+	protected function _reset_routing_properties($new_route)
919
+	{
920
+		$this->_is_UI_request = true;
921
+		//now we set the current route to whatever the headers_sent_route is set at
922
+		$this->_req_data['action'] = $new_route;
923
+		//rerun page setup
924
+		$this->_page_setup();
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * _add_query_arg
931
+	 * adds nonce to array of arguments then calls WP add_query_arg function
932
+	 *(internally just uses EEH_URL's function with the same name)
933
+	 *
934
+	 * @access public
935
+	 * @param array  $args
936
+	 * @param string $url
937
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
938
+	 *                                        url in an associative array indexed by the key 'wp_referer';
939
+	 *                                        Example usage:
940
+	 *                                        If the current page is:
941
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
942
+	 *                                        &action=default&event_id=20&month_range=March%202015
943
+	 *                                        &_wpnonce=5467821
944
+	 *                                        and you call:
945
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
946
+	 *                                        array(
947
+	 *                                        'action' => 'resend_something',
948
+	 *                                        'page=>espresso_registrations'
949
+	 *                                        ),
950
+	 *                                        $some_url,
951
+	 *                                        true
952
+	 *                                        );
953
+	 *                                        It will produce a url in this structure:
954
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
955
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
956
+	 *                                        month_range]=March%202015
957
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
958
+	 * @return string
959
+	 */
960
+	public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
961
+	{
962
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
963
+		if ($sticky) {
964
+			$request = $_REQUEST;
965
+			unset($request['_wp_http_referer']);
966
+			unset($request['wp_referer']);
967
+			foreach ($request as $key => $value) {
968
+				//do not add nonces
969
+				if (strpos($key, 'nonce') !== false) {
970
+					continue;
971
+				}
972
+				$args['wp_referer[' . $key . ']'] = $value;
973
+			}
974
+		}
975
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
976
+	}
977
+
978
+
979
+
980
+	/**
981
+	 * This returns a generated link that will load the related help tab.
982
+	 *
983
+	 * @param  string $help_tab_id the id for the connected help tab
984
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
985
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
986
+	 * @uses EEH_Template::get_help_tab_link()
987
+	 * @return string              generated link
988
+	 */
989
+	protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
990
+	{
991
+		return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
992
+	}
993
+
994
+
995
+
996
+	/**
997
+	 * _add_help_tabs
998
+	 * Note child classes define their help tabs within the page_config array.
999
+	 *
1000
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1001
+	 * @access protected
1002
+	 * @return void
1003
+	 */
1004
+	protected function _add_help_tabs()
1005
+	{
1006
+		$tour_buttons = '';
1007
+		if (isset($this->_page_config[$this->_req_action])) {
1008
+			$config = $this->_page_config[$this->_req_action];
1009
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1010
+			if (isset($this->_help_tour[$this->_req_action])) {
1011
+				$tb = array();
1012
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1013
+				foreach ($this->_help_tour['tours'] as $tour) {
1014
+					//if this is the end tour then we don't need to setup a button
1015
+					if ($tour instanceof EE_Help_Tour_final_stop) {
1016
+						continue;
1017
+					}
1018
+					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1019
+				}
1020
+				$tour_buttons .= implode('<br />', $tb);
1021
+				$tour_buttons .= '</div></div>';
1022
+			}
1023
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1024
+			if (is_array($config) && isset($config['help_sidebar'])) {
1025
+				//check that the callback given is valid
1026
+				if ( ! method_exists($this, $config['help_sidebar'])) {
1027
+					throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1028
+							'event_espresso'), $config['help_sidebar'], get_class($this)));
1029
+				}
1030
+				$content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1031
+				$content .= $tour_buttons; //add help tour buttons.
1032
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1033
+				$this->_current_screen->set_help_sidebar($content);
1034
+			}
1035
+			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1036
+			if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1037
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1038
+			}
1039
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1040
+			if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1041
+				$_ht['id'] = $this->page_slug;
1042
+				$_ht['title'] = __('Help Tours', 'event_espresso');
1043
+				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1044
+				$this->_current_screen->add_help_tab($_ht);
1045
+			}/**/
1046
+			if ( ! isset($config['help_tabs'])) {
1047
+				return;
1048
+			} //no help tabs for this route
1049
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1050
+				//we're here so there ARE help tabs!
1051
+				//make sure we've got what we need
1052
+				if ( ! isset($cfg['title'])) {
1053
+					throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1054
+				}
1055
+				if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1056
+					throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1057
+							'event_espresso'));
1058
+				}
1059
+				//first priority goes to content.
1060
+				if ( ! empty($cfg['content'])) {
1061
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1062
+					//second priority goes to filename
1063
+				} else if ( ! empty($cfg['filename'])) {
1064
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1065
+					//it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1066
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1067
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1068
+					if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1069
+						EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1070
+								'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1071
+						return;
1072
+					}
1073
+					$template_args['admin_page_obj'] = $this;
1074
+					$content = EEH_Template::display_template($file_path, $template_args, true);
1075
+				} else {
1076
+					$content = '';
1077
+				}
1078
+				//check if callback is valid
1079
+				if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1080
+					EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1081
+							'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1082
+					return;
1083
+				}
1084
+				//setup config array for help tab method
1085
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1086
+				$_ht = array(
1087
+						'id'       => $id,
1088
+						'title'    => $cfg['title'],
1089
+						'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1090
+						'content'  => $content,
1091
+				);
1092
+				$this->_current_screen->add_help_tab($_ht);
1093
+			}
1094
+		}
1095
+	}
1096
+
1097
+
1098
+
1099
+	/**
1100
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1101
+	 *
1102
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1103
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1104
+	 * @access protected
1105
+	 * @return void
1106
+	 */
1107
+	protected function _add_help_tour()
1108
+	{
1109
+		$tours = array();
1110
+		$this->_help_tour = array();
1111
+		//exit early if help tours are turned off globally
1112
+		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1113
+			return;
1114
+		}
1115
+		//loop through _page_config to find any help_tour defined
1116
+		foreach ($this->_page_config as $route => $config) {
1117
+			//we're only going to set things up for this route
1118
+			if ($route !== $this->_req_action) {
1119
+				continue;
1120
+			}
1121
+			if (isset($config['help_tour'])) {
1122
+				foreach ($config['help_tour'] as $tour) {
1123
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1124
+					//let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1125
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1126
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1127
+					if ( ! is_readable($file_path)) {
1128
+						EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1129
+								$file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1130
+						return;
1131
+					}
1132
+					require_once $file_path;
1133
+					if ( ! class_exists($tour)) {
1134
+						$error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1135
+						$error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1136
+										'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1137
+						throw new EE_Error(implode('||', $error_msg));
1138
+					}
1139
+					$a = new ReflectionClass($tour);
1140
+					$tour_obj = $a->newInstance($this->_is_caf);
1141
+					$tours[] = $tour_obj;
1142
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1143
+				}
1144
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1145
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1146
+				$tours[] = $end_stop_tour;
1147
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1148
+			}
1149
+		}
1150
+		if ( ! empty($tours)) {
1151
+			$this->_help_tour['tours'] = $tours;
1152
+		}
1153
+		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1154
+	}
1155
+
1156
+
1157
+
1158
+	/**
1159
+	 * This simply sets up any qtips that have been defined in the page config
1160
+	 *
1161
+	 * @access protected
1162
+	 * @return void
1163
+	 */
1164
+	protected function _add_qtips()
1165
+	{
1166
+		if (isset($this->_route_config['qtips'])) {
1167
+			$qtips = (array)$this->_route_config['qtips'];
1168
+			//load qtip loader
1169
+			$path = array(
1170
+					$this->_get_dir() . '/qtips/',
1171
+					EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1172
+			);
1173
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1174
+		}
1175
+	}
1176
+
1177
+
1178
+
1179
+	/**
1180
+	 * _set_nav_tabs
1181
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1182
+	 *
1183
+	 * @access protected
1184
+	 * @return void
1185
+	 */
1186
+	protected function _set_nav_tabs()
1187
+	{
1188
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1189
+		$i = 0;
1190
+		foreach ($this->_page_config as $slug => $config) {
1191
+			if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1192
+				continue;
1193
+			} //no nav tab for this config
1194
+			//check for persistent flag
1195
+			if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1196
+				continue;
1197
+			} //nav tab is only to appear when route requested.
1198
+			if ( ! $this->check_user_access($slug, true)) {
1199
+				continue;
1200
+			} //no nav tab becasue current user does not have access.
1201
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1202
+			$this->_nav_tabs[$slug] = array(
1203
+					'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1204
+					'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1205
+					'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1206
+					'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1207
+			);
1208
+			$i++;
1209
+		}
1210
+		//if $this->_nav_tabs is empty then lets set the default
1211
+		if (empty($this->_nav_tabs)) {
1212
+			$this->_nav_tabs[$this->default_nav_tab_name] = array(
1213
+					'url'       => $this->admin_base_url,
1214
+					'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1215
+					'css_class' => 'nav-tab-active',
1216
+					'order'     => 10,
1217
+			);
1218
+		}
1219
+		//now let's sort the tabs according to order
1220
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1221
+	}
1222
+
1223
+
1224
+
1225
+	/**
1226
+	 * _set_current_labels
1227
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1228
+	 *
1229
+	 * @access private
1230
+	 * @return void
1231
+	 */
1232
+	private function _set_current_labels()
1233
+	{
1234
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1235
+			foreach ($this->_route_config['labels'] as $label => $text) {
1236
+				if (is_array($text)) {
1237
+					foreach ($text as $sublabel => $subtext) {
1238
+						$this->_labels[$label][$sublabel] = $subtext;
1239
+					}
1240
+				} else {
1241
+					$this->_labels[$label] = $text;
1242
+				}
1243
+			}
1244
+		}
1245
+	}
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 *        verifies user access for this admin page
1251
+	 *
1252
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1253
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1254
+	 * @return        BOOL|wp_die()
1255
+	 */
1256
+	public function check_user_access($route_to_check = '', $verify_only = false)
1257
+	{
1258
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1259
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1260
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1261
+				? $this->_page_routes[$route_to_check]['capability'] : null;
1262
+		if (empty($capability) && empty($route_to_check)) {
1263
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1264
+		} else {
1265
+			$capability = empty($capability) ? 'manage_options' : $capability;
1266
+		}
1267
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1268
+		if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1269
+			if ($verify_only) {
1270
+				return false;
1271
+			} else {
1272
+				if ( is_user_logged_in() ) {
1273
+					wp_die(__('You do not have access to this route.', 'event_espresso'));
1274
+				} else {
1275
+					return false;
1276
+				}
1277
+			}
1278
+		}
1279
+		return true;
1280
+	}
1281
+
1282
+
1283
+
1284
+	/**
1285
+	 * admin_init_global
1286
+	 * This runs all the code that we want executed within the WP admin_init hook.
1287
+	 * This method executes for ALL EE Admin pages.
1288
+	 *
1289
+	 * @access public
1290
+	 * @return void
1291
+	 */
1292
+	public function admin_init_global()
1293
+	{
1294
+	}
1295
+
1296
+
1297
+
1298
+	/**
1299
+	 * wp_loaded_global
1300
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1301
+	 *
1302
+	 * @access public
1303
+	 * @return void
1304
+	 */
1305
+	public function wp_loaded()
1306
+	{
1307
+	}
1308
+
1309
+
1310
+
1311
+	/**
1312
+	 * admin_notices
1313
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1314
+	 *
1315
+	 * @access public
1316
+	 * @return void
1317
+	 */
1318
+	public function admin_notices_global()
1319
+	{
1320
+		$this->_display_no_javascript_warning();
1321
+		$this->_display_espresso_notices();
1322
+	}
1323
+
1324
+
1325
+
1326
+	public function network_admin_notices_global()
1327
+	{
1328
+		$this->_display_no_javascript_warning();
1329
+		$this->_display_espresso_notices();
1330
+	}
1331
+
1332
+
1333
+
1334
+	/**
1335
+	 * admin_footer_scripts_global
1336
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1337
+	 *
1338
+	 * @access public
1339
+	 * @return void
1340
+	 */
1341
+	public function admin_footer_scripts_global()
1342
+	{
1343
+		$this->_add_admin_page_ajax_loading_img();
1344
+		$this->_add_admin_page_overlay();
1345
+		//if metaboxes are present we need to add the nonce field
1346
+		if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1347
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1348
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1349
+		}
1350
+	}
1351
+
1352
+
1353
+
1354
+	/**
1355
+	 * admin_footer_global
1356
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1357
+	 *
1358
+	 * @access  public
1359
+	 * @return  void
1360
+	 */
1361
+	public function admin_footer_global()
1362
+	{
1363
+		//dialog container for dialog helper
1364
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1365
+		$d_cont .= '<div class="ee-notices"></div>';
1366
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1367
+		$d_cont .= '</div>';
1368
+		echo $d_cont;
1369
+		//help tour stuff?
1370
+		if (isset($this->_help_tour[$this->_req_action])) {
1371
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1372
+		}
1373
+		//current set timezone for timezone js
1374
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1375
+	}
1376
+
1377
+
1378
+
1379
+	/**
1380
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1381
+	 * For child classes:
1382
+	 * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1383
+	 * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1384
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1385
+	 *    'help_trigger_id' => array(
1386
+	 *        'title' => __('localized title for popup', 'event_espresso'),
1387
+	 *        'content' => __('localized content for popup', 'event_espresso')
1388
+	 *    )
1389
+	 * );
1390
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1391
+	 *
1392
+	 * @access protected
1393
+	 * @return string content
1394
+	 */
1395
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1396
+	{
1397
+		$content = '';
1398
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1399
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1400
+		//loop through the array and setup content
1401
+		foreach ($help_array as $trigger => $help) {
1402
+			//make sure the array is setup properly
1403
+			if ( ! isset($help['title']) || ! isset($help['content'])) {
1404
+				throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1405
+						'event_espresso'));
1406
+			}
1407
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1408
+			$template_args = array(
1409
+					'help_popup_id'      => $trigger,
1410
+					'help_popup_title'   => $help['title'],
1411
+					'help_popup_content' => $help['content'],
1412
+			);
1413
+			$content .= EEH_Template::display_template($template_path, $template_args, true);
1414
+		}
1415
+		if ($display) {
1416
+			echo $content;
1417
+		} else {
1418
+			return $content;
1419
+		}
1420
+	}
1421
+
1422
+
1423
+
1424
+	/**
1425
+	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1426
+	 *
1427
+	 * @access private
1428
+	 * @return array properly formatted array for help popup content
1429
+	 */
1430
+	private function _get_help_content()
1431
+	{
1432
+		//what is the method we're looking for?
1433
+		$method_name = '_help_popup_content_' . $this->_req_action;
1434
+		//if method doesn't exist let's get out.
1435
+		if ( ! method_exists($this, $method_name)) {
1436
+			return array();
1437
+		}
1438
+		//k we're good to go let's retrieve the help array
1439
+		$help_array = call_user_func(array($this, $method_name));
1440
+		//make sure we've got an array!
1441
+		if ( ! is_array($help_array)) {
1442
+			throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1443
+		}
1444
+		return $help_array;
1445
+	}
1446
+
1447
+
1448
+
1449
+	/**
1450
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1451
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1452
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1453
+	 *
1454
+	 * @access protected
1455
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1456
+	 * @param boolean $display    if false then we return the trigger string
1457
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1458
+	 * @return string
1459
+	 */
1460
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1461
+	{
1462
+		if (defined('DOING_AJAX')) {
1463
+			return;
1464
+		}
1465
+		//let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1466
+		$help_array = $this->_get_help_content();
1467
+		$help_content = '';
1468
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1469
+			$help_array[$trigger_id] = array(
1470
+					'title'   => __('Missing Content', 'event_espresso'),
1471
+					'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1472
+							'event_espresso'),
1473
+			);
1474
+			$help_content = $this->_set_help_popup_content($help_array, false);
1475
+		}
1476
+		//let's setup the trigger
1477
+		$content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1478
+		$content = $content . $help_content;
1479
+		if ($display) {
1480
+			echo $content;
1481
+		} else {
1482
+			return $content;
1483
+		}
1484
+	}
1485
+
1486
+
1487
+
1488
+	/**
1489
+	 * _add_global_screen_options
1490
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1491
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1492
+	 *
1493
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1494
+	 *         see also WP_Screen object documents...
1495
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1496
+	 * @abstract
1497
+	 * @access private
1498
+	 * @return void
1499
+	 */
1500
+	private function _add_global_screen_options()
1501
+	{
1502
+	}
1503
+
1504
+
1505
+
1506
+	/**
1507
+	 * _add_global_feature_pointers
1508
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1509
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1510
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1511
+	 *
1512
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1513
+	 * @link   http://eamann.com/tech/wordpress-portland/
1514
+	 * @abstract
1515
+	 * @access protected
1516
+	 * @return void
1517
+	 */
1518
+	private function _add_global_feature_pointers()
1519
+	{
1520
+	}
1521
+
1522
+
1523
+
1524
+	/**
1525
+	 * load_global_scripts_styles
1526
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1527
+	 *
1528
+	 * @return void
1529
+	 */
1530
+	public function load_global_scripts_styles()
1531
+	{
1532
+		/** STYLES **/
1533
+		// add debugging styles
1534
+		if (WP_DEBUG) {
1535
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1536
+		}
1537
+		// register all styles
1538
+		wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1539
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1540
+		//helpers styles
1541
+		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1542
+		/** SCRIPTS **/
1543
+		//register all scripts
1544
+		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
+		wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1546
+		wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1547
+		add_filter('FHEE_load_joyride', '__return_true');
1548
+		//script for sorting tables
1549
+		wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1550
+		//script for parsing uri's
1551
+		wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1552
+		//and parsing associative serialized form elements
1553
+		wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
+		//helpers scripts
1555
+		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556
+		wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1557
+		wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1558
+		wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1559
+		//google charts
1560
+		wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1561
+		// ENQUEUE ALL BASICS BY DEFAULT
1562
+		wp_enqueue_style('ee-admin-css');
1563
+		wp_enqueue_script('ee_admin_js');
1564
+		wp_enqueue_script('ee-accounting');
1565
+		wp_enqueue_script('jquery-validate');
1566
+		//taking care of metaboxes
1567
+		if (
1568
+			empty($this->_cpt_route)
1569
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1570
+		) {
1571
+			wp_enqueue_script('dashboard');
1572
+		}
1573
+		// LOCALIZED DATA
1574
+		//localize script for ajax lazy loading
1575
+		$lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1576
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1577
+		/**
1578
+		 * help tour stuff
1579
+		 */
1580
+		if ( ! empty($this->_help_tour)) {
1581
+			//register the js for kicking things off
1582
+			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1583
+			//setup tours for the js tour object
1584
+			foreach ($this->_help_tour['tours'] as $tour) {
1585
+				$tours[] = array(
1586
+						'id'      => $tour->get_slug(),
1587
+						'options' => $tour->get_options(),
1588
+				);
1589
+			}
1590
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1591
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1592
+		}
1593
+	}
1594
+
1595
+
1596
+
1597
+	/**
1598
+	 *        admin_footer_scripts_eei18n_js_strings
1599
+	 *
1600
+	 * @access        public
1601
+	 * @return        void
1602
+	 */
1603
+	public function admin_footer_scripts_eei18n_js_strings()
1604
+	{
1605
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1606
+		EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1607
+		EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1608
+		EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1609
+		EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1610
+		EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1611
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1612
+		EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1613
+		EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1614
+		EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1615
+		EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1616
+		EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1617
+		EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1618
+		EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1619
+		EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1620
+		EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1621
+		EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1622
+		EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1623
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1624
+		EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1625
+		EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1626
+		EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1627
+		EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1628
+		EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1629
+		EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1630
+		EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1631
+		EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1632
+		EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1633
+		EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1634
+		EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1635
+		EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1636
+		EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1637
+		EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1638
+		EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1639
+		EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1640
+		EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1641
+		EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1642
+		EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1643
+		EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1644
+		EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1645
+	}
1646
+
1647
+
1648
+
1649
+	/**
1650
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1651
+	 *
1652
+	 * @access        public
1653
+	 * @return        void
1654
+	 */
1655
+	public function add_xdebug_style()
1656
+	{
1657
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1658
+	}
1659
+
1660
+
1661
+	/************************/
1662
+	/** LIST TABLE METHODS **/
1663
+	/************************/
1664
+	/**
1665
+	 * this sets up the list table if the current view requires it.
1666
+	 *
1667
+	 * @access protected
1668
+	 * @return void
1669
+	 */
1670
+	protected function _set_list_table()
1671
+	{
1672
+		//first is this a list_table view?
1673
+		if ( ! isset($this->_route_config['list_table'])) {
1674
+			return;
1675
+		} //not a list_table view so get out.
1676
+		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1677
+		if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1678
+			//user error msg
1679
+			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1680
+			//developer error msg
1681
+			$error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1682
+							$this->_req_action, '_set_list_table_views_' . $this->_req_action);
1683
+			throw new EE_Error($error_msg);
1684
+		}
1685
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1686
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1687
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1688
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1689
+		$this->_set_list_table_view();
1690
+		$this->_set_list_table_object();
1691
+	}
1692
+
1693
+
1694
+
1695
+	/**
1696
+	 *        set current view for List Table
1697
+	 *
1698
+	 * @access public
1699
+	 * @return array
1700
+	 */
1701
+	protected function _set_list_table_view()
1702
+	{
1703
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1704
+		// looking at active items or dumpster diving ?
1705
+		if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1706
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1707
+		} else {
1708
+			$this->_view = sanitize_key($this->_req_data['status']);
1709
+		}
1710
+	}
1711
+
1712
+
1713
+
1714
+	/**
1715
+	 * _set_list_table_object
1716
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1717
+	 *
1718
+	 * @throws \EE_Error
1719
+	 */
1720
+	protected function _set_list_table_object()
1721
+	{
1722
+		if (isset($this->_route_config['list_table'])) {
1723
+			if ( ! class_exists($this->_route_config['list_table'])) {
1724
+				throw new EE_Error(
1725
+						sprintf(
1726
+								__(
1727
+										'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1728
+										'event_espresso'
1729
+								),
1730
+								$this->_route_config['list_table'],
1731
+								get_class($this)
1732
+						)
1733
+				);
1734
+			}
1735
+			$list_table = $this->_route_config['list_table'];
1736
+			$this->_list_table_object = new $list_table($this);
1737
+		}
1738
+	}
1739
+
1740
+
1741
+
1742
+	/**
1743
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1744
+	 *
1745
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1746
+	 *                                                    urls.  The array should be indexed by the view it is being
1747
+	 *                                                    added to.
1748
+	 * @return array
1749
+	 */
1750
+	public function get_list_table_view_RLs($extra_query_args = array())
1751
+	{
1752
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1753
+		if (empty($this->_views)) {
1754
+			$this->_views = array();
1755
+		}
1756
+		// cycle thru views
1757
+		foreach ($this->_views as $key => $view) {
1758
+			$query_args = array();
1759
+			// check for current view
1760
+			$this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1761
+			$query_args['action'] = $this->_req_action;
1762
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1763
+			$query_args['status'] = $view['slug'];
1764
+			//merge any other arguments sent in.
1765
+			if (isset($extra_query_args[$view['slug']])) {
1766
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1767
+			}
1768
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1769
+		}
1770
+		return $this->_views;
1771
+	}
1772
+
1773
+
1774
+
1775
+	/**
1776
+	 * _entries_per_page_dropdown
1777
+	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1778
+	 *
1779
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1780
+	 * @access protected
1781
+	 * @param int $max_entries total number of rows in the table
1782
+	 * @return string
1783
+	 */
1784
+	protected function _entries_per_page_dropdown($max_entries = false)
1785
+	{
1786
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1787
+		$values = array(10, 25, 50, 100);
1788
+		$per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1789
+		if ($max_entries) {
1790
+			$values[] = $max_entries;
1791
+			sort($values);
1792
+		}
1793
+		$entries_per_page_dropdown = '
1794 1794
 			<div id="entries-per-page-dv" class="alignleft actions">
1795 1795
 				<label class="hide-if-no-js">
1796 1796
 					Show
1797 1797
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1798
-        foreach ($values as $value) {
1799
-            if ($value < $max_entries) {
1800
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1801
-                $entries_per_page_dropdown .= '
1798
+		foreach ($values as $value) {
1799
+			if ($value < $max_entries) {
1800
+				$selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1801
+				$entries_per_page_dropdown .= '
1802 1802
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1803
-            }
1804
-        }
1805
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1806
-        $entries_per_page_dropdown .= '
1803
+			}
1804
+		}
1805
+		$selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1806
+		$entries_per_page_dropdown .= '
1807 1807
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1808
-        $entries_per_page_dropdown .= '
1808
+		$entries_per_page_dropdown .= '
1809 1809
 					</select>
1810 1810
 					entries
1811 1811
 				</label>
1812 1812
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1813 1813
 			</div>
1814 1814
 		';
1815
-        return $entries_per_page_dropdown;
1816
-    }
1817
-
1818
-
1819
-
1820
-    /**
1821
-     *        _set_search_attributes
1822
-     *
1823
-     * @access        protected
1824
-     * @return        void
1825
-     */
1826
-    public function _set_search_attributes()
1827
-    {
1828
-        $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1829
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1830
-    }
1831
-
1832
-    /*** END LIST TABLE METHODS **/
1833
-    /*****************************/
1834
-    /**
1835
-     *        _add_registered_metaboxes
1836
-     *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1837
-     *
1838
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1839
-     * @access private
1840
-     * @return void
1841
-     */
1842
-    private function _add_registered_meta_boxes()
1843
-    {
1844
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1845
-        //we only add meta boxes if the page_route calls for it
1846
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1847
-            && is_array(
1848
-                    $this->_route_config['metaboxes']
1849
-            )
1850
-        ) {
1851
-            // this simply loops through the callbacks provided
1852
-            // and checks if there is a corresponding callback registered by the child
1853
-            // if there is then we go ahead and process the metabox loader.
1854
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1855
-                // first check for Closures
1856
-                if ($metabox_callback instanceof Closure) {
1857
-                    $result = $metabox_callback();
1858
-                } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1859
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1860
-                } else {
1861
-                    $result = call_user_func(array($this, &$metabox_callback));
1862
-                }
1863
-                if ($result === false) {
1864
-                    // user error msg
1865
-                    $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1866
-                    // developer error msg
1867
-                    $error_msg .= '||' . sprintf(
1868
-                                    __(
1869
-                                            'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1870
-                                            'event_espresso'
1871
-                                    ),
1872
-                                    $metabox_callback
1873
-                            );
1874
-                    throw new EE_Error($error_msg);
1875
-                }
1876
-            }
1877
-        }
1878
-    }
1879
-
1880
-
1881
-
1882
-    /**
1883
-     * _add_screen_columns
1884
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1885
-     *
1886
-     * @access private
1887
-     * @return void
1888
-     */
1889
-    private function _add_screen_columns()
1890
-    {
1891
-        if (
1892
-                is_array($this->_route_config)
1893
-                && isset($this->_route_config['columns'])
1894
-                && is_array($this->_route_config['columns'])
1895
-                && count($this->_route_config['columns']) === 2
1896
-        ) {
1897
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1898
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1899
-            $screen_id = $this->_current_screen->id;
1900
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1901
-            $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1902
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1903
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
1904
-            $this->_template_args['screen'] = $this->_current_screen;
1905
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1906
-            //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1907
-            $this->_route_config['has_metaboxes'] = true;
1908
-        }
1909
-    }
1910
-
1911
-
1912
-
1913
-    /**********************************/
1914
-    /** GLOBALLY AVAILABLE METABOXES **/
1915
-    /**
1916
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1917
-     * loaded on.
1918
-     */
1919
-    private function _espresso_news_post_box()
1920
-    {
1921
-        $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1922
-        add_meta_box('espresso_news_post_box', $news_box_title, array(
1923
-                $this,
1924
-                'espresso_news_post_box',
1925
-        ), $this->_wp_page_slug, 'side');
1926
-    }
1927
-
1928
-
1929
-
1930
-    /**
1931
-     * Code for setting up espresso ratings request metabox.
1932
-     */
1933
-    protected function _espresso_ratings_request()
1934
-    {
1935
-        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1936
-            return '';
1937
-        }
1938
-        $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1939
-        add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1940
-                $this,
1941
-                'espresso_ratings_request',
1942
-        ), $this->_wp_page_slug, 'side');
1943
-    }
1944
-
1945
-
1946
-
1947
-    /**
1948
-     * Code for setting up espresso ratings request metabox content.
1949
-     */
1950
-    public function espresso_ratings_request()
1951
-    {
1952
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1953
-        EEH_Template::display_template($template_path, array());
1954
-    }
1955
-
1956
-
1957
-
1958
-    public static function cached_rss_display($rss_id, $url)
1959
-    {
1960
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1961
-        $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1962
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1963
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1964
-        $post = '</div>' . "\n";
1965
-        $cache_key = 'ee_rss_' . md5($rss_id);
1966
-        if (false != ($output = get_transient($cache_key))) {
1967
-            echo $pre . $output . $post;
1968
-            return true;
1969
-        }
1970
-        if ( ! $doing_ajax) {
1971
-            echo $pre . $loading . $post;
1972
-            return false;
1973
-        }
1974
-        ob_start();
1975
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1976
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1977
-        return true;
1978
-    }
1979
-
1980
-
1981
-
1982
-    public function espresso_news_post_box()
1983
-    {
1984
-        ?>
1815
+		return $entries_per_page_dropdown;
1816
+	}
1817
+
1818
+
1819
+
1820
+	/**
1821
+	 *        _set_search_attributes
1822
+	 *
1823
+	 * @access        protected
1824
+	 * @return        void
1825
+	 */
1826
+	public function _set_search_attributes()
1827
+	{
1828
+		$this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1829
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1830
+	}
1831
+
1832
+	/*** END LIST TABLE METHODS **/
1833
+	/*****************************/
1834
+	/**
1835
+	 *        _add_registered_metaboxes
1836
+	 *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1837
+	 *
1838
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1839
+	 * @access private
1840
+	 * @return void
1841
+	 */
1842
+	private function _add_registered_meta_boxes()
1843
+	{
1844
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1845
+		//we only add meta boxes if the page_route calls for it
1846
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1847
+			&& is_array(
1848
+					$this->_route_config['metaboxes']
1849
+			)
1850
+		) {
1851
+			// this simply loops through the callbacks provided
1852
+			// and checks if there is a corresponding callback registered by the child
1853
+			// if there is then we go ahead and process the metabox loader.
1854
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1855
+				// first check for Closures
1856
+				if ($metabox_callback instanceof Closure) {
1857
+					$result = $metabox_callback();
1858
+				} else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1859
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1860
+				} else {
1861
+					$result = call_user_func(array($this, &$metabox_callback));
1862
+				}
1863
+				if ($result === false) {
1864
+					// user error msg
1865
+					$error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1866
+					// developer error msg
1867
+					$error_msg .= '||' . sprintf(
1868
+									__(
1869
+											'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1870
+											'event_espresso'
1871
+									),
1872
+									$metabox_callback
1873
+							);
1874
+					throw new EE_Error($error_msg);
1875
+				}
1876
+			}
1877
+		}
1878
+	}
1879
+
1880
+
1881
+
1882
+	/**
1883
+	 * _add_screen_columns
1884
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1885
+	 *
1886
+	 * @access private
1887
+	 * @return void
1888
+	 */
1889
+	private function _add_screen_columns()
1890
+	{
1891
+		if (
1892
+				is_array($this->_route_config)
1893
+				&& isset($this->_route_config['columns'])
1894
+				&& is_array($this->_route_config['columns'])
1895
+				&& count($this->_route_config['columns']) === 2
1896
+		) {
1897
+			add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1898
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1899
+			$screen_id = $this->_current_screen->id;
1900
+			$screen_columns = (int)get_user_option("screen_layout_$screen_id");
1901
+			$total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1902
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1903
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
1904
+			$this->_template_args['screen'] = $this->_current_screen;
1905
+			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1906
+			//finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1907
+			$this->_route_config['has_metaboxes'] = true;
1908
+		}
1909
+	}
1910
+
1911
+
1912
+
1913
+	/**********************************/
1914
+	/** GLOBALLY AVAILABLE METABOXES **/
1915
+	/**
1916
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1917
+	 * loaded on.
1918
+	 */
1919
+	private function _espresso_news_post_box()
1920
+	{
1921
+		$news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1922
+		add_meta_box('espresso_news_post_box', $news_box_title, array(
1923
+				$this,
1924
+				'espresso_news_post_box',
1925
+		), $this->_wp_page_slug, 'side');
1926
+	}
1927
+
1928
+
1929
+
1930
+	/**
1931
+	 * Code for setting up espresso ratings request metabox.
1932
+	 */
1933
+	protected function _espresso_ratings_request()
1934
+	{
1935
+		if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1936
+			return '';
1937
+		}
1938
+		$ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1939
+		add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1940
+				$this,
1941
+				'espresso_ratings_request',
1942
+		), $this->_wp_page_slug, 'side');
1943
+	}
1944
+
1945
+
1946
+
1947
+	/**
1948
+	 * Code for setting up espresso ratings request metabox content.
1949
+	 */
1950
+	public function espresso_ratings_request()
1951
+	{
1952
+		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1953
+		EEH_Template::display_template($template_path, array());
1954
+	}
1955
+
1956
+
1957
+
1958
+	public static function cached_rss_display($rss_id, $url)
1959
+	{
1960
+		$loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1961
+		$doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1962
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
1963
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1964
+		$post = '</div>' . "\n";
1965
+		$cache_key = 'ee_rss_' . md5($rss_id);
1966
+		if (false != ($output = get_transient($cache_key))) {
1967
+			echo $pre . $output . $post;
1968
+			return true;
1969
+		}
1970
+		if ( ! $doing_ajax) {
1971
+			echo $pre . $loading . $post;
1972
+			return false;
1973
+		}
1974
+		ob_start();
1975
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1976
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1977
+		return true;
1978
+	}
1979
+
1980
+
1981
+
1982
+	public function espresso_news_post_box()
1983
+	{
1984
+		?>
1985 1985
         <div class="padding">
1986 1986
             <div id="espresso_news_post_box_content" class="infolinks">
1987 1987
                 <?php
1988
-                // Get RSS Feed(s)
1989
-                $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1990
-                $url = urlencode($feed_url);
1991
-                self::cached_rss_display('espresso_news_post_box_content', $url);
1992
-                ?>
1988
+				// Get RSS Feed(s)
1989
+				$feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1990
+				$url = urlencode($feed_url);
1991
+				self::cached_rss_display('espresso_news_post_box_content', $url);
1992
+				?>
1993 1993
             </div>
1994 1994
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
1995 1995
         </div>
1996 1996
         <?php
1997
-    }
1998
-
1999
-
2000
-
2001
-    private function _espresso_links_post_box()
2002
-    {
2003
-        //Hiding until we actually have content to put in here...
2004
-        //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2005
-    }
2006
-
2007
-
2008
-
2009
-    public function espresso_links_post_box()
2010
-    {
2011
-        //Hiding until we actually have content to put in here...
2012
-        //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2013
-        //EEH_Template::display_template( $templatepath );
2014
-    }
2015
-
2016
-
2017
-
2018
-    protected function _espresso_sponsors_post_box()
2019
-    {
2020
-        $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2021
-        if ($show_sponsors) {
2022
-            add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2023
-        }
2024
-    }
2025
-
2026
-
2027
-
2028
-    public function espresso_sponsors_post_box()
2029
-    {
2030
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2031
-        EEH_Template::display_template($templatepath);
2032
-    }
2033
-
2034
-
2035
-
2036
-    private function _publish_post_box()
2037
-    {
2038
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2039
-        //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2040
-        if ( ! empty($this->_labels['publishbox'])) {
2041
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2042
-        } else {
2043
-            $box_label = __('Publish', 'event_espresso');
2044
-        }
2045
-        $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2046
-        add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2047
-    }
2048
-
2049
-
2050
-
2051
-    public function editor_overview()
2052
-    {
2053
-        //if we have extra content set let's add it in if not make sure its empty
2054
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2055
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2056
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2057
-    }
2058
-
2059
-
2060
-    /** end of globally available metaboxes section **/
2061
-    /*************************************************/
2062
-    /**
2063
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2064
-     * protected method.
2065
-     *
2066
-     * @see   $this->_set_publish_post_box_vars for param details
2067
-     * @since 4.6.0
2068
-     */
2069
-    public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2070
-    {
2071
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2072
-    }
2073
-
2074
-
2075
-
2076
-    /**
2077
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2078
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2079
-     * save, and save and close buttons to work properly, then you will want to include a
2080
-     * values for the name and id arguments.
2081
-     *
2082
-     * @todo  Add in validation for name/id arguments.
2083
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2084
-     * @param    int     $id                      id attached to the item published
2085
-     * @param    string  $delete                  page route callback for the delete action
2086
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2087
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2088
-     * @throws \EE_Error
2089
-     */
2090
-    protected function _set_publish_post_box_vars(
2091
-            $name = '',
2092
-            $id = 0,
2093
-            $delete = '',
2094
-            $save_close_redirect_URL = '',
2095
-            $both_btns = true
2096
-    ) {
2097
-        // if Save & Close, use a custom redirect URL or default to the main page?
2098
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2099
-        // create the Save & Close and Save buttons
2100
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2101
-        //if we have extra content set let's add it in if not make sure its empty
2102
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2103
-        if ($delete && ! empty($id)) {
2104
-            //make sure we have a default if just true is sent.
2105
-            $delete = ! empty($delete) ? $delete : 'delete';
2106
-            $delete_link_args = array($name => $id);
2107
-            $delete = $this->get_action_link_or_button(
2108
-                    $delete,
2109
-                    $delete,
2110
-                    $delete_link_args,
2111
-                    'submitdelete deletion',
2112
-                    '',
2113
-                    false
2114
-            );
2115
-        }
2116
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2117
-        if ( ! empty($name) && ! empty($id)) {
2118
-            $hidden_field_arr[$name] = array(
2119
-                    'type'  => 'hidden',
2120
-                    'value' => $id,
2121
-            );
2122
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2123
-        } else {
2124
-            $hf = '';
2125
-        }
2126
-        // add hidden field
2127
-        $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2128
-    }
2129
-
2130
-
2131
-
2132
-    /**
2133
-     *        displays an error message to ppl who have javascript disabled
2134
-     *
2135
-     * @access        private
2136
-     * @return        string
2137
-     */
2138
-    private function _display_no_javascript_warning()
2139
-    {
2140
-        ?>
1997
+	}
1998
+
1999
+
2000
+
2001
+	private function _espresso_links_post_box()
2002
+	{
2003
+		//Hiding until we actually have content to put in here...
2004
+		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2005
+	}
2006
+
2007
+
2008
+
2009
+	public function espresso_links_post_box()
2010
+	{
2011
+		//Hiding until we actually have content to put in here...
2012
+		//$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2013
+		//EEH_Template::display_template( $templatepath );
2014
+	}
2015
+
2016
+
2017
+
2018
+	protected function _espresso_sponsors_post_box()
2019
+	{
2020
+		$show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2021
+		if ($show_sponsors) {
2022
+			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2023
+		}
2024
+	}
2025
+
2026
+
2027
+
2028
+	public function espresso_sponsors_post_box()
2029
+	{
2030
+		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2031
+		EEH_Template::display_template($templatepath);
2032
+	}
2033
+
2034
+
2035
+
2036
+	private function _publish_post_box()
2037
+	{
2038
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2039
+		//if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2040
+		if ( ! empty($this->_labels['publishbox'])) {
2041
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2042
+		} else {
2043
+			$box_label = __('Publish', 'event_espresso');
2044
+		}
2045
+		$box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2046
+		add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2047
+	}
2048
+
2049
+
2050
+
2051
+	public function editor_overview()
2052
+	{
2053
+		//if we have extra content set let's add it in if not make sure its empty
2054
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2055
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2056
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2057
+	}
2058
+
2059
+
2060
+	/** end of globally available metaboxes section **/
2061
+	/*************************************************/
2062
+	/**
2063
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2064
+	 * protected method.
2065
+	 *
2066
+	 * @see   $this->_set_publish_post_box_vars for param details
2067
+	 * @since 4.6.0
2068
+	 */
2069
+	public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2070
+	{
2071
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2072
+	}
2073
+
2074
+
2075
+
2076
+	/**
2077
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2078
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2079
+	 * save, and save and close buttons to work properly, then you will want to include a
2080
+	 * values for the name and id arguments.
2081
+	 *
2082
+	 * @todo  Add in validation for name/id arguments.
2083
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2084
+	 * @param    int     $id                      id attached to the item published
2085
+	 * @param    string  $delete                  page route callback for the delete action
2086
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2087
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2088
+	 * @throws \EE_Error
2089
+	 */
2090
+	protected function _set_publish_post_box_vars(
2091
+			$name = '',
2092
+			$id = 0,
2093
+			$delete = '',
2094
+			$save_close_redirect_URL = '',
2095
+			$both_btns = true
2096
+	) {
2097
+		// if Save & Close, use a custom redirect URL or default to the main page?
2098
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2099
+		// create the Save & Close and Save buttons
2100
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2101
+		//if we have extra content set let's add it in if not make sure its empty
2102
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2103
+		if ($delete && ! empty($id)) {
2104
+			//make sure we have a default if just true is sent.
2105
+			$delete = ! empty($delete) ? $delete : 'delete';
2106
+			$delete_link_args = array($name => $id);
2107
+			$delete = $this->get_action_link_or_button(
2108
+					$delete,
2109
+					$delete,
2110
+					$delete_link_args,
2111
+					'submitdelete deletion',
2112
+					'',
2113
+					false
2114
+			);
2115
+		}
2116
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2117
+		if ( ! empty($name) && ! empty($id)) {
2118
+			$hidden_field_arr[$name] = array(
2119
+					'type'  => 'hidden',
2120
+					'value' => $id,
2121
+			);
2122
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2123
+		} else {
2124
+			$hf = '';
2125
+		}
2126
+		// add hidden field
2127
+		$this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2128
+	}
2129
+
2130
+
2131
+
2132
+	/**
2133
+	 *        displays an error message to ppl who have javascript disabled
2134
+	 *
2135
+	 * @access        private
2136
+	 * @return        string
2137
+	 */
2138
+	private function _display_no_javascript_warning()
2139
+	{
2140
+		?>
2141 2141
         <noscript>
2142 2142
             <div id="no-js-message" class="error">
2143 2143
                 <p style="font-size:1.3em;">
@@ -2147,1267 +2147,1267 @@  discard block
 block discarded – undo
2147 2147
             </div>
2148 2148
         </noscript>
2149 2149
         <?php
2150
-    }
2150
+	}
2151 2151
 
2152 2152
 
2153 2153
 
2154
-    /**
2155
-     *        displays espresso success and/or error notices
2156
-     *
2157
-     * @access        private
2158
-     * @return        string
2159
-     */
2160
-    private function _display_espresso_notices()
2161
-    {
2162
-        $notices = $this->_get_transient(true);
2163
-        echo stripslashes($notices);
2164
-    }
2154
+	/**
2155
+	 *        displays espresso success and/or error notices
2156
+	 *
2157
+	 * @access        private
2158
+	 * @return        string
2159
+	 */
2160
+	private function _display_espresso_notices()
2161
+	{
2162
+		$notices = $this->_get_transient(true);
2163
+		echo stripslashes($notices);
2164
+	}
2165 2165
 
2166 2166
 
2167 2167
 
2168
-    /**
2169
-     *        spinny things pacify the masses
2170
-     *
2171
-     * @access private
2172
-     * @return string
2173
-     */
2174
-    protected function _add_admin_page_ajax_loading_img()
2175
-    {
2176
-        ?>
2168
+	/**
2169
+	 *        spinny things pacify the masses
2170
+	 *
2171
+	 * @access private
2172
+	 * @return string
2173
+	 */
2174
+	protected function _add_admin_page_ajax_loading_img()
2175
+	{
2176
+		?>
2177 2177
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2178 2178
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span>
2179 2179
         </div>
2180 2180
         <?php
2181
-    }
2181
+	}
2182 2182
 
2183 2183
 
2184 2184
 
2185
-    /**
2186
-     *        add admin page overlay for modal boxes
2187
-     *
2188
-     * @access private
2189
-     * @return string
2190
-     */
2191
-    protected function _add_admin_page_overlay()
2192
-    {
2193
-        ?>
2185
+	/**
2186
+	 *        add admin page overlay for modal boxes
2187
+	 *
2188
+	 * @access private
2189
+	 * @return string
2190
+	 */
2191
+	protected function _add_admin_page_overlay()
2192
+	{
2193
+		?>
2194 2194
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2195 2195
         <?php
2196
-    }
2197
-
2198
-
2199
-
2200
-    /**
2201
-     * facade for add_meta_box
2202
-     *
2203
-     * @param string  $action        where the metabox get's displayed
2204
-     * @param string  $title         Title of Metabox (output in metabox header)
2205
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2206
-     * @param array   $callback_args an array of args supplied for the metabox
2207
-     * @param string  $column        what metabox column
2208
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2209
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2210
-     */
2211
-    public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2212
-    {
2213
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2214
-        //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2215
-        if (empty($callback_args) && $create_func) {
2216
-            $callback_args = array(
2217
-                    'template_path' => $this->_template_path,
2218
-                    'template_args' => $this->_template_args,
2219
-            );
2220
-        }
2221
-        //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2222
-        $call_back_func = $create_func ? create_function('$post, $metabox',
2223
-                'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2224
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2225
-    }
2226
-
2227
-
2228
-
2229
-    /**
2230
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2231
-     *
2232
-     * @return [type] [description]
2233
-     */
2234
-    public function display_admin_page_with_metabox_columns()
2235
-    {
2236
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2237
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2238
-        //the final wrapper
2239
-        $this->admin_page_wrapper();
2240
-    }
2241
-
2242
-
2243
-
2244
-    /**
2245
-     *        generates  HTML wrapper for an admin details page
2246
-     *
2247
-     * @access public
2248
-     * @return void
2249
-     */
2250
-    public function display_admin_page_with_sidebar()
2251
-    {
2252
-        $this->_display_admin_page(true);
2253
-    }
2254
-
2255
-
2256
-
2257
-    /**
2258
-     *        generates  HTML wrapper for an admin details page (except no sidebar)
2259
-     *
2260
-     * @access public
2261
-     * @return void
2262
-     */
2263
-    public function display_admin_page_with_no_sidebar()
2264
-    {
2265
-        $this->_display_admin_page();
2266
-    }
2267
-
2268
-
2269
-
2270
-    /**
2271
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2272
-     *
2273
-     * @access public
2274
-     * @return void
2275
-     */
2276
-    public function display_about_admin_page()
2277
-    {
2278
-        $this->_display_admin_page(false, true);
2279
-    }
2280
-
2281
-
2282
-
2283
-    /**
2284
-     * display_admin_page
2285
-     * contains the code for actually displaying an admin page
2286
-     *
2287
-     * @access private
2288
-     * @param  boolean $sidebar true with sidebar, false without
2289
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2290
-     * @return void
2291
-     */
2292
-    private function _display_admin_page($sidebar = false, $about = false)
2293
-    {
2294
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2295
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2296
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2297
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2298
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2299
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2300
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2301
-                ? 'poststuff'
2302
-                : 'espresso-default-admin';
2303
-        $template_path = $sidebar
2304
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2305
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2306
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2307
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2308
-        }
2309
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2310
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2311
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2312
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2313
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2314
-        // the final template wrapper
2315
-        $this->admin_page_wrapper($about);
2316
-    }
2317
-
2318
-
2319
-
2320
-    /**
2321
-     * This is used to display caf preview pages.
2322
-     *
2323
-     * @since 4.3.2
2324
-     * @param string $utm_campaign_source what is the key used for google analytics link
2325
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2326
-     * @return void
2327
-     * @throws \EE_Error
2328
-     */
2329
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2330
-    {
2331
-        //let's generate a default preview action button if there isn't one already present.
2332
-        $this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2333
-        $buy_now_url = add_query_arg(
2334
-                array(
2335
-                        'ee_ver'       => 'ee4',
2336
-                        'utm_source'   => 'ee4_plugin_admin',
2337
-                        'utm_medium'   => 'link',
2338
-                        'utm_campaign' => $utm_campaign_source,
2339
-                        'utm_content'  => 'buy_now_button',
2340
-                ),
2341
-                'http://eventespresso.com/pricing/'
2342
-        );
2343
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2344
-                ? $this->get_action_link_or_button(
2345
-                        '',
2346
-                        'buy_now',
2347
-                        array(),
2348
-                        'button-primary button-large',
2349
-                        $buy_now_url,
2350
-                        true
2351
-                )
2352
-                : $this->_template_args['preview_action_button'];
2353
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2354
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2355
-                $template_path,
2356
-                $this->_template_args,
2357
-                true
2358
-        );
2359
-        $this->_display_admin_page($display_sidebar);
2360
-    }
2361
-
2362
-
2363
-
2364
-    /**
2365
-     * display_admin_list_table_page_with_sidebar
2366
-     * generates HTML wrapper for an admin_page with list_table
2367
-     *
2368
-     * @access public
2369
-     * @return void
2370
-     */
2371
-    public function display_admin_list_table_page_with_sidebar()
2372
-    {
2373
-        $this->_display_admin_list_table_page(true);
2374
-    }
2375
-
2376
-
2377
-
2378
-    /**
2379
-     * display_admin_list_table_page_with_no_sidebar
2380
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2381
-     *
2382
-     * @access public
2383
-     * @return void
2384
-     */
2385
-    public function display_admin_list_table_page_with_no_sidebar()
2386
-    {
2387
-        $this->_display_admin_list_table_page();
2388
-    }
2389
-
2390
-
2391
-
2392
-    /**
2393
-     * generates html wrapper for an admin_list_table page
2394
-     *
2395
-     * @access private
2396
-     * @param boolean $sidebar whether to display with sidebar or not.
2397
-     * @return void
2398
-     */
2399
-    private function _display_admin_list_table_page($sidebar = false)
2400
-    {
2401
-        //setup search attributes
2402
-        $this->_set_search_attributes();
2403
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2404
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2405
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2406
-                ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2407
-                : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2408
-        $this->_template_args['list_table'] = $this->_list_table_object;
2409
-        $this->_template_args['current_route'] = $this->_req_action;
2410
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2411
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2412
-        if ( ! empty($ajax_sorting_callback)) {
2413
-            $sortable_list_table_form_fields = wp_nonce_field(
2414
-                    $ajax_sorting_callback . '_nonce',
2415
-                    $ajax_sorting_callback . '_nonce',
2416
-                    false,
2417
-                    false
2418
-            );
2419
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2420
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2421
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2422
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2423
-        } else {
2424
-            $sortable_list_table_form_fields = '';
2425
-        }
2426
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2427
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2428
-        $nonce_ref = $this->_req_action . '_nonce';
2429
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2430
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2431
-        //display message about search results?
2432
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2433
-                ? '<p class="ee-search-results">' . sprintf(
2434
-                        esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2435
-                        trim($this->_req_data['s'], '%')
2436
-                ) . '</p>'
2437
-                : '';
2438
-        // filter before_list_table template arg
2439
-        $this->_template_args['before_list_table'] = apply_filters(
2440
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2441
-            $this->_template_args['before_list_table'],
2442
-            $this->page_slug,
2443
-            $this->_req_data,
2444
-            $this->_req_action
2445
-        );
2446
-        // convert to array and filter again
2447
-        // arrays are easier to inject new items in a specific location,
2448
-        // but would not be backwards compatible, so we have to add a new filter
2449
-        $this->_template_args['before_list_table'] = implode(
2450
-            " \n",
2451
-            (array) apply_filters(
2452
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2453
-                (array) $this->_template_args['before_list_table'],
2454
-                $this->page_slug,
2455
-                $this->_req_data,
2456
-                $this->_req_action
2457
-            )
2458
-        );
2459
-        // filter after_list_table template arg
2460
-        $this->_template_args['after_list_table'] = apply_filters(
2461
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2462
-            $this->_template_args['after_list_table'],
2463
-            $this->page_slug,
2464
-            $this->_req_data,
2465
-            $this->_req_action
2466
-        );
2467
-        // convert to array and filter again
2468
-        // arrays are easier to inject new items in a specific location,
2469
-        // but would not be backwards compatible, so we have to add a new filter
2470
-        $this->_template_args['after_list_table'] = implode(
2471
-            " \n",
2472
-            (array) apply_filters(
2473
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2474
-                (array) $this->_template_args['after_list_table'],
2475
-                $this->page_slug,
2476
-                $this->_req_data,
2477
-                $this->_req_action
2478
-            )
2479
-        );
2480
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2481
-                $template_path,
2482
-                $this->_template_args,
2483
-                true
2484
-        );
2485
-        // the final template wrapper
2486
-        if ($sidebar) {
2487
-            $this->display_admin_page_with_sidebar();
2488
-        } else {
2489
-            $this->display_admin_page_with_no_sidebar();
2490
-        }
2491
-    }
2492
-
2493
-
2494
-
2495
-    /**
2496
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2497
-     * $items are expected in an array in the following format:
2498
-     * $legend_items = array(
2499
-     *        'item_id' => array(
2500
-     *            'icon' => 'http://url_to_icon_being_described.png',
2501
-     *            'desc' => __('localized description of item');
2502
-     *        )
2503
-     * );
2504
-     *
2505
-     * @param  array $items see above for format of array
2506
-     * @return string        html string of legend
2507
-     */
2508
-    protected function _display_legend($items)
2509
-    {
2510
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2511
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2512
-        return EEH_Template::display_template($legend_template, $this->_template_args, true);
2513
-    }
2514
-
2515
-
2516
-
2517
-    /**
2518
-     * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2519
-     *
2520
-     * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2521
-     *                             The returned json object is created from an array in the following format:
2522
-     *                             array(
2523
-     *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2524
-     *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2525
-     *                             'notices' => '', // - contains any EE_Error formatted notices
2526
-     *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2527
-     *                             'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2528
-     *                             specific template args that might be included in here)
2529
-     *                             )
2530
-     *                             The json object is populated by whatever is set in the $_template_args property.
2531
-     * @return void
2532
-     */
2533
-    protected function _return_json($sticky_notices = false)
2534
-    {
2535
-        //make sure any EE_Error notices have been handled.
2536
-        $this->_process_notices(array(), true, $sticky_notices);
2537
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2538
-        unset($this->_template_args['data']);
2539
-        $json = array(
2540
-                'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2541
-                'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2542
-                'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2543
-                'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2544
-                'notices'   => EE_Error::get_notices(),
2545
-                'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2546
-                'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2547
-                'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2548
-        );
2549
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2550
-        if (null === error_get_last() || ! headers_sent()) {
2551
-            header('Content-Type: application/json; charset=UTF-8');
2552
-        }
2553
-        echo wp_json_encode($json);
2554
-
2555
-        exit();
2556
-    }
2557
-
2558
-
2559
-
2560
-    /**
2561
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2562
-     *
2563
-     * @return void
2564
-     * @throws EE_Error
2565
-     */
2566
-    public function return_json()
2567
-    {
2568
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2569
-            $this->_return_json();
2570
-        } else {
2571
-            throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2572
-        }
2573
-    }
2574
-
2575
-
2576
-
2577
-    /**
2578
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2579
-     *
2580
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2581
-     * @access   public
2582
-     */
2583
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
2584
-    {
2585
-        $this->_hook_obj = $hook_obj;
2586
-    }
2587
-
2588
-
2589
-
2590
-    /**
2591
-     *        generates  HTML wrapper with Tabbed nav for an admin page
2592
-     *
2593
-     * @access public
2594
-     * @param  boolean $about whether to use the special about page wrapper or default.
2595
-     * @return void
2596
-     */
2597
-    public function admin_page_wrapper($about = false)
2598
-    {
2599
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2600
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
2601
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2602
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2603
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2604
-                isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2605
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2606
-                isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2607
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2608
-        // load settings page wrapper template
2609
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2610
-        //about page?
2611
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2612
-        if (defined('DOING_AJAX')) {
2613
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2614
-            $this->_return_json();
2615
-        } else {
2616
-            EEH_Template::display_template($template_path, $this->_template_args);
2617
-        }
2618
-    }
2619
-
2620
-
2621
-
2622
-    /**
2623
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2624
-     *
2625
-     * @return string html
2626
-     */
2627
-    protected function _get_main_nav_tabs()
2628
-    {
2629
-        //let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2630
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2631
-    }
2632
-
2633
-
2634
-
2635
-    /**
2636
-     *        sort nav tabs
2637
-     *
2638
-     * @access public
2639
-     * @param $a
2640
-     * @param $b
2641
-     * @return int
2642
-     */
2643
-    private function _sort_nav_tabs($a, $b)
2644
-    {
2645
-        if ($a['order'] == $b['order']) {
2646
-            return 0;
2647
-        }
2648
-        return ($a['order'] < $b['order']) ? -1 : 1;
2649
-    }
2650
-
2651
-
2652
-
2653
-    /**
2654
-     *    generates HTML for the forms used on admin pages
2655
-     *
2656
-     * @access protected
2657
-     * @param    array $input_vars - array of input field details
2658
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2659
-     * @return string
2660
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2661
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2662
-     */
2663
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2664
-    {
2665
-        $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2666
-        return $content;
2667
-    }
2668
-
2669
-
2670
-
2671
-    /**
2672
-     * generates the "Save" and "Save & Close" buttons for edit forms
2673
-     *
2674
-     * @access protected
2675
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2676
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2677
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2678
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2679
-     */
2680
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2681
-    {
2682
-        //make sure $text and $actions are in an array
2683
-        $text = (array)$text;
2684
-        $actions = (array)$actions;
2685
-        $referrer_url = empty($referrer) ? '' : $referrer;
2686
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2687
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2688
-        $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2689
-        $default_names = array('save', 'save_and_close');
2690
-        //add in a hidden index for the current page (so save and close redirects properly)
2691
-        $this->_template_args['save_buttons'] = $referrer_url;
2692
-        foreach ($button_text as $key => $button) {
2693
-            $ref = $default_names[$key];
2694
-            $id = $this->_current_view . '_' . $ref;
2695
-            $name = ! empty($actions) ? $actions[$key] : $ref;
2696
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2697
-            if ( ! $both) {
2698
-                break;
2699
-            }
2700
-        }
2701
-    }
2702
-
2703
-
2704
-
2705
-    /**
2706
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2707
-     *
2708
-     * @see   $this->_set_add_edit_form_tags() for details on params
2709
-     * @since 4.6.0
2710
-     * @param string $route
2711
-     * @param array  $additional_hidden_fields
2712
-     */
2713
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2714
-    {
2715
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2716
-    }
2717
-
2718
-
2719
-
2720
-    /**
2721
-     * set form open and close tags on add/edit pages.
2722
-     *
2723
-     * @access protected
2724
-     * @param string $route                    the route you want the form to direct to
2725
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2726
-     * @return void
2727
-     */
2728
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2729
-    {
2730
-        if (empty($route)) {
2731
-            $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2732
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2733
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2734
-        }
2735
-        // open form
2736
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2737
-        // add nonce
2738
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2739
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2740
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2741
-        // add REQUIRED form action
2742
-        $hidden_fields = array(
2743
-                'action' => array('type' => 'hidden', 'value' => $route),
2744
-        );
2745
-        // merge arrays
2746
-        $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2747
-        // generate form fields
2748
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2749
-        // add fields to form
2750
-        foreach ((array)$form_fields as $field_name => $form_field) {
2751
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2752
-        }
2753
-        // close form
2754
-        $this->_template_args['after_admin_page_content'] = '</form>';
2755
-    }
2756
-
2757
-
2758
-
2759
-    /**
2760
-     * Public Wrapper for _redirect_after_action() method since its
2761
-     * discovered it would be useful for external code to have access.
2762
-     *
2763
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
2764
-     * @since 4.5.0
2765
-     */
2766
-    public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2767
-    {
2768
-        $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2769
-    }
2770
-
2771
-
2772
-
2773
-    /**
2774
-     *    _redirect_after_action
2775
-     *
2776
-     * @param int    $success            - whether success was for two or more records, or just one, or none
2777
-     * @param string $what               - what the action was performed on
2778
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
2779
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2780
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2781
-     * @access protected
2782
-     * @return void
2783
-     */
2784
-    protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2785
-    {
2786
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2787
-        //class name for actions/filters.
2788
-        $classname = get_class($this);
2789
-        //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2790
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2791
-        $notices = EE_Error::get_notices(false);
2792
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
2793
-        if ( ! $override_overwrite || ! empty($notices['errors'])) {
2794
-            EE_Error::overwrite_success();
2795
-        }
2796
-        if ( ! empty($what) && ! empty($action_desc)) {
2797
-            // how many records affected ? more than one record ? or just one ?
2798
-            if ($success > 1 && empty($notices['errors'])) {
2799
-                // set plural msg
2800
-                EE_Error::add_success(
2801
-                        sprintf(
2802
-                                __('The "%s" have been successfully %s.', 'event_espresso'),
2803
-                                $what,
2804
-                                $action_desc
2805
-                        ),
2806
-                        __FILE__, __FUNCTION__, __LINE__
2807
-                );
2808
-            } else if ($success == 1 && empty($notices['errors'])) {
2809
-                // set singular msg
2810
-                EE_Error::add_success(
2811
-                        sprintf(
2812
-                                __('The "%s" has been successfully %s.', 'event_espresso'),
2813
-                                $what,
2814
-                                $action_desc
2815
-                        ),
2816
-                        __FILE__, __FUNCTION__, __LINE__
2817
-                );
2818
-            }
2819
-        }
2820
-        // check that $query_args isn't something crazy
2821
-        if ( ! is_array($query_args)) {
2822
-            $query_args = array();
2823
-        }
2824
-        /**
2825
-         * Allow injecting actions before the query_args are modified for possible different
2826
-         * redirections on save and close actions
2827
-         *
2828
-         * @since 4.2.0
2829
-         * @param array $query_args       The original query_args array coming into the
2830
-         *                                method.
2831
-         */
2832
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2833
-        //calculate where we're going (if we have a "save and close" button pushed)
2834
-        if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2835
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2836
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2837
-            // regenerate query args array from referrer URL
2838
-            parse_str($parsed_url['query'], $query_args);
2839
-            // correct page and action will be in the query args now
2840
-            $redirect_url = admin_url('admin.php');
2841
-        }
2842
-        //merge any default query_args set in _default_route_query_args property
2843
-        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2844
-            $args_to_merge = array();
2845
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
2846
-                //is there a wp_referer array in our _default_route_query_args property?
2847
-                if ($query_param == 'wp_referer') {
2848
-                    $query_value = (array)$query_value;
2849
-                    foreach ($query_value as $reference => $value) {
2850
-                        if (strpos($reference, 'nonce') !== false) {
2851
-                            continue;
2852
-                        }
2853
-                        //finally we will override any arguments in the referer with
2854
-                        //what might be set on the _default_route_query_args array.
2855
-                        if (isset($this->_default_route_query_args[$reference])) {
2856
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2857
-                        } else {
2858
-                            $args_to_merge[$reference] = urlencode($value);
2859
-                        }
2860
-                    }
2861
-                    continue;
2862
-                }
2863
-                $args_to_merge[$query_param] = $query_value;
2864
-            }
2865
-            //now let's merge these arguments but override with what was specifically sent in to the
2866
-            //redirect.
2867
-            $query_args = array_merge($args_to_merge, $query_args);
2868
-        }
2869
-        $this->_process_notices($query_args);
2870
-        // generate redirect url
2871
-        // if redirecting to anything other than the main page, add a nonce
2872
-        if (isset($query_args['action'])) {
2873
-            // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2874
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2875
-        }
2876
-        //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2877
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2878
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2879
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2880
-        if (defined('DOING_AJAX')) {
2881
-            $default_data = array(
2882
-                    'close'        => true,
2883
-                    'redirect_url' => $redirect_url,
2884
-                    'where'        => 'main',
2885
-                    'what'         => 'append',
2886
-            );
2887
-            $this->_template_args['success'] = $success;
2888
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2889
-            $this->_return_json();
2890
-        }
2891
-        wp_safe_redirect($redirect_url);
2892
-        exit();
2893
-    }
2894
-
2895
-
2896
-
2897
-    /**
2898
-     * process any notices before redirecting (or returning ajax request)
2899
-     * This method sets the $this->_template_args['notices'] attribute;
2900
-     *
2901
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
2902
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2903
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2904
-     * @return void
2905
-     */
2906
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2907
-    {
2908
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
2909
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2910
-            $notices = EE_Error::get_notices(false);
2911
-            if (empty($this->_template_args['success'])) {
2912
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2913
-            }
2914
-            if (empty($this->_template_args['errors'])) {
2915
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2916
-            }
2917
-            if (empty($this->_template_args['attention'])) {
2918
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2919
-            }
2920
-        }
2921
-        $this->_template_args['notices'] = EE_Error::get_notices();
2922
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2923
-        if ( ! defined('DOING_AJAX') || $sticky_notices) {
2924
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
2925
-            $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2926
-        }
2927
-    }
2928
-
2929
-
2930
-
2931
-    /**
2932
-     * get_action_link_or_button
2933
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
2934
-     *
2935
-     * @param string $action        use this to indicate which action the url is generated with.
2936
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2937
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2938
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2939
-     * @param string $base_url      If this is not provided
2940
-     *                              the _admin_base_url will be used as the default for the button base_url.
2941
-     *                              Otherwise this value will be used.
2942
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2943
-     * @return string
2944
-     * @throws \EE_Error
2945
-     */
2946
-    public function get_action_link_or_button(
2947
-            $action,
2948
-            $type = 'add',
2949
-            $extra_request = array(),
2950
-            $class = 'button-primary',
2951
-            $base_url = '',
2952
-            $exclude_nonce = false
2953
-    ) {
2954
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2955
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2956
-            throw new EE_Error(
2957
-                    sprintf(
2958
-                            __(
2959
-                                    'There is no page route for given action for the button.  This action was given: %s',
2960
-                                    'event_espresso'
2961
-                            ),
2962
-                            $action
2963
-                    )
2964
-            );
2965
-        }
2966
-        if ( ! isset($this->_labels['buttons'][$type])) {
2967
-            throw new EE_Error(
2968
-                    sprintf(
2969
-                            __(
2970
-                                    'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2971
-                                    'event_espresso'
2972
-                            ),
2973
-                            $type
2974
-                    )
2975
-            );
2976
-        }
2977
-        //finally check user access for this button.
2978
-        $has_access = $this->check_user_access($action, true);
2979
-        if ( ! $has_access) {
2980
-            return '';
2981
-        }
2982
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2983
-        $query_args = array(
2984
-                'action' => $action,
2985
-        );
2986
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2987
-        if ( ! empty($extra_request)) {
2988
-            $query_args = array_merge($extra_request, $query_args);
2989
-        }
2990
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2991
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2992
-    }
2993
-
2994
-
2995
-
2996
-    /**
2997
-     * _per_page_screen_option
2998
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
2999
-     *
3000
-     * @return void
3001
-     */
3002
-    protected function _per_page_screen_option()
3003
-    {
3004
-        $option = 'per_page';
3005
-        $args = array(
3006
-                'label'   => $this->_admin_page_title,
3007
-                'default' => 10,
3008
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3009
-        );
3010
-        //ONLY add the screen option if the user has access to it.
3011
-        if ($this->check_user_access($this->_current_view, true)) {
3012
-            add_screen_option($option, $args);
3013
-        }
3014
-    }
3015
-
3016
-
3017
-
3018
-    /**
3019
-     * set_per_page_screen_option
3020
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3021
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3022
-     *
3023
-     * @access private
3024
-     * @return void
3025
-     */
3026
-    private function _set_per_page_screen_options()
3027
-    {
3028
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3029
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3030
-            if ( ! $user = wp_get_current_user()) {
3031
-                return;
3032
-            }
3033
-            $option = $_POST['wp_screen_options']['option'];
3034
-            $value = $_POST['wp_screen_options']['value'];
3035
-            if ($option != sanitize_key($option)) {
3036
-                return;
3037
-            }
3038
-            $map_option = $option;
3039
-            $option = str_replace('-', '_', $option);
3040
-            switch ($map_option) {
3041
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3042
-                    $value = (int)$value;
3043
-                    if ($value < 1 || $value > 999) {
3044
-                        return;
3045
-                    }
3046
-                    break;
3047
-                default:
3048
-                    $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3049
-                    if (false === $value) {
3050
-                        return;
3051
-                    }
3052
-                    break;
3053
-            }
3054
-            update_user_meta($user->ID, $option, $value);
3055
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3056
-            exit;
3057
-        }
3058
-    }
3059
-
3060
-
3061
-
3062
-    /**
3063
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3064
-     *
3065
-     * @param array $data array that will be assigned to template args.
3066
-     */
3067
-    public function set_template_args($data)
3068
-    {
3069
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3070
-    }
3071
-
3072
-
3073
-
3074
-    /**
3075
-     * This makes available the WP transient system for temporarily moving data between routes
3076
-     *
3077
-     * @access protected
3078
-     * @param string $route             the route that should receive the transient
3079
-     * @param array  $data              the data that gets sent
3080
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3081
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3082
-     * @return void
3083
-     */
3084
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3085
-    {
3086
-        $user_id = get_current_user_id();
3087
-        if ( ! $skip_route_verify) {
3088
-            $this->_verify_route($route);
3089
-        }
3090
-        //now let's set the string for what kind of transient we're setting
3091
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3092
-        $data = $notices ? array('notices' => $data) : $data;
3093
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3094
-        $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3095
-        if ($existing) {
3096
-            $data = array_merge((array)$data, (array)$existing);
3097
-        }
3098
-        if (is_multisite() && is_network_admin()) {
3099
-            set_site_transient($transient, $data, 8);
3100
-        } else {
3101
-            set_transient($transient, $data, 8);
3102
-        }
3103
-    }
3104
-
3105
-
3106
-
3107
-    /**
3108
-     * this retrieves the temporary transient that has been set for moving data between routes.
3109
-     *
3110
-     * @param bool $notices true we get notices transient. False we just return normal route transient
3111
-     * @return mixed data
3112
-     */
3113
-    protected function _get_transient($notices = false, $route = false)
3114
-    {
3115
-        $user_id = get_current_user_id();
3116
-        $route = ! $route ? $this->_req_action : $route;
3117
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3118
-        $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3119
-        //delete transient after retrieval (just in case it hasn't expired);
3120
-        if (is_multisite() && is_network_admin()) {
3121
-            delete_site_transient($transient);
3122
-        } else {
3123
-            delete_transient($transient);
3124
-        }
3125
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3126
-    }
3127
-
3128
-
3129
-
3130
-    /**
3131
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3132
-     * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3133
-     *
3134
-     * @return void
3135
-     */
3136
-    protected function _transient_garbage_collection()
3137
-    {
3138
-        global $wpdb;
3139
-        //retrieve all existing transients
3140
-        $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3141
-        if ($results = $wpdb->get_results($query)) {
3142
-            foreach ($results as $result) {
3143
-                $transient = str_replace('_transient_', '', $result->option_name);
3144
-                get_transient($transient);
3145
-                if (is_multisite() && is_network_admin()) {
3146
-                    get_site_transient($transient);
3147
-                }
3148
-            }
3149
-        }
3150
-    }
3151
-
3152
-
3153
-
3154
-    /**
3155
-     * get_view
3156
-     *
3157
-     * @access public
3158
-     * @return string content of _view property
3159
-     */
3160
-    public function get_view()
3161
-    {
3162
-        return $this->_view;
3163
-    }
3164
-
3165
-
3166
-
3167
-    /**
3168
-     * getter for the protected $_views property
3169
-     *
3170
-     * @return array
3171
-     */
3172
-    public function get_views()
3173
-    {
3174
-        return $this->_views;
3175
-    }
3176
-
3177
-
3178
-
3179
-    /**
3180
-     * get_current_page
3181
-     *
3182
-     * @access public
3183
-     * @return string _current_page property value
3184
-     */
3185
-    public function get_current_page()
3186
-    {
3187
-        return $this->_current_page;
3188
-    }
3189
-
3190
-
3191
-
3192
-    /**
3193
-     * get_current_view
3194
-     *
3195
-     * @access public
3196
-     * @return string _current_view property value
3197
-     */
3198
-    public function get_current_view()
3199
-    {
3200
-        return $this->_current_view;
3201
-    }
3202
-
3203
-
3204
-
3205
-    /**
3206
-     * get_current_screen
3207
-     *
3208
-     * @access public
3209
-     * @return object The current WP_Screen object
3210
-     */
3211
-    public function get_current_screen()
3212
-    {
3213
-        return $this->_current_screen;
3214
-    }
3215
-
3216
-
3217
-
3218
-    /**
3219
-     * get_current_page_view_url
3220
-     *
3221
-     * @access public
3222
-     * @return string This returns the url for the current_page_view.
3223
-     */
3224
-    public function get_current_page_view_url()
3225
-    {
3226
-        return $this->_current_page_view_url;
3227
-    }
3228
-
3229
-
3230
-
3231
-    /**
3232
-     * just returns the _req_data property
3233
-     *
3234
-     * @return array
3235
-     */
3236
-    public function get_request_data()
3237
-    {
3238
-        return $this->_req_data;
3239
-    }
3240
-
3241
-
3242
-
3243
-    /**
3244
-     * returns the _req_data protected property
3245
-     *
3246
-     * @return string
3247
-     */
3248
-    public function get_req_action()
3249
-    {
3250
-        return $this->_req_action;
3251
-    }
3252
-
3253
-
3254
-
3255
-    /**
3256
-     * @return bool  value of $_is_caf property
3257
-     */
3258
-    public function is_caf()
3259
-    {
3260
-        return $this->_is_caf;
3261
-    }
3262
-
3263
-
3264
-
3265
-    /**
3266
-     * @return mixed
3267
-     */
3268
-    public function default_espresso_metaboxes()
3269
-    {
3270
-        return $this->_default_espresso_metaboxes;
3271
-    }
3272
-
3273
-
3274
-
3275
-    /**
3276
-     * @return mixed
3277
-     */
3278
-    public function admin_base_url()
3279
-    {
3280
-        return $this->_admin_base_url;
3281
-    }
3282
-
3283
-
3284
-
3285
-    /**
3286
-     * @return mixed
3287
-     */
3288
-    public function wp_page_slug()
3289
-    {
3290
-        return $this->_wp_page_slug;
3291
-    }
3292
-
3293
-
3294
-
3295
-    /**
3296
-     * updates  espresso configuration settings
3297
-     *
3298
-     * @access    protected
3299
-     * @param string                   $tab
3300
-     * @param EE_Config_Base|EE_Config $config
3301
-     * @param string                   $file file where error occurred
3302
-     * @param string                   $func function  where error occurred
3303
-     * @param string                   $line line no where error occurred
3304
-     * @return boolean
3305
-     */
3306
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3307
-    {
3308
-        //remove any options that are NOT going to be saved with the config settings.
3309
-        if (isset($config->core->ee_ueip_optin)) {
3310
-            $config->core->ee_ueip_has_notified = true;
3311
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3312
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3313
-            update_option('ee_ueip_has_notified', true);
3314
-        }
3315
-        // and save it (note we're also doing the network save here)
3316
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3317
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3318
-        if ($config_saved && $net_saved) {
3319
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3320
-            return true;
3321
-        } else {
3322
-            EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3323
-            return false;
3324
-        }
3325
-    }
3326
-
3327
-
3328
-
3329
-    /**
3330
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3331
-     *
3332
-     * @return array
3333
-     */
3334
-    public function get_yes_no_values()
3335
-    {
3336
-        return $this->_yes_no_values;
3337
-    }
3338
-
3339
-
3340
-
3341
-    protected function _get_dir()
3342
-    {
3343
-        $reflector = new ReflectionClass(get_class($this));
3344
-        return dirname($reflector->getFileName());
3345
-    }
3346
-
3347
-
3348
-
3349
-    /**
3350
-     * A helper for getting a "next link".
3351
-     *
3352
-     * @param string $url   The url to link to
3353
-     * @param string $class The class to use.
3354
-     * @return string
3355
-     */
3356
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3357
-    {
3358
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3359
-    }
3360
-
3361
-
3362
-
3363
-    /**
3364
-     * A helper for getting a "previous link".
3365
-     *
3366
-     * @param string $url   The url to link to
3367
-     * @param string $class The class to use.
3368
-     * @return string
3369
-     */
3370
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3371
-    {
3372
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3373
-    }
3374
-
3375
-
3376
-
3377
-
3378
-
3379
-
3380
-
3381
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3382
-    /**
3383
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3384
-     * array.
3385
-     *
3386
-     * @return bool success/fail
3387
-     */
3388
-    protected function _process_resend_registration()
3389
-    {
3390
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3391
-        do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3392
-        return $this->_template_args['success'];
3393
-    }
3394
-
3395
-
3396
-
3397
-    /**
3398
-     * This automatically processes any payment message notifications when manual payment has been applied.
3399
-     *
3400
-     * @access protected
3401
-     * @param \EE_Payment $payment
3402
-     * @return bool success/fail
3403
-     */
3404
-    protected function _process_payment_notification(EE_Payment $payment)
3405
-    {
3406
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3407
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3408
-        $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3409
-        return $this->_template_args['success'];
3410
-    }
2196
+	}
2197
+
2198
+
2199
+
2200
+	/**
2201
+	 * facade for add_meta_box
2202
+	 *
2203
+	 * @param string  $action        where the metabox get's displayed
2204
+	 * @param string  $title         Title of Metabox (output in metabox header)
2205
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2206
+	 * @param array   $callback_args an array of args supplied for the metabox
2207
+	 * @param string  $column        what metabox column
2208
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2209
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2210
+	 */
2211
+	public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2212
+	{
2213
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2214
+		//if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2215
+		if (empty($callback_args) && $create_func) {
2216
+			$callback_args = array(
2217
+					'template_path' => $this->_template_path,
2218
+					'template_args' => $this->_template_args,
2219
+			);
2220
+		}
2221
+		//if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2222
+		$call_back_func = $create_func ? create_function('$post, $metabox',
2223
+				'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2224
+		add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2225
+	}
2226
+
2227
+
2228
+
2229
+	/**
2230
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2231
+	 *
2232
+	 * @return [type] [description]
2233
+	 */
2234
+	public function display_admin_page_with_metabox_columns()
2235
+	{
2236
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2237
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2238
+		//the final wrapper
2239
+		$this->admin_page_wrapper();
2240
+	}
2241
+
2242
+
2243
+
2244
+	/**
2245
+	 *        generates  HTML wrapper for an admin details page
2246
+	 *
2247
+	 * @access public
2248
+	 * @return void
2249
+	 */
2250
+	public function display_admin_page_with_sidebar()
2251
+	{
2252
+		$this->_display_admin_page(true);
2253
+	}
2254
+
2255
+
2256
+
2257
+	/**
2258
+	 *        generates  HTML wrapper for an admin details page (except no sidebar)
2259
+	 *
2260
+	 * @access public
2261
+	 * @return void
2262
+	 */
2263
+	public function display_admin_page_with_no_sidebar()
2264
+	{
2265
+		$this->_display_admin_page();
2266
+	}
2267
+
2268
+
2269
+
2270
+	/**
2271
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2272
+	 *
2273
+	 * @access public
2274
+	 * @return void
2275
+	 */
2276
+	public function display_about_admin_page()
2277
+	{
2278
+		$this->_display_admin_page(false, true);
2279
+	}
2280
+
2281
+
2282
+
2283
+	/**
2284
+	 * display_admin_page
2285
+	 * contains the code for actually displaying an admin page
2286
+	 *
2287
+	 * @access private
2288
+	 * @param  boolean $sidebar true with sidebar, false without
2289
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2290
+	 * @return void
2291
+	 */
2292
+	private function _display_admin_page($sidebar = false, $about = false)
2293
+	{
2294
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2295
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2296
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2297
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2298
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2299
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2300
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2301
+				? 'poststuff'
2302
+				: 'espresso-default-admin';
2303
+		$template_path = $sidebar
2304
+				? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2305
+				: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2306
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2307
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2308
+		}
2309
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2310
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2311
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2312
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2313
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2314
+		// the final template wrapper
2315
+		$this->admin_page_wrapper($about);
2316
+	}
2317
+
2318
+
2319
+
2320
+	/**
2321
+	 * This is used to display caf preview pages.
2322
+	 *
2323
+	 * @since 4.3.2
2324
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2325
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2326
+	 * @return void
2327
+	 * @throws \EE_Error
2328
+	 */
2329
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2330
+	{
2331
+		//let's generate a default preview action button if there isn't one already present.
2332
+		$this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2333
+		$buy_now_url = add_query_arg(
2334
+				array(
2335
+						'ee_ver'       => 'ee4',
2336
+						'utm_source'   => 'ee4_plugin_admin',
2337
+						'utm_medium'   => 'link',
2338
+						'utm_campaign' => $utm_campaign_source,
2339
+						'utm_content'  => 'buy_now_button',
2340
+				),
2341
+				'http://eventespresso.com/pricing/'
2342
+		);
2343
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2344
+				? $this->get_action_link_or_button(
2345
+						'',
2346
+						'buy_now',
2347
+						array(),
2348
+						'button-primary button-large',
2349
+						$buy_now_url,
2350
+						true
2351
+				)
2352
+				: $this->_template_args['preview_action_button'];
2353
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2354
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2355
+				$template_path,
2356
+				$this->_template_args,
2357
+				true
2358
+		);
2359
+		$this->_display_admin_page($display_sidebar);
2360
+	}
2361
+
2362
+
2363
+
2364
+	/**
2365
+	 * display_admin_list_table_page_with_sidebar
2366
+	 * generates HTML wrapper for an admin_page with list_table
2367
+	 *
2368
+	 * @access public
2369
+	 * @return void
2370
+	 */
2371
+	public function display_admin_list_table_page_with_sidebar()
2372
+	{
2373
+		$this->_display_admin_list_table_page(true);
2374
+	}
2375
+
2376
+
2377
+
2378
+	/**
2379
+	 * display_admin_list_table_page_with_no_sidebar
2380
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2381
+	 *
2382
+	 * @access public
2383
+	 * @return void
2384
+	 */
2385
+	public function display_admin_list_table_page_with_no_sidebar()
2386
+	{
2387
+		$this->_display_admin_list_table_page();
2388
+	}
2389
+
2390
+
2391
+
2392
+	/**
2393
+	 * generates html wrapper for an admin_list_table page
2394
+	 *
2395
+	 * @access private
2396
+	 * @param boolean $sidebar whether to display with sidebar or not.
2397
+	 * @return void
2398
+	 */
2399
+	private function _display_admin_list_table_page($sidebar = false)
2400
+	{
2401
+		//setup search attributes
2402
+		$this->_set_search_attributes();
2403
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2404
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2405
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2406
+				? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2407
+				: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2408
+		$this->_template_args['list_table'] = $this->_list_table_object;
2409
+		$this->_template_args['current_route'] = $this->_req_action;
2410
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2411
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2412
+		if ( ! empty($ajax_sorting_callback)) {
2413
+			$sortable_list_table_form_fields = wp_nonce_field(
2414
+					$ajax_sorting_callback . '_nonce',
2415
+					$ajax_sorting_callback . '_nonce',
2416
+					false,
2417
+					false
2418
+			);
2419
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2420
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2421
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2422
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2423
+		} else {
2424
+			$sortable_list_table_form_fields = '';
2425
+		}
2426
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2427
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2428
+		$nonce_ref = $this->_req_action . '_nonce';
2429
+		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2430
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2431
+		//display message about search results?
2432
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2433
+				? '<p class="ee-search-results">' . sprintf(
2434
+						esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2435
+						trim($this->_req_data['s'], '%')
2436
+				) . '</p>'
2437
+				: '';
2438
+		// filter before_list_table template arg
2439
+		$this->_template_args['before_list_table'] = apply_filters(
2440
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2441
+			$this->_template_args['before_list_table'],
2442
+			$this->page_slug,
2443
+			$this->_req_data,
2444
+			$this->_req_action
2445
+		);
2446
+		// convert to array and filter again
2447
+		// arrays are easier to inject new items in a specific location,
2448
+		// but would not be backwards compatible, so we have to add a new filter
2449
+		$this->_template_args['before_list_table'] = implode(
2450
+			" \n",
2451
+			(array) apply_filters(
2452
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2453
+				(array) $this->_template_args['before_list_table'],
2454
+				$this->page_slug,
2455
+				$this->_req_data,
2456
+				$this->_req_action
2457
+			)
2458
+		);
2459
+		// filter after_list_table template arg
2460
+		$this->_template_args['after_list_table'] = apply_filters(
2461
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2462
+			$this->_template_args['after_list_table'],
2463
+			$this->page_slug,
2464
+			$this->_req_data,
2465
+			$this->_req_action
2466
+		);
2467
+		// convert to array and filter again
2468
+		// arrays are easier to inject new items in a specific location,
2469
+		// but would not be backwards compatible, so we have to add a new filter
2470
+		$this->_template_args['after_list_table'] = implode(
2471
+			" \n",
2472
+			(array) apply_filters(
2473
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2474
+				(array) $this->_template_args['after_list_table'],
2475
+				$this->page_slug,
2476
+				$this->_req_data,
2477
+				$this->_req_action
2478
+			)
2479
+		);
2480
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2481
+				$template_path,
2482
+				$this->_template_args,
2483
+				true
2484
+		);
2485
+		// the final template wrapper
2486
+		if ($sidebar) {
2487
+			$this->display_admin_page_with_sidebar();
2488
+		} else {
2489
+			$this->display_admin_page_with_no_sidebar();
2490
+		}
2491
+	}
2492
+
2493
+
2494
+
2495
+	/**
2496
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2497
+	 * $items are expected in an array in the following format:
2498
+	 * $legend_items = array(
2499
+	 *        'item_id' => array(
2500
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2501
+	 *            'desc' => __('localized description of item');
2502
+	 *        )
2503
+	 * );
2504
+	 *
2505
+	 * @param  array $items see above for format of array
2506
+	 * @return string        html string of legend
2507
+	 */
2508
+	protected function _display_legend($items)
2509
+	{
2510
+		$this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2511
+		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2512
+		return EEH_Template::display_template($legend_template, $this->_template_args, true);
2513
+	}
2514
+
2515
+
2516
+
2517
+	/**
2518
+	 * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2519
+	 *
2520
+	 * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2521
+	 *                             The returned json object is created from an array in the following format:
2522
+	 *                             array(
2523
+	 *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2524
+	 *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2525
+	 *                             'notices' => '', // - contains any EE_Error formatted notices
2526
+	 *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2527
+	 *                             'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2528
+	 *                             specific template args that might be included in here)
2529
+	 *                             )
2530
+	 *                             The json object is populated by whatever is set in the $_template_args property.
2531
+	 * @return void
2532
+	 */
2533
+	protected function _return_json($sticky_notices = false)
2534
+	{
2535
+		//make sure any EE_Error notices have been handled.
2536
+		$this->_process_notices(array(), true, $sticky_notices);
2537
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2538
+		unset($this->_template_args['data']);
2539
+		$json = array(
2540
+				'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2541
+				'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2542
+				'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2543
+				'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2544
+				'notices'   => EE_Error::get_notices(),
2545
+				'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2546
+				'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2547
+				'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2548
+		);
2549
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2550
+		if (null === error_get_last() || ! headers_sent()) {
2551
+			header('Content-Type: application/json; charset=UTF-8');
2552
+		}
2553
+		echo wp_json_encode($json);
2554
+
2555
+		exit();
2556
+	}
2557
+
2558
+
2559
+
2560
+	/**
2561
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2562
+	 *
2563
+	 * @return void
2564
+	 * @throws EE_Error
2565
+	 */
2566
+	public function return_json()
2567
+	{
2568
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2569
+			$this->_return_json();
2570
+		} else {
2571
+			throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2572
+		}
2573
+	}
2574
+
2575
+
2576
+
2577
+	/**
2578
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2579
+	 *
2580
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2581
+	 * @access   public
2582
+	 */
2583
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
2584
+	{
2585
+		$this->_hook_obj = $hook_obj;
2586
+	}
2587
+
2588
+
2589
+
2590
+	/**
2591
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
2592
+	 *
2593
+	 * @access public
2594
+	 * @param  boolean $about whether to use the special about page wrapper or default.
2595
+	 * @return void
2596
+	 */
2597
+	public function admin_page_wrapper($about = false)
2598
+	{
2599
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2600
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
2601
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2602
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2603
+		$this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2604
+				isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2605
+		$this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2606
+				isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2607
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2608
+		// load settings page wrapper template
2609
+		$template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2610
+		//about page?
2611
+		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2612
+		if (defined('DOING_AJAX')) {
2613
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2614
+			$this->_return_json();
2615
+		} else {
2616
+			EEH_Template::display_template($template_path, $this->_template_args);
2617
+		}
2618
+	}
2619
+
2620
+
2621
+
2622
+	/**
2623
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2624
+	 *
2625
+	 * @return string html
2626
+	 */
2627
+	protected function _get_main_nav_tabs()
2628
+	{
2629
+		//let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2630
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2631
+	}
2632
+
2633
+
2634
+
2635
+	/**
2636
+	 *        sort nav tabs
2637
+	 *
2638
+	 * @access public
2639
+	 * @param $a
2640
+	 * @param $b
2641
+	 * @return int
2642
+	 */
2643
+	private function _sort_nav_tabs($a, $b)
2644
+	{
2645
+		if ($a['order'] == $b['order']) {
2646
+			return 0;
2647
+		}
2648
+		return ($a['order'] < $b['order']) ? -1 : 1;
2649
+	}
2650
+
2651
+
2652
+
2653
+	/**
2654
+	 *    generates HTML for the forms used on admin pages
2655
+	 *
2656
+	 * @access protected
2657
+	 * @param    array $input_vars - array of input field details
2658
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2659
+	 * @return string
2660
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2661
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2662
+	 */
2663
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2664
+	{
2665
+		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2666
+		return $content;
2667
+	}
2668
+
2669
+
2670
+
2671
+	/**
2672
+	 * generates the "Save" and "Save & Close" buttons for edit forms
2673
+	 *
2674
+	 * @access protected
2675
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2676
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2677
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2678
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2679
+	 */
2680
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2681
+	{
2682
+		//make sure $text and $actions are in an array
2683
+		$text = (array)$text;
2684
+		$actions = (array)$actions;
2685
+		$referrer_url = empty($referrer) ? '' : $referrer;
2686
+		$referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2687
+				: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2688
+		$button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2689
+		$default_names = array('save', 'save_and_close');
2690
+		//add in a hidden index for the current page (so save and close redirects properly)
2691
+		$this->_template_args['save_buttons'] = $referrer_url;
2692
+		foreach ($button_text as $key => $button) {
2693
+			$ref = $default_names[$key];
2694
+			$id = $this->_current_view . '_' . $ref;
2695
+			$name = ! empty($actions) ? $actions[$key] : $ref;
2696
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2697
+			if ( ! $both) {
2698
+				break;
2699
+			}
2700
+		}
2701
+	}
2702
+
2703
+
2704
+
2705
+	/**
2706
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2707
+	 *
2708
+	 * @see   $this->_set_add_edit_form_tags() for details on params
2709
+	 * @since 4.6.0
2710
+	 * @param string $route
2711
+	 * @param array  $additional_hidden_fields
2712
+	 */
2713
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2714
+	{
2715
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2716
+	}
2717
+
2718
+
2719
+
2720
+	/**
2721
+	 * set form open and close tags on add/edit pages.
2722
+	 *
2723
+	 * @access protected
2724
+	 * @param string $route                    the route you want the form to direct to
2725
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2726
+	 * @return void
2727
+	 */
2728
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2729
+	{
2730
+		if (empty($route)) {
2731
+			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2732
+			$dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2733
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2734
+		}
2735
+		// open form
2736
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2737
+		// add nonce
2738
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2739
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2740
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2741
+		// add REQUIRED form action
2742
+		$hidden_fields = array(
2743
+				'action' => array('type' => 'hidden', 'value' => $route),
2744
+		);
2745
+		// merge arrays
2746
+		$hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2747
+		// generate form fields
2748
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2749
+		// add fields to form
2750
+		foreach ((array)$form_fields as $field_name => $form_field) {
2751
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2752
+		}
2753
+		// close form
2754
+		$this->_template_args['after_admin_page_content'] = '</form>';
2755
+	}
2756
+
2757
+
2758
+
2759
+	/**
2760
+	 * Public Wrapper for _redirect_after_action() method since its
2761
+	 * discovered it would be useful for external code to have access.
2762
+	 *
2763
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
2764
+	 * @since 4.5.0
2765
+	 */
2766
+	public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2767
+	{
2768
+		$this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2769
+	}
2770
+
2771
+
2772
+
2773
+	/**
2774
+	 *    _redirect_after_action
2775
+	 *
2776
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
2777
+	 * @param string $what               - what the action was performed on
2778
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
2779
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2780
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2781
+	 * @access protected
2782
+	 * @return void
2783
+	 */
2784
+	protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2785
+	{
2786
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2787
+		//class name for actions/filters.
2788
+		$classname = get_class($this);
2789
+		//set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2790
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2791
+		$notices = EE_Error::get_notices(false);
2792
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
2793
+		if ( ! $override_overwrite || ! empty($notices['errors'])) {
2794
+			EE_Error::overwrite_success();
2795
+		}
2796
+		if ( ! empty($what) && ! empty($action_desc)) {
2797
+			// how many records affected ? more than one record ? or just one ?
2798
+			if ($success > 1 && empty($notices['errors'])) {
2799
+				// set plural msg
2800
+				EE_Error::add_success(
2801
+						sprintf(
2802
+								__('The "%s" have been successfully %s.', 'event_espresso'),
2803
+								$what,
2804
+								$action_desc
2805
+						),
2806
+						__FILE__, __FUNCTION__, __LINE__
2807
+				);
2808
+			} else if ($success == 1 && empty($notices['errors'])) {
2809
+				// set singular msg
2810
+				EE_Error::add_success(
2811
+						sprintf(
2812
+								__('The "%s" has been successfully %s.', 'event_espresso'),
2813
+								$what,
2814
+								$action_desc
2815
+						),
2816
+						__FILE__, __FUNCTION__, __LINE__
2817
+				);
2818
+			}
2819
+		}
2820
+		// check that $query_args isn't something crazy
2821
+		if ( ! is_array($query_args)) {
2822
+			$query_args = array();
2823
+		}
2824
+		/**
2825
+		 * Allow injecting actions before the query_args are modified for possible different
2826
+		 * redirections on save and close actions
2827
+		 *
2828
+		 * @since 4.2.0
2829
+		 * @param array $query_args       The original query_args array coming into the
2830
+		 *                                method.
2831
+		 */
2832
+		do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2833
+		//calculate where we're going (if we have a "save and close" button pushed)
2834
+		if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2835
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2836
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2837
+			// regenerate query args array from referrer URL
2838
+			parse_str($parsed_url['query'], $query_args);
2839
+			// correct page and action will be in the query args now
2840
+			$redirect_url = admin_url('admin.php');
2841
+		}
2842
+		//merge any default query_args set in _default_route_query_args property
2843
+		if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2844
+			$args_to_merge = array();
2845
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
2846
+				//is there a wp_referer array in our _default_route_query_args property?
2847
+				if ($query_param == 'wp_referer') {
2848
+					$query_value = (array)$query_value;
2849
+					foreach ($query_value as $reference => $value) {
2850
+						if (strpos($reference, 'nonce') !== false) {
2851
+							continue;
2852
+						}
2853
+						//finally we will override any arguments in the referer with
2854
+						//what might be set on the _default_route_query_args array.
2855
+						if (isset($this->_default_route_query_args[$reference])) {
2856
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2857
+						} else {
2858
+							$args_to_merge[$reference] = urlencode($value);
2859
+						}
2860
+					}
2861
+					continue;
2862
+				}
2863
+				$args_to_merge[$query_param] = $query_value;
2864
+			}
2865
+			//now let's merge these arguments but override with what was specifically sent in to the
2866
+			//redirect.
2867
+			$query_args = array_merge($args_to_merge, $query_args);
2868
+		}
2869
+		$this->_process_notices($query_args);
2870
+		// generate redirect url
2871
+		// if redirecting to anything other than the main page, add a nonce
2872
+		if (isset($query_args['action'])) {
2873
+			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2874
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2875
+		}
2876
+		//we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2877
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2878
+		$redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2879
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2880
+		if (defined('DOING_AJAX')) {
2881
+			$default_data = array(
2882
+					'close'        => true,
2883
+					'redirect_url' => $redirect_url,
2884
+					'where'        => 'main',
2885
+					'what'         => 'append',
2886
+			);
2887
+			$this->_template_args['success'] = $success;
2888
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2889
+			$this->_return_json();
2890
+		}
2891
+		wp_safe_redirect($redirect_url);
2892
+		exit();
2893
+	}
2894
+
2895
+
2896
+
2897
+	/**
2898
+	 * process any notices before redirecting (or returning ajax request)
2899
+	 * This method sets the $this->_template_args['notices'] attribute;
2900
+	 *
2901
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
2902
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2903
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2904
+	 * @return void
2905
+	 */
2906
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2907
+	{
2908
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2909
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2910
+			$notices = EE_Error::get_notices(false);
2911
+			if (empty($this->_template_args['success'])) {
2912
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2913
+			}
2914
+			if (empty($this->_template_args['errors'])) {
2915
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2916
+			}
2917
+			if (empty($this->_template_args['attention'])) {
2918
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2919
+			}
2920
+		}
2921
+		$this->_template_args['notices'] = EE_Error::get_notices();
2922
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2923
+		if ( ! defined('DOING_AJAX') || $sticky_notices) {
2924
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
2925
+			$this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2926
+		}
2927
+	}
2928
+
2929
+
2930
+
2931
+	/**
2932
+	 * get_action_link_or_button
2933
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2934
+	 *
2935
+	 * @param string $action        use this to indicate which action the url is generated with.
2936
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2937
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2938
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2939
+	 * @param string $base_url      If this is not provided
2940
+	 *                              the _admin_base_url will be used as the default for the button base_url.
2941
+	 *                              Otherwise this value will be used.
2942
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2943
+	 * @return string
2944
+	 * @throws \EE_Error
2945
+	 */
2946
+	public function get_action_link_or_button(
2947
+			$action,
2948
+			$type = 'add',
2949
+			$extra_request = array(),
2950
+			$class = 'button-primary',
2951
+			$base_url = '',
2952
+			$exclude_nonce = false
2953
+	) {
2954
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2955
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2956
+			throw new EE_Error(
2957
+					sprintf(
2958
+							__(
2959
+									'There is no page route for given action for the button.  This action was given: %s',
2960
+									'event_espresso'
2961
+							),
2962
+							$action
2963
+					)
2964
+			);
2965
+		}
2966
+		if ( ! isset($this->_labels['buttons'][$type])) {
2967
+			throw new EE_Error(
2968
+					sprintf(
2969
+							__(
2970
+									'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2971
+									'event_espresso'
2972
+							),
2973
+							$type
2974
+					)
2975
+			);
2976
+		}
2977
+		//finally check user access for this button.
2978
+		$has_access = $this->check_user_access($action, true);
2979
+		if ( ! $has_access) {
2980
+			return '';
2981
+		}
2982
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2983
+		$query_args = array(
2984
+				'action' => $action,
2985
+		);
2986
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2987
+		if ( ! empty($extra_request)) {
2988
+			$query_args = array_merge($extra_request, $query_args);
2989
+		}
2990
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2991
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2992
+	}
2993
+
2994
+
2995
+
2996
+	/**
2997
+	 * _per_page_screen_option
2998
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
2999
+	 *
3000
+	 * @return void
3001
+	 */
3002
+	protected function _per_page_screen_option()
3003
+	{
3004
+		$option = 'per_page';
3005
+		$args = array(
3006
+				'label'   => $this->_admin_page_title,
3007
+				'default' => 10,
3008
+				'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3009
+		);
3010
+		//ONLY add the screen option if the user has access to it.
3011
+		if ($this->check_user_access($this->_current_view, true)) {
3012
+			add_screen_option($option, $args);
3013
+		}
3014
+	}
3015
+
3016
+
3017
+
3018
+	/**
3019
+	 * set_per_page_screen_option
3020
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3021
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3022
+	 *
3023
+	 * @access private
3024
+	 * @return void
3025
+	 */
3026
+	private function _set_per_page_screen_options()
3027
+	{
3028
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3029
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3030
+			if ( ! $user = wp_get_current_user()) {
3031
+				return;
3032
+			}
3033
+			$option = $_POST['wp_screen_options']['option'];
3034
+			$value = $_POST['wp_screen_options']['value'];
3035
+			if ($option != sanitize_key($option)) {
3036
+				return;
3037
+			}
3038
+			$map_option = $option;
3039
+			$option = str_replace('-', '_', $option);
3040
+			switch ($map_option) {
3041
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3042
+					$value = (int)$value;
3043
+					if ($value < 1 || $value > 999) {
3044
+						return;
3045
+					}
3046
+					break;
3047
+				default:
3048
+					$value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3049
+					if (false === $value) {
3050
+						return;
3051
+					}
3052
+					break;
3053
+			}
3054
+			update_user_meta($user->ID, $option, $value);
3055
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3056
+			exit;
3057
+		}
3058
+	}
3059
+
3060
+
3061
+
3062
+	/**
3063
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3064
+	 *
3065
+	 * @param array $data array that will be assigned to template args.
3066
+	 */
3067
+	public function set_template_args($data)
3068
+	{
3069
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3070
+	}
3071
+
3072
+
3073
+
3074
+	/**
3075
+	 * This makes available the WP transient system for temporarily moving data between routes
3076
+	 *
3077
+	 * @access protected
3078
+	 * @param string $route             the route that should receive the transient
3079
+	 * @param array  $data              the data that gets sent
3080
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3081
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3082
+	 * @return void
3083
+	 */
3084
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3085
+	{
3086
+		$user_id = get_current_user_id();
3087
+		if ( ! $skip_route_verify) {
3088
+			$this->_verify_route($route);
3089
+		}
3090
+		//now let's set the string for what kind of transient we're setting
3091
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3092
+		$data = $notices ? array('notices' => $data) : $data;
3093
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3094
+		$existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3095
+		if ($existing) {
3096
+			$data = array_merge((array)$data, (array)$existing);
3097
+		}
3098
+		if (is_multisite() && is_network_admin()) {
3099
+			set_site_transient($transient, $data, 8);
3100
+		} else {
3101
+			set_transient($transient, $data, 8);
3102
+		}
3103
+	}
3104
+
3105
+
3106
+
3107
+	/**
3108
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3109
+	 *
3110
+	 * @param bool $notices true we get notices transient. False we just return normal route transient
3111
+	 * @return mixed data
3112
+	 */
3113
+	protected function _get_transient($notices = false, $route = false)
3114
+	{
3115
+		$user_id = get_current_user_id();
3116
+		$route = ! $route ? $this->_req_action : $route;
3117
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3118
+		$data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3119
+		//delete transient after retrieval (just in case it hasn't expired);
3120
+		if (is_multisite() && is_network_admin()) {
3121
+			delete_site_transient($transient);
3122
+		} else {
3123
+			delete_transient($transient);
3124
+		}
3125
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3126
+	}
3127
+
3128
+
3129
+
3130
+	/**
3131
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3132
+	 * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3133
+	 *
3134
+	 * @return void
3135
+	 */
3136
+	protected function _transient_garbage_collection()
3137
+	{
3138
+		global $wpdb;
3139
+		//retrieve all existing transients
3140
+		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3141
+		if ($results = $wpdb->get_results($query)) {
3142
+			foreach ($results as $result) {
3143
+				$transient = str_replace('_transient_', '', $result->option_name);
3144
+				get_transient($transient);
3145
+				if (is_multisite() && is_network_admin()) {
3146
+					get_site_transient($transient);
3147
+				}
3148
+			}
3149
+		}
3150
+	}
3151
+
3152
+
3153
+
3154
+	/**
3155
+	 * get_view
3156
+	 *
3157
+	 * @access public
3158
+	 * @return string content of _view property
3159
+	 */
3160
+	public function get_view()
3161
+	{
3162
+		return $this->_view;
3163
+	}
3164
+
3165
+
3166
+
3167
+	/**
3168
+	 * getter for the protected $_views property
3169
+	 *
3170
+	 * @return array
3171
+	 */
3172
+	public function get_views()
3173
+	{
3174
+		return $this->_views;
3175
+	}
3176
+
3177
+
3178
+
3179
+	/**
3180
+	 * get_current_page
3181
+	 *
3182
+	 * @access public
3183
+	 * @return string _current_page property value
3184
+	 */
3185
+	public function get_current_page()
3186
+	{
3187
+		return $this->_current_page;
3188
+	}
3189
+
3190
+
3191
+
3192
+	/**
3193
+	 * get_current_view
3194
+	 *
3195
+	 * @access public
3196
+	 * @return string _current_view property value
3197
+	 */
3198
+	public function get_current_view()
3199
+	{
3200
+		return $this->_current_view;
3201
+	}
3202
+
3203
+
3204
+
3205
+	/**
3206
+	 * get_current_screen
3207
+	 *
3208
+	 * @access public
3209
+	 * @return object The current WP_Screen object
3210
+	 */
3211
+	public function get_current_screen()
3212
+	{
3213
+		return $this->_current_screen;
3214
+	}
3215
+
3216
+
3217
+
3218
+	/**
3219
+	 * get_current_page_view_url
3220
+	 *
3221
+	 * @access public
3222
+	 * @return string This returns the url for the current_page_view.
3223
+	 */
3224
+	public function get_current_page_view_url()
3225
+	{
3226
+		return $this->_current_page_view_url;
3227
+	}
3228
+
3229
+
3230
+
3231
+	/**
3232
+	 * just returns the _req_data property
3233
+	 *
3234
+	 * @return array
3235
+	 */
3236
+	public function get_request_data()
3237
+	{
3238
+		return $this->_req_data;
3239
+	}
3240
+
3241
+
3242
+
3243
+	/**
3244
+	 * returns the _req_data protected property
3245
+	 *
3246
+	 * @return string
3247
+	 */
3248
+	public function get_req_action()
3249
+	{
3250
+		return $this->_req_action;
3251
+	}
3252
+
3253
+
3254
+
3255
+	/**
3256
+	 * @return bool  value of $_is_caf property
3257
+	 */
3258
+	public function is_caf()
3259
+	{
3260
+		return $this->_is_caf;
3261
+	}
3262
+
3263
+
3264
+
3265
+	/**
3266
+	 * @return mixed
3267
+	 */
3268
+	public function default_espresso_metaboxes()
3269
+	{
3270
+		return $this->_default_espresso_metaboxes;
3271
+	}
3272
+
3273
+
3274
+
3275
+	/**
3276
+	 * @return mixed
3277
+	 */
3278
+	public function admin_base_url()
3279
+	{
3280
+		return $this->_admin_base_url;
3281
+	}
3282
+
3283
+
3284
+
3285
+	/**
3286
+	 * @return mixed
3287
+	 */
3288
+	public function wp_page_slug()
3289
+	{
3290
+		return $this->_wp_page_slug;
3291
+	}
3292
+
3293
+
3294
+
3295
+	/**
3296
+	 * updates  espresso configuration settings
3297
+	 *
3298
+	 * @access    protected
3299
+	 * @param string                   $tab
3300
+	 * @param EE_Config_Base|EE_Config $config
3301
+	 * @param string                   $file file where error occurred
3302
+	 * @param string                   $func function  where error occurred
3303
+	 * @param string                   $line line no where error occurred
3304
+	 * @return boolean
3305
+	 */
3306
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3307
+	{
3308
+		//remove any options that are NOT going to be saved with the config settings.
3309
+		if (isset($config->core->ee_ueip_optin)) {
3310
+			$config->core->ee_ueip_has_notified = true;
3311
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3312
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3313
+			update_option('ee_ueip_has_notified', true);
3314
+		}
3315
+		// and save it (note we're also doing the network save here)
3316
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3317
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3318
+		if ($config_saved && $net_saved) {
3319
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3320
+			return true;
3321
+		} else {
3322
+			EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3323
+			return false;
3324
+		}
3325
+	}
3326
+
3327
+
3328
+
3329
+	/**
3330
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3331
+	 *
3332
+	 * @return array
3333
+	 */
3334
+	public function get_yes_no_values()
3335
+	{
3336
+		return $this->_yes_no_values;
3337
+	}
3338
+
3339
+
3340
+
3341
+	protected function _get_dir()
3342
+	{
3343
+		$reflector = new ReflectionClass(get_class($this));
3344
+		return dirname($reflector->getFileName());
3345
+	}
3346
+
3347
+
3348
+
3349
+	/**
3350
+	 * A helper for getting a "next link".
3351
+	 *
3352
+	 * @param string $url   The url to link to
3353
+	 * @param string $class The class to use.
3354
+	 * @return string
3355
+	 */
3356
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3357
+	{
3358
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3359
+	}
3360
+
3361
+
3362
+
3363
+	/**
3364
+	 * A helper for getting a "previous link".
3365
+	 *
3366
+	 * @param string $url   The url to link to
3367
+	 * @param string $class The class to use.
3368
+	 * @return string
3369
+	 */
3370
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3371
+	{
3372
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3373
+	}
3374
+
3375
+
3376
+
3377
+
3378
+
3379
+
3380
+
3381
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3382
+	/**
3383
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3384
+	 * array.
3385
+	 *
3386
+	 * @return bool success/fail
3387
+	 */
3388
+	protected function _process_resend_registration()
3389
+	{
3390
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3391
+		do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3392
+		return $this->_template_args['success'];
3393
+	}
3394
+
3395
+
3396
+
3397
+	/**
3398
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3399
+	 *
3400
+	 * @access protected
3401
+	 * @param \EE_Payment $payment
3402
+	 * @return bool success/fail
3403
+	 */
3404
+	protected function _process_payment_notification(EE_Payment $payment)
3405
+	{
3406
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3407
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3408
+		$this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3409
+		return $this->_template_args['success'];
3410
+	}
3411 3411
 
3412 3412
 
3413 3413
 }
Please login to merge, or discard this patch.