Advertisement
Guest User

gbf plugin

a guest
Jan 31st, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: gbf-admin-custom
  4. Description: Site specific code for TEO
  5. */
  6. /* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
  7. /**
  8. * Filters the $is_contact_data before it's sent to infusionsoft
  9. * in order to add the last registration's custom question answers
  10. * @param array $is_contact_data
  11. * @param EE_Attendee $ee_attendee
  12. */
  13. function ee_infusionsoft_save_my_custom_questions( $is_contact_data, $ee_attendee ) {
  14. if( $ee_attendee instanceof EE_Attendee ) {
  15.  
  16. //get the last answer this attendee provided to the question with admin label 'company'
  17. $company_answer = EEM_Answer::instance()->get_one( array( array( 'Registration.ATT_ID' => $ee_attendee->ID(), 'Question.QST_admin_label' => 'company-name' ) , 'order' => 'DESC' ) );
  18. if( $company_answer ){
  19. $is_contact_data[ 'Company' ] = $company_answer->pretty_value();
  20. }
  21.  
  22. //get the last answer this attendee provided to the question wtih admin label 'course-materials'
  23. $course-materials_answer = EEM_Answer::instance()->get_one( array( array( 'Registration.ATT_ID' => $ee_attendee->ID(), 'Question.QST_admin_label' => 'course-materials' ) , 'order' => 'DESC' ) );
  24. if( $course-materials_answer ){
  25. $is_contact_data[ '_CourseMaterials' ] = $course-materials_answer->pretty_value();
  26. }
  27. }else{
  28. EE_Error::add_error(sprintf( __( 'ee_infusionsoft_save_my_custom_questions was not called with an EE_Attendee but a %s', 'event_espresso' ), gettype( $ee_attendee )), __FILE__, __FUNCTION__, __LINE__ );
  29. }
  30. return $is_contact_data;
  31. }
  32. add_filter( 'FHEE__EED_Infusionsoft__save_infusionsoft_attendee__extra_attendee_data', 'ee_infusionsoft_save_my_custom_questions', 10, 2 );
  33.  
  34. /**
  35. * Adds event data to Infusionsoft Customfields
  36. * @param array $original_info_to_send as documented on http://help.infusionsoft.com/developers/tables/product
  37. * @param array $is_contact_data
  38. * @param EE_Attendee $ee_attendee
  39. */
  40.  
  41. function ee_infusionsoft_pass_event_start_and_name( $is_contact_data, $ee_attendee ) {
  42. if( $ee_attendee instanceof EE_Attendee ) {
  43. $startdate = '';
  44. $eventname = '';
  45. $checkout = EE_Registry::instance()->SSN->checkout();
  46. if ( $checkout instanceof EE_Checkout ) {
  47. $transaction = $checkout->transaction;
  48. if ( $transaction instanceof EE_Transaction ) {
  49. foreach ( $transaction->registrations() as $registration ) {
  50. if ( $registration instanceof EE_Registration ) {
  51. $event = $registration->event();
  52. if ( $event instanceof EE_Event ) {
  53. //get the event start date
  54. $startdate = $event->primary_datetime()->start_date( EED_Infusionsoft::IS_datetime_format );
  55. //get the event name
  56. $eventname = $event->name();
  57. $is_contact_data[ '_Event1StartTime' ] = $startdate;
  58. $is_contact_data[ '_EventName' ] = $eventname;
  59. }
  60. }
  61. }
  62. }
  63. }
  64. } else {
  65. EE_Error::add_error(sprintf( __( 'ee_infusionsoft_save_my_custom_questions was not called with an EE_Attendee but a %s', 'event_espresso' ), gettype( $ee_attendee )), __FILE__, __FUNCTION__, __LINE__ );
  66. }
  67. return $is_contact_data;
  68. }
  69. add_filter( 'FHEE__EED_Infusionsoft__save_infusionsoft_attendee__extra_attendee_data', 'ee_infusionsoft_pass_event_start_and_name', 10, 2 );
  70.  
  71.  
  72. /**
  73. * Adds an Infusionsoft tag to an Infusionsoft contact dynamically based
  74. * on a registration's answer to the 'gender' question
  75. * @param array $tags
  76. * @param EE_Registration $registration
  77. * @return array
  78. */
  79. function ee_infusionsoft_save_additional_tags( $tags, $registration ) {
  80.  
  81. //assign to group based on the question with admin label "course-materials"
  82. if( $registration instanceof EE_Registration ){
  83. $answer_to_course-materials = EEM_Answer::instance()->get_one( array( array( 'REG_ID' => $registration->ID(), 'Question.QST_admin_label' => 'course-materials' ) ) );
  84. if( $answer_to_course-materials instanceof EE_Answer) {
  85. switch( $answer_to_course-materials->value() ){
  86. case '1' :
  87. $tags[] = 788;
  88. break;
  89. case '2' :
  90. $tags[] = 780;
  91. break;
  92. }
  93. }
  94. }else{
  95. EE_Error::add_error( sprintf( __( 'The registration variable must be a proper EE_Registration, but was instead a %s', 'event_espresso' ), gettype( $registration ) ), __FILE__, __FUNCTION__, __LINE__ );
  96. }
  97. return $tags;
  98. }
  99. add_filter('FHEE__EEE_Infusionsoft_Registration__sync_to_infusionsoft__infusionsoft_tags', 'ee_infusionsoft_save_additional_tags', 10, 2 );
  100.  
  101.  
  102. /* Stop Adding Functions */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement