|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* New Donation Email |
|
4
|
|
|
* |
|
5
|
|
|
* This class handles all email notification settings. |
|
6
|
|
|
* |
|
7
|
|
|
* @package Give |
|
8
|
|
|
* @subpackage Classes/Emails |
|
9
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
|
10
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
|
11
|
|
|
* @since 1.9 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
// Exit if access directly. |
|
15
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
16
|
|
|
exit; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
if ( ! class_exists( 'Give_New_Donation_Email' ) ) : |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Give_New_Donation_Email |
|
23
|
|
|
* |
|
24
|
|
|
* @abstract |
|
25
|
|
|
* @since 1.9 |
|
26
|
|
|
*/ |
|
27
|
|
|
class Give_New_Donation_Email extends Give_Email_Notification { |
|
28
|
|
|
/* @var Give_Payment $payment */ |
|
29
|
|
|
public $payment; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Create a class instance. |
|
33
|
|
|
* |
|
34
|
|
|
* @access public |
|
35
|
|
|
* @since 1.9 |
|
36
|
|
|
*/ |
|
37
|
|
|
public function init() { |
|
38
|
|
|
$this->id = 'new-donation'; |
|
39
|
|
|
$this->label = __( 'New Donation', 'give' ); |
|
40
|
|
|
$this->description = __( 'Donation Notification will be sent to recipient(s) when new donation received except offline donation.', 'give' ); |
|
41
|
|
|
|
|
42
|
|
|
$this->has_recipient_field = true; |
|
43
|
|
|
$this->notification_status = 'enabled'; |
|
44
|
|
|
|
|
45
|
|
|
// Initialize empty payment. |
|
46
|
|
|
$this->payment = new Give_Payment( 0 ); |
|
47
|
|
|
|
|
48
|
|
|
parent::load(); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
add_action( "give_{$this->id}_email_notification", array( $this, 'setup_email_notification' ) ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get email subject. |
|
56
|
|
|
* |
|
57
|
|
|
* @since 1.9 |
|
58
|
|
|
* @access public |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
public function get_email_subject() { |
|
62
|
|
|
$subject = wp_strip_all_tags( give_get_option( "{$this->id}_email_subject", $this->get_default_email_subject() ) ); |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Filters the donation notification subject. |
|
66
|
|
|
* Note: This filter will deprecate soon. |
|
67
|
|
|
* |
|
68
|
|
|
* @since 1.0 |
|
69
|
|
|
*/ |
|
70
|
|
|
$subject = apply_filters( 'give_admin_donation_notification_subject', $subject, $this->payment ); |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Filters the donation notification subject. |
|
74
|
|
|
* |
|
75
|
|
|
* @since 1.9 |
|
76
|
|
|
*/ |
|
77
|
|
|
$subject = apply_filters( "give_{$this->id}_get_email_subject", $subject, $this ); |
|
78
|
|
|
|
|
79
|
|
|
return $subject; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get email attachment. |
|
85
|
|
|
* |
|
86
|
|
|
* @since 1.9 |
|
87
|
|
|
* @access public |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function get_email_message() { |
|
91
|
|
|
$message = give_get_option( "{$this->id}_email_message", $this->get_default_email_message() ); |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Filter the email message |
|
95
|
|
|
* Note: This filter will deprecate soon. |
|
96
|
|
|
* |
|
97
|
|
|
* @since 1.0 |
|
98
|
|
|
*/ |
|
99
|
|
|
$message = apply_filters( 'give_donation_notification', $message, $this->payment->ID, $this->payment->payment_meta ); |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Filter the email message |
|
103
|
|
|
* |
|
104
|
|
|
* @since 1.9 |
|
105
|
|
|
*/ |
|
106
|
|
|
$message = apply_filters( "give_{$this->id}_get_default_email_message", $message, $this ); |
|
107
|
|
|
|
|
108
|
|
|
return $message; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get email attachment. |
|
114
|
|
|
* |
|
115
|
|
|
* @since 1.9 |
|
116
|
|
|
* @access public |
|
117
|
|
|
* @return array |
|
118
|
|
|
*/ |
|
119
|
|
|
public function get_email_attachments() { |
|
120
|
|
|
/** |
|
121
|
|
|
* Filters the donation notification email attachments. |
|
122
|
|
|
* By default, there is no attachment but plugins can hook in to provide one more multiple. |
|
123
|
|
|
* Note: This filter will deprecate soon. |
|
124
|
|
|
* |
|
125
|
|
|
* @since 1.0 |
|
126
|
|
|
*/ |
|
127
|
|
|
$attachments = apply_filters( 'give_admin_donation_notification_attachments', array(), $this->payment->ID, $this->payment->payment_meta ); |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Filters the donation notification email attachments. |
|
131
|
|
|
* By default, there is no attachment but plugins can hook in to provide one more multiple. |
|
132
|
|
|
* |
|
133
|
|
|
* @since 1.9 |
|
134
|
|
|
*/ |
|
135
|
|
|
$attachments = apply_filters( "give_{$this->id}_get_email_attachments", $attachments, $this ); |
|
136
|
|
|
|
|
137
|
|
|
return $attachments; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Get default email subject. |
|
142
|
|
|
* |
|
143
|
|
|
* @since 1.9 |
|
144
|
|
|
* @access public |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
public function get_default_email_subject() { |
|
148
|
|
|
/** |
|
149
|
|
|
* Filter the defaul email subject. |
|
150
|
|
|
* |
|
151
|
|
|
* @since 1.9 |
|
152
|
|
|
*/ |
|
153
|
|
|
return apply_filters( "give_{$this->id}_get_default_email_subject", esc_attr__( 'New Donation - #{payment_id}', 'give' ), $this ); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Get default email message. |
|
159
|
|
|
* |
|
160
|
|
|
* @since 1.9 |
|
161
|
|
|
* @access public |
|
162
|
|
|
* |
|
163
|
|
|
* @return string |
|
164
|
|
|
*/ |
|
165
|
|
|
public function get_default_email_message() { |
|
166
|
|
|
/** |
|
167
|
|
|
* Filter the new donation email message |
|
168
|
|
|
* |
|
169
|
|
|
* @since 1.9 |
|
170
|
|
|
* |
|
171
|
|
|
* @param string $message |
|
172
|
|
|
*/ |
|
173
|
|
|
return apply_filters( "give_{$this->id}_get_default_email_message", give_get_default_donation_notification_email(), $this ); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Set email data |
|
179
|
|
|
* |
|
180
|
|
|
* @since 1.9 |
|
181
|
|
|
*/ |
|
182
|
|
|
public function setup_email_data() { |
|
183
|
|
|
/** |
|
184
|
|
|
* Filters the from name. |
|
185
|
|
|
* Note: This filter will deprecate soon. |
|
186
|
|
|
* |
|
187
|
|
|
* @since 1.0 |
|
188
|
|
|
*/ |
|
189
|
|
|
$from_name = apply_filters( 'give_donation_from_name', Give()->emails->get_from_name(), $this->payment->ID, $this->payment->payment_meta ); |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Filters the from email. |
|
193
|
|
|
* Note: This filter will deprecate soon. |
|
194
|
|
|
* |
|
195
|
|
|
* @since 1.0 |
|
196
|
|
|
*/ |
|
197
|
|
|
$from_email = apply_filters( 'give_donation_from_address', Give()->emails->get_from_address(), $this->payment->ID, $this->payment->payment_meta ); |
|
198
|
|
|
|
|
199
|
|
|
Give()->emails->__set( 'from_name', $from_name ); |
|
200
|
|
|
Give()->emails->__set( 'from_email', $from_email ); |
|
201
|
|
|
Give()->emails->__set( 'heading', esc_html__( 'New Donation!', 'give' ) ); |
|
202
|
|
|
/** |
|
203
|
|
|
* Filters the donation notification email headers. |
|
204
|
|
|
* |
|
205
|
|
|
* @since 1.0 |
|
206
|
|
|
*/ |
|
207
|
|
|
$headers = apply_filters( 'give_admin_donation_notification_headers', Give()->emails->get_headers(), $this->payment->ID, $this->payment->payment_meta ); |
|
208
|
|
|
|
|
209
|
|
|
Give()->emails->__set( 'headers', $headers ); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Setup email notification. |
|
214
|
|
|
* |
|
215
|
|
|
* @since 1.9 |
|
216
|
|
|
* @access public |
|
217
|
|
|
* |
|
218
|
|
|
* @param int $payment_id |
|
219
|
|
|
*/ |
|
220
|
|
|
public function setup_email_notification( $payment_id ) { |
|
221
|
|
|
$this->payment = new Give_Payment( $payment_id ); |
|
222
|
|
|
|
|
223
|
|
|
// Set email data. |
|
224
|
|
|
$this->setup_email_data(); |
|
225
|
|
|
|
|
226
|
|
|
// Send email. |
|
227
|
|
|
$this->send_email_notification( array( 'payment_id' => $payment_id ) ); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
endif; // End class_exists check |
|
232
|
|
|
|
|
233
|
|
|
return Give_New_Donation_Email::get_instance(); |
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.