Test Failed
Push — issue-2937 ( c6b853 )
by Ravinder
404:30 queued 397:15
created

offline-donations.php ➔ give_get_offline_payment_instruction()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

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