1: <?php
2:
3: if ( ! defined( 'ABSPATH' ) ) exit;
4:
5: if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Completed_Course' ) ) :
6:
7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class WooThemes_Sensei_Email_Learner_Completed_Course {
18:
19: var $template;
20: var $subject;
21: var $heading;
22: var $recipient;
23: var $user;
24:
25: 26: 27: 28: 29: 30:
31: function __construct() {
32: $this->template = 'learner-completed-course';
33: $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
34: $this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a course', 'woothemes-sensei' ), $this->template );
35: }
36:
37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
47: function trigger( $user_id = 0, $course_id = 0 ) {
48: global $sensei_email_data;
49:
50: if ( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ) {
51: return;
52: }
53:
54:
55: $this->user = new WP_User( $user_id );
56:
57:
58: $passed = __( 'passed', 'woothemes-sensei' );
59: if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $user_id ) ) {
60: $passed = __( 'failed', 'woothemes-sensei' );
61: }
62:
63:
64: $sensei_email_data = apply_filters( 'sensei_email_data', array(
65: 'template' => $this->template,
66: 'heading' => $this->heading,
67: 'user_id' => $user_id,
68: 'course_id' => $course_id,
69: 'passed' => $passed,
70: ), $this->template );
71:
72:
73: $this->recipient = stripslashes( $this->user->user_email );
74:
75:
76: Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
77: }
78: }
79:
80: endif;
81:
82: return new WooThemes_Sensei_Email_Learner_Completed_Course();