Send an email to all active users upon creation of event.

When I create a new event I'd like to send an e-mail to all registered users of my Buddypress site (limited to a particular user role). Is this capability available within the plugin? If not, can anyone point me to the location of the "create event" method in the plugin so I can wire-up my own method and hook into it that sucker?

  • Vladislav
    • Dead Eye Dev


    As Brian said, this feature isn't currently available. However, if you're up for some custom coding, you may want to make use of the default "wp_insert_post" hook and send your emails when this is triggered. I'd also suggest binding your function to a higher then the default, to give some space for possible add-ons and custom modifications to do their thing first too.

  • leon_amarant
    • New Recruit

    Thanks guys...not sure why I didn't think of "wp_insert_post" hook. Anyway, since I have your attention, does this psuedo-code look right?

    Create and wire a method into the wp_insert_post hook that:
    1: checks post type of the inserted post
    2: if post type = incsub_event then:
    3: assemble list of users to email using get_users( $args )
    4: create the e-mail and send it to the list of users

    Also, assuming I get this thing working the obvious next question is what will happen if the event is modified or deleted? In each of these cases I'd like to send an e-mail to all of the registered attendees of the event (Yes', Maybe's, and No's...No's just in case the reason for the No was the date/location of the event). My question to you is how would I retrieve a list of event attendees?

    Finally, I'm thinking of developing this as an "extension" plugin to Events+ where admins could customize the email as well as the list of users it is sent to. If it works out I'd like to make it publicly available. Is there anything I need to consider with regard to extending this plugin?

  • Vladislav
    • Dead Eye Dev


    A lot of the heavy lifting for the individual Event is done through the event model instance object (class Eab_EventModel, file lib/class_eab_event_model.php). You can instantiate an object of this type in your wp_insert_post handler by passing a post object ($post) to the constructor. The method you'd likely be interested in for getting the bookings for your event is called "get_bookings($status, $since)" - it will return a list of promised bookings, and accepts two optional arguments which will fiter its output. The first optional argument is "status", which will reduce the returned list to only the results that have the passed status - this is best passed as one of class constants (Eab_EventModel::BOOKING_YES, Eab_EventModel::BOOKING_MAYBE, Eab_EventModel::BOOKING_NO). The second optional parameter ($since) is supposed to be a valid UNIX timestamp and, if present, it'll act as a lower limit for the returned list.

    There are a number of other useful methods in this class, which will hopefully significantly reduce the effort needed to create the extension plugin. Most of the methods are also documented inline, so hopefully it shouldn't be difficult to follow either.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.