1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
4
|
|
|
|
5
|
|
|
if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_New_Message' ) ) : |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Teacher New Message |
9
|
|
|
* |
10
|
|
|
* An email sent to the teacher when one of their students sends them a private message. |
11
|
|
|
* |
12
|
|
|
* @package Users |
13
|
|
|
* @author Automattic |
14
|
|
|
* |
15
|
|
|
* @since 1.6.0 |
16
|
|
|
*/ |
17
|
|
|
class WooThemes_Sensei_Email_Teacher_New_Message { |
18
|
|
|
|
19
|
|
|
var $template; |
|
|
|
|
20
|
|
|
var $subject; |
|
|
|
|
21
|
|
|
var $heading; |
|
|
|
|
22
|
|
|
var $recipient; |
|
|
|
|
23
|
|
|
var $learner; |
|
|
|
|
24
|
|
|
var $teacher; |
|
|
|
|
25
|
|
|
var $message; |
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor |
29
|
|
|
*/ |
30
|
|
|
function __construct() { |
|
|
|
|
31
|
|
|
$this->template = 'teacher-new-message'; |
32
|
|
|
$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have received a new private message', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
33
|
|
|
$this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has sent you a private message', 'woothemes-sensei' ), $this->template ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* trigger function. |
38
|
|
|
* |
39
|
|
|
* @access public |
40
|
|
|
* @param integer $message_id |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
function trigger( $message_id = 0 ) { |
|
|
|
|
44
|
|
|
global $sensei_email_data; |
45
|
|
|
|
46
|
|
|
$this->message = get_post( $message_id ); |
47
|
|
|
|
48
|
|
|
$learner_username = get_post_meta( $message_id, '_sender', true ); |
49
|
|
|
$this->learner = get_user_by( 'login', $learner_username ); |
50
|
|
|
|
51
|
|
|
$teacher_username = get_post_meta( $message_id, '_receiver', true ); |
52
|
|
|
$this->teacher = get_user_by( 'login', $teacher_username ); |
53
|
|
|
|
54
|
|
|
$content_type = get_post_meta( $message_id, '_posttype', true ); |
|
|
|
|
55
|
|
|
$content_id = get_post_meta( $message_id, '_post', true ); |
56
|
|
|
$content_title = get_the_title( $content_id ); |
57
|
|
|
|
58
|
|
|
// setup the post type parameter |
59
|
|
|
$content_type = get_post_type( $content_id ); |
60
|
|
|
if( !$content_type ){ |
61
|
|
|
$content_type =''; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Construct data array |
65
|
|
|
$sensei_email_data = apply_filters( 'sensei_email_data', array( |
66
|
|
|
'template' => $this->template, |
67
|
|
|
$content_type.'_id' => $content_id, |
68
|
|
|
'heading' => $this->heading, |
69
|
|
|
'teacher_id' => $this->teacher->ID, |
70
|
|
|
'learner_id' => $this->learner->ID, |
71
|
|
|
'learner_name' => $this->learner->display_name, |
72
|
|
|
'message_id' => $message_id, |
73
|
|
|
'message' => $this->message->post_content, |
74
|
|
|
'content_title' => $content_title, |
75
|
|
|
'content_type' => $content_type, |
76
|
|
|
), $this->template ); |
77
|
|
|
|
78
|
|
|
// Set recipient (teacher) |
79
|
|
|
$this->recipient = stripslashes( $this->teacher->user_email ); |
80
|
|
|
|
81
|
|
|
// Send mail |
82
|
|
|
Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
83
|
|
|
|
84
|
|
|
wp_safe_redirect( esc_url_raw( add_query_arg( array( 'send' => 'complete' ) ) ) ); |
85
|
|
|
exit; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
endif; |
90
|
|
|
|
91
|
|
|
return new WooThemes_Sensei_Email_Teacher_New_Message(); |
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.