MC4WP_Events_Manager_Integration

Class MC4WP_Events_Manager_Integration.

Defined (1)

The class is defined in the following location(s).

/includes/integrations/class-events-manager.php  
  1. class MC4WP_Events_Manager_Integration extends MC4WP_General_Integration { 
  2.  
  3. protected $type = 'events_manager'; 
  4.  
  5. public function __construct() { 
  6. add_action( 'em_bookings_added', array( $this, 'subscribe_from_events_manager' ) ); 
  7.  
  8. /** 
  9. * Subscribe from Events Manager booking forms. 
  10. * @param array $args 
  11. * @return bool 
  12. */ 
  13. public function subscribe_from_events_manager( $args ) { 
  14.  
  15. // was sign-up checkbox checked? 
  16. if( ! isset( $args->booking_meta['booking']['mc4wp-subscribe'] ) || $args->booking_meta['booking']['mc4wp-subscribe'] != 1 ) { 
  17. return false; 
  18.  
  19. // find email field 
  20. if( isset( $args->booking_meta['registration']['user_email'] ) ) { 
  21.  
  22. $meta = $args->booking_meta; 
  23.  
  24. $email = $meta['registration']['user_email']; 
  25. $merge_vars = array(); 
  26.  
  27. // find name fields 
  28. if( isset( $meta['registration']['user_name'] ) ) { 
  29. $merge_vars['NAME'] = $meta['registration']['user_name']; 
  30.  
  31. if( isset( $meta['registration']['first_name'] ) ) { 
  32. $merge_vars['FNAME'] = $meta['registration']['first_name']; 
  33.  
  34. if( isset( $meta['registration']['last_name'] ) ) { 
  35. $merge_vars['LNAME'] = $meta['registration']['last_name']; 
  36.  
  37. if( is_array( $meta['booking'] ) ) { 
  38. foreach( $meta['booking'] as $field_name => $field_value ) { 
  39.  
  40. // only add fields starting with mc4wp- 
  41. if( strtolower( substr( $field_name, 0, 6 ) ) !== 'mc4wp-' || $field_name === 'mc4wp-subscribe' ) { 
  42. continue; 
  43.  
  44. $field_name = strtoupper( substr( $field_name, 6 ) ); 
  45.  
  46. // add to merge vars 
  47. $merge_vars[ $field_name ] = $field_value; 
  48.  
  49. // subscribe using email and name 
  50. return $this->subscribe( $email, $merge_vars ); 
  51.  
  52. // try general fallback to get the email and stuff. 
  53. return $this->try_subscribe(); 
  54.