PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.6.0
GiveWP – Donation Plugin and Fundraising Platform v2.6.0
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / gateways / offline-donations.php
give / includes / gateways Last commit date
stripe 6 years ago actions.php 6 years ago functions.php 6 years ago manual.php 6 years ago offline-donations.php 6 years ago paypal-standard.php 6 years ago
offline-donations.php
496 lines
1 <?php
2 /**
3 * Offline Donations Gateway
4 *
5 * @package Give
6 * @subpackage Gateways
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 /**
13 * Add our payment instructions to the checkout
14 *
15 * @since 1.0
16 *
17 * @param int $form_id Give form id.
18 *
19 * @return void
20 */
21 function give_offline_payment_cc_form( $form_id ) {
22 // Get offline payment instruction.
23 $offline_instructions = give_get_offline_payment_instruction( $form_id, true );
24
25 ob_start();
26
27 /**
28 * Fires before the offline info fields.
29 *
30 * @since 1.0
31 *
32 * @param int $form_id Give form id.
33 */
34 do_action( 'give_before_offline_info_fields', $form_id );
35 ?>
36 <fieldset id="give_offline_payment_info">
37 <?php echo stripslashes( $offline_instructions ); ?>
38 </fieldset>
39 <?php
40 /**
41 * Fires after the offline info fields.
42 *
43 * @since 1.0
44 *
45 * @param int $form_id Give form id.
46 */
47 do_action( 'give_after_offline_info_fields', $form_id );
48
49 echo ob_get_clean();
50 }
51
52 add_action( 'give_offline_cc_form', 'give_offline_payment_cc_form' );
53
54 /**
55 * Give Offline Billing Field
56 *
57 * @param $form_id
58 */
59 function give_offline_billing_fields( $form_id ) {
60 //Enable Default CC fields (billing info)
61 $post_offline_cc_fields = give_get_meta( $form_id, '_give_offline_donation_enable_billing_fields_single', true );
62 $post_offline_customize_option = give_get_meta( $form_id, '_give_customize_offline_donations', true, 'global' );
63
64 $global_offline_cc_fields = give_get_option( 'give_offline_donation_enable_billing_fields' );
65
66 //Output CC Address fields if global option is on and user hasn't elected to customize this form's offline donation options
67 if (
68 ( give_is_setting_enabled( $post_offline_customize_option, 'global' ) && give_is_setting_enabled( $global_offline_cc_fields ) )
69 || ( give_is_setting_enabled( $post_offline_customize_option, 'enabled' ) && give_is_setting_enabled( $post_offline_cc_fields ) )
70 ) {
71 give_default_cc_address_fields( $form_id );
72 }
73 }
74
75 add_action( 'give_before_offline_info_fields', 'give_offline_billing_fields', 10, 1 );
76
77 /**
78 * Process the payment
79 *
80 * @since 1.0
81 *
82 * @param $purchase_data
83 *
84 * @return void
85 */
86 function give_offline_process_payment( $purchase_data ) {
87
88 // Setup the payment details.
89 $payment_data = array(
90 'price' => $purchase_data['price'],
91 'give_form_title' => $purchase_data['post_data']['give-form-title'],
92 'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ),
93 'give_price_id' => isset( $purchase_data['post_data']['give-price-id'] ) ? $purchase_data['post_data']['give-price-id'] : '',
94 'date' => $purchase_data['date'],
95 'user_email' => $purchase_data['user_email'],
96 'purchase_key' => $purchase_data['purchase_key'],
97 'currency' => give_get_currency( $purchase_data['post_data']['give-form-id'], $purchase_data ),
98 'user_info' => $purchase_data['user_info'],
99 'status' => 'pending',
100 'gateway' => 'offline',
101 );
102
103 // record the pending payment
104 $payment = give_insert_payment( $payment_data );
105
106 if ( $payment ) {
107 give_send_to_success_page();
108 } else {
109 // if errors are present, send the user back to the donation form so they can be corrected
110 give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] );
111 }
112
113 }
114
115 add_action( 'give_gateway_offline', 'give_offline_process_payment' );
116
117
118 /**
119 * Send Offline Donation Instructions
120 *
121 * Sends a notice to the donor with offline instructions; can be customized per form
122 *
123 * @param int $payment_id
124 *
125 * @since 1.0
126 * @return void
127 */
128 function give_offline_send_donor_instructions( $payment_id = 0 ) {
129
130 $payment_data = give_get_payment_meta( $payment_id );
131 $post_offline_customization_option = give_get_meta( $payment_data['form_id'], '_give_customize_offline_donations', true );
132
133 //Customize email content depending on whether the single form has been customized
134 $email_content = give_get_option( 'global_offline_donation_email' );
135
136 if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
137 $email_content = give_get_meta( $payment_data['form_id'], '_give_offline_donation_email', true );
138 }
139
140 $from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
141
142 /**
143 * Filters the from name.
144 *
145 * @since 1.7
146 */
147 $from_name = apply_filters( 'give_donation_from_name', $from_name, $payment_id, $payment_data );
148
149 $from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) );
150
151 /**
152 * Filters the from email.
153 *
154 * @since 1.7
155 */
156 $from_email = apply_filters( 'give_donation_from_address', $from_email, $payment_id, $payment_data );
157
158 $to_email = give_get_payment_user_email( $payment_id );
159
160 $subject = give_get_option( 'offline_donation_subject', __( 'Offline Donation Instructions', 'give' ) );
161 if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
162 $subject = give_get_meta( $payment_data['form_id'], '_give_offline_donation_subject', true );
163 }
164
165 $subject = apply_filters( 'give_offline_donation_subject', wp_strip_all_tags( $subject ), $payment_id );
166 $subject = give_do_email_tags( $subject, $payment_id );
167
168 $attachments = apply_filters( 'give_offline_donation_attachments', array(), $payment_id, $payment_data );
169 $message = give_do_email_tags( $email_content, $payment_id );
170
171 $emails = Give()->emails;
172
173 $emails->__set( 'from_name', $from_name );
174 $emails->__set( 'from_email', $from_email );
175 $emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) );
176
177 $headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data );
178 $emails->__set( 'headers', $headers );
179
180 $emails->send( $to_email, $subject, $message, $attachments );
181
182 }
183
184
185 /**
186 * Send Offline Donation Admin Notice.
187 *
188 * Sends a notice to site admins about the pending donation.
189 *
190 * @since 1.0
191 *
192 * @param int $payment_id
193 *
194 * @return void
195 *
196 */
197 function give_offline_send_admin_notice( $payment_id = 0 ) {
198
199 /* Send an email notification to the admin */
200 $admin_email = give_get_admin_notice_emails();
201 $user_info = give_get_payment_meta_user_info( $payment_id );
202
203 if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) {
204 $user_data = get_userdata( $user_info['id'] );
205 $name = $user_data->display_name;
206 } elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) {
207 $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
208 } else {
209 $name = $user_info['email'];
210 }
211
212 $amount = give_donation_amount( $payment_id );
213
214 $admin_subject = apply_filters( 'give_offline_admin_donation_notification_subject', __( 'New Pending Donation', 'give' ), $payment_id );
215
216 $admin_message = __( 'Dear Admin,', 'give' ) . "\n\n";
217 $admin_message .= sprintf(__( 'A new offline donation has been made on your website for %s.', 'give' ), $amount) . "\n\n";
218 $admin_message .= __( 'The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give' ) . "\n\n";
219
220
221 $admin_message .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n";
222 $admin_message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n";
223
224 $admin_message .= sprintf(
225 '<a href="%1$s">%2$s</a>',
226 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ),
227 __( 'View Donation Details &raquo;', 'give' )
228 ) . "\n\n";
229
230 $admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id );
231 $admin_message = give_do_email_tags( $admin_message, $payment_id );
232
233 $attachments = apply_filters( 'give_offline_admin_donation_notification_attachments', array(), $payment_id );
234 $admin_headers = apply_filters( 'give_offline_admin_donation_notification_headers', array(), $payment_id );
235
236 //Send Email
237 $emails = Give()->emails;
238 $emails->__set( 'heading', __( 'New Offline Donation', 'give' ) );
239
240 if ( ! empty( $admin_headers ) ) {
241 $emails->__set( 'headers', $admin_headers );
242 }
243
244 $emails->send( $admin_email, $admin_subject, $admin_message, $attachments );
245
246 }
247
248
249 /**
250 * Register gateway settings.
251 *
252 * @param $settings
253 *
254 * @return array
255 */
256 function give_offline_add_settings( $settings ) {
257
258 // Bailout: Do not show offline gateways setting in to metabox if its disabled globally.
259 if ( in_array( 'offline', (array) give_get_option( 'gateways' ) ) ) {
260 return $settings;
261 }
262
263 //Vars
264 $prefix = '_give_';
265
266 $is_gateway_active = give_is_gateway_active( 'offline' );
267
268 //this gateway isn't active
269 if ( ! $is_gateway_active ) {
270 //return settings and bounce
271 return $settings;
272 }
273
274 //Fields
275 $check_settings = array(
276
277 array(
278 'name' => __( 'Offline Donations', 'give' ),
279 'desc' => __( 'Do you want to customize the donation instructions for this form?', 'give' ),
280 'id' => $prefix . 'customize_offline_donations',
281 'type' => 'radio_inline',
282 'default' => 'global',
283 'options' => apply_filters( 'give_forms_content_options_select', array(
284 'global' => __( 'Global Option', 'give' ),
285 'enabled' => __( 'Customize', 'give' ),
286 'disabled' => __( 'Disable', 'give' ),
287 )
288 ),
289 ),
290 array(
291 'name' => __( 'Billing Fields', 'give' ),
292 'desc' => __( 'This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give' ),
293 'id' => $prefix . 'offline_donation_enable_billing_fields_single',
294 'row_classes' => 'give-subfield give-hidden',
295 'type' => 'radio_inline',
296 'default' => 'disabled',
297 'options' => array(
298 'enabled' => __( 'Enabled', 'give' ),
299 'disabled' => __( 'Disabled', 'give' ),
300 ),
301 ),
302 array(
303 'id' => $prefix . 'offline_checkout_notes',
304 'name' => __( 'Donation Instructions', 'give' ),
305 'desc' => __( 'Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
306 'default' => give_get_default_offline_donation_content(),
307 'type' => 'wysiwyg',
308 'row_classes' => 'give-subfield give-hidden',
309 'options' => array(
310 'textarea_rows' => 6,
311 )
312 ),
313 array(
314 'name' => 'offline_docs',
315 'type' => 'docs_link',
316 'url' => 'http://docs.givewp.com/settings-gateway-offline-donations',
317 'title' => __( 'Offline Donations', 'give' ),
318 ),
319 );
320
321 return array_merge( $settings, $check_settings );
322 }
323
324 add_filter( 'give_forms_offline_donations_metabox_fields', 'give_offline_add_settings' );
325
326
327 /**
328 * Offline Donation Content
329 *
330 * Get default offline donation text
331 *
332 * @return string
333 */
334 function give_get_default_offline_donation_content() {
335 $default_text = '<p>' . __( 'In order to make an offline donation we ask that you please follow these instructions', 'give' ) . ': </p>';
336 $default_text .= '<ol>';
337 $default_text .= '<li>';
338 $default_text .= sprintf(
339 /* translators: %s: site name */
340 __( 'Make a check payable to "{sitename}"', 'give' ) );
341 $default_text .= '</li>';
342 $default_text .= '<li>';
343 $default_text .= sprintf(
344 /* translators: %s: site name */
345 __( 'On the memo line of the check, please indicate that the donation is for "{sitename}"', 'give' ) );
346 $default_text .= '</li>';
347 $default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
348 $default_text .= '</ol>';
349 $default_text .= '{offline_mailing_address}<br>';
350 $default_text .= '<p>' . __( 'All contributions will be gratefully acknowledged and are tax deductible.', 'give' ) . '</p>';
351
352 return apply_filters( 'give_default_offline_donation_content', $default_text );
353
354 }
355
356 /**
357 * Offline Donation Email Content
358 *
359 * Gets the default offline donation email content
360 *
361 * @return string
362 */
363 function give_get_default_offline_donation_email_content() {
364 $default_text = '<p>' . __( 'Dear {name},', 'give' ) . '</p>';
365 $default_text .= '<p>' . __( 'Thank you for your offline donation request! Your generosity is greatly appreciated. In order to make an offline donation we ask that you please follow these instructions:', 'give' ) . '</p>';
366 $default_text .= '<ol>';
367 $default_text .= '<li>';
368 $default_text .= sprintf(
369 /* translators: %s: site name */
370 __( 'Make a check payable to "{sitename}"', 'give' )
371 );
372 $default_text .= '</li>';
373 $default_text .= '<li>';
374 $default_text .= sprintf(
375 __( 'On the memo line of the check, please indicate that the donation is for "{sitename}"', 'give' )
376 );
377 $default_text .= '</li>';
378 $default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
379 $default_text .= '</ol>';
380 $default_text .= '{offline_mailing_address}<br>';
381 $default_text .= '<p>' . __( 'Once your donation has been received we will mark it as complete and you will receive an email receipt for your records. Please contact us with any questions you may have!', 'give' ) . '</p>';
382 $default_text .= '<p>' . __( 'Sincerely,', 'give' ) . '</p>';
383 $default_text .= '<p>{sitename}</p>';
384
385 return apply_filters( 'give_default_offline_donation_content', $default_text );
386
387 }
388
389 /**
390 * Get offline payment instructions.
391 *
392 * @since 1.7
393 *
394 * @param int $form_id
395 * @param bool $wpautop
396 *
397 * @return string
398 */
399 function give_get_offline_payment_instruction( $form_id, $wpautop = false ) {
400 // Bailout.
401 if ( ! $form_id ) {
402 return '';
403 }
404
405 $post_offline_customization_option = give_get_meta( $form_id, '_give_customize_offline_donations', true );
406 $post_offline_instructions = give_get_meta( $form_id, '_give_offline_checkout_notes', true );
407 $global_offline_instruction = give_get_option( 'global_offline_donation_content' );
408 $offline_instructions = $global_offline_instruction;
409
410 if ( give_is_setting_enabled( $post_offline_customization_option ) ) {
411 $offline_instructions = $post_offline_instructions;
412 }
413
414 $settings_url = admin_url( 'post.php?post=' . $form_id . '&action=edit&message=1' );
415
416 /* translators: %s: form settings url */
417 $offline_instructions = ! empty( $offline_instructions )
418 ? $offline_instructions
419 : sprintf(
420 __( 'Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give' ),
421 $settings_url
422 );
423
424 $offline_instructions = give_do_email_tags( $offline_instructions, null );
425
426 $formmated_offline_instructions = $wpautop
427 ? wpautop( do_shortcode( $offline_instructions ) )
428 : $offline_instructions;
429
430 /**
431 * Filter the offline instruction content
432 *
433 * @since 2.2.0
434 *
435 */
436 $formmated_offline_instructions = apply_filters(
437 'give_the_offline_instructions_content',
438 $formmated_offline_instructions,
439 $offline_instructions,
440 $form_id,
441 $wpautop
442 );
443
444 return $formmated_offline_instructions;
445 }
446
447
448 /**
449 * Remove offline gateway from gateway list of offline disable for form.
450 *
451 * @since 1.8
452 *
453 * @param array $gateway_list
454 * @param $form_id
455 *
456 * @return array
457 */
458 function give_filter_offline_gateway( $gateway_list, $form_id ) {
459 if (
460 // Show offline payment gateway if enable for new donation form.
461 ( false === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post-new.php?post_type=give_forms' ) )
462 && $form_id
463 && ! give_is_setting_enabled( give_get_meta( $form_id, '_give_customize_offline_donations', true, 'global' ), array( 'enabled', 'global' ) )
464 ) {
465 unset( $gateway_list['offline'] );
466 }
467
468 // Output.
469 return $gateway_list;
470 }
471
472 add_filter( 'give_enabled_payment_gateways', 'give_filter_offline_gateway', 10, 2 );
473
474 /**
475 * Set default gateway to global default payment gateway
476 * if current default gateways selected offline and offline payment gateway is disabled.
477 *
478 * @since 1.8
479 *
480 * @param string $meta_key Meta key.
481 * @param string $meta_value Meta value.
482 * @param int $postid Form ID.
483 *
484 * @return void
485 */
486 function _give_customize_offline_donations_on_save_callback( $meta_key, $meta_value, $postid ) {
487 if (
488 ! give_is_setting_enabled( $meta_value, array( 'global', 'enabled' ) )
489 && ( 'offline' === give_get_meta( $postid, '_give_default_gateway', true ) )
490 ) {
491 give_update_meta( $postid, '_give_default_gateway', 'global' );
492 }
493 }
494
495 add_filter( 'give_save__give_customize_offline_donations', '_give_customize_offline_donations_on_save_callback', 10, 3 );
496