|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* Offline Donation Instruction 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_Offline_Donation_Instruction_Email' ) ) : |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Give_Offline_Donation_Instruction_Email |
|
23
|
|
|
* |
|
24
|
|
|
* @abstract |
|
25
|
|
|
* @since 1.9 |
|
26
|
|
|
*/ |
|
27
|
|
|
class Give_Offline_Donation_Instruction_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 = 'offline-donation-instruction'; |
|
39
|
|
|
$this->label = __( 'Offline Donation Instruction', 'give' ); |
|
40
|
|
|
$this->description = __( 'Offline Donation Instruction will be sent to recipient(s) when offline donation received.', 'give' ); |
|
41
|
|
|
|
|
42
|
|
|
$this->notification_status = 'enabled'; |
|
43
|
|
|
$this->recipient_group_name = __( 'Donor', 'give' ); |
|
44
|
|
|
$this->preview_email_tags_values = array( |
|
45
|
|
|
'payment_method' => esc_html__( 'Offline', 'give' ), |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
// Initialize empty payment. |
|
49
|
|
|
$this->payment = new Give_Payment( 0 ); |
|
50
|
|
|
|
|
51
|
|
|
parent::load(); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
add_action( 'give_insert_payment', array( $this, 'setup_email_notification' ) ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get email message |
|
59
|
|
|
* |
|
60
|
|
|
* @since 1.9 |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function get_email_message() { |
|
64
|
|
|
$post_offline_customization_option = get_post_meta( |
|
65
|
|
|
$this->payment->form_id, |
|
66
|
|
|
'_give_customize_offline_donations', |
|
67
|
|
|
true |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
//Customize email content depending on whether the single form has been customized |
|
71
|
|
|
$message = give_get_option( "{$this->id}_email_message", $this->get_default_email_message() ); |
|
72
|
|
|
|
|
73
|
|
|
if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) { |
|
74
|
|
|
$message = get_post_meta( $this->payment->form_id, '_give_offline_donation_email', true ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Filter the email message. |
|
79
|
|
|
* |
|
80
|
|
|
* @since 1.9 |
|
81
|
|
|
*/ |
|
82
|
|
|
$message = apply_filters( "give_{$this->id}_get_email_message", $message, $this ); |
|
83
|
|
|
|
|
84
|
|
|
return $message; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get email message |
|
89
|
|
|
* |
|
90
|
|
|
* @since 1.9 |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function get_email_subject() { |
|
94
|
|
|
$post_offline_customization_option = get_post_meta( |
|
95
|
|
|
$this->payment->form_id, |
|
96
|
|
|
'_give_customize_offline_donations', |
|
97
|
|
|
true |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
$subject = give_get_option( |
|
101
|
|
|
"{$this->id}_email_subject", |
|
102
|
|
|
$this->get_default_email_subject() |
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
|
|
if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) { |
|
106
|
|
|
$subject = get_post_meta( $this->payment->form_id, '_give_offline_donation_subject', true ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Filter the email subject. |
|
111
|
|
|
* |
|
112
|
|
|
* @since 1.9 |
|
113
|
|
|
*/ |
|
114
|
|
|
$subject = apply_filters( "give_{$this->id}_get_email_subject", $subject, $this ); |
|
115
|
|
|
|
|
116
|
|
|
return $subject; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Get attachments. |
|
121
|
|
|
* |
|
122
|
|
|
* @since 1.9 |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
|
|
public function get_email_attachments() { |
|
126
|
|
|
/** |
|
127
|
|
|
* Filter the attachments. |
|
128
|
|
|
* Note: This filter will deprecate soon. |
|
129
|
|
|
* |
|
130
|
|
|
* @since 1.0 |
|
131
|
|
|
*/ |
|
132
|
|
|
$attachment = apply_filters( |
|
133
|
|
|
'give_offline_donation_attachments', |
|
134
|
|
|
array(), |
|
135
|
|
|
$this->payment->ID, |
|
136
|
|
|
$this->payment->payment_meta |
|
137
|
|
|
); |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Filter the email attachment. |
|
141
|
|
|
* |
|
142
|
|
|
* @since 1.9 |
|
143
|
|
|
*/ |
|
144
|
|
|
$attachment = apply_filters( "give_{$this->id}_get_email_attachment", $attachment, $this ); |
|
145
|
|
|
|
|
146
|
|
|
return $attachment; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Get default email subject. |
|
151
|
|
|
* |
|
152
|
|
|
* @since 1.9 |
|
153
|
|
|
* @access public |
|
154
|
|
|
* @return string |
|
155
|
|
|
*/ |
|
156
|
|
|
public function get_default_email_subject() { |
|
157
|
|
|
/** |
|
158
|
|
|
* Filter the default subject. |
|
159
|
|
|
* |
|
160
|
|
|
* @since 1.9 |
|
161
|
|
|
*/ |
|
162
|
|
|
return apply_filters( "give_{$this->id}_get_default_email_subject", esc_attr__( '{donation} - Offline Donation Instructions', 'give' ), $this ); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Get default email message. |
|
168
|
|
|
* |
|
169
|
|
|
* @since 1.9 |
|
170
|
|
|
* @access public |
|
171
|
|
|
* |
|
172
|
|
|
* @return string |
|
173
|
|
|
*/ |
|
174
|
|
|
public function get_default_email_message() { |
|
175
|
|
|
$message = give_get_default_offline_donation_email_content(); |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Filter the email message |
|
179
|
|
|
* |
|
180
|
|
|
* @since 1.9 |
|
181
|
|
|
* |
|
182
|
|
|
* @param string $message |
|
183
|
|
|
*/ |
|
184
|
|
|
return apply_filters( "give_{$this->id}_get_default_email_message", $message, $this ); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Set email data. |
|
190
|
|
|
* |
|
191
|
|
|
* @since 1.9 |
|
192
|
|
|
*/ |
|
193
|
|
|
public function setup_email_data() { |
|
194
|
|
|
// Set recipient email. |
|
195
|
|
|
$this->recipient_email = $this->payment->email; |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Filters the from name. |
|
199
|
|
|
* |
|
200
|
|
|
* @since 1.7 |
|
201
|
|
|
*/ |
|
202
|
|
|
$from_name = apply_filters( 'give_donation_from_name', Give()->emails->get_from_name(), $this->payment->ID, $this->payment->payment_meta ); |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Filters the from email. |
|
206
|
|
|
* |
|
207
|
|
|
* @since 1.7 |
|
208
|
|
|
*/ |
|
209
|
|
|
$from_email = apply_filters( 'give_donation_from_address', Give()->emails->get_from_address(), $this->payment->ID, $this->payment->payment_meta ); |
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
Give()->emails->__set( 'from_name', $from_name ); |
|
213
|
|
|
Give()->emails->__set( 'from_email', $from_email ); |
|
214
|
|
|
Give()->emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) ); |
|
215
|
|
|
Give()->emails->__set( 'headers', apply_filters( 'give_receipt_headers', Give()->emails->get_headers(), $this->payment->ID, $this->payment->payment_meta ) ); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Setup email notification. |
|
220
|
|
|
* |
|
221
|
|
|
* @since 1.9 |
|
222
|
|
|
* @access public |
|
223
|
|
|
* |
|
224
|
|
|
* @param int $payment_id |
|
225
|
|
|
*/ |
|
226
|
|
|
public function setup_email_notification( $payment_id ) { |
|
227
|
|
|
$this->payment = new Give_Payment( $payment_id ); |
|
228
|
|
|
|
|
229
|
|
|
// Exit if not donation was not with offline donation. |
|
230
|
|
|
if ( 'offline' !== $this->payment->gateway ) { |
|
231
|
|
|
return; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
// Set email data. |
|
235
|
|
|
$this->setup_email_data(); |
|
236
|
|
|
|
|
237
|
|
|
// Send email. |
|
238
|
|
|
$this->send_email_notification( array( 'payment_id' => $this->payment->ID ) ); |
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
endif; // End class_exists check |
|
243
|
|
|
|
|
244
|
|
|
return Give_Offline_Donation_Instruction_Email::get_instance(); |
|
245
|
|
|
|
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.