PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.2
GiveWP – Donation Plugin and Fundraising Platform v2.1.2
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
actions.php 8 years ago functions.php 8 years ago manual.php 8 years ago offline-donations.php 8 years ago paypal-standard.php 8 years ago
offline-donations.php
511 lines
1 <?php
2 /**
3 * Offline Donations Gateway
4 *
5 * @package Give
6 * @subpackage Gateways
7 * @copyright Copyright (c) 2016, WordImpress
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 /**
13 * Register the payment gateway
14 *
15 * @since 1.0
16 *
17 * @param array $gateways
18 *
19 * @return array
20 */
21 function give_offline_register_gateway( $gateways ) {
22 // Format: ID => Name
23 $gateways['offline'] = array(
24 'admin_label' => esc_attr__( 'Offline Donation', 'give' ),
25 'checkout_label' => esc_attr__( 'Offline Donation', 'give' ),
26 );
27
28 return $gateways;
29 }
30
31 add_filter( 'give_payment_gateways', 'give_offline_register_gateway', 1 );
32
33
34 /**
35 * Add our payment instructions to the checkout
36 *
37 * @since 1.0
38 *
39 * @param int $form_id Give form id.
40 *
41 * @return void
42 */
43 function give_offline_payment_cc_form( $form_id ) {
44 // Get offline payment instruction.
45 $offline_instructions = give_get_offline_payment_instruction( $form_id, true );
46
47 ob_start();
48
49 /**
50 * Fires before the offline info fields.
51 *
52 * @since 1.0
53 *
54 * @param int $form_id Give form id.
55 */
56 do_action( 'give_before_offline_info_fields', $form_id );
57 ?>
58 <fieldset id="give_offline_payment_info">
59 <?php echo stripslashes( $offline_instructions ); ?>
60 </fieldset>
61 <?php
62 /**
63 * Fires after the offline info fields.
64 *
65 * @since 1.0
66 *
67 * @param int $form_id Give form id.
68 */
69 do_action( 'give_after_offline_info_fields', $form_id );
70
71 echo ob_get_clean();
72 }
73
74 add_action( 'give_offline_cc_form', 'give_offline_payment_cc_form' );
75
76 /**
77 * Give Offline Billing Field
78 *
79 * @param $form_id
80 */
81 function give_offline_billing_fields( $form_id ) {
82 //Enable Default CC fields (billing info)
83 $post_offline_cc_fields = give_get_meta( $form_id, '_give_offline_donation_enable_billing_fields_single', true );
84 $post_offline_customize_option = give_get_meta( $form_id, '_give_customize_offline_donations', true );
85
86 $global_offline_cc_fields = give_get_option( 'give_offline_donation_enable_billing_fields' );
87
88 //Output CC Address fields if global option is on and user hasn't elected to customize this form's offline donation options
89 if (
90 ( give_is_setting_enabled( $post_offline_customize_option, 'global' ) && give_is_setting_enabled( $global_offline_cc_fields ) )
91 || ( give_is_setting_enabled( $post_offline_customize_option, 'enabled' ) && give_is_setting_enabled( $post_offline_cc_fields ) )
92 ) {
93 give_default_cc_address_fields( $form_id );
94 }
95 }
96
97 add_action( 'give_before_offline_info_fields', 'give_offline_billing_fields', 10, 1 );
98
99 /**
100 * Process the payment
101 *
102 * @since 1.0
103 *
104 * @param $purchase_data
105 *
106 * @return void
107 */
108 function give_offline_process_payment( $purchase_data ) {
109
110 // Setup the payment details.
111 $payment_data = array(
112 'price' => $purchase_data['price'],
113 'give_form_title' => $purchase_data['post_data']['give-form-title'],
114 'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ),
115 'give_price_id' => isset( $purchase_data['post_data']['give-price-id'] ) ? $purchase_data['post_data']['give-price-id'] : '',
116 'date' => $purchase_data['date'],
117 'user_email' => $purchase_data['user_email'],
118 'purchase_key' => $purchase_data['purchase_key'],
119 'currency' => give_get_currency( $purchase_data['post_data']['give-form-id'], $purchase_data ),
120 'user_info' => $purchase_data['user_info'],
121 'status' => 'pending',
122 'gateway' => 'offline',
123 );
124
125
126 // record the pending payment
127 $payment = give_insert_payment( $payment_data );
128
129 if ( $payment ) {
130 give_send_to_success_page();
131 } else {
132 // if errors are present, send the user back to the donation form so they can be corrected
133 give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] );
134 }
135
136 }
137
138 add_action( 'give_gateway_offline', 'give_offline_process_payment' );
139
140
141 /**
142 * Send Offline Donation Instructions
143 *
144 * Sends a notice to the donor with offline instructions; can be customized per form
145 *
146 * @param int $payment_id
147 *
148 * @since 1.0
149 * @return void
150 */
151 function give_offline_send_donor_instructions( $payment_id = 0 ) {
152
153 $payment_data = give_get_payment_meta( $payment_id );
154 $post_offline_customization_option = give_get_meta( $payment_data['form_id'], '_give_customize_offline_donations', true );
155
156 //Customize email content depending on whether the single form has been customized
157 $email_content = give_get_option( 'global_offline_donation_email' );
158
159 if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
160 $email_content = give_get_meta( $payment_data['form_id'], '_give_offline_donation_email', true );
161 }
162
163 $from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
164
165 /**
166 * Filters the from name.
167 *
168 * @since 1.7
169 */
170 $from_name = apply_filters( 'give_donation_from_name', $from_name, $payment_id, $payment_data );
171
172 $from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) );
173
174 /**
175 * Filters the from email.
176 *
177 * @since 1.7
178 */
179 $from_email = apply_filters( 'give_donation_from_address', $from_email, $payment_id, $payment_data );
180
181 $to_email = give_get_payment_user_email( $payment_id );
182
183 $subject = give_get_option( 'offline_donation_subject', __( 'Offline Donation Instructions', 'give' ) );
184 if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
185 $subject = give_get_meta( $payment_data['form_id'], '_give_offline_donation_subject', true );
186 }
187
188 $subject = apply_filters( 'give_offline_donation_subject', wp_strip_all_tags( $subject ), $payment_id );
189 $subject = give_do_email_tags( $subject, $payment_id );
190
191 $attachments = apply_filters( 'give_offline_donation_attachments', array(), $payment_id, $payment_data );
192 $message = give_do_email_tags( $email_content, $payment_id );
193
194 $emails = Give()->emails;
195
196 $emails->__set( 'from_name', $from_name );
197 $emails->__set( 'from_email', $from_email );
198 $emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) );
199
200 $headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data );
201 $emails->__set( 'headers', $headers );
202
203 $emails->send( $to_email, $subject, $message, $attachments );
204
205 }
206
207
208 /**
209 * Send Offline Donation Admin Notice.
210 *
211 * Sends a notice to site admins about the pending donation.
212 *
213 * @since 1.0
214 *
215 * @param int $payment_id
216 *
217 * @return void
218 *
219 */
220 function give_offline_send_admin_notice( $payment_id = 0 ) {
221
222 /* Send an email notification to the admin */
223 $admin_email = give_get_admin_notice_emails();
224 $user_info = give_get_payment_meta_user_info( $payment_id );
225
226 if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) {
227 $user_data = get_userdata( $user_info['id'] );
228 $name = $user_data->display_name;
229 } elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) {
230 $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
231 } else {
232 $name = $user_info['email'];
233 }
234
235 $amount = give_donation_amount( $payment_id );
236
237 $admin_subject = apply_filters( 'give_offline_admin_donation_notification_subject', __( 'New Pending Donation', 'give' ), $payment_id );
238
239 $admin_message = __( 'Dear Admin,', 'give' ) . "\n\n";
240 $admin_message .= sprintf(__( 'A new offline donation has been made on your website for %s.', 'give' ), $amount) . "\n\n";
241 $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";
242
243
244 $admin_message .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n";
245 $admin_message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n";
246
247 $admin_message .= sprintf(
248 '<a href="%1$s">%2$s</a>',
249 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ),
250 __( 'View Donation Details &raquo;', 'give' )
251 ) . "\n\n";
252
253 $admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id );
254 $admin_message = give_do_email_tags( $admin_message, $payment_id );
255
256 $attachments = apply_filters( 'give_offline_admin_donation_notification_attachments', array(), $payment_id );
257 $admin_headers = apply_filters( 'give_offline_admin_donation_notification_headers', array(), $payment_id );
258
259 //Send Email
260 $emails = Give()->emails;
261 $emails->__set( 'heading', __( 'New Offline Donation', 'give' ) );
262
263 if ( ! empty( $admin_headers ) ) {
264 $emails->__set( 'headers', $admin_headers );
265 }
266
267 $emails->send( $admin_email, $admin_subject, $admin_message, $attachments );
268
269 }
270
271
272 /**
273 >>>>>>> release/2.0
274 * Register gateway settings.
275 *
276 * @param $settings
277 *
278 * @return array
279 */
280 function give_offline_add_settings( $settings ) {
281
282 // Bailout: Do not show offline gateways setting in to metabox if its disabled globally.
283 if ( in_array( 'offline', (array) give_get_option( 'gateways' ) ) ) {
284 return $settings;
285 }
286
287 //Vars
288 $prefix = '_give_';
289
290 $is_gateway_active = give_is_gateway_active( 'offline' );
291
292 //this gateway isn't active
293 if ( ! $is_gateway_active ) {
294 //return settings and bounce
295 return $settings;
296 }
297
298 //Fields
299 $check_settings = array(
300
301 array(
302 'name' => __( 'Offline Donations', 'give' ),
303 'desc' => __( 'Do you want to customize the donation instructions for this form?', 'give' ),
304 'id' => $prefix . 'customize_offline_donations',
305 'type' => 'radio_inline',
306 'default' => 'global',
307 'options' => apply_filters( 'give_forms_content_options_select', array(
308 'global' => __( 'Global Option', 'give' ),
309 'enabled' => __( 'Customize', 'give' ),
310 'disabled' => __( 'Disable', 'give' ),
311 )
312 ),
313 ),
314 array(
315 'name' => __( 'Billing Fields', 'give' ),
316 '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' ),
317 'id' => $prefix . 'offline_donation_enable_billing_fields_single',
318 'row_classes' => 'give-subfield give-hidden',
319 'type' => 'radio_inline',
320 'default' => 'disabled',
321 'options' => array(
322 'enabled' => __( 'Enabled', 'give' ),
323 'disabled' => __( 'Disabled', 'give' ),
324 ),
325 ),
326 array(
327 'id' => $prefix . 'offline_checkout_notes',
328 'name' => __( 'Donation Instructions', 'give' ),
329 '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' ),
330 'default' => give_get_default_offline_donation_content(),
331 'type' => 'wysiwyg',
332 'row_classes' => 'give-subfield give-hidden',
333 'options' => array(
334 'textarea_rows' => 6,
335 )
336 ),
337 array(
338 'name' => 'offline_docs',
339 'type' => 'docs_link',
340 'url' => 'http://docs.givewp.com/settings-gateway-offline-donations',
341 'title' => __( 'Offline Donations', 'give' ),
342 ),
343 );
344
345 return array_merge( $settings, $check_settings );
346 }
347
348 add_filter( 'give_forms_offline_donations_metabox_fields', 'give_offline_add_settings' );
349
350
351 /**
352 * Offline Donation Content
353 *
354 * Get default offline donation text
355 *
356 * @return string
357 */
358 function give_get_default_offline_donation_content() {
359
360 $sitename = get_bloginfo( 'sitename' );
361
362 $default_text = '<p>' . __( 'In order to make an offline donation we ask that you please follow these instructions', 'give' ) . ': </p>';
363 $default_text .= '<ol>';
364 $default_text .= '<li>';
365 $default_text .= sprintf(
366 /* translators: %s: site name */
367 __( 'Make a check payable to "%s"', 'give' ),
368 $sitename
369 );
370 $default_text .= '</li>';
371 $default_text .= '<li>';
372 $default_text .= sprintf(
373 /* translators: %s: site name */
374 __( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ),
375 $sitename
376 );
377 $default_text .= '</li>';
378 $default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
379 $default_text .= '</ol>';
380 $default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>' . $sitename . '</em><br>';
381 $default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>';
382 $default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>';
383 $default_text .= '<p>' . __( 'All contributions will be gratefully acknowledged and are tax deductible.', 'give' ) . '</p>';
384
385 return apply_filters( 'give_default_offline_donation_content', $default_text );
386
387 }
388
389 /**
390 * Offline Donation Email Content
391 *
392 * Gets the default offline donation email content
393 *
394 * @return string
395 */
396 function give_get_default_offline_donation_email_content() {
397
398 $sitename = get_bloginfo( 'sitename' );
399 $default_text = '<p>' . __( 'Dear {name},', 'give' ) . '</p>';
400 $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>';
401 $default_text .= '<ol>';
402 $default_text .= '<li>';
403 $default_text .= sprintf(
404 /* translators: %s: site name */
405 __( 'Make a check payable to "%s"', 'give' ),
406 $sitename
407 );
408 $default_text .= '</li>';
409 $default_text .= '<li>';
410 $default_text .= sprintf(
411 /* translators: %s: site name */
412 __( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ),
413 $sitename
414 );
415 $default_text .= '</li>';
416 $default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
417 $default_text .= '</ol>';
418 $default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>' . $sitename . '</em><br>';
419 $default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>';
420 $default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>';
421 $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>';
422 $default_text .= '<p>' . __( 'Sincerely,', 'give' ) . '</p>';
423 $default_text .= '<p>' . $sitename . '</p>';
424
425 return apply_filters( 'give_default_offline_donation_content', $default_text );
426
427 }
428
429 /**
430 * Get offline payment instructions.
431 *
432 * @since 1.7
433 *
434 * @param int $form_id
435 * @param bool $wpautop
436 *
437 * @return string
438 */
439 function give_get_offline_payment_instruction( $form_id, $wpautop = false ) {
440 // Bailout.
441 if ( ! $form_id ) {
442 return '';
443 }
444
445 $post_offline_customization_option = give_get_meta( $form_id, '_give_customize_offline_donations', true );
446 $post_offline_instructions = give_get_meta( $form_id, '_give_offline_checkout_notes', true );
447 $global_offline_instruction = give_get_option( 'global_offline_donation_content' );
448 $offline_instructions = $global_offline_instruction;
449
450 if ( give_is_setting_enabled( $post_offline_customization_option ) ) {
451 $offline_instructions = $post_offline_instructions;
452 }
453
454 $settings_url = admin_url( 'post.php?post=' . $form_id . '&action=edit&message=1' );
455
456 /* translators: %s: form settings url */
457 $offline_instructions = ! empty( $offline_instructions ) ? $offline_instructions : sprintf( __( 'Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give' ), $settings_url );
458
459 return ( $wpautop ? wpautop( $offline_instructions ) : $offline_instructions );
460 }
461
462
463 /**
464 * Remove offline gateway from gateway list of offline disable for form.
465 *
466 * @since 1.8
467 *
468 * @param array $gateway_list
469 * @param $form_id
470 *
471 * @return array
472 */
473 function give_filter_offline_gateway( $gateway_list, $form_id ) {
474 if (
475 // Show offline payment gateway if enable for new donation form.
476 ( false === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post-new.php?post_type=give_forms' ) )
477 && $form_id
478 && ! give_is_setting_enabled( give_get_meta( $form_id, '_give_customize_offline_donations', true ), array( 'enabled', 'global' ) )
479 ) {
480 unset( $gateway_list['offline'] );
481 }
482
483 // Output.
484 return $gateway_list;
485 }
486
487 add_filter( 'give_enabled_payment_gateways', 'give_filter_offline_gateway', 10, 2 );
488
489 /**
490 * Set default gateway to global default payment gateway
491 * if current default gateways selected offline and offline payment gateway is disabled.
492 *
493 * @since 1.8
494 *
495 * @param string $meta_key Meta key.
496 * @param string $meta_value Meta value.
497 * @param int $postid Form ID.
498 *
499 * @return void
500 */
501 function _give_customize_offline_donations_on_save_callback( $meta_key, $meta_value, $postid ) {
502 if (
503 ! give_is_setting_enabled( $meta_value, array( 'global', 'enabled' ) )
504 && ( 'offline' === give_get_meta( $postid, '_give_default_gateway', true ) )
505 ) {
506 give_update_meta( $postid, '_give_default_gateway', 'global' );
507 }
508 }
509
510 add_filter( 'give_save__give_customize_offline_donations', '_give_customize_offline_donations_on_save_callback', 10, 3 );
511