Test Failed
Push — release/1.8.12 ( b58a2f...d255b1 )
by Ravinder
375:09 queued 372:17
created

offline-donations.php ➔ give_offline_billing_fields()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 2
nop 1
dl 0
loc 15
rs 8.8571
c 0
b 0
f 0
ccs 0
cts 7
cp 0
crap 30
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 44
	$gateways['offline'] = array(
24 44
		'admin_label'    => esc_attr__( 'Offline Donation', 'give' ),
25 44
		'checkout_label' => esc_attr__( 'Offline Donation', 'give' )
26 44
	);
27
28 44
	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 ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'stripslashes'
Loading history...
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();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
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(),
120
		'user_info'       => $purchase_data['user_info'],
121
		'status'          => 'pending',
122
		'gateway'         => 'offline'
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
123
	);
124
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
125
126
	// record the pending payment
127
	$payment = give_insert_payment( $payment_data );
128
129
	if ( $payment ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $payment of type false|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
130
		give_offline_send_admin_notice( $payment );
131
		give_offline_send_donor_instructions( $payment );
132
		give_send_to_success_page();
133
	} else {
134
		// if errors are present, send the user back to the donation form so they can be corrected
135
		give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] );
0 ignored issues
show
Documentation introduced by
'?payment-mode=' . $purc..._data']['give-gateway'] is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
136
	}
137
138
}
139
140
add_action( 'give_gateway_offline', 'give_offline_process_payment' );
141
142
143
/**
144
 * Send Offline Donation Instructions
145
 *
146
 * Sends a notice to the donor with offline instructions; can be customized per form
147
 *
148
 * @param int $payment_id
149
 *
150
 * @since       1.0
151
 * @return void
152
 */
153
function give_offline_send_donor_instructions( $payment_id = 0 ) {
154
155
	$payment_data                      = give_get_payment_meta( $payment_id );
156
	$post_offline_customization_option = give_get_meta( $payment_data['form_id'], '_give_customize_offline_donations', true );
157
158
	//Customize email content depending on whether the single form has been customized
159
	$email_content = give_get_option( 'global_offline_donation_email' );
160
161
	if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
162
		$email_content = give_get_meta( $payment_data['form_id'], '_give_offline_donation_email', true );
163
	}
164
165
	$from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
166
167
	/**
168
	 * Filters the from name.
169
	 *
170
	 * @since 1.7
171
	 */
172
	$from_name = apply_filters( 'give_donation_from_name', $from_name, $payment_id, $payment_data );
173
174
	$from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) );
175
176
	/**
177
	 * Filters the from email.
178
	 *
179
	 * @since 1.7
180
	 */
181
	$from_email = apply_filters( 'give_donation_from_address', $from_email, $payment_id, $payment_data );
182
183
	$to_email = give_get_payment_user_email( $payment_id );
184
185
	$subject = give_get_option( 'offline_donation_subject', __( 'Offline Donation Instructions', 'give' ) );
186
	if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
187
		$subject = give_get_meta( $payment_data['form_id'], '_give_offline_donation_subject', true );
188
	}
189
190
	$subject = apply_filters( 'give_offline_donation_subject', wp_strip_all_tags( $subject ), $payment_id );
191
	$subject = give_do_email_tags( $subject, $payment_id );
192
193
	$attachments = apply_filters( 'give_offline_donation_attachments', array(), $payment_id, $payment_data );
194
	$message     = give_do_email_tags( $email_content, $payment_id );
195
196
	$emails = Give()->emails;
197
198
	$emails->__set( 'from_name', $from_name );
199
	$emails->__set( 'from_email', $from_email );
200
	$emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) );
201
202
	$headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data );
203
	$emails->__set( 'headers', $headers );
204
205
	$emails->send( $to_email, $subject, $message, $attachments );
206
207
}
208
209
210
/**
211
 * Send Offline Donation Admin Notice.
212
 *
213
 * Sends a notice to site admins about the pending donation.
214
 *
215
 * @since       1.0
216
 *
217
 * @param int $payment_id
218
 *
219
 * @return void
220
 *
221
 */
222
function give_offline_send_admin_notice( $payment_id = 0 ) {
223
224
	/* Send an email notification to the admin */
225
	$admin_email = give_get_admin_notice_emails();
226
	$user_info   = give_get_payment_meta_user_info( $payment_id );
227
228 View Code Duplication
	if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
229
		$user_data = get_userdata( $user_info['id'] );
230
		$name      = $user_data->display_name;
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
231
	} elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) {
232
		$name = $user_info['first_name'] . ' ' . $user_info['last_name'];
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
233
	} else {
234
		$name = $user_info['email'];
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
235
	}
236
237
	$amount = give_currency_filter( give_format_amount( give_get_payment_amount( $payment_id ), array( 'sanitize' => false ) ) );
238
239
	$admin_subject = apply_filters( 'give_offline_admin_donation_notification_subject', __( 'New Pending Donation', 'give' ), $payment_id );
240
241
	$admin_message = __( 'Dear Admin,', 'give' ) . "\n\n";
242
	$admin_message .= sprintf(__( 'A new offline donation has been made on your website for %s.', 'give' ), $amount) . "\n\n";
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
243
	$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";
244
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
245
246
	$admin_message .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n";
247
	$admin_message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n";
248
249
	$admin_message .= sprintf(
250
		                  '<a href="%1$s">%2$s</a>',
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 26.
Loading history...
251
		                  admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 26.
Loading history...
252
		                  __( 'View Donation Details &raquo;', 'give' )
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 26.
Loading history...
253
	                  ) . "\n\n";
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 4 spaces, but found 22.
Loading history...
254
255
	$admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id );
256
	$admin_message = give_do_email_tags( $admin_message, $payment_id );
257
258
	$attachments   = apply_filters( 'give_offline_admin_donation_notification_attachments', array(), $payment_id );
259
	$admin_headers = apply_filters( 'give_offline_admin_donation_notification_headers', array(), $payment_id );
260
261
	//Send Email
262
	$emails = Give()->emails;
263
	$emails->__set( 'heading', __( 'New Offline Donation', 'give' ) );
264
265
	if ( ! empty( $admin_headers ) ) {
266
		$emails->__set( 'headers', $admin_headers );
267
	}
268
269
	$emails->send( $admin_email, $admin_subject, $admin_message, $attachments );
270
271
}
272
273
274
/**
275
 * Register gateway settings.
276
 *
277
 * @param $settings
278
 *
279
 * @return array
280
 */
281
function give_offline_add_settings( $settings ) {
282
283
	// Bailout: Do not show offline gateways setting in to metabox if its disabled globally.
284
	if ( in_array( 'offline', give_get_option( 'gateways' ) ) ) {
285
		return $settings;
286
	}
287
288
	//Vars
289
	$prefix = '_give_';
290
291
	$is_gateway_active = give_is_gateway_active( 'offline' );
292
293
	//this gateway isn't active
294
	if ( ! $is_gateway_active ) {
295
		//return settings and bounce
296
		return $settings;
297
	}
298
299
	//Fields
300
	$check_settings = array(
301
302
		array(
303
			'name'    => __( 'Offline Donations', 'give' ),
304
			'desc'    => __( 'Do you want to customize the donation instructions for this form?', 'give' ),
305
			'id'      => $prefix . 'customize_offline_donations',
306
			'type'    => 'radio_inline',
307
			'default' => 'global',
308
			'options' => apply_filters( 'give_forms_content_options_select', array(
309
					'global'   => __( 'Global Option', 'give' ),
310
					'enabled'  => __( 'Customize', 'give' ),
311
					'disabled' => __( 'Disable', 'give' ),
312
				)
313
			),
314
		),
315
		array(
316
			'name'        => __( 'Billing Fields', 'give' ),
317
			'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' ),
318
			'id'          => $prefix . 'offline_donation_enable_billing_fields_single',
319
			'row_classes' => 'give-subfield',
320
			'type'        => 'radio_inline',
321
			'default'     => 'disabled',
322
			'options'     => array(
323
				'enabled'  => __( 'Enabled', 'give' ),
324
				'disabled' => __( 'Disabled', 'give' ),
325
			),
326
		),
327
		array(
328
			'id'          => $prefix . 'offline_checkout_notes',
329
			'name'        => __( 'Donation Instructions', 'give' ),
330
			'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' ),
331
			'default'     => give_get_default_offline_donation_content(),
332
			'type'        => 'wysiwyg',
333
			'row_classes' => 'give-subfield',
334
			'options'     => array(
335
				'textarea_rows' => 6,
336
			)
337
		),
338
		array(
339
			'id'          => $prefix . 'offline_donation_subject',
340
			'name'        => __( 'Email Subject', 'give' ),
341
			'desc'        => __( 'Enter the subject line for the donation receipt email.', 'give' ),
342
			'default'     => __( '{form_title} - Offline Donation Instructions', 'give' ),
343
			'row_classes' => 'give-subfield',
344
			'type'        => 'text'
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
345
		),
346
		array(
347
			'id'          => $prefix . 'offline_donation_email',
348
			'name'        => __( 'Email Instructions', 'give' ),
349
			'desc'        => __( 'Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ) . ' ' . __( 'Available template tags:', 'give' ) . give_get_emails_tags_list(),
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw '__'
Loading history...
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_emails_tags_list'
Loading history...
350
			'default'     => give_get_default_offline_donation_email_content(),
351
			'type'        => 'wysiwyg',
352
			'row_classes' => 'give-subfield',
353
			'options'     => array(
354
				'textarea_rows' => 6,
355
			)
356
		),
357
		array(
358
			'name'  => 'offline_docs',
359
			'type'  => 'docs_link',
360
			'url'   => 'http://docs.givewp.com/settings-gateway-offline-donations',
361
			'title' => __( 'Offline Donations', 'give' ),
362
		),
363
	);
364
365
	return array_merge( $settings, $check_settings );
366
}
367
368
add_filter( 'give_forms_offline_donations_metabox_fields', 'give_offline_add_settings' );
369
370
371
/**
372
 * Offline Donation Content
373
 *
374
 * Get default offline donation text
375
 *
376
 * @return string
377
 */
378
function give_get_default_offline_donation_content() {
379
380
	$sitename = get_bloginfo( 'sitename' );
381
382
	$default_text = '<p>' . __( 'In order to make an offline donation we ask that you please follow these instructions', 'give' ) . ': </p>';
383
	$default_text .= '<ol>';
384
	$default_text .= '<li>';
385
	$default_text .= sprintf(
386
	/* translators: %s: site name */
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 4.
Loading history...
387
		__( 'Make a check payable to "%s"', 'give' ),
388
		$sitename
389
	);
390
	$default_text .= '</li>';
391
	$default_text .= '<li>';
392
	$default_text .= sprintf(
393
	/* translators: %s: site name */
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 4.
Loading history...
394
		__( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ),
395
		$sitename
396
	);
397
	$default_text .= '</li>';
398
	$default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
399
	$default_text .= '</ol>';
400
	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>' . $sitename . '</em><br>';
401
	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>';
402
	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>';
403
	$default_text .= '<p>' . __( 'All contributions will be gratefully acknowledged and are tax deductible.', 'give' ) . '</p>';
404
405
	return apply_filters( 'give_default_offline_donation_content', $default_text );
406
407
}
408
409
/**
410
 * Offline Donation Email Content
411
 *
412
 * Gets the default offline donation email content
413
 *
414
 * @return string
415
 */
416
function give_get_default_offline_donation_email_content() {
417
418
	$sitename     = get_bloginfo( 'sitename' );
419
	$default_text = '<p>' . __( 'Dear {name},', 'give' ) . '</p>';
420
	$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>';
421
	$default_text .= '<ol>';
422
	$default_text .= '<li>';
423
	$default_text .= sprintf(
424
	/* translators: %s: site name */
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 4.
Loading history...
425
		__( 'Make a check payable to "%s"', 'give' ),
426
		$sitename
427
	);
428
	$default_text .= '</li>';
429
	$default_text .= '<li>';
430
	$default_text .= sprintf(
431
	/* translators: %s: site name */
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 4.
Loading history...
432
		__( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ),
433
		$sitename
434
	);
435
	$default_text .= '</li>';
436
	$default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
437
	$default_text .= '</ol>';
438
	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>' . $sitename . '</em><br>';
439
	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>';
440
	$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>';
441
	$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>';
442
	$default_text .= '<p>' . __( 'Sincerely,', 'give' ) . '</p>';
443
	$default_text .= '<p>' . $sitename . '</p>';
444
445
	return apply_filters( 'give_default_offline_donation_content', $default_text );
446
447
}
448
449
/**
450
 * Set notice for offline donation.
451
 *
452
 * @since 1.7
453
 *
454
 * @param string $notice
455
 * @param int    $id
456
 *
457
 * @return string
458
 */
459
function give_offline_donation_receipt_status_notice( $notice, $id ) {
460
	$payment = new Give_Payment( $id );
461
462
	if ( 'offline' !== $payment->gateway || $payment->is_completed() ) {
463
		return $notice;
464
	}
465
466
	return Give()->notices->print_frontend_notice( __( 'Payment Pending: Please follow the instructions below to complete your donation.', 'give' ), false, 'warning' );
467
}
468
469
add_filter( 'give_receipt_status_notice', 'give_offline_donation_receipt_status_notice', 10, 2 );
470
471
/**
472
 * Add offline payment instruction on payment receipt.
473
 *
474
 * @since 1.7
475
 *
476
 * @param WP_Post $payment
477
 *
478
 * @return mixed
479
 */
480
function give_offline_payment_receipt_after( $payment ) {
481
	// Get payment object.
482
	$payment = new Give_Payment( $payment->ID );
483
484
	// Bailout.
485
	if ( 'offline' !== $payment->gateway ) {
486
		return false;
487
	}
488
489
	?>
490
    <tr>
491
        <td scope="row"><strong><?php esc_html_e( 'Offline Donations Instructions', 'give' ); ?></strong></td>
492
        <td>
493
			<?php echo give_get_offline_payment_instruction( $payment->form_id, true ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_offline_payment_instruction'
Loading history...
494
        </td>
495
    </tr>
496
	<?php
497
}
498
499
add_filter( 'give_payment_receipt_after', 'give_offline_payment_receipt_after' );
500
501
/**
502
 * Get offline payment instructions.
503
 *
504
 * @since 1.7
505
 *
506
 * @param int  $form_id
507
 * @param bool $wpautop
508
 *
509
 * @return string
510
 */
511
function give_get_offline_payment_instruction( $form_id, $wpautop = false ) {
512
	// Bailout.
513
	if ( ! $form_id ) {
514
		return '';
515
	}
516
517
	$post_offline_customization_option = give_get_meta( $form_id, '_give_customize_offline_donations', true );
518
	$post_offline_instructions         = give_get_meta( $form_id, '_give_offline_checkout_notes', true );
519
	$global_offline_instruction        = give_get_option( 'global_offline_donation_content' );
520
	$offline_instructions              = $global_offline_instruction;
521
522
	if ( give_is_setting_enabled( $post_offline_customization_option ) ) {
523
		$offline_instructions = $post_offline_instructions;
524
	}
525
526
	$settings_url = admin_url( 'post.php?post=' . $form_id . '&action=edit&message=1' );
527
528
	/* translators: %s: form settings url */
529
	$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 );
530
531
	return ( $wpautop ? wpautop( $offline_instructions ) : $offline_instructions );
532
}
533
534
535
/**
536
 * Remove offline gateway from gateway list of offline disable for form.
537
 *
538
 * @since  1.8
539
 *
540
 * @param  array $gateway_list
541
 * @param        $form_id
542
 *
543
 * @return array
544
 */
545
function give_filter_offline_gateway( $gateway_list, $form_id ) {
546
	if (
547
		// Show offline payment gateway if enable for new donation form.
548
		( false === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post-new.php?post_type=give_forms' ) )
0 ignored issues
show
introduced by
Detected usage of a non-validated input variable: $_SERVER
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_SERVER
Loading history...
549
		&& $form_id
550
		&& ! give_is_setting_enabled( give_get_meta( $form_id, '_give_customize_offline_donations', true ), array(
0 ignored issues
show
Documentation introduced by
array('enabled', 'global') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
551
			'enabled',
552
			'global',
553
		) )
554
	) {
555
		unset( $gateway_list['offline'] );
556
	}
557
558
	// Output.
559
	return $gateway_list;
560
}
561
562
add_filter( 'give_enabled_payment_gateways', 'give_filter_offline_gateway', 10, 2 );
563
564
/**
565
 * Set default gateway to global default payment gateway
566
 * if current default gateways selected offline and offline payment gateway is disabled.
567
 *
568
 * @since 1.8
569
 *
570
 * @param  string $meta_key   Meta key.
571
 * @param  string $meta_value Meta value.
572
 * @param  int    $postid     Form ID.
573
 *
574
 * @return void
575
 */
576
function _give_customize_offline_donations_on_save_callback( $meta_key, $meta_value, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $meta_key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
577
	if ( ! give_is_setting_enabled( $meta_value ) && ( 'offline' === give_get_meta( $postid, '_give_default_gateway', true ) ) ) {
578
		give_update_meta( $postid, '_give_default_gateway', 'global' );
579
	}
580
}
581
582
add_filter( 'give_save__give_customize_offline_donations', '_give_customize_offline_donations_on_save_callback', 10, 3 );
583