. */ if(!class_exists('AEM')) { /* Class: AEM The AEM class which enables the AfterEM functionality in WordPress. */ class AEM { const ID = 'AEM'; const OPTIONS = 'AEM_options'; const AUTOLOAD = 'no'; const PLUGIN_NAME = 'AfterEM'; const SCHEDULE_TIME = '06:00:00'; // The time at which the scheduler will run. private static $defaultOptions = array( 'afterEventEnabled' => true, 'afterEventSubject' => 'Thank You for Attending #_EVENTNAME', 'afterEventBody' => '

Dear #_BOOKINGNAME,

Please take a few minutes to evaluate the event you recently attended, #_EVENTNAME, using the following form: #.

Thank you for your attendance and participation!

AfterEM

' ); /* Function: __construct The constructor function is used to setup WordPress hooks. */ public function __construct() { register_activation_hook(__FILE__, array('AEM', 'activationHook')); register_deactivation_hook(__FILE__, array('AEM', 'deactivationHook')); register_uninstall_hook(__FILE__, array('AEM', 'uninstallHook')); add_action('admin_init', array(&$this, 'adminInit')); add_action('admin_menu', array(&$this, 'addSubmenuItem'), 11); // Lower priority to make sure parent menu has a chance to be loaded first. add_action(self::ID.'_sendMail', array(&$this, 'sendMail')); // Create a hook for the scheduler. } /* Function: activationHook Adds scheduled mailer hook and options to database. ***STATIC FUNCTION*** */ public static function activationHook() { if(!current_user_can('manage_options')) { wp_die('You do not have sufficient permissions to access this page.'); } // Setup/make sure scheduler is setup. if(!wp_next_scheduled(self::ID.'_sendMail')) { wp_schedule_event(strtotime(self::SCHEDULE_TIME.' +1 day', current_time('timestamp')), 'daily', self::ID.'_sendMail'); } // Add options to database, no autoload. add_option(self::OPTIONS, self::$defaultOptions, '', self::AUTOLOAD); } /* Function: deactivationHook Removes scheduled mailer hook. ***STATIC FUNCTION*** */ public static function deactivationHook() { if(!current_user_can('manage_options')) { wp_die('You do not have sufficient permissions to access this page.'); } // Remove scheduled hook. wp_clear_scheduled_hook(self::ID.'_sendMail'); } /* Function: uninstallHook Makes sure scheduled mailer hook is gone and removes options from database. ***STATIC FUNCTION*** */ public static function uninstallHook() { // Do not check WP_UNINSTALL_PLUGIN here, it is only present for uninstall.php files!!! if(!current_user_can('manage_options')) { wp_die('You do not have sufficient permissions to access this page.'); } // Remove options from database. delete_option(self::OPTIONS); // Make sure the scheduler is gone. wp_clear_scheduled_hook(self::ID.'_sendMail'); } /* Function: adminInit Saves options and sends the test email. */ public function adminInit() { // Make sure user is an admin (lower permissions?). if(current_user_can('manage_options')) { // If form was submitted and the nonce is verified save it to the options. if(isset($_POST[self::ID.'_save']) && isset($_POST[self::ID.'_nonce']) && wp_verify_nonce($_POST[self::ID.'_nonce'], 'saveTemplate')) { $options = array(); $options['afterEventEnabled'] = (isset($_POST['afterEventEnabled']) && $_POST['afterEventEnabled'] == 'on') ? true : false; $options['afterEventSubject'] = isset($_POST['afterEventSubject']) ? stripslashes_deep($_POST['afterEventSubject']) : ''; $options['afterEventBody'] = isset($_POST['afterEventBody']) ? stripslashes_deep($_POST['afterEventBody']) : ''; update_option(self::OPTIONS, $options, self::AUTOLOAD); } // Send test email if nonce is good. if(isset($_POST[self::ID.'_test_email']) && isset($_POST['testEmail']) && isset($_POST[self::ID.'_nonce']) && wp_verify_nonce($_POST[self::ID.'_nonce'], 'sendEmail')) { $options = get_option(self::OPTIONS, self::$defaultOptions); if($to = sanitize_email($_POST['testEmail'])) { wp_mail($to, $options['afterEventSubject'], $options['afterEventBody'], 'Content-type: text/html'); } } } } /* Function: addSubmenuItem Adds the new submenu item under Events. */ public function addSubmenuItem() { add_submenu_page('edit.php?post_type=event', self::PLUGIN_NAME, self::PLUGIN_NAME, 'manage_options', self::ID, array(&$this, 'submenuPage')); } /* Function: submenuPage Controls output on this page including messages. Outputs: HTML for the submenu page. */ public function submenuPage() { $options = get_option(self::OPTIONS, self::$defaultOptions); ?>

Plugin

The template has been saved!

An email has been sent to .

Email Template

This accepts booking, event, and location related placeholders. Please see Events Manager Help for more information on placeholders.

/>

Send Test Email (save changes above first)

Note: This does not replace the placeholders in the email.

       

date('Y-m-d', strtotime('-1 day', current_time('timestamp'))))); // For each event. foreach($yesterdaysEvents as $x) { $event = new EM_Event($x->event_id); $event->get_location(); // Adds the location object to the event object. $event->get_bookings(); // Get the bookings (adds the bookings object to the event object). // Each user booking is one booking. foreach($event->bookings as $y) { // If booking status is not "approved" then do not send an email (1 is approved). if($y->booking_status != 1) { continue; } // Parses event, location, and booking related placeholders. $subject = $y->output($event->output($event->location->output($options['afterEventSubject']))); $body = $y->output($event->output($event->location->output($options['afterEventBody']))); wp_mail($y->get_person()->user_email, $subject, $body, 'Content-type: text/html'); } } } } $AEM = new AEM(); }