|
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 2.0 |
|
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 2.0 |
|
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 2.0 |
|
36
|
|
|
*/ |
|
37
|
|
|
public function init() { |
|
38
|
|
|
// Initialize empty payment. |
|
39
|
|
|
$this->payment = new Give_Payment( 0 ); |
|
40
|
|
|
|
|
41
|
|
|
$this->load( array( |
|
42
|
|
|
'id' => 'offline-donation-instruction', |
|
43
|
|
|
'label' => __( 'Offline Donation Instruction', 'give' ), |
|
44
|
|
|
'description' => __( 'Offline Donation Instruction will be sent to recipient(s) when offline donation received.', 'give' ), |
|
45
|
|
|
'notification_status' => give_is_gateway_active( 'offline' ) ? 'enabled' : 'disabled', |
|
46
|
|
|
'form_metabox_setting' => true, |
|
47
|
|
|
'notification_status_editable' => false, |
|
48
|
|
|
'preview_email_tag_values' => array( |
|
49
|
|
|
'payment_method' => esc_html__( 'Offline', 'give' ), |
|
50
|
|
|
), |
|
51
|
|
|
'default_email_subject' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ), |
|
52
|
|
|
'default_email_message' => give_get_default_offline_donation_email_content(), |
|
53
|
|
|
) ); |
|
54
|
|
|
|
|
55
|
|
|
add_action( 'give_insert_payment', array( $this, 'setup_email_notification' ) ); |
|
56
|
|
|
add_action( 'give_save_settings_give_settings', array( $this, 'set_notification_status' ), 10, 2 ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get email message |
|
62
|
|
|
* |
|
63
|
|
|
* @since 2.0 |
|
64
|
|
|
* |
|
65
|
|
|
* @param int $form_id |
|
66
|
|
|
* |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
View Code Duplication |
public function get_email_message( $form_id = null ) { |
|
|
|
|
|
|
70
|
|
|
$message = Give_Email_Notification_Util::get_value( |
|
71
|
|
|
$this, |
|
72
|
|
|
Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_message', |
|
73
|
|
|
$form_id, |
|
74
|
|
|
$this->config['default_email_message'] |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Filter the email message. |
|
79
|
|
|
* |
|
80
|
|
|
* @since 2.0 |
|
81
|
|
|
*/ |
|
82
|
|
|
$message = apply_filters( |
|
83
|
|
|
"give_{$this->config['id']}_get_email_message", |
|
84
|
|
|
$message, |
|
85
|
|
|
$this, |
|
86
|
|
|
$form_id |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
return $message; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get email message |
|
94
|
|
|
* |
|
95
|
|
|
* @since 2.0 |
|
96
|
|
|
* |
|
97
|
|
|
* @param int $form_id |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
View Code Duplication |
public function get_email_subject( $form_id = null ) { |
|
|
|
|
|
|
102
|
|
|
$subject = wp_strip_all_tags( |
|
103
|
|
|
Give_Email_Notification_Util::get_value( |
|
104
|
|
|
$this, |
|
105
|
|
|
Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_subject', |
|
106
|
|
|
$form_id, |
|
107
|
|
|
$this->config['default_email_subject'] |
|
108
|
|
|
) |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Filter the email subject. |
|
113
|
|
|
* |
|
114
|
|
|
* @since 2.0 |
|
115
|
|
|
*/ |
|
116
|
|
|
$subject = apply_filters( |
|
117
|
|
|
"give_{$this->config['id']}_get_email_subject", |
|
118
|
|
|
$subject, |
|
119
|
|
|
$this, |
|
120
|
|
|
$form_id |
|
121
|
|
|
); |
|
122
|
|
|
|
|
123
|
|
|
return $subject; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get attachments. |
|
128
|
|
|
* |
|
129
|
|
|
* @since 2.0 |
|
130
|
|
|
* |
|
131
|
|
|
* @param int $form_id |
|
132
|
|
|
* @return array |
|
133
|
|
|
*/ |
|
134
|
|
View Code Duplication |
public function get_email_attachments( $form_id = null ) { |
|
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Filter the attachments. |
|
137
|
|
|
* Note: This filter will deprecate soon. |
|
138
|
|
|
* |
|
139
|
|
|
* @since 1.0 |
|
140
|
|
|
*/ |
|
141
|
|
|
$attachment = apply_filters( |
|
142
|
|
|
'give_offline_donation_attachments', |
|
143
|
|
|
array(), |
|
144
|
|
|
$this->payment->ID, |
|
145
|
|
|
$this->payment->payment_meta |
|
146
|
|
|
); |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Filter the email attachment. |
|
150
|
|
|
* |
|
151
|
|
|
* @since 2.0 |
|
152
|
|
|
*/ |
|
153
|
|
|
$attachment = apply_filters( |
|
154
|
|
|
"give_{$this->config['id']}_get_email_attachment", |
|
155
|
|
|
$attachment, |
|
156
|
|
|
$this, |
|
157
|
|
|
$form_id |
|
158
|
|
|
); |
|
159
|
|
|
|
|
160
|
|
|
return $attachment; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Set email data. |
|
166
|
|
|
* |
|
167
|
|
|
* @since 2.0 |
|
168
|
|
|
*/ |
|
169
|
|
View Code Duplication |
public function setup_email_data() { |
|
|
|
|
|
|
170
|
|
|
// Set recipient email. |
|
171
|
|
|
$this->recipient_email = $this->payment->email; |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Filters the from name. |
|
175
|
|
|
* |
|
176
|
|
|
* @since 1.7 |
|
177
|
|
|
*/ |
|
178
|
|
|
$from_name = apply_filters( |
|
179
|
|
|
'give_donation_from_name', |
|
180
|
|
|
Give()->emails->get_from_name(), |
|
181
|
|
|
$this->payment->ID, |
|
182
|
|
|
$this->payment->payment_meta |
|
183
|
|
|
); |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Filters the from email. |
|
187
|
|
|
* |
|
188
|
|
|
* @since 1.7 |
|
189
|
|
|
*/ |
|
190
|
|
|
$from_email = apply_filters( |
|
191
|
|
|
'give_donation_from_address', |
|
192
|
|
|
Give()->emails->get_from_address(), |
|
193
|
|
|
$this->payment->ID, |
|
194
|
|
|
$this->payment->payment_meta |
|
195
|
|
|
); |
|
196
|
|
|
|
|
197
|
|
|
Give()->emails->__set( 'from_name', $from_name ); |
|
198
|
|
|
Give()->emails->__set( 'from_email', $from_email ); |
|
199
|
|
|
Give()->emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) ); |
|
200
|
|
|
Give()->emails->__set( 'headers', apply_filters( 'give_receipt_headers', Give()->emails->get_headers(), $this->payment->ID, $this->payment->payment_meta ) ); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Setup email notification. |
|
205
|
|
|
* |
|
206
|
|
|
* @since 2.0 |
|
207
|
|
|
* @access public |
|
208
|
|
|
* |
|
209
|
|
|
* @param int $payment_id |
|
210
|
|
|
*/ |
|
211
|
|
View Code Duplication |
public function setup_email_notification( $payment_id ) { |
|
|
|
|
|
|
212
|
|
|
$this->payment = new Give_Payment( $payment_id ); |
|
213
|
|
|
|
|
214
|
|
|
// Exit if not donation was not with offline donation. |
|
215
|
|
|
if ( 'offline' !== $this->payment->gateway ) { |
|
216
|
|
|
return; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
// Set email data. |
|
220
|
|
|
$this->setup_email_data(); |
|
221
|
|
|
|
|
222
|
|
|
// Send email. |
|
223
|
|
|
$this->send_email_notification( array( |
|
224
|
|
|
'payment_id' => $this->payment->ID, |
|
225
|
|
|
) ); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Set notification status |
|
230
|
|
|
* |
|
231
|
|
|
* @since 2.0 |
|
232
|
|
|
* @access public |
|
233
|
|
|
* |
|
234
|
|
|
* @param $update_options |
|
235
|
|
|
* @param $option_name |
|
236
|
|
|
*/ |
|
237
|
|
View Code Duplication |
public function set_notification_status( $update_options, $option_name ) { |
|
|
|
|
|
|
238
|
|
|
// Get updated settings. |
|
239
|
|
|
$update_options = give_get_settings(); |
|
240
|
|
|
|
|
241
|
|
|
$notification_status = isset( $update_options['gateways']['offline'] ) ? 'enabled' : 'disabled'; |
|
242
|
|
|
|
|
243
|
|
|
if ( |
|
244
|
|
|
empty( $update_options["{$this->config['id']}_notification"] ) |
|
|
|
|
|
|
245
|
|
|
|| $notification_status !== $update_options["{$this->config['id']}_notification"] |
|
|
|
|
|
|
246
|
|
|
) { |
|
247
|
|
|
$update_options["{$this->config['id']}_notification"] = $notification_status; |
|
|
|
|
|
|
248
|
|
|
update_option( $option_name, $update_options ); |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
endif; // End class_exists check |
|
254
|
|
|
|
|
255
|
|
|
return Give_Offline_Donation_Instruction_Email::get_instance(); |
|
256
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.