1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
4
|
|
|
|
5
|
|
|
if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_Completed_Course' ) ) : |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Teacher Completed Course |
9
|
|
|
* |
10
|
|
|
* An email sent to the teacher when one of their students completes a course. |
11
|
|
|
* |
12
|
|
|
* @package Users |
13
|
|
|
* @author Automattic |
14
|
|
|
* |
15
|
|
|
* @since 1.6.0 |
16
|
|
|
*/ |
17
|
|
|
class WooThemes_Sensei_Email_Teacher_Completed_Course { |
18
|
|
|
|
19
|
|
|
var $template; |
|
|
|
|
20
|
|
|
var $subject; |
|
|
|
|
21
|
|
|
var $heading; |
|
|
|
|
22
|
|
|
var $recipient; |
|
|
|
|
23
|
|
|
var $learner; |
|
|
|
|
24
|
|
|
var $teacher; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Constructor |
28
|
|
|
* |
29
|
|
|
* @access public |
30
|
|
|
*/ |
31
|
|
|
function __construct() { |
|
|
|
|
32
|
|
|
$this->template = 'teacher-completed-course'; |
33
|
|
|
$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your student has completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
34
|
|
|
$this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has completed a course', 'woothemes-sensei' ), $this->template ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* trigger function. |
39
|
|
|
* |
40
|
|
|
* @param int $learner_id |
41
|
|
|
* @param int $course_id |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
function trigger( $learner_id = 0, $course_id = 0 ) { |
|
|
|
|
46
|
|
|
global $sensei_email_data; |
47
|
|
|
|
48
|
|
|
// Get learner user object |
49
|
|
|
$this->learner = new WP_User( $learner_id ); |
50
|
|
|
|
51
|
|
|
// Get teacher ID and user object |
52
|
|
|
$teacher_id = get_post_field( 'post_author', $course_id, 'raw' ); |
53
|
|
|
$this->teacher = new WP_User( $teacher_id ); |
54
|
|
|
|
55
|
|
|
// Get passed status |
56
|
|
|
$passed = __( 'passed', 'woothemes-sensei' ); |
57
|
|
|
if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $learner_id ) ) { |
58
|
|
|
$passed = __( 'failed', 'woothemes-sensei' ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// Construct data array |
62
|
|
|
$sensei_email_data = apply_filters( 'sensei_email_data', array( |
63
|
|
|
'template' => $this->template, |
64
|
|
|
'heading' => $this->heading, |
65
|
|
|
'teacher_id' => $teacher_id, |
66
|
|
|
'learner_id' => $learner_id, |
67
|
|
|
'learner_name' => $this->learner->display_name, |
68
|
|
|
'course_id' => $course_id, |
69
|
|
|
'passed' => $passed, |
70
|
|
|
), $this->template ); |
71
|
|
|
|
72
|
|
|
// Set recipient (learner) |
73
|
|
|
$this->recipient = stripslashes( $this->teacher->user_email ); |
74
|
|
|
|
75
|
|
|
// Send mail |
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_Teacher_Completed_Course(); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.