1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
4
|
|
|
|
5
|
|
|
if ( ! class_exists( 'WooThemes_Sensei_Email_New_Message_Reply' ) ) : |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Teacher New Message |
9
|
|
|
* |
10
|
|
|
* An email sent to the a user when they receive a reply to the private message. |
11
|
|
|
* |
12
|
|
|
* @package Users |
13
|
|
|
* @author Automattic |
14
|
|
|
* |
15
|
|
|
* @since 1.6.0 |
16
|
|
|
*/ |
17
|
|
|
class WooThemes_Sensei_Email_New_Message_Reply { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
var $template; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
var $subject; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
var $heading; |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
var $recipient; |
|
|
|
|
38
|
|
|
|
39
|
|
|
var $original_sender; |
|
|
|
|
40
|
|
|
var $original_receiver; |
|
|
|
|
41
|
|
|
var $commenter; |
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var WP_Post |
45
|
|
|
*/ |
46
|
|
|
var $message; |
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var WP_Comment |
50
|
|
|
*/ |
51
|
|
|
var $comment; |
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Constructor |
55
|
|
|
* |
56
|
|
|
* @access public |
57
|
|
|
*/ |
58
|
|
|
function __construct() { |
|
|
|
|
59
|
|
|
$this->template = 'new-message-reply'; |
60
|
|
|
$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have a new message', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
61
|
|
|
$this->heading = apply_filters( 'sensei_email_heading', __( 'You have received a reply to your private message', 'woothemes-sensei' ), $this->template ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* trigger function. |
66
|
|
|
* |
67
|
|
|
* @param WP_Comment $comment |
68
|
|
|
* @param string $message |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
function trigger ( $comment, $message ) { |
|
|
|
|
73
|
|
|
|
74
|
|
|
global $sensei_email_data; |
75
|
|
|
|
76
|
|
|
$this->comment = $comment; |
77
|
|
|
$this->message = $message; |
|
|
|
|
78
|
|
|
|
79
|
|
|
$this->commenter = get_userdata( $comment->user_id ); |
80
|
|
|
|
81
|
|
|
$original_sender = get_post_meta( $this->message->ID, '_sender', true ); |
82
|
|
|
$this->original_sender = get_user_by( 'login', $original_sender ); |
83
|
|
|
|
84
|
|
|
$original_receiver = get_post_meta( $this->message->ID, '_receiver', true ); |
85
|
|
|
$this->original_receiver = get_user_by( 'login', $original_receiver ); |
86
|
|
|
|
87
|
|
|
$content_type = get_post_meta( $this->message->ID, '_posttype', true ); |
|
|
|
|
88
|
|
|
$content_id = get_post_meta( $this->message->ID, '_post', true ); |
89
|
|
|
$content_title = get_the_title( $content_id ); |
90
|
|
|
|
91
|
|
|
$comment_link = get_comment_link( $comment ); |
92
|
|
|
|
93
|
|
|
// setup the post type parameter |
94
|
|
|
$content_type = get_post_type( $content_id ); |
95
|
|
|
if( !$content_type ){ |
96
|
|
|
$content_type =''; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// Construct data array |
100
|
|
|
$sensei_email_data = apply_filters( 'sensei_email_data', array( |
101
|
|
|
'template' => $this->template, |
102
|
|
|
$content_type.'_id' => $content_id, |
103
|
|
|
'heading' => $this->heading, |
104
|
|
|
'commenter_name' => $this->commenter->display_name, |
105
|
|
|
'message' => $this->comment->comment_content, |
106
|
|
|
'comment_link' => $comment_link, |
107
|
|
|
'content_title' => $content_title, |
108
|
|
|
'content_type' => $content_type, |
109
|
|
|
), $this->template ); |
110
|
|
|
|
111
|
|
|
// Set recipient |
112
|
|
|
if( $this->commenter->user_login == $original_sender ) { |
113
|
|
|
$this->recipient = stripslashes( $this->original_receiver->user_email ); |
114
|
|
|
} else { |
115
|
|
|
$this->recipient = stripslashes( $this->original_sender->user_email ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
// Send mail |
119
|
|
|
Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
endif; |
124
|
|
|
|
125
|
|
|
return new WooThemes_Sensei_Email_New_Message_Reply(); |
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.