|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Email Template |
|
4
|
|
|
* |
|
5
|
|
|
* @package Give |
|
6
|
|
|
* @subpackage Emails |
|
7
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
|
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
|
9
|
|
|
* @since 1.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
|
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
14
|
|
|
exit; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Gets all the email templates that have been registered. The list is extendable |
|
19
|
|
|
* and more templates can be added. |
|
20
|
|
|
* |
|
21
|
|
|
* This is simply a wrapper to Give_Email_Templates->get_templates() |
|
22
|
|
|
* |
|
23
|
|
|
* @since 1.0 |
|
24
|
|
|
* @return array $templates All the registered email templates. |
|
25
|
|
|
*/ |
|
26
|
|
|
function give_get_email_templates() { |
|
27
|
|
|
$templates = new Give_Emails; |
|
28
|
|
|
|
|
29
|
|
|
return $templates->get_templates(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Email Template Tags. |
|
34
|
|
|
* @todo Modify this function to remove payment id dependency. |
|
35
|
|
|
* |
|
36
|
|
|
* @since 1.0 |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $message Message with the template tags. |
|
39
|
|
|
* @param array $payment_data Payment Data. |
|
40
|
|
|
* @param int $payment_id Payment ID. |
|
41
|
|
|
* @param bool $admin_notice Whether or not this is a notification email. |
|
42
|
|
|
* |
|
43
|
|
|
* @return string $message Fully formatted message |
|
44
|
|
|
*/ |
|
45
|
|
|
function give_email_template_tags( $message, $payment_data, $payment_id, $admin_notice = false ) { |
|
|
|
|
|
|
46
|
|
|
return give_do_email_tags( $message, $payment_id ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Email Preview Template Tags. |
|
51
|
|
|
* |
|
52
|
|
|
* Provides sample content for the preview email functionality within settings > email. |
|
53
|
|
|
* |
|
54
|
|
|
* @since 1.0 |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $message Email message with template tags |
|
57
|
|
|
* |
|
58
|
|
|
* @return string $message Fully formatted message |
|
59
|
|
|
*/ |
|
60
|
|
|
function give_email_preview_template_tags( $message ) { |
|
61
|
|
|
|
|
62
|
|
|
$price = give_currency_filter( give_format_amount( 10.50, array( 'sanitize' => false ) ) ); |
|
63
|
|
|
|
|
64
|
|
|
$gateway = 'PayPal'; |
|
65
|
|
|
|
|
66
|
|
|
$receipt_id = strtolower( md5( uniqid() ) ); |
|
67
|
|
|
|
|
68
|
|
|
$payment_id = rand( 1, 100 ); |
|
69
|
|
|
|
|
70
|
|
|
$receipt_link_url = esc_url( add_query_arg( array( 'payment_key' => $receipt_id, 'give_action' => 'view_receipt' ), home_url() ) ); |
|
71
|
|
|
$receipt_link = sprintf( |
|
72
|
|
|
'<a href="%1$s">%2$s</a>', |
|
73
|
|
|
$receipt_link_url, |
|
74
|
|
|
esc_html__( 'View the receipt in your browser »', 'give' ) |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
// Set user. |
|
78
|
|
|
$user = wp_get_current_user(); |
|
79
|
|
|
|
|
80
|
|
|
$message = str_replace( '{name}', $user->display_name, $message ); |
|
81
|
|
|
$message = str_replace( '{fullname}', $user->display_name, $message ); |
|
82
|
|
|
$message = str_replace( '{username}', $user->user_login, $message ); |
|
83
|
|
|
$message = str_replace( '{user_email}', $user->user_email, $message ); |
|
84
|
|
|
$message = str_replace( '{billing_address}', "123 Test Street, Unit 222\nSomewhere Town, CA, 92101", $message ); |
|
85
|
|
|
$message = str_replace( '{date}', date( give_date_format(), current_time( 'timestamp' ) ), $message ); |
|
86
|
|
|
$message = str_replace( '{amount}', $price, $message ); |
|
87
|
|
|
$message = str_replace( '{price}', $price, $message ); |
|
88
|
|
|
$message = str_replace( '{donation}', esc_html__( 'Sample Donation Form Title', 'give' ), $message ); |
|
89
|
|
|
$message = str_replace( '{form_title}', esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ), $message ); |
|
90
|
|
|
$message = str_replace( '{receipt_id}', $receipt_id, $message ); |
|
91
|
|
|
$message = str_replace( '{payment_method}', $gateway, $message ); |
|
92
|
|
|
$message = str_replace( '{sitename}', get_bloginfo( 'name' ), $message ); |
|
93
|
|
|
$message = str_replace( '{payment_id}', $payment_id, $message ); |
|
94
|
|
|
$message = str_replace( '{receipt_link}', $receipt_link, $message ); |
|
95
|
|
|
$message = str_replace( '{receipt_link_url}', $receipt_link_url, $message ); |
|
96
|
|
|
$message = str_replace( '{pdf_receipt}', '<a href="#">Download Receipt</a>', $message ); |
|
97
|
|
|
|
|
98
|
|
|
return wpautop( apply_filters( 'give_email_preview_template_tags', $message ) ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Output Email Template Preview Buttons. |
|
105
|
|
|
* |
|
106
|
|
|
* @access private |
|
107
|
|
|
* @since 1.0 |
|
108
|
|
|
* @since 1.8 Field arguments param added. |
|
109
|
|
|
* |
|
110
|
|
|
* @param array $field Field arguments. |
|
111
|
|
|
* |
|
112
|
|
|
* @return array |
|
113
|
|
|
*/ |
|
114
|
|
|
function give_email_preview_buttons_callback( $field ) { |
|
115
|
|
|
$field_id = str_replace( '_preview_buttons', '', $field['id'] ); |
|
116
|
|
|
|
|
117
|
|
|
ob_start(); |
|
118
|
|
|
|
|
119
|
|
|
echo sprintf( |
|
|
|
|
|
|
120
|
|
|
'<a href="%1$s" class="button-secondary" target="_blank">%2$s</a>', |
|
121
|
|
|
wp_nonce_url( |
|
122
|
|
|
add_query_arg( |
|
123
|
|
|
array( 'give_action' => 'preview_email', 'email_type' => $field_id ), |
|
124
|
|
|
home_url() |
|
125
|
|
|
), 'give-preview-email' |
|
126
|
|
|
), |
|
127
|
|
|
$field['name'] |
|
128
|
|
|
); |
|
129
|
|
|
|
|
130
|
|
|
echo sprintf( |
|
|
|
|
|
|
131
|
|
|
' <a href="%1$s" aria-label="%2$s" class="button-secondary">%3$s</a>', |
|
132
|
|
|
wp_nonce_url( |
|
133
|
|
|
add_query_arg( array( |
|
|
|
|
|
|
134
|
|
|
'give_action' => 'send_preview_email', |
|
|
|
|
|
|
135
|
|
|
'email_type' => $field_id, |
|
|
|
|
|
|
136
|
|
|
'give-message' => 'sent-test-email', |
|
|
|
|
|
|
137
|
|
|
) ), 'give-send-preview-email' ), |
|
|
|
|
|
|
138
|
|
|
esc_attr__( 'Send Test Email.', 'give' ), |
|
139
|
|
|
esc_html__( 'Send Test Email', 'give' ) |
|
140
|
|
|
); |
|
141
|
|
|
|
|
142
|
|
|
echo ob_get_clean(); |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Render Receipt in the Browser. |
|
148
|
|
|
* |
|
149
|
|
|
* A link is added to the Donation Receipt to view the email in the browser and |
|
150
|
|
|
* this function renders the Donation Receipt in the browser. It overrides the |
|
151
|
|
|
* Donation Receipt template and provides its only styling. |
|
152
|
|
|
* |
|
153
|
|
|
* @since 1.0 |
|
154
|
|
|
*/ |
|
155
|
|
|
function give_render_receipt_in_browser() { |
|
156
|
|
|
if ( ! isset( $_GET['payment_key'] ) ) { |
|
|
|
|
|
|
157
|
|
|
wp_die( esc_html__( 'Missing donation payment key.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 400 ) ); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
$key = urlencode( $_GET['payment_key'] ); |
|
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
ob_start(); |
|
163
|
|
|
//Disallows caching of the page |
|
164
|
|
|
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" ); |
|
|
|
|
|
|
165
|
|
|
header( "Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1 |
|
|
|
|
|
|
166
|
|
|
header( "Cache-Control: post-check=0, pre-check=0", false ); |
|
|
|
|
|
|
167
|
|
|
header( "Pragma: no-cache" ); // HTTP/1.0 |
|
|
|
|
|
|
168
|
|
|
header( "Expires: Sat, 23 Oct 1977 05:00:00 PST" ); // Date in the past |
|
|
|
|
|
|
169
|
|
|
?> |
|
170
|
|
|
<!DOCTYPE html> |
|
171
|
|
|
<html lang="en"> |
|
172
|
|
|
<head> |
|
173
|
|
|
<?php |
|
174
|
|
|
/** |
|
175
|
|
|
* Fires in the receipt HEAD. |
|
176
|
|
|
* |
|
177
|
|
|
* @since 1.0 |
|
178
|
|
|
*/ |
|
179
|
|
|
do_action( 'give_receipt_head' ); |
|
180
|
|
|
?> |
|
181
|
|
|
</head> |
|
182
|
|
|
<body class="<?php echo apply_filters( 'give_receipt_page_body_class', 'give_receipt_page' ); ?>"> |
|
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
<div id="give_receipt_wrapper"> |
|
185
|
|
|
<?php |
|
186
|
|
|
/** |
|
187
|
|
|
* Fires in the receipt template before the content. |
|
188
|
|
|
* |
|
189
|
|
|
* @since 1.0 |
|
190
|
|
|
*/ |
|
191
|
|
|
do_action( 'give_render_receipt_in_browser_before' ); |
|
192
|
|
|
|
|
193
|
|
|
echo do_shortcode( '[give_receipt payment_key=' . $key . ']' ); |
|
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Fires in the receipt template after the content. |
|
197
|
|
|
* |
|
198
|
|
|
* @since 1.0 |
|
199
|
|
|
*/ |
|
200
|
|
|
do_action( 'give_render_receipt_in_browser_after' ); |
|
201
|
|
|
?> |
|
202
|
|
|
</div> |
|
203
|
|
|
|
|
204
|
|
|
<?php |
|
205
|
|
|
/** |
|
206
|
|
|
* Fires in the receipt footer. |
|
207
|
|
|
* |
|
208
|
|
|
* @since 1.0 |
|
209
|
|
|
*/ |
|
210
|
|
|
do_action( 'give_receipt_footer' ); |
|
211
|
|
|
?> |
|
212
|
|
|
</body> |
|
213
|
|
|
</html> |
|
214
|
|
|
<?php |
|
215
|
|
|
echo ob_get_clean(); |
|
|
|
|
|
|
216
|
|
|
die(); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
add_action( 'give_view_receipt', 'give_render_receipt_in_browser' ); |
|
220
|
|
|
|
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Give Preview Email Header. |
|
224
|
|
|
* |
|
225
|
|
|
* Displays a header bar with the ability to change donations to preview actual data within the preview. Will not display if |
|
226
|
|
|
* |
|
227
|
|
|
* @since 1.6 |
|
228
|
|
|
* |
|
229
|
|
|
*/ |
|
230
|
|
|
function give_get_preview_email_header() { |
|
231
|
|
|
|
|
232
|
|
|
//Payment receipt switcher |
|
233
|
|
|
$payment_count = give_count_payments()->publish; |
|
234
|
|
|
$payment_id = give_check_variable( give_clean( $_GET ), 'isset', 0, 'preview_id' ); |
|
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
if ( $payment_count <= 0 ) { |
|
237
|
|
|
return false; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
//Get payments. |
|
241
|
|
|
$payments = new Give_Payments_Query( array( |
|
242
|
|
|
'number' => 100, |
|
243
|
|
|
) ); |
|
244
|
|
|
$payments = $payments->get_payments(); |
|
245
|
|
|
$options = array(); |
|
246
|
|
|
|
|
247
|
|
|
// Default option. |
|
248
|
|
|
$options[0] = esc_html__( 'No donations found.', 'give' ); |
|
249
|
|
|
|
|
250
|
|
|
//Provide nice human readable options. |
|
251
|
|
|
if ( $payments ) { |
|
|
|
|
|
|
252
|
|
|
$options[0] = esc_html__( '- Select a donation -', 'give' ); |
|
253
|
|
|
foreach ( $payments as $payment ) { |
|
254
|
|
|
|
|
255
|
|
|
$options[ $payment->ID ] = esc_html( '#' . $payment->ID . ' - ' . $payment->email . ' - ' . $payment->form_title ); |
|
256
|
|
|
|
|
257
|
|
|
} |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
//Start constructing HTML output. |
|
261
|
|
|
$transaction_header = '<div style="margin:0;padding:10px 0;width:100%;background-color:#FFF;border-bottom:1px solid #eee; text-align:center;">'; |
|
262
|
|
|
|
|
263
|
|
|
//Inline JS function for switching donations. |
|
264
|
|
|
$request_url = $_SERVER['REQUEST_URI']; |
|
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
// Remove payment id query param if set from request url. |
|
267
|
|
|
if ( $payment_id ) { |
|
268
|
|
|
$request_url_data = wp_parse_url( $_SERVER['REQUEST_URI'] ); |
|
|
|
|
|
|
269
|
|
|
$query = $request_url_data['query']; |
|
270
|
|
|
$query = str_replace( "&preview_id={$payment_id}", '', $query ); |
|
271
|
|
|
|
|
272
|
|
|
$request_url = home_url( '/?' . str_replace( '', '', $query ) ); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
$transaction_header .= '<script> |
|
277
|
|
|
function change_preview(){ |
|
278
|
|
|
var transactions = document.getElementById("give_preview_email_payment_id"); |
|
279
|
|
|
var selected_trans = transactions.options[transactions.selectedIndex]; |
|
280
|
|
|
console.log(selected_trans); |
|
281
|
|
|
if (selected_trans){ |
|
282
|
|
|
var url_string = "' . $request_url . '&preview_id=" + selected_trans.value; |
|
283
|
|
|
window.location = url_string; |
|
284
|
|
|
} |
|
285
|
|
|
} |
|
286
|
|
|
</script>'; |
|
287
|
|
|
|
|
288
|
|
|
$transaction_header .= '<label for="give_preview_email_payment_id" style="font-size:12px;color:#333;margin:0 4px 0 0;">' . esc_html__( 'Preview email with a donation:', 'give' ) . '</label>'; |
|
289
|
|
|
|
|
290
|
|
|
//The select field with 100 latest transactions |
|
291
|
|
|
$transaction_header .= Give()->html->select( array( |
|
292
|
|
|
'name' => 'preview_email_payment_id', |
|
293
|
|
|
'selected' => $payment_id, |
|
294
|
|
|
'id' => 'give_preview_email_payment_id', |
|
295
|
|
|
'class' => 'give-preview-email-payment-id', |
|
296
|
|
|
'options' => $options, |
|
297
|
|
|
'chosen' => false, |
|
298
|
|
|
'select_atts' => 'onchange="change_preview()"', |
|
299
|
|
|
'show_option_all' => false, |
|
300
|
|
|
'show_option_none' => false, |
|
301
|
|
|
) ); |
|
302
|
|
|
|
|
303
|
|
|
//Closing tag |
|
304
|
|
|
$transaction_header .= '</div>'; |
|
305
|
|
|
|
|
306
|
|
|
return apply_filters( 'give_preview_email_receipt_header', $transaction_header ); |
|
307
|
|
|
|
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* Give Receipt Head Content |
|
313
|
|
|
* |
|
314
|
|
|
* @since 1.6 |
|
315
|
|
|
* @return string |
|
316
|
|
|
*/ |
|
317
|
|
|
function give_receipt_head_content() { |
|
318
|
|
|
|
|
319
|
|
|
//Title. |
|
320
|
|
|
$output = '<title>' . esc_html__( 'Donation Receipt', 'give' ) . '</title>'; |
|
321
|
|
|
|
|
322
|
|
|
//Meta. |
|
323
|
|
|
$output .= '<meta charset="utf-8"/> |
|
324
|
|
|
<!-- Further disallowing of caching of this page --> |
|
325
|
|
|
<meta charset="utf-8"/> |
|
326
|
|
|
<meta http-equiv="cache-control" content="max-age=0"/> |
|
327
|
|
|
<meta http-equiv="cache-control" content="no-cache"/> |
|
328
|
|
|
<meta http-equiv="expires" content="0"/> |
|
329
|
|
|
<meta http-equiv="expires" content="Tue, 23 Oct 1977 05:00:00 PST"/> |
|
330
|
|
|
<meta http-equiv="pragma" content="no-cache"/> |
|
331
|
|
|
<meta name="robots" content="noindex, nofollow"/>'; |
|
332
|
|
|
|
|
333
|
|
|
//CSS |
|
334
|
|
|
$output .= '<link rel="stylesheet" href="' . give_get_stylesheet_uri() . '?ver=' . GIVE_VERSION . '">'; |
|
|
|
|
|
|
335
|
|
|
|
|
336
|
|
|
echo apply_filters( 'give_receipt_head_content', $output ); |
|
|
|
|
|
|
337
|
|
|
|
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
add_action( 'give_receipt_head', 'give_receipt_head_content' ); |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.