Advertisement
eventsmanager

Auto-Approve Event Submission Emails

Apr 22nd, 2021
1,082
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Very slight mod to the em-emails.php em_event_submission_emails function to allow submissions by anonymous guests which are auto-approved to still get sent an email.
  3. For installation instructions please see:
  4. http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/
  5.  * @param boolean $result
  6.  * @param EM_Event $EM_Event
  7.  * @return boolean
  8.  */
  9. function my_em_event_submission_emails($result, $EM_Event) {
  10.     remove_filter('em_event_save', 'em_event_submission_emails', 10);
  11.     if ($result) {
  12.         //if this is just published, we need to email the user about the publication, or send to pending mode again for review
  13.         $output_type = get_option('dbem_smtp_html') ? 'html' : 'email';
  14.         if (true || $cant_publish_event || $cant_publish_recurring_event) {
  15.             if ($EM_Event->is_published() && !$EM_Event->get_previous_status()) {
  16.                 //only send email to users that can't publish events themselves and that were previously unpublished
  17.                 $approvals_count = get_post_meta($EM_Event->post_id, '_event_approvals_count', true);
  18.                 $approvals_count = $approvals_count > 0 ? $approvals_count : 0;
  19.                 if ($approvals_count == 1) {
  20.                     $subject = $EM_Event->output(get_option('dbem_event_approved_email_subject'), 'raw');
  21.                     $body = $EM_Event->output(get_option('dbem_event_approved_email_body'), $output_type);
  22.                 } else {
  23.                     $subject = $EM_Event->output(get_option('dbem_event_reapproved_email_subject'), 'raw');
  24.                     $body = $EM_Event->output(get_option('dbem_event_reapproved_email_body'), $output_type);
  25.                 }
  26.                 if ($EM_Event->event_owner == "") return true;
  27.                 $EM_Event->email_send($subject, $body, $EM_Event->get_contact()->user_email);
  28.             } elseif ($EM_Event->get_status() === 0 && get_option('dbem_event_submitted_email_admin') != '' && empty($EM_Event->duplicated)) {
  29.                 $approvals_count = get_post_meta($EM_Event->post_id, '_event_approvals_count', true);
  30.                 $approvals_count = $approvals_count > 0 ? $approvals_count : 0;
  31.                 update_post_meta($EM_Event->post_id, '_event_approvals_count', $approvals_count + 1);
  32.                 $admin_emails = explode(',', str_replace(' ', '', get_option('dbem_event_submitted_email_admin'))); //admin emails are in an array, single or multiple
  33.                 if (empty($admin_emails)) return true;
  34.                 if ($approvals_count > 1) {
  35.                     $subject = $EM_Event->output(get_option('dbem_event_resubmitted_email_subject'), 'raw');
  36.                     $message = $EM_Event->output(get_option('dbem_event_resubmitted_email_body'), $output_type);
  37.                 } else {
  38.                     $subject = $EM_Event->output(get_option('dbem_event_submitted_email_subject'), 'raw');
  39.                     $message = $EM_Event->output(get_option('dbem_event_submitted_email_body'), $output_type);
  40.                 }
  41.                 //Send email to admins
  42.                 $EM_Event->email_send($subject, $message, $admin_emails);
  43.             }
  44.         } elseif (!current_user_can('manage_options')) {
  45.             if ($EM_Event->is_published() && !$EM_Event->get_previous_status()) {
  46.                 $admin_emails = explode(',', str_replace(' ', '', get_option('dbem_event_submitted_email_admin'))); //admin emails are in an array, single or multiple
  47.                 if (empty($admin_emails)) return true;
  48.                 $subject = $EM_Event->output(get_option('dbem_event_published_email_subject'), 'raw');
  49.                 $body = $EM_Event->output(get_option('dbem_event_published_email_body'), $output_type);
  50.                 $EM_Event->email_send($subject, $body, $admin_emails);
  51.             }
  52.         }
  53.     }
  54.     return $result;
  55. }
  56.  
  57. add_filter('em_event_save', 'my_em_event_submission_emails', 9, 2);
Advertisement
RAW Paste Data Copied
Advertisement