@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | //reset property so that the new event is cached. |
55 | 55 | EEH_Event_View::$_event = null; |
56 | - if (! $EVT_ID && $post instanceof EE_Event) { |
|
56 | + if ( ! $EVT_ID && $post instanceof EE_Event) { |
|
57 | 57 | EEH_Event_View::$_event = $post; |
58 | 58 | return EEH_Event_View::$_event; |
59 | 59 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | return EEH_Event_View::$_event; |
73 | 73 | } |
74 | 74 | //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
75 | - if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
75 | + if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
76 | 76 | EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
77 | 77 | } |
78 | 78 | return EEH_Event_View::$_event; |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @param int $EVT_ID |
88 | 88 | * @return boolean |
89 | 89 | */ |
90 | - public static function display_ticket_selector( $EVT_ID = 0 ) { |
|
91 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
90 | + public static function display_ticket_selector($EVT_ID = 0) { |
|
91 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
92 | 92 | return $event instanceof EE_Event ? $event->display_ticket_selector() : FALSE; |
93 | 93 | } |
94 | 94 | |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param int $EVT_ID |
102 | 102 | * @return string |
103 | 103 | */ |
104 | - public static function event_status( $EVT_ID = 0 ) { |
|
105 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
106 | - return $event instanceof EE_Event ? $event->pretty_active_status( FALSE ) : ''; |
|
104 | + public static function event_status($EVT_ID = 0) { |
|
105 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
106 | + return $event instanceof EE_Event ? $event->pretty_active_status(FALSE) : ''; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * @param int $EVT_ID |
116 | 116 | * @return string |
117 | 117 | */ |
118 | - public static function event_active_status( $EVT_ID = 0 ) { |
|
119 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
118 | + public static function event_active_status($EVT_ID = 0) { |
|
119 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
120 | 120 | return $event instanceof EE_Event ? $event->pretty_active_status() : 'inactive'; |
121 | 121 | } |
122 | 122 | |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | * @param int $EVT_ID |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public static function event_has_content_or_excerpt( $EVT_ID = 0 ) { |
|
133 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
132 | + public static function event_has_content_or_excerpt($EVT_ID = 0) { |
|
133 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
134 | 134 | $has_content_or_excerpt = FALSE; |
135 | - if ( $event instanceof EE_Event ) { |
|
136 | - $has_content_or_excerpt = $event->description() != '' || $event->short_description( NULL, NULL, TRUE ) != '' ? TRUE : FALSE; |
|
135 | + if ($event instanceof EE_Event) { |
|
136 | + $has_content_or_excerpt = $event->description() != '' || $event->short_description(NULL, NULL, TRUE) != '' ? TRUE : FALSE; |
|
137 | 137 | } |
138 | - if ( is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) { |
|
138 | + if (is_archive() && ! (espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list())) { |
|
139 | 139 | $has_content_or_excerpt = FALSE; |
140 | 140 | } |
141 | 141 | return $has_content_or_excerpt; |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | * @param null $more |
152 | 152 | * @return string |
153 | 153 | */ |
154 | - public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) { |
|
154 | + public static function event_content_or_excerpt($num_words = NULL, $more = NULL) { |
|
155 | 155 | global $post; |
156 | 156 | ob_start(); |
157 | - if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) { |
|
157 | + if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) { |
|
158 | 158 | // admin has chosen "full description" |
159 | 159 | // for the "Event Espresso - Events > Templates > Display Description" option |
160 | 160 | the_content(); |
161 | - } else if (( is_archive() && espresso_display_excerpt_in_event_list() ) ) { |
|
162 | - if ( has_excerpt( $post->ID )) { |
|
161 | + } else if ((is_archive() && espresso_display_excerpt_in_event_list())) { |
|
162 | + if (has_excerpt($post->ID)) { |
|
163 | 163 | // admin has chosen "excerpt (short desc)" |
164 | 164 | // for the "Event Espresso - Events > Templates > Display Description" option |
165 | 165 | // AND an excerpt actually exists |
@@ -168,20 +168,20 @@ discard block |
||
168 | 168 | // admin has chosen "excerpt (short desc)" |
169 | 169 | // for the "Event Espresso - Events > Templates > Display Description" option |
170 | 170 | // but NO excerpt actually exists, so we need to create one |
171 | - if ( ! empty( $num_words )) { |
|
172 | - if ( empty( $more )) { |
|
173 | - $more_link_text = __( '(more…)' ); |
|
174 | - $more = ' <a href="' . get_permalink() . '"'; |
|
171 | + if ( ! empty($num_words)) { |
|
172 | + if (empty($more)) { |
|
173 | + $more_link_text = __('(more…)'); |
|
174 | + $more = ' <a href="'.get_permalink().'"'; |
|
175 | 175 | $more .= ' class="more-link"'; |
176 | 176 | $more .= \EED_Events_Archive::link_target(); |
177 | - $more .= '>' . $more_link_text . '</a>'; |
|
178 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
177 | + $more .= '>'.$more_link_text.'</a>'; |
|
178 | + $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
179 | 179 | } |
180 | - $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
|
180 | + $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
|
181 | 181 | |
182 | - $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
|
182 | + $content = wp_trim_words($content, $num_words, ' ').$more; |
|
183 | 183 | } else { |
184 | - $content = get_the_content(); |
|
184 | + $content = get_the_content(); |
|
185 | 185 | } |
186 | 186 | global $allowedtags; |
187 | 187 | // make sure links are allowed |
@@ -195,15 +195,15 @@ discard block |
||
195 | 195 | // but get previous value so we can reset it |
196 | 196 | $prev_value = $allowedtags['a']['target']; |
197 | 197 | $allowedtags['a']['target'] = true; |
198 | - $content = wp_kses( $content, $allowedtags ); |
|
199 | - $content = strip_shortcodes( $content ); |
|
200 | - echo apply_filters( 'the_content', $content ); |
|
198 | + $content = wp_kses($content, $allowedtags); |
|
199 | + $content = strip_shortcodes($content); |
|
200 | + echo apply_filters('the_content', $content); |
|
201 | 201 | $allowedtags['a']['target'] = $prev_value; |
202 | 202 | } |
203 | 203 | } else { |
204 | 204 | // admin has chosen "none" |
205 | 205 | // for the "Event Espresso - Events > Templates > Display Description" option |
206 | - echo apply_filters( 'the_content', '' ); |
|
206 | + echo apply_filters('the_content', ''); |
|
207 | 207 | } |
208 | 208 | return ob_get_clean(); |
209 | 209 | } |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | * @param int $EVT_ID |
218 | 218 | * @return EE_Ticket[] |
219 | 219 | */ |
220 | - public static function event_tickets_available( $EVT_ID = 0 ) { |
|
221 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
220 | + public static function event_tickets_available($EVT_ID = 0) { |
|
221 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
222 | 222 | $tickets_available_for_purchase = array(); |
223 | - if( $event instanceof EE_Event ) { |
|
224 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, FALSE ); |
|
225 | - foreach( $datetimes as $datetime ) { |
|
226 | - $tickets_available_for_purchase = array_merge( $tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase() ); |
|
223 | + if ($event instanceof EE_Event) { |
|
224 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, FALSE); |
|
225 | + foreach ($datetimes as $datetime) { |
|
226 | + $tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase()); |
|
227 | 227 | } |
228 | 228 | } |
229 | 229 | return $tickets_available_for_purchase; |
@@ -239,17 +239,17 @@ discard block |
||
239 | 239 | * @param bool $hide_uncategorized |
240 | 240 | * @return string |
241 | 241 | */ |
242 | - public static function event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE ) { |
|
242 | + public static function event_categories($EVT_ID = 0, $hide_uncategorized = TRUE) { |
|
243 | 243 | $category_links = array(); |
244 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
245 | - if ( $event instanceof EE_Event ) { |
|
246 | - $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' ); |
|
247 | - if ( $event_categories ) { |
|
244 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
245 | + if ($event instanceof EE_Event) { |
|
246 | + $event_categories = get_the_terms($event->ID(), 'espresso_event_categories'); |
|
247 | + if ($event_categories) { |
|
248 | 248 | // loop thru terms and create links |
249 | - foreach ( $event_categories as $term ) { |
|
250 | - $url = get_term_link( $term, 'espresso_venue_categories' ); |
|
251 | - if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
|
252 | - $category_links[] = '<a href="' . esc_url( $url ) |
|
249 | + foreach ($event_categories as $term) { |
|
250 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
251 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
252 | + $category_links[] = '<a href="'.esc_url($url) |
|
253 | 253 | . '" rel="tag"' |
254 | 254 | . \EED_Events_Archive::link_target() |
255 | 255 | .'>' |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
262 | - return implode( ', ', $category_links ); |
|
262 | + return implode(', ', $category_links); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | |
@@ -273,10 +273,10 @@ discard block |
||
273 | 273 | * @param int $EVT_ID |
274 | 274 | * @return string |
275 | 275 | */ |
276 | - public static function the_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
277 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
278 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
279 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
276 | + public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
277 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
278 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
279 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -290,10 +290,10 @@ discard block |
||
290 | 290 | * @param int $EVT_ID |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - public static function the_event_end_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
294 | - $datetime = EEH_Event_View::get_last_date_obj( $EVT_ID ); |
|
295 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
296 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
293 | + public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
294 | + $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
295 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
296 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | |
@@ -307,10 +307,10 @@ discard block |
||
307 | 307 | * @param int $EVT_ID |
308 | 308 | * @return string |
309 | 309 | */ |
310 | - public static function the_earliest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
311 | - $datetime = EEH_Event_View::get_earliest_date_obj( $EVT_ID ); |
|
312 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
313 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
310 | + public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
311 | + $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
|
312 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
313 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param int $EVT_ID |
325 | 325 | * @return string |
326 | 326 | */ |
327 | - public static function the_latest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
328 | - $datetime = EEH_Event_View::get_latest_date_obj( $EVT_ID ); |
|
329 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
330 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
327 | + public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
328 | + $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID); |
|
329 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
330 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
@@ -339,13 +339,13 @@ discard block |
||
339 | 339 | * @param int $EVT_ID |
340 | 340 | * @return string |
341 | 341 | */ |
342 | - public static function event_date_as_calendar_page( $EVT_ID = 0 ) { |
|
343 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
344 | - if ( $datetime instanceof EE_Datetime ) { |
|
342 | + public static function event_date_as_calendar_page($EVT_ID = 0) { |
|
343 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
344 | + if ($datetime instanceof EE_Datetime) { |
|
345 | 345 | ?> |
346 | 346 | <div class="event-date-calendar-page-dv"> |
347 | - <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime( 'DTT_EVT_start', 'M' );?></div> |
|
348 | - <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date( 'd' );?></div> |
|
347 | + <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M'); ?></div> |
|
348 | + <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d'); ?></div> |
|
349 | 349 | </div> |
350 | 350 | <?php |
351 | 351 | } |
@@ -360,17 +360,17 @@ discard block |
||
360 | 360 | * @param int $EVT_ID |
361 | 361 | * @return string |
362 | 362 | */ |
363 | - public static function get_primary_date_obj( $EVT_ID = 0 ) { |
|
364 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
365 | - if ( $event instanceof EE_Event ) { |
|
363 | + public static function get_primary_date_obj($EVT_ID = 0) { |
|
364 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
365 | + if ($event instanceof EE_Event) { |
|
366 | 366 | $datetimes = $event->get_many_related( |
367 | 367 | 'Datetime', |
368 | 368 | array( |
369 | 369 | 'limit' => 1, |
370 | - 'order_by' => array( 'DTT_order' => 'ASC' ) |
|
370 | + 'order_by' => array('DTT_order' => 'ASC') |
|
371 | 371 | ) |
372 | 372 | ); |
373 | - return reset( $datetimes ); |
|
373 | + return reset($datetimes); |
|
374 | 374 | } else { |
375 | 375 | return FALSE; |
376 | 376 | } |
@@ -385,17 +385,17 @@ discard block |
||
385 | 385 | * @param int $EVT_ID |
386 | 386 | * @return string |
387 | 387 | */ |
388 | - public static function get_last_date_obj( $EVT_ID = 0 ) { |
|
389 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
390 | - if ( $event instanceof EE_Event ) { |
|
388 | + public static function get_last_date_obj($EVT_ID = 0) { |
|
389 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
390 | + if ($event instanceof EE_Event) { |
|
391 | 391 | $datetimes = $event->get_many_related( |
392 | 392 | 'Datetime', |
393 | 393 | array( |
394 | 394 | 'limit' => 1, |
395 | - 'order_by' => array( 'DTT_order' => 'DESC' ) |
|
395 | + 'order_by' => array('DTT_order' => 'DESC') |
|
396 | 396 | ) |
397 | 397 | ); |
398 | - return end( $datetimes ); |
|
398 | + return end($datetimes); |
|
399 | 399 | } else { |
400 | 400 | return FALSE; |
401 | 401 | } |
@@ -410,17 +410,17 @@ discard block |
||
410 | 410 | * @param int $EVT_ID |
411 | 411 | * @return string |
412 | 412 | */ |
413 | - public static function get_earliest_date_obj( $EVT_ID = 0 ) { |
|
414 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
415 | - if ( $event instanceof EE_Event ) { |
|
413 | + public static function get_earliest_date_obj($EVT_ID = 0) { |
|
414 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
415 | + if ($event instanceof EE_Event) { |
|
416 | 416 | $datetimes = $event->get_many_related( |
417 | 417 | 'Datetime', |
418 | 418 | array( |
419 | 419 | 'limit' => 1, |
420 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
420 | + 'order_by' => array('DTT_EVT_start' => 'ASC') |
|
421 | 421 | ) |
422 | 422 | ); |
423 | - return reset( $datetimes ); |
|
423 | + return reset($datetimes); |
|
424 | 424 | } else { |
425 | 425 | return FALSE; |
426 | 426 | } |
@@ -435,17 +435,17 @@ discard block |
||
435 | 435 | * @param int $EVT_ID |
436 | 436 | * @return string |
437 | 437 | */ |
438 | - public static function get_latest_date_obj( $EVT_ID = 0 ) { |
|
439 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
440 | - if ( $event instanceof EE_Event ) { |
|
438 | + public static function get_latest_date_obj($EVT_ID = 0) { |
|
439 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
440 | + if ($event instanceof EE_Event) { |
|
441 | 441 | $datetimes = $event->get_many_related( |
442 | 442 | 'Datetime', |
443 | 443 | array( |
444 | 444 | 'limit' => 1, |
445 | - 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
445 | + 'order_by' => array('DTT_EVT_start' => 'DESC') |
|
446 | 446 | ) |
447 | 447 | ); |
448 | - return end( $datetimes ); |
|
448 | + return end($datetimes); |
|
449 | 449 | } else { |
450 | 450 | return FALSE; |
451 | 451 | } |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | * @param int $EVT_ID |
459 | 459 | * @return EE_Datetime|null |
460 | 460 | */ |
461 | - public static function get_next_upcoming_date_obj( $EVT_ID = 0 ) { |
|
461 | + public static function get_next_upcoming_date_obj($EVT_ID = 0) { |
|
462 | 462 | $datetime = EEM_Datetime::instance()->get_one( |
463 | 463 | array( |
464 | 464 | array( |
@@ -481,17 +481,17 @@ discard block |
||
481 | 481 | * @param null $limit |
482 | 482 | * @return EE_Datetime[] |
483 | 483 | */ |
484 | - public static function get_all_date_obj( $EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL ) { |
|
485 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
486 | - if($include_expired === null){ |
|
487 | - if($event instanceof EE_Event && $event->is_expired()){ |
|
484 | + public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL) { |
|
485 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
486 | + if ($include_expired === null) { |
|
487 | + if ($event instanceof EE_Event && $event->is_expired()) { |
|
488 | 488 | $include_expired = true; |
489 | - }else{ |
|
489 | + } else { |
|
490 | 490 | $include_expired = false; |
491 | 491 | } |
492 | 492 | } |
493 | 493 | |
494 | - if ( $event instanceof EE_Event ) { |
|
494 | + if ($event instanceof EE_Event) { |
|
495 | 495 | return $event->datetimes_ordered($include_expired, $include_deleted, $limit); |
496 | 496 | } else { |
497 | 497 | return array(); |
@@ -507,11 +507,11 @@ discard block |
||
507 | 507 | * @param int $EVT_ID |
508 | 508 | * @return string |
509 | 509 | */ |
510 | - public static function event_link_url( $EVT_ID = 0 ) { |
|
511 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
512 | - if ( $event instanceof EE_Event ) { |
|
513 | - $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink( $event->ID() ); |
|
514 | - return preg_match( "~^(?:f|ht)tps?://~i", $url ) ? $url : 'http://' . $url; |
|
510 | + public static function event_link_url($EVT_ID = 0) { |
|
511 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
512 | + if ($event instanceof EE_Event) { |
|
513 | + $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID()); |
|
514 | + return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://'.$url; |
|
515 | 515 | } |
516 | 516 | return NULL; |
517 | 517 | } |
@@ -525,10 +525,10 @@ discard block |
||
525 | 525 | * @param int $EVT_ID |
526 | 526 | * @return string |
527 | 527 | */ |
528 | - public static function event_phone( $EVT_ID = 0 ) { |
|
529 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
530 | - if ( $event instanceof EE_Event ) { |
|
531 | - return EEH_Schema::telephone( $event->phone() ); |
|
528 | + public static function event_phone($EVT_ID = 0) { |
|
529 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
530 | + if ($event instanceof EE_Event) { |
|
531 | + return EEH_Schema::telephone($event->phone()); |
|
532 | 532 | } |
533 | 533 | return NULL; |
534 | 534 | } |
@@ -545,26 +545,26 @@ discard block |
||
545 | 545 | * @param string $after |
546 | 546 | * @return string |
547 | 547 | */ |
548 | - public static function edit_event_link( $EVT_ID = 0, $link = '', $before = '', $after = '' ) { |
|
549 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
550 | - if ( $event instanceof EE_Event ) { |
|
548 | + public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') { |
|
549 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
550 | + if ($event instanceof EE_Event) { |
|
551 | 551 | // can the user edit this post ? |
552 | - if ( current_user_can( 'edit_post', $event->ID() )) { |
|
552 | + if (current_user_can('edit_post', $event->ID())) { |
|
553 | 553 | // set link text |
554 | - $link_text = ! empty( $link ) ? $link : __('edit this event'); |
|
554 | + $link_text = ! empty($link) ? $link : __('edit this event'); |
|
555 | 555 | // generate nonce |
556 | - $nonce = wp_create_nonce( 'edit_nonce' ); |
|
556 | + $nonce = wp_create_nonce('edit_nonce'); |
|
557 | 557 | // generate url to event editor for this event |
558 | - $url = add_query_arg( array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url() ); |
|
558 | + $url = add_query_arg(array('page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce), admin_url()); |
|
559 | 559 | // get edit CPT text |
560 | - $post_type_obj = get_post_type_object( 'espresso_events' ); |
|
560 | + $post_type_obj = get_post_type_object('espresso_events'); |
|
561 | 561 | // build final link html |
562 | - $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
563 | - $link .= ' title="' . esc_attr( $post_type_obj->labels->edit_item ) . '"'; |
|
562 | + $link = '<a class="post-edit-link" href="'.$url.'" '; |
|
563 | + $link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"'; |
|
564 | 564 | $link .= \EED_Events_Archive::link_target(); |
565 | - $link .='>' . $link_text . '</a>'; |
|
565 | + $link .= '>'.$link_text.'</a>'; |
|
566 | 566 | // put it all together |
567 | - return $before . apply_filters( 'edit_post_link', $link, $event->ID() ) . $after; |
|
567 | + return $before.apply_filters('edit_post_link', $link, $event->ID()).$after; |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | return ''; |
@@ -15,214 +15,214 @@ |
||
15 | 15 | class EEH_Money extends EEH_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This removes all localized money formatting from the incoming value |
|
20 | - * Note: uses this site's currency settings for deciding what is considered a |
|
21 | - * "thousands separator" (usually the character "," ) |
|
22 | - * and what is a "decimal mark" (usually the character ".") |
|
23 | - * |
|
24 | - * @param int|float|string $money_value |
|
25 | - * @param string $CNT_ISO |
|
26 | - * @return float |
|
27 | - * @throws EE_Error |
|
28 | - */ |
|
29 | - public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') |
|
30 | - { |
|
31 | - $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
32 | - $money_value = str_replace( |
|
33 | - array( |
|
34 | - $currency_config->thsnds, |
|
35 | - $currency_config->dec_mrk, |
|
36 | - ), |
|
37 | - array( |
|
38 | - '', // remove thousands separator |
|
39 | - '.', // convert decimal mark to what PHP expects |
|
40 | - ), |
|
41 | - $money_value |
|
42 | - ); |
|
43 | - $money_value = filter_var( |
|
44 | - $money_value, |
|
45 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
46 | - FILTER_FLAG_ALLOW_FRACTION |
|
47 | - ); |
|
48 | - return $money_value; |
|
49 | - } |
|
18 | + /** |
|
19 | + * This removes all localized money formatting from the incoming value |
|
20 | + * Note: uses this site's currency settings for deciding what is considered a |
|
21 | + * "thousands separator" (usually the character "," ) |
|
22 | + * and what is a "decimal mark" (usually the character ".") |
|
23 | + * |
|
24 | + * @param int|float|string $money_value |
|
25 | + * @param string $CNT_ISO |
|
26 | + * @return float |
|
27 | + * @throws EE_Error |
|
28 | + */ |
|
29 | + public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') |
|
30 | + { |
|
31 | + $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
32 | + $money_value = str_replace( |
|
33 | + array( |
|
34 | + $currency_config->thsnds, |
|
35 | + $currency_config->dec_mrk, |
|
36 | + ), |
|
37 | + array( |
|
38 | + '', // remove thousands separator |
|
39 | + '.', // convert decimal mark to what PHP expects |
|
40 | + ), |
|
41 | + $money_value |
|
42 | + ); |
|
43 | + $money_value = filter_var( |
|
44 | + $money_value, |
|
45 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
46 | + FILTER_FLAG_ALLOW_FRACTION |
|
47 | + ); |
|
48 | + return $money_value; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
54 | - * Only use this if you know the $money_value follows your currency configuration's |
|
55 | - * settings. Note: this uses this site's currency settings for deciding what is considered a |
|
56 | - * "thousands separator" (usually the character "," ) |
|
57 | - * and what is a "decimal mark" (usually the character ".") |
|
58 | - * |
|
59 | - * @param int|string $money_value |
|
60 | - * @return float |
|
61 | - * @throws EE_Error |
|
62 | - */ |
|
63 | - public static function convert_to_float_from_localized_money($money_value) |
|
64 | - { |
|
65 | - //float it! and round to three decimal places |
|
66 | - return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3); |
|
67 | - } |
|
52 | + /** |
|
53 | + * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
54 | + * Only use this if you know the $money_value follows your currency configuration's |
|
55 | + * settings. Note: this uses this site's currency settings for deciding what is considered a |
|
56 | + * "thousands separator" (usually the character "," ) |
|
57 | + * and what is a "decimal mark" (usually the character ".") |
|
58 | + * |
|
59 | + * @param int|string $money_value |
|
60 | + * @return float |
|
61 | + * @throws EE_Error |
|
62 | + */ |
|
63 | + public static function convert_to_float_from_localized_money($money_value) |
|
64 | + { |
|
65 | + //float it! and round to three decimal places |
|
66 | + return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
72 | - * This should be used to compare floats instead of normal '==' because floats |
|
73 | - * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
74 | - * but actually differ by 0.00000001. |
|
75 | - * |
|
76 | - * @see http://biostall.com/php-function-to-compare-floating-point-numbers |
|
77 | - * @param float $float1 |
|
78 | - * @param float $float2 |
|
79 | - * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
80 | - * @return bool whether the equation is true or false |
|
81 | - * @throws EE_Error |
|
82 | - */ |
|
83 | - public static function compare_floats($float1, $float2, $operator = '=') |
|
84 | - { |
|
85 | - // Check numbers to 5 digits of precision |
|
86 | - $epsilon = 0.00001; |
|
87 | - $float1 = (float) $float1; |
|
88 | - $float2 = (float) $float2; |
|
89 | - switch ($operator) { |
|
90 | - // equal |
|
91 | - case "=": |
|
92 | - case "==": |
|
93 | - case "===": |
|
94 | - case "eq": |
|
95 | - if (abs($float1 - $float2) < $epsilon) { |
|
96 | - return true; |
|
97 | - } |
|
98 | - break; |
|
99 | - // less than |
|
100 | - case "<": |
|
101 | - case "lt": |
|
102 | - if (abs($float1 - $float2) < $epsilon) { |
|
103 | - return false; |
|
104 | - } else { |
|
105 | - if ($float1 < $float2) { |
|
106 | - return true; |
|
107 | - } |
|
108 | - } |
|
109 | - break; |
|
110 | - // less than or equal |
|
111 | - case "<=": |
|
112 | - case "lte": |
|
113 | - if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) { |
|
114 | - return true; |
|
115 | - } |
|
116 | - break; |
|
117 | - // greater than |
|
118 | - case ">": |
|
119 | - case "gt": |
|
120 | - if (abs($float1 - $float2) < $epsilon) { |
|
121 | - return false; |
|
122 | - } else { |
|
123 | - if ($float1 > $float2) { |
|
124 | - return true; |
|
125 | - } |
|
126 | - } |
|
127 | - break; |
|
128 | - // greater than or equal |
|
129 | - case ">=": |
|
130 | - case "gte": |
|
131 | - if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) { |
|
132 | - return true; |
|
133 | - } |
|
134 | - break; |
|
135 | - case "<>": |
|
136 | - case "!=": |
|
137 | - case "ne": |
|
138 | - if (abs($float1 - $float2) > $epsilon) { |
|
139 | - return true; |
|
140 | - } |
|
141 | - break; |
|
142 | - default: |
|
143 | - throw new EE_Error(__("Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", |
|
144 | - 'event_espresso')); |
|
145 | - } |
|
146 | - return false; |
|
147 | - } |
|
70 | + /** |
|
71 | + * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
72 | + * This should be used to compare floats instead of normal '==' because floats |
|
73 | + * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
74 | + * but actually differ by 0.00000001. |
|
75 | + * |
|
76 | + * @see http://biostall.com/php-function-to-compare-floating-point-numbers |
|
77 | + * @param float $float1 |
|
78 | + * @param float $float2 |
|
79 | + * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
80 | + * @return bool whether the equation is true or false |
|
81 | + * @throws EE_Error |
|
82 | + */ |
|
83 | + public static function compare_floats($float1, $float2, $operator = '=') |
|
84 | + { |
|
85 | + // Check numbers to 5 digits of precision |
|
86 | + $epsilon = 0.00001; |
|
87 | + $float1 = (float) $float1; |
|
88 | + $float2 = (float) $float2; |
|
89 | + switch ($operator) { |
|
90 | + // equal |
|
91 | + case "=": |
|
92 | + case "==": |
|
93 | + case "===": |
|
94 | + case "eq": |
|
95 | + if (abs($float1 - $float2) < $epsilon) { |
|
96 | + return true; |
|
97 | + } |
|
98 | + break; |
|
99 | + // less than |
|
100 | + case "<": |
|
101 | + case "lt": |
|
102 | + if (abs($float1 - $float2) < $epsilon) { |
|
103 | + return false; |
|
104 | + } else { |
|
105 | + if ($float1 < $float2) { |
|
106 | + return true; |
|
107 | + } |
|
108 | + } |
|
109 | + break; |
|
110 | + // less than or equal |
|
111 | + case "<=": |
|
112 | + case "lte": |
|
113 | + if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) { |
|
114 | + return true; |
|
115 | + } |
|
116 | + break; |
|
117 | + // greater than |
|
118 | + case ">": |
|
119 | + case "gt": |
|
120 | + if (abs($float1 - $float2) < $epsilon) { |
|
121 | + return false; |
|
122 | + } else { |
|
123 | + if ($float1 > $float2) { |
|
124 | + return true; |
|
125 | + } |
|
126 | + } |
|
127 | + break; |
|
128 | + // greater than or equal |
|
129 | + case ">=": |
|
130 | + case "gte": |
|
131 | + if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) { |
|
132 | + return true; |
|
133 | + } |
|
134 | + break; |
|
135 | + case "<>": |
|
136 | + case "!=": |
|
137 | + case "ne": |
|
138 | + if (abs($float1 - $float2) > $epsilon) { |
|
139 | + return true; |
|
140 | + } |
|
141 | + break; |
|
142 | + default: |
|
143 | + throw new EE_Error(__("Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", |
|
144 | + 'event_espresso')); |
|
145 | + } |
|
146 | + return false; |
|
147 | + } |
|
148 | 148 | |
149 | 149 | |
150 | - /** |
|
151 | - * This returns a localized format string suitable for jQplot. |
|
152 | - * |
|
153 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
154 | - * Otherwise will use currency settings for current active country on site. |
|
155 | - * @return string |
|
156 | - * @throws EE_Error |
|
157 | - */ |
|
158 | - public static function get_format_for_jqplot($CNT_ISO = '') |
|
159 | - { |
|
160 | - //default format |
|
161 | - $format = 'f'; |
|
162 | - $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
163 | - //first get the decimal place and number of places |
|
164 | - $format = "%'." . $currency_config->dec_plc . $format; |
|
165 | - //currency symbol on right side. |
|
166 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
167 | - return $format; |
|
168 | - } |
|
150 | + /** |
|
151 | + * This returns a localized format string suitable for jQplot. |
|
152 | + * |
|
153 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
154 | + * Otherwise will use currency settings for current active country on site. |
|
155 | + * @return string |
|
156 | + * @throws EE_Error |
|
157 | + */ |
|
158 | + public static function get_format_for_jqplot($CNT_ISO = '') |
|
159 | + { |
|
160 | + //default format |
|
161 | + $format = 'f'; |
|
162 | + $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
163 | + //first get the decimal place and number of places |
|
164 | + $format = "%'." . $currency_config->dec_plc . $format; |
|
165 | + //currency symbol on right side. |
|
166 | + $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
167 | + return $format; |
|
168 | + } |
|
169 | 169 | |
170 | 170 | |
171 | - /** |
|
172 | - * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
173 | - * |
|
174 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
175 | - * Otherwise will use currency settings for current active country on site. |
|
176 | - * Note: GoogleCharts uses ICU pattern set |
|
177 | - * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
178 | - * @return string |
|
179 | - * @throws EE_Error |
|
180 | - */ |
|
181 | - public static function get_format_for_google_charts($CNT_ISO = '') |
|
182 | - { |
|
183 | - $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
184 | - $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
|
185 | - //first get the decimal place and number of places |
|
186 | - $format = '#,##0.' . $decimal_places_placeholder; |
|
187 | - //currency symbol on right side. |
|
188 | - $format = $currency_config->sign_b4 |
|
189 | - ? $currency_config->sign . $format |
|
190 | - : $format |
|
191 | - . $currency_config->sign; |
|
192 | - $formatterObject = array( |
|
193 | - 'decimalSymbol' => $currency_config->dec_mrk, |
|
194 | - 'groupingSymbol' => $currency_config->thsnds, |
|
195 | - 'fractionDigits' => $currency_config->dec_plc, |
|
196 | - ); |
|
197 | - if ($currency_config->sign_b4) { |
|
198 | - $formatterObject['prefix'] = $currency_config->sign; |
|
199 | - } else { |
|
200 | - $formatterObject['suffix'] = $currency_config->sign; |
|
201 | - } |
|
202 | - return array( |
|
203 | - 'format' => $format, |
|
204 | - 'formatterObject' => $formatterObject, |
|
205 | - ); |
|
206 | - } |
|
171 | + /** |
|
172 | + * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
173 | + * |
|
174 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
175 | + * Otherwise will use currency settings for current active country on site. |
|
176 | + * Note: GoogleCharts uses ICU pattern set |
|
177 | + * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
178 | + * @return string |
|
179 | + * @throws EE_Error |
|
180 | + */ |
|
181 | + public static function get_format_for_google_charts($CNT_ISO = '') |
|
182 | + { |
|
183 | + $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
184 | + $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
|
185 | + //first get the decimal place and number of places |
|
186 | + $format = '#,##0.' . $decimal_places_placeholder; |
|
187 | + //currency symbol on right side. |
|
188 | + $format = $currency_config->sign_b4 |
|
189 | + ? $currency_config->sign . $format |
|
190 | + : $format |
|
191 | + . $currency_config->sign; |
|
192 | + $formatterObject = array( |
|
193 | + 'decimalSymbol' => $currency_config->dec_mrk, |
|
194 | + 'groupingSymbol' => $currency_config->thsnds, |
|
195 | + 'fractionDigits' => $currency_config->dec_plc, |
|
196 | + ); |
|
197 | + if ($currency_config->sign_b4) { |
|
198 | + $formatterObject['prefix'] = $currency_config->sign; |
|
199 | + } else { |
|
200 | + $formatterObject['suffix'] = $currency_config->sign; |
|
201 | + } |
|
202 | + return array( |
|
203 | + 'format' => $format, |
|
204 | + 'formatterObject' => $formatterObject, |
|
205 | + ); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | - /** |
|
210 | - * @param string $CNT_ISO |
|
211 | - * @return EE_Currency_Config|null |
|
212 | - * @throws EE_Error |
|
213 | - */ |
|
214 | - public static function get_currency_config($CNT_ISO = '') |
|
215 | - { |
|
216 | - //if CNT_ISO passed lets try to get currency settings for it. |
|
217 | - $currency_config = $CNT_ISO !== '' |
|
218 | - ? new EE_Currency_Config($CNT_ISO) |
|
219 | - : null; |
|
220 | - //default currency settings for site if not set |
|
221 | - if (! $currency_config instanceof EE_Currency_Config) { |
|
222 | - $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
223 | - ? EE_Registry::instance()->CFG->currency |
|
224 | - : new EE_Currency_Config(); |
|
225 | - } |
|
226 | - return $currency_config; |
|
227 | - } |
|
209 | + /** |
|
210 | + * @param string $CNT_ISO |
|
211 | + * @return EE_Currency_Config|null |
|
212 | + * @throws EE_Error |
|
213 | + */ |
|
214 | + public static function get_currency_config($CNT_ISO = '') |
|
215 | + { |
|
216 | + //if CNT_ISO passed lets try to get currency settings for it. |
|
217 | + $currency_config = $CNT_ISO !== '' |
|
218 | + ? new EE_Currency_Config($CNT_ISO) |
|
219 | + : null; |
|
220 | + //default currency settings for site if not set |
|
221 | + if (! $currency_config instanceof EE_Currency_Config) { |
|
222 | + $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
223 | + ? EE_Registry::instance()->CFG->currency |
|
224 | + : new EE_Currency_Config(); |
|
225 | + } |
|
226 | + return $currency_config; |
|
227 | + } |
|
228 | 228 | } //end class EEH_Money |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | ), |
41 | 41 | $money_value |
42 | 42 | ); |
43 | - $money_value = filter_var( |
|
43 | + $money_value = filter_var( |
|
44 | 44 | $money_value, |
45 | 45 | FILTER_SANITIZE_NUMBER_FLOAT, |
46 | 46 | FILTER_FLAG_ALLOW_FRACTION |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | } |
141 | 141 | break; |
142 | 142 | default: |
143 | - throw new EE_Error(__("Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", |
|
143 | + throw new EE_Error(__("Unknown operator '".$operator."' in EEH_Money::compare_floats()", |
|
144 | 144 | 'event_espresso')); |
145 | 145 | } |
146 | 146 | return false; |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | $format = 'f'; |
162 | 162 | $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
163 | 163 | //first get the decimal place and number of places |
164 | - $format = "%'." . $currency_config->dec_plc . $format; |
|
164 | + $format = "%'.".$currency_config->dec_plc.$format; |
|
165 | 165 | //currency symbol on right side. |
166 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
166 | + $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign; |
|
167 | 167 | return $format; |
168 | 168 | } |
169 | 169 | |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
184 | 184 | $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
185 | 185 | //first get the decimal place and number of places |
186 | - $format = '#,##0.' . $decimal_places_placeholder; |
|
186 | + $format = '#,##0.'.$decimal_places_placeholder; |
|
187 | 187 | //currency symbol on right side. |
188 | - $format = $currency_config->sign_b4 |
|
189 | - ? $currency_config->sign . $format |
|
188 | + $format = $currency_config->sign_b4 |
|
189 | + ? $currency_config->sign.$format |
|
190 | 190 | : $format |
191 | 191 | . $currency_config->sign; |
192 | 192 | $formatterObject = array( |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | ? new EE_Currency_Config($CNT_ISO) |
219 | 219 | : null; |
220 | 220 | //default currency settings for site if not set |
221 | - if (! $currency_config instanceof EE_Currency_Config) { |
|
221 | + if ( ! $currency_config instanceof EE_Currency_Config) { |
|
222 | 222 | $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
223 | 223 | ? EE_Registry::instance()->CFG->currency |
224 | 224 | : new EE_Currency_Config(); |
@@ -16,114 +16,114 @@ discard block |
||
16 | 16 | class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table |
17 | 17 | { |
18 | 18 | |
19 | - private $_status; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * @param \Transactions_Admin_Page $admin_page |
|
24 | - */ |
|
25 | - public function __construct(\Transactions_Admin_Page $admin_page) |
|
26 | - { |
|
27 | - parent::__construct($admin_page); |
|
28 | - $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - *_setup_data |
|
34 | - */ |
|
35 | - protected function _setup_data() |
|
36 | - { |
|
37 | - $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
38 | - $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
39 | - $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - *_set_properties |
|
45 | - */ |
|
46 | - protected function _set_properties() |
|
47 | - { |
|
48 | - $this->_wp_list_args = array( |
|
49 | - 'singular' => __('transaction', 'event_espresso'), |
|
50 | - 'plural' => __('transactions', 'event_espresso'), |
|
51 | - 'ajax' => true, |
|
52 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | - ); |
|
54 | - $ID_column_name = __('ID', 'event_espresso'); |
|
55 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
56 | - $ID_column_name .= __('Transaction Date', 'event_espresso'); |
|
57 | - $ID_column_name .= '</span> '; |
|
58 | - $this->_columns = array( |
|
59 | - 'TXN_ID' => $ID_column_name, |
|
60 | - 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
|
61 | - 'TXN_total' => __('Total', 'event_espresso'), |
|
62 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
63 | - 'ATT_fname' => __('Primary Registrant', 'event_espresso'), |
|
64 | - 'event_name' => __('Event', 'event_espresso'), |
|
65 | - 'actions' => __('Actions', 'event_espresso'), |
|
66 | - ); |
|
67 | - |
|
68 | - $this->_sortable_columns = array( |
|
69 | - 'TXN_ID' => array('TXN_ID' => false), |
|
70 | - 'event_name' => array('event_name' => false), |
|
71 | - 'ATT_fname' => array('ATT_fname' => false), |
|
72 | - 'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted |
|
73 | - ); |
|
74 | - |
|
75 | - $this->_primary_column = 'TXN_ID'; |
|
76 | - |
|
77 | - $this->_hidden_columns = array(); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * This simply sets up the row class for the table rows. |
|
83 | - * Allows for easier overriding of child methods for setting up sorting. |
|
84 | - * |
|
85 | - * @param EE_Transaction $transaction the current item |
|
86 | - * @return string |
|
87 | - * @throws \EE_Error |
|
88 | - */ |
|
89 | - protected function _get_row_class($transaction) |
|
90 | - { |
|
91 | - $class = parent::_get_row_class($transaction); |
|
92 | - //add status class |
|
93 | - $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
94 | - if ($this->_has_checkbox_column) { |
|
95 | - $class .= ' has-checkbox-column'; |
|
96 | - } |
|
97 | - return $class; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * _get_table_filters |
|
103 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
104 | - * get's shown in the table. |
|
105 | - * |
|
106 | - * @abstract |
|
107 | - * @access protected |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - protected function _get_table_filters() |
|
111 | - { |
|
112 | - $filters = array(); |
|
113 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
114 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
115 | - : date( |
|
116 | - 'm/d/Y', |
|
117 | - strtotime('-10 year') |
|
118 | - ); |
|
119 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
120 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
121 | - : date( |
|
122 | - 'm/d/Y', |
|
123 | - current_time('timestamp') |
|
124 | - ); |
|
125 | - ob_start(); |
|
126 | - ?> |
|
19 | + private $_status; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * @param \Transactions_Admin_Page $admin_page |
|
24 | + */ |
|
25 | + public function __construct(\Transactions_Admin_Page $admin_page) |
|
26 | + { |
|
27 | + parent::__construct($admin_page); |
|
28 | + $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + *_setup_data |
|
34 | + */ |
|
35 | + protected function _setup_data() |
|
36 | + { |
|
37 | + $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
38 | + $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
39 | + $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + *_set_properties |
|
45 | + */ |
|
46 | + protected function _set_properties() |
|
47 | + { |
|
48 | + $this->_wp_list_args = array( |
|
49 | + 'singular' => __('transaction', 'event_espresso'), |
|
50 | + 'plural' => __('transactions', 'event_espresso'), |
|
51 | + 'ajax' => true, |
|
52 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | + ); |
|
54 | + $ID_column_name = __('ID', 'event_espresso'); |
|
55 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
56 | + $ID_column_name .= __('Transaction Date', 'event_espresso'); |
|
57 | + $ID_column_name .= '</span> '; |
|
58 | + $this->_columns = array( |
|
59 | + 'TXN_ID' => $ID_column_name, |
|
60 | + 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
|
61 | + 'TXN_total' => __('Total', 'event_espresso'), |
|
62 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
63 | + 'ATT_fname' => __('Primary Registrant', 'event_espresso'), |
|
64 | + 'event_name' => __('Event', 'event_espresso'), |
|
65 | + 'actions' => __('Actions', 'event_espresso'), |
|
66 | + ); |
|
67 | + |
|
68 | + $this->_sortable_columns = array( |
|
69 | + 'TXN_ID' => array('TXN_ID' => false), |
|
70 | + 'event_name' => array('event_name' => false), |
|
71 | + 'ATT_fname' => array('ATT_fname' => false), |
|
72 | + 'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted |
|
73 | + ); |
|
74 | + |
|
75 | + $this->_primary_column = 'TXN_ID'; |
|
76 | + |
|
77 | + $this->_hidden_columns = array(); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * This simply sets up the row class for the table rows. |
|
83 | + * Allows for easier overriding of child methods for setting up sorting. |
|
84 | + * |
|
85 | + * @param EE_Transaction $transaction the current item |
|
86 | + * @return string |
|
87 | + * @throws \EE_Error |
|
88 | + */ |
|
89 | + protected function _get_row_class($transaction) |
|
90 | + { |
|
91 | + $class = parent::_get_row_class($transaction); |
|
92 | + //add status class |
|
93 | + $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
94 | + if ($this->_has_checkbox_column) { |
|
95 | + $class .= ' has-checkbox-column'; |
|
96 | + } |
|
97 | + return $class; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * _get_table_filters |
|
103 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
104 | + * get's shown in the table. |
|
105 | + * |
|
106 | + * @abstract |
|
107 | + * @access protected |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + protected function _get_table_filters() |
|
111 | + { |
|
112 | + $filters = array(); |
|
113 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
114 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
115 | + : date( |
|
116 | + 'm/d/Y', |
|
117 | + strtotime('-10 year') |
|
118 | + ); |
|
119 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
120 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
121 | + : date( |
|
122 | + 'm/d/Y', |
|
123 | + current_time('timestamp') |
|
124 | + ); |
|
125 | + ob_start(); |
|
126 | + ?> |
|
127 | 127 | <label for="txn-filter-start-date">Display Transactions from </label> |
128 | 128 | <input id="txn-filter-start-date" class="datepicker" type="text" value="<?php echo $start_date; ?>" |
129 | 129 | name="txn-filter-start-date" size="15"/> |
@@ -131,554 +131,554 @@ discard block |
||
131 | 131 | <input id="txn-filter-end-date" class="datepicker" type="text" value="<?php echo $end_date; ?>" |
132 | 132 | name="txn-filter-end-date" size="15"/> |
133 | 133 | <?php |
134 | - $filters[] = ob_get_contents(); |
|
135 | - ob_end_clean(); |
|
136 | - return $filters; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - *_add_view_counts |
|
142 | - */ |
|
143 | - protected function _add_view_counts() |
|
144 | - { |
|
145 | - $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); |
|
146 | - $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); |
|
147 | - $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * column TXN_ID |
|
153 | - * |
|
154 | - * @param \EE_Transaction $transaction |
|
155 | - * @return string |
|
156 | - * @throws \EE_Error |
|
157 | - */ |
|
158 | - public function column_TXN_ID(EE_Transaction $transaction) |
|
159 | - { |
|
160 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
161 | - 'action' => 'view_transaction', |
|
162 | - 'TXN_ID' => $transaction->ID(), |
|
163 | - ), TXN_ADMIN_URL); |
|
164 | - $content = '<a href="' . $view_lnk_url . '"' |
|
165 | - . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
166 | - . $transaction->ID() |
|
167 | - . '</a>'; |
|
168 | - |
|
169 | - //txn timestamp |
|
170 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
171 | - return $content; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param \EE_Transaction $transaction |
|
177 | - * @return string |
|
178 | - * @throws EE_Error |
|
179 | - * @throws InvalidArgumentException |
|
180 | - * @throws InvalidDataTypeException |
|
181 | - * @throws InvalidInterfaceException |
|
182 | - */ |
|
183 | - protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
184 | - { |
|
185 | - //txn timestamp |
|
186 | - // is TXN less than 2 hours old ? |
|
187 | - if (($transaction->failed() || $transaction->is_abandoned()) |
|
188 | - && ( |
|
189 | - (time() - EE_Registry::instance()->SSN->lifespan()) < $transaction->datetime(false, true) |
|
190 | - ) |
|
191 | - ) { |
|
192 | - $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
193 | - } else { |
|
194 | - $timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); |
|
195 | - } |
|
196 | - return $timestamp; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * column_cb |
|
202 | - * |
|
203 | - * @param \EE_Transaction $transaction |
|
204 | - * @return string |
|
205 | - * @throws \EE_Error |
|
206 | - */ |
|
207 | - public function column_cb($transaction) |
|
208 | - { |
|
209 | - return sprintf( |
|
210 | - '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
211 | - $this->_wp_list_args['singular'], |
|
212 | - $transaction->ID() |
|
213 | - ); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * column_TXN_timestamp |
|
219 | - * |
|
220 | - * @param \EE_Transaction $transaction |
|
221 | - * @return string |
|
222 | - * @throws \EE_Error |
|
223 | - */ |
|
224 | - public function column_TXN_timestamp(EE_Transaction $transaction) |
|
225 | - { |
|
226 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
227 | - 'action' => 'view_transaction', |
|
228 | - 'TXN_ID' => $transaction->ID(), |
|
229 | - ), TXN_ADMIN_URL); |
|
230 | - $txn_date = '<a href="' . $view_lnk_url . '"' |
|
231 | - . ' title="' |
|
232 | - . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
233 | - . $this->_get_txn_timestamp($transaction) |
|
234 | - . '</a>'; |
|
235 | - //status |
|
236 | - $txn_date .= '<br><span class="ee-status-text-small">' |
|
237 | - . EEH_Template::pretty_status( |
|
238 | - $transaction->status_ID(), |
|
239 | - false, |
|
240 | - 'sentence' |
|
241 | - ) |
|
242 | - . '</span>'; |
|
243 | - return $txn_date; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * column_TXN_total |
|
249 | - * |
|
250 | - * @param \EE_Transaction $transaction |
|
251 | - * @return string |
|
252 | - * @throws \EE_Error |
|
253 | - */ |
|
254 | - public function column_TXN_total(EE_Transaction $transaction) |
|
255 | - { |
|
256 | - if ($transaction->get('TXN_total') > 0) { |
|
257 | - return '<span class="txn-pad-rght">' |
|
258 | - . apply_filters( |
|
259 | - 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
260 | - $transaction->get_pretty('TXN_total'), |
|
261 | - $transaction |
|
262 | - ) |
|
263 | - . '</span>'; |
|
264 | - } else { |
|
265 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * column_TXN_paid |
|
272 | - * |
|
273 | - * @param \EE_Transaction $transaction |
|
274 | - * @return mixed|string |
|
275 | - * @throws \EE_Error |
|
276 | - */ |
|
277 | - public function column_TXN_paid(EE_Transaction $transaction) |
|
278 | - { |
|
279 | - $transaction_total = $transaction->get('TXN_total'); |
|
280 | - $transaction_paid = $transaction->get('TXN_paid'); |
|
281 | - |
|
282 | - if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
283 | - // monies owing |
|
284 | - $span_class = 'txn-overview-part-payment-spn'; |
|
285 | - if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
286 | - // paid in full |
|
287 | - $span_class = 'txn-overview-full-payment-spn'; |
|
288 | - } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
289 | - // no payments made |
|
290 | - $span_class = 'txn-overview-no-payment-spn'; |
|
291 | - } |
|
292 | - } else { |
|
293 | - $span_class = 'txn-overview-free-event-spn'; |
|
294 | - $transaction_paid = 0; |
|
295 | - } |
|
296 | - |
|
297 | - $payment_method = $transaction->payment_method(); |
|
298 | - $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
299 | - ? $payment_method->admin_name() |
|
300 | - : esc_html__('Unknown', 'event_espresso'); |
|
301 | - $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; |
|
302 | - |
|
303 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
304 | - . $transaction_paid_content |
|
305 | - . '</span>'; |
|
306 | - if ($transaction_paid > 0) { |
|
307 | - $content .= '<br><span class="ee-status-text-small">' |
|
308 | - . sprintf( |
|
309 | - esc_html__('...via %s', 'event_espresso'), |
|
310 | - $payment_method_name |
|
311 | - ) |
|
312 | - . '</span>'; |
|
313 | - } |
|
314 | - return $content; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * column_ATT_fname |
|
320 | - * |
|
321 | - * @param \EE_Transaction $transaction |
|
322 | - * @return string |
|
323 | - * @throws EE_Error |
|
324 | - * @throws InvalidArgumentException |
|
325 | - * @throws InvalidDataTypeException |
|
326 | - * @throws InvalidInterfaceException |
|
327 | - */ |
|
328 | - public function column_ATT_fname(EE_Transaction $transaction) |
|
329 | - { |
|
330 | - $primary_reg = $transaction->primary_registration(); |
|
331 | - $attendee = $primary_reg->get_first_related('Attendee'); |
|
332 | - if ($attendee instanceof EE_Attendee) { |
|
333 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
334 | - 'action' => 'view_registration', |
|
335 | - '_REG_ID' => $primary_reg->ID(), |
|
336 | - ), REG_ADMIN_URL); |
|
337 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
338 | - 'ee_read_registration', |
|
339 | - 'espresso_registrations_view_registration', |
|
340 | - $primary_reg->ID() |
|
341 | - ) |
|
342 | - ? '<a href="' . $edit_lnk_url . '"' |
|
343 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
344 | - . $attendee->full_name() |
|
345 | - . '</a>' |
|
346 | - : $attendee->full_name(); |
|
347 | - $content .= '<br>' . $attendee->email(); |
|
348 | - return $content; |
|
349 | - } |
|
350 | - return $transaction->failed() || $transaction->is_abandoned() |
|
351 | - ? esc_html__('no contact record.', 'event_espresso') |
|
352 | - : esc_html__( |
|
353 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
354 | - 'event_espresso' |
|
355 | - ); |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * column_ATT_email |
|
361 | - * |
|
362 | - * @param \EE_Transaction $transaction |
|
363 | - * @return string |
|
364 | - * @throws \EE_Error |
|
365 | - */ |
|
366 | - public function column_ATT_email(EE_Transaction $transaction) |
|
367 | - { |
|
368 | - $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
369 | - if (! empty($attendee)) { |
|
370 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
371 | - . $attendee->get('ATT_email') |
|
372 | - . '</a>'; |
|
373 | - } else { |
|
374 | - return $transaction->failed() || $transaction->is_abandoned() |
|
375 | - ? esc_html__('no contact record.', 'event_espresso') |
|
376 | - : esc_html__( |
|
377 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
378 | - 'event_espresso' |
|
379 | - ); |
|
380 | - } |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * column_event_name |
|
386 | - * |
|
387 | - * @param \EE_Transaction $transaction |
|
388 | - * @return string |
|
389 | - * @throws EE_Error |
|
390 | - * @throws InvalidArgumentException |
|
391 | - * @throws InvalidDataTypeException |
|
392 | - * @throws InvalidInterfaceException |
|
393 | - */ |
|
394 | - public function column_event_name(EE_Transaction $transaction) |
|
395 | - { |
|
396 | - $actions = array(); |
|
397 | - $event = $transaction->primary_registration()->get_first_related('Event'); |
|
398 | - if (! empty($event)) { |
|
399 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
400 | - array('action' => 'edit', 'post' => $event->ID()), |
|
401 | - EVENTS_ADMIN_URL |
|
402 | - ); |
|
403 | - $event_name = $event->get('EVT_name'); |
|
404 | - |
|
405 | - //filter this view by transactions for this event |
|
406 | - $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
|
407 | - 'action' => 'default', |
|
408 | - 'EVT_ID' => $event->ID(), |
|
409 | - )); |
|
410 | - if (empty($this->_req_data['EVT_ID']) |
|
411 | - && EE_Registry::instance()->CAP->current_user_can( |
|
412 | - 'ee_edit_event', |
|
413 | - 'espresso_events_edit', |
|
414 | - $event->ID() |
|
415 | - ) |
|
416 | - ) { |
|
417 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
418 | - . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' |
|
419 | - . esc_html__('View Transactions for this event', 'event_espresso') |
|
420 | - . '</a>'; |
|
421 | - } |
|
422 | - |
|
423 | - return sprintf( |
|
424 | - '%1$s %2$s', |
|
425 | - EE_Registry::instance()->CAP->current_user_can( |
|
426 | - 'ee_edit_event', |
|
427 | - 'espresso_events_edit', |
|
428 | - $event->ID() |
|
429 | - ) |
|
430 | - ? '<a href="' . $edit_event_url . '"' |
|
431 | - . ' title="' |
|
432 | - . sprintf( |
|
433 | - esc_attr__('Edit Event: %s', 'event_espresso'), |
|
434 | - $event->get('EVT_name') |
|
435 | - ) |
|
436 | - . '">' |
|
437 | - . wp_trim_words( |
|
438 | - $event_name, |
|
439 | - 30, |
|
440 | - '...' |
|
441 | - ) |
|
442 | - . '</a>' |
|
443 | - : wp_trim_words($event_name, 30, '...'), |
|
444 | - $this->row_actions($actions) |
|
445 | - ); |
|
446 | - } else { |
|
447 | - return esc_html__( |
|
448 | - 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
449 | - 'event_espresso' |
|
450 | - ); |
|
451 | - } |
|
452 | - } |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * column_actions |
|
457 | - * |
|
458 | - * @param \EE_Transaction $transaction |
|
459 | - * @return string |
|
460 | - * @throws \EE_Error |
|
461 | - */ |
|
462 | - public function column_actions(EE_Transaction $transaction) |
|
463 | - { |
|
464 | - return $this->_action_string( |
|
465 | - $this->get_transaction_details_link($transaction) |
|
466 | - . $this->get_invoice_link($transaction) |
|
467 | - . $this->get_receipt_link($transaction) |
|
468 | - . $this->get_primary_registration_details_link($transaction) |
|
469 | - . $this->get_send_payment_reminder_trigger_link($transaction) |
|
470 | - . $this->get_payment_overview_link($transaction) |
|
471 | - . $this->get_related_messages_link($transaction), |
|
472 | - $transaction, |
|
473 | - 'ul', |
|
474 | - 'txn-overview-actions-ul' |
|
475 | - ); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Get the transaction details link. |
|
481 | - * @param EE_Transaction $transaction |
|
482 | - * @return string |
|
483 | - * @throws EE_Error |
|
484 | - */ |
|
485 | - protected function get_transaction_details_link(EE_Transaction $transaction) |
|
486 | - { |
|
487 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
488 | - 'action' => 'view_transaction', |
|
489 | - 'TXN_ID' => $transaction->ID(), |
|
490 | - ), TXN_ADMIN_URL); |
|
491 | - return ' |
|
134 | + $filters[] = ob_get_contents(); |
|
135 | + ob_end_clean(); |
|
136 | + return $filters; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + *_add_view_counts |
|
142 | + */ |
|
143 | + protected function _add_view_counts() |
|
144 | + { |
|
145 | + $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); |
|
146 | + $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); |
|
147 | + $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * column TXN_ID |
|
153 | + * |
|
154 | + * @param \EE_Transaction $transaction |
|
155 | + * @return string |
|
156 | + * @throws \EE_Error |
|
157 | + */ |
|
158 | + public function column_TXN_ID(EE_Transaction $transaction) |
|
159 | + { |
|
160 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
161 | + 'action' => 'view_transaction', |
|
162 | + 'TXN_ID' => $transaction->ID(), |
|
163 | + ), TXN_ADMIN_URL); |
|
164 | + $content = '<a href="' . $view_lnk_url . '"' |
|
165 | + . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
166 | + . $transaction->ID() |
|
167 | + . '</a>'; |
|
168 | + |
|
169 | + //txn timestamp |
|
170 | + $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
171 | + return $content; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param \EE_Transaction $transaction |
|
177 | + * @return string |
|
178 | + * @throws EE_Error |
|
179 | + * @throws InvalidArgumentException |
|
180 | + * @throws InvalidDataTypeException |
|
181 | + * @throws InvalidInterfaceException |
|
182 | + */ |
|
183 | + protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
184 | + { |
|
185 | + //txn timestamp |
|
186 | + // is TXN less than 2 hours old ? |
|
187 | + if (($transaction->failed() || $transaction->is_abandoned()) |
|
188 | + && ( |
|
189 | + (time() - EE_Registry::instance()->SSN->lifespan()) < $transaction->datetime(false, true) |
|
190 | + ) |
|
191 | + ) { |
|
192 | + $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
193 | + } else { |
|
194 | + $timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); |
|
195 | + } |
|
196 | + return $timestamp; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * column_cb |
|
202 | + * |
|
203 | + * @param \EE_Transaction $transaction |
|
204 | + * @return string |
|
205 | + * @throws \EE_Error |
|
206 | + */ |
|
207 | + public function column_cb($transaction) |
|
208 | + { |
|
209 | + return sprintf( |
|
210 | + '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
211 | + $this->_wp_list_args['singular'], |
|
212 | + $transaction->ID() |
|
213 | + ); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * column_TXN_timestamp |
|
219 | + * |
|
220 | + * @param \EE_Transaction $transaction |
|
221 | + * @return string |
|
222 | + * @throws \EE_Error |
|
223 | + */ |
|
224 | + public function column_TXN_timestamp(EE_Transaction $transaction) |
|
225 | + { |
|
226 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
227 | + 'action' => 'view_transaction', |
|
228 | + 'TXN_ID' => $transaction->ID(), |
|
229 | + ), TXN_ADMIN_URL); |
|
230 | + $txn_date = '<a href="' . $view_lnk_url . '"' |
|
231 | + . ' title="' |
|
232 | + . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
233 | + . $this->_get_txn_timestamp($transaction) |
|
234 | + . '</a>'; |
|
235 | + //status |
|
236 | + $txn_date .= '<br><span class="ee-status-text-small">' |
|
237 | + . EEH_Template::pretty_status( |
|
238 | + $transaction->status_ID(), |
|
239 | + false, |
|
240 | + 'sentence' |
|
241 | + ) |
|
242 | + . '</span>'; |
|
243 | + return $txn_date; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * column_TXN_total |
|
249 | + * |
|
250 | + * @param \EE_Transaction $transaction |
|
251 | + * @return string |
|
252 | + * @throws \EE_Error |
|
253 | + */ |
|
254 | + public function column_TXN_total(EE_Transaction $transaction) |
|
255 | + { |
|
256 | + if ($transaction->get('TXN_total') > 0) { |
|
257 | + return '<span class="txn-pad-rght">' |
|
258 | + . apply_filters( |
|
259 | + 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
260 | + $transaction->get_pretty('TXN_total'), |
|
261 | + $transaction |
|
262 | + ) |
|
263 | + . '</span>'; |
|
264 | + } else { |
|
265 | + return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * column_TXN_paid |
|
272 | + * |
|
273 | + * @param \EE_Transaction $transaction |
|
274 | + * @return mixed|string |
|
275 | + * @throws \EE_Error |
|
276 | + */ |
|
277 | + public function column_TXN_paid(EE_Transaction $transaction) |
|
278 | + { |
|
279 | + $transaction_total = $transaction->get('TXN_total'); |
|
280 | + $transaction_paid = $transaction->get('TXN_paid'); |
|
281 | + |
|
282 | + if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
283 | + // monies owing |
|
284 | + $span_class = 'txn-overview-part-payment-spn'; |
|
285 | + if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
286 | + // paid in full |
|
287 | + $span_class = 'txn-overview-full-payment-spn'; |
|
288 | + } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
289 | + // no payments made |
|
290 | + $span_class = 'txn-overview-no-payment-spn'; |
|
291 | + } |
|
292 | + } else { |
|
293 | + $span_class = 'txn-overview-free-event-spn'; |
|
294 | + $transaction_paid = 0; |
|
295 | + } |
|
296 | + |
|
297 | + $payment_method = $transaction->payment_method(); |
|
298 | + $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
299 | + ? $payment_method->admin_name() |
|
300 | + : esc_html__('Unknown', 'event_espresso'); |
|
301 | + $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; |
|
302 | + |
|
303 | + $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
304 | + . $transaction_paid_content |
|
305 | + . '</span>'; |
|
306 | + if ($transaction_paid > 0) { |
|
307 | + $content .= '<br><span class="ee-status-text-small">' |
|
308 | + . sprintf( |
|
309 | + esc_html__('...via %s', 'event_espresso'), |
|
310 | + $payment_method_name |
|
311 | + ) |
|
312 | + . '</span>'; |
|
313 | + } |
|
314 | + return $content; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * column_ATT_fname |
|
320 | + * |
|
321 | + * @param \EE_Transaction $transaction |
|
322 | + * @return string |
|
323 | + * @throws EE_Error |
|
324 | + * @throws InvalidArgumentException |
|
325 | + * @throws InvalidDataTypeException |
|
326 | + * @throws InvalidInterfaceException |
|
327 | + */ |
|
328 | + public function column_ATT_fname(EE_Transaction $transaction) |
|
329 | + { |
|
330 | + $primary_reg = $transaction->primary_registration(); |
|
331 | + $attendee = $primary_reg->get_first_related('Attendee'); |
|
332 | + if ($attendee instanceof EE_Attendee) { |
|
333 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
334 | + 'action' => 'view_registration', |
|
335 | + '_REG_ID' => $primary_reg->ID(), |
|
336 | + ), REG_ADMIN_URL); |
|
337 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
338 | + 'ee_read_registration', |
|
339 | + 'espresso_registrations_view_registration', |
|
340 | + $primary_reg->ID() |
|
341 | + ) |
|
342 | + ? '<a href="' . $edit_lnk_url . '"' |
|
343 | + . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
344 | + . $attendee->full_name() |
|
345 | + . '</a>' |
|
346 | + : $attendee->full_name(); |
|
347 | + $content .= '<br>' . $attendee->email(); |
|
348 | + return $content; |
|
349 | + } |
|
350 | + return $transaction->failed() || $transaction->is_abandoned() |
|
351 | + ? esc_html__('no contact record.', 'event_espresso') |
|
352 | + : esc_html__( |
|
353 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
354 | + 'event_espresso' |
|
355 | + ); |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * column_ATT_email |
|
361 | + * |
|
362 | + * @param \EE_Transaction $transaction |
|
363 | + * @return string |
|
364 | + * @throws \EE_Error |
|
365 | + */ |
|
366 | + public function column_ATT_email(EE_Transaction $transaction) |
|
367 | + { |
|
368 | + $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
369 | + if (! empty($attendee)) { |
|
370 | + return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
371 | + . $attendee->get('ATT_email') |
|
372 | + . '</a>'; |
|
373 | + } else { |
|
374 | + return $transaction->failed() || $transaction->is_abandoned() |
|
375 | + ? esc_html__('no contact record.', 'event_espresso') |
|
376 | + : esc_html__( |
|
377 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
378 | + 'event_espresso' |
|
379 | + ); |
|
380 | + } |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * column_event_name |
|
386 | + * |
|
387 | + * @param \EE_Transaction $transaction |
|
388 | + * @return string |
|
389 | + * @throws EE_Error |
|
390 | + * @throws InvalidArgumentException |
|
391 | + * @throws InvalidDataTypeException |
|
392 | + * @throws InvalidInterfaceException |
|
393 | + */ |
|
394 | + public function column_event_name(EE_Transaction $transaction) |
|
395 | + { |
|
396 | + $actions = array(); |
|
397 | + $event = $transaction->primary_registration()->get_first_related('Event'); |
|
398 | + if (! empty($event)) { |
|
399 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
400 | + array('action' => 'edit', 'post' => $event->ID()), |
|
401 | + EVENTS_ADMIN_URL |
|
402 | + ); |
|
403 | + $event_name = $event->get('EVT_name'); |
|
404 | + |
|
405 | + //filter this view by transactions for this event |
|
406 | + $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
|
407 | + 'action' => 'default', |
|
408 | + 'EVT_ID' => $event->ID(), |
|
409 | + )); |
|
410 | + if (empty($this->_req_data['EVT_ID']) |
|
411 | + && EE_Registry::instance()->CAP->current_user_can( |
|
412 | + 'ee_edit_event', |
|
413 | + 'espresso_events_edit', |
|
414 | + $event->ID() |
|
415 | + ) |
|
416 | + ) { |
|
417 | + $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
418 | + . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' |
|
419 | + . esc_html__('View Transactions for this event', 'event_espresso') |
|
420 | + . '</a>'; |
|
421 | + } |
|
422 | + |
|
423 | + return sprintf( |
|
424 | + '%1$s %2$s', |
|
425 | + EE_Registry::instance()->CAP->current_user_can( |
|
426 | + 'ee_edit_event', |
|
427 | + 'espresso_events_edit', |
|
428 | + $event->ID() |
|
429 | + ) |
|
430 | + ? '<a href="' . $edit_event_url . '"' |
|
431 | + . ' title="' |
|
432 | + . sprintf( |
|
433 | + esc_attr__('Edit Event: %s', 'event_espresso'), |
|
434 | + $event->get('EVT_name') |
|
435 | + ) |
|
436 | + . '">' |
|
437 | + . wp_trim_words( |
|
438 | + $event_name, |
|
439 | + 30, |
|
440 | + '...' |
|
441 | + ) |
|
442 | + . '</a>' |
|
443 | + : wp_trim_words($event_name, 30, '...'), |
|
444 | + $this->row_actions($actions) |
|
445 | + ); |
|
446 | + } else { |
|
447 | + return esc_html__( |
|
448 | + 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
449 | + 'event_espresso' |
|
450 | + ); |
|
451 | + } |
|
452 | + } |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * column_actions |
|
457 | + * |
|
458 | + * @param \EE_Transaction $transaction |
|
459 | + * @return string |
|
460 | + * @throws \EE_Error |
|
461 | + */ |
|
462 | + public function column_actions(EE_Transaction $transaction) |
|
463 | + { |
|
464 | + return $this->_action_string( |
|
465 | + $this->get_transaction_details_link($transaction) |
|
466 | + . $this->get_invoice_link($transaction) |
|
467 | + . $this->get_receipt_link($transaction) |
|
468 | + . $this->get_primary_registration_details_link($transaction) |
|
469 | + . $this->get_send_payment_reminder_trigger_link($transaction) |
|
470 | + . $this->get_payment_overview_link($transaction) |
|
471 | + . $this->get_related_messages_link($transaction), |
|
472 | + $transaction, |
|
473 | + 'ul', |
|
474 | + 'txn-overview-actions-ul' |
|
475 | + ); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Get the transaction details link. |
|
481 | + * @param EE_Transaction $transaction |
|
482 | + * @return string |
|
483 | + * @throws EE_Error |
|
484 | + */ |
|
485 | + protected function get_transaction_details_link(EE_Transaction $transaction) |
|
486 | + { |
|
487 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
488 | + 'action' => 'view_transaction', |
|
489 | + 'TXN_ID' => $transaction->ID(), |
|
490 | + ), TXN_ADMIN_URL); |
|
491 | + return ' |
|
492 | 492 | <li> |
493 | 493 | <a href="' . $url . '"' |
494 | - . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
494 | + . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
495 | 495 | <span class="dashicons dashicons-cart"></span> |
496 | 496 | </a> |
497 | 497 | </li>'; |
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * Get the invoice link for the given registration. |
|
503 | - * @param EE_Transaction $transaction |
|
504 | - * @return string |
|
505 | - * @throws EE_Error |
|
506 | - */ |
|
507 | - protected function get_invoice_link(EE_Transaction $transaction) |
|
508 | - { |
|
509 | - $registration = $transaction->primary_registration(); |
|
510 | - if ($registration instanceof EE_Registration) { |
|
511 | - $url = $registration->invoice_url(); |
|
512 | - //only show invoice link if message type is active. |
|
513 | - if ($registration->attendee() instanceof EE_Attendee |
|
514 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
515 | - ) { |
|
516 | - return ' |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * Get the invoice link for the given registration. |
|
503 | + * @param EE_Transaction $transaction |
|
504 | + * @return string |
|
505 | + * @throws EE_Error |
|
506 | + */ |
|
507 | + protected function get_invoice_link(EE_Transaction $transaction) |
|
508 | + { |
|
509 | + $registration = $transaction->primary_registration(); |
|
510 | + if ($registration instanceof EE_Registration) { |
|
511 | + $url = $registration->invoice_url(); |
|
512 | + //only show invoice link if message type is active. |
|
513 | + if ($registration->attendee() instanceof EE_Attendee |
|
514 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
515 | + ) { |
|
516 | + return ' |
|
517 | 517 | <li> |
518 | 518 | <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
519 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
519 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
520 | 520 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
521 | 521 | </a> |
522 | 522 | </li>'; |
523 | - } |
|
524 | - } |
|
525 | - return ''; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * Get the receipt link for the transaction. |
|
531 | - * @param EE_Transaction $transaction |
|
532 | - * @return string |
|
533 | - * @throws EE_Error |
|
534 | - */ |
|
535 | - protected function get_receipt_link(EE_Transaction $transaction) |
|
536 | - { |
|
537 | - $registration = $transaction->primary_registration(); |
|
538 | - if ($registration instanceof EE_Registration) { |
|
539 | - $url = $registration->receipt_url(); |
|
540 | - //only show receipt link if message type is active. |
|
541 | - if ($registration->attendee() instanceof EE_Attendee |
|
542 | - && EEH_MSG_Template::is_mt_active('receipt')) { |
|
543 | - return ' |
|
523 | + } |
|
524 | + } |
|
525 | + return ''; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * Get the receipt link for the transaction. |
|
531 | + * @param EE_Transaction $transaction |
|
532 | + * @return string |
|
533 | + * @throws EE_Error |
|
534 | + */ |
|
535 | + protected function get_receipt_link(EE_Transaction $transaction) |
|
536 | + { |
|
537 | + $registration = $transaction->primary_registration(); |
|
538 | + if ($registration instanceof EE_Registration) { |
|
539 | + $url = $registration->receipt_url(); |
|
540 | + //only show receipt link if message type is active. |
|
541 | + if ($registration->attendee() instanceof EE_Attendee |
|
542 | + && EEH_MSG_Template::is_mt_active('receipt')) { |
|
543 | + return ' |
|
544 | 544 | <li> |
545 | 545 | <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
546 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
546 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
547 | 547 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> |
548 | 548 | </a> |
549 | 549 | </li>'; |
550 | - } |
|
551 | - } |
|
552 | - return ''; |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * Get the link to view the details for the primary registration. |
|
558 | - * |
|
559 | - * @param EE_Transaction $transaction |
|
560 | - * @return string |
|
561 | - * @throws EE_Error |
|
562 | - * @throws InvalidArgumentException |
|
563 | - * @throws InvalidDataTypeException |
|
564 | - * @throws InvalidInterfaceException |
|
565 | - */ |
|
566 | - protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
567 | - { |
|
568 | - $registration = $transaction->primary_registration(); |
|
569 | - if ($registration instanceof EE_Registration) { |
|
570 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
571 | - 'action' => 'view_registration', |
|
572 | - '_REG_ID' => $registration->ID(), |
|
573 | - ), REG_ADMIN_URL); |
|
574 | - return EE_Registry::instance()->CAP->current_user_can( |
|
575 | - 'ee_read_registration', |
|
576 | - 'espresso_registrations_view_registration', |
|
577 | - $registration->ID() |
|
578 | - ) |
|
579 | - ? ' |
|
550 | + } |
|
551 | + } |
|
552 | + return ''; |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * Get the link to view the details for the primary registration. |
|
558 | + * |
|
559 | + * @param EE_Transaction $transaction |
|
560 | + * @return string |
|
561 | + * @throws EE_Error |
|
562 | + * @throws InvalidArgumentException |
|
563 | + * @throws InvalidDataTypeException |
|
564 | + * @throws InvalidInterfaceException |
|
565 | + */ |
|
566 | + protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
567 | + { |
|
568 | + $registration = $transaction->primary_registration(); |
|
569 | + if ($registration instanceof EE_Registration) { |
|
570 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
571 | + 'action' => 'view_registration', |
|
572 | + '_REG_ID' => $registration->ID(), |
|
573 | + ), REG_ADMIN_URL); |
|
574 | + return EE_Registry::instance()->CAP->current_user_can( |
|
575 | + 'ee_read_registration', |
|
576 | + 'espresso_registrations_view_registration', |
|
577 | + $registration->ID() |
|
578 | + ) |
|
579 | + ? ' |
|
580 | 580 | <li> |
581 | 581 | <a href="' . $url . '"' |
582 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
582 | + . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
583 | 583 | <span class="dashicons dashicons-clipboard"></span> |
584 | 584 | </a> |
585 | 585 | </li>' |
586 | - : ''; |
|
587 | - } |
|
588 | - return ''; |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * Get send payment reminder trigger link |
|
594 | - * @param EE_Transaction $transaction |
|
595 | - * @return string |
|
596 | - * @throws EE_Error |
|
597 | - * @throws InvalidArgumentException |
|
598 | - * @throws InvalidDataTypeException |
|
599 | - * @throws InvalidInterfaceException |
|
600 | - */ |
|
601 | - protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
602 | - { |
|
603 | - $registration = $transaction->primary_registration(); |
|
604 | - if ($registration instanceof EE_Registration |
|
605 | - && $registration->attendee() instanceof EE_Attendee |
|
606 | - && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
607 | - && ! in_array( |
|
608 | - $transaction->status_ID(), |
|
609 | - array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
610 | - true |
|
611 | - ) |
|
612 | - && EE_Registry::instance()->CAP->current_user_can( |
|
613 | - 'ee_send_message', |
|
614 | - 'espresso_transactions_send_payment_reminder' |
|
615 | - ) |
|
616 | - ) { |
|
617 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
618 | - 'action' => 'send_payment_reminder', |
|
619 | - 'TXN_ID' => $transaction->ID(), |
|
620 | - ), TXN_ADMIN_URL); |
|
621 | - return ' |
|
586 | + : ''; |
|
587 | + } |
|
588 | + return ''; |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * Get send payment reminder trigger link |
|
594 | + * @param EE_Transaction $transaction |
|
595 | + * @return string |
|
596 | + * @throws EE_Error |
|
597 | + * @throws InvalidArgumentException |
|
598 | + * @throws InvalidDataTypeException |
|
599 | + * @throws InvalidInterfaceException |
|
600 | + */ |
|
601 | + protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
602 | + { |
|
603 | + $registration = $transaction->primary_registration(); |
|
604 | + if ($registration instanceof EE_Registration |
|
605 | + && $registration->attendee() instanceof EE_Attendee |
|
606 | + && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
607 | + && ! in_array( |
|
608 | + $transaction->status_ID(), |
|
609 | + array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
610 | + true |
|
611 | + ) |
|
612 | + && EE_Registry::instance()->CAP->current_user_can( |
|
613 | + 'ee_send_message', |
|
614 | + 'espresso_transactions_send_payment_reminder' |
|
615 | + ) |
|
616 | + ) { |
|
617 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
618 | + 'action' => 'send_payment_reminder', |
|
619 | + 'TXN_ID' => $transaction->ID(), |
|
620 | + ), TXN_ADMIN_URL); |
|
621 | + return ' |
|
622 | 622 | <li> |
623 | 623 | <a href="' . $url . '"' |
624 | - . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
624 | + . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
625 | 625 | <span class="dashicons dashicons-email-alt"></span> |
626 | 626 | </a> |
627 | 627 | </li>'; |
628 | - } |
|
629 | - return ''; |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * Get link to filtered view in the message activity list table of messages for this transaction. |
|
635 | - * @param EE_Transaction $transaction |
|
636 | - * @return string |
|
637 | - * @throws EE_Error |
|
638 | - * @throws InvalidArgumentException |
|
639 | - * @throws InvalidDataTypeException |
|
640 | - * @throws InvalidInterfaceException |
|
641 | - */ |
|
642 | - protected function get_related_messages_link(EE_Transaction $transaction) |
|
643 | - { |
|
644 | - $url = EEH_MSG_Template::get_message_action_link( |
|
645 | - 'see_notifications_for', |
|
646 | - null, |
|
647 | - array('TXN_ID' => $transaction->ID()) |
|
648 | - ); |
|
649 | - return EE_Registry::instance()->CAP->current_user_can( |
|
650 | - 'ee_read_global_messages', |
|
651 | - 'view_filtered_messages' |
|
652 | - ) |
|
653 | - ? '<li>' . $url . '</li>' |
|
654 | - : ''; |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * Return the link to make a payment on the frontend |
|
660 | - * @param EE_Transaction $transaction |
|
661 | - * @return string |
|
662 | - * @throws EE_Error |
|
663 | - */ |
|
664 | - protected function get_payment_overview_link(EE_Transaction $transaction) |
|
665 | - { |
|
666 | - $registration = $transaction->primary_registration(); |
|
667 | - if ($registration instanceof EE_Registration |
|
668 | - && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
669 | - && $registration->owes_monies_and_can_pay() |
|
670 | - ) { |
|
671 | - return ' |
|
628 | + } |
|
629 | + return ''; |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * Get link to filtered view in the message activity list table of messages for this transaction. |
|
635 | + * @param EE_Transaction $transaction |
|
636 | + * @return string |
|
637 | + * @throws EE_Error |
|
638 | + * @throws InvalidArgumentException |
|
639 | + * @throws InvalidDataTypeException |
|
640 | + * @throws InvalidInterfaceException |
|
641 | + */ |
|
642 | + protected function get_related_messages_link(EE_Transaction $transaction) |
|
643 | + { |
|
644 | + $url = EEH_MSG_Template::get_message_action_link( |
|
645 | + 'see_notifications_for', |
|
646 | + null, |
|
647 | + array('TXN_ID' => $transaction->ID()) |
|
648 | + ); |
|
649 | + return EE_Registry::instance()->CAP->current_user_can( |
|
650 | + 'ee_read_global_messages', |
|
651 | + 'view_filtered_messages' |
|
652 | + ) |
|
653 | + ? '<li>' . $url . '</li>' |
|
654 | + : ''; |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * Return the link to make a payment on the frontend |
|
660 | + * @param EE_Transaction $transaction |
|
661 | + * @return string |
|
662 | + * @throws EE_Error |
|
663 | + */ |
|
664 | + protected function get_payment_overview_link(EE_Transaction $transaction) |
|
665 | + { |
|
666 | + $registration = $transaction->primary_registration(); |
|
667 | + if ($registration instanceof EE_Registration |
|
668 | + && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
669 | + && $registration->owes_monies_and_can_pay() |
|
670 | + ) { |
|
671 | + return ' |
|
672 | 672 | <li> |
673 | 673 | <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
674 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
675 | - . ' class="tiny-text"> |
|
674 | + . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
675 | + . ' class="tiny-text"> |
|
676 | 676 | <span class="dashicons dashicons-money ee-icon-size-18"></span> |
677 | 677 | </a> |
678 | 678 | </li> |
679 | 679 | '; |
680 | 680 | |
681 | - } |
|
682 | - return ''; |
|
683 | - } |
|
681 | + } |
|
682 | + return ''; |
|
683 | + } |
|
684 | 684 | } |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | 'ajax' => true, |
52 | 52 | 'screen' => $this->_admin_page->get_current_screen()->id, |
53 | 53 | ); |
54 | - $ID_column_name = __('ID', 'event_espresso'); |
|
54 | + $ID_column_name = __('ID', 'event_espresso'); |
|
55 | 55 | $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
56 | 56 | $ID_column_name .= __('Transaction Date', 'event_espresso'); |
57 | 57 | $ID_column_name .= '</span> '; |
58 | - $this->_columns = array( |
|
58 | + $this->_columns = array( |
|
59 | 59 | 'TXN_ID' => $ID_column_name, |
60 | 60 | 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
61 | 61 | 'TXN_total' => __('Total', 'event_espresso'), |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | { |
91 | 91 | $class = parent::_get_row_class($transaction); |
92 | 92 | //add status class |
93 | - $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
93 | + $class .= ' ee-status-strip txn-status-'.$transaction->status_ID(); |
|
94 | 94 | if ($this->_has_checkbox_column) { |
95 | 95 | $class .= ' has-checkbox-column'; |
96 | 96 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | 'm/d/Y', |
117 | 117 | strtotime('-10 year') |
118 | 118 | ); |
119 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
119 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
120 | 120 | ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
121 | 121 | : date( |
122 | 122 | 'm/d/Y', |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | 'action' => 'view_transaction', |
162 | 162 | 'TXN_ID' => $transaction->ID(), |
163 | 163 | ), TXN_ADMIN_URL); |
164 | - $content = '<a href="' . $view_lnk_url . '"' |
|
165 | - . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
164 | + $content = '<a href="'.$view_lnk_url.'"' |
|
165 | + . ' title="'.esc_attr__('Go to Transaction Details', 'event_espresso').'">' |
|
166 | 166 | . $transaction->ID() |
167 | 167 | . '</a>'; |
168 | 168 | |
169 | 169 | //txn timestamp |
170 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
170 | + $content .= ' <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>'; |
|
171 | 171 | return $content; |
172 | 172 | } |
173 | 173 | |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | 'action' => 'view_transaction', |
228 | 228 | 'TXN_ID' => $transaction->ID(), |
229 | 229 | ), TXN_ADMIN_URL); |
230 | - $txn_date = '<a href="' . $view_lnk_url . '"' |
|
230 | + $txn_date = '<a href="'.$view_lnk_url.'"' |
|
231 | 231 | . ' title="' |
232 | - . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
232 | + . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID().'">' |
|
233 | 233 | . $this->_get_txn_timestamp($transaction) |
234 | 234 | . '</a>'; |
235 | 235 | //status |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | ) |
263 | 263 | . '</span>'; |
264 | 264 | } else { |
265 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
265 | + return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>'; |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | : esc_html__('Unknown', 'event_espresso'); |
301 | 301 | $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; |
302 | 302 | |
303 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
303 | + $content = '<span class="'.$span_class.' txn-pad-rght">' |
|
304 | 304 | . $transaction_paid_content |
305 | 305 | . '</span>'; |
306 | 306 | if ($transaction_paid > 0) { |
@@ -334,17 +334,17 @@ discard block |
||
334 | 334 | 'action' => 'view_registration', |
335 | 335 | '_REG_ID' => $primary_reg->ID(), |
336 | 336 | ), REG_ADMIN_URL); |
337 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
337 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
338 | 338 | 'ee_read_registration', |
339 | 339 | 'espresso_registrations_view_registration', |
340 | 340 | $primary_reg->ID() |
341 | 341 | ) |
342 | - ? '<a href="' . $edit_lnk_url . '"' |
|
343 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
342 | + ? '<a href="'.$edit_lnk_url.'"' |
|
343 | + . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
344 | 344 | . $attendee->full_name() |
345 | 345 | . '</a>' |
346 | 346 | : $attendee->full_name(); |
347 | - $content .= '<br>' . $attendee->email(); |
|
347 | + $content .= '<br>'.$attendee->email(); |
|
348 | 348 | return $content; |
349 | 349 | } |
350 | 350 | return $transaction->failed() || $transaction->is_abandoned() |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | public function column_ATT_email(EE_Transaction $transaction) |
367 | 367 | { |
368 | 368 | $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
369 | - if (! empty($attendee)) { |
|
370 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
369 | + if ( ! empty($attendee)) { |
|
370 | + return '<a href="mailto:'.$attendee->get('ATT_email').'">' |
|
371 | 371 | . $attendee->get('ATT_email') |
372 | 372 | . '</a>'; |
373 | 373 | } else { |
@@ -395,12 +395,12 @@ discard block |
||
395 | 395 | { |
396 | 396 | $actions = array(); |
397 | 397 | $event = $transaction->primary_registration()->get_first_related('Event'); |
398 | - if (! empty($event)) { |
|
398 | + if ( ! empty($event)) { |
|
399 | 399 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
400 | 400 | array('action' => 'edit', 'post' => $event->ID()), |
401 | 401 | EVENTS_ADMIN_URL |
402 | 402 | ); |
403 | - $event_name = $event->get('EVT_name'); |
|
403 | + $event_name = $event->get('EVT_name'); |
|
404 | 404 | |
405 | 405 | //filter this view by transactions for this event |
406 | 406 | $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | $event->ID() |
415 | 415 | ) |
416 | 416 | ) { |
417 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
418 | - . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' |
|
417 | + $actions['filter_by_event'] = '<a href="'.$txn_by_event_lnk.'"' |
|
418 | + . ' title="'.esc_attr__('Filter transactions by this event', 'event_espresso').'">' |
|
419 | 419 | . esc_html__('View Transactions for this event', 'event_espresso') |
420 | 420 | . '</a>'; |
421 | 421 | } |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | 'espresso_events_edit', |
428 | 428 | $event->ID() |
429 | 429 | ) |
430 | - ? '<a href="' . $edit_event_url . '"' |
|
430 | + ? '<a href="'.$edit_event_url.'"' |
|
431 | 431 | . ' title="' |
432 | 432 | . sprintf( |
433 | 433 | esc_attr__('Edit Event: %s', 'event_espresso'), |
@@ -484,14 +484,14 @@ discard block |
||
484 | 484 | */ |
485 | 485 | protected function get_transaction_details_link(EE_Transaction $transaction) |
486 | 486 | { |
487 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
487 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
488 | 488 | 'action' => 'view_transaction', |
489 | 489 | 'TXN_ID' => $transaction->ID(), |
490 | 490 | ), TXN_ADMIN_URL); |
491 | 491 | return ' |
492 | 492 | <li> |
493 | - <a href="' . $url . '"' |
|
494 | - . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
493 | + <a href="' . $url.'"' |
|
494 | + . ' title="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="tiny-text"> |
|
495 | 495 | <span class="dashicons dashicons-cart"></span> |
496 | 496 | </a> |
497 | 497 | </li>'; |
@@ -515,8 +515,8 @@ discard block |
||
515 | 515 | ) { |
516 | 516 | return ' |
517 | 517 | <li> |
518 | - <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
|
519 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
518 | + <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"' |
|
519 | + . ' target="_blank" href="'.$url.'" class="tiny-text"> |
|
520 | 520 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
521 | 521 | </a> |
522 | 522 | </li>'; |
@@ -542,8 +542,8 @@ discard block |
||
542 | 542 | && EEH_MSG_Template::is_mt_active('receipt')) { |
543 | 543 | return ' |
544 | 544 | <li> |
545 | - <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
|
546 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
545 | + <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"' |
|
546 | + . ' target="_blank" href="'.$url.'" class="tiny-text"> |
|
547 | 547 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> |
548 | 548 | </a> |
549 | 549 | </li>'; |
@@ -578,8 +578,8 @@ discard block |
||
578 | 578 | ) |
579 | 579 | ? ' |
580 | 580 | <li> |
581 | - <a href="' . $url . '"' |
|
582 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
581 | + <a href="' . $url.'"' |
|
582 | + . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text"> |
|
583 | 583 | <span class="dashicons dashicons-clipboard"></span> |
584 | 584 | </a> |
585 | 585 | </li>' |
@@ -620,8 +620,8 @@ discard block |
||
620 | 620 | ), TXN_ADMIN_URL); |
621 | 621 | return ' |
622 | 622 | <li> |
623 | - <a href="' . $url . '"' |
|
624 | - . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
623 | + <a href="' . $url.'"' |
|
624 | + . ' title="'.esc_attr__('Send Payment Reminder', 'event_espresso').'" class="tiny-text"> |
|
625 | 625 | <span class="dashicons dashicons-email-alt"></span> |
626 | 626 | </a> |
627 | 627 | </li>'; |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | 'ee_read_global_messages', |
651 | 651 | 'view_filtered_messages' |
652 | 652 | ) |
653 | - ? '<li>' . $url . '</li>' |
|
653 | + ? '<li>'.$url.'</li>' |
|
654 | 654 | : ''; |
655 | 655 | } |
656 | 656 | |
@@ -670,8 +670,8 @@ discard block |
||
670 | 670 | ) { |
671 | 671 | return ' |
672 | 672 | <li> |
673 | - <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
|
674 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
673 | + <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"' |
|
674 | + . ' target="_blank" href="'.$registration->payment_overview_url(true).'"' |
|
675 | 675 | . ' class="tiny-text"> |
676 | 676 | <span class="dashicons dashicons-money ee-icon-size-18"></span> |
677 | 677 | </a> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -22,975 +22,975 @@ discard block |
||
22 | 22 | class EED_Ticket_Sales_Monitor extends EED_Module |
23 | 23 | { |
24 | 24 | |
25 | - const debug = false; // true false |
|
26 | - |
|
27 | - /** |
|
28 | - * an array of raw ticket data from EED_Ticket_Selector |
|
29 | - * |
|
30 | - * @var array $ticket_selections |
|
31 | - */ |
|
32 | - protected $ticket_selections = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | - * according to how they are displayed in the actual Ticket_Selector |
|
37 | - * this tracks the current row being processed |
|
38 | - * |
|
39 | - * @var int $current_row |
|
40 | - */ |
|
41 | - protected $current_row = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * an array for tracking names of tickets that have sold out |
|
45 | - * |
|
46 | - * @var array $sold_out_tickets |
|
47 | - */ |
|
48 | - protected $sold_out_tickets = array(); |
|
49 | - |
|
50 | - /** |
|
51 | - * an array for tracking names of tickets that have had their quantities reduced |
|
52 | - * |
|
53 | - * @var array $decremented_tickets |
|
54 | - */ |
|
55 | - protected $decremented_tickets = array(); |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public static function set_hooks() |
|
65 | - { |
|
66 | - // release tickets for expired carts |
|
67 | - add_action( |
|
68 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | - 1 |
|
71 | - ); |
|
72 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | - add_filter( |
|
74 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | - 20, |
|
77 | - 3 |
|
78 | - ); |
|
79 | - // add notices for sold out tickets |
|
80 | - add_action( |
|
81 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | - 10 |
|
84 | - ); |
|
85 | - // handle ticket quantities adjusted in cart |
|
86 | - //add_action( |
|
87 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
88 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
89 | - // 10, 2 |
|
90 | - //); |
|
91 | - // handle tickets deleted from cart |
|
92 | - add_action( |
|
93 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
94 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
95 | - 10, |
|
96 | - 2 |
|
97 | - ); |
|
98 | - // handle emptied carts |
|
99 | - add_action( |
|
100 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
101 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
102 | - 10, |
|
103 | - 1 |
|
104 | - ); |
|
105 | - add_action( |
|
106 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
107 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
108 | - 10, |
|
109 | - 1 |
|
110 | - ); |
|
111 | - // handle cancelled registrations |
|
112 | - add_action( |
|
113 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
114 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
115 | - 10, |
|
116 | - 1 |
|
117 | - ); |
|
118 | - // cron tasks |
|
119 | - add_action( |
|
120 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
121 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
122 | - 10, |
|
123 | - 1 |
|
124 | - ); |
|
125 | - add_action( |
|
126 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
127 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
128 | - 10, |
|
129 | - 1 |
|
130 | - ); |
|
131 | - add_action( |
|
132 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
133 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
134 | - 10, |
|
135 | - 1 |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public static function set_hooks_admin() |
|
147 | - { |
|
148 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
155 | - */ |
|
156 | - public static function instance() |
|
157 | - { |
|
158 | - return parent::get_instance(__CLASS__); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param WP_Query $WP_Query |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function run($WP_Query) |
|
168 | - { |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Retrieves grand totals from the line items that have no TXN ID |
|
179 | - * and timestamps less than the current time minus the session lifespan. |
|
180 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
181 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
182 | - * |
|
183 | - * @return void |
|
184 | - * @throws EE_Error |
|
185 | - * @throws InvalidArgumentException |
|
186 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
187 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
188 | - */ |
|
189 | - public static function release_tickets_for_expired_carts() |
|
190 | - { |
|
191 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
192 | - $expired_ticket_IDs = array(); |
|
193 | - $valid_ticket_line_items = array(); |
|
194 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
195 | - if (empty($total_line_items)) { |
|
196 | - do_action( |
|
197 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
198 | - $total_line_items, |
|
199 | - $valid_ticket_line_items, |
|
200 | - $expired_ticket_IDs |
|
201 | - ); |
|
202 | - return; |
|
203 | - } |
|
204 | - $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
205 | - foreach ($total_line_items as $total_line_item) { |
|
206 | - /** @var EE_Line_Item $total_line_item */ |
|
207 | - $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
208 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
209 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
210 | - continue; |
|
211 | - } |
|
212 | - if ($total_line_item->timestamp(true) <= $expired) { |
|
213 | - $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
214 | - } else { |
|
215 | - $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
216 | - } |
|
217 | - } |
|
218 | - } |
|
219 | - if (! empty($expired_ticket_IDs)) { |
|
220 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
221 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
222 | - $valid_ticket_line_items |
|
223 | - ); |
|
224 | - // let's get rid of expired line items so that they can't interfere with tracking |
|
225 | - add_action( |
|
226 | - 'shutdown', |
|
227 | - array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
228 | - 999 |
|
229 | - ); |
|
230 | - } |
|
231 | - do_action( |
|
232 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
233 | - $total_line_items, |
|
234 | - $valid_ticket_line_items, |
|
235 | - $expired_ticket_IDs |
|
236 | - ); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
247 | - * |
|
248 | - * @param int $qty |
|
249 | - * @param EE_Ticket $ticket |
|
250 | - * @return bool |
|
251 | - * @throws UnexpectedEntityException |
|
252 | - * @throws EE_Error |
|
253 | - */ |
|
254 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
255 | - { |
|
256 | - $qty = absint($qty); |
|
257 | - if ($qty > 0) { |
|
258 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
259 | - } |
|
260 | - if (self::debug) { |
|
261 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
262 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
263 | - } |
|
264 | - return $qty; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
271 | - * |
|
272 | - * @param EE_Ticket $ticket |
|
273 | - * @param int $qty |
|
274 | - * @return int |
|
275 | - * @throws UnexpectedEntityException |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
279 | - { |
|
280 | - if (self::debug) { |
|
281 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
282 | - } |
|
283 | - if (! $ticket instanceof EE_Ticket) { |
|
284 | - return 0; |
|
285 | - } |
|
286 | - if (self::debug) { |
|
287 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
288 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
289 | - } |
|
290 | - $ticket->refresh_from_db(); |
|
291 | - // first let's determine the ticket availability based on sales |
|
292 | - $available = $ticket->qty('saleable'); |
|
293 | - if (self::debug) { |
|
294 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
295 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
296 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
297 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
298 | - echo '<br /> . . . available: ' . $available; |
|
299 | - } |
|
300 | - if ($available < 1) { |
|
301 | - $this->_ticket_sold_out($ticket); |
|
302 | - return 0; |
|
303 | - } |
|
304 | - if (self::debug) { |
|
305 | - echo '<br /> . . . qty: ' . $qty; |
|
306 | - } |
|
307 | - if ($available < $qty) { |
|
308 | - $qty = $available; |
|
309 | - if (self::debug) { |
|
310 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
311 | - } |
|
312 | - $this->_ticket_quantity_decremented($ticket); |
|
313 | - } |
|
314 | - $this->_reserve_ticket($ticket, $qty); |
|
315 | - return $qty; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * increments ticket reserved based on quantity passed |
|
322 | - * |
|
323 | - * @param EE_Ticket $ticket |
|
324 | - * @param int $quantity |
|
325 | - * @return bool |
|
326 | - * @throws EE_Error |
|
327 | - */ |
|
328 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
329 | - { |
|
330 | - if (self::debug) { |
|
331 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
332 | - } |
|
333 | - $ticket->increase_reserved($quantity); |
|
334 | - return $ticket->save(); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @param EE_Ticket $ticket |
|
341 | - * @param int $quantity |
|
342 | - * @return bool |
|
343 | - * @throws EE_Error |
|
344 | - */ |
|
345 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
346 | - { |
|
347 | - if (self::debug) { |
|
348 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
349 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
350 | - } |
|
351 | - $ticket->decrease_reserved($quantity); |
|
352 | - if (self::debug) { |
|
353 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
354 | - } |
|
355 | - return $ticket->save() ? 1 : 0; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * removes quantities within the ticket selector based on zero ticket availability |
|
362 | - * |
|
363 | - * @param EE_Ticket $ticket |
|
364 | - * @return void |
|
365 | - * @throws UnexpectedEntityException |
|
366 | - * @throws EE_Error |
|
367 | - */ |
|
368 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
369 | - { |
|
370 | - if (self::debug) { |
|
371 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
372 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
373 | - } |
|
374 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
381 | - * |
|
382 | - * @param EE_Ticket $ticket |
|
383 | - * @return void |
|
384 | - * @throws UnexpectedEntityException |
|
385 | - * @throws EE_Error |
|
386 | - */ |
|
387 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
388 | - { |
|
389 | - if (self::debug) { |
|
390 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
391 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
392 | - } |
|
393 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * builds string out of ticket and event name |
|
400 | - * |
|
401 | - * @param EE_Ticket $ticket |
|
402 | - * @return string |
|
403 | - * @throws UnexpectedEntityException |
|
404 | - * @throws EE_Error |
|
405 | - */ |
|
406 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
407 | - { |
|
408 | - $event = $ticket->get_related_event(); |
|
409 | - if ($event instanceof EE_Event) { |
|
410 | - $ticket_name = sprintf( |
|
411 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
412 | - $ticket->name(), |
|
413 | - $event->name() |
|
414 | - ); |
|
415 | - } else { |
|
416 | - $ticket_name = $ticket->name(); |
|
417 | - } |
|
418 | - return $ticket_name; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /********************************** EVENT CART **********************************/ |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * releases or reserves ticket(s) based on quantity passed |
|
429 | - * |
|
430 | - * @param EE_Line_Item $line_item |
|
431 | - * @param int $quantity |
|
432 | - * @return void |
|
433 | - * @throws EE_Error |
|
434 | - * @throws InvalidArgumentException |
|
435 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
436 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
437 | - */ |
|
438 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
439 | - { |
|
440 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
441 | - if ($ticket instanceof EE_Ticket) { |
|
442 | - if ($quantity > 0) { |
|
443 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
444 | - } else { |
|
445 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
446 | - } |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * releases reserved ticket(s) based on quantity passed |
|
454 | - * |
|
455 | - * @param EE_Ticket $ticket |
|
456 | - * @param int $quantity |
|
457 | - * @return void |
|
458 | - * @throws EE_Error |
|
459 | - */ |
|
460 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
461 | - { |
|
462 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /********************************** POST_NOTICES **********************************/ |
|
468 | - |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * @return void |
|
473 | - * @throws EE_Error |
|
474 | - * @throws InvalidArgumentException |
|
475 | - * @throws ReflectionException |
|
476 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
477 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
478 | - */ |
|
479 | - public static function post_notices() |
|
480 | - { |
|
481 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @return void |
|
488 | - * @throws EE_Error |
|
489 | - * @throws InvalidArgumentException |
|
490 | - * @throws ReflectionException |
|
491 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
492 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
493 | - */ |
|
494 | - protected function _post_notices() |
|
495 | - { |
|
496 | - if (self::debug) { |
|
497 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
498 | - } |
|
499 | - $refresh_msg = ''; |
|
500 | - $none_added_msg = ''; |
|
501 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
502 | - $refresh_msg = __( |
|
503 | - 'Please refresh the page to view updated ticket quantities.', |
|
504 | - 'event_espresso' |
|
505 | - ); |
|
506 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
507 | - } |
|
508 | - if (! empty($this->sold_out_tickets)) { |
|
509 | - EE_Error::add_attention( |
|
510 | - sprintf( |
|
511 | - apply_filters( |
|
512 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
513 | - __( |
|
514 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
515 | - 'event_espresso' |
|
516 | - ) |
|
517 | - ), |
|
518 | - '<br />', |
|
519 | - implode('<br />', $this->sold_out_tickets), |
|
520 | - $none_added_msg, |
|
521 | - $refresh_msg |
|
522 | - ) |
|
523 | - ); |
|
524 | - // alter code flow in the Ticket Selector for better UX |
|
525 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
526 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
527 | - $this->sold_out_tickets = array(); |
|
528 | - // and reset the cart |
|
529 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
530 | - } |
|
531 | - if (! empty($this->decremented_tickets)) { |
|
532 | - EE_Error::add_attention( |
|
533 | - sprintf( |
|
534 | - apply_filters( |
|
535 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
536 | - __( |
|
537 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
538 | - 'event_espresso' |
|
539 | - ) |
|
540 | - ), |
|
541 | - '<br />', |
|
542 | - implode('<br />', $this->decremented_tickets), |
|
543 | - $none_added_msg, |
|
544 | - $refresh_msg |
|
545 | - ) |
|
546 | - ); |
|
547 | - $this->decremented_tickets = array(); |
|
548 | - } |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - |
|
553 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
554 | - |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
559 | - * by default, will NOT release tickets for finalized transactions |
|
560 | - * |
|
561 | - * @param EE_Transaction $transaction |
|
562 | - * @return int |
|
563 | - * @throws EE_Error |
|
564 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
565 | - */ |
|
566 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
567 | - { |
|
568 | - if (self::debug) { |
|
569 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
570 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
571 | - } |
|
572 | - // check if 'finalize_registration' step has been completed... |
|
573 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
574 | - if (self::debug) { |
|
575 | - // DEBUG LOG |
|
576 | - EEH_Debug_Tools::log( |
|
577 | - __CLASS__, |
|
578 | - __FUNCTION__, |
|
579 | - __LINE__, |
|
580 | - array('finalized' => $finalized), |
|
581 | - false, |
|
582 | - 'EE_Transaction: ' . $transaction->ID() |
|
583 | - ); |
|
584 | - } |
|
585 | - // how many tickets were released |
|
586 | - $count = 0; |
|
587 | - if (self::debug) { |
|
588 | - echo '<br /> . . . finalized: ' . $finalized; |
|
589 | - } |
|
590 | - $release_tickets_with_TXN_status = array( |
|
591 | - EEM_Transaction::failed_status_code, |
|
592 | - EEM_Transaction::abandoned_status_code, |
|
593 | - EEM_Transaction::incomplete_status_code, |
|
594 | - ); |
|
595 | - // if the session is getting cleared BEFORE the TXN has been finalized |
|
596 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
597 | - // let's cancel any reserved tickets |
|
598 | - $registrations = $transaction->registrations(); |
|
599 | - if (! empty($registrations)) { |
|
600 | - foreach ($registrations as $registration) { |
|
601 | - if ($registration instanceof EE_Registration) { |
|
602 | - $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
603 | - } |
|
604 | - } |
|
605 | - } |
|
606 | - } |
|
607 | - return $count; |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * releases reserved tickets for an EE_Registration |
|
614 | - * by default, will NOT release tickets for APPROVED registrations |
|
615 | - * |
|
616 | - * @param EE_Registration $registration |
|
617 | - * @param EE_Transaction $transaction |
|
618 | - * @return int |
|
619 | - * @throws EE_Error |
|
620 | - */ |
|
621 | - protected function _release_reserved_ticket_for_registration( |
|
622 | - EE_Registration $registration, |
|
623 | - EE_Transaction $transaction |
|
624 | - ) { |
|
625 | - $STS_ID = $transaction->status_ID(); |
|
626 | - if (self::debug) { |
|
627 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
628 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
629 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
630 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
631 | - } |
|
632 | - if ( |
|
633 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
634 | - $STS_ID === EEM_Transaction::failed_status_code |
|
635 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
636 | - || ( |
|
637 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
638 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
639 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
640 | - ) |
|
641 | - ) { |
|
642 | - $ticket = $registration->ticket(); |
|
643 | - if ($ticket instanceof EE_Ticket) { |
|
644 | - return $this->_release_reserved_ticket($ticket); |
|
645 | - } |
|
646 | - } |
|
647 | - return 0; |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - |
|
652 | - /********************************** SESSION_CART_RESET **********************************/ |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
658 | - * |
|
659 | - * @param EE_Session $session |
|
660 | - * @return void |
|
661 | - * @throws EE_Error |
|
662 | - * @throws InvalidArgumentException |
|
663 | - * @throws ReflectionException |
|
664 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
665 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
666 | - */ |
|
667 | - public static function session_cart_reset(EE_Session $session) |
|
668 | - { |
|
669 | - if (self::debug) { |
|
670 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
671 | - } |
|
672 | - $cart = $session->cart(); |
|
673 | - if ($cart instanceof EE_Cart) { |
|
674 | - if (self::debug) { |
|
675 | - echo '<br /><br /> cart instance of EE_Cart: '; |
|
676 | - } |
|
677 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
678 | - } else { |
|
679 | - if (self::debug) { |
|
680 | - echo '<br /><br /> invalid EE_Cart: '; |
|
681 | - var_export($cart, true); |
|
682 | - } |
|
683 | - } |
|
684 | - } |
|
685 | - |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * releases reserved tickets in the EE_Cart |
|
690 | - * |
|
691 | - * @param EE_Cart $cart |
|
692 | - * @return void |
|
693 | - * @throws EE_Error |
|
694 | - * @throws InvalidArgumentException |
|
695 | - * @throws ReflectionException |
|
696 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
697 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
698 | - */ |
|
699 | - protected function _session_cart_reset(EE_Cart $cart) |
|
700 | - { |
|
701 | - if (self::debug) { |
|
702 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
703 | - } |
|
704 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
705 | - $ticket_line_items = $cart->get_tickets(); |
|
706 | - if (empty($ticket_line_items)) { |
|
707 | - return; |
|
708 | - } |
|
709 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
710 | - if (self::debug) { |
|
711 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
712 | - } |
|
713 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
714 | - if (self::debug) { |
|
715 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
716 | - } |
|
717 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
718 | - if ($ticket instanceof EE_Ticket) { |
|
719 | - if (self::debug) { |
|
720 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
721 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
722 | - } |
|
723 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
724 | - } |
|
725 | - } |
|
726 | - } |
|
727 | - if (self::debug) { |
|
728 | - echo '<br /><br /> RESET COMPLETED '; |
|
729 | - } |
|
730 | - } |
|
731 | - |
|
732 | - |
|
733 | - |
|
734 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
735 | - |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
740 | - * |
|
741 | - * @param EE_Session $session |
|
742 | - * @return void |
|
743 | - * @throws EE_Error |
|
744 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
745 | - */ |
|
746 | - public static function session_checkout_reset(EE_Session $session) |
|
747 | - { |
|
748 | - $checkout = $session->checkout(); |
|
749 | - if ($checkout instanceof EE_Checkout) { |
|
750 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
751 | - } |
|
752 | - } |
|
753 | - |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * releases reserved tickets for the EE_Checkout->transaction |
|
758 | - * |
|
759 | - * @param EE_Checkout $checkout |
|
760 | - * @return void |
|
761 | - * @throws EE_Error |
|
762 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
763 | - */ |
|
764 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
765 | - { |
|
766 | - if (self::debug) { |
|
767 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
768 | - } |
|
769 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
770 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
771 | - return; |
|
772 | - } |
|
773 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
774 | - } |
|
775 | - |
|
776 | - |
|
777 | - |
|
778 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
779 | - |
|
780 | - |
|
781 | - |
|
782 | - /** |
|
783 | - * @param EE_Session $session |
|
784 | - * @return void |
|
785 | - */ |
|
786 | - public static function session_expired_reset(EE_Session $session) |
|
787 | - { |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - |
|
792 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
793 | - |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
798 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
799 | - * |
|
800 | - * @param EE_Transaction $transaction |
|
801 | - * @return void |
|
802 | - * @throws EE_Error |
|
803 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
804 | - */ |
|
805 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
806 | - { |
|
807 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
808 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
809 | - if (self::debug) { |
|
810 | - // DEBUG LOG |
|
811 | - EEH_Debug_Tools::log( |
|
812 | - __CLASS__, |
|
813 | - __FUNCTION__, |
|
814 | - __LINE__, |
|
815 | - array($transaction), |
|
816 | - false, |
|
817 | - 'EE_Transaction: ' . $transaction->ID() |
|
818 | - ); |
|
819 | - } |
|
820 | - return; |
|
821 | - } |
|
822 | - // have their been any successful payments made ? |
|
823 | - $payments = $transaction->payments(); |
|
824 | - foreach ($payments as $payment) { |
|
825 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
826 | - if (self::debug) { |
|
827 | - // DEBUG LOG |
|
828 | - EEH_Debug_Tools::log( |
|
829 | - __CLASS__, |
|
830 | - __FUNCTION__, |
|
831 | - __LINE__, |
|
832 | - array($payment), |
|
833 | - false, |
|
834 | - 'EE_Transaction: ' . $transaction->ID() |
|
835 | - ); |
|
836 | - } |
|
837 | - return; |
|
838 | - } |
|
839 | - } |
|
840 | - // since you haven't even attempted to pay for your ticket... |
|
841 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
842 | - } |
|
843 | - |
|
844 | - |
|
845 | - |
|
846 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
847 | - |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
852 | - * |
|
853 | - * @param EE_Transaction $transaction |
|
854 | - * @return void |
|
855 | - * @throws EE_Error |
|
856 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
857 | - */ |
|
858 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
859 | - { |
|
860 | - // since you haven't even attempted to pay for your ticket... |
|
861 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - |
|
866 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
867 | - /** |
|
868 | - * Resets all ticket and datetime reserved counts to zero |
|
869 | - * Tickets that are currently associated with a Transaction that is in progress |
|
870 | - * |
|
871 | - * @throws \EE_Error |
|
872 | - * @throws \DomainException |
|
873 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
874 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
875 | - * @throws \InvalidArgumentException |
|
876 | - */ |
|
877 | - public static function reset_reservation_counts() |
|
878 | - { |
|
879 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
880 | - $valid_reserved_tickets = array(); |
|
881 | - $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
882 | - foreach ($transactions_in_progress as $transaction_in_progress) { |
|
883 | - // if this TXN has been fully completed, then skip it |
|
884 | - if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
885 | - continue; |
|
886 | - } |
|
887 | - /** @var EE_Transaction $transaction_in_progress */ |
|
888 | - $total_line_item = $transaction_in_progress->total_line_item(); |
|
889 | - // $transaction_in_progress->line |
|
890 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
891 | - throw new DomainException( |
|
892 | - esc_html__( |
|
893 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
894 | - 'event_espresso' |
|
895 | - ) |
|
896 | - ); |
|
897 | - } |
|
898 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
899 | - $total_line_item |
|
900 | - ); |
|
901 | - } |
|
902 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
903 | - foreach ($total_line_items as $total_line_item) { |
|
904 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
905 | - $total_line_item |
|
906 | - ); |
|
907 | - } |
|
908 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
909 | - EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
910 | - $valid_reserved_tickets |
|
911 | - ); |
|
912 | - } |
|
913 | - |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * @param EE_Line_Item $total_line_item |
|
918 | - * @return EE_Line_Item[] |
|
919 | - */ |
|
920 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
921 | - { |
|
922 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
923 | - $valid_reserved_tickets = array(); |
|
924 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
925 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
926 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
927 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
928 | - } |
|
929 | - } |
|
930 | - return $valid_reserved_tickets; |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - |
|
935 | - /** |
|
936 | - * @param EE_Ticket[] $tickets_with_reservations |
|
937 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
938 | - * @return int |
|
939 | - * @throws \EE_Error |
|
940 | - */ |
|
941 | - private static function release_reservations_for_tickets( |
|
942 | - array $tickets_with_reservations, |
|
943 | - $valid_reserved_ticket_line_items = array() |
|
944 | - ) { |
|
945 | - $total_tickets_released = 0; |
|
946 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
947 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
948 | - continue; |
|
949 | - } |
|
950 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
951 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
952 | - if ( |
|
953 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
954 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
955 | - ) { |
|
956 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
957 | - } |
|
958 | - } |
|
959 | - if ($reserved_qty > 0) { |
|
960 | - $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
961 | - $ticket_with_reservations->save(); |
|
962 | - $total_tickets_released += $reserved_qty; |
|
963 | - } |
|
964 | - } |
|
965 | - return $total_tickets_released; |
|
966 | - } |
|
967 | - |
|
968 | - |
|
969 | - |
|
970 | - /********************************** SHUTDOWN **********************************/ |
|
971 | - |
|
972 | - |
|
973 | - |
|
974 | - /** |
|
975 | - * @return false|int |
|
976 | - * @throws EE_Error |
|
977 | - * @throws InvalidArgumentException |
|
978 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
979 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
980 | - */ |
|
981 | - public static function clear_expired_line_items_with_no_transaction() |
|
982 | - { |
|
983 | - /** @type WPDB $wpdb */ |
|
984 | - global $wpdb; |
|
985 | - return $wpdb->query( |
|
986 | - $wpdb->prepare( |
|
987 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
25 | + const debug = false; // true false |
|
26 | + |
|
27 | + /** |
|
28 | + * an array of raw ticket data from EED_Ticket_Selector |
|
29 | + * |
|
30 | + * @var array $ticket_selections |
|
31 | + */ |
|
32 | + protected $ticket_selections = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | + * according to how they are displayed in the actual Ticket_Selector |
|
37 | + * this tracks the current row being processed |
|
38 | + * |
|
39 | + * @var int $current_row |
|
40 | + */ |
|
41 | + protected $current_row = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * an array for tracking names of tickets that have sold out |
|
45 | + * |
|
46 | + * @var array $sold_out_tickets |
|
47 | + */ |
|
48 | + protected $sold_out_tickets = array(); |
|
49 | + |
|
50 | + /** |
|
51 | + * an array for tracking names of tickets that have had their quantities reduced |
|
52 | + * |
|
53 | + * @var array $decremented_tickets |
|
54 | + */ |
|
55 | + protected $decremented_tickets = array(); |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public static function set_hooks() |
|
65 | + { |
|
66 | + // release tickets for expired carts |
|
67 | + add_action( |
|
68 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | + 1 |
|
71 | + ); |
|
72 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | + add_filter( |
|
74 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | + 20, |
|
77 | + 3 |
|
78 | + ); |
|
79 | + // add notices for sold out tickets |
|
80 | + add_action( |
|
81 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | + 10 |
|
84 | + ); |
|
85 | + // handle ticket quantities adjusted in cart |
|
86 | + //add_action( |
|
87 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
88 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
89 | + // 10, 2 |
|
90 | + //); |
|
91 | + // handle tickets deleted from cart |
|
92 | + add_action( |
|
93 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
94 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
95 | + 10, |
|
96 | + 2 |
|
97 | + ); |
|
98 | + // handle emptied carts |
|
99 | + add_action( |
|
100 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
101 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
102 | + 10, |
|
103 | + 1 |
|
104 | + ); |
|
105 | + add_action( |
|
106 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
107 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
108 | + 10, |
|
109 | + 1 |
|
110 | + ); |
|
111 | + // handle cancelled registrations |
|
112 | + add_action( |
|
113 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
114 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
115 | + 10, |
|
116 | + 1 |
|
117 | + ); |
|
118 | + // cron tasks |
|
119 | + add_action( |
|
120 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
121 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
122 | + 10, |
|
123 | + 1 |
|
124 | + ); |
|
125 | + add_action( |
|
126 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
127 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
128 | + 10, |
|
129 | + 1 |
|
130 | + ); |
|
131 | + add_action( |
|
132 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
133 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
134 | + 10, |
|
135 | + 1 |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public static function set_hooks_admin() |
|
147 | + { |
|
148 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
155 | + */ |
|
156 | + public static function instance() |
|
157 | + { |
|
158 | + return parent::get_instance(__CLASS__); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param WP_Query $WP_Query |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function run($WP_Query) |
|
168 | + { |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Retrieves grand totals from the line items that have no TXN ID |
|
179 | + * and timestamps less than the current time minus the session lifespan. |
|
180 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
181 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
182 | + * |
|
183 | + * @return void |
|
184 | + * @throws EE_Error |
|
185 | + * @throws InvalidArgumentException |
|
186 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
187 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
188 | + */ |
|
189 | + public static function release_tickets_for_expired_carts() |
|
190 | + { |
|
191 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
192 | + $expired_ticket_IDs = array(); |
|
193 | + $valid_ticket_line_items = array(); |
|
194 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
195 | + if (empty($total_line_items)) { |
|
196 | + do_action( |
|
197 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
198 | + $total_line_items, |
|
199 | + $valid_ticket_line_items, |
|
200 | + $expired_ticket_IDs |
|
201 | + ); |
|
202 | + return; |
|
203 | + } |
|
204 | + $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
205 | + foreach ($total_line_items as $total_line_item) { |
|
206 | + /** @var EE_Line_Item $total_line_item */ |
|
207 | + $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
208 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
209 | + if (! $ticket_line_item instanceof EE_Line_Item) { |
|
210 | + continue; |
|
211 | + } |
|
212 | + if ($total_line_item->timestamp(true) <= $expired) { |
|
213 | + $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
214 | + } else { |
|
215 | + $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
216 | + } |
|
217 | + } |
|
218 | + } |
|
219 | + if (! empty($expired_ticket_IDs)) { |
|
220 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
221 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
222 | + $valid_ticket_line_items |
|
223 | + ); |
|
224 | + // let's get rid of expired line items so that they can't interfere with tracking |
|
225 | + add_action( |
|
226 | + 'shutdown', |
|
227 | + array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
228 | + 999 |
|
229 | + ); |
|
230 | + } |
|
231 | + do_action( |
|
232 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
233 | + $total_line_items, |
|
234 | + $valid_ticket_line_items, |
|
235 | + $expired_ticket_IDs |
|
236 | + ); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + |
|
241 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
247 | + * |
|
248 | + * @param int $qty |
|
249 | + * @param EE_Ticket $ticket |
|
250 | + * @return bool |
|
251 | + * @throws UnexpectedEntityException |
|
252 | + * @throws EE_Error |
|
253 | + */ |
|
254 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
255 | + { |
|
256 | + $qty = absint($qty); |
|
257 | + if ($qty > 0) { |
|
258 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
259 | + } |
|
260 | + if (self::debug) { |
|
261 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
262 | + echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
263 | + } |
|
264 | + return $qty; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
271 | + * |
|
272 | + * @param EE_Ticket $ticket |
|
273 | + * @param int $qty |
|
274 | + * @return int |
|
275 | + * @throws UnexpectedEntityException |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
279 | + { |
|
280 | + if (self::debug) { |
|
281 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
282 | + } |
|
283 | + if (! $ticket instanceof EE_Ticket) { |
|
284 | + return 0; |
|
285 | + } |
|
286 | + if (self::debug) { |
|
287 | + echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
288 | + echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
289 | + } |
|
290 | + $ticket->refresh_from_db(); |
|
291 | + // first let's determine the ticket availability based on sales |
|
292 | + $available = $ticket->qty('saleable'); |
|
293 | + if (self::debug) { |
|
294 | + echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
295 | + echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
296 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
297 | + echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
298 | + echo '<br /> . . . available: ' . $available; |
|
299 | + } |
|
300 | + if ($available < 1) { |
|
301 | + $this->_ticket_sold_out($ticket); |
|
302 | + return 0; |
|
303 | + } |
|
304 | + if (self::debug) { |
|
305 | + echo '<br /> . . . qty: ' . $qty; |
|
306 | + } |
|
307 | + if ($available < $qty) { |
|
308 | + $qty = $available; |
|
309 | + if (self::debug) { |
|
310 | + echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
311 | + } |
|
312 | + $this->_ticket_quantity_decremented($ticket); |
|
313 | + } |
|
314 | + $this->_reserve_ticket($ticket, $qty); |
|
315 | + return $qty; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * increments ticket reserved based on quantity passed |
|
322 | + * |
|
323 | + * @param EE_Ticket $ticket |
|
324 | + * @param int $quantity |
|
325 | + * @return bool |
|
326 | + * @throws EE_Error |
|
327 | + */ |
|
328 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
329 | + { |
|
330 | + if (self::debug) { |
|
331 | + echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
332 | + } |
|
333 | + $ticket->increase_reserved($quantity); |
|
334 | + return $ticket->save(); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @param EE_Ticket $ticket |
|
341 | + * @param int $quantity |
|
342 | + * @return bool |
|
343 | + * @throws EE_Error |
|
344 | + */ |
|
345 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
346 | + { |
|
347 | + if (self::debug) { |
|
348 | + echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
349 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
350 | + } |
|
351 | + $ticket->decrease_reserved($quantity); |
|
352 | + if (self::debug) { |
|
353 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
354 | + } |
|
355 | + return $ticket->save() ? 1 : 0; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * removes quantities within the ticket selector based on zero ticket availability |
|
362 | + * |
|
363 | + * @param EE_Ticket $ticket |
|
364 | + * @return void |
|
365 | + * @throws UnexpectedEntityException |
|
366 | + * @throws EE_Error |
|
367 | + */ |
|
368 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
369 | + { |
|
370 | + if (self::debug) { |
|
371 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
372 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
373 | + } |
|
374 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
381 | + * |
|
382 | + * @param EE_Ticket $ticket |
|
383 | + * @return void |
|
384 | + * @throws UnexpectedEntityException |
|
385 | + * @throws EE_Error |
|
386 | + */ |
|
387 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
388 | + { |
|
389 | + if (self::debug) { |
|
390 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
391 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
392 | + } |
|
393 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * builds string out of ticket and event name |
|
400 | + * |
|
401 | + * @param EE_Ticket $ticket |
|
402 | + * @return string |
|
403 | + * @throws UnexpectedEntityException |
|
404 | + * @throws EE_Error |
|
405 | + */ |
|
406 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
407 | + { |
|
408 | + $event = $ticket->get_related_event(); |
|
409 | + if ($event instanceof EE_Event) { |
|
410 | + $ticket_name = sprintf( |
|
411 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
412 | + $ticket->name(), |
|
413 | + $event->name() |
|
414 | + ); |
|
415 | + } else { |
|
416 | + $ticket_name = $ticket->name(); |
|
417 | + } |
|
418 | + return $ticket_name; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /********************************** EVENT CART **********************************/ |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * releases or reserves ticket(s) based on quantity passed |
|
429 | + * |
|
430 | + * @param EE_Line_Item $line_item |
|
431 | + * @param int $quantity |
|
432 | + * @return void |
|
433 | + * @throws EE_Error |
|
434 | + * @throws InvalidArgumentException |
|
435 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
436 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
437 | + */ |
|
438 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
439 | + { |
|
440 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
441 | + if ($ticket instanceof EE_Ticket) { |
|
442 | + if ($quantity > 0) { |
|
443 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
444 | + } else { |
|
445 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
446 | + } |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * releases reserved ticket(s) based on quantity passed |
|
454 | + * |
|
455 | + * @param EE_Ticket $ticket |
|
456 | + * @param int $quantity |
|
457 | + * @return void |
|
458 | + * @throws EE_Error |
|
459 | + */ |
|
460 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
461 | + { |
|
462 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /********************************** POST_NOTICES **********************************/ |
|
468 | + |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * @return void |
|
473 | + * @throws EE_Error |
|
474 | + * @throws InvalidArgumentException |
|
475 | + * @throws ReflectionException |
|
476 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
477 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
478 | + */ |
|
479 | + public static function post_notices() |
|
480 | + { |
|
481 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @return void |
|
488 | + * @throws EE_Error |
|
489 | + * @throws InvalidArgumentException |
|
490 | + * @throws ReflectionException |
|
491 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
492 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
493 | + */ |
|
494 | + protected function _post_notices() |
|
495 | + { |
|
496 | + if (self::debug) { |
|
497 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
498 | + } |
|
499 | + $refresh_msg = ''; |
|
500 | + $none_added_msg = ''; |
|
501 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
502 | + $refresh_msg = __( |
|
503 | + 'Please refresh the page to view updated ticket quantities.', |
|
504 | + 'event_espresso' |
|
505 | + ); |
|
506 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
507 | + } |
|
508 | + if (! empty($this->sold_out_tickets)) { |
|
509 | + EE_Error::add_attention( |
|
510 | + sprintf( |
|
511 | + apply_filters( |
|
512 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
513 | + __( |
|
514 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
515 | + 'event_espresso' |
|
516 | + ) |
|
517 | + ), |
|
518 | + '<br />', |
|
519 | + implode('<br />', $this->sold_out_tickets), |
|
520 | + $none_added_msg, |
|
521 | + $refresh_msg |
|
522 | + ) |
|
523 | + ); |
|
524 | + // alter code flow in the Ticket Selector for better UX |
|
525 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
526 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
527 | + $this->sold_out_tickets = array(); |
|
528 | + // and reset the cart |
|
529 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
530 | + } |
|
531 | + if (! empty($this->decremented_tickets)) { |
|
532 | + EE_Error::add_attention( |
|
533 | + sprintf( |
|
534 | + apply_filters( |
|
535 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
536 | + __( |
|
537 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
538 | + 'event_espresso' |
|
539 | + ) |
|
540 | + ), |
|
541 | + '<br />', |
|
542 | + implode('<br />', $this->decremented_tickets), |
|
543 | + $none_added_msg, |
|
544 | + $refresh_msg |
|
545 | + ) |
|
546 | + ); |
|
547 | + $this->decremented_tickets = array(); |
|
548 | + } |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + |
|
553 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
554 | + |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
559 | + * by default, will NOT release tickets for finalized transactions |
|
560 | + * |
|
561 | + * @param EE_Transaction $transaction |
|
562 | + * @return int |
|
563 | + * @throws EE_Error |
|
564 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
565 | + */ |
|
566 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
567 | + { |
|
568 | + if (self::debug) { |
|
569 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
570 | + echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
571 | + } |
|
572 | + // check if 'finalize_registration' step has been completed... |
|
573 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
574 | + if (self::debug) { |
|
575 | + // DEBUG LOG |
|
576 | + EEH_Debug_Tools::log( |
|
577 | + __CLASS__, |
|
578 | + __FUNCTION__, |
|
579 | + __LINE__, |
|
580 | + array('finalized' => $finalized), |
|
581 | + false, |
|
582 | + 'EE_Transaction: ' . $transaction->ID() |
|
583 | + ); |
|
584 | + } |
|
585 | + // how many tickets were released |
|
586 | + $count = 0; |
|
587 | + if (self::debug) { |
|
588 | + echo '<br /> . . . finalized: ' . $finalized; |
|
589 | + } |
|
590 | + $release_tickets_with_TXN_status = array( |
|
591 | + EEM_Transaction::failed_status_code, |
|
592 | + EEM_Transaction::abandoned_status_code, |
|
593 | + EEM_Transaction::incomplete_status_code, |
|
594 | + ); |
|
595 | + // if the session is getting cleared BEFORE the TXN has been finalized |
|
596 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
597 | + // let's cancel any reserved tickets |
|
598 | + $registrations = $transaction->registrations(); |
|
599 | + if (! empty($registrations)) { |
|
600 | + foreach ($registrations as $registration) { |
|
601 | + if ($registration instanceof EE_Registration) { |
|
602 | + $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
603 | + } |
|
604 | + } |
|
605 | + } |
|
606 | + } |
|
607 | + return $count; |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * releases reserved tickets for an EE_Registration |
|
614 | + * by default, will NOT release tickets for APPROVED registrations |
|
615 | + * |
|
616 | + * @param EE_Registration $registration |
|
617 | + * @param EE_Transaction $transaction |
|
618 | + * @return int |
|
619 | + * @throws EE_Error |
|
620 | + */ |
|
621 | + protected function _release_reserved_ticket_for_registration( |
|
622 | + EE_Registration $registration, |
|
623 | + EE_Transaction $transaction |
|
624 | + ) { |
|
625 | + $STS_ID = $transaction->status_ID(); |
|
626 | + if (self::debug) { |
|
627 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
628 | + echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
629 | + echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
630 | + echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
631 | + } |
|
632 | + if ( |
|
633 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
634 | + $STS_ID === EEM_Transaction::failed_status_code |
|
635 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
636 | + || ( |
|
637 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
638 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
639 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
640 | + ) |
|
641 | + ) { |
|
642 | + $ticket = $registration->ticket(); |
|
643 | + if ($ticket instanceof EE_Ticket) { |
|
644 | + return $this->_release_reserved_ticket($ticket); |
|
645 | + } |
|
646 | + } |
|
647 | + return 0; |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + |
|
652 | + /********************************** SESSION_CART_RESET **********************************/ |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
658 | + * |
|
659 | + * @param EE_Session $session |
|
660 | + * @return void |
|
661 | + * @throws EE_Error |
|
662 | + * @throws InvalidArgumentException |
|
663 | + * @throws ReflectionException |
|
664 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
665 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
666 | + */ |
|
667 | + public static function session_cart_reset(EE_Session $session) |
|
668 | + { |
|
669 | + if (self::debug) { |
|
670 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
671 | + } |
|
672 | + $cart = $session->cart(); |
|
673 | + if ($cart instanceof EE_Cart) { |
|
674 | + if (self::debug) { |
|
675 | + echo '<br /><br /> cart instance of EE_Cart: '; |
|
676 | + } |
|
677 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
678 | + } else { |
|
679 | + if (self::debug) { |
|
680 | + echo '<br /><br /> invalid EE_Cart: '; |
|
681 | + var_export($cart, true); |
|
682 | + } |
|
683 | + } |
|
684 | + } |
|
685 | + |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * releases reserved tickets in the EE_Cart |
|
690 | + * |
|
691 | + * @param EE_Cart $cart |
|
692 | + * @return void |
|
693 | + * @throws EE_Error |
|
694 | + * @throws InvalidArgumentException |
|
695 | + * @throws ReflectionException |
|
696 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
697 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
698 | + */ |
|
699 | + protected function _session_cart_reset(EE_Cart $cart) |
|
700 | + { |
|
701 | + if (self::debug) { |
|
702 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
703 | + } |
|
704 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
705 | + $ticket_line_items = $cart->get_tickets(); |
|
706 | + if (empty($ticket_line_items)) { |
|
707 | + return; |
|
708 | + } |
|
709 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
710 | + if (self::debug) { |
|
711 | + echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
712 | + } |
|
713 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
714 | + if (self::debug) { |
|
715 | + echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
716 | + } |
|
717 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
718 | + if ($ticket instanceof EE_Ticket) { |
|
719 | + if (self::debug) { |
|
720 | + echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
721 | + echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
722 | + } |
|
723 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
724 | + } |
|
725 | + } |
|
726 | + } |
|
727 | + if (self::debug) { |
|
728 | + echo '<br /><br /> RESET COMPLETED '; |
|
729 | + } |
|
730 | + } |
|
731 | + |
|
732 | + |
|
733 | + |
|
734 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
735 | + |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
740 | + * |
|
741 | + * @param EE_Session $session |
|
742 | + * @return void |
|
743 | + * @throws EE_Error |
|
744 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
745 | + */ |
|
746 | + public static function session_checkout_reset(EE_Session $session) |
|
747 | + { |
|
748 | + $checkout = $session->checkout(); |
|
749 | + if ($checkout instanceof EE_Checkout) { |
|
750 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
751 | + } |
|
752 | + } |
|
753 | + |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * releases reserved tickets for the EE_Checkout->transaction |
|
758 | + * |
|
759 | + * @param EE_Checkout $checkout |
|
760 | + * @return void |
|
761 | + * @throws EE_Error |
|
762 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
763 | + */ |
|
764 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
765 | + { |
|
766 | + if (self::debug) { |
|
767 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
768 | + } |
|
769 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
770 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
771 | + return; |
|
772 | + } |
|
773 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
774 | + } |
|
775 | + |
|
776 | + |
|
777 | + |
|
778 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
779 | + |
|
780 | + |
|
781 | + |
|
782 | + /** |
|
783 | + * @param EE_Session $session |
|
784 | + * @return void |
|
785 | + */ |
|
786 | + public static function session_expired_reset(EE_Session $session) |
|
787 | + { |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + |
|
792 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
793 | + |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
798 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
799 | + * |
|
800 | + * @param EE_Transaction $transaction |
|
801 | + * @return void |
|
802 | + * @throws EE_Error |
|
803 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
804 | + */ |
|
805 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
806 | + { |
|
807 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
808 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
809 | + if (self::debug) { |
|
810 | + // DEBUG LOG |
|
811 | + EEH_Debug_Tools::log( |
|
812 | + __CLASS__, |
|
813 | + __FUNCTION__, |
|
814 | + __LINE__, |
|
815 | + array($transaction), |
|
816 | + false, |
|
817 | + 'EE_Transaction: ' . $transaction->ID() |
|
818 | + ); |
|
819 | + } |
|
820 | + return; |
|
821 | + } |
|
822 | + // have their been any successful payments made ? |
|
823 | + $payments = $transaction->payments(); |
|
824 | + foreach ($payments as $payment) { |
|
825 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
826 | + if (self::debug) { |
|
827 | + // DEBUG LOG |
|
828 | + EEH_Debug_Tools::log( |
|
829 | + __CLASS__, |
|
830 | + __FUNCTION__, |
|
831 | + __LINE__, |
|
832 | + array($payment), |
|
833 | + false, |
|
834 | + 'EE_Transaction: ' . $transaction->ID() |
|
835 | + ); |
|
836 | + } |
|
837 | + return; |
|
838 | + } |
|
839 | + } |
|
840 | + // since you haven't even attempted to pay for your ticket... |
|
841 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
842 | + } |
|
843 | + |
|
844 | + |
|
845 | + |
|
846 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
847 | + |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
852 | + * |
|
853 | + * @param EE_Transaction $transaction |
|
854 | + * @return void |
|
855 | + * @throws EE_Error |
|
856 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
857 | + */ |
|
858 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
859 | + { |
|
860 | + // since you haven't even attempted to pay for your ticket... |
|
861 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + |
|
866 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
867 | + /** |
|
868 | + * Resets all ticket and datetime reserved counts to zero |
|
869 | + * Tickets that are currently associated with a Transaction that is in progress |
|
870 | + * |
|
871 | + * @throws \EE_Error |
|
872 | + * @throws \DomainException |
|
873 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
874 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
875 | + * @throws \InvalidArgumentException |
|
876 | + */ |
|
877 | + public static function reset_reservation_counts() |
|
878 | + { |
|
879 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
880 | + $valid_reserved_tickets = array(); |
|
881 | + $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
882 | + foreach ($transactions_in_progress as $transaction_in_progress) { |
|
883 | + // if this TXN has been fully completed, then skip it |
|
884 | + if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
885 | + continue; |
|
886 | + } |
|
887 | + /** @var EE_Transaction $transaction_in_progress */ |
|
888 | + $total_line_item = $transaction_in_progress->total_line_item(); |
|
889 | + // $transaction_in_progress->line |
|
890 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
891 | + throw new DomainException( |
|
892 | + esc_html__( |
|
893 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
894 | + 'event_espresso' |
|
895 | + ) |
|
896 | + ); |
|
897 | + } |
|
898 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
899 | + $total_line_item |
|
900 | + ); |
|
901 | + } |
|
902 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
903 | + foreach ($total_line_items as $total_line_item) { |
|
904 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
905 | + $total_line_item |
|
906 | + ); |
|
907 | + } |
|
908 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
909 | + EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
910 | + $valid_reserved_tickets |
|
911 | + ); |
|
912 | + } |
|
913 | + |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * @param EE_Line_Item $total_line_item |
|
918 | + * @return EE_Line_Item[] |
|
919 | + */ |
|
920 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
921 | + { |
|
922 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
923 | + $valid_reserved_tickets = array(); |
|
924 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
925 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
926 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
927 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
928 | + } |
|
929 | + } |
|
930 | + return $valid_reserved_tickets; |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + |
|
935 | + /** |
|
936 | + * @param EE_Ticket[] $tickets_with_reservations |
|
937 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
938 | + * @return int |
|
939 | + * @throws \EE_Error |
|
940 | + */ |
|
941 | + private static function release_reservations_for_tickets( |
|
942 | + array $tickets_with_reservations, |
|
943 | + $valid_reserved_ticket_line_items = array() |
|
944 | + ) { |
|
945 | + $total_tickets_released = 0; |
|
946 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
947 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
948 | + continue; |
|
949 | + } |
|
950 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
951 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
952 | + if ( |
|
953 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
954 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
955 | + ) { |
|
956 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
957 | + } |
|
958 | + } |
|
959 | + if ($reserved_qty > 0) { |
|
960 | + $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
961 | + $ticket_with_reservations->save(); |
|
962 | + $total_tickets_released += $reserved_qty; |
|
963 | + } |
|
964 | + } |
|
965 | + return $total_tickets_released; |
|
966 | + } |
|
967 | + |
|
968 | + |
|
969 | + |
|
970 | + /********************************** SHUTDOWN **********************************/ |
|
971 | + |
|
972 | + |
|
973 | + |
|
974 | + /** |
|
975 | + * @return false|int |
|
976 | + * @throws EE_Error |
|
977 | + * @throws InvalidArgumentException |
|
978 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
979 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
980 | + */ |
|
981 | + public static function clear_expired_line_items_with_no_transaction() |
|
982 | + { |
|
983 | + /** @type WPDB $wpdb */ |
|
984 | + global $wpdb; |
|
985 | + return $wpdb->query( |
|
986 | + $wpdb->prepare( |
|
987 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
988 | 988 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
989 | - // use GMT time because that's what LIN_timestamps are in |
|
990 | - date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
991 | - ) |
|
992 | - ); |
|
993 | - } |
|
989 | + // use GMT time because that's what LIN_timestamps are in |
|
990 | + date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
991 | + ) |
|
992 | + ); |
|
993 | + } |
|
994 | 994 | |
995 | 995 | } |
996 | 996 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | // if you're a dev and want to receive all errors via email |
12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -27,256 +27,256 @@ discard block |
||
27 | 27 | class EE_Error extends Exception |
28 | 28 | { |
29 | 29 | |
30 | - const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * name of the file to log exceptions to |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | - |
|
40 | - /** |
|
41 | - * stores details for all exception |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private static $_all_exceptions = array(); |
|
46 | - |
|
47 | - /** |
|
48 | - * tracks number of errors |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - private static $_error_count = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $_espresso_notices |
|
56 | - */ |
|
57 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @override default exception handling |
|
63 | - * @param string $message |
|
64 | - * @param int $code |
|
65 | - * @param Exception|null $previous |
|
66 | - */ |
|
67 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | - { |
|
69 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | - parent::__construct($message, $code); |
|
71 | - } else { |
|
72 | - parent::__construct($message, $code, $previous); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * error_handler |
|
80 | - * |
|
81 | - * @param $code |
|
82 | - * @param $message |
|
83 | - * @param $file |
|
84 | - * @param $line |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public static function error_handler($code, $message, $file, $line) |
|
88 | - { |
|
89 | - $type = EE_Error::error_type($code); |
|
90 | - $site = site_url(); |
|
91 | - switch ($site) { |
|
92 | - case 'http://ee4.eventespresso.com/' : |
|
93 | - case 'http://ee4decaf.eventespresso.com/' : |
|
94 | - case 'http://ee4hf.eventespresso.com/' : |
|
95 | - case 'http://ee4a.eventespresso.com/' : |
|
96 | - case 'http://ee4ad.eventespresso.com/' : |
|
97 | - case 'http://ee4b.eventespresso.com/' : |
|
98 | - case 'http://ee4bd.eventespresso.com/' : |
|
99 | - case 'http://ee4d.eventespresso.com/' : |
|
100 | - case 'http://ee4dd.eventespresso.com/' : |
|
101 | - $to = '[email protected]'; |
|
102 | - break; |
|
103 | - default : |
|
104 | - $to = get_option('admin_email'); |
|
105 | - } |
|
106 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
107 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
108 | - if (function_exists('wp_mail')) { |
|
109 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
110 | - wp_mail($to, $subject, $msg); |
|
111 | - } |
|
112 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
113 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
114 | - echo '<br /></p></div>'; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * error_type |
|
121 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
122 | - * |
|
123 | - * @param $code |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public static function error_type($code) |
|
127 | - { |
|
128 | - switch ($code) { |
|
129 | - case E_ERROR: // 1 // |
|
130 | - return 'E_ERROR'; |
|
131 | - case E_WARNING: // 2 // |
|
132 | - return 'E_WARNING'; |
|
133 | - case E_PARSE: // 4 // |
|
134 | - return 'E_PARSE'; |
|
135 | - case E_NOTICE: // 8 // |
|
136 | - return 'E_NOTICE'; |
|
137 | - case E_CORE_ERROR: // 16 // |
|
138 | - return 'E_CORE_ERROR'; |
|
139 | - case E_CORE_WARNING: // 32 // |
|
140 | - return 'E_CORE_WARNING'; |
|
141 | - case E_COMPILE_ERROR: // 64 // |
|
142 | - return 'E_COMPILE_ERROR'; |
|
143 | - case E_COMPILE_WARNING: // 128 // |
|
144 | - return 'E_COMPILE_WARNING'; |
|
145 | - case E_USER_ERROR: // 256 // |
|
146 | - return 'E_USER_ERROR'; |
|
147 | - case E_USER_WARNING: // 512 // |
|
148 | - return 'E_USER_WARNING'; |
|
149 | - case E_USER_NOTICE: // 1024 // |
|
150 | - return 'E_USER_NOTICE'; |
|
151 | - case E_STRICT: // 2048 // |
|
152 | - return 'E_STRICT'; |
|
153 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
154 | - return 'E_RECOVERABLE_ERROR'; |
|
155 | - case E_DEPRECATED: // 8192 // |
|
156 | - return 'E_DEPRECATED'; |
|
157 | - case E_USER_DEPRECATED: // 16384 // |
|
158 | - return 'E_USER_DEPRECATED'; |
|
159 | - case E_ALL: // 16384 // |
|
160 | - return 'E_ALL'; |
|
161 | - } |
|
162 | - return ''; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * fatal_error_handler |
|
169 | - * |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - public static function fatal_error_handler() |
|
173 | - { |
|
174 | - $last_error = error_get_last(); |
|
175 | - if ($last_error['type'] === E_ERROR) { |
|
176 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * _format_error |
|
184 | - * |
|
185 | - * @param $code |
|
186 | - * @param $message |
|
187 | - * @param $file |
|
188 | - * @param $line |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - private static function _format_error($code, $message, $file, $line) |
|
192 | - { |
|
193 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
194 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
195 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
196 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
197 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
198 | - $html .= '</tbody></table>'; |
|
199 | - return $html; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * set_content_type |
|
206 | - * |
|
207 | - * @param $content_type |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public static function set_content_type($content_type) |
|
211 | - { |
|
212 | - return 'text/html'; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * @return void |
|
219 | - * @throws EE_Error |
|
220 | - * @throws ReflectionException |
|
221 | - */ |
|
222 | - public function get_error() |
|
223 | - { |
|
224 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
225 | - throw $this; |
|
226 | - } |
|
227 | - // get separate user and developer messages if they exist |
|
228 | - $msg = explode('||', $this->getMessage()); |
|
229 | - $user_msg = $msg[0]; |
|
230 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
231 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
232 | - // add details to _all_exceptions array |
|
233 | - $x_time = time(); |
|
234 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
235 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
236 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
237 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
238 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
239 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
240 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
241 | - self::$_error_count++; |
|
242 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
243 | - $this->display_errors(); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * @param bool $check_stored |
|
250 | - * @param string $type_to_check |
|
251 | - * @return bool |
|
252 | - */ |
|
253 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
254 | - { |
|
255 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
256 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
257 | - ? true |
|
258 | - : false; |
|
259 | - if ($check_stored && ! $has_error) { |
|
260 | - $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | - foreach ($notices as $type => $notice) { |
|
262 | - if ($type === $type_to_check && $notice) { |
|
263 | - return true; |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - return $has_error; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @echo string |
|
274 | - * @throws \ReflectionException |
|
275 | - */ |
|
276 | - public function display_errors() |
|
277 | - { |
|
278 | - $trace_details = ''; |
|
279 | - $output = ' |
|
30 | + const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * name of the file to log exceptions to |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | + |
|
40 | + /** |
|
41 | + * stores details for all exception |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private static $_all_exceptions = array(); |
|
46 | + |
|
47 | + /** |
|
48 | + * tracks number of errors |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + private static $_error_count = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $_espresso_notices |
|
56 | + */ |
|
57 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @override default exception handling |
|
63 | + * @param string $message |
|
64 | + * @param int $code |
|
65 | + * @param Exception|null $previous |
|
66 | + */ |
|
67 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | + { |
|
69 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | + parent::__construct($message, $code); |
|
71 | + } else { |
|
72 | + parent::__construct($message, $code, $previous); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * error_handler |
|
80 | + * |
|
81 | + * @param $code |
|
82 | + * @param $message |
|
83 | + * @param $file |
|
84 | + * @param $line |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public static function error_handler($code, $message, $file, $line) |
|
88 | + { |
|
89 | + $type = EE_Error::error_type($code); |
|
90 | + $site = site_url(); |
|
91 | + switch ($site) { |
|
92 | + case 'http://ee4.eventespresso.com/' : |
|
93 | + case 'http://ee4decaf.eventespresso.com/' : |
|
94 | + case 'http://ee4hf.eventespresso.com/' : |
|
95 | + case 'http://ee4a.eventespresso.com/' : |
|
96 | + case 'http://ee4ad.eventespresso.com/' : |
|
97 | + case 'http://ee4b.eventespresso.com/' : |
|
98 | + case 'http://ee4bd.eventespresso.com/' : |
|
99 | + case 'http://ee4d.eventespresso.com/' : |
|
100 | + case 'http://ee4dd.eventespresso.com/' : |
|
101 | + $to = '[email protected]'; |
|
102 | + break; |
|
103 | + default : |
|
104 | + $to = get_option('admin_email'); |
|
105 | + } |
|
106 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
107 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
108 | + if (function_exists('wp_mail')) { |
|
109 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
110 | + wp_mail($to, $subject, $msg); |
|
111 | + } |
|
112 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
113 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
114 | + echo '<br /></p></div>'; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * error_type |
|
121 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
122 | + * |
|
123 | + * @param $code |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public static function error_type($code) |
|
127 | + { |
|
128 | + switch ($code) { |
|
129 | + case E_ERROR: // 1 // |
|
130 | + return 'E_ERROR'; |
|
131 | + case E_WARNING: // 2 // |
|
132 | + return 'E_WARNING'; |
|
133 | + case E_PARSE: // 4 // |
|
134 | + return 'E_PARSE'; |
|
135 | + case E_NOTICE: // 8 // |
|
136 | + return 'E_NOTICE'; |
|
137 | + case E_CORE_ERROR: // 16 // |
|
138 | + return 'E_CORE_ERROR'; |
|
139 | + case E_CORE_WARNING: // 32 // |
|
140 | + return 'E_CORE_WARNING'; |
|
141 | + case E_COMPILE_ERROR: // 64 // |
|
142 | + return 'E_COMPILE_ERROR'; |
|
143 | + case E_COMPILE_WARNING: // 128 // |
|
144 | + return 'E_COMPILE_WARNING'; |
|
145 | + case E_USER_ERROR: // 256 // |
|
146 | + return 'E_USER_ERROR'; |
|
147 | + case E_USER_WARNING: // 512 // |
|
148 | + return 'E_USER_WARNING'; |
|
149 | + case E_USER_NOTICE: // 1024 // |
|
150 | + return 'E_USER_NOTICE'; |
|
151 | + case E_STRICT: // 2048 // |
|
152 | + return 'E_STRICT'; |
|
153 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
154 | + return 'E_RECOVERABLE_ERROR'; |
|
155 | + case E_DEPRECATED: // 8192 // |
|
156 | + return 'E_DEPRECATED'; |
|
157 | + case E_USER_DEPRECATED: // 16384 // |
|
158 | + return 'E_USER_DEPRECATED'; |
|
159 | + case E_ALL: // 16384 // |
|
160 | + return 'E_ALL'; |
|
161 | + } |
|
162 | + return ''; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * fatal_error_handler |
|
169 | + * |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + public static function fatal_error_handler() |
|
173 | + { |
|
174 | + $last_error = error_get_last(); |
|
175 | + if ($last_error['type'] === E_ERROR) { |
|
176 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * _format_error |
|
184 | + * |
|
185 | + * @param $code |
|
186 | + * @param $message |
|
187 | + * @param $file |
|
188 | + * @param $line |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + private static function _format_error($code, $message, $file, $line) |
|
192 | + { |
|
193 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
194 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
195 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
196 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
197 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
198 | + $html .= '</tbody></table>'; |
|
199 | + return $html; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * set_content_type |
|
206 | + * |
|
207 | + * @param $content_type |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + public static function set_content_type($content_type) |
|
211 | + { |
|
212 | + return 'text/html'; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * @return void |
|
219 | + * @throws EE_Error |
|
220 | + * @throws ReflectionException |
|
221 | + */ |
|
222 | + public function get_error() |
|
223 | + { |
|
224 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
225 | + throw $this; |
|
226 | + } |
|
227 | + // get separate user and developer messages if they exist |
|
228 | + $msg = explode('||', $this->getMessage()); |
|
229 | + $user_msg = $msg[0]; |
|
230 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
231 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
232 | + // add details to _all_exceptions array |
|
233 | + $x_time = time(); |
|
234 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
235 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
236 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
237 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
238 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
239 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
240 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
241 | + self::$_error_count++; |
|
242 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
243 | + $this->display_errors(); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * @param bool $check_stored |
|
250 | + * @param string $type_to_check |
|
251 | + * @return bool |
|
252 | + */ |
|
253 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
254 | + { |
|
255 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
256 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
257 | + ? true |
|
258 | + : false; |
|
259 | + if ($check_stored && ! $has_error) { |
|
260 | + $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | + foreach ($notices as $type => $notice) { |
|
262 | + if ($type === $type_to_check && $notice) { |
|
263 | + return true; |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + return $has_error; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @echo string |
|
274 | + * @throws \ReflectionException |
|
275 | + */ |
|
276 | + public function display_errors() |
|
277 | + { |
|
278 | + $trace_details = ''; |
|
279 | + $output = ' |
|
280 | 280 | <style type="text/css"> |
281 | 281 | #ee-error-message { |
282 | 282 | max-width:90% !important; |
@@ -332,21 +332,21 @@ discard block |
||
332 | 332 | } |
333 | 333 | </style> |
334 | 334 | <div id="ee-error-message" class="error">'; |
335 | - if (! WP_DEBUG) { |
|
336 | - $output .= ' |
|
335 | + if (! WP_DEBUG) { |
|
336 | + $output .= ' |
|
337 | 337 | <p>'; |
338 | - } |
|
339 | - // cycle thru errors |
|
340 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
341 | - $error_code = ''; |
|
342 | - // process trace info |
|
343 | - if (empty($ex['trace'])) { |
|
344 | - $trace_details .= __( |
|
345 | - 'Sorry, but no trace information was available for this exception.', |
|
346 | - 'event_espresso' |
|
347 | - ); |
|
348 | - } else { |
|
349 | - $trace_details .= ' |
|
338 | + } |
|
339 | + // cycle thru errors |
|
340 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
341 | + $error_code = ''; |
|
342 | + // process trace info |
|
343 | + if (empty($ex['trace'])) { |
|
344 | + $trace_details .= __( |
|
345 | + 'Sorry, but no trace information was available for this exception.', |
|
346 | + 'event_espresso' |
|
347 | + ); |
|
348 | + } else { |
|
349 | + $trace_details .= ' |
|
350 | 350 | <div id="ee-trace-details"> |
351 | 351 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
352 | 352 | <tr> |
@@ -356,43 +356,43 @@ discard block |
||
356 | 356 | <th scope="col" align="left">Class</th> |
357 | 357 | <th scope="col" align="left">Method( arguments )</th> |
358 | 358 | </tr>'; |
359 | - $last_on_stack = count($ex['trace']) - 1; |
|
360 | - // reverse array so that stack is in proper chronological order |
|
361 | - $sorted_trace = array_reverse($ex['trace']); |
|
362 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
363 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
364 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
365 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
366 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
367 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
368 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
369 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
370 | - if (empty($file) && ! empty($class)) { |
|
371 | - $a = new ReflectionClass($class); |
|
372 | - $file = $a->getFileName(); |
|
373 | - if (empty($line) && ! empty($function)) { |
|
374 | - try { |
|
375 | - //if $function is a closure, this throws an exception |
|
376 | - $b = new ReflectionMethod($class, $function); |
|
377 | - $line = $b->getStartLine(); |
|
378 | - } catch (Exception $closure_exception) { |
|
379 | - $line = 'unknown'; |
|
380 | - } |
|
381 | - } |
|
382 | - } |
|
383 | - if ($nmbr === $last_on_stack) { |
|
384 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
385 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
386 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
387 | - } |
|
388 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
389 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
390 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
391 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
392 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
393 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
394 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
395 | - $trace_details .= ' |
|
359 | + $last_on_stack = count($ex['trace']) - 1; |
|
360 | + // reverse array so that stack is in proper chronological order |
|
361 | + $sorted_trace = array_reverse($ex['trace']); |
|
362 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
363 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
364 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
365 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
366 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
367 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
368 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
369 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
370 | + if (empty($file) && ! empty($class)) { |
|
371 | + $a = new ReflectionClass($class); |
|
372 | + $file = $a->getFileName(); |
|
373 | + if (empty($line) && ! empty($function)) { |
|
374 | + try { |
|
375 | + //if $function is a closure, this throws an exception |
|
376 | + $b = new ReflectionMethod($class, $function); |
|
377 | + $line = $b->getStartLine(); |
|
378 | + } catch (Exception $closure_exception) { |
|
379 | + $line = 'unknown'; |
|
380 | + } |
|
381 | + } |
|
382 | + } |
|
383 | + if ($nmbr === $last_on_stack) { |
|
384 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
385 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
386 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
387 | + } |
|
388 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
389 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
390 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
391 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
392 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
393 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
394 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
395 | + $trace_details .= ' |
|
396 | 396 | <tr> |
397 | 397 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
398 | 398 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -400,523 +400,523 @@ discard block |
||
400 | 400 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
401 | 401 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
402 | 402 | </tr>'; |
403 | - } |
|
404 | - $trace_details .= ' |
|
403 | + } |
|
404 | + $trace_details .= ' |
|
405 | 405 | </table> |
406 | 406 | </div>'; |
407 | - } |
|
408 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
409 | - // add generic non-identifying messages for non-privileged users |
|
410 | - if (! WP_DEBUG) { |
|
411 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
412 | - . trim($ex['msg']) |
|
413 | - . '</span> <sup>' |
|
414 | - . $ex['code'] |
|
415 | - . '</sup><br />'; |
|
416 | - } else { |
|
417 | - // or helpful developer messages if debugging is on |
|
418 | - $output .= ' |
|
407 | + } |
|
408 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
409 | + // add generic non-identifying messages for non-privileged users |
|
410 | + if (! WP_DEBUG) { |
|
411 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
412 | + . trim($ex['msg']) |
|
413 | + . '</span> <sup>' |
|
414 | + . $ex['code'] |
|
415 | + . '</sup><br />'; |
|
416 | + } else { |
|
417 | + // or helpful developer messages if debugging is on |
|
418 | + $output .= ' |
|
419 | 419 | <div class="ee-error-dev-msg-dv"> |
420 | 420 | <p class="ee-error-dev-msg-pg"> |
421 | 421 | <strong class="ee-error-dev-msg-str">An ' |
422 | - . $ex['name'] |
|
423 | - . ' exception was thrown!</strong> <span>code: ' |
|
424 | - . $ex['code'] |
|
425 | - . '</span><br /> |
|
422 | + . $ex['name'] |
|
423 | + . ' exception was thrown!</strong> <span>code: ' |
|
424 | + . $ex['code'] |
|
425 | + . '</span><br /> |
|
426 | 426 | <span class="big-text">"' |
427 | - . trim($ex['msg']) |
|
428 | - . '"</span><br/> |
|
427 | + . trim($ex['msg']) |
|
428 | + . '"</span><br/> |
|
429 | 429 | <a id="display-ee-error-trace-' |
430 | - . self::$_error_count |
|
431 | - . $time |
|
432 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
433 | - . self::$_error_count |
|
434 | - . $time |
|
435 | - . '"> |
|
430 | + . self::$_error_count |
|
431 | + . $time |
|
432 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
433 | + . self::$_error_count |
|
434 | + . $time |
|
435 | + . '"> |
|
436 | 436 | ' |
437 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
438 | - . ' |
|
437 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
438 | + . ' |
|
439 | 439 | </a><br /> |
440 | 440 | <span class="small-text lt-grey-text">' |
441 | - . $ex['file'] |
|
442 | - . ' ( line no: ' |
|
443 | - . $ex['line'] |
|
444 | - . ' )</span> |
|
441 | + . $ex['file'] |
|
442 | + . ' ( line no: ' |
|
443 | + . $ex['line'] |
|
444 | + . ' )</span> |
|
445 | 445 | </p> |
446 | 446 | <div id="ee-error-trace-' |
447 | - . self::$_error_count |
|
448 | - . $time |
|
449 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
447 | + . self::$_error_count |
|
448 | + . $time |
|
449 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
450 | 450 | ' |
451 | - . $trace_details; |
|
452 | - if (! empty($class)) { |
|
453 | - $output .= ' |
|
451 | + . $trace_details; |
|
452 | + if (! empty($class)) { |
|
453 | + $output .= ' |
|
454 | 454 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
455 | 455 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
456 | 456 | <h3>Class Details</h3>'; |
457 | - $a = new ReflectionClass($class); |
|
458 | - $output .= ' |
|
457 | + $a = new ReflectionClass($class); |
|
458 | + $output .= ' |
|
459 | 459 | <pre>' . $a . '</pre> |
460 | 460 | </div> |
461 | 461 | </div>'; |
462 | - } |
|
463 | - $output .= ' |
|
462 | + } |
|
463 | + $output .= ' |
|
464 | 464 | </div> |
465 | 465 | </div> |
466 | 466 | <br />'; |
467 | - } |
|
468 | - $this->write_to_error_log($time, $ex); |
|
469 | - } |
|
470 | - // remove last linebreak |
|
471 | - $output = substr($output, 0, -6); |
|
472 | - if (! WP_DEBUG) { |
|
473 | - $output .= ' |
|
467 | + } |
|
468 | + $this->write_to_error_log($time, $ex); |
|
469 | + } |
|
470 | + // remove last linebreak |
|
471 | + $output = substr($output, 0, -6); |
|
472 | + if (! WP_DEBUG) { |
|
473 | + $output .= ' |
|
474 | 474 | </p>'; |
475 | - } |
|
476 | - $output .= ' |
|
475 | + } |
|
476 | + $output .= ' |
|
477 | 477 | </div>'; |
478 | - $output .= self::_print_scripts(true); |
|
479 | - if (defined('DOING_AJAX')) { |
|
480 | - echo wp_json_encode(array('error' => $output)); |
|
481 | - exit(); |
|
482 | - } |
|
483 | - echo $output; |
|
484 | - die(); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * generate string from exception trace args |
|
491 | - * |
|
492 | - * @param array $arguments |
|
493 | - * @param bool $array |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
497 | - { |
|
498 | - $arg_string = ''; |
|
499 | - if (! empty($arguments)) { |
|
500 | - $args = array(); |
|
501 | - foreach ($arguments as $arg) { |
|
502 | - if (! empty($arg)) { |
|
503 | - if (is_string($arg)) { |
|
504 | - $args[] = " '" . $arg . "'"; |
|
505 | - } elseif (is_array($arg)) { |
|
506 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
507 | - } elseif ($arg === null) { |
|
508 | - $args[] = ' NULL'; |
|
509 | - } elseif (is_bool($arg)) { |
|
510 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
511 | - } elseif (is_object($arg)) { |
|
512 | - $args[] = ' OBJECT ' . get_class($arg); |
|
513 | - } elseif (is_resource($arg)) { |
|
514 | - $args[] = get_resource_type($arg); |
|
515 | - } else { |
|
516 | - $args[] = $arg; |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
520 | - $arg_string = implode(', ', $args); |
|
521 | - } |
|
522 | - if ($array) { |
|
523 | - $arg_string .= ' )'; |
|
524 | - } |
|
525 | - return $arg_string; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * add error message |
|
532 | - * |
|
533 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
534 | - * separate messages for user || dev |
|
535 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
536 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
537 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
538 | - * @return void |
|
539 | - */ |
|
540 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
541 | - { |
|
542 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
543 | - self::$_error_count++; |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
550 | - * adds an error |
|
551 | - * |
|
552 | - * @param string $msg |
|
553 | - * @param string $file |
|
554 | - * @param string $func |
|
555 | - * @param string $line |
|
556 | - * @throws EE_Error |
|
557 | - */ |
|
558 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
559 | - { |
|
560 | - if (WP_DEBUG) { |
|
561 | - throw new EE_Error($msg); |
|
562 | - } |
|
563 | - EE_Error::add_error($msg, $file, $func, $line); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * add success message |
|
570 | - * |
|
571 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
572 | - * separate messages for user || dev |
|
573 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
574 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
575 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
576 | - * @return void |
|
577 | - */ |
|
578 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
579 | - { |
|
580 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * add attention message |
|
587 | - * |
|
588 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
589 | - * separate messages for user || dev |
|
590 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
591 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
592 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
593 | - * @return void |
|
594 | - */ |
|
595 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
596 | - { |
|
597 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * @param string $type whether the message is for a success or error notification |
|
604 | - * @param string $msg the message to display to users or developers |
|
605 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
606 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
607 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
608 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
609 | - * @return void |
|
610 | - */ |
|
611 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
612 | - { |
|
613 | - if (empty($msg)) { |
|
614 | - EE_Error::doing_it_wrong( |
|
615 | - 'EE_Error::add_' . $type . '()', |
|
616 | - sprintf( |
|
617 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
618 | - 'event_espresso'), |
|
619 | - $type, |
|
620 | - $file, |
|
621 | - $line |
|
622 | - ), |
|
623 | - EVENT_ESPRESSO_VERSION |
|
624 | - ); |
|
625 | - } |
|
626 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
627 | - EE_Error::doing_it_wrong( |
|
628 | - 'EE_Error::add_error()', |
|
629 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
630 | - 'event_espresso'), |
|
631 | - EVENT_ESPRESSO_VERSION |
|
632 | - ); |
|
633 | - } |
|
634 | - // get separate user and developer messages if they exist |
|
635 | - $msg = explode('||', $msg); |
|
636 | - $user_msg = $msg[0]; |
|
637 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
638 | - /** |
|
639 | - * Do an action so other code can be triggered when a notice is created |
|
640 | - * |
|
641 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
642 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
643 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
644 | - * @param string $file file where error was generated |
|
645 | - * @param string $func function where error was generated |
|
646 | - * @param string $line line where error was generated |
|
647 | - */ |
|
648 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
649 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
650 | - // add notice if message exists |
|
651 | - if (! empty($msg)) { |
|
652 | - // get error code |
|
653 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
654 | - if (WP_DEBUG && $type === 'errors') { |
|
655 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
656 | - } |
|
657 | - // add notice. Index by code if it's not blank |
|
658 | - if ($notice_code) { |
|
659 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
660 | - } else { |
|
661 | - self::$_espresso_notices[$type][] = $msg; |
|
662 | - } |
|
663 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
664 | - } |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * in some case it may be necessary to overwrite the existing success messages |
|
670 | - * |
|
671 | - * @return void |
|
672 | - */ |
|
673 | - public static function overwrite_success() |
|
674 | - { |
|
675 | - self::$_espresso_notices['success'] = false; |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * in some case it may be necessary to overwrite the existing attention messages |
|
682 | - * |
|
683 | - * @return void |
|
684 | - */ |
|
685 | - public static function overwrite_attention() |
|
686 | - { |
|
687 | - self::$_espresso_notices['attention'] = false; |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * in some case it may be necessary to overwrite the existing error messages |
|
694 | - * |
|
695 | - * @return void |
|
696 | - */ |
|
697 | - public static function overwrite_errors() |
|
698 | - { |
|
699 | - self::$_espresso_notices['errors'] = false; |
|
700 | - } |
|
701 | - |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * @return void |
|
706 | - */ |
|
707 | - public static function reset_notices() |
|
708 | - { |
|
709 | - self::$_espresso_notices['success'] = false; |
|
710 | - self::$_espresso_notices['attention'] = false; |
|
711 | - self::$_espresso_notices['errors'] = false; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * @return int |
|
718 | - */ |
|
719 | - public static function has_notices() |
|
720 | - { |
|
721 | - $has_notices = 0; |
|
722 | - // check for success messages |
|
723 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
724 | - ? 3 |
|
725 | - : $has_notices; |
|
726 | - // check for attention messages |
|
727 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
728 | - ? 2 |
|
729 | - : $has_notices; |
|
730 | - // check for error messages |
|
731 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
732 | - ? 1 |
|
733 | - : $has_notices; |
|
734 | - return $has_notices; |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
740 | - * |
|
741 | - * @since 4.9.0 |
|
742 | - * @return array |
|
743 | - */ |
|
744 | - public static function get_vanilla_notices() |
|
745 | - { |
|
746 | - return array( |
|
747 | - 'success' => isset(self::$_espresso_notices['success']) |
|
748 | - ? self::$_espresso_notices['success'] |
|
749 | - : array(), |
|
750 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
751 | - ? self::$_espresso_notices['attention'] |
|
752 | - : array(), |
|
753 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
754 | - ? self::$_espresso_notices['errors'] |
|
755 | - : array(), |
|
756 | - ); |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * compile all error or success messages into one string |
|
763 | - * |
|
764 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
765 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
766 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
767 | - * - ONLY do this just before redirecting |
|
768 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
769 | - * @return array |
|
770 | - */ |
|
771 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
772 | - { |
|
773 | - // do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
774 | - $success_messages = ''; |
|
775 | - $attention_messages = ''; |
|
776 | - $error_messages = ''; |
|
777 | - $print_scripts = false; |
|
778 | - // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
779 | - // either save notices to the db |
|
780 | - if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
781 | - $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | - $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
|
783 | - self::$_espresso_notices = array_merge( |
|
784 | - $existing_notices, |
|
785 | - self::$_espresso_notices |
|
786 | - ); |
|
787 | - update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices); |
|
788 | - return array(); |
|
789 | - } |
|
790 | - // grab any notices that have been previously saved |
|
791 | - if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) { |
|
792 | - foreach ($notices as $type => $notice) { |
|
793 | - if (is_array($notice) && ! empty($notice)) { |
|
794 | - // make sure that existing notice type is an array |
|
795 | - self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
796 | - && ! empty(self::$_espresso_notices[$type]) |
|
797 | - ? self::$_espresso_notices[$type] |
|
798 | - : array(); |
|
799 | - // merge stored notices with any newly created ones |
|
800 | - self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
801 | - $print_scripts = true; |
|
802 | - } |
|
803 | - } |
|
804 | - // now clear any stored notices |
|
805 | - update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
806 | - } |
|
807 | - // check for success messages |
|
808 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
809 | - // combine messages |
|
810 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
811 | - $print_scripts = true; |
|
812 | - } |
|
813 | - // check for attention messages |
|
814 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
815 | - // combine messages |
|
816 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
817 | - $print_scripts = true; |
|
818 | - } |
|
819 | - // check for error messages |
|
820 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
821 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
822 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
823 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
824 | - // combine messages |
|
825 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
826 | - $print_scripts = true; |
|
827 | - } |
|
828 | - if ($format_output) { |
|
829 | - |
|
830 | - $notices = '<div id="espresso-notices">'; |
|
831 | - $close = is_admin() ? '' |
|
832 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
833 | - if ($success_messages !== '') { |
|
834 | - $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
835 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
836 | - //showMessage( $success_messages ); |
|
837 | - $notices .= '<div id="' |
|
838 | - . $css_id |
|
839 | - . '" class="espresso-notices ' |
|
840 | - . $css_class |
|
841 | - . '" style="display:none;"><p>' |
|
842 | - . $success_messages |
|
843 | - . '</p>' |
|
844 | - . $close |
|
845 | - . '</div>'; |
|
846 | - } |
|
847 | - if ($attention_messages !== '') { |
|
848 | - $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
849 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
850 | - //showMessage( $error_messages, TRUE ); |
|
851 | - $notices .= '<div id="' |
|
852 | - . $css_id |
|
853 | - . '" class="espresso-notices ' |
|
854 | - . $css_class |
|
855 | - . '" style="display:none;"><p>' |
|
856 | - . $attention_messages |
|
857 | - . '</p>' |
|
858 | - . $close |
|
859 | - . '</div>'; |
|
860 | - } |
|
861 | - if ($error_messages !== '') { |
|
862 | - $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
863 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
864 | - //showMessage( $error_messages, TRUE ); |
|
865 | - $notices .= '<div id="' |
|
866 | - . $css_id |
|
867 | - . '" class="espresso-notices ' |
|
868 | - . $css_class |
|
869 | - . '" style="display:none;"><p>' |
|
870 | - . $error_messages |
|
871 | - . '</p>' |
|
872 | - . $close |
|
873 | - . '</div>'; |
|
874 | - } |
|
875 | - $notices .= '</div>'; |
|
876 | - } else { |
|
877 | - |
|
878 | - $notices = array( |
|
879 | - 'success' => $success_messages, |
|
880 | - 'attention' => $attention_messages, |
|
881 | - 'errors' => $error_messages, |
|
882 | - ); |
|
883 | - if ($remove_empty) { |
|
884 | - // remove empty notices |
|
885 | - foreach ($notices as $type => $notice) { |
|
886 | - if (empty($notice)) { |
|
887 | - unset($notices[$type]); |
|
888 | - } |
|
889 | - } |
|
890 | - } |
|
891 | - } |
|
892 | - if ($print_scripts) { |
|
893 | - self::_print_scripts(); |
|
894 | - } |
|
895 | - return $notices; |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * _print_scripts |
|
902 | - * |
|
903 | - * @param bool $force_print |
|
904 | - * @return string |
|
905 | - */ |
|
906 | - private static function _print_scripts($force_print = false) |
|
907 | - { |
|
908 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
910 | - return ''; |
|
911 | - } |
|
912 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
913 | - wp_enqueue_style('espresso_default'); |
|
914 | - wp_enqueue_style('espresso_custom_css'); |
|
915 | - wp_enqueue_script('ee_error_js'); |
|
916 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
917 | - } |
|
918 | - } else { |
|
919 | - return ' |
|
478 | + $output .= self::_print_scripts(true); |
|
479 | + if (defined('DOING_AJAX')) { |
|
480 | + echo wp_json_encode(array('error' => $output)); |
|
481 | + exit(); |
|
482 | + } |
|
483 | + echo $output; |
|
484 | + die(); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * generate string from exception trace args |
|
491 | + * |
|
492 | + * @param array $arguments |
|
493 | + * @param bool $array |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
497 | + { |
|
498 | + $arg_string = ''; |
|
499 | + if (! empty($arguments)) { |
|
500 | + $args = array(); |
|
501 | + foreach ($arguments as $arg) { |
|
502 | + if (! empty($arg)) { |
|
503 | + if (is_string($arg)) { |
|
504 | + $args[] = " '" . $arg . "'"; |
|
505 | + } elseif (is_array($arg)) { |
|
506 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
507 | + } elseif ($arg === null) { |
|
508 | + $args[] = ' NULL'; |
|
509 | + } elseif (is_bool($arg)) { |
|
510 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
511 | + } elseif (is_object($arg)) { |
|
512 | + $args[] = ' OBJECT ' . get_class($arg); |
|
513 | + } elseif (is_resource($arg)) { |
|
514 | + $args[] = get_resource_type($arg); |
|
515 | + } else { |
|
516 | + $args[] = $arg; |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | + $arg_string = implode(', ', $args); |
|
521 | + } |
|
522 | + if ($array) { |
|
523 | + $arg_string .= ' )'; |
|
524 | + } |
|
525 | + return $arg_string; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * add error message |
|
532 | + * |
|
533 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
534 | + * separate messages for user || dev |
|
535 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
536 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
537 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
538 | + * @return void |
|
539 | + */ |
|
540 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
541 | + { |
|
542 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
543 | + self::$_error_count++; |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
550 | + * adds an error |
|
551 | + * |
|
552 | + * @param string $msg |
|
553 | + * @param string $file |
|
554 | + * @param string $func |
|
555 | + * @param string $line |
|
556 | + * @throws EE_Error |
|
557 | + */ |
|
558 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
559 | + { |
|
560 | + if (WP_DEBUG) { |
|
561 | + throw new EE_Error($msg); |
|
562 | + } |
|
563 | + EE_Error::add_error($msg, $file, $func, $line); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * add success message |
|
570 | + * |
|
571 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
572 | + * separate messages for user || dev |
|
573 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
574 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
575 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
576 | + * @return void |
|
577 | + */ |
|
578 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
579 | + { |
|
580 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * add attention message |
|
587 | + * |
|
588 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
589 | + * separate messages for user || dev |
|
590 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
591 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
592 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
593 | + * @return void |
|
594 | + */ |
|
595 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
596 | + { |
|
597 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * @param string $type whether the message is for a success or error notification |
|
604 | + * @param string $msg the message to display to users or developers |
|
605 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
606 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
607 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
608 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
609 | + * @return void |
|
610 | + */ |
|
611 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
612 | + { |
|
613 | + if (empty($msg)) { |
|
614 | + EE_Error::doing_it_wrong( |
|
615 | + 'EE_Error::add_' . $type . '()', |
|
616 | + sprintf( |
|
617 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
618 | + 'event_espresso'), |
|
619 | + $type, |
|
620 | + $file, |
|
621 | + $line |
|
622 | + ), |
|
623 | + EVENT_ESPRESSO_VERSION |
|
624 | + ); |
|
625 | + } |
|
626 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
627 | + EE_Error::doing_it_wrong( |
|
628 | + 'EE_Error::add_error()', |
|
629 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
630 | + 'event_espresso'), |
|
631 | + EVENT_ESPRESSO_VERSION |
|
632 | + ); |
|
633 | + } |
|
634 | + // get separate user and developer messages if they exist |
|
635 | + $msg = explode('||', $msg); |
|
636 | + $user_msg = $msg[0]; |
|
637 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
638 | + /** |
|
639 | + * Do an action so other code can be triggered when a notice is created |
|
640 | + * |
|
641 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
642 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
643 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
644 | + * @param string $file file where error was generated |
|
645 | + * @param string $func function where error was generated |
|
646 | + * @param string $line line where error was generated |
|
647 | + */ |
|
648 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
649 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
650 | + // add notice if message exists |
|
651 | + if (! empty($msg)) { |
|
652 | + // get error code |
|
653 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
654 | + if (WP_DEBUG && $type === 'errors') { |
|
655 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
656 | + } |
|
657 | + // add notice. Index by code if it's not blank |
|
658 | + if ($notice_code) { |
|
659 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
660 | + } else { |
|
661 | + self::$_espresso_notices[$type][] = $msg; |
|
662 | + } |
|
663 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
664 | + } |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * in some case it may be necessary to overwrite the existing success messages |
|
670 | + * |
|
671 | + * @return void |
|
672 | + */ |
|
673 | + public static function overwrite_success() |
|
674 | + { |
|
675 | + self::$_espresso_notices['success'] = false; |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * in some case it may be necessary to overwrite the existing attention messages |
|
682 | + * |
|
683 | + * @return void |
|
684 | + */ |
|
685 | + public static function overwrite_attention() |
|
686 | + { |
|
687 | + self::$_espresso_notices['attention'] = false; |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * in some case it may be necessary to overwrite the existing error messages |
|
694 | + * |
|
695 | + * @return void |
|
696 | + */ |
|
697 | + public static function overwrite_errors() |
|
698 | + { |
|
699 | + self::$_espresso_notices['errors'] = false; |
|
700 | + } |
|
701 | + |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * @return void |
|
706 | + */ |
|
707 | + public static function reset_notices() |
|
708 | + { |
|
709 | + self::$_espresso_notices['success'] = false; |
|
710 | + self::$_espresso_notices['attention'] = false; |
|
711 | + self::$_espresso_notices['errors'] = false; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * @return int |
|
718 | + */ |
|
719 | + public static function has_notices() |
|
720 | + { |
|
721 | + $has_notices = 0; |
|
722 | + // check for success messages |
|
723 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
724 | + ? 3 |
|
725 | + : $has_notices; |
|
726 | + // check for attention messages |
|
727 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
728 | + ? 2 |
|
729 | + : $has_notices; |
|
730 | + // check for error messages |
|
731 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
732 | + ? 1 |
|
733 | + : $has_notices; |
|
734 | + return $has_notices; |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
740 | + * |
|
741 | + * @since 4.9.0 |
|
742 | + * @return array |
|
743 | + */ |
|
744 | + public static function get_vanilla_notices() |
|
745 | + { |
|
746 | + return array( |
|
747 | + 'success' => isset(self::$_espresso_notices['success']) |
|
748 | + ? self::$_espresso_notices['success'] |
|
749 | + : array(), |
|
750 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
751 | + ? self::$_espresso_notices['attention'] |
|
752 | + : array(), |
|
753 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
754 | + ? self::$_espresso_notices['errors'] |
|
755 | + : array(), |
|
756 | + ); |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * compile all error or success messages into one string |
|
763 | + * |
|
764 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
765 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
766 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
767 | + * - ONLY do this just before redirecting |
|
768 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
769 | + * @return array |
|
770 | + */ |
|
771 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
772 | + { |
|
773 | + // do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
774 | + $success_messages = ''; |
|
775 | + $attention_messages = ''; |
|
776 | + $error_messages = ''; |
|
777 | + $print_scripts = false; |
|
778 | + // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
779 | + // either save notices to the db |
|
780 | + if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
781 | + $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | + $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
|
783 | + self::$_espresso_notices = array_merge( |
|
784 | + $existing_notices, |
|
785 | + self::$_espresso_notices |
|
786 | + ); |
|
787 | + update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices); |
|
788 | + return array(); |
|
789 | + } |
|
790 | + // grab any notices that have been previously saved |
|
791 | + if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) { |
|
792 | + foreach ($notices as $type => $notice) { |
|
793 | + if (is_array($notice) && ! empty($notice)) { |
|
794 | + // make sure that existing notice type is an array |
|
795 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
796 | + && ! empty(self::$_espresso_notices[$type]) |
|
797 | + ? self::$_espresso_notices[$type] |
|
798 | + : array(); |
|
799 | + // merge stored notices with any newly created ones |
|
800 | + self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
801 | + $print_scripts = true; |
|
802 | + } |
|
803 | + } |
|
804 | + // now clear any stored notices |
|
805 | + update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
806 | + } |
|
807 | + // check for success messages |
|
808 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
809 | + // combine messages |
|
810 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
811 | + $print_scripts = true; |
|
812 | + } |
|
813 | + // check for attention messages |
|
814 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
815 | + // combine messages |
|
816 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
817 | + $print_scripts = true; |
|
818 | + } |
|
819 | + // check for error messages |
|
820 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
821 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
822 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
823 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
824 | + // combine messages |
|
825 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
826 | + $print_scripts = true; |
|
827 | + } |
|
828 | + if ($format_output) { |
|
829 | + |
|
830 | + $notices = '<div id="espresso-notices">'; |
|
831 | + $close = is_admin() ? '' |
|
832 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
833 | + if ($success_messages !== '') { |
|
834 | + $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
835 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
836 | + //showMessage( $success_messages ); |
|
837 | + $notices .= '<div id="' |
|
838 | + . $css_id |
|
839 | + . '" class="espresso-notices ' |
|
840 | + . $css_class |
|
841 | + . '" style="display:none;"><p>' |
|
842 | + . $success_messages |
|
843 | + . '</p>' |
|
844 | + . $close |
|
845 | + . '</div>'; |
|
846 | + } |
|
847 | + if ($attention_messages !== '') { |
|
848 | + $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
849 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
850 | + //showMessage( $error_messages, TRUE ); |
|
851 | + $notices .= '<div id="' |
|
852 | + . $css_id |
|
853 | + . '" class="espresso-notices ' |
|
854 | + . $css_class |
|
855 | + . '" style="display:none;"><p>' |
|
856 | + . $attention_messages |
|
857 | + . '</p>' |
|
858 | + . $close |
|
859 | + . '</div>'; |
|
860 | + } |
|
861 | + if ($error_messages !== '') { |
|
862 | + $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
863 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
864 | + //showMessage( $error_messages, TRUE ); |
|
865 | + $notices .= '<div id="' |
|
866 | + . $css_id |
|
867 | + . '" class="espresso-notices ' |
|
868 | + . $css_class |
|
869 | + . '" style="display:none;"><p>' |
|
870 | + . $error_messages |
|
871 | + . '</p>' |
|
872 | + . $close |
|
873 | + . '</div>'; |
|
874 | + } |
|
875 | + $notices .= '</div>'; |
|
876 | + } else { |
|
877 | + |
|
878 | + $notices = array( |
|
879 | + 'success' => $success_messages, |
|
880 | + 'attention' => $attention_messages, |
|
881 | + 'errors' => $error_messages, |
|
882 | + ); |
|
883 | + if ($remove_empty) { |
|
884 | + // remove empty notices |
|
885 | + foreach ($notices as $type => $notice) { |
|
886 | + if (empty($notice)) { |
|
887 | + unset($notices[$type]); |
|
888 | + } |
|
889 | + } |
|
890 | + } |
|
891 | + } |
|
892 | + if ($print_scripts) { |
|
893 | + self::_print_scripts(); |
|
894 | + } |
|
895 | + return $notices; |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * _print_scripts |
|
902 | + * |
|
903 | + * @param bool $force_print |
|
904 | + * @return string |
|
905 | + */ |
|
906 | + private static function _print_scripts($force_print = false) |
|
907 | + { |
|
908 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
910 | + return ''; |
|
911 | + } |
|
912 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
913 | + wp_enqueue_style('espresso_default'); |
|
914 | + wp_enqueue_style('espresso_custom_css'); |
|
915 | + wp_enqueue_script('ee_error_js'); |
|
916 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
917 | + } |
|
918 | + } else { |
|
919 | + return ' |
|
920 | 920 | <script> |
921 | 921 | /* <![CDATA[ */ |
922 | 922 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -926,223 +926,223 @@ discard block |
||
926 | 926 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
927 | 927 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
928 | 928 | '; |
929 | - } |
|
930 | - return ''; |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - |
|
935 | - /** |
|
936 | - * @return void |
|
937 | - */ |
|
938 | - public static function enqueue_error_scripts() |
|
939 | - { |
|
940 | - self::_print_scripts(); |
|
941 | - } |
|
942 | - |
|
943 | - |
|
944 | - |
|
945 | - /** |
|
946 | - * create error code from filepath, function name, |
|
947 | - * and line number where exception or error was thrown |
|
948 | - * |
|
949 | - * @param string $file |
|
950 | - * @param string $func |
|
951 | - * @param string $line |
|
952 | - * @return string |
|
953 | - */ |
|
954 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
955 | - { |
|
956 | - $file = explode('.', basename($file)); |
|
957 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
958 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
960 | - return $error_code; |
|
961 | - } |
|
962 | - |
|
963 | - |
|
964 | - |
|
965 | - /** |
|
966 | - * write exception details to log file |
|
967 | - * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
968 | - * |
|
969 | - * @param int $time |
|
970 | - * @param array $ex |
|
971 | - * @param bool $clear |
|
972 | - * @return void |
|
973 | - */ |
|
974 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
975 | - { |
|
976 | - if (empty($ex)) { |
|
977 | - return; |
|
978 | - } |
|
979 | - if (! $time) { |
|
980 | - $time = time(); |
|
981 | - } |
|
982 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
983 | - . PHP_EOL; |
|
984 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
991 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
992 | - . PHP_EOL; |
|
993 | - try { |
|
994 | - error_log($exception_log); |
|
995 | - } catch (EE_Error $e) { |
|
996 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
997 | - 'event_espresso'), $e->getMessage())); |
|
998 | - } |
|
999 | - } |
|
1000 | - |
|
1001 | - |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1005 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1006 | - * but the code execution is done in a manner that could lead to unexpected results |
|
1007 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
1008 | - * A good test for knowing whether to use this method is: |
|
1009 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1010 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1011 | - * 2. If this is loaded before something else, it won't break anything, |
|
1012 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1013 | - * |
|
1014 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1015 | - * @param string $function The function that was called |
|
1016 | - * @param string $message A message explaining what has been done incorrectly |
|
1017 | - * @param string $version The version of Event Espresso where the error was added |
|
1018 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1019 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
1020 | - * but not have any notices appear until a later version. This allows developers |
|
1021 | - * extra time to update their code before notices appear. |
|
1022 | - * @param int $error_type |
|
1023 | - */ |
|
1024 | - public static function doing_it_wrong( |
|
1025 | - $function, |
|
1026 | - $message, |
|
1027 | - $version, |
|
1028 | - $applies_when = '', |
|
1029 | - $error_type = null |
|
1030 | - ) { |
|
1031 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1032 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1033 | - } |
|
1034 | - } |
|
1035 | - |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
1040 | - * |
|
1041 | - * @return array { |
|
1042 | - * @type array $success all the success messages |
|
1043 | - * @type array $errors all the error messages |
|
1044 | - * @type array $attention all the attention messages |
|
1045 | - * } |
|
1046 | - */ |
|
1047 | - public static function get_raw_notices() |
|
1048 | - { |
|
1049 | - return self::$_espresso_notices; |
|
1050 | - } |
|
1051 | - |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * @deprecated 4.9.27 |
|
1056 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1057 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1058 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1059 | - * @return void |
|
1060 | - * @throws InvalidDataTypeException |
|
1061 | - */ |
|
1062 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1063 | - { |
|
1064 | - new PersistentAdminNotice( |
|
1065 | - $pan_name, |
|
1066 | - $pan_message, |
|
1067 | - $force_update |
|
1068 | - ); |
|
1069 | - EE_Error::doing_it_wrong( |
|
1070 | - __METHOD__, |
|
1071 | - sprintf( |
|
1072 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1073 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1074 | - ), |
|
1075 | - '4.9.27' |
|
1076 | - ); |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * @deprecated 4.9.27 |
|
1083 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1084 | - * @param bool $purge |
|
1085 | - * @param bool $return |
|
1086 | - * @throws DomainException |
|
1087 | - * @throws InvalidInterfaceException |
|
1088 | - * @throws InvalidDataTypeException |
|
1089 | - * @throws ServiceNotFoundException |
|
1090 | - * @throws InvalidArgumentException |
|
1091 | - */ |
|
1092 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1093 | - { |
|
1094 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1095 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1096 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1097 | - ); |
|
1098 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1099 | - EE_Error::doing_it_wrong( |
|
1100 | - __METHOD__, |
|
1101 | - sprintf( |
|
1102 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1103 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1104 | - ), |
|
1105 | - '4.9.27' |
|
1106 | - ); |
|
1107 | - } |
|
1108 | - |
|
1109 | - |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * @deprecated 4.9.27 |
|
1113 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1114 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1115 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
1116 | - */ |
|
1117 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1118 | - { |
|
1119 | - EE_Error::doing_it_wrong( |
|
1120 | - __METHOD__, |
|
1121 | - sprintf( |
|
1122 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1123 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1124 | - ), |
|
1125 | - '4.9.27' |
|
1126 | - ); |
|
1127 | - } |
|
1128 | - |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * @deprecated 4.9.27 |
|
1133 | - * @param string $return_url |
|
1134 | - */ |
|
1135 | - public static function get_persistent_admin_notices($return_url = '') |
|
1136 | - { |
|
1137 | - EE_Error::doing_it_wrong( |
|
1138 | - __METHOD__, |
|
1139 | - sprintf( |
|
1140 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1141 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1142 | - ), |
|
1143 | - '4.9.27' |
|
1144 | - ); |
|
1145 | - } |
|
929 | + } |
|
930 | + return ''; |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + |
|
935 | + /** |
|
936 | + * @return void |
|
937 | + */ |
|
938 | + public static function enqueue_error_scripts() |
|
939 | + { |
|
940 | + self::_print_scripts(); |
|
941 | + } |
|
942 | + |
|
943 | + |
|
944 | + |
|
945 | + /** |
|
946 | + * create error code from filepath, function name, |
|
947 | + * and line number where exception or error was thrown |
|
948 | + * |
|
949 | + * @param string $file |
|
950 | + * @param string $func |
|
951 | + * @param string $line |
|
952 | + * @return string |
|
953 | + */ |
|
954 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
955 | + { |
|
956 | + $file = explode('.', basename($file)); |
|
957 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
958 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
960 | + return $error_code; |
|
961 | + } |
|
962 | + |
|
963 | + |
|
964 | + |
|
965 | + /** |
|
966 | + * write exception details to log file |
|
967 | + * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
968 | + * |
|
969 | + * @param int $time |
|
970 | + * @param array $ex |
|
971 | + * @param bool $clear |
|
972 | + * @return void |
|
973 | + */ |
|
974 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
975 | + { |
|
976 | + if (empty($ex)) { |
|
977 | + return; |
|
978 | + } |
|
979 | + if (! $time) { |
|
980 | + $time = time(); |
|
981 | + } |
|
982 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
983 | + . PHP_EOL; |
|
984 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
991 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
992 | + . PHP_EOL; |
|
993 | + try { |
|
994 | + error_log($exception_log); |
|
995 | + } catch (EE_Error $e) { |
|
996 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
997 | + 'event_espresso'), $e->getMessage())); |
|
998 | + } |
|
999 | + } |
|
1000 | + |
|
1001 | + |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1005 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1006 | + * but the code execution is done in a manner that could lead to unexpected results |
|
1007 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
1008 | + * A good test for knowing whether to use this method is: |
|
1009 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1010 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1011 | + * 2. If this is loaded before something else, it won't break anything, |
|
1012 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1013 | + * |
|
1014 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1015 | + * @param string $function The function that was called |
|
1016 | + * @param string $message A message explaining what has been done incorrectly |
|
1017 | + * @param string $version The version of Event Espresso where the error was added |
|
1018 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1019 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
1020 | + * but not have any notices appear until a later version. This allows developers |
|
1021 | + * extra time to update their code before notices appear. |
|
1022 | + * @param int $error_type |
|
1023 | + */ |
|
1024 | + public static function doing_it_wrong( |
|
1025 | + $function, |
|
1026 | + $message, |
|
1027 | + $version, |
|
1028 | + $applies_when = '', |
|
1029 | + $error_type = null |
|
1030 | + ) { |
|
1031 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1032 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1033 | + } |
|
1034 | + } |
|
1035 | + |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
1040 | + * |
|
1041 | + * @return array { |
|
1042 | + * @type array $success all the success messages |
|
1043 | + * @type array $errors all the error messages |
|
1044 | + * @type array $attention all the attention messages |
|
1045 | + * } |
|
1046 | + */ |
|
1047 | + public static function get_raw_notices() |
|
1048 | + { |
|
1049 | + return self::$_espresso_notices; |
|
1050 | + } |
|
1051 | + |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * @deprecated 4.9.27 |
|
1056 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1057 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1058 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1059 | + * @return void |
|
1060 | + * @throws InvalidDataTypeException |
|
1061 | + */ |
|
1062 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1063 | + { |
|
1064 | + new PersistentAdminNotice( |
|
1065 | + $pan_name, |
|
1066 | + $pan_message, |
|
1067 | + $force_update |
|
1068 | + ); |
|
1069 | + EE_Error::doing_it_wrong( |
|
1070 | + __METHOD__, |
|
1071 | + sprintf( |
|
1072 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1073 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1074 | + ), |
|
1075 | + '4.9.27' |
|
1076 | + ); |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * @deprecated 4.9.27 |
|
1083 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1084 | + * @param bool $purge |
|
1085 | + * @param bool $return |
|
1086 | + * @throws DomainException |
|
1087 | + * @throws InvalidInterfaceException |
|
1088 | + * @throws InvalidDataTypeException |
|
1089 | + * @throws ServiceNotFoundException |
|
1090 | + * @throws InvalidArgumentException |
|
1091 | + */ |
|
1092 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1093 | + { |
|
1094 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1095 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1096 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1097 | + ); |
|
1098 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1099 | + EE_Error::doing_it_wrong( |
|
1100 | + __METHOD__, |
|
1101 | + sprintf( |
|
1102 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1103 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1104 | + ), |
|
1105 | + '4.9.27' |
|
1106 | + ); |
|
1107 | + } |
|
1108 | + |
|
1109 | + |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * @deprecated 4.9.27 |
|
1113 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1114 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1115 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
1116 | + */ |
|
1117 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1118 | + { |
|
1119 | + EE_Error::doing_it_wrong( |
|
1120 | + __METHOD__, |
|
1121 | + sprintf( |
|
1122 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1123 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1124 | + ), |
|
1125 | + '4.9.27' |
|
1126 | + ); |
|
1127 | + } |
|
1128 | + |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * @deprecated 4.9.27 |
|
1133 | + * @param string $return_url |
|
1134 | + */ |
|
1135 | + public static function get_persistent_admin_notices($return_url = '') |
|
1136 | + { |
|
1137 | + EE_Error::doing_it_wrong( |
|
1138 | + __METHOD__, |
|
1139 | + sprintf( |
|
1140 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1141 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1142 | + ), |
|
1143 | + '4.9.27' |
|
1144 | + ); |
|
1145 | + } |
|
1146 | 1146 | |
1147 | 1147 | |
1148 | 1148 | |
@@ -1157,27 +1157,27 @@ discard block |
||
1157 | 1157 | */ |
1158 | 1158 | function espresso_error_enqueue_scripts() |
1159 | 1159 | { |
1160 | - // js for error handling |
|
1161 | - wp_register_script( |
|
1162 | - 'espresso_core', |
|
1163 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1164 | - array('jquery'), |
|
1165 | - EVENT_ESPRESSO_VERSION, |
|
1166 | - false |
|
1167 | - ); |
|
1168 | - wp_register_script( |
|
1169 | - 'ee_error_js', |
|
1170 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1171 | - array('espresso_core'), |
|
1172 | - EVENT_ESPRESSO_VERSION, |
|
1173 | - false |
|
1174 | - ); |
|
1160 | + // js for error handling |
|
1161 | + wp_register_script( |
|
1162 | + 'espresso_core', |
|
1163 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1164 | + array('jquery'), |
|
1165 | + EVENT_ESPRESSO_VERSION, |
|
1166 | + false |
|
1167 | + ); |
|
1168 | + wp_register_script( |
|
1169 | + 'ee_error_js', |
|
1170 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1171 | + array('espresso_core'), |
|
1172 | + EVENT_ESPRESSO_VERSION, |
|
1173 | + false |
|
1174 | + ); |
|
1175 | 1175 | } |
1176 | 1176 | |
1177 | 1177 | if (is_admin()) { |
1178 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1178 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1179 | 1179 | } else { |
1180 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1180 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | default : |
104 | 104 | $to = get_option('admin_email'); |
105 | 105 | } |
106 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
106 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
107 | 107 | $msg = EE_Error::_format_error($type, $message, $file, $line); |
108 | 108 | if (function_exists('wp_mail')) { |
109 | 109 | add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
110 | 110 | wp_mail($to, $subject, $msg); |
111 | 111 | } |
112 | 112 | echo '<div id="message" class="espresso-notices error"><p>'; |
113 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
113 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
114 | 114 | echo '<br /></p></div>'; |
115 | 115 | } |
116 | 116 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | ? true |
258 | 258 | : false; |
259 | 259 | if ($check_stored && ! $has_error) { |
260 | - $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
260 | + $notices = (array) get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | 261 | foreach ($notices as $type => $notice) { |
262 | 262 | if ($type === $type_to_check && $notice) { |
263 | 263 | return true; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | } |
333 | 333 | </style> |
334 | 334 | <div id="ee-error-message" class="error">'; |
335 | - if (! WP_DEBUG) { |
|
335 | + if ( ! WP_DEBUG) { |
|
336 | 336 | $output .= ' |
337 | 337 | <p>'; |
338 | 338 | } |
@@ -391,14 +391,14 @@ discard block |
||
391 | 391 | $class_dsply = ! empty($class) ? $class : ' '; |
392 | 392 | $type_dsply = ! empty($type) ? $type : ' '; |
393 | 393 | $function_dsply = ! empty($function) ? $function : ' '; |
394 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
394 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
395 | 395 | $trace_details .= ' |
396 | 396 | <tr> |
397 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
398 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
399 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
400 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
401 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
397 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
398 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
399 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
400 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
401 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
402 | 402 | </tr>'; |
403 | 403 | } |
404 | 404 | $trace_details .= ' |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | } |
408 | 408 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
409 | 409 | // add generic non-identifying messages for non-privileged users |
410 | - if (! WP_DEBUG) { |
|
410 | + if ( ! WP_DEBUG) { |
|
411 | 411 | $output .= '<span class="ee-error-user-msg-spn">' |
412 | 412 | . trim($ex['msg']) |
413 | 413 | . '</span> <sup>' |
@@ -449,14 +449,14 @@ discard block |
||
449 | 449 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
450 | 450 | ' |
451 | 451 | . $trace_details; |
452 | - if (! empty($class)) { |
|
452 | + if ( ! empty($class)) { |
|
453 | 453 | $output .= ' |
454 | 454 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
455 | 455 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
456 | 456 | <h3>Class Details</h3>'; |
457 | 457 | $a = new ReflectionClass($class); |
458 | 458 | $output .= ' |
459 | - <pre>' . $a . '</pre> |
|
459 | + <pre>' . $a.'</pre> |
|
460 | 460 | </div> |
461 | 461 | </div>'; |
462 | 462 | } |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | } |
470 | 470 | // remove last linebreak |
471 | 471 | $output = substr($output, 0, -6); |
472 | - if (! WP_DEBUG) { |
|
472 | + if ( ! WP_DEBUG) { |
|
473 | 473 | $output .= ' |
474 | 474 | </p>'; |
475 | 475 | } |
@@ -496,20 +496,20 @@ discard block |
||
496 | 496 | private function _convert_args_to_string($arguments = array(), $array = false) |
497 | 497 | { |
498 | 498 | $arg_string = ''; |
499 | - if (! empty($arguments)) { |
|
499 | + if ( ! empty($arguments)) { |
|
500 | 500 | $args = array(); |
501 | 501 | foreach ($arguments as $arg) { |
502 | - if (! empty($arg)) { |
|
502 | + if ( ! empty($arg)) { |
|
503 | 503 | if (is_string($arg)) { |
504 | - $args[] = " '" . $arg . "'"; |
|
504 | + $args[] = " '".$arg."'"; |
|
505 | 505 | } elseif (is_array($arg)) { |
506 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
506 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true); |
|
507 | 507 | } elseif ($arg === null) { |
508 | 508 | $args[] = ' NULL'; |
509 | 509 | } elseif (is_bool($arg)) { |
510 | 510 | $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
511 | 511 | } elseif (is_object($arg)) { |
512 | - $args[] = ' OBJECT ' . get_class($arg); |
|
512 | + $args[] = ' OBJECT '.get_class($arg); |
|
513 | 513 | } elseif (is_resource($arg)) { |
514 | 514 | $args[] = get_resource_type($arg); |
515 | 515 | } else { |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | { |
613 | 613 | if (empty($msg)) { |
614 | 614 | EE_Error::doing_it_wrong( |
615 | - 'EE_Error::add_' . $type . '()', |
|
615 | + 'EE_Error::add_'.$type.'()', |
|
616 | 616 | sprintf( |
617 | 617 | __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
618 | 618 | 'event_espresso'), |
@@ -648,11 +648,11 @@ discard block |
||
648 | 648 | do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
649 | 649 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
650 | 650 | // add notice if message exists |
651 | - if (! empty($msg)) { |
|
651 | + if ( ! empty($msg)) { |
|
652 | 652 | // get error code |
653 | 653 | $notice_code = EE_Error::generate_error_code($file, $func, $line); |
654 | 654 | if (WP_DEBUG && $type === 'errors') { |
655 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
655 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
656 | 656 | } |
657 | 657 | // add notice. Index by code if it's not blank |
658 | 658 | if ($notice_code) { |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
779 | 779 | // either save notices to the db |
780 | 780 | if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
781 | - $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
781 | + $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | 782 | $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
783 | 783 | self::$_espresso_notices = array_merge( |
784 | 784 | $existing_notices, |
@@ -808,13 +808,13 @@ discard block |
||
808 | 808 | if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
809 | 809 | // combine messages |
810 | 810 | $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
811 | - $print_scripts = true; |
|
811 | + $print_scripts = true; |
|
812 | 812 | } |
813 | 813 | // check for attention messages |
814 | 814 | if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
815 | 815 | // combine messages |
816 | 816 | $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
817 | - $print_scripts = true; |
|
817 | + $print_scripts = true; |
|
818 | 818 | } |
819 | 819 | // check for error messages |
820 | 820 | if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | : __('An error has occurred:<br />', 'event_espresso'); |
824 | 824 | // combine messages |
825 | 825 | $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
826 | - $print_scripts = true; |
|
826 | + $print_scripts = true; |
|
827 | 827 | } |
828 | 828 | if ($format_output) { |
829 | 829 | |
@@ -905,7 +905,7 @@ discard block |
||
905 | 905 | */ |
906 | 906 | private static function _print_scripts($force_print = false) |
907 | 907 | { |
908 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
908 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | 909 | if (wp_script_is('ee_error_js', 'enqueued')) { |
910 | 910 | return ''; |
911 | 911 | } |
@@ -919,12 +919,12 @@ discard block |
||
919 | 919 | return ' |
920 | 920 | <script> |
921 | 921 | /* <![CDATA[ */ |
922 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
922 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
923 | 923 | /* ]]> */ |
924 | 924 | </script> |
925 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
926 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
927 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
925 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
926 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
927 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
928 | 928 | '; |
929 | 929 | } |
930 | 930 | return ''; |
@@ -955,8 +955,8 @@ discard block |
||
955 | 955 | { |
956 | 956 | $file = explode('.', basename($file)); |
957 | 957 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
958 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
958 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
959 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
960 | 960 | return $error_code; |
961 | 961 | } |
962 | 962 | |
@@ -976,18 +976,18 @@ discard block |
||
976 | 976 | if (empty($ex)) { |
977 | 977 | return; |
978 | 978 | } |
979 | - if (! $time) { |
|
979 | + if ( ! $time) { |
|
980 | 980 | $time = time(); |
981 | 981 | } |
982 | 982 | $exception_log = '----------------------------------------------------------------------------------------' |
983 | 983 | . PHP_EOL; |
984 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
984 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
985 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
986 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
987 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
988 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
989 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
990 | + $exception_log .= $ex['string'].PHP_EOL; |
|
991 | 991 | $exception_log .= '----------------------------------------------------------------------------------------' |
992 | 992 | . PHP_EOL; |
993 | 993 | try { |
@@ -1160,14 +1160,14 @@ discard block |
||
1160 | 1160 | // js for error handling |
1161 | 1161 | wp_register_script( |
1162 | 1162 | 'espresso_core', |
1163 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1163 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
1164 | 1164 | array('jquery'), |
1165 | 1165 | EVENT_ESPRESSO_VERSION, |
1166 | 1166 | false |
1167 | 1167 | ); |
1168 | 1168 | wp_register_script( |
1169 | 1169 | 'ee_error_js', |
1170 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1170 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
1171 | 1171 | array('espresso_core'), |
1172 | 1172 | EVENT_ESPRESSO_VERSION, |
1173 | 1173 | false |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * cancelTicketSelections |
43 | 43 | * |
44 | - * @return string |
|
44 | + * @return false|null |
|
45 | 45 | * @throws EE_Error |
46 | 46 | * @throws InvalidArgumentException |
47 | 47 | * @throws InvalidInterfaceException |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * process_ticket_selections |
115 | 115 | * |
116 | - * @return array|bool |
|
116 | + * @return boolean|null |
|
117 | 117 | * @throws \ReflectionException |
118 | 118 | * @throws InvalidArgumentException |
119 | 119 | * @throws InvalidInterfaceException |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * validate_post_data |
288 | 288 | * |
289 | 289 | * @param int $id |
290 | - * @return array|FALSE |
|
290 | + * @return string |
|
291 | 291 | * @throws \ReflectionException |
292 | 292 | * @throws InvalidArgumentException |
293 | 293 | * @throws InvalidInterfaceException |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * |
411 | 411 | * @param EE_Ticket $ticket |
412 | 412 | * @param int $qty |
413 | - * @return TRUE on success, FALSE on fail |
|
413 | + * @return boolean on success, FALSE on fail |
|
414 | 414 | * @throws InvalidArgumentException |
415 | 415 | * @throws InvalidInterfaceException |
416 | 416 | * @throws InvalidDataTypeException |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use InvalidArgumentException; |
14 | 14 | |
15 | 15 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
16 | - exit('No direct script access allowed'); |
|
16 | + exit('No direct script access allowed'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
@@ -30,592 +30,592 @@ discard block |
||
30 | 30 | class ProcessTicketSelector |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * array of datetimes and the spaces available for them |
|
35 | - * |
|
36 | - * @var array[][] |
|
37 | - */ |
|
38 | - private static $_available_spaces = array(); |
|
33 | + /** |
|
34 | + * array of datetimes and the spaces available for them |
|
35 | + * |
|
36 | + * @var array[][] |
|
37 | + */ |
|
38 | + private static $_available_spaces = array(); |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * cancelTicketSelections |
|
43 | - * |
|
44 | - * @return string |
|
45 | - * @throws EE_Error |
|
46 | - * @throws InvalidArgumentException |
|
47 | - * @throws InvalidInterfaceException |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - */ |
|
50 | - public function cancelTicketSelections() |
|
51 | - { |
|
52 | - // check nonce |
|
53 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
54 | - return false; |
|
55 | - } |
|
56 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
57 | - if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
58 | - wp_safe_redirect( |
|
59 | - EEH_Event_View::event_link_url( |
|
60 | - EE_Registry::instance()->REQ->get('event_id') |
|
61 | - ) |
|
62 | - ); |
|
63 | - } else { |
|
64 | - wp_safe_redirect( |
|
65 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
66 | - ); |
|
67 | - } |
|
68 | - exit(); |
|
69 | - } |
|
41 | + /** |
|
42 | + * cancelTicketSelections |
|
43 | + * |
|
44 | + * @return string |
|
45 | + * @throws EE_Error |
|
46 | + * @throws InvalidArgumentException |
|
47 | + * @throws InvalidInterfaceException |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + */ |
|
50 | + public function cancelTicketSelections() |
|
51 | + { |
|
52 | + // check nonce |
|
53 | + if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
54 | + return false; |
|
55 | + } |
|
56 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
57 | + if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
58 | + wp_safe_redirect( |
|
59 | + EEH_Event_View::event_link_url( |
|
60 | + EE_Registry::instance()->REQ->get('event_id') |
|
61 | + ) |
|
62 | + ); |
|
63 | + } else { |
|
64 | + wp_safe_redirect( |
|
65 | + site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
66 | + ); |
|
67 | + } |
|
68 | + exit(); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * processTicketSelectorNonce |
|
74 | - * |
|
75 | - * @param string $nonce_name |
|
76 | - * @param string $id |
|
77 | - * @return bool |
|
78 | - * @throws InvalidArgumentException |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - */ |
|
82 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
83 | - { |
|
84 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
85 | - if ( |
|
86 | - ! is_admin() |
|
87 | - && ( |
|
88 | - ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
89 | - || ! wp_verify_nonce( |
|
90 | - EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
91 | - $nonce_name |
|
92 | - ) |
|
93 | - ) |
|
94 | - ) { |
|
95 | - EE_Error::add_error( |
|
96 | - sprintf( |
|
97 | - __( |
|
98 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
99 | - 'event_espresso' |
|
100 | - ), |
|
101 | - '<br/>' |
|
102 | - ), |
|
103 | - __FILE__, |
|
104 | - __FUNCTION__, |
|
105 | - __LINE__ |
|
106 | - ); |
|
107 | - return false; |
|
108 | - } |
|
109 | - return true; |
|
110 | - } |
|
72 | + /** |
|
73 | + * processTicketSelectorNonce |
|
74 | + * |
|
75 | + * @param string $nonce_name |
|
76 | + * @param string $id |
|
77 | + * @return bool |
|
78 | + * @throws InvalidArgumentException |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + */ |
|
82 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
83 | + { |
|
84 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
85 | + if ( |
|
86 | + ! is_admin() |
|
87 | + && ( |
|
88 | + ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
89 | + || ! wp_verify_nonce( |
|
90 | + EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
91 | + $nonce_name |
|
92 | + ) |
|
93 | + ) |
|
94 | + ) { |
|
95 | + EE_Error::add_error( |
|
96 | + sprintf( |
|
97 | + __( |
|
98 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
99 | + 'event_espresso' |
|
100 | + ), |
|
101 | + '<br/>' |
|
102 | + ), |
|
103 | + __FILE__, |
|
104 | + __FUNCTION__, |
|
105 | + __LINE__ |
|
106 | + ); |
|
107 | + return false; |
|
108 | + } |
|
109 | + return true; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * process_ticket_selections |
|
115 | - * |
|
116 | - * @return array|bool |
|
117 | - * @throws \ReflectionException |
|
118 | - * @throws InvalidArgumentException |
|
119 | - * @throws InvalidInterfaceException |
|
120 | - * @throws InvalidDataTypeException |
|
121 | - * @throws EE_Error |
|
122 | - */ |
|
123 | - public function processTicketSelections() |
|
124 | - { |
|
125 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
126 | - // do we have an event id? |
|
127 | - if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
128 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
129 | - EE_Error::add_error( |
|
130 | - sprintf( |
|
131 | - __( |
|
132 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
133 | - 'event_espresso' |
|
134 | - ), |
|
135 | - '<br/>' |
|
136 | - ), |
|
137 | - __FILE__, |
|
138 | - __FUNCTION__, |
|
139 | - __LINE__ |
|
140 | - ); |
|
141 | - } |
|
142 | - //if event id is valid |
|
143 | - $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
144 | - // d( \EE_Registry::instance()->REQ ); |
|
145 | - self::$_available_spaces = array( |
|
146 | - 'tickets' => array(), |
|
147 | - 'datetimes' => array(), |
|
148 | - ); |
|
149 | - //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
150 | - // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
151 | - EE_Registry::instance()->load_core('Session'); |
|
152 | - // unless otherwise requested, clear the session |
|
153 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
154 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
155 | - } |
|
156 | - //d( \EE_Registry::instance()->SSN ); |
|
157 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
158 | - // validate/sanitize data |
|
159 | - $valid = $this->validatePostData($id); |
|
160 | - //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
161 | - //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
162 | - //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
163 | - //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
164 | - //check total tickets ordered vs max number of attendees that can register |
|
165 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
166 | - // ordering too many tickets !!! |
|
167 | - $total_tickets_string = _n( |
|
168 | - 'You have attempted to purchase %s ticket.', |
|
169 | - 'You have attempted to purchase %s tickets.', |
|
170 | - $valid['total_tickets'], |
|
171 | - 'event_espresso' |
|
172 | - ); |
|
173 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
174 | - // dev only message |
|
175 | - $max_atndz_string = _n( |
|
176 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
177 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
178 | - $valid['max_atndz'], |
|
179 | - 'event_espresso' |
|
180 | - ); |
|
181 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
182 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
183 | - } else { |
|
184 | - // all data appears to be valid |
|
185 | - $tckts_slctd = false; |
|
186 | - $tickets_added = 0; |
|
187 | - $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
188 | - $valid); |
|
189 | - if ($valid['total_tickets'] > 0) { |
|
190 | - // load cart |
|
191 | - EE_Registry::instance()->load_core('Cart'); |
|
192 | - // cycle thru the number of data rows sent from the event listing |
|
193 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
194 | - // does this row actually contain a ticket quantity? |
|
195 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
196 | - // YES we have a ticket quantity |
|
197 | - $tckts_slctd = true; |
|
198 | - // d( $valid['ticket_obj'][$x] ); |
|
199 | - if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
200 | - // then add ticket to cart |
|
201 | - $tickets_added += $this->addTicketToCart( |
|
202 | - $valid['ticket_obj'][ $x ], |
|
203 | - $valid['qty'][ $x ] |
|
204 | - ); |
|
205 | - if (EE_Error::has_error()) { |
|
206 | - break; |
|
207 | - } |
|
208 | - } else { |
|
209 | - // nothing added to cart retrieved |
|
210 | - EE_Error::add_error( |
|
211 | - sprintf( |
|
212 | - __( |
|
213 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
214 | - 'event_espresso' |
|
215 | - ), |
|
216 | - '<br/>' |
|
217 | - ), |
|
218 | - __FILE__, __FUNCTION__, __LINE__ |
|
219 | - ); |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - do_action( |
|
225 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
226 | - EE_Registry::instance()->CART, |
|
227 | - $this |
|
228 | - ); |
|
229 | - //d( \EE_Registry::instance()->CART ); |
|
230 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
231 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
232 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
233 | - do_action( |
|
234 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
235 | - EE_Registry::instance()->CART, |
|
236 | - $this |
|
237 | - ); |
|
238 | - EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
239 | - EE_Registry::instance()->CART->save_cart(false); |
|
240 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
241 | - // just return TRUE for registrations being made from admin |
|
242 | - if (is_admin()) { |
|
243 | - return true; |
|
244 | - } |
|
245 | - EE_Error::get_notices(false, true); |
|
246 | - wp_safe_redirect( |
|
247 | - apply_filters( |
|
248 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
249 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
250 | - ) |
|
251 | - ); |
|
252 | - exit(); |
|
253 | - } else { |
|
254 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
255 | - // nothing added to cart |
|
256 | - EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
257 | - __FILE__, __FUNCTION__, __LINE__); |
|
258 | - } |
|
259 | - } |
|
260 | - } else { |
|
261 | - // no ticket quantities were selected |
|
262 | - EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
263 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
264 | - } |
|
265 | - } |
|
266 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
267 | - // at this point, just return if registration is being made from admin |
|
268 | - if (is_admin()) { |
|
269 | - return false; |
|
270 | - } |
|
271 | - if ($valid['return_url']) { |
|
272 | - EE_Error::get_notices(false, true); |
|
273 | - wp_safe_redirect($valid['return_url']); |
|
274 | - exit(); |
|
275 | - } elseif (isset($event_to_add['id'])) { |
|
276 | - EE_Error::get_notices(false, true); |
|
277 | - wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
278 | - exit(); |
|
279 | - } else { |
|
280 | - echo EE_Error::get_notices(); |
|
281 | - } |
|
282 | - return false; |
|
283 | - } |
|
113 | + /** |
|
114 | + * process_ticket_selections |
|
115 | + * |
|
116 | + * @return array|bool |
|
117 | + * @throws \ReflectionException |
|
118 | + * @throws InvalidArgumentException |
|
119 | + * @throws InvalidInterfaceException |
|
120 | + * @throws InvalidDataTypeException |
|
121 | + * @throws EE_Error |
|
122 | + */ |
|
123 | + public function processTicketSelections() |
|
124 | + { |
|
125 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
126 | + // do we have an event id? |
|
127 | + if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
128 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
129 | + EE_Error::add_error( |
|
130 | + sprintf( |
|
131 | + __( |
|
132 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
133 | + 'event_espresso' |
|
134 | + ), |
|
135 | + '<br/>' |
|
136 | + ), |
|
137 | + __FILE__, |
|
138 | + __FUNCTION__, |
|
139 | + __LINE__ |
|
140 | + ); |
|
141 | + } |
|
142 | + //if event id is valid |
|
143 | + $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
144 | + // d( \EE_Registry::instance()->REQ ); |
|
145 | + self::$_available_spaces = array( |
|
146 | + 'tickets' => array(), |
|
147 | + 'datetimes' => array(), |
|
148 | + ); |
|
149 | + //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
150 | + // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
151 | + EE_Registry::instance()->load_core('Session'); |
|
152 | + // unless otherwise requested, clear the session |
|
153 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
154 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
155 | + } |
|
156 | + //d( \EE_Registry::instance()->SSN ); |
|
157 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
158 | + // validate/sanitize data |
|
159 | + $valid = $this->validatePostData($id); |
|
160 | + //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
161 | + //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
162 | + //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
163 | + //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
164 | + //check total tickets ordered vs max number of attendees that can register |
|
165 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
166 | + // ordering too many tickets !!! |
|
167 | + $total_tickets_string = _n( |
|
168 | + 'You have attempted to purchase %s ticket.', |
|
169 | + 'You have attempted to purchase %s tickets.', |
|
170 | + $valid['total_tickets'], |
|
171 | + 'event_espresso' |
|
172 | + ); |
|
173 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
174 | + // dev only message |
|
175 | + $max_atndz_string = _n( |
|
176 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
177 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
178 | + $valid['max_atndz'], |
|
179 | + 'event_espresso' |
|
180 | + ); |
|
181 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
182 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
183 | + } else { |
|
184 | + // all data appears to be valid |
|
185 | + $tckts_slctd = false; |
|
186 | + $tickets_added = 0; |
|
187 | + $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
188 | + $valid); |
|
189 | + if ($valid['total_tickets'] > 0) { |
|
190 | + // load cart |
|
191 | + EE_Registry::instance()->load_core('Cart'); |
|
192 | + // cycle thru the number of data rows sent from the event listing |
|
193 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
194 | + // does this row actually contain a ticket quantity? |
|
195 | + if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
196 | + // YES we have a ticket quantity |
|
197 | + $tckts_slctd = true; |
|
198 | + // d( $valid['ticket_obj'][$x] ); |
|
199 | + if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
200 | + // then add ticket to cart |
|
201 | + $tickets_added += $this->addTicketToCart( |
|
202 | + $valid['ticket_obj'][ $x ], |
|
203 | + $valid['qty'][ $x ] |
|
204 | + ); |
|
205 | + if (EE_Error::has_error()) { |
|
206 | + break; |
|
207 | + } |
|
208 | + } else { |
|
209 | + // nothing added to cart retrieved |
|
210 | + EE_Error::add_error( |
|
211 | + sprintf( |
|
212 | + __( |
|
213 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
214 | + 'event_espresso' |
|
215 | + ), |
|
216 | + '<br/>' |
|
217 | + ), |
|
218 | + __FILE__, __FUNCTION__, __LINE__ |
|
219 | + ); |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + do_action( |
|
225 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
226 | + EE_Registry::instance()->CART, |
|
227 | + $this |
|
228 | + ); |
|
229 | + //d( \EE_Registry::instance()->CART ); |
|
230 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
231 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
232 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
233 | + do_action( |
|
234 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
235 | + EE_Registry::instance()->CART, |
|
236 | + $this |
|
237 | + ); |
|
238 | + EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
239 | + EE_Registry::instance()->CART->save_cart(false); |
|
240 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
241 | + // just return TRUE for registrations being made from admin |
|
242 | + if (is_admin()) { |
|
243 | + return true; |
|
244 | + } |
|
245 | + EE_Error::get_notices(false, true); |
|
246 | + wp_safe_redirect( |
|
247 | + apply_filters( |
|
248 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
249 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
250 | + ) |
|
251 | + ); |
|
252 | + exit(); |
|
253 | + } else { |
|
254 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
255 | + // nothing added to cart |
|
256 | + EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
257 | + __FILE__, __FUNCTION__, __LINE__); |
|
258 | + } |
|
259 | + } |
|
260 | + } else { |
|
261 | + // no ticket quantities were selected |
|
262 | + EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
263 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
264 | + } |
|
265 | + } |
|
266 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
267 | + // at this point, just return if registration is being made from admin |
|
268 | + if (is_admin()) { |
|
269 | + return false; |
|
270 | + } |
|
271 | + if ($valid['return_url']) { |
|
272 | + EE_Error::get_notices(false, true); |
|
273 | + wp_safe_redirect($valid['return_url']); |
|
274 | + exit(); |
|
275 | + } elseif (isset($event_to_add['id'])) { |
|
276 | + EE_Error::get_notices(false, true); |
|
277 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
278 | + exit(); |
|
279 | + } else { |
|
280 | + echo EE_Error::get_notices(); |
|
281 | + } |
|
282 | + return false; |
|
283 | + } |
|
284 | 284 | |
285 | 285 | |
286 | - /** |
|
287 | - * validate_post_data |
|
288 | - * |
|
289 | - * @param int $id |
|
290 | - * @return array|FALSE |
|
291 | - * @throws \ReflectionException |
|
292 | - * @throws InvalidArgumentException |
|
293 | - * @throws InvalidInterfaceException |
|
294 | - * @throws InvalidDataTypeException |
|
295 | - * @throws EE_Error |
|
296 | - */ |
|
297 | - private function validatePostData($id = 0) |
|
298 | - { |
|
299 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
300 | - if (! $id) { |
|
301 | - EE_Error::add_error( |
|
302 | - __('The event id provided was not valid.', 'event_espresso'), |
|
303 | - __FILE__, |
|
304 | - __FUNCTION__, |
|
305 | - __LINE__ |
|
306 | - ); |
|
307 | - return false; |
|
308 | - } |
|
309 | - // start with an empty array() |
|
310 | - $valid_data = array(); |
|
311 | - // grab valid id |
|
312 | - $valid_data['id'] = $id; |
|
313 | - // array of other form names |
|
314 | - $inputs_to_clean = array( |
|
315 | - 'event_id' => 'tkt-slctr-event-id', |
|
316 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
317 | - 'rows' => 'tkt-slctr-rows-', |
|
318 | - 'qty' => 'tkt-slctr-qty-', |
|
319 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
320 | - 'return_url' => 'tkt-slctr-return-url-', |
|
321 | - ); |
|
322 | - // let's track the total number of tickets ordered.' |
|
323 | - $valid_data['total_tickets'] = 0; |
|
324 | - // cycle through $inputs_to_clean array |
|
325 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
326 | - // check for POST data |
|
327 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
328 | - // grab value |
|
329 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
330 | - switch ($what) { |
|
331 | - // integers |
|
332 | - case 'event_id': |
|
333 | - $valid_data[ $what ] = absint($input_value); |
|
334 | - // get event via the event id we put in the form |
|
335 | - $valid_data['event'] = EE_Registry::instance() |
|
336 | - ->load_model('Event') |
|
337 | - ->get_one_by_ID($valid_data['event_id']); |
|
338 | - break; |
|
339 | - case 'rows': |
|
340 | - case 'max_atndz': |
|
341 | - $valid_data[ $what ] = absint($input_value); |
|
342 | - break; |
|
343 | - // arrays of integers |
|
344 | - case 'qty': |
|
345 | - /** @var array $row_qty */ |
|
346 | - $row_qty = $input_value; |
|
347 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
348 | - if (! is_array($row_qty)) { |
|
349 | - // get number of rows |
|
350 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
351 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
352 | - : 1; |
|
353 | - // explode ints by the dash |
|
354 | - $row_qty = explode('-', $row_qty); |
|
355 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
356 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
357 | - $row_qty = array($row => $qty); |
|
358 | - for ($x = 1; $x <= $rows; $x++) { |
|
359 | - if (! isset($row_qty[ $x ])) { |
|
360 | - $row_qty[ $x ] = 0; |
|
361 | - } |
|
362 | - } |
|
363 | - } |
|
364 | - ksort($row_qty); |
|
365 | - // cycle thru values |
|
366 | - foreach ($row_qty as $qty) { |
|
367 | - $qty = absint($qty); |
|
368 | - // sanitize as integers |
|
369 | - $valid_data[ $what ][] = $qty; |
|
370 | - $valid_data['total_tickets'] += $qty; |
|
371 | - } |
|
372 | - break; |
|
373 | - // array of integers |
|
374 | - case 'ticket_id': |
|
375 | - $value_array = array(); |
|
376 | - // cycle thru values |
|
377 | - foreach ((array) $input_value as $key => $value) { |
|
378 | - // allow only numbers, letters, spaces, commas and dashes |
|
379 | - $value_array[ $key ] = wp_strip_all_tags($value); |
|
380 | - // get ticket via the ticket id we put in the form |
|
381 | - $ticket_obj = EE_Registry::instance() |
|
382 | - ->load_model('Ticket') |
|
383 | - ->get_one_by_ID($value); |
|
384 | - $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
385 | - } |
|
386 | - $valid_data[ $what ] = $value_array; |
|
387 | - break; |
|
388 | - case 'return_url' : |
|
389 | - // grab and sanitize return-url |
|
390 | - $input_value = esc_url_raw($input_value); |
|
391 | - // was the request coming from an iframe ? if so, then: |
|
392 | - if (strpos($input_value, 'event_list=iframe')) { |
|
393 | - // get anchor fragment |
|
394 | - $input_value = explode('#', $input_value); |
|
395 | - $input_value = end($input_value); |
|
396 | - // use event list url instead, but append anchor |
|
397 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
398 | - } |
|
399 | - $valid_data[ $what ] = $input_value; |
|
400 | - break; |
|
401 | - } // end switch $what |
|
402 | - } |
|
403 | - } // end foreach $inputs_to_clean |
|
404 | - return $valid_data; |
|
405 | - } |
|
286 | + /** |
|
287 | + * validate_post_data |
|
288 | + * |
|
289 | + * @param int $id |
|
290 | + * @return array|FALSE |
|
291 | + * @throws \ReflectionException |
|
292 | + * @throws InvalidArgumentException |
|
293 | + * @throws InvalidInterfaceException |
|
294 | + * @throws InvalidDataTypeException |
|
295 | + * @throws EE_Error |
|
296 | + */ |
|
297 | + private function validatePostData($id = 0) |
|
298 | + { |
|
299 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
300 | + if (! $id) { |
|
301 | + EE_Error::add_error( |
|
302 | + __('The event id provided was not valid.', 'event_espresso'), |
|
303 | + __FILE__, |
|
304 | + __FUNCTION__, |
|
305 | + __LINE__ |
|
306 | + ); |
|
307 | + return false; |
|
308 | + } |
|
309 | + // start with an empty array() |
|
310 | + $valid_data = array(); |
|
311 | + // grab valid id |
|
312 | + $valid_data['id'] = $id; |
|
313 | + // array of other form names |
|
314 | + $inputs_to_clean = array( |
|
315 | + 'event_id' => 'tkt-slctr-event-id', |
|
316 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
317 | + 'rows' => 'tkt-slctr-rows-', |
|
318 | + 'qty' => 'tkt-slctr-qty-', |
|
319 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
320 | + 'return_url' => 'tkt-slctr-return-url-', |
|
321 | + ); |
|
322 | + // let's track the total number of tickets ordered.' |
|
323 | + $valid_data['total_tickets'] = 0; |
|
324 | + // cycle through $inputs_to_clean array |
|
325 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
326 | + // check for POST data |
|
327 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
328 | + // grab value |
|
329 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
330 | + switch ($what) { |
|
331 | + // integers |
|
332 | + case 'event_id': |
|
333 | + $valid_data[ $what ] = absint($input_value); |
|
334 | + // get event via the event id we put in the form |
|
335 | + $valid_data['event'] = EE_Registry::instance() |
|
336 | + ->load_model('Event') |
|
337 | + ->get_one_by_ID($valid_data['event_id']); |
|
338 | + break; |
|
339 | + case 'rows': |
|
340 | + case 'max_atndz': |
|
341 | + $valid_data[ $what ] = absint($input_value); |
|
342 | + break; |
|
343 | + // arrays of integers |
|
344 | + case 'qty': |
|
345 | + /** @var array $row_qty */ |
|
346 | + $row_qty = $input_value; |
|
347 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
348 | + if (! is_array($row_qty)) { |
|
349 | + // get number of rows |
|
350 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
351 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
352 | + : 1; |
|
353 | + // explode ints by the dash |
|
354 | + $row_qty = explode('-', $row_qty); |
|
355 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
356 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
357 | + $row_qty = array($row => $qty); |
|
358 | + for ($x = 1; $x <= $rows; $x++) { |
|
359 | + if (! isset($row_qty[ $x ])) { |
|
360 | + $row_qty[ $x ] = 0; |
|
361 | + } |
|
362 | + } |
|
363 | + } |
|
364 | + ksort($row_qty); |
|
365 | + // cycle thru values |
|
366 | + foreach ($row_qty as $qty) { |
|
367 | + $qty = absint($qty); |
|
368 | + // sanitize as integers |
|
369 | + $valid_data[ $what ][] = $qty; |
|
370 | + $valid_data['total_tickets'] += $qty; |
|
371 | + } |
|
372 | + break; |
|
373 | + // array of integers |
|
374 | + case 'ticket_id': |
|
375 | + $value_array = array(); |
|
376 | + // cycle thru values |
|
377 | + foreach ((array) $input_value as $key => $value) { |
|
378 | + // allow only numbers, letters, spaces, commas and dashes |
|
379 | + $value_array[ $key ] = wp_strip_all_tags($value); |
|
380 | + // get ticket via the ticket id we put in the form |
|
381 | + $ticket_obj = EE_Registry::instance() |
|
382 | + ->load_model('Ticket') |
|
383 | + ->get_one_by_ID($value); |
|
384 | + $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
385 | + } |
|
386 | + $valid_data[ $what ] = $value_array; |
|
387 | + break; |
|
388 | + case 'return_url' : |
|
389 | + // grab and sanitize return-url |
|
390 | + $input_value = esc_url_raw($input_value); |
|
391 | + // was the request coming from an iframe ? if so, then: |
|
392 | + if (strpos($input_value, 'event_list=iframe')) { |
|
393 | + // get anchor fragment |
|
394 | + $input_value = explode('#', $input_value); |
|
395 | + $input_value = end($input_value); |
|
396 | + // use event list url instead, but append anchor |
|
397 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
398 | + } |
|
399 | + $valid_data[ $what ] = $input_value; |
|
400 | + break; |
|
401 | + } // end switch $what |
|
402 | + } |
|
403 | + } // end foreach $inputs_to_clean |
|
404 | + return $valid_data; |
|
405 | + } |
|
406 | 406 | |
407 | 407 | |
408 | - /** |
|
409 | - * adds a ticket to the cart |
|
410 | - * |
|
411 | - * @param EE_Ticket $ticket |
|
412 | - * @param int $qty |
|
413 | - * @return TRUE on success, FALSE on fail |
|
414 | - * @throws InvalidArgumentException |
|
415 | - * @throws InvalidInterfaceException |
|
416 | - * @throws InvalidDataTypeException |
|
417 | - * @throws EE_Error |
|
418 | - */ |
|
419 | - private function addTicketToCart(EE_Ticket $ticket = null, $qty = 1) |
|
420 | - { |
|
421 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
422 | - // get the number of spaces left for this datetime ticket |
|
423 | - $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
424 | - // compare available spaces against the number of tickets being purchased |
|
425 | - if ($available_spaces >= $qty) { |
|
426 | - // allow addons to prevent a ticket from being added to cart |
|
427 | - if ( |
|
428 | - ! apply_filters( |
|
429 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
430 | - true, |
|
431 | - $ticket, |
|
432 | - $qty, |
|
433 | - $available_spaces |
|
434 | - ) |
|
435 | - ) { |
|
436 | - return false; |
|
437 | - } |
|
438 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
439 | - // add event to cart |
|
440 | - if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
441 | - $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
442 | - return true; |
|
443 | - } |
|
444 | - return false; |
|
445 | - } |
|
446 | - // tickets can not be purchased but let's find the exact number left |
|
447 | - // for the last ticket selected PRIOR to subtracting tickets |
|
448 | - $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
449 | - // greedy greedy greedy eh? |
|
450 | - if ($available_spaces > 0) { |
|
451 | - if ( |
|
452 | - apply_filters( |
|
453 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
454 | - true, |
|
455 | - $ticket, |
|
456 | - $qty, |
|
457 | - $available_spaces |
|
458 | - ) |
|
459 | - ) { |
|
460 | - $this->displayAvailabilityError($available_spaces); |
|
461 | - } |
|
462 | - } else { |
|
463 | - EE_Error::add_error( |
|
464 | - __( |
|
465 | - 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
466 | - 'event_espresso' |
|
467 | - ), |
|
468 | - __FILE__, __FUNCTION__, __LINE__ |
|
469 | - ); |
|
470 | - } |
|
471 | - return false; |
|
472 | - } |
|
408 | + /** |
|
409 | + * adds a ticket to the cart |
|
410 | + * |
|
411 | + * @param EE_Ticket $ticket |
|
412 | + * @param int $qty |
|
413 | + * @return TRUE on success, FALSE on fail |
|
414 | + * @throws InvalidArgumentException |
|
415 | + * @throws InvalidInterfaceException |
|
416 | + * @throws InvalidDataTypeException |
|
417 | + * @throws EE_Error |
|
418 | + */ |
|
419 | + private function addTicketToCart(EE_Ticket $ticket = null, $qty = 1) |
|
420 | + { |
|
421 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
422 | + // get the number of spaces left for this datetime ticket |
|
423 | + $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
424 | + // compare available spaces against the number of tickets being purchased |
|
425 | + if ($available_spaces >= $qty) { |
|
426 | + // allow addons to prevent a ticket from being added to cart |
|
427 | + if ( |
|
428 | + ! apply_filters( |
|
429 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
430 | + true, |
|
431 | + $ticket, |
|
432 | + $qty, |
|
433 | + $available_spaces |
|
434 | + ) |
|
435 | + ) { |
|
436 | + return false; |
|
437 | + } |
|
438 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
439 | + // add event to cart |
|
440 | + if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
441 | + $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
442 | + return true; |
|
443 | + } |
|
444 | + return false; |
|
445 | + } |
|
446 | + // tickets can not be purchased but let's find the exact number left |
|
447 | + // for the last ticket selected PRIOR to subtracting tickets |
|
448 | + $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
449 | + // greedy greedy greedy eh? |
|
450 | + if ($available_spaces > 0) { |
|
451 | + if ( |
|
452 | + apply_filters( |
|
453 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
454 | + true, |
|
455 | + $ticket, |
|
456 | + $qty, |
|
457 | + $available_spaces |
|
458 | + ) |
|
459 | + ) { |
|
460 | + $this->displayAvailabilityError($available_spaces); |
|
461 | + } |
|
462 | + } else { |
|
463 | + EE_Error::add_error( |
|
464 | + __( |
|
465 | + 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
466 | + 'event_espresso' |
|
467 | + ), |
|
468 | + __FILE__, __FUNCTION__, __LINE__ |
|
469 | + ); |
|
470 | + } |
|
471 | + return false; |
|
472 | + } |
|
473 | 473 | |
474 | 474 | |
475 | - /** |
|
476 | - * @param int $available_spaces |
|
477 | - * @throws InvalidArgumentException |
|
478 | - * @throws InvalidInterfaceException |
|
479 | - * @throws InvalidDataTypeException |
|
480 | - * @throws EE_Error |
|
481 | - */ |
|
482 | - private function displayAvailabilityError($available_spaces = 1) |
|
483 | - { |
|
484 | - // add error messaging - we're using the _n function that will generate |
|
485 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
486 | - if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
487 | - $msg = sprintf( |
|
488 | - _n( |
|
489 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
490 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
491 | - $available_spaces, |
|
492 | - 'event_espresso' |
|
493 | - ), |
|
494 | - $available_spaces, |
|
495 | - '<br />' |
|
496 | - ); |
|
497 | - } else { |
|
498 | - $msg = sprintf( |
|
499 | - _n( |
|
500 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
501 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
502 | - $available_spaces, |
|
503 | - 'event_espresso' |
|
504 | - ), |
|
505 | - $available_spaces, |
|
506 | - '<br />' |
|
507 | - ); |
|
508 | - } |
|
509 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
510 | - } |
|
475 | + /** |
|
476 | + * @param int $available_spaces |
|
477 | + * @throws InvalidArgumentException |
|
478 | + * @throws InvalidInterfaceException |
|
479 | + * @throws InvalidDataTypeException |
|
480 | + * @throws EE_Error |
|
481 | + */ |
|
482 | + private function displayAvailabilityError($available_spaces = 1) |
|
483 | + { |
|
484 | + // add error messaging - we're using the _n function that will generate |
|
485 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
486 | + if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
487 | + $msg = sprintf( |
|
488 | + _n( |
|
489 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
490 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
491 | + $available_spaces, |
|
492 | + 'event_espresso' |
|
493 | + ), |
|
494 | + $available_spaces, |
|
495 | + '<br />' |
|
496 | + ); |
|
497 | + } else { |
|
498 | + $msg = sprintf( |
|
499 | + _n( |
|
500 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
501 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
502 | + $available_spaces, |
|
503 | + 'event_espresso' |
|
504 | + ), |
|
505 | + $available_spaces, |
|
506 | + '<br />' |
|
507 | + ); |
|
508 | + } |
|
509 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
510 | + } |
|
511 | 511 | |
512 | 512 | |
513 | - /** |
|
514 | - * ticketDatetimeAvailability |
|
515 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
516 | - * and tracks the spaces remaining for each of those datetimes |
|
517 | - * |
|
518 | - * @param EE_Ticket $ticket - selected ticket |
|
519 | - * @param bool $get_original_ticket_spaces |
|
520 | - * @return int |
|
521 | - * @throws InvalidArgumentException |
|
522 | - * @throws InvalidInterfaceException |
|
523 | - * @throws InvalidDataTypeException |
|
524 | - * @throws EE_Error |
|
525 | - */ |
|
526 | - private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
527 | - { |
|
528 | - // if the $_available_spaces array has not been set up yet... |
|
529 | - if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
530 | - $this->setInitialTicketDatetimeAvailability($ticket); |
|
531 | - } |
|
532 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
533 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
534 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
535 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
536 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
537 | - if ($get_original_ticket_spaces) { |
|
538 | - // then grab the available spaces from the "tickets" array |
|
539 | - // and compare with the above to get the lowest number |
|
540 | - $available_spaces = min( |
|
541 | - $available_spaces, |
|
542 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
543 | - ); |
|
544 | - } else { |
|
545 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
546 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
547 | - } |
|
548 | - } |
|
549 | - } |
|
550 | - return $available_spaces; |
|
551 | - } |
|
513 | + /** |
|
514 | + * ticketDatetimeAvailability |
|
515 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
516 | + * and tracks the spaces remaining for each of those datetimes |
|
517 | + * |
|
518 | + * @param EE_Ticket $ticket - selected ticket |
|
519 | + * @param bool $get_original_ticket_spaces |
|
520 | + * @return int |
|
521 | + * @throws InvalidArgumentException |
|
522 | + * @throws InvalidInterfaceException |
|
523 | + * @throws InvalidDataTypeException |
|
524 | + * @throws EE_Error |
|
525 | + */ |
|
526 | + private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
527 | + { |
|
528 | + // if the $_available_spaces array has not been set up yet... |
|
529 | + if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
530 | + $this->setInitialTicketDatetimeAvailability($ticket); |
|
531 | + } |
|
532 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
533 | + if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
534 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
535 | + foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
536 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
537 | + if ($get_original_ticket_spaces) { |
|
538 | + // then grab the available spaces from the "tickets" array |
|
539 | + // and compare with the above to get the lowest number |
|
540 | + $available_spaces = min( |
|
541 | + $available_spaces, |
|
542 | + self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
543 | + ); |
|
544 | + } else { |
|
545 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
546 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
547 | + } |
|
548 | + } |
|
549 | + } |
|
550 | + return $available_spaces; |
|
551 | + } |
|
552 | 552 | |
553 | 553 | |
554 | - /** |
|
555 | - * @param EE_Ticket $ticket |
|
556 | - * @return void |
|
557 | - * @throws InvalidArgumentException |
|
558 | - * @throws InvalidInterfaceException |
|
559 | - * @throws InvalidDataTypeException |
|
560 | - * @throws EE_Error |
|
561 | - */ |
|
562 | - private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
563 | - { |
|
564 | - // first, get all of the datetimes that are available to this ticket |
|
565 | - $datetimes = $ticket->get_many_related( |
|
566 | - 'Datetime', |
|
567 | - array( |
|
568 | - array( |
|
569 | - 'DTT_EVT_end' => array( |
|
570 | - '>=', |
|
571 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
572 | - ), |
|
573 | - ), |
|
574 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
575 | - ) |
|
576 | - ); |
|
577 | - if (! empty($datetimes)) { |
|
578 | - // now loop thru all of the datetimes |
|
579 | - foreach ($datetimes as $datetime) { |
|
580 | - if ($datetime instanceof EE_Datetime) { |
|
581 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
582 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
583 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
584 | - // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
585 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
586 | - $ticket->qty() - $ticket->sold(), |
|
587 | - $spaces_remaining |
|
588 | - ); |
|
589 | - // if the remaining spaces for this datetime is already set, |
|
590 | - // then compare that against the datetime spaces remaining, and take the lowest number, |
|
591 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
592 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
593 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
594 | - ) |
|
595 | - ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
596 | - : $spaces_remaining; |
|
597 | - } |
|
598 | - } |
|
599 | - } |
|
600 | - } |
|
554 | + /** |
|
555 | + * @param EE_Ticket $ticket |
|
556 | + * @return void |
|
557 | + * @throws InvalidArgumentException |
|
558 | + * @throws InvalidInterfaceException |
|
559 | + * @throws InvalidDataTypeException |
|
560 | + * @throws EE_Error |
|
561 | + */ |
|
562 | + private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
563 | + { |
|
564 | + // first, get all of the datetimes that are available to this ticket |
|
565 | + $datetimes = $ticket->get_many_related( |
|
566 | + 'Datetime', |
|
567 | + array( |
|
568 | + array( |
|
569 | + 'DTT_EVT_end' => array( |
|
570 | + '>=', |
|
571 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
572 | + ), |
|
573 | + ), |
|
574 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
575 | + ) |
|
576 | + ); |
|
577 | + if (! empty($datetimes)) { |
|
578 | + // now loop thru all of the datetimes |
|
579 | + foreach ($datetimes as $datetime) { |
|
580 | + if ($datetime instanceof EE_Datetime) { |
|
581 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
582 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
583 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
584 | + // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
585 | + self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
586 | + $ticket->qty() - $ticket->sold(), |
|
587 | + $spaces_remaining |
|
588 | + ); |
|
589 | + // if the remaining spaces for this datetime is already set, |
|
590 | + // then compare that against the datetime spaces remaining, and take the lowest number, |
|
591 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
592 | + self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
593 | + self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
594 | + ) |
|
595 | + ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
596 | + : $spaces_remaining; |
|
597 | + } |
|
598 | + } |
|
599 | + } |
|
600 | + } |
|
601 | 601 | |
602 | 602 | |
603 | - /** |
|
604 | - * @param EE_Ticket $ticket |
|
605 | - * @param int $qty |
|
606 | - * @return void |
|
607 | - * @throws EE_Error |
|
608 | - */ |
|
609 | - private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
610 | - { |
|
611 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
612 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
613 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
614 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
615 | - self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
616 | - } |
|
617 | - } |
|
618 | - } |
|
603 | + /** |
|
604 | + * @param EE_Ticket $ticket |
|
605 | + * @param int $qty |
|
606 | + * @return void |
|
607 | + * @throws EE_Error |
|
608 | + */ |
|
609 | + private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
610 | + { |
|
611 | + if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
612 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
613 | + foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
614 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
615 | + self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
616 | + } |
|
617 | + } |
|
618 | + } |
|
619 | 619 | } |
620 | 620 | // End of file ProcessTicketSelector.php |
621 | 621 | // Location: /ProcessTicketSelector.php |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
13 | 13 | use InvalidArgumentException; |
14 | 14 | |
15 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
15 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
16 | 16 | exit('No direct script access allowed'); |
17 | 17 | } |
18 | 18 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | public function cancelTicketSelections() |
51 | 51 | { |
52 | 52 | // check nonce |
53 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
53 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | ); |
63 | 63 | } else { |
64 | 64 | wp_safe_redirect( |
65 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
65 | + site_url('/'.EE_Registry::instance()->CFG->core->event_cpt_slug.'/') |
|
66 | 66 | ); |
67 | 67 | } |
68 | 68 | exit(); |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | { |
125 | 125 | do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
126 | 126 | // do we have an event id? |
127 | - if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
127 | + if ( ! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
128 | 128 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
129 | 129 | EE_Error::add_error( |
130 | 130 | sprintf( |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $valid['total_tickets'], |
171 | 171 | 'event_espresso' |
172 | 172 | ); |
173 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
173 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
174 | 174 | // dev only message |
175 | 175 | $max_atndz_string = _n( |
176 | 176 | 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | $valid['max_atndz'], |
179 | 179 | 'event_espresso' |
180 | 180 | ); |
181 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
182 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
181 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
182 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
183 | 183 | } else { |
184 | 184 | // all data appears to be valid |
185 | 185 | $tckts_slctd = false; |
@@ -192,15 +192,15 @@ discard block |
||
192 | 192 | // cycle thru the number of data rows sent from the event listing |
193 | 193 | for ($x = 0; $x < $valid['rows']; $x++) { |
194 | 194 | // does this row actually contain a ticket quantity? |
195 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
195 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
196 | 196 | // YES we have a ticket quantity |
197 | 197 | $tckts_slctd = true; |
198 | 198 | // d( $valid['ticket_obj'][$x] ); |
199 | - if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
199 | + if ($valid['ticket_obj'][$x] instanceof EE_Ticket) { |
|
200 | 200 | // then add ticket to cart |
201 | 201 | $tickets_added += $this->addTicketToCart( |
202 | - $valid['ticket_obj'][ $x ], |
|
203 | - $valid['qty'][ $x ] |
|
202 | + $valid['ticket_obj'][$x], |
|
203 | + $valid['qty'][$x] |
|
204 | 204 | ); |
205 | 205 | if (EE_Error::has_error()) { |
206 | 206 | break; |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | ); |
252 | 252 | exit(); |
253 | 253 | } else { |
254 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
254 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
255 | 255 | // nothing added to cart |
256 | 256 | EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
257 | 257 | __FILE__, __FUNCTION__, __LINE__); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | private function validatePostData($id = 0) |
298 | 298 | { |
299 | 299 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
300 | - if (! $id) { |
|
300 | + if ( ! $id) { |
|
301 | 301 | EE_Error::add_error( |
302 | 302 | __('The event id provided was not valid.', 'event_espresso'), |
303 | 303 | __FILE__, |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | // cycle through $inputs_to_clean array |
325 | 325 | foreach ($inputs_to_clean as $what => $input_to_clean) { |
326 | 326 | // check for POST data |
327 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
327 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean.$id)) { |
|
328 | 328 | // grab value |
329 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
329 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean.$id); |
|
330 | 330 | switch ($what) { |
331 | 331 | // integers |
332 | 332 | case 'event_id': |
333 | - $valid_data[ $what ] = absint($input_value); |
|
333 | + $valid_data[$what] = absint($input_value); |
|
334 | 334 | // get event via the event id we put in the form |
335 | 335 | $valid_data['event'] = EE_Registry::instance() |
336 | 336 | ->load_model('Event') |
@@ -338,17 +338,17 @@ discard block |
||
338 | 338 | break; |
339 | 339 | case 'rows': |
340 | 340 | case 'max_atndz': |
341 | - $valid_data[ $what ] = absint($input_value); |
|
341 | + $valid_data[$what] = absint($input_value); |
|
342 | 342 | break; |
343 | 343 | // arrays of integers |
344 | 344 | case 'qty': |
345 | 345 | /** @var array $row_qty */ |
346 | 346 | $row_qty = $input_value; |
347 | 347 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
348 | - if (! is_array($row_qty)) { |
|
348 | + if ( ! is_array($row_qty)) { |
|
349 | 349 | // get number of rows |
350 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
351 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
350 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-'.$id) |
|
351 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-'.$id)) |
|
352 | 352 | : 1; |
353 | 353 | // explode ints by the dash |
354 | 354 | $row_qty = explode('-', $row_qty); |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
357 | 357 | $row_qty = array($row => $qty); |
358 | 358 | for ($x = 1; $x <= $rows; $x++) { |
359 | - if (! isset($row_qty[ $x ])) { |
|
360 | - $row_qty[ $x ] = 0; |
|
359 | + if ( ! isset($row_qty[$x])) { |
|
360 | + $row_qty[$x] = 0; |
|
361 | 361 | } |
362 | 362 | } |
363 | 363 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | foreach ($row_qty as $qty) { |
367 | 367 | $qty = absint($qty); |
368 | 368 | // sanitize as integers |
369 | - $valid_data[ $what ][] = $qty; |
|
369 | + $valid_data[$what][] = $qty; |
|
370 | 370 | $valid_data['total_tickets'] += $qty; |
371 | 371 | } |
372 | 372 | break; |
@@ -376,14 +376,14 @@ discard block |
||
376 | 376 | // cycle thru values |
377 | 377 | foreach ((array) $input_value as $key => $value) { |
378 | 378 | // allow only numbers, letters, spaces, commas and dashes |
379 | - $value_array[ $key ] = wp_strip_all_tags($value); |
|
379 | + $value_array[$key] = wp_strip_all_tags($value); |
|
380 | 380 | // get ticket via the ticket id we put in the form |
381 | 381 | $ticket_obj = EE_Registry::instance() |
382 | 382 | ->load_model('Ticket') |
383 | 383 | ->get_one_by_ID($value); |
384 | - $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
384 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
385 | 385 | } |
386 | - $valid_data[ $what ] = $value_array; |
|
386 | + $valid_data[$what] = $value_array; |
|
387 | 387 | break; |
388 | 388 | case 'return_url' : |
389 | 389 | // grab and sanitize return-url |
@@ -394,9 +394,9 @@ discard block |
||
394 | 394 | $input_value = explode('#', $input_value); |
395 | 395 | $input_value = end($input_value); |
396 | 396 | // use event list url instead, but append anchor |
397 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
397 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; |
|
398 | 398 | } |
399 | - $valid_data[ $what ] = $input_value; |
|
399 | + $valid_data[$what] = $input_value; |
|
400 | 400 | break; |
401 | 401 | } // end switch $what |
402 | 402 | } |
@@ -526,24 +526,24 @@ discard block |
||
526 | 526 | private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
527 | 527 | { |
528 | 528 | // if the $_available_spaces array has not been set up yet... |
529 | - if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
529 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
530 | 530 | $this->setInitialTicketDatetimeAvailability($ticket); |
531 | 531 | } |
532 | 532 | $available_spaces = $ticket->qty() - $ticket->sold(); |
533 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
533 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
534 | 534 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
535 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
535 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
536 | 536 | // if we want the original datetime availability BEFORE we started subtracting tickets ? |
537 | 537 | if ($get_original_ticket_spaces) { |
538 | 538 | // then grab the available spaces from the "tickets" array |
539 | 539 | // and compare with the above to get the lowest number |
540 | 540 | $available_spaces = min( |
541 | 541 | $available_spaces, |
542 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
542 | + self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
543 | 543 | ); |
544 | 544 | } else { |
545 | 545 | // we want the updated ticket availability as stored in the "datetimes" array |
546 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
546 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | } |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | 'order_by' => array('DTT_EVT_start' => 'ASC'), |
575 | 575 | ) |
576 | 576 | ); |
577 | - if (! empty($datetimes)) { |
|
577 | + if ( ! empty($datetimes)) { |
|
578 | 578 | // now loop thru all of the datetimes |
579 | 579 | foreach ($datetimes as $datetime) { |
580 | 580 | if ($datetime instanceof EE_Datetime) { |
@@ -582,17 +582,17 @@ discard block |
||
582 | 582 | $spaces_remaining = $datetime->spaces_remaining(); |
583 | 583 | // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
584 | 584 | // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
585 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
585 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
586 | 586 | $ticket->qty() - $ticket->sold(), |
587 | 587 | $spaces_remaining |
588 | 588 | ); |
589 | 589 | // if the remaining spaces for this datetime is already set, |
590 | 590 | // then compare that against the datetime spaces remaining, and take the lowest number, |
591 | 591 | // else just take the datetime spaces remaining, and assign to the datetimes array |
592 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
593 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
592 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
593 | + self::$_available_spaces['datetimes'][$datetime->ID()] |
|
594 | 594 | ) |
595 | - ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
595 | + ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
596 | 596 | : $spaces_remaining; |
597 | 597 | } |
598 | 598 | } |
@@ -608,11 +608,11 @@ discard block |
||
608 | 608 | */ |
609 | 609 | private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
610 | 610 | { |
611 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
611 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
612 | 612 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
613 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
613 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
614 | 614 | // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
615 | - self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
615 | + self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | } |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*'); |
13 | 13 | $class_to_filepath = array(); |
14 | 14 | foreach ($stages as $filepath) { |
15 | - $matches = array(); |
|
16 | - preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | - $class_to_filepath[$matches[1]] = $filepath; |
|
15 | + $matches = array(); |
|
16 | + preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | + $class_to_filepath[$matches[1]] = $filepath; |
|
18 | 18 | } |
19 | 19 | //give addons a chance to autoload their stages too |
20 | 20 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath); |
@@ -33,68 +33,68 @@ discard block |
||
33 | 33 | class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * return EE_DMS_Core_4_9_0 |
|
38 | - * |
|
39 | - * @param TableManager $table_manager |
|
40 | - * @param TableAnalysis $table_analysis |
|
41 | - */ |
|
42 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | - { |
|
44 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | - $this->_priority = 10; |
|
46 | - $this->_migration_stages = array( |
|
47 | - new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | - new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | - ); |
|
50 | - parent::__construct($table_manager, $table_analysis); |
|
51 | - } |
|
36 | + /** |
|
37 | + * return EE_DMS_Core_4_9_0 |
|
38 | + * |
|
39 | + * @param TableManager $table_manager |
|
40 | + * @param TableAnalysis $table_analysis |
|
41 | + */ |
|
42 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | + { |
|
44 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | + $this->_priority = 10; |
|
46 | + $this->_migration_stages = array( |
|
47 | + new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | + new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | + ); |
|
50 | + parent::__construct($table_manager, $table_analysis); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Whether to migrate or not. |
|
57 | - * |
|
58 | - * @param array $version_array |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function can_migrate_from_version($version_array) |
|
62 | - { |
|
63 | - $version_string = $version_array['Core']; |
|
64 | - if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) { |
|
65 | - // echo "$version_string can be migrated from"; |
|
66 | - return true; |
|
67 | - } elseif ( ! $version_string) { |
|
68 | - // echo "no version string provided: $version_string"; |
|
69 | - //no version string provided... this must be pre 4.3 |
|
70 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | - } else { |
|
72 | - // echo "$version_string doesnt apply"; |
|
73 | - return false; |
|
74 | - } |
|
75 | - } |
|
55 | + /** |
|
56 | + * Whether to migrate or not. |
|
57 | + * |
|
58 | + * @param array $version_array |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function can_migrate_from_version($version_array) |
|
62 | + { |
|
63 | + $version_string = $version_array['Core']; |
|
64 | + if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) { |
|
65 | + // echo "$version_string can be migrated from"; |
|
66 | + return true; |
|
67 | + } elseif ( ! $version_string) { |
|
68 | + // echo "no version string provided: $version_string"; |
|
69 | + //no version string provided... this must be pre 4.3 |
|
70 | + return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | + } else { |
|
72 | + // echo "$version_string doesnt apply"; |
|
73 | + return false; |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public function schema_changes_before_migration() |
|
83 | - { |
|
84 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | - $now_in_mysql = current_time('mysql', true); |
|
86 | - $table_name = 'esp_answer'; |
|
87 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
79 | + /** |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public function schema_changes_before_migration() |
|
83 | + { |
|
84 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | + $now_in_mysql = current_time('mysql', true); |
|
86 | + $table_name = 'esp_answer'; |
|
87 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
88 | 88 | REG_ID int(10) unsigned NOT NULL, |
89 | 89 | QST_ID int(10) unsigned NOT NULL, |
90 | 90 | ANS_value text NOT NULL, |
91 | 91 | PRIMARY KEY (ANS_ID), |
92 | 92 | KEY REG_ID (REG_ID), |
93 | 93 | KEY QST_ID (QST_ID)"; |
94 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | - $table_name = 'esp_attendee_meta'; |
|
96 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
94 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | + $table_name = 'esp_attendee_meta'; |
|
96 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
98 | 98 | ATT_ID bigint(20) unsigned NOT NULL, |
99 | 99 | ATT_fname varchar(45) NOT NULL, |
100 | 100 | ATT_lname varchar(45) NOT NULL, |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | KEY ATT_email (ATT_email(191)), |
112 | 112 | KEY ATT_lname (ATT_lname), |
113 | 113 | KEY ATT_fname (ATT_fname)"; |
114 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | - $table_name = 'esp_checkin'; |
|
116 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
114 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | + $table_name = 'esp_checkin'; |
|
116 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
117 | 117 | REG_ID int(10) unsigned NOT NULL, |
118 | 118 | DTT_ID int(10) unsigned NOT NULL, |
119 | 119 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | PRIMARY KEY (CHK_ID), |
122 | 122 | KEY REG_ID (REG_ID), |
123 | 123 | KEY DTT_ID (DTT_ID)"; |
124 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | - $table_name = 'esp_country'; |
|
126 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
124 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | + $table_name = 'esp_country'; |
|
126 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
127 | 127 | CNT_ISO3 varchar(3) NOT NULL, |
128 | 128 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
129 | 129 | CNT_name varchar(45) NOT NULL, |
@@ -139,29 +139,29 @@ discard block |
||
139 | 139 | CNT_is_EU tinyint(1) DEFAULT '0', |
140 | 140 | CNT_active tinyint(1) DEFAULT '0', |
141 | 141 | PRIMARY KEY (CNT_ISO)"; |
142 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | - $table_name = 'esp_currency'; |
|
144 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
142 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | + $table_name = 'esp_currency'; |
|
144 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
145 | 145 | CUR_single varchar(45) DEFAULT 'dollar', |
146 | 146 | CUR_plural varchar(45) DEFAULT 'dollars', |
147 | 147 | CUR_sign varchar(45) DEFAULT '$', |
148 | 148 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
149 | 149 | CUR_active tinyint(1) DEFAULT '0', |
150 | 150 | PRIMARY KEY (CUR_code)"; |
151 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | - //note: although this table is no longer in use, |
|
153 | - //it hasn't been removed because then queries to the model will have errors. |
|
154 | - //but you should expect this table and its corresponding model to be removed in |
|
155 | - //the next few months |
|
156 | - $table_name = 'esp_currency_payment_method'; |
|
157 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
151 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | + //note: although this table is no longer in use, |
|
153 | + //it hasn't been removed because then queries to the model will have errors. |
|
154 | + //but you should expect this table and its corresponding model to be removed in |
|
155 | + //the next few months |
|
156 | + $table_name = 'esp_currency_payment_method'; |
|
157 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
158 | 158 | CUR_code varchar(6) NOT NULL, |
159 | 159 | PMD_ID int(11) NOT NULL, |
160 | 160 | PRIMARY KEY (CPM_ID), |
161 | 161 | KEY PMD_ID (PMD_ID)"; |
162 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | - $table_name = 'esp_datetime'; |
|
164 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
162 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | + $table_name = 'esp_datetime'; |
|
164 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
165 | 165 | EVT_ID bigint(20) unsigned NOT NULL, |
166 | 166 | DTT_name varchar(255) NOT NULL DEFAULT '', |
167 | 167 | DTT_description text NOT NULL, |
@@ -178,25 +178,25 @@ discard block |
||
178 | 178 | KEY DTT_EVT_start (DTT_EVT_start), |
179 | 179 | KEY EVT_ID (EVT_ID), |
180 | 180 | KEY DTT_is_primary (DTT_is_primary)"; |
181 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | - $table_name = "esp_datetime_ticket"; |
|
183 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
181 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | + $table_name = "esp_datetime_ticket"; |
|
183 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
184 | 184 | DTT_ID int(10) unsigned NOT NULL, |
185 | 185 | TKT_ID int(10) unsigned NOT NULL, |
186 | 186 | PRIMARY KEY (DTK_ID), |
187 | 187 | KEY DTT_ID (DTT_ID), |
188 | 188 | KEY TKT_ID (TKT_ID)"; |
189 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | - $table_name = 'esp_event_message_template'; |
|
191 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
189 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | + $table_name = 'esp_event_message_template'; |
|
191 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
192 | 192 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
193 | 193 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
194 | 194 | PRIMARY KEY (EMT_ID), |
195 | 195 | KEY EVT_ID (EVT_ID), |
196 | 196 | KEY GRP_ID (GRP_ID)"; |
197 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_event_meta'; |
|
199 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_event_meta'; |
|
199 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
200 | 200 | EVT_ID bigint(20) unsigned NOT NULL, |
201 | 201 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
202 | 202 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -211,34 +211,34 @@ discard block |
||
211 | 211 | EVT_donations tinyint(1) NULL, |
212 | 212 | PRIMARY KEY (EVTM_ID), |
213 | 213 | KEY EVT_ID (EVT_ID)"; |
214 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | - $table_name = 'esp_event_question_group'; |
|
216 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
214 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | + $table_name = 'esp_event_question_group'; |
|
216 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
217 | 217 | EVT_ID bigint(20) unsigned NOT NULL, |
218 | 218 | QSG_ID int(10) unsigned NOT NULL, |
219 | 219 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
220 | 220 | PRIMARY KEY (EQG_ID), |
221 | 221 | KEY EVT_ID (EVT_ID), |
222 | 222 | KEY QSG_ID (QSG_ID)"; |
223 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | - $table_name = 'esp_event_venue'; |
|
225 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
223 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | + $table_name = 'esp_event_venue'; |
|
225 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
226 | 226 | EVT_ID bigint(20) unsigned NOT NULL, |
227 | 227 | VNU_ID bigint(20) unsigned NOT NULL, |
228 | 228 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
229 | 229 | PRIMARY KEY (EVV_ID)"; |
230 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | - $table_name = 'esp_extra_meta'; |
|
232 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
230 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | + $table_name = 'esp_extra_meta'; |
|
232 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
233 | 233 | OBJ_ID int(11) DEFAULT NULL, |
234 | 234 | EXM_type varchar(45) DEFAULT NULL, |
235 | 235 | EXM_key varchar(45) DEFAULT NULL, |
236 | 236 | EXM_value text, |
237 | 237 | PRIMARY KEY (EXM_ID), |
238 | 238 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
239 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | - $table_name = 'esp_extra_join'; |
|
241 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
239 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | + $table_name = 'esp_extra_join'; |
|
241 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
242 | 242 | EXJ_first_model_id varchar(6) NOT NULL, |
243 | 243 | EXJ_first_model_name varchar(20) NOT NULL, |
244 | 244 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | PRIMARY KEY (EXJ_ID), |
247 | 247 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
248 | 248 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
249 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | - $table_name = 'esp_line_item'; |
|
251 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
249 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | + $table_name = 'esp_line_item'; |
|
251 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
252 | 252 | LIN_code varchar(245) NOT NULL DEFAULT '', |
253 | 253 | TXN_ID int(11) DEFAULT NULL, |
254 | 254 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
270 | 270 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
271 | 271 | KEY obj_id_obj_type (OBJ_ID, OBJ_type)"; |
272 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
273 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
274 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
275 | - $table_name = 'esp_log'; |
|
276 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
272 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
273 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
274 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
275 | + $table_name = 'esp_log'; |
|
276 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
277 | 277 | LOG_time datetime DEFAULT NULL, |
278 | 278 | OBJ_ID varchar(45) DEFAULT NULL, |
279 | 279 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | KEY LOG_time (LOG_time), |
285 | 285 | KEY OBJ (OBJ_type,OBJ_ID), |
286 | 286 | KEY LOG_type (LOG_type)"; |
287 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
288 | - $table_name = 'esp_message'; |
|
289 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
290 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
291 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
292 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
287 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
288 | + $table_name = 'esp_message'; |
|
289 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
290 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
291 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
292 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
293 | 293 | GRP_ID int(10) unsigned NULL, |
294 | 294 | MSG_token varchar(255) NULL, |
295 | 295 | TXN_ID int(10) unsigned NULL, |
@@ -321,18 +321,18 @@ discard block |
||
321 | 321 | KEY STS_ID (STS_ID), |
322 | 322 | KEY MSG_created (MSG_created), |
323 | 323 | KEY MSG_modified (MSG_modified)"; |
324 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
325 | - $table_name = 'esp_message_template'; |
|
326 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
324 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
325 | + $table_name = 'esp_message_template'; |
|
326 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
327 | 327 | GRP_ID int(10) unsigned NOT NULL, |
328 | 328 | MTP_context varchar(50) NOT NULL, |
329 | 329 | MTP_template_field varchar(30) NOT NULL, |
330 | 330 | MTP_content text NOT NULL, |
331 | 331 | PRIMARY KEY (MTP_ID), |
332 | 332 | KEY GRP_ID (GRP_ID)"; |
333 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | - $table_name = 'esp_message_template_group'; |
|
335 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
333 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | + $table_name = 'esp_message_template_group'; |
|
335 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
336 | 336 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
337 | 337 | MTP_name varchar(245) NOT NULL DEFAULT '', |
338 | 338 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -344,9 +344,9 @@ discard block |
||
344 | 344 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
345 | 345 | PRIMARY KEY (GRP_ID), |
346 | 346 | KEY MTP_user_id (MTP_user_id)"; |
347 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
348 | - $table_name = 'esp_payment'; |
|
349 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
347 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
348 | + $table_name = 'esp_payment'; |
|
349 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
350 | 350 | TXN_ID int(10) unsigned DEFAULT NULL, |
351 | 351 | STS_ID varchar(3) DEFAULT NULL, |
352 | 352 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | PRIMARY KEY (PAY_ID), |
364 | 364 | KEY PAY_timestamp (PAY_timestamp), |
365 | 365 | KEY TXN_ID (TXN_ID)"; |
366 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
367 | - $table_name = 'esp_payment_method'; |
|
368 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
366 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
367 | + $table_name = 'esp_payment_method'; |
|
368 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
369 | 369 | PMD_type varchar(124) DEFAULT NULL, |
370 | 370 | PMD_name varchar(255) DEFAULT NULL, |
371 | 371 | PMD_desc text, |
@@ -381,24 +381,24 @@ discard block |
||
381 | 381 | PRIMARY KEY (PMD_ID), |
382 | 382 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
383 | 383 | KEY PMD_type (PMD_type)"; |
384 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
385 | - $table_name = "esp_ticket_price"; |
|
386 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
384 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
385 | + $table_name = "esp_ticket_price"; |
|
386 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
387 | 387 | TKT_ID int(10) unsigned NOT NULL, |
388 | 388 | PRC_ID int(10) unsigned NOT NULL, |
389 | 389 | PRIMARY KEY (TKP_ID), |
390 | 390 | KEY TKT_ID (TKT_ID), |
391 | 391 | KEY PRC_ID (PRC_ID)"; |
392 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | - $table_name = "esp_ticket_template"; |
|
394 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
392 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | + $table_name = "esp_ticket_template"; |
|
394 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
395 | 395 | TTM_name varchar(45) NOT NULL, |
396 | 396 | TTM_description text, |
397 | 397 | TTM_file varchar(45), |
398 | 398 | PRIMARY KEY (TTM_ID)"; |
399 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
400 | - $table_name = 'esp_question'; |
|
401 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
399 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
400 | + $table_name = 'esp_question'; |
|
401 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
402 | 402 | QST_display_text text NOT NULL, |
403 | 403 | QST_admin_label varchar(255) NOT NULL, |
404 | 404 | QST_system varchar(25) DEFAULT NULL, |
@@ -412,18 +412,18 @@ discard block |
||
412 | 412 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
413 | 413 | PRIMARY KEY (QST_ID), |
414 | 414 | KEY QST_order (QST_order)'; |
415 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | - $table_name = 'esp_question_group_question'; |
|
417 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
415 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | + $table_name = 'esp_question_group_question'; |
|
417 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
418 | 418 | QSG_ID int(10) unsigned NOT NULL, |
419 | 419 | QST_ID int(10) unsigned NOT NULL, |
420 | 420 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
421 | 421 | PRIMARY KEY (QGQ_ID), |
422 | 422 | KEY QST_ID (QST_ID), |
423 | 423 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
424 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | - $table_name = 'esp_question_option'; |
|
426 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
424 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | + $table_name = 'esp_question_option'; |
|
426 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
427 | 427 | QSO_value varchar(255) NOT NULL, |
428 | 428 | QSO_desc text NOT NULL, |
429 | 429 | QST_ID int(10) unsigned NOT NULL, |
@@ -433,9 +433,9 @@ discard block |
||
433 | 433 | PRIMARY KEY (QSO_ID), |
434 | 434 | KEY QST_ID (QST_ID), |
435 | 435 | KEY QSO_order (QSO_order)"; |
436 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
437 | - $table_name = 'esp_registration'; |
|
438 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
436 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
437 | + $table_name = 'esp_registration'; |
|
438 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
439 | 439 | EVT_ID bigint(20) unsigned NOT NULL, |
440 | 440 | ATT_ID bigint(20) unsigned NOT NULL, |
441 | 441 | TXN_ID int(10) unsigned NOT NULL, |
@@ -459,18 +459,18 @@ discard block |
||
459 | 459 | KEY TKT_ID (TKT_ID), |
460 | 460 | KEY EVT_ID (EVT_ID), |
461 | 461 | KEY STS_ID (STS_ID)"; |
462 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
463 | - $table_name = 'esp_registration_payment'; |
|
464 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
462 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
463 | + $table_name = 'esp_registration_payment'; |
|
464 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
465 | 465 | REG_ID int(10) unsigned NOT NULL, |
466 | 466 | PAY_ID int(10) unsigned NULL, |
467 | 467 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
468 | 468 | PRIMARY KEY (RPY_ID), |
469 | 469 | KEY REG_ID (REG_ID), |
470 | 470 | KEY PAY_ID (PAY_ID)"; |
471 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
472 | - $table_name = 'esp_state'; |
|
473 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
471 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
472 | + $table_name = 'esp_state'; |
|
473 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
474 | 474 | CNT_ISO varchar(2) NOT NULL, |
475 | 475 | STA_abbrev varchar(24) NOT NULL, |
476 | 476 | STA_name varchar(100) NOT NULL, |
@@ -478,9 +478,9 @@ discard block |
||
478 | 478 | PRIMARY KEY (STA_ID), |
479 | 479 | KEY STA_abbrev (STA_abbrev), |
480 | 480 | KEY CNT_ISO (CNT_ISO)"; |
481 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
482 | - $table_name = 'esp_status'; |
|
483 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
481 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
482 | + $table_name = 'esp_status'; |
|
483 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
484 | 484 | STS_code varchar(45) NOT NULL, |
485 | 485 | STS_type varchar(45) NOT NULL, |
486 | 486 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -488,9 +488,9 @@ discard block |
||
488 | 488 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
489 | 489 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
490 | 490 | KEY STS_type (STS_type)"; |
491 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
492 | - $table_name = 'esp_transaction'; |
|
493 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
491 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
492 | + $table_name = 'esp_transaction'; |
|
493 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
494 | 494 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
495 | 495 | TXN_total decimal(12,3) DEFAULT '0.00', |
496 | 496 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | PRIMARY KEY (TXN_ID), |
503 | 503 | KEY TXN_timestamp (TXN_timestamp), |
504 | 504 | KEY STS_ID (STS_ID)"; |
505 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
506 | - $table_name = 'esp_venue_meta'; |
|
507 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
505 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
506 | + $table_name = 'esp_venue_meta'; |
|
507 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
508 | 508 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
509 | 509 | VNU_address varchar(255) DEFAULT NULL, |
510 | 510 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -523,10 +523,10 @@ discard block |
||
523 | 523 | KEY VNU_ID (VNU_ID), |
524 | 524 | KEY STA_ID (STA_ID), |
525 | 525 | KEY CNT_ISO (CNT_ISO)"; |
526 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
527 | - //modified tables |
|
528 | - $table_name = "esp_price"; |
|
529 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
526 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
527 | + //modified tables |
|
528 | + $table_name = "esp_price"; |
|
529 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
530 | 530 | PRT_ID tinyint(3) unsigned NOT NULL, |
531 | 531 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
532 | 532 | PRC_name varchar(245) NOT NULL, |
@@ -539,9 +539,9 @@ discard block |
||
539 | 539 | PRC_parent int(10) unsigned DEFAULT 0, |
540 | 540 | PRIMARY KEY (PRC_ID), |
541 | 541 | KEY PRT_ID (PRT_ID)"; |
542 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
543 | - $table_name = "esp_price_type"; |
|
544 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
542 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
543 | + $table_name = "esp_price_type"; |
|
544 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
545 | 545 | PRT_name varchar(45) NOT NULL, |
546 | 546 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
547 | 547 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -550,9 +550,9 @@ discard block |
||
550 | 550 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
551 | 551 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
552 | 552 | PRIMARY KEY (PRT_ID)"; |
553 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
554 | - $table_name = "esp_ticket"; |
|
555 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
553 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
554 | + $table_name = "esp_ticket"; |
|
555 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
556 | 556 | TTM_ID int(10) unsigned NOT NULL, |
557 | 557 | TKT_name varchar(245) NOT NULL DEFAULT '', |
558 | 558 | TKT_description text NOT NULL, |
@@ -575,9 +575,9 @@ discard block |
||
575 | 575 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
576 | 576 | PRIMARY KEY (TKT_ID), |
577 | 577 | KEY TKT_start_date (TKT_start_date)"; |
578 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
579 | - $table_name = 'esp_question_group'; |
|
580 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
578 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
579 | + $table_name = 'esp_question_group'; |
|
580 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
581 | 581 | QSG_name varchar(255) NOT NULL, |
582 | 582 | QSG_identifier varchar(100) NOT NULL, |
583 | 583 | QSG_desc text NULL, |
@@ -590,145 +590,145 @@ discard block |
||
590 | 590 | PRIMARY KEY (QSG_ID), |
591 | 591 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
592 | 592 | KEY QSG_order (QSG_order)'; |
593 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
594 | - /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
595 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
596 | - //(because many need to convert old string states to foreign keys into the states table) |
|
597 | - $script_4_1_defaults->insert_default_states(); |
|
598 | - $script_4_1_defaults->insert_default_countries(); |
|
599 | - /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
600 | - $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
601 | - $script_4_5_defaults->insert_default_price_types(); |
|
602 | - $script_4_5_defaults->insert_default_prices(); |
|
603 | - $script_4_5_defaults->insert_default_tickets(); |
|
604 | - /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
605 | - $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
606 | - $script_4_6_defaults->add_default_admin_only_payments(); |
|
607 | - $script_4_6_defaults->insert_default_currencies(); |
|
608 | - /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
609 | - $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
610 | - $script_4_8_defaults->verify_new_countries(); |
|
611 | - $script_4_8_defaults->verify_new_currencies(); |
|
612 | - $this->verify_db_collations(); |
|
613 | - $this->verify_db_collations_again(); |
|
614 | - return true; |
|
615 | - } |
|
593 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
594 | + /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
595 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
596 | + //(because many need to convert old string states to foreign keys into the states table) |
|
597 | + $script_4_1_defaults->insert_default_states(); |
|
598 | + $script_4_1_defaults->insert_default_countries(); |
|
599 | + /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
600 | + $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
601 | + $script_4_5_defaults->insert_default_price_types(); |
|
602 | + $script_4_5_defaults->insert_default_prices(); |
|
603 | + $script_4_5_defaults->insert_default_tickets(); |
|
604 | + /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
605 | + $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
606 | + $script_4_6_defaults->add_default_admin_only_payments(); |
|
607 | + $script_4_6_defaults->insert_default_currencies(); |
|
608 | + /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
609 | + $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
610 | + $script_4_8_defaults->verify_new_countries(); |
|
611 | + $script_4_8_defaults->verify_new_currencies(); |
|
612 | + $this->verify_db_collations(); |
|
613 | + $this->verify_db_collations_again(); |
|
614 | + return true; |
|
615 | + } |
|
616 | 616 | |
617 | 617 | |
618 | 618 | |
619 | - /** |
|
620 | - * @return boolean |
|
621 | - */ |
|
622 | - public function schema_changes_after_migration() |
|
623 | - { |
|
624 | - return true; |
|
625 | - } |
|
619 | + /** |
|
620 | + * @return boolean |
|
621 | + */ |
|
622 | + public function schema_changes_after_migration() |
|
623 | + { |
|
624 | + return true; |
|
625 | + } |
|
626 | 626 | |
627 | 627 | |
628 | 628 | |
629 | - public function migration_page_hooks() |
|
630 | - { |
|
631 | - } |
|
629 | + public function migration_page_hooks() |
|
630 | + { |
|
631 | + } |
|
632 | 632 | |
633 | 633 | |
634 | 634 | |
635 | - /** |
|
636 | - * Verify all EE4 models' tables use utf8mb4 collation |
|
637 | - * |
|
638 | - * @return void |
|
639 | - */ |
|
640 | - public function verify_db_collations() |
|
641 | - { |
|
642 | - global $wpdb; |
|
643 | - //double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
644 | - if ('utf8mb4' !== $wpdb->charset |
|
645 | - || get_option('ee_verified_db_collations', false)) { |
|
646 | - return; |
|
647 | - } |
|
648 | - // grab tables from each model |
|
649 | - $tables_to_check = array(); |
|
650 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
651 | - if (method_exists($model_name, 'instance')) { |
|
652 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
653 | - if ($model_obj instanceof EEM_Base) { |
|
654 | - foreach ($model_obj->get_tables() as $table) { |
|
655 | - if ( |
|
656 | - strpos($table->get_table_name(), 'esp_') |
|
657 | - && (is_main_site()//for main tables, verify global tables |
|
658 | - || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
659 | - ) |
|
660 | - && function_exists('maybe_convert_table_to_utf8mb4') |
|
661 | - ) { |
|
662 | - $tables_to_check[] = $table->get_table_name(); |
|
663 | - } |
|
664 | - } |
|
665 | - } |
|
666 | - } |
|
667 | - } |
|
668 | - //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
669 | - //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
670 | - //of hard-coding this |
|
671 | - $addon_tables = array( |
|
672 | - //mailchimp |
|
673 | - 'esp_event_mailchimp_list_group', |
|
674 | - 'esp_event_question_mailchimp_field', |
|
675 | - //multisite |
|
676 | - 'esp_blog_meta', |
|
677 | - //people |
|
678 | - 'esp_people_to_post', |
|
679 | - //promotions |
|
680 | - 'esp_promotion', |
|
681 | - 'esp_promotion_object', |
|
682 | - ); |
|
683 | - foreach ($addon_tables as $table_name) { |
|
684 | - $tables_to_check[] = $table_name; |
|
685 | - } |
|
686 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
687 | - //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
688 | - add_option('ee_verified_db_collations', true, null, 'no'); |
|
689 | - //seeing how this ran with the fix from 10435, no need to check again |
|
690 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
691 | - } |
|
635 | + /** |
|
636 | + * Verify all EE4 models' tables use utf8mb4 collation |
|
637 | + * |
|
638 | + * @return void |
|
639 | + */ |
|
640 | + public function verify_db_collations() |
|
641 | + { |
|
642 | + global $wpdb; |
|
643 | + //double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
644 | + if ('utf8mb4' !== $wpdb->charset |
|
645 | + || get_option('ee_verified_db_collations', false)) { |
|
646 | + return; |
|
647 | + } |
|
648 | + // grab tables from each model |
|
649 | + $tables_to_check = array(); |
|
650 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
651 | + if (method_exists($model_name, 'instance')) { |
|
652 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
653 | + if ($model_obj instanceof EEM_Base) { |
|
654 | + foreach ($model_obj->get_tables() as $table) { |
|
655 | + if ( |
|
656 | + strpos($table->get_table_name(), 'esp_') |
|
657 | + && (is_main_site()//for main tables, verify global tables |
|
658 | + || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
659 | + ) |
|
660 | + && function_exists('maybe_convert_table_to_utf8mb4') |
|
661 | + ) { |
|
662 | + $tables_to_check[] = $table->get_table_name(); |
|
663 | + } |
|
664 | + } |
|
665 | + } |
|
666 | + } |
|
667 | + } |
|
668 | + //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
669 | + //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
670 | + //of hard-coding this |
|
671 | + $addon_tables = array( |
|
672 | + //mailchimp |
|
673 | + 'esp_event_mailchimp_list_group', |
|
674 | + 'esp_event_question_mailchimp_field', |
|
675 | + //multisite |
|
676 | + 'esp_blog_meta', |
|
677 | + //people |
|
678 | + 'esp_people_to_post', |
|
679 | + //promotions |
|
680 | + 'esp_promotion', |
|
681 | + 'esp_promotion_object', |
|
682 | + ); |
|
683 | + foreach ($addon_tables as $table_name) { |
|
684 | + $tables_to_check[] = $table_name; |
|
685 | + } |
|
686 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
687 | + //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
688 | + add_option('ee_verified_db_collations', true, null, 'no'); |
|
689 | + //seeing how this ran with the fix from 10435, no need to check again |
|
690 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
691 | + } |
|
692 | 692 | |
693 | 693 | |
694 | 694 | |
695 | - /** |
|
696 | - * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
697 | - * which meant some DB collations might not have been updated |
|
698 | - * @return void |
|
699 | - */ |
|
700 | - public function verify_db_collations_again(){ |
|
701 | - global $wpdb; |
|
702 | - //double-check we haven't already done this or that the DB doesn't support it |
|
703 | - //compare to how WordPress' upgrade_430() function does this check |
|
704 | - if ('utf8mb4' !== $wpdb->charset |
|
705 | - || get_option('ee_verified_db_collations_again', false)) { |
|
706 | - return; |
|
707 | - } |
|
708 | - $tables_to_check = array( |
|
709 | - 'esp_attendee_meta', |
|
710 | - 'esp_message' |
|
711 | - ); |
|
712 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
713 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
714 | - } |
|
695 | + /** |
|
696 | + * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
697 | + * which meant some DB collations might not have been updated |
|
698 | + * @return void |
|
699 | + */ |
|
700 | + public function verify_db_collations_again(){ |
|
701 | + global $wpdb; |
|
702 | + //double-check we haven't already done this or that the DB doesn't support it |
|
703 | + //compare to how WordPress' upgrade_430() function does this check |
|
704 | + if ('utf8mb4' !== $wpdb->charset |
|
705 | + || get_option('ee_verified_db_collations_again', false)) { |
|
706 | + return; |
|
707 | + } |
|
708 | + $tables_to_check = array( |
|
709 | + 'esp_attendee_meta', |
|
710 | + 'esp_message' |
|
711 | + ); |
|
712 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
713 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
714 | + } |
|
715 | 715 | |
716 | 716 | |
717 | 717 | |
718 | - /** |
|
719 | - * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
720 | - * @param $tables_to_check |
|
721 | - * @return boolean true if logic ran, false if it didn't |
|
722 | - */ |
|
723 | - protected function _verify_db_collations_for_tables($tables_to_check) |
|
724 | - { |
|
725 | - foreach ($tables_to_check as $table_name) { |
|
726 | - $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
727 | - if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
728 | - && $this->_get_table_analysis()->tableExists($table_name) |
|
729 | - ) { |
|
730 | - maybe_convert_table_to_utf8mb4($table_name); |
|
731 | - } |
|
732 | - } |
|
733 | - } |
|
718 | + /** |
|
719 | + * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
720 | + * @param $tables_to_check |
|
721 | + * @return boolean true if logic ran, false if it didn't |
|
722 | + */ |
|
723 | + protected function _verify_db_collations_for_tables($tables_to_check) |
|
724 | + { |
|
725 | + foreach ($tables_to_check as $table_name) { |
|
726 | + $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
727 | + if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
728 | + && $this->_get_table_analysis()->tableExists($table_name) |
|
729 | + ) { |
|
730 | + maybe_convert_table_to_utf8mb4($table_name); |
|
731 | + } |
|
732 | + } |
|
733 | + } |
|
734 | 734 | } |
735 | 735 | \ No newline at end of file |
@@ -22,457 +22,457 @@ discard block |
||
22 | 22 | final class EE_Admin implements InterminableInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var EE_Admin $_instance |
|
27 | - */ |
|
28 | - private static $_instance; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
32 | - */ |
|
33 | - private $persistent_admin_notice_manager; |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @return EE_Admin |
|
38 | - * @throws EE_Error |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated |
|
43 | - if (! self::$_instance instanceof EE_Admin) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - return self::$_instance; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @return EE_Admin |
|
52 | - * @throws EE_Error |
|
53 | - */ |
|
54 | - public static function reset() |
|
55 | - { |
|
56 | - self::$_instance = null; |
|
57 | - return self::instance(); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * class constructor |
|
63 | - * |
|
64 | - * @throws EE_Error |
|
65 | - * @throws InvalidDataTypeException |
|
66 | - * @throws InvalidInterfaceException |
|
67 | - * @throws InvalidArgumentException |
|
68 | - */ |
|
69 | - protected function __construct() |
|
70 | - { |
|
71 | - // define global EE_Admin constants |
|
72 | - $this->_define_all_constants(); |
|
73 | - // set autoloaders for our admin page classes based on included path information |
|
74 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
75 | - // admin hooks |
|
76 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
77 | - // load EE_Request_Handler early |
|
78 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
79 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
80 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
81 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
82 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
83 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
84 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
85 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
86 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
87 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
88 | - //reset Environment config (we only do this on admin page loads); |
|
89 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
90 | - do_action('AHEE__EE_Admin__loaded'); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * _define_all_constants |
|
97 | - * define constants that are set globally for all admin pages |
|
98 | - * |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - private function _define_all_constants() |
|
102 | - { |
|
103 | - if (! defined('EE_ADMIN_URL')) { |
|
104 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
105 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
106 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
107 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
108 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
115 | - * |
|
116 | - * @param array $links |
|
117 | - * @param string $plugin |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public function filter_plugin_actions($links, $plugin) |
|
121 | - { |
|
122 | - // set $main_file in stone |
|
123 | - static $main_file; |
|
124 | - // if $main_file is not set yet |
|
125 | - if (! $main_file) { |
|
126 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
127 | - } |
|
128 | - if ($plugin === $main_file) { |
|
129 | - // compare current plugin to this one |
|
130 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
131 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
132 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
133 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
134 | - . '</a>'; |
|
135 | - array_unshift($links, $maintenance_link); |
|
136 | - } else { |
|
137 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
138 | - . esc_html__('Settings', 'event_espresso') |
|
139 | - . '</a>'; |
|
140 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
141 | - . esc_html__('Events', 'event_espresso') |
|
142 | - . '</a>'; |
|
143 | - // add before other links |
|
144 | - array_unshift($links, $org_settings_link, $events_link); |
|
145 | - } |
|
146 | - } |
|
147 | - return $links; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * _get_request |
|
153 | - * |
|
154 | - * @return void |
|
155 | - * @throws EE_Error |
|
156 | - * @throws InvalidArgumentException |
|
157 | - * @throws InvalidDataTypeException |
|
158 | - * @throws InvalidInterfaceException |
|
159 | - * @throws ReflectionException |
|
160 | - */ |
|
161 | - public function get_request() |
|
162 | - { |
|
163 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
164 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * hide_admin_pages_except_maintenance_mode |
|
171 | - * |
|
172 | - * @param array $admin_page_folder_names |
|
173 | - * @return array |
|
174 | - */ |
|
175 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
176 | - { |
|
177 | - return array( |
|
178 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
179 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
180 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
181 | - ); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
188 | - * EE_Front_Controller's init phases have run |
|
189 | - * |
|
190 | - * @return void |
|
191 | - * @throws EE_Error |
|
192 | - * @throws InvalidArgumentException |
|
193 | - * @throws InvalidDataTypeException |
|
194 | - * @throws InvalidInterfaceException |
|
195 | - * @throws ReflectionException |
|
196 | - * @throws ServiceNotFoundException |
|
197 | - */ |
|
198 | - public function init() |
|
199 | - { |
|
200 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
201 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
202 | - //ok so we want to enable the entire admin |
|
203 | - $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
204 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager', |
|
205 | - array( |
|
206 | - EE_Admin_Page::add_query_args_and_nonce( |
|
207 | - array( |
|
208 | - 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
209 | - 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
210 | - ), |
|
211 | - EE_ADMIN_URL |
|
212 | - ), |
|
213 | - ) |
|
214 | - ); |
|
215 | - $this->maybeSetDatetimeWarningNotice(); |
|
216 | - //at a glance dashboard widget |
|
217 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
218 | - //filter for get_edit_post_link used on comments for custom post types |
|
219 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
220 | - } |
|
221 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
222 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
223 | - try { |
|
224 | - //this loads the controller for the admin pages which will setup routing etc |
|
225 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
226 | - } catch (EE_Error $e) { |
|
227 | - $e->get_error(); |
|
228 | - } |
|
229 | - } |
|
230 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
231 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
232 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
233 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
234 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
235 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * get_persistent_admin_notices |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @return void |
|
244 | - * @throws EE_Error |
|
245 | - * @throws InvalidArgumentException |
|
246 | - * @throws InvalidDataTypeException |
|
247 | - * @throws InvalidInterfaceException |
|
248 | - */ |
|
249 | - public function maybeSetDatetimeWarningNotice() |
|
250 | - { |
|
251 | - //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
252 | - //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
253 | - //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
254 | - //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
255 | - if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
256 | - && ! get_option('timezone_string') |
|
257 | - && EEM_Event::instance()->count() > 0 |
|
258 | - ) { |
|
259 | - new PersistentAdminNotice( |
|
260 | - 'datetime_fix_notice', |
|
261 | - sprintf( |
|
262 | - esc_html__( |
|
263 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
264 | - 'event_espresso' |
|
265 | - ), |
|
266 | - '<strong>', |
|
267 | - '</strong>', |
|
268 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
269 | - '</a>', |
|
270 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
271 | - array( |
|
272 | - 'page' => 'espresso_maintenance_settings', |
|
273 | - 'action' => 'datetime_tools' |
|
274 | - ), |
|
275 | - admin_url('admin.php') |
|
276 | - ) . '">' |
|
277 | - ), |
|
278 | - false, |
|
279 | - 'manage_options', |
|
280 | - 'datetime_fix_persistent_notice' |
|
281 | - ); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
289 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
290 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
291 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
292 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
293 | - * |
|
294 | - * @param WP_Post $post_type WP post type object |
|
295 | - * @return WP_Post |
|
296 | - * @throws InvalidArgumentException |
|
297 | - * @throws InvalidDataTypeException |
|
298 | - * @throws InvalidInterfaceException |
|
299 | - */ |
|
300 | - public function remove_pages_from_nav_menu($post_type) |
|
301 | - { |
|
302 | - //if this isn't the "pages" post type let's get out |
|
303 | - if ($post_type->name !== 'page') { |
|
304 | - return $post_type; |
|
305 | - } |
|
306 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
307 | - $post_type->_default_query = array( |
|
308 | - 'post__not_in' => $critical_pages, |
|
309 | - ); |
|
310 | - return $post_type; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
317 | - * metaboxes get shown as well |
|
318 | - * |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
322 | - { |
|
323 | - global $wp_meta_boxes, $pagenow; |
|
324 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
325 | - return; |
|
326 | - } |
|
327 | - $user = wp_get_current_user(); |
|
328 | - //has this been done yet? |
|
329 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
330 | - return; |
|
331 | - } |
|
332 | - |
|
333 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
334 | - $initial_meta_boxes = apply_filters( |
|
335 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
336 | - array( |
|
337 | - 'nav-menu-theme-locations', |
|
338 | - 'add-page', |
|
339 | - 'add-custom-links', |
|
340 | - 'add-category', |
|
341 | - 'add-espresso_events', |
|
342 | - 'add-espresso_venues', |
|
343 | - 'add-espresso_event_categories', |
|
344 | - 'add-espresso_venue_categories', |
|
345 | - 'add-post-type-post', |
|
346 | - 'add-post-type-page', |
|
347 | - ) |
|
348 | - ); |
|
349 | - |
|
350 | - if (is_array($hidden_meta_boxes)) { |
|
351 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
352 | - if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
353 | - unset($hidden_meta_boxes[$key]); |
|
354 | - } |
|
355 | - } |
|
356 | - } |
|
357 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
358 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
365 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
366 | - * |
|
367 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
368 | - * addons etc. |
|
369 | - * @return void |
|
370 | - */ |
|
371 | - public function register_custom_nav_menu_boxes() |
|
372 | - { |
|
373 | - add_meta_box( |
|
374 | - 'add-extra-nav-menu-pages', |
|
375 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
376 | - array($this, 'ee_cpt_archive_pages'), |
|
377 | - 'nav-menus', |
|
378 | - 'side', |
|
379 | - 'core' |
|
380 | - ); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
387 | - * |
|
388 | - * @since 4.3.0 |
|
389 | - * @param string $link the original link generated by wp |
|
390 | - * @param int $id post id |
|
391 | - * @return string the (maybe) modified link |
|
392 | - */ |
|
393 | - public function modify_edit_post_link($link, $id) |
|
394 | - { |
|
395 | - if (! $post = get_post($id)) { |
|
396 | - return $link; |
|
397 | - } |
|
398 | - if ($post->post_type === 'espresso_attendees') { |
|
399 | - $query_args = array( |
|
400 | - 'action' => 'edit_attendee', |
|
401 | - 'post' => $id, |
|
402 | - ); |
|
403 | - return EEH_URL::add_query_args_and_nonce( |
|
404 | - $query_args, |
|
405 | - admin_url('admin.php?page=espresso_registrations') |
|
406 | - ); |
|
407 | - } |
|
408 | - return $link; |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - |
|
413 | - public function ee_cpt_archive_pages() |
|
414 | - { |
|
415 | - global $nav_menu_selected_id; |
|
416 | - $db_fields = false; |
|
417 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
418 | - $current_tab = 'event-archives'; |
|
419 | - $removed_args = array( |
|
420 | - 'action', |
|
421 | - 'customlink-tab', |
|
422 | - 'edit-menu-item', |
|
423 | - 'menu-item', |
|
424 | - 'page-tab', |
|
425 | - '_wpnonce', |
|
426 | - ); |
|
427 | - ?> |
|
25 | + /** |
|
26 | + * @var EE_Admin $_instance |
|
27 | + */ |
|
28 | + private static $_instance; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
32 | + */ |
|
33 | + private $persistent_admin_notice_manager; |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @return EE_Admin |
|
38 | + * @throws EE_Error |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated |
|
43 | + if (! self::$_instance instanceof EE_Admin) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + return self::$_instance; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @return EE_Admin |
|
52 | + * @throws EE_Error |
|
53 | + */ |
|
54 | + public static function reset() |
|
55 | + { |
|
56 | + self::$_instance = null; |
|
57 | + return self::instance(); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * class constructor |
|
63 | + * |
|
64 | + * @throws EE_Error |
|
65 | + * @throws InvalidDataTypeException |
|
66 | + * @throws InvalidInterfaceException |
|
67 | + * @throws InvalidArgumentException |
|
68 | + */ |
|
69 | + protected function __construct() |
|
70 | + { |
|
71 | + // define global EE_Admin constants |
|
72 | + $this->_define_all_constants(); |
|
73 | + // set autoloaders for our admin page classes based on included path information |
|
74 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
75 | + // admin hooks |
|
76 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
77 | + // load EE_Request_Handler early |
|
78 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
79 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
80 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
81 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
82 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
83 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
84 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
85 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
86 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
87 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
88 | + //reset Environment config (we only do this on admin page loads); |
|
89 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
90 | + do_action('AHEE__EE_Admin__loaded'); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * _define_all_constants |
|
97 | + * define constants that are set globally for all admin pages |
|
98 | + * |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + private function _define_all_constants() |
|
102 | + { |
|
103 | + if (! defined('EE_ADMIN_URL')) { |
|
104 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
105 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
106 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
107 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
108 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
115 | + * |
|
116 | + * @param array $links |
|
117 | + * @param string $plugin |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public function filter_plugin_actions($links, $plugin) |
|
121 | + { |
|
122 | + // set $main_file in stone |
|
123 | + static $main_file; |
|
124 | + // if $main_file is not set yet |
|
125 | + if (! $main_file) { |
|
126 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
127 | + } |
|
128 | + if ($plugin === $main_file) { |
|
129 | + // compare current plugin to this one |
|
130 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
131 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
132 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
133 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
134 | + . '</a>'; |
|
135 | + array_unshift($links, $maintenance_link); |
|
136 | + } else { |
|
137 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
138 | + . esc_html__('Settings', 'event_espresso') |
|
139 | + . '</a>'; |
|
140 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
141 | + . esc_html__('Events', 'event_espresso') |
|
142 | + . '</a>'; |
|
143 | + // add before other links |
|
144 | + array_unshift($links, $org_settings_link, $events_link); |
|
145 | + } |
|
146 | + } |
|
147 | + return $links; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * _get_request |
|
153 | + * |
|
154 | + * @return void |
|
155 | + * @throws EE_Error |
|
156 | + * @throws InvalidArgumentException |
|
157 | + * @throws InvalidDataTypeException |
|
158 | + * @throws InvalidInterfaceException |
|
159 | + * @throws ReflectionException |
|
160 | + */ |
|
161 | + public function get_request() |
|
162 | + { |
|
163 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
164 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * hide_admin_pages_except_maintenance_mode |
|
171 | + * |
|
172 | + * @param array $admin_page_folder_names |
|
173 | + * @return array |
|
174 | + */ |
|
175 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
176 | + { |
|
177 | + return array( |
|
178 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
179 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
180 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
181 | + ); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
188 | + * EE_Front_Controller's init phases have run |
|
189 | + * |
|
190 | + * @return void |
|
191 | + * @throws EE_Error |
|
192 | + * @throws InvalidArgumentException |
|
193 | + * @throws InvalidDataTypeException |
|
194 | + * @throws InvalidInterfaceException |
|
195 | + * @throws ReflectionException |
|
196 | + * @throws ServiceNotFoundException |
|
197 | + */ |
|
198 | + public function init() |
|
199 | + { |
|
200 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
201 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
202 | + //ok so we want to enable the entire admin |
|
203 | + $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
204 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager', |
|
205 | + array( |
|
206 | + EE_Admin_Page::add_query_args_and_nonce( |
|
207 | + array( |
|
208 | + 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
209 | + 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
210 | + ), |
|
211 | + EE_ADMIN_URL |
|
212 | + ), |
|
213 | + ) |
|
214 | + ); |
|
215 | + $this->maybeSetDatetimeWarningNotice(); |
|
216 | + //at a glance dashboard widget |
|
217 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
218 | + //filter for get_edit_post_link used on comments for custom post types |
|
219 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
220 | + } |
|
221 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
222 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
223 | + try { |
|
224 | + //this loads the controller for the admin pages which will setup routing etc |
|
225 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
226 | + } catch (EE_Error $e) { |
|
227 | + $e->get_error(); |
|
228 | + } |
|
229 | + } |
|
230 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
231 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
232 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
233 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
234 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
235 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * get_persistent_admin_notices |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @return void |
|
244 | + * @throws EE_Error |
|
245 | + * @throws InvalidArgumentException |
|
246 | + * @throws InvalidDataTypeException |
|
247 | + * @throws InvalidInterfaceException |
|
248 | + */ |
|
249 | + public function maybeSetDatetimeWarningNotice() |
|
250 | + { |
|
251 | + //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
252 | + //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
253 | + //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
254 | + //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
255 | + if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
256 | + && ! get_option('timezone_string') |
|
257 | + && EEM_Event::instance()->count() > 0 |
|
258 | + ) { |
|
259 | + new PersistentAdminNotice( |
|
260 | + 'datetime_fix_notice', |
|
261 | + sprintf( |
|
262 | + esc_html__( |
|
263 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
264 | + 'event_espresso' |
|
265 | + ), |
|
266 | + '<strong>', |
|
267 | + '</strong>', |
|
268 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
269 | + '</a>', |
|
270 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
271 | + array( |
|
272 | + 'page' => 'espresso_maintenance_settings', |
|
273 | + 'action' => 'datetime_tools' |
|
274 | + ), |
|
275 | + admin_url('admin.php') |
|
276 | + ) . '">' |
|
277 | + ), |
|
278 | + false, |
|
279 | + 'manage_options', |
|
280 | + 'datetime_fix_persistent_notice' |
|
281 | + ); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
289 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
290 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
291 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
292 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
293 | + * |
|
294 | + * @param WP_Post $post_type WP post type object |
|
295 | + * @return WP_Post |
|
296 | + * @throws InvalidArgumentException |
|
297 | + * @throws InvalidDataTypeException |
|
298 | + * @throws InvalidInterfaceException |
|
299 | + */ |
|
300 | + public function remove_pages_from_nav_menu($post_type) |
|
301 | + { |
|
302 | + //if this isn't the "pages" post type let's get out |
|
303 | + if ($post_type->name !== 'page') { |
|
304 | + return $post_type; |
|
305 | + } |
|
306 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
307 | + $post_type->_default_query = array( |
|
308 | + 'post__not_in' => $critical_pages, |
|
309 | + ); |
|
310 | + return $post_type; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
317 | + * metaboxes get shown as well |
|
318 | + * |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
322 | + { |
|
323 | + global $wp_meta_boxes, $pagenow; |
|
324 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
325 | + return; |
|
326 | + } |
|
327 | + $user = wp_get_current_user(); |
|
328 | + //has this been done yet? |
|
329 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
330 | + return; |
|
331 | + } |
|
332 | + |
|
333 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
334 | + $initial_meta_boxes = apply_filters( |
|
335 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
336 | + array( |
|
337 | + 'nav-menu-theme-locations', |
|
338 | + 'add-page', |
|
339 | + 'add-custom-links', |
|
340 | + 'add-category', |
|
341 | + 'add-espresso_events', |
|
342 | + 'add-espresso_venues', |
|
343 | + 'add-espresso_event_categories', |
|
344 | + 'add-espresso_venue_categories', |
|
345 | + 'add-post-type-post', |
|
346 | + 'add-post-type-page', |
|
347 | + ) |
|
348 | + ); |
|
349 | + |
|
350 | + if (is_array($hidden_meta_boxes)) { |
|
351 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
352 | + if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
353 | + unset($hidden_meta_boxes[$key]); |
|
354 | + } |
|
355 | + } |
|
356 | + } |
|
357 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
358 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
365 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
366 | + * |
|
367 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
368 | + * addons etc. |
|
369 | + * @return void |
|
370 | + */ |
|
371 | + public function register_custom_nav_menu_boxes() |
|
372 | + { |
|
373 | + add_meta_box( |
|
374 | + 'add-extra-nav-menu-pages', |
|
375 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
376 | + array($this, 'ee_cpt_archive_pages'), |
|
377 | + 'nav-menus', |
|
378 | + 'side', |
|
379 | + 'core' |
|
380 | + ); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
387 | + * |
|
388 | + * @since 4.3.0 |
|
389 | + * @param string $link the original link generated by wp |
|
390 | + * @param int $id post id |
|
391 | + * @return string the (maybe) modified link |
|
392 | + */ |
|
393 | + public function modify_edit_post_link($link, $id) |
|
394 | + { |
|
395 | + if (! $post = get_post($id)) { |
|
396 | + return $link; |
|
397 | + } |
|
398 | + if ($post->post_type === 'espresso_attendees') { |
|
399 | + $query_args = array( |
|
400 | + 'action' => 'edit_attendee', |
|
401 | + 'post' => $id, |
|
402 | + ); |
|
403 | + return EEH_URL::add_query_args_and_nonce( |
|
404 | + $query_args, |
|
405 | + admin_url('admin.php?page=espresso_registrations') |
|
406 | + ); |
|
407 | + } |
|
408 | + return $link; |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + |
|
413 | + public function ee_cpt_archive_pages() |
|
414 | + { |
|
415 | + global $nav_menu_selected_id; |
|
416 | + $db_fields = false; |
|
417 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
418 | + $current_tab = 'event-archives'; |
|
419 | + $removed_args = array( |
|
420 | + 'action', |
|
421 | + 'customlink-tab', |
|
422 | + 'edit-menu-item', |
|
423 | + 'menu-item', |
|
424 | + 'page-tab', |
|
425 | + '_wpnonce', |
|
426 | + ); |
|
427 | + ?> |
|
428 | 428 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
429 | 429 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
430 | 430 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
431 | 431 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
432 | 432 | href="<?php if ($nav_menu_selected_id) { |
433 | - echo esc_url( |
|
434 | - add_query_arg( |
|
435 | - 'extra-nav-menu-pages-tab', |
|
436 | - 'event-archives', |
|
437 | - remove_query_arg($removed_args) |
|
438 | - ) |
|
439 | - ); |
|
440 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
433 | + echo esc_url( |
|
434 | + add_query_arg( |
|
435 | + 'extra-nav-menu-pages-tab', |
|
436 | + 'event-archives', |
|
437 | + remove_query_arg($removed_args) |
|
438 | + ) |
|
439 | + ); |
|
440 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
441 | 441 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
442 | 442 | </a> |
443 | 443 | </li> |
444 | 444 | </ul><!-- .posttype-tabs --> |
445 | 445 | |
446 | 446 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
447 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
448 | - ?>"> |
|
447 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
448 | + ?>"> |
|
449 | 449 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
450 | 450 | <?php |
451 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
452 | - $args['walker'] = $walker; |
|
453 | - echo walk_nav_menu_tree( |
|
454 | - array_map( |
|
455 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
456 | - $pages |
|
457 | - ), |
|
458 | - 0, |
|
459 | - (object) $args |
|
460 | - ); |
|
461 | - ?> |
|
451 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
452 | + $args['walker'] = $walker; |
|
453 | + echo walk_nav_menu_tree( |
|
454 | + array_map( |
|
455 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
456 | + $pages |
|
457 | + ), |
|
458 | + 0, |
|
459 | + (object) $args |
|
460 | + ); |
|
461 | + ?> |
|
462 | 462 | </ul> |
463 | 463 | </div><!-- /.tabs-panel --> |
464 | 464 | |
465 | 465 | <p class="button-controls"> |
466 | 466 | <span class="list-controls"> |
467 | 467 | <a href="<?php |
468 | - echo esc_url(add_query_arg( |
|
469 | - array( |
|
470 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
471 | - 'selectall' => 1, |
|
472 | - ), |
|
473 | - remove_query_arg($removed_args) |
|
474 | - )); |
|
475 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
468 | + echo esc_url(add_query_arg( |
|
469 | + array( |
|
470 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
471 | + 'selectall' => 1, |
|
472 | + ), |
|
473 | + remove_query_arg($removed_args) |
|
474 | + )); |
|
475 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
476 | 476 | </span> |
477 | 477 | <span class="add-to-menu"> |
478 | 478 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -485,471 +485,471 @@ discard block |
||
485 | 485 | |
486 | 486 | </div><!-- /.posttypediv --> |
487 | 487 | <?php |
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Returns an array of event archive nav items. |
|
493 | - * |
|
494 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
495 | - * method we use for getting the extra nav menu items |
|
496 | - * @return array |
|
497 | - */ |
|
498 | - private function _get_extra_nav_menu_pages_items() |
|
499 | - { |
|
500 | - $menuitems[] = array( |
|
501 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
502 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
503 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
504 | - ); |
|
505 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
511 | - * the properties and converts it to the menu item object. |
|
512 | - * |
|
513 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
514 | - * @param $menu_item_values |
|
515 | - * @return stdClass |
|
516 | - */ |
|
517 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
518 | - { |
|
519 | - $menu_item = new stdClass(); |
|
520 | - $keys = array( |
|
521 | - 'ID' => 0, |
|
522 | - 'db_id' => 0, |
|
523 | - 'menu_item_parent' => 0, |
|
524 | - 'object_id' => -1, |
|
525 | - 'post_parent' => 0, |
|
526 | - 'type' => 'custom', |
|
527 | - 'object' => '', |
|
528 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
529 | - 'title' => '', |
|
530 | - 'url' => '', |
|
531 | - 'target' => '', |
|
532 | - 'attr_title' => '', |
|
533 | - 'description' => '', |
|
534 | - 'classes' => array(), |
|
535 | - 'xfn' => '', |
|
536 | - ); |
|
537 | - |
|
538 | - foreach ($keys as $key => $value) { |
|
539 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
540 | - } |
|
541 | - return $menu_item; |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
547 | - * EE_Admin_Page route is called. |
|
548 | - * |
|
549 | - * @return void |
|
550 | - */ |
|
551 | - public function route_admin_request() |
|
552 | - { |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
558 | - * |
|
559 | - * @return void |
|
560 | - */ |
|
561 | - public function wp_loaded() |
|
562 | - { |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * admin_init |
|
568 | - * |
|
569 | - * @return void |
|
570 | - * @throws EE_Error |
|
571 | - * @throws InvalidArgumentException |
|
572 | - * @throws InvalidDataTypeException |
|
573 | - * @throws InvalidInterfaceException |
|
574 | - * @throws ReflectionException |
|
575 | - */ |
|
576 | - public function admin_init() |
|
577 | - { |
|
578 | - |
|
579 | - /** |
|
580 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
581 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
582 | - * - check if doing post processing. |
|
583 | - * - check if doing post processing of one of EE CPTs |
|
584 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
585 | - */ |
|
586 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
587 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
588 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
594 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
595 | - * Pages" tab in the EE General Settings Admin page. |
|
596 | - * This is for user-proofing. |
|
597 | - */ |
|
598 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
604 | - * |
|
605 | - * @param string $output Current output. |
|
606 | - * @return string |
|
607 | - * @throws InvalidArgumentException |
|
608 | - * @throws InvalidDataTypeException |
|
609 | - * @throws InvalidInterfaceException |
|
610 | - */ |
|
611 | - public function modify_dropdown_pages($output) |
|
612 | - { |
|
613 | - //get critical pages |
|
614 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
615 | - |
|
616 | - //split current output by line break for easier parsing. |
|
617 | - $split_output = explode("\n", $output); |
|
618 | - |
|
619 | - //loop through to remove any critical pages from the array. |
|
620 | - foreach ($critical_pages as $page_id) { |
|
621 | - $needle = 'value="' . $page_id . '"'; |
|
622 | - foreach ($split_output as $key => $haystack) { |
|
623 | - if (strpos($haystack, $needle) !== false) { |
|
624 | - unset($split_output[$key]); |
|
625 | - } |
|
626 | - } |
|
627 | - } |
|
628 | - //replace output with the new contents |
|
629 | - return implode("\n", $split_output); |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * enqueue all admin scripts that need loaded for admin pages |
|
635 | - * |
|
636 | - * @return void |
|
637 | - */ |
|
638 | - public function enqueue_admin_scripts() |
|
639 | - { |
|
640 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
641 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
642 | - // calls. |
|
643 | - wp_enqueue_script( |
|
644 | - 'ee-inject-wp', |
|
645 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
646 | - array('jquery'), |
|
647 | - EVENT_ESPRESSO_VERSION, |
|
648 | - true |
|
649 | - ); |
|
650 | - // register cookie script for future dependencies |
|
651 | - wp_register_script( |
|
652 | - 'jquery-cookie', |
|
653 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
654 | - array('jquery'), |
|
655 | - '2.1', |
|
656 | - true |
|
657 | - ); |
|
658 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
659 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
660 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
661 | - //joyride style |
|
662 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
663 | - wp_register_style( |
|
664 | - 'ee-joyride-css', |
|
665 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
666 | - array('joyride-css'), |
|
667 | - EVENT_ESPRESSO_VERSION |
|
668 | - ); |
|
669 | - wp_register_script( |
|
670 | - 'joyride-modernizr', |
|
671 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
672 | - array(), |
|
673 | - '2.1', |
|
674 | - true |
|
675 | - ); |
|
676 | - //joyride JS |
|
677 | - wp_register_script( |
|
678 | - 'jquery-joyride', |
|
679 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
680 | - array('jquery-cookie', 'joyride-modernizr'), |
|
681 | - '2.1', |
|
682 | - true |
|
683 | - ); |
|
684 | - // wanna go for a joyride? |
|
685 | - wp_enqueue_style('ee-joyride-css'); |
|
686 | - wp_enqueue_script('jquery-joyride'); |
|
687 | - } |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * display_admin_notices |
|
693 | - * |
|
694 | - * @return void |
|
695 | - */ |
|
696 | - public function display_admin_notices() |
|
697 | - { |
|
698 | - echo EE_Error::get_notices(); |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * @param array $elements |
|
705 | - * @return array |
|
706 | - * @throws EE_Error |
|
707 | - * @throws InvalidArgumentException |
|
708 | - * @throws InvalidDataTypeException |
|
709 | - * @throws InvalidInterfaceException |
|
710 | - */ |
|
711 | - public function dashboard_glance_items($elements) |
|
712 | - { |
|
713 | - $elements = is_array($elements) ? $elements : array($elements); |
|
714 | - $events = EEM_Event::instance()->count(); |
|
715 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
716 | - array('page' => 'espresso_events'), |
|
717 | - admin_url('admin.php') |
|
718 | - ); |
|
719 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
720 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
721 | - $registrations = EEM_Registration::instance()->count( |
|
722 | - array( |
|
723 | - array( |
|
724 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
725 | - ), |
|
726 | - ) |
|
727 | - ); |
|
728 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
729 | - array('page' => 'espresso_registrations'), |
|
730 | - admin_url('admin.php') |
|
731 | - ); |
|
732 | - $items['registrations']['text'] = sprintf( |
|
733 | - _n('%s Registration', '%s Registrations', $registrations), |
|
734 | - number_format_i18n($registrations) |
|
735 | - ); |
|
736 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
737 | - |
|
738 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
739 | - |
|
740 | - foreach ($items as $type => $item_properties) { |
|
741 | - $elements[] = sprintf( |
|
742 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
743 | - $item_properties['url'], |
|
744 | - $item_properties['title'], |
|
745 | - $item_properties['text'] |
|
746 | - ); |
|
747 | - } |
|
748 | - return $elements; |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - /** |
|
753 | - * check_for_invalid_datetime_formats |
|
754 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
755 | - * their selected format can be parsed by PHP |
|
756 | - * |
|
757 | - * @param $value |
|
758 | - * @param $option |
|
759 | - * @throws EE_Error |
|
760 | - * @return string |
|
761 | - */ |
|
762 | - public function check_for_invalid_datetime_formats($value, $option) |
|
763 | - { |
|
764 | - // check for date_format or time_format |
|
765 | - switch ($option) { |
|
766 | - case 'date_format': |
|
767 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
768 | - break; |
|
769 | - case 'time_format': |
|
770 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
771 | - break; |
|
772 | - default: |
|
773 | - $date_time_format = false; |
|
774 | - } |
|
775 | - // do we have a date_time format to check ? |
|
776 | - if ($date_time_format) { |
|
777 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
778 | - |
|
779 | - if (is_array($error_msg)) { |
|
780 | - $msg = '<p>' |
|
781 | - . sprintf( |
|
782 | - esc_html__( |
|
783 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
784 | - 'event_espresso' |
|
785 | - ), |
|
786 | - date($date_time_format), |
|
787 | - $date_time_format |
|
788 | - ) |
|
789 | - . '</p><p><ul>'; |
|
790 | - |
|
791 | - |
|
792 | - foreach ($error_msg as $error) { |
|
793 | - $msg .= '<li>' . $error . '</li>'; |
|
794 | - } |
|
795 | - |
|
796 | - $msg .= '</ul></p><p>' |
|
797 | - . sprintf( |
|
798 | - esc_html__( |
|
799 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
800 | - 'event_espresso' |
|
801 | - ), |
|
802 | - '<span style="color:#D54E21;">', |
|
803 | - '</span>' |
|
804 | - ) |
|
805 | - . '</p>'; |
|
806 | - |
|
807 | - // trigger WP settings error |
|
808 | - add_settings_error( |
|
809 | - 'date_format', |
|
810 | - 'date_format', |
|
811 | - $msg |
|
812 | - ); |
|
813 | - |
|
814 | - // set format to something valid |
|
815 | - switch ($option) { |
|
816 | - case 'date_format': |
|
817 | - $value = 'F j, Y'; |
|
818 | - break; |
|
819 | - case 'time_format': |
|
820 | - $value = 'g:i a'; |
|
821 | - break; |
|
822 | - } |
|
823 | - } |
|
824 | - } |
|
825 | - return $value; |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
831 | - * |
|
832 | - * @param $content |
|
833 | - * @return string |
|
834 | - */ |
|
835 | - public function its_eSpresso($content) |
|
836 | - { |
|
837 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * espresso_admin_footer |
|
843 | - * |
|
844 | - * @return string |
|
845 | - */ |
|
846 | - public function espresso_admin_footer() |
|
847 | - { |
|
848 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - /** |
|
853 | - * static method for registering ee admin page. |
|
854 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
855 | - * |
|
856 | - * @since 4.3.0 |
|
857 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
858 | - * @see EE_Register_Admin_Page::register() |
|
859 | - * @param $page_basename |
|
860 | - * @param $page_path |
|
861 | - * @param array $config |
|
862 | - * @return void |
|
863 | - * @throws EE_Error |
|
864 | - */ |
|
865 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
866 | - { |
|
867 | - EE_Error::doing_it_wrong( |
|
868 | - __METHOD__, |
|
869 | - sprintf( |
|
870 | - esc_html__( |
|
871 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
872 | - 'event_espresso' |
|
873 | - ), |
|
874 | - $page_basename |
|
875 | - ), |
|
876 | - '4.3' |
|
877 | - ); |
|
878 | - if (class_exists('EE_Register_Admin_Page')) { |
|
879 | - $config['page_path'] = $page_path; |
|
880 | - } |
|
881 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * @deprecated 4.8.41 |
|
887 | - * @param int $post_ID |
|
888 | - * @param \WP_Post $post |
|
889 | - * @return void |
|
890 | - */ |
|
891 | - public static function parse_post_content_on_save($post_ID, $post) |
|
892 | - { |
|
893 | - EE_Error::doing_it_wrong( |
|
894 | - __METHOD__, |
|
895 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
896 | - '4.8.41' |
|
897 | - ); |
|
898 | - } |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * @deprecated 4.8.41 |
|
903 | - * @param $option |
|
904 | - * @param $old_value |
|
905 | - * @param $value |
|
906 | - * @return void |
|
907 | - */ |
|
908 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
909 | - { |
|
910 | - EE_Error::doing_it_wrong( |
|
911 | - __METHOD__, |
|
912 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
913 | - '4.8.41' |
|
914 | - ); |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * @deprecated 4.9.27 |
|
921 | - * @return void |
|
922 | - */ |
|
923 | - public function get_persistent_admin_notices() |
|
924 | - { |
|
925 | - EE_Error::doing_it_wrong( |
|
926 | - __METHOD__, |
|
927 | - sprintf( |
|
928 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
929 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
930 | - ), |
|
931 | - '4.9.27' |
|
932 | - ); |
|
933 | - } |
|
934 | - |
|
935 | - |
|
936 | - |
|
937 | - /** |
|
938 | - * @deprecated 4.9.27 |
|
939 | - * @throws InvalidInterfaceException |
|
940 | - * @throws InvalidDataTypeException |
|
941 | - * @throws DomainException |
|
942 | - */ |
|
943 | - public function dismiss_ee_nag_notice_callback() |
|
944 | - { |
|
945 | - EE_Error::doing_it_wrong( |
|
946 | - __METHOD__, |
|
947 | - sprintf( |
|
948 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
949 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
950 | - ), |
|
951 | - '4.9.27' |
|
952 | - ); |
|
953 | - $this->persistent_admin_notice_manager->dismissNotice(); |
|
954 | - } |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Returns an array of event archive nav items. |
|
493 | + * |
|
494 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
495 | + * method we use for getting the extra nav menu items |
|
496 | + * @return array |
|
497 | + */ |
|
498 | + private function _get_extra_nav_menu_pages_items() |
|
499 | + { |
|
500 | + $menuitems[] = array( |
|
501 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
502 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
503 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
504 | + ); |
|
505 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
511 | + * the properties and converts it to the menu item object. |
|
512 | + * |
|
513 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
514 | + * @param $menu_item_values |
|
515 | + * @return stdClass |
|
516 | + */ |
|
517 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
518 | + { |
|
519 | + $menu_item = new stdClass(); |
|
520 | + $keys = array( |
|
521 | + 'ID' => 0, |
|
522 | + 'db_id' => 0, |
|
523 | + 'menu_item_parent' => 0, |
|
524 | + 'object_id' => -1, |
|
525 | + 'post_parent' => 0, |
|
526 | + 'type' => 'custom', |
|
527 | + 'object' => '', |
|
528 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
529 | + 'title' => '', |
|
530 | + 'url' => '', |
|
531 | + 'target' => '', |
|
532 | + 'attr_title' => '', |
|
533 | + 'description' => '', |
|
534 | + 'classes' => array(), |
|
535 | + 'xfn' => '', |
|
536 | + ); |
|
537 | + |
|
538 | + foreach ($keys as $key => $value) { |
|
539 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
540 | + } |
|
541 | + return $menu_item; |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
547 | + * EE_Admin_Page route is called. |
|
548 | + * |
|
549 | + * @return void |
|
550 | + */ |
|
551 | + public function route_admin_request() |
|
552 | + { |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
558 | + * |
|
559 | + * @return void |
|
560 | + */ |
|
561 | + public function wp_loaded() |
|
562 | + { |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * admin_init |
|
568 | + * |
|
569 | + * @return void |
|
570 | + * @throws EE_Error |
|
571 | + * @throws InvalidArgumentException |
|
572 | + * @throws InvalidDataTypeException |
|
573 | + * @throws InvalidInterfaceException |
|
574 | + * @throws ReflectionException |
|
575 | + */ |
|
576 | + public function admin_init() |
|
577 | + { |
|
578 | + |
|
579 | + /** |
|
580 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
581 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
582 | + * - check if doing post processing. |
|
583 | + * - check if doing post processing of one of EE CPTs |
|
584 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
585 | + */ |
|
586 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
587 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
588 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
594 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
595 | + * Pages" tab in the EE General Settings Admin page. |
|
596 | + * This is for user-proofing. |
|
597 | + */ |
|
598 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
604 | + * |
|
605 | + * @param string $output Current output. |
|
606 | + * @return string |
|
607 | + * @throws InvalidArgumentException |
|
608 | + * @throws InvalidDataTypeException |
|
609 | + * @throws InvalidInterfaceException |
|
610 | + */ |
|
611 | + public function modify_dropdown_pages($output) |
|
612 | + { |
|
613 | + //get critical pages |
|
614 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
615 | + |
|
616 | + //split current output by line break for easier parsing. |
|
617 | + $split_output = explode("\n", $output); |
|
618 | + |
|
619 | + //loop through to remove any critical pages from the array. |
|
620 | + foreach ($critical_pages as $page_id) { |
|
621 | + $needle = 'value="' . $page_id . '"'; |
|
622 | + foreach ($split_output as $key => $haystack) { |
|
623 | + if (strpos($haystack, $needle) !== false) { |
|
624 | + unset($split_output[$key]); |
|
625 | + } |
|
626 | + } |
|
627 | + } |
|
628 | + //replace output with the new contents |
|
629 | + return implode("\n", $split_output); |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * enqueue all admin scripts that need loaded for admin pages |
|
635 | + * |
|
636 | + * @return void |
|
637 | + */ |
|
638 | + public function enqueue_admin_scripts() |
|
639 | + { |
|
640 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
641 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
642 | + // calls. |
|
643 | + wp_enqueue_script( |
|
644 | + 'ee-inject-wp', |
|
645 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
646 | + array('jquery'), |
|
647 | + EVENT_ESPRESSO_VERSION, |
|
648 | + true |
|
649 | + ); |
|
650 | + // register cookie script for future dependencies |
|
651 | + wp_register_script( |
|
652 | + 'jquery-cookie', |
|
653 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
654 | + array('jquery'), |
|
655 | + '2.1', |
|
656 | + true |
|
657 | + ); |
|
658 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
659 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
660 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
661 | + //joyride style |
|
662 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
663 | + wp_register_style( |
|
664 | + 'ee-joyride-css', |
|
665 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
666 | + array('joyride-css'), |
|
667 | + EVENT_ESPRESSO_VERSION |
|
668 | + ); |
|
669 | + wp_register_script( |
|
670 | + 'joyride-modernizr', |
|
671 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
672 | + array(), |
|
673 | + '2.1', |
|
674 | + true |
|
675 | + ); |
|
676 | + //joyride JS |
|
677 | + wp_register_script( |
|
678 | + 'jquery-joyride', |
|
679 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
680 | + array('jquery-cookie', 'joyride-modernizr'), |
|
681 | + '2.1', |
|
682 | + true |
|
683 | + ); |
|
684 | + // wanna go for a joyride? |
|
685 | + wp_enqueue_style('ee-joyride-css'); |
|
686 | + wp_enqueue_script('jquery-joyride'); |
|
687 | + } |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * display_admin_notices |
|
693 | + * |
|
694 | + * @return void |
|
695 | + */ |
|
696 | + public function display_admin_notices() |
|
697 | + { |
|
698 | + echo EE_Error::get_notices(); |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * @param array $elements |
|
705 | + * @return array |
|
706 | + * @throws EE_Error |
|
707 | + * @throws InvalidArgumentException |
|
708 | + * @throws InvalidDataTypeException |
|
709 | + * @throws InvalidInterfaceException |
|
710 | + */ |
|
711 | + public function dashboard_glance_items($elements) |
|
712 | + { |
|
713 | + $elements = is_array($elements) ? $elements : array($elements); |
|
714 | + $events = EEM_Event::instance()->count(); |
|
715 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
716 | + array('page' => 'espresso_events'), |
|
717 | + admin_url('admin.php') |
|
718 | + ); |
|
719 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
720 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
721 | + $registrations = EEM_Registration::instance()->count( |
|
722 | + array( |
|
723 | + array( |
|
724 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
725 | + ), |
|
726 | + ) |
|
727 | + ); |
|
728 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
729 | + array('page' => 'espresso_registrations'), |
|
730 | + admin_url('admin.php') |
|
731 | + ); |
|
732 | + $items['registrations']['text'] = sprintf( |
|
733 | + _n('%s Registration', '%s Registrations', $registrations), |
|
734 | + number_format_i18n($registrations) |
|
735 | + ); |
|
736 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
737 | + |
|
738 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
739 | + |
|
740 | + foreach ($items as $type => $item_properties) { |
|
741 | + $elements[] = sprintf( |
|
742 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
743 | + $item_properties['url'], |
|
744 | + $item_properties['title'], |
|
745 | + $item_properties['text'] |
|
746 | + ); |
|
747 | + } |
|
748 | + return $elements; |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + /** |
|
753 | + * check_for_invalid_datetime_formats |
|
754 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
755 | + * their selected format can be parsed by PHP |
|
756 | + * |
|
757 | + * @param $value |
|
758 | + * @param $option |
|
759 | + * @throws EE_Error |
|
760 | + * @return string |
|
761 | + */ |
|
762 | + public function check_for_invalid_datetime_formats($value, $option) |
|
763 | + { |
|
764 | + // check for date_format or time_format |
|
765 | + switch ($option) { |
|
766 | + case 'date_format': |
|
767 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
768 | + break; |
|
769 | + case 'time_format': |
|
770 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
771 | + break; |
|
772 | + default: |
|
773 | + $date_time_format = false; |
|
774 | + } |
|
775 | + // do we have a date_time format to check ? |
|
776 | + if ($date_time_format) { |
|
777 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
778 | + |
|
779 | + if (is_array($error_msg)) { |
|
780 | + $msg = '<p>' |
|
781 | + . sprintf( |
|
782 | + esc_html__( |
|
783 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
784 | + 'event_espresso' |
|
785 | + ), |
|
786 | + date($date_time_format), |
|
787 | + $date_time_format |
|
788 | + ) |
|
789 | + . '</p><p><ul>'; |
|
790 | + |
|
791 | + |
|
792 | + foreach ($error_msg as $error) { |
|
793 | + $msg .= '<li>' . $error . '</li>'; |
|
794 | + } |
|
795 | + |
|
796 | + $msg .= '</ul></p><p>' |
|
797 | + . sprintf( |
|
798 | + esc_html__( |
|
799 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
800 | + 'event_espresso' |
|
801 | + ), |
|
802 | + '<span style="color:#D54E21;">', |
|
803 | + '</span>' |
|
804 | + ) |
|
805 | + . '</p>'; |
|
806 | + |
|
807 | + // trigger WP settings error |
|
808 | + add_settings_error( |
|
809 | + 'date_format', |
|
810 | + 'date_format', |
|
811 | + $msg |
|
812 | + ); |
|
813 | + |
|
814 | + // set format to something valid |
|
815 | + switch ($option) { |
|
816 | + case 'date_format': |
|
817 | + $value = 'F j, Y'; |
|
818 | + break; |
|
819 | + case 'time_format': |
|
820 | + $value = 'g:i a'; |
|
821 | + break; |
|
822 | + } |
|
823 | + } |
|
824 | + } |
|
825 | + return $value; |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
831 | + * |
|
832 | + * @param $content |
|
833 | + * @return string |
|
834 | + */ |
|
835 | + public function its_eSpresso($content) |
|
836 | + { |
|
837 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * espresso_admin_footer |
|
843 | + * |
|
844 | + * @return string |
|
845 | + */ |
|
846 | + public function espresso_admin_footer() |
|
847 | + { |
|
848 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + /** |
|
853 | + * static method for registering ee admin page. |
|
854 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
855 | + * |
|
856 | + * @since 4.3.0 |
|
857 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
858 | + * @see EE_Register_Admin_Page::register() |
|
859 | + * @param $page_basename |
|
860 | + * @param $page_path |
|
861 | + * @param array $config |
|
862 | + * @return void |
|
863 | + * @throws EE_Error |
|
864 | + */ |
|
865 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
866 | + { |
|
867 | + EE_Error::doing_it_wrong( |
|
868 | + __METHOD__, |
|
869 | + sprintf( |
|
870 | + esc_html__( |
|
871 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
872 | + 'event_espresso' |
|
873 | + ), |
|
874 | + $page_basename |
|
875 | + ), |
|
876 | + '4.3' |
|
877 | + ); |
|
878 | + if (class_exists('EE_Register_Admin_Page')) { |
|
879 | + $config['page_path'] = $page_path; |
|
880 | + } |
|
881 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * @deprecated 4.8.41 |
|
887 | + * @param int $post_ID |
|
888 | + * @param \WP_Post $post |
|
889 | + * @return void |
|
890 | + */ |
|
891 | + public static function parse_post_content_on_save($post_ID, $post) |
|
892 | + { |
|
893 | + EE_Error::doing_it_wrong( |
|
894 | + __METHOD__, |
|
895 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
896 | + '4.8.41' |
|
897 | + ); |
|
898 | + } |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * @deprecated 4.8.41 |
|
903 | + * @param $option |
|
904 | + * @param $old_value |
|
905 | + * @param $value |
|
906 | + * @return void |
|
907 | + */ |
|
908 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
909 | + { |
|
910 | + EE_Error::doing_it_wrong( |
|
911 | + __METHOD__, |
|
912 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
913 | + '4.8.41' |
|
914 | + ); |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * @deprecated 4.9.27 |
|
921 | + * @return void |
|
922 | + */ |
|
923 | + public function get_persistent_admin_notices() |
|
924 | + { |
|
925 | + EE_Error::doing_it_wrong( |
|
926 | + __METHOD__, |
|
927 | + sprintf( |
|
928 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
929 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
930 | + ), |
|
931 | + '4.9.27' |
|
932 | + ); |
|
933 | + } |
|
934 | + |
|
935 | + |
|
936 | + |
|
937 | + /** |
|
938 | + * @deprecated 4.9.27 |
|
939 | + * @throws InvalidInterfaceException |
|
940 | + * @throws InvalidDataTypeException |
|
941 | + * @throws DomainException |
|
942 | + */ |
|
943 | + public function dismiss_ee_nag_notice_callback() |
|
944 | + { |
|
945 | + EE_Error::doing_it_wrong( |
|
946 | + __METHOD__, |
|
947 | + sprintf( |
|
948 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
949 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
950 | + ), |
|
951 | + '4.9.27' |
|
952 | + ); |
|
953 | + $this->persistent_admin_notice_manager->dismissNotice(); |
|
954 | + } |
|
955 | 955 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public static function instance() |
41 | 41 | { |
42 | 42 | // check if class object is instantiated |
43 | - if (! self::$_instance instanceof EE_Admin) { |
|
43 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
44 | 44 | self::$_instance = new self(); |
45 | 45 | } |
46 | 46 | return self::$_instance; |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | */ |
101 | 101 | private function _define_all_constants() |
102 | 102 | { |
103 | - if (! defined('EE_ADMIN_URL')) { |
|
104 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
105 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
106 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
107 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
103 | + if ( ! defined('EE_ADMIN_URL')) { |
|
104 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
105 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
106 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
107 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
108 | 108 | define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
109 | 109 | } |
110 | 110 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | // set $main_file in stone |
123 | 123 | static $main_file; |
124 | 124 | // if $main_file is not set yet |
125 | - if (! $main_file) { |
|
125 | + if ( ! $main_file) { |
|
126 | 126 | $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
127 | 127 | } |
128 | 128 | if ($plugin === $main_file) { |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
176 | 176 | { |
177 | 177 | return array( |
178 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
179 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
180 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
178 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
179 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
180 | + 'support' => EE_ADMIN_PAGES.'support'.DS, |
|
181 | 181 | ); |
182 | 182 | } |
183 | 183 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
220 | 220 | } |
221 | 221 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
222 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
222 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
223 | 223 | try { |
224 | 224 | //this loads the controller for the admin pages which will setup routing etc |
225 | 225 | EE_Registry::instance()->load_core('Admin_Page_Loader'); |
@@ -267,13 +267,13 @@ discard block |
||
267 | 267 | '</strong>', |
268 | 268 | '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
269 | 269 | '</a>', |
270 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
270 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
271 | 271 | array( |
272 | 272 | 'page' => 'espresso_maintenance_settings', |
273 | 273 | 'action' => 'datetime_tools' |
274 | 274 | ), |
275 | 275 | admin_url('admin.php') |
276 | - ) . '">' |
|
276 | + ).'">' |
|
277 | 277 | ), |
278 | 278 | false, |
279 | 279 | 'manage_options', |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | public function enable_hidden_ee_nav_menu_metaboxes() |
322 | 322 | { |
323 | 323 | global $wp_meta_boxes, $pagenow; |
324 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
324 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
325 | 325 | return; |
326 | 326 | } |
327 | 327 | $user = wp_get_current_user(); |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | */ |
393 | 393 | public function modify_edit_post_link($link, $id) |
394 | 394 | { |
395 | - if (! $post = get_post($id)) { |
|
395 | + if ( ! $post = get_post($id)) { |
|
396 | 396 | return $link; |
397 | 397 | } |
398 | 398 | if ($post->post_type === 'espresso_attendees') { |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | |
619 | 619 | //loop through to remove any critical pages from the array. |
620 | 620 | foreach ($critical_pages as $page_id) { |
621 | - $needle = 'value="' . $page_id . '"'; |
|
621 | + $needle = 'value="'.$page_id.'"'; |
|
622 | 622 | foreach ($split_output as $key => $haystack) { |
623 | 623 | if (strpos($haystack, $needle) !== false) { |
624 | 624 | unset($split_output[$key]); |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | // calls. |
643 | 643 | wp_enqueue_script( |
644 | 644 | 'ee-inject-wp', |
645 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
645 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
646 | 646 | array('jquery'), |
647 | 647 | EVENT_ESPRESSO_VERSION, |
648 | 648 | true |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | // register cookie script for future dependencies |
651 | 651 | wp_register_script( |
652 | 652 | 'jquery-cookie', |
653 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
653 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
654 | 654 | array('jquery'), |
655 | 655 | '2.1', |
656 | 656 | true |
@@ -659,16 +659,16 @@ discard block |
||
659 | 659 | // via: add_filter('FHEE_load_joyride', '__return_true' ); |
660 | 660 | if (apply_filters('FHEE_load_joyride', false)) { |
661 | 661 | //joyride style |
662 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
662 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
663 | 663 | wp_register_style( |
664 | 664 | 'ee-joyride-css', |
665 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
665 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
666 | 666 | array('joyride-css'), |
667 | 667 | EVENT_ESPRESSO_VERSION |
668 | 668 | ); |
669 | 669 | wp_register_script( |
670 | 670 | 'joyride-modernizr', |
671 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
671 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
672 | 672 | array(), |
673 | 673 | '2.1', |
674 | 674 | true |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | //joyride JS |
677 | 677 | wp_register_script( |
678 | 678 | 'jquery-joyride', |
679 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
679 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
680 | 680 | array('jquery-cookie', 'joyride-modernizr'), |
681 | 681 | '2.1', |
682 | 682 | true |
@@ -725,21 +725,21 @@ discard block |
||
725 | 725 | ), |
726 | 726 | ) |
727 | 727 | ); |
728 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
728 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
729 | 729 | array('page' => 'espresso_registrations'), |
730 | 730 | admin_url('admin.php') |
731 | 731 | ); |
732 | - $items['registrations']['text'] = sprintf( |
|
732 | + $items['registrations']['text'] = sprintf( |
|
733 | 733 | _n('%s Registration', '%s Registrations', $registrations), |
734 | 734 | number_format_i18n($registrations) |
735 | 735 | ); |
736 | 736 | $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
737 | 737 | |
738 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
738 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
739 | 739 | |
740 | 740 | foreach ($items as $type => $item_properties) { |
741 | 741 | $elements[] = sprintf( |
742 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
742 | + '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', |
|
743 | 743 | $item_properties['url'], |
744 | 744 | $item_properties['title'], |
745 | 745 | $item_properties['text'] |
@@ -764,10 +764,10 @@ discard block |
||
764 | 764 | // check for date_format or time_format |
765 | 765 | switch ($option) { |
766 | 766 | case 'date_format': |
767 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
767 | + $date_time_format = $value.' '.get_option('time_format'); |
|
768 | 768 | break; |
769 | 769 | case 'time_format': |
770 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
770 | + $date_time_format = get_option('date_format').' '.$value; |
|
771 | 771 | break; |
772 | 772 | default: |
773 | 773 | $date_time_format = false; |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | |
791 | 791 | |
792 | 792 | foreach ($error_msg as $error) { |
793 | - $msg .= '<li>' . $error . '</li>'; |
|
793 | + $msg .= '<li>'.$error.'</li>'; |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | $msg .= '</ul></p><p>' |
@@ -294,15 +294,15 @@ discard block |
||
294 | 294 | |
295 | 295 | |
296 | 296 | |
297 | - /** |
|
298 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
299 | - * but also verifies the payment method type of each is a usable object. If not, |
|
300 | - * deactivate it, sets a notification, and deactivates it |
|
301 | - * |
|
302 | - * @param array $rows |
|
303 | - * @return EE_Payment_Method[] |
|
304 | - * @throws InvalidDataTypeException |
|
305 | - */ |
|
297 | + /** |
|
298 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
299 | + * but also verifies the payment method type of each is a usable object. If not, |
|
300 | + * deactivate it, sets a notification, and deactivates it |
|
301 | + * |
|
302 | + * @param array $rows |
|
303 | + * @return EE_Payment_Method[] |
|
304 | + * @throws InvalidDataTypeException |
|
305 | + */ |
|
306 | 306 | protected function _create_objects( $rows = array() ) { |
307 | 307 | EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
308 | 308 | $payment_methods = parent::_create_objects( $rows ); |
@@ -319,22 +319,22 @@ discard block |
||
319 | 319 | //only deactivate and notify the admin if the payment is active somewhere |
320 | 320 | $payment_method->deactivate(); |
321 | 321 | $payment_method->save(); |
322 | - do_action( |
|
323 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
324 | - $payment_method |
|
325 | - ); |
|
326 | - new PersistentAdminNotice( |
|
327 | - 'auto-deactivated-' . $payment_method->type(), |
|
328 | - sprintf( |
|
329 | - __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
330 | - 'event_espresso'), |
|
331 | - $payment_method->admin_name(), |
|
332 | - '<br />', |
|
333 | - '<a href="' . admin_url('plugins.php') . '">', |
|
334 | - '</a>' |
|
335 | - ), |
|
336 | - true |
|
337 | - ); |
|
322 | + do_action( |
|
323 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
324 | + $payment_method |
|
325 | + ); |
|
326 | + new PersistentAdminNotice( |
|
327 | + 'auto-deactivated-' . $payment_method->type(), |
|
328 | + sprintf( |
|
329 | + __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
330 | + 'event_espresso'), |
|
331 | + $payment_method->admin_name(), |
|
332 | + '<br />', |
|
333 | + '<a href="' . admin_url('plugins.php') . '">', |
|
334 | + '</a>' |
|
335 | + ), |
|
336 | + true |
|
337 | + ); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | return $usable_payment_methods; |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
2 | 2 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
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 | * |
@@ -40,33 +40,33 @@ discard block |
||
40 | 40 | * @access protected |
41 | 41 | * @return EEM_Payment_Method |
42 | 42 | */ |
43 | - protected function __construct( $timezone = NULL ) { |
|
44 | - $this->singlular_item = __( 'Payment Method', 'event_espresso' ); |
|
45 | - $this->plural_item = __( 'Payment Methods', 'event_espresso' ); |
|
46 | - $this->_tables = array( 'Payment_Method' => new EE_Primary_Table( 'esp_payment_method', 'PMD_ID' ) ); |
|
43 | + protected function __construct($timezone = NULL) { |
|
44 | + $this->singlular_item = __('Payment Method', 'event_espresso'); |
|
45 | + $this->plural_item = __('Payment Methods', 'event_espresso'); |
|
46 | + $this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID')); |
|
47 | 47 | $this->_fields = array( |
48 | 48 | 'Payment_Method' => array( |
49 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( 'PMD_ID', __( "ID", 'event_espresso' ) ), |
|
50 | - 'PMD_type' => new EE_Plain_Text_Field( 'PMD_type', __( "Payment Method Type", 'event_espresso' ), FALSE, 'Admin_Only' ), |
|
51 | - 'PMD_name' => new EE_Plain_Text_Field( 'PMD_name', __( "Name", 'event_espresso' ), FALSE ), |
|
52 | - 'PMD_desc' => new EE_Post_Content_Field( 'PMD_desc', __( "Description", 'event_espresso' ), FALSE, '' ), |
|
53 | - 'PMD_admin_name' => new EE_Plain_Text_Field( 'PMD_admin_name', __( "Admin-Only Name", 'event_espresso' ), TRUE ), |
|
54 | - 'PMD_admin_desc' => new EE_Post_Content_Field( 'PMD_admin_desc', __( "Admin-Only Description", 'event_espresso' ), TRUE ), |
|
55 | - 'PMD_slug' => new EE_Slug_Field( 'PMD_slug', __( "Slug", 'event_espresso' ), FALSE ), |
|
56 | - 'PMD_order' => new EE_Integer_Field( 'PMD_order', __( "Order", 'event_espresso' ), FALSE, 0 ), |
|
57 | - 'PMD_debug_mode' => new EE_Boolean_Field( 'PMD_debug_mode', __( "Debug Mode On?", 'event_espresso' ), FALSE, FALSE ), |
|
58 | - 'PMD_wp_user' => new EE_WP_User_Field( 'PMD_wp_user', __( "Payment Method Creator ID", 'event_espresso' ), FALSE ), |
|
59 | - 'PMD_open_by_default' => new EE_Boolean_Field( 'PMD_open_by_default', __( "Open by Default?", 'event_espresso' ), FALSE, FALSE ), 'PMD_button_url' => new EE_Plain_Text_Field( 'PMD_button_url', __( "Button URL", 'event_espresso' ), TRUE, '' ), |
|
60 | - 'PMD_scope' => new EE_Serialized_Text_Field( 'PMD_scope', __( "Usable From?", 'event_espresso' ), FALSE, array() ), //possible values currently are 'CART','ADMIN','API' |
|
49 | + 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
|
50 | + 'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), FALSE, 'Admin_Only'), |
|
51 | + 'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), FALSE), |
|
52 | + 'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), FALSE, ''), |
|
53 | + 'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), TRUE), |
|
54 | + 'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), TRUE), |
|
55 | + 'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), FALSE), |
|
56 | + 'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), FALSE, 0), |
|
57 | + 'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), FALSE, FALSE), |
|
58 | + 'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), FALSE), |
|
59 | + 'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), FALSE, FALSE), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), TRUE, ''), |
|
60 | + 'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), FALSE, array()), //possible values currently are 'CART','ADMIN','API' |
|
61 | 61 | ) ); |
62 | 62 | $this->_model_relations = array( |
63 | 63 | // 'Event'=>new EE_HABTM_Relation('Event_Payment_Method'), |
64 | 64 | 'Payment' => new EE_Has_Many_Relation(), |
65 | - 'Currency' => new EE_HABTM_Relation( 'Currency_Payment_Method' ), |
|
65 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
66 | 66 | 'Transaction' => new EE_Has_Many_Relation(), |
67 | 67 | 'WP_User' => new EE_Belongs_To_Relation(), |
68 | 68 | ); |
69 | - parent::__construct( $timezone ); |
|
69 | + parent::__construct($timezone); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param string $slug |
77 | 77 | * @return EE_Payment_Method |
78 | 78 | */ |
79 | - public function get_one_by_slug( $slug ) { |
|
80 | - return $this->get_one( array( array( 'PMD_slug' => $slug ) ) ); |
|
79 | + public function get_one_by_slug($slug) { |
|
80 | + return $this->get_one(array(array('PMD_slug' => $slug))); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | return apply_filters( |
92 | 92 | 'FHEE__EEM_Payment_Method__scopes', |
93 | 93 | array( |
94 | - self::scope_cart => __( "Front-end Registration Page", 'event_espresso' ), |
|
95 | - self::scope_admin => __( "Admin Registration Page (no online processing)", 'event_espresso' ) |
|
94 | + self::scope_cart => __("Front-end Registration Page", 'event_espresso'), |
|
95 | + self::scope_admin => __("Admin Registration Page (no online processing)", 'event_espresso') |
|
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | } |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
105 | 105 | * @return boolean |
106 | 106 | */ |
107 | - public function is_valid_scope( $scope ) { |
|
107 | + public function is_valid_scope($scope) { |
|
108 | 108 | $scopes = $this->scopes(); |
109 | - if ( isset( $scopes[ $scope ] ) ) { |
|
109 | + if (isset($scopes[$scope])) { |
|
110 | 110 | return TRUE; |
111 | 111 | } else { |
112 | 112 | return FALSE; |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | * @throws EE_Error |
123 | 123 | * @return EE_Payment_Method[] |
124 | 124 | */ |
125 | - public function get_all_active( $scope = NULL, $query_params = array() ) { |
|
126 | - if( ! isset( $query_params[ 'order_by' ] ) && ! isset( $query_params[ 'order' ] ) ) { |
|
127 | - $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ); |
|
125 | + public function get_all_active($scope = NULL, $query_params = array()) { |
|
126 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
127 | + $query_params['order_by'] = array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC'); |
|
128 | 128 | } |
129 | - return $this->get_all( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
129 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * @param array $query_params |
136 | 136 | * @return int |
137 | 137 | */ |
138 | - public function count_active( $scope = NULL, $query_params = array() ){ |
|
139 | - return $this->count( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
138 | + public function count_active($scope = NULL, $query_params = array()) { |
|
139 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -147,21 +147,21 @@ discard block |
||
147 | 147 | * @return array like param of EEM_Base::get_all() |
148 | 148 | * @throws EE_Error |
149 | 149 | */ |
150 | - protected function _get_query_params_for_all_active( $scope = NULL, $query_params = array() ){ |
|
151 | - if ( $scope ) { |
|
152 | - if ( $this->is_valid_scope( $scope ) ) { |
|
153 | - return array_replace_recursive( array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params ); |
|
150 | + protected function _get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
151 | + if ($scope) { |
|
152 | + if ($this->is_valid_scope($scope)) { |
|
153 | + return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params); |
|
154 | 154 | } else { |
155 | - throw new EE_Error( sprintf( __( "'%s' is not a valid scope for a payment method", "event_espresso" ), $scope ) ); |
|
155 | + throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
|
156 | 156 | } |
157 | 157 | } else { |
158 | 158 | $acceptable_scopes = array(); |
159 | 159 | $count = 0; |
160 | - foreach ( $this->scopes() as $scope_name => $desc ) { |
|
160 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
161 | 161 | $count++; |
162 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
162 | + $acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%'); |
|
163 | 163 | } |
164 | - return array_replace_recursive( array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params ); |
|
164 | + return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @return array like param of EEM_Base::get_all() |
174 | 174 | * @throws EE_Error |
175 | 175 | */ |
176 | - public function get_query_params_for_all_active( $scope = NULL, $query_params = array() ) { |
|
177 | - return $this->_get_query_params_for_all_active( $scope, $query_params ); |
|
176 | + public function get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
177 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param array $query_params |
185 | 185 | * @return EE_Payment_Method |
186 | 186 | */ |
187 | - public function get_one_active( $scope = NULL, $query_params = array() ) { |
|
188 | - return $this->get_one( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
187 | + public function get_one_active($scope = NULL, $query_params = array()) { |
|
188 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | * @param string $type |
196 | 196 | * @return EE_Payment_Method |
197 | 197 | */ |
198 | - public function get_one_of_type( $type ) { |
|
199 | - return $this->get_one( array( array( 'PMD_type' => $type ) ) ); |
|
198 | + public function get_one_of_type($type) { |
|
199 | + return $this->get_one(array(array('PMD_type' => $type))); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -209,22 +209,22 @@ discard block |
||
209 | 209 | * @return EE_Payment_Method |
210 | 210 | * @throws EE_Error |
211 | 211 | */ |
212 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ) { |
|
212 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
213 | 213 | //first: check if it's a slug |
214 | - if( is_string( $base_class_obj_or_id ) ) { |
|
215 | - $obj = $this->get_one_by_slug( $base_class_obj_or_id ); |
|
216 | - if( $obj ) { |
|
214 | + if (is_string($base_class_obj_or_id)) { |
|
215 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
216 | + if ($obj) { |
|
217 | 217 | return $obj; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | //ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
221 | 221 | try { |
222 | - return parent::ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db ); |
|
222 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
223 | 223 | } |
224 | - catch ( EE_Error $e ) { |
|
224 | + catch (EE_Error $e) { |
|
225 | 225 | //handle it outside the catch |
226 | 226 | } |
227 | - throw new EE_Error( sprintf( __( "'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso" ), $base_class_obj_or_id ) ); |
|
227 | + throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | |
@@ -235,12 +235,12 @@ discard block |
||
235 | 235 | * @param mixed $base_obj_or_id_or_slug |
236 | 236 | * @return int |
237 | 237 | */ |
238 | - function ensure_is_ID( $base_obj_or_id_or_slug ) { |
|
239 | - if ( is_string( $base_obj_or_id_or_slug ) ) { |
|
238 | + function ensure_is_ID($base_obj_or_id_or_slug) { |
|
239 | + if (is_string($base_obj_or_id_or_slug)) { |
|
240 | 240 | //assume it's a slug |
241 | - $base_obj_or_id_or_slug = $this->get_one_by_slug( $base_obj_or_id_or_slug ); |
|
241 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
242 | 242 | } |
243 | - return parent::ensure_is_ID( $base_obj_or_id_or_slug ); |
|
243 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | |
@@ -249,36 +249,36 @@ discard block |
||
249 | 249 | * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default. |
250 | 250 | * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart |
251 | 251 | */ |
252 | - function verify_button_urls( $payment_methods = NULL ) { |
|
253 | - $payment_methods = is_array( $payment_methods ) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
254 | - foreach ( $payment_methods as $payment_method ) { |
|
252 | + function verify_button_urls($payment_methods = NULL) { |
|
253 | + $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
254 | + foreach ($payment_methods as $payment_method) { |
|
255 | 255 | try { |
256 | 256 | $current_button_url = $payment_method->button_url(); |
257 | - $buttons_urls_to_try = apply_filters( 'FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
258 | - 'current_ssl' => str_replace( "http://", "https://", $current_button_url ), |
|
259 | - 'current' => str_replace( "https://", "http://", $current_button_url ), |
|
260 | - 'default_ssl' => str_replace( "http://", "https://", $payment_method->type_obj()->default_button_url() ), |
|
261 | - 'default' => str_replace( "https://", "http://", $payment_method->type_obj()->default_button_url() ), |
|
262 | - ) ); |
|
263 | - foreach( $buttons_urls_to_try as $button_url_to_try ) { |
|
264 | - if( |
|
257 | + $buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
258 | + 'current_ssl' => str_replace("http://", "https://", $current_button_url), |
|
259 | + 'current' => str_replace("https://", "http://", $current_button_url), |
|
260 | + 'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()), |
|
261 | + 'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()), |
|
262 | + )); |
|
263 | + foreach ($buttons_urls_to_try as $button_url_to_try) { |
|
264 | + if ( |
|
265 | 265 | (//this is the current url and it exists, regardless of SSL issues |
266 | 266 | $button_url_to_try == $current_button_url && |
267 | 267 | EEH_URL::remote_file_exists( |
268 | 268 | $button_url_to_try, |
269 | 269 | array( |
270 | 270 | 'sslverify' => false, |
271 | - 'limit_response_size' => 4095,//we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
271 | + 'limit_response_size' => 4095, //we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
272 | 272 | ) ) |
273 | 273 | ) |
274 | 274 | || |
275 | 275 | (//this is NOT the current url and it exists with a working SSL cert |
276 | 276 | $button_url_to_try != $current_button_url && |
277 | - EEH_URL::remote_file_exists( $button_url_to_try ) |
|
277 | + EEH_URL::remote_file_exists($button_url_to_try) |
|
278 | 278 | ) ) { |
279 | - if( $current_button_url != $button_url_to_try ){ |
|
280 | - $payment_method->save( array( 'PMD_button_url' => $button_url_to_try ) ); |
|
281 | - EE_Error::add_attention( sprintf( __( "Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso" ), $payment_method->name(), $button_url_to_try ) ); |
|
279 | + if ($current_button_url != $button_url_to_try) { |
|
280 | + $payment_method->save(array('PMD_button_url' => $button_url_to_try)); |
|
281 | + EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try)); |
|
282 | 282 | } |
283 | 283 | //this image exists. So if wasn't set before, now it is; |
284 | 284 | //or if it was already set, we have nothing to do |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | } |
287 | 287 | } |
288 | 288 | } |
289 | - catch ( EE_Error $e ) { |
|
290 | - $payment_method->set_active( FALSE ); |
|
289 | + catch (EE_Error $e) { |
|
290 | + $payment_method->set_active(FALSE); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
@@ -303,19 +303,19 @@ discard block |
||
303 | 303 | * @return EE_Payment_Method[] |
304 | 304 | * @throws InvalidDataTypeException |
305 | 305 | */ |
306 | - protected function _create_objects( $rows = array() ) { |
|
307 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
308 | - $payment_methods = parent::_create_objects( $rows ); |
|
306 | + protected function _create_objects($rows = array()) { |
|
307 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
308 | + $payment_methods = parent::_create_objects($rows); |
|
309 | 309 | /* @var $payment_methods EE_Payment_Method[] */ |
310 | 310 | $usable_payment_methods = array(); |
311 | - foreach ( $payment_methods as $key => $payment_method ) { |
|
312 | - if ( EE_Payment_Method_Manager::instance()->payment_method_type_exists( $payment_method->type() ) ) { |
|
313 | - $usable_payment_methods[ $key ] = $payment_method; |
|
311 | + foreach ($payment_methods as $key => $payment_method) { |
|
312 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
313 | + $usable_payment_methods[$key] = $payment_method; |
|
314 | 314 | //some payment methods enqueue their scripts in EE_PMT_*::__construct |
315 | 315 | //which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
316 | 316 | //its scripts). but for backwards-compat we should continue to do that |
317 | 317 | $payment_method->type_obj(); |
318 | - } elseif( $payment_method->active() ) { |
|
318 | + } elseif ($payment_method->active()) { |
|
319 | 319 | //only deactivate and notify the admin if the payment is active somewhere |
320 | 320 | $payment_method->deactivate(); |
321 | 321 | $payment_method->save(); |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | $payment_method |
325 | 325 | ); |
326 | 326 | new PersistentAdminNotice( |
327 | - 'auto-deactivated-' . $payment_method->type(), |
|
327 | + 'auto-deactivated-'.$payment_method->type(), |
|
328 | 328 | sprintf( |
329 | 329 | __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
330 | 330 | 'event_espresso'), |
331 | 331 | $payment_method->admin_name(), |
332 | 332 | '<br />', |
333 | - '<a href="' . admin_url('plugins.php') . '">', |
|
333 | + '<a href="'.admin_url('plugins.php').'">', |
|
334 | 334 | '</a>' |
335 | 335 | ), |
336 | 336 | true |
@@ -350,11 +350,11 @@ discard block |
||
350 | 350 | * @param string $scope @see EEM_Payment_Method::get_all_for_events |
351 | 351 | * @return EE_Payment_Method[] |
352 | 352 | */ |
353 | - public function get_all_for_transaction( $transaction, $scope ) { |
|
353 | + public function get_all_for_transaction($transaction, $scope) { |
|
354 | 354 | //give addons a chance to override what payment methods are chosen based on the transaction |
355 | 355 | return apply_filters( |
356 | 356 | 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
357 | - $this->get_all_active( $scope, array( 'group_by' => 'PMD_type' ) ), |
|
357 | + $this->get_all_active($scope, array('group_by' => 'PMD_type')), |
|
358 | 358 | $transaction, |
359 | 359 | $scope |
360 | 360 | ); |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
371 | 371 | * @return EE_Payment|null |
372 | 372 | */ |
373 | - public function get_last_used_for_registration( $registration_or_reg_id ) { |
|
374 | - $registration_id = EEM_Registration::instance()->ensure_is_ID( $registration_or_reg_id ); |
|
373 | + public function get_last_used_for_registration($registration_or_reg_id) { |
|
374 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
375 | 375 | |
376 | 376 | $query_params = array( |
377 | 377 | 0 => array( |
378 | 378 | 'Payment.Registration.REG_ID' => $registration_id, |
379 | 379 | ), |
380 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
380 | + 'order_by' => array('Payment.PAY_ID' => 'DESC') |
|
381 | 381 | ); |
382 | - return $this->get_one( $query_params ); |
|
382 | + return $this->get_one($query_params); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | } |