Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panoslyrakis/a25615d6afbcc87a1ff435bf2a35286a to your computer and use it in GitHub Desktop.
Save panoslyrakis/a25615d6afbcc87a1ff435bf2a35286a to your computer and use it in GitHub Desktop.
Send enrollment notification to admin and instructors
<?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