Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php
  2. //* Please do NOT include the opening php tag, except of course if you're starting with a blank file
  3.  
  4. add_action(
  5. 'AHEE_event_details_before_post',
  6. 'my_add_content_event_if_logged_in_registered',
  7. 11
  8. );
  9. function my_add_content_event_if_logged_in_registered( $post ) {
  10. if ( is_user_logged_in() && is_singular() ) {
  11.  
  12. $user = wp_get_current_user();
  13. if ( ! $user instanceof WP_User ) {
  14. return;
  15. }
  16. //is there an attached EE_Attendee?
  17. $att_id = get_user_option( 'EE_Attendee_ID', $user->ID );
  18. if ( empty( $att_id ) ) {
  19. return; //bail, no attached attendee_id.
  20. }
  21. //grab contact
  22. $contact = EEM_Attendee::instance()->get_one_by_ID( $att_id );
  23. //if no contact then bail
  24. if ( ! $contact instanceof EE_Attendee ) {
  25. return;
  26. }
  27. // get events for this user
  28. $events = $contact->get_many_related( 'Event' );
  29. // build an array of event IDs
  30. foreach ( $events as $event ){
  31. $user_event_ids[] = $event->get( 'EVT_ID' );
  32. }
  33. // get this event's ID
  34. $this_event_id = $post->ID;
  35. // look for a match
  36. if( in_array( $this_event_id, $user_event_ids ) ) {
  37. echo '<h3>You\'ve been here before!</h3>';
  38. } else {
  39. echo '<h3>Welcome ' . $user->user_nicename . ', please register.</h3>';
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement