Last active
April 2, 2017 21:03
-
-
Save panoslyrakis/a25615d6afbcc87a1ff435bf2a35286a to your computer and use it in GitHub Desktop.
Send enrollment notification to admin and instructors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'coursepress_email_sent-enrollment_confirm', function( $args, $result ){ | |
$course_id = $args['course_id']; | |
$send_to = array( get_option('admin_email') ); | |
$course_title = get_the_title( $course_id ); | |
$course_instructors = array(); | |
$instructors = (array) CoursePress_Data_Course::get_setting( $course_id, 'instructors', array() ); | |
$instructors = array_filter( $instructors ); | |
if ( ! empty( $instructors ) ) { | |
foreach ( $instructors as $instructor_id ) { | |
$instructor = get_userdata( $instructor_id ); | |
$send_to[] = $instructor->user_email; | |
} | |
} | |
$send_to = array_unique( $send_to, SORT_REGULAR ); | |
$args['intructor_subject'] = 'New student for course ' . $course_title; | |
ob_start(); | |
?> | |
Hi, | |
A new student has enrolled for course <strong>"<?php echo $course_title; ?>"</strong>! | |
<p> | |
<u>Student info</u>:<br /> | |
<strong>First name: </strong><?php echo $args['first_name']; ?><br /> | |
<strong>Last name: </strong><?php echo $args['last_name']; ?><br /> | |
<strong>Student email: </strong><?php echo $args['email']; ?><br /> | |
</p> | |
<?php | |
$intructor_message = ob_get_clean(); | |
$args['intructor_message'] = $intructor_message; | |
foreach( $send_to as $email_to ){ | |
$email = array( | |
'to' => apply_filters( | |
'coursepress_email_to_address', | |
sanitize_email( $email_to ), | |
$args | |
), | |
'subject' => apply_filters( | |
'coursepress_email_subject', | |
sanitize_text_field( $args['intructor_subject'] ) , | |
$args | |
), | |
'message' => apply_filters( | |
'coursepress_email_message', | |
$args['intructor_message'], | |
$args | |
), | |
'headers' => apply_filters( | |
'coursepress_email_headers_to_instructor', | |
array( | |
'Content-Type: text/html; charset=UTF-8', | |
) | |
) | |
); | |
try { | |
$result = wp_mail( | |
$email['to'], | |
$email['subject'], | |
$email['message'], | |
$email['headers'] | |
); | |
} catch(phpmailerException $e) { | |
$result = false; | |
} | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment