Skip to content

Hooks and filters

24-Jan-11

EME provides a number of hooks and filters so you can customize a number of things to your liking. For a howto in general about hooks and filters, see here for actions and here for filters.
As an example, if you would want to hook into eme_insert_rsvp_action, you would add something like this to your theme’s functions.php:


add_action('eme_insert_rsvp_action','do_my_stuff');
function do_my_stuff($booking) {
 ....
}

The following hooks are available:

  • eme_insert_event_action (1 parameter: $event)
    An example for how to use this to send mail to all users for new events:
    add_action('eme_insert_event_action','eme_mail_event');
    function eme_mail_event ($event) {
       $contact = eme_get_contact ($event);
       $contact_email = $contact->user_email;
       $contact_name = $contact->display_name;
       $subject_format="This is the new event called ' #_EVENTNAME '";
       $body_format="This is the new event called ' #_EVENTNAME '";
    
       $subject=eme_replace_placeholders($subject_format, $event, "text");
       $body=eme_replace_placeholders($body_format, $event, "text");
       $blogusers = get_users();
       foreach ( $blogusers as $user ) {
          eme_send_mail($subject,$body, $user->email, $user->display_name, $contact_email, $contact_name);
       }
    }
    

  • eme_update_event_action (1 parameter: $event)
  • eme_insert_recurrence_action (2 parameters: $event,$recurrence)
  • eme_update_recurrence_action (2 parameters: $event,$recurrence)
  • eme_insert_rsvp_action (1 parameter: $booking), executed after inserting rsvp info into the db.
    An example for how to use this to implement discounts:
    add_action('eme_insert_rsvp_action', 'my_eme_discount_function',20,1);
    function my_eme_discount_function($booking) {
       global $wpdb;
       $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
       $where = array();
       $fields = array();
    
       $booking_id = $booking['booking_id'];
       $event_id = $booking['event_id'];
    
       if ($event_id == 5) {        /* put in the event_id that needs processing, or leave out this line to process all events */
          //echo 'EVENT ID='.$event_id .' Booking_id = '.$booking['booking_id'];
    
          $seats=$booking['booking_seats'];
          $price=$booking['booking_price'];
    
          // more than 2 seats, then the price is 25 per seat
          if ($seats> 1)
              $price = 25;
    
            // below a small example to check own input
    	//$coupon = "";
            //$answers = eme_get_answers($booking_id);
            //foreach ($answers as $answer) {
            //    if ($answer['field_name'] == "MY_FIELD_NAME") {
            //       $coupon = $answer['answer'];
            //    }
            //}
            // now check $coupon for your wanted value
    
          $fields['booking_price'] = $price;
          $where['booking_id'] = $booking['booking_id'];
          $wpdb->update($bookings_table, $fields, $where);
       }
       return;
    }
    


    For multiseat events (and possibly multiprice), the discount code is similar:

    add_action('eme_insert_rsvp_action', 'my_eme_discount_function',20,1);
    function my_eme_discount_function($booking) {
       global $wpdb;
       $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
       $where = array();
       $fields = array();
    
       $booking_id = $booking['booking_id'];
       $event_id = $booking['event_id'];
    
       if ($event_id == 5 && eme_is_event_multiseats($event_id)) {
          /* put in the event_id that needs processing, or leave out this line to process all events */
          $seats=eme_convert_multi2array($booking['booking_seats']); // $seats is now an array for the different seat categories defined
    
          // now check if we defined different prices per seat category
          if (eme_is_multi($booking['booking_price']))
              $price=eme_convert_multi2array($booking['booking_price']);
          else
              $price=$booking['booking_price'];
    
          // example: more than 2 seats in the first category and 3 seats in the second, then the price is 25 per seat in the first
          // and 15 in the second, or in the case all prices are the same for the different seat categories, set the new price to 30
          if ($seats[0]> 2 && $seats[1]> 3) {
              if (eme_is_multi($booking['booking_price'])) {
                 $price[0] = 25;
                 $price[1] = 15;
              } else {
                 $price = 30;
              }
          }
    
          if (eme_is_multi($booking['booking_price']))
              $fields['booking_price'] = eme_convert_array2multi($price);
          else
              $fields['booking_price'] = $price;
          $where['booking_id'] = $booking['booking_id'];
          $wpdb->update($bookings_table, $fields, $where);
       }
       return;
    }
    

  • eme_update_rsvp_action (1 parameter: $booking), executed after updating booking info
  • eme_ipn_action (1 parameter: $booking), executed after a successfull IPN arrived from one of the payment gateways

Hint: get the event from the booking id by using this: $event = eme_get_event_by_booking_id($booking['booking_id']);

The following filters are available:

  • eme_event_filter (1 parameter: $event array, return value should be modified array)
  • eme_event_list_filter (1 parameter: array of events, return value should be modified array)
  • eme_location_filter (1 parameter: $location array, return value should be modified array)
  • eme_location_list_filter (1 parameter: array of locations, return value should be modified array)
  • eme_directions_form_filter (1 parameter: generated html for the directions form, return value should be modified html)
  • eme_add_booking_form_filter and eme_delete_booking_form_filter (1parameter: generated html for the add or delete booking form, return value should be modified html)
  • eme_email_obfuscate_filter (1 parameter: email address or phone). If defined, the standard ascii obfuscating won’t take place and you can use your own filters, eg. from an obfuscating plugin, if you define it in functions.php:
    add_filter( ‘eme_email_obfuscate_filter’, ‘c2c_obfuscate_email’ );
    This filter is used to alter the obfuscation for email address and phone in mails sent.
  • eme_eval_booking_form_filter (2 parameters: $event, $booker). If defined, this function can do extra evaluations on the booking being done before it is recorded. You can use the $event, $booker and $_POST info for your evaluations. The return should be an array, with the first element of that array indicating that your evaluation is successful or not (1 or 0) and the second parameter a string indicating the reason if not successfull. Returning the array happens like this for success:
    array(0=>1,1=>'');
    or for failure:
    array(0=>0,1=>'The eval failed because of ....');
    For example, put the following in your theme functions.php to prevent double name/email combo’s to register twice (EME can check for this, but only if you require WP membership, otherwise it’s just too easy to change a letter in the name):
    add_filter('eme_eval_booking_filter','do_my_stuff');
    function do_my_stuff($event) {
        $event_id=$event['event_id'];
        $already_registered=0;
    
        // only do a specific event
        if ($event_id != 5) return;
    
        // get all attendees
        $attendees = eme_get_attendees_for($event_id);
        foreach ( $attendees as $attendee ) {
           // $attendee['person_email'], $attendee['person_name']
           $bookerEmail = eme_sanitize_html(stripslashes_deep($_POST['bookerEmail']));
           $bookerName = eme_sanitize_html(stripslashes_deep($_POST['bookerName']));
           if ($bookerEmail == $attendee['person_email'] && $bookerName == $attendee['person_name'])
              $already_registered=1;
        }
    
        if (!$already_registered) {
           // eval is success
           return array(0=>1,1=>'');
        } else {
           // bad form entry
           return array(0=>0,1=>'Already registered');
        }
    }
    

  • eme_event_preinsert_filter (1 parameter: $event), taking place just before the event is inserted in the DB. The return should be the modified $event array.
  • eme_event_preupdate_filter (1 parameter: $event), taking place just before the event is updated in the DB. The return should be the modified $event array.
  • eme_add_currencies (1 parameter: array of currencies), so you can add extra currencies to the list. Be aware that not all payment portals support all currencies.
    Example: to add Ghanaian Cedi (GHS) to the list of currencies, add the following to your theme’s functions.php:

      function my_eme_add_currencies($currencies){
          $currencies['GHS'] = 'Ghanaian Cedi';
          return $currencies;
      }
      add_filter('eme_add_currencies','my_eme_add_currencies');

  • eme_categories_filter (1 parameter: array of categories) executed when searching for the categories (e.g. when creating an event). With this, you can e.g. limit the categories shown when creating an event or location or … .
  • eme_rsvp_email_body_text_filter and eme_rsvp_email_body_html_filter (1 parameter: mail body being sent), taking place just before a mail is being sent (all mails: pending, success, cancelled, to contact person or booker, …). The return should be the modified mail body